Skip to content

Commit

Permalink
Merge branch 'scaling' into 'master'
Browse files Browse the repository at this point in the history
Support Heightened +1 damage scaling for prepared slots

See merge request hooking/foundry-vtt---pathfinder-2e!18
  • Loading branch information
shaun-newsome committed Feb 18, 2020
2 parents 763302d + 554c8f8 commit f0ed876
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 9 deletions.
2 changes: 1 addition & 1 deletion scripts/actor/sheet/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ class ActorSheetPF2e extends ActorSheet {
event.preventDefault();
let itemId = $(event.currentTarget).parents(".item").attr("data-item-id"),
item = this.actor.getOwnedItem(itemId);
item.roll();
item.roll(event);
}

/* -------------------------------------------- */
Expand Down
6 changes: 6 additions & 0 deletions scripts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -845,3 +845,9 @@ CONFIG.languages = {
"terran": "Terran",
"undercommon": "Undercommon"
};

CONFIG.spellScalingModes = {
"none": "None",
"cantrip": "Cantrip",
"level": "Heightened +1"
}
15 changes: 12 additions & 3 deletions scripts/item/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ class ItemPF2e extends Item {
* Roll the item to Chat, creating a chat card which contains follow up attack or damage roll options
* @return {Promise}
*/
async roll() {
async roll(event) {

// Basic template rendering data
const template = `systems/pf2e/templates/chat/${this.data.type}-card.html`
const token = this.actor.token;
const nearestItem = event.currentTarget.closest(".item")
const templateData = {
actor: this.actor,
tokenId: token ? `${token.scene._id}.${token._id}` : null,
item: this.data,
data: this.getChatData()
data: this.getChatData(),
contextualItemData: nearestItem.dataset
};

// Basic chat message data
Expand Down Expand Up @@ -604,14 +606,18 @@ class ItemPF2e extends Item {
rollSpellDamage(event) {
if ( this.type !== "spell" ) throw "Wrong item type!";

const button = event.currentTarget,
card = button.closest('*[data-spell-lvl]');

// Get data
let itemData = this.data.data,
spellcastingEntry = this.actor.getOwnedItem(itemData.location.value),
rollData = duplicate(this.actor.data.data),
abl = spellcastingEntry.data.data.ability.value || "int",
parts = [itemData.damage.value],
isHeal = itemData.spellType.value === "heal",
dtype = CONFIG.damageTypes[itemData.damageType.value];
dtype = CONFIG.damageTypes[itemData.damageType.value],
spellLvl = parseInt(card.dataset.spellLvl);

// Append damage type to title
let title = this.name + (isHeal ? " - Healing" : " - Damage");
Expand All @@ -622,6 +628,9 @@ class ItemPF2e extends Item {
rollData.item = itemData;

if (itemData.damage.applyMod) parts.push(rollData.abilities[abl].mod);
if (itemData.scaling.mode === "level" && itemData.scaling.formula !== "" && itemData.level.value < spellLvl) {
parts.push(`(${spellLvl - itemData.level.value})*(${itemData.scaling.formula})`)
}

// Call the roll helper utility
DicePF2e.damageRoll({
Expand Down
5 changes: 3 additions & 2 deletions scripts/item/sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class ItemSheetPF2e extends ItemSheet {
//spellBasic: CONFIG.spellBasic,
spellComponents: this._formatSpellComponents(data.data),
areaSizes: CONFIG.areaSizes,
areaTypes: CONFIG.areaTypes
areaTypes: CONFIG.areaTypes,
spellScalingModes: CONFIG.spellScalingModes
});
}

Expand Down Expand Up @@ -231,4 +232,4 @@ Hooks.on('renderChatLog', (log, html, data) => ItemPF2e.chatListeners(html));

// Register Item Sheet
Items.unregisterSheet("core", ItemSheet);
Items.registerSheet("pf2e", ItemSheetPF2e, {makeDefault: true});
Items.registerSheet("pf2e", ItemSheetPF2e, {makeDefault: true});
8 changes: 7 additions & 1 deletion template.json
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,12 @@
"type": "String",
"label": "Damage Type"
},
"scaling": {
"type": "String",
"label": "Scaling",
"mode": null,
"formula": null
},
"save": {
"type": "String",
"label": "Saving Throw",
Expand Down Expand Up @@ -1138,4 +1144,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion templates/chat/spell-card.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="pf2e chat-card item-card" data-actor-id="{{actor._id}}" data-item-id="{{item._id}}" {{#if tokenId}}data-token-id="{{tokenId}}"{{/if}}>
<div class="pf2e chat-card item-card" data-spell-lvl="{{contextualItemData.spellLvl}}" data-actor-id="{{actor._id}}" data-item-id="{{item._id}}" {{#if tokenId}}data-token-id="{{tokenId}}"{{/if}}>
<header class="card-header flexrow">
<img src="{{item.img}}" title="{{item.name}}" width="36" height="36"/>
<h3>{{item.name}}</h3>
Expand Down
14 changes: 13 additions & 1 deletion templates/items/spell-details.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@
</select>
</div>

<div class="form-group">
<label>{{data.scaling.label}}</label>
<select name="data.scaling.mode">
{{#select data.scaling.mode}}
{{#each spellScalingModes as |name key|}}
<option value="{{key}}">{{name}}</option>
{{/each}}
{{/select}}
</select>
<input type="text" name="data.scaling.formula" value="{{data.scaling.formula}}" placeholder="Scaling Formula"/>
</div>

<div class="form-group">
<label>{{data.save.label}}</label>
<div class="details-container-two-columns">
Expand Down Expand Up @@ -193,4 +205,4 @@
<span class="tag {{k}}">{{v}}</span>
{{/each}}
</ul>
</div>
</div>

0 comments on commit f0ed876

Please sign in to comment.