Skip to content

Commit

Permalink
[#2463] Add configuration for whether to default to true/false for li…
Browse files Browse the repository at this point in the history
…mited uses and templates in AbilityUseDialog (#2492)

Co-authored-by: Zhell <zhellqol@gmail.com>
  • Loading branch information
krbz999 and Zhell committed Oct 19, 2023
1 parent b75c657 commit 286e9ff
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
3 changes: 3 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@
"DND5E.ItemCritExtraDamage": "Extra Critical Hit Damage",
"DND5E.ItemDelete": "Delete Item",
"DND5E.ItemDestroyEmpty": "Destroy on Empty",
"DND5E.ItemDestroyEmptyTooltip": "If this item has limited uses, it will be destroyed when none are left.",
"DND5E.ItemEdit": "Edit Item",
"DND5E.ItemEquipmentAction": "Equipment Action",
"DND5E.ItemEquipmentBase": "Base Equipment",
Expand Down Expand Up @@ -792,6 +793,7 @@
"DND5E.LimitedUsesMax": "Maximum Uses",
"DND5E.LimitedUsesPer": "Use Recovery Mode",
"DND5E.LimitedUsesPrompt": "Uses Prompt",
"DND5E.LimitedUsesPromptTooltip": "If unchecked, the prompt to consume an available use will be suppressed.",
"DND5E.Long": "Long",
"DND5E.LongRest": "Long Rest",
"DND5E.LongRestNormal": "Long Rest (8 hours)",
Expand Down Expand Up @@ -1095,6 +1097,7 @@
"DND5E.TargetWidth": "Line Width",
"DND5E.TargetWilling": "Willing Creature",
"DND5E.TemplatePrompt": "Template Prompt",
"DND5E.TemplatePromptTooltip": "If unchecked, the prompt for placing a Measured Template will be suppressed.",
"DND5E.Temp": "Temp",
"DND5E.Threshold": "Threshold",
"DND5E.TimeDay": "Days",
Expand Down
6 changes: 4 additions & 2 deletions module/data/item/templates/activated-effect.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export default class ActivatedEffectTemplate extends SystemDataModel {
value: new foundry.data.fields.NumberField({required: true, min: 0, label: "DND5E.TargetValue"}),
width: new foundry.data.fields.NumberField({required: true, min: 0, label: "DND5E.TargetWidth"}),
units: new foundry.data.fields.StringField({required: true, blank: true, label: "DND5E.TargetUnits"}),
type: new foundry.data.fields.StringField({required: true, blank: true, label: "DND5E.TargetType"})
type: new foundry.data.fields.StringField({required: true, blank: true, label: "DND5E.TargetType"}),
prompt: new foundry.data.fields.BooleanField({initial: true, label: "DND5E.TemplatePrompt"})
}, {label: "DND5E.Target"}),
range: new foundry.data.fields.SchemaField({
value: new foundry.data.fields.NumberField({required: true, min: 0, label: "DND5E.RangeNormal"}),
Expand Down Expand Up @@ -86,7 +87,8 @@ export default class ActivatedEffectTemplate extends SystemDataModel {
per: new foundry.data.fields.StringField({
required: true, nullable: true, blank: false, initial: null, label: "DND5E.LimitedUsesPer"
}),
recovery: new FormulaField({required: true, label: "DND5E.RecoveryFormula"})
recovery: new FormulaField({required: true, label: "DND5E.RecoveryFormula"}),
prompt: new foundry.data.fields.BooleanField({initial: true, label: "DND5E.LimitedUsesPrompt"})
}, extraSchema), options);
}
};
Expand Down
9 changes: 4 additions & 5 deletions module/documents/item.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -935,8 +935,7 @@ export default class Item5e extends Item {
* @returns {ItemUseConfiguration} Configuration data for the roll.
*/
_getUsageConfig() {
const { consume, activation, uses, target, level, preparation } = this.system;
const active = !!activation?.type;
const { consume, uses, target, level, preparation } = this.system;

const config = {
consumeSpellSlot: null,
Expand All @@ -950,13 +949,13 @@ export default class Item5e extends Item {
config.consumeSpellSlot = true;
config.slotLevel = preparation?.mode === "pact" ? "pact" : `spell${level}`;
}
if ( active && this.hasLimitedUses ) config.consumeUsage = true;
if ( active && !!consume?.type && !!consume?.target && (!this.hasAttack || (consume.type !== "ammo")) ) {
if ( this.hasLimitedUses ) config.consumeUsage = uses.prompt;
if ( this.hasResource ) {
config.consumeResource = true;
// Do not suggest consuming your own uses if also consuming them through resources.
if ( consume.target === this.id ) config.consumeUsage = null;
}
if ( active && game.user.can("TEMPLATE_CREATE") && this.hasAreaTarget ) config.createMeasuredTemplate = true;
if ( game.user.can("TEMPLATE_CREATE") && this.hasAreaTarget ) config.createMeasuredTemplate = target.prompt;

return config;
}
Expand Down
7 changes: 0 additions & 7 deletions templates/items/consumable.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,6 @@

{{!-- Item Activation Template --}}
{{> "dnd5e.item-activation"}}
{{#if system.activation.type}}
<div class="form-group">
<label class="checkbox">
<input type="checkbox" name="system.uses.autoDestroy" {{checked system.uses.autoDestroy}}> {{ localize "DND5E.ItemDestroyEmpty" }}
</label>
</div>
{{/if}}

<h3 class="form-header">{{ localize "DND5E.ItemConsumableActivation" }}</h3>

Expand Down
19 changes: 19 additions & 0 deletions templates/items/parts/item-activation.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,23 @@
</select>
</div>
</div>

{{!-- Prompt Configuration --}}
<div class="form-group">
{{#if (eq item.type "consumable")}}
<label class="checkbox" data-tooltip="DND5E.ItemDestroyEmptyTooltip">
<input type="checkbox" name="system.uses.autoDestroy" {{checked system.uses.autoDestroy}}> {{ localize "DND5E.ItemDestroyEmpty" }}
</label>
{{/if}}
{{#if item.hasAreaTarget}}
<label class="checkbox" data-tooltip="DND5E.TemplatePromptTooltip">
<input type="checkbox" name="system.target.prompt" {{checked system.target.prompt}}> {{ localize "DND5E.TemplatePrompt" }}
</label>
{{/if}}
{{#if system.uses.per}}
<label class="checkbox" data-tooltip="DND5E.LimitedUsesPromptTooltip">
<input type="checkbox" name="system.uses.prompt" {{checked system.uses.prompt}}> {{ localize "DND5E.LimitedUsesPrompt" }}
</label>
{{/if}}
</div>
{{/if}}

0 comments on commit 286e9ff

Please sign in to comment.