Skip to content

Commit

Permalink
Fix bug with spell upcasting and limited sheet scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
aaclayton committed Aug 15, 2020
1 parent 3bcd6a9 commit 97a81b3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
31 changes: 21 additions & 10 deletions module/actor/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,11 @@ export default class Actor5e extends Actor {
/** @override */
async update(data, options={}) {

// TODO: 0.7.1 compatibility - remove when stable
if ( !data.hasOwnProperty("data") ) data = expandObject(data);

// Apply changes in Actor size to Token width/height
const newSize = data["data.traits.size"];
const newSize = getProperty(data, "data.traits.size");
if ( newSize && (newSize !== getProperty(this.data, "data.traits.size")) ) {
let size = CONFIG.DND5E.tokenSizes[newSize];
if ( this.isToken ) this.token.update({height: size, width: size});
Expand All @@ -474,6 +477,14 @@ export default class Actor5e extends Actor {
data["token.width"] = size;
}
}

// Reset death save counters
if ( (this.data.data.attributes.hp.value <= 0) && (getProperty(data, "data.attributes.hp.value") > 0) ) {
setProperty(data, "data.attributes.death.success", 0);
setProperty(data, "data.attributes.death.failure", 0);
}

// Perform the update
return super.update(data, options);
}

Expand Down Expand Up @@ -570,16 +581,16 @@ export default class Actor5e extends Actor {
consumeUse = Boolean(usage.get("consumeUse"));
placeTemplate = Boolean(usage.get("placeTemplate"));

// Spell slot consumption and up-casting
if ( consumeSlot ) {
const isPact = usage.get('level') === 'pact';
const lvl = isPact ? this.data.data.spells.pact.level : parseInt(usage.get("level"));
if ( lvl !== item.data.data.level ) {
const upcastData = mergeObject(item.data, {"data.level": lvl}, {inplace: false});
item = item.constructor.createOwned(upcastData, this);
}
consumeSlot = isPact ? "pact" : `spell${lvl}`;
// Determine the cast spell level
const isPact = usage.get('level') === 'pact';
const lvl = isPact ? this.data.data.spells.pact.level : parseInt(usage.get("level"));
if ( lvl !== item.data.data.level ) {
const upcastData = mergeObject(item.data, {"data.level": lvl}, {inplace: false});
item = item.constructor.createOwned(upcastData, this);
}

// Denote the spell slot being consumed
if ( consumeSlot ) consumeSlot = isPact ? "pact" : `spell${lvl}`;
}

// Update Actor data
Expand Down
2 changes: 1 addition & 1 deletion templates/actors/limited-sheet.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form class="{{cssClass}} limited" autocomplete="off">
<form class="{{cssClass}} flexcol limited" autocomplete="off">

{{!-- Sheet Header --}}
<header class="sheet-header flexrow">
Expand Down

0 comments on commit 97a81b3

Please sign in to comment.