Skip to content

Commit

Permalink
Reject prompts of several properties when an item has no activation t…
Browse files Browse the repository at this point in the history
…ype (#2317)

Co-authored-by: Zhell <zhellqol@gmail.com>
  • Loading branch information
krbz999 and Zhell committed Oct 19, 2023
1 parent ee225a1 commit 9596c7c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 14 deletions.
6 changes: 3 additions & 3 deletions module/applications/actor/character-sheet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ export default class ActorSheet5eCharacter extends ActorSheet5e {
ctx.isExpanded = this._expanded.has(item.id);

// Item usage
ctx.hasUses = uses && (uses.max > 0);
ctx.hasUses = item.hasLimitedUses;
ctx.isOnCooldown = recharge && !!recharge.value && (recharge.charged === false);
ctx.isDepleted = ctx.isOnCooldown && (uses.per && (uses.value > 0));
ctx.hasTarget = !!target && !(["none", ""].includes(target.type));
ctx.isDepleted = ctx.isOnCooldown && ctx.hasUses && (uses.value > 0);
ctx.hasTarget = item.hasAreaTarget || item.hasIndividualTarget;

// Item toggle state
this._prepareItemToggleState(item, ctx);
Expand Down
2 changes: 1 addition & 1 deletion module/data/item/feat.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default class FeatData extends SystemDataModel.mixin(

/** @inheritdoc */
get hasLimitedUses() {
return !!this.recharge.value || super.hasLimitedUses;
return this.isActive && (!!this.recharge.value || super.hasLimitedUses);
}

/* -------------------------------------------- */
Expand Down
25 changes: 21 additions & 4 deletions module/data/item/templates/activated-effect.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,20 @@ export default class ActivatedEffectTemplate extends SystemDataModel {

/* -------------------------------------------- */

/**
* Is this Item an activatable item?
* @type {boolean}
*/
get isActive() {
return !!this.activation.type;
}

/**
* Does the Item have an area of effect target?
* @type {boolean}
*/
get hasAreaTarget() {
return this.target.type in CONFIG.DND5E.areaTargetTypes;
return this.isActive && (this.target.type in CONFIG.DND5E.areaTargetTypes);
}

/* -------------------------------------------- */
Expand All @@ -225,7 +233,7 @@ export default class ActivatedEffectTemplate extends SystemDataModel {
* @type {boolean}
*/
get hasIndividualTarget() {
return this.target.type in CONFIG.DND5E.individualTargetTypes;
return this.isActive && (this.target.type in CONFIG.DND5E.individualTargetTypes);
}

/* -------------------------------------------- */
Expand All @@ -235,7 +243,16 @@ export default class ActivatedEffectTemplate extends SystemDataModel {
* @type {boolean}
*/
get hasLimitedUses() {
return !!this.uses.per && (this.uses.max > 0);
return this.isActive && (this.uses.per in CONFIG.DND5E.limitedUsePeriods) && (this.uses.max > 0);
}

/**
* Does this Item draw from a resource?
* @type {boolean}
*/
get hasResource() {
const consume = this.consume;
return this.isActive && !!consume.target && !!consume.type && (!this.hasAttack || (consume.type !== "ammo"));
}

/* -------------------------------------------- */
Expand Down Expand Up @@ -275,7 +292,7 @@ export default class ActivatedEffectTemplate extends SystemDataModel {
* @type {boolean}
*/
get hasTarget() {
return !["", null].includes(this.target.type);
return this.isActive && !["", null].includes(this.target.type);
}

}
28 changes: 24 additions & 4 deletions module/documents/item.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ export default class Item5e extends Item {
/* Item Properties */
/* -------------------------------------------- */

/**
* Is this Item an activatable item?
* @type {boolean}
*/
get isActive() {
return this.system.isActive ?? false;
}

/**
* Which ability score modifier is used by this item?
* @type {string|null}
Expand Down Expand Up @@ -117,6 +125,15 @@ export default class Item5e extends Item {
return this.system.hasLimitedUses ?? false;
}

/**
* Does this Item draw from a resource?
* @type {boolean}
* @see {@link ActivatedEffectTemplate#hasResource}
*/
get hasResource() {
return this.system.hasResource ?? false;
}

/* -------------------------------------------- */

/**
Expand Down Expand Up @@ -421,15 +438,18 @@ export default class Item5e extends Item {
if ( ["none", ""].includes(tgt.type) ) tgt.type = null; // Backwards compatibility
if ( [null, "self"].includes(tgt.type) ) tgt.value = tgt.units = null;
else if ( tgt.units === "touch" ) tgt.value = null;
this.labels.target = tgt.type
? [tgt.value, C.distanceUnits[tgt.units], C.targetTypes[tgt.type]].filterJoin(" ") : "";

if ( this.hasTarget ) {
this.labels.target = [tgt.value, C.distanceUnits[tgt.units], C.targetTypes[tgt.type]].filterJoin(" ");
}

// Range Label
let rng = this.system.range ?? {};
if ( ["none", ""].includes(rng.units) ) rng.units = null; // Backwards compatibility
if ( [null, "touch", "self"].includes(rng.units) ) rng.value = rng.long = null;
this.labels.range = rng.units
? [rng.value, rng.long ? `/ ${rng.long}` : null, C.distanceUnits[rng.units]].filterJoin(" ") : "";
if ( this.isActive && rng.units ) {
this.labels.range = [rng.value, rng.long ? `/ ${rng.long}` : null, C.distanceUnits[rng.units]].filterJoin(" ");
} else this.labels.range = game.i18n.localize("DND5E.None");

// Recharge Label
let chg = this.system.recharge ?? {};
Expand Down
6 changes: 4 additions & 2 deletions templates/actors/parts/actor-spellbook.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@
<div class="item-name flexrow rollable">
<div class="item-image" tabindex="0" role="button" aria-label="{{item.name}}" style="background-image: url('{{item.img}}')"></div>
<h4>{{item.name}}</h4>
{{#if item.system.uses.per }}
<div class="item-detail spell-uses">Uses {{item.system.uses.value}} / {{item.system.uses.max}}</div>
{{#if item.hasLimitedUses}}
<div class="item-detail spell-uses">
{{localize "DND5E.Uses"}} {{#if item.system.uses.value}}{{item.system.uses.value}}{{else}}0{{/if}} / {{item.system.uses.max}}
</div>
{{/if}}
<div class="spell-comps">
{{#each item.labels.components.all}}
Expand Down

0 comments on commit 9596c7c

Please sign in to comment.