Skip to content

Commit

Permalink
closes #517
Browse files Browse the repository at this point in the history
  • Loading branch information
Muttley committed Oct 10, 2023
1 parent 5b78eab commit eb07e80
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 9 deletions.
5 changes: 4 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* [#515] Backstab option not available on attack rolls
* [#516] Wand and Scroll item sheets not showing spell caster classes correctly

### Enhancements
* [#517] Add support for limited use Class Abilities, and Class Abilities with no associated rolls

## v.1.4.4

### Bugfixes
Expand Down Expand Up @@ -36,7 +39,7 @@
* [#493] Compendium item "Sword of the Ancients" missing base weapon type
* [#496] Mage Armor spell effect not being applied

### Enhancement
### Enhancements
* [#71] Add the ability to extend various character options
* [#374] Added ability to create custom Classes
* [#375] Added support for custom ancestries
Expand Down
6 changes: 6 additions & 0 deletions i18n/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,13 @@ SHADOWDARK.chat.welcome_message.title: Shadowdark RPG for Foundry
SHADOWDARK.chat.welcome_message.tour_button: Shadowdark RPG Tours
SHADOWDARK.chatcard.default: Roll
SHADOWDARK.class-ability.ability.label: Ability
SHADOWDARK.class-ability.available.label: Available
SHADOWDARK.class-ability.dc.label: DC
SHADOWDARK.class-ability.group.label: Ability Group
SHADOWDARK.class-ability.limited-uses.label: Limited Uses?
SHADOWDARK.class-ability.lose_on_failure.label: Lose on Failure?
SHADOWDARK.class-ability.lost.label: Lost
SHADOWDARK.class-ability.maximum.label: Maximum
SHADOWDARK.class.armor.all.label: All Armor
SHADOWDARK.class.armor.label: Armor
SHADOWDARK.class.armor.prompt: Select Armor...
Expand Down Expand Up @@ -225,6 +228,7 @@ SHADOWDARK.effect.tooltip.transfer.do_not: Does not transfer
SHADOWDARK.effect.tooltip.transfer.do: Does transfer
SHADOWDARK.effect.tooltip.transfer.header: Transfer effect to actor when item is added
SHADOWDARK.effect.unavailable: Disabled Effects
SHADOWDARK.error.class_ability.no-uses-remaining: No uses remaining
SHADOWDARK.error.general.gm_required: You must have the Game Master role to do that.
SHADOWDARK.error.general.no_character_class: No character class has been selected
SHADOWDARK.error.spells.no_spellcasting_ability_set: No character spellcasting ability has been configured
Expand Down Expand Up @@ -490,6 +494,8 @@ SHADOWDARK.settings.track_light_sources.realtime_tracking.hint: If checked the L
SHADOWDARK.settings.track_light_sources.realtime_tracking.name: Realtime Light Tracking
SHADOWDARK.sheet.abilities.label: Abilities
SHADOWDARK.sheet.abilities.ungrouped.label: Miscellaneous
SHADOWDARK.sheet.abilities.uses.decrement.tooltip: Decrease Available Uses
SHADOWDARK.sheet.abilities.uses.increment.tooltip: Increase Available Uses
SHADOWDARK.sheet.actor.ac: AC
SHADOWDARK.sheet.actor.alignment: Alignment
SHADOWDARK.sheet.actor.hp_max: Max
Expand Down
27 changes: 22 additions & 5 deletions system/src/documents/ActorSD.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -930,12 +930,29 @@ export default class ActorSD extends Actor {
async useAbility(itemId) {
const item = this.items.get(itemId);

const result = await this.rollAbility(
item.system.ability,
{target: item.system.dc}
);
let success = true;
if (item.system.ability !== "") {
const result = await this.rollAbility(
item.system.ability,
{target: item.system.dc}
);

const success = result?.rolls?.main?.success ?? false;
success = result?.rolls?.main?.success ?? false;
}
else if (item.system.limitedUses) {
if (item.system.uses.available > 0) {
item.update({
"system.uses.available": item.system.uses.available - 1,
});
}
else {
success = false;
ui.notifications.error(
game.i18n.format("SHADOWDARK.error.class_ability.no-uses-remaining"),
{permanent: false}
);
}
}

const messageType = success
? "SHADOWDARK.chat.use_ability.success"
Expand Down
40 changes: 40 additions & 0 deletions system/src/sheets/PlayerSheetSD.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ export default class PlayerSheetSD extends ActorSheetSD {
event => this._onItemChatClick(event)
);

html.find(".ability-uses-decrement").click(
event => this._onAbilityUsesDecrement(event)
);

html.find(".ability-uses-increment").click(
event => this._onAbilityUsesIncrement(event)
);

html.find(".item-quantity-decrement").click(
event => this._onItemQuantityDecrement(event)
);
Expand Down Expand Up @@ -427,6 +435,38 @@ export default class PlayerSheetSD extends ActorSheetSD {
super._onDropItemCreate(itemData);
}

async _onAbilityUsesDecrement(event) {
event.preventDefault();

const itemId = $(event.currentTarget).data("item-id");
const item = this.actor.getEmbeddedDocument("Item", itemId);

if (item.system.uses.available > 0) {
this.actor.updateEmbeddedDocuments("Item", [
{
_id: itemId,
"system.uses.available": item.system.uses.available - 1,
},
]);
}
}

async _onAbilityUsesIncrement(event) {
event.preventDefault();

const itemId = $(event.currentTarget).data("item-id");
const item = this.actor.getEmbeddedDocument("Item", itemId);

if (item.system.uses.available < item.system.uses.max) {
this.actor.updateEmbeddedDocuments("Item", [
{
_id: itemId,
"system.uses.available": item.system.uses.available + 1,
},
]);
}
}

async _onItemChatClick(event) {
event.preventDefault();
const itemId = $(event.currentTarget).data("item-id");
Expand Down
7 changes: 6 additions & 1 deletion system/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,13 @@
"ability": "",
"group": "",
"dc": 10,
"limitedUses": false,
"loseOnFailure": true,
"lost": false
"lost": false,
"uses": {
"available": 0,
"max": 0
}
},
"Deity": {
"templates": [
Expand Down
30 changes: 28 additions & 2 deletions system/templates/items/partials/class-ability.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,41 @@
placeholder="0"
}}
</div>
<div class="item-detail">
<div class="checkbox">
<label>{{localize "SHADOWDARK.class-ability.limited-uses.label"}}</label>
<input type="checkbox" name="system.limitedUses" {{checked item.system.limitedUses}}>
</div>
{{#if system.limitedUses}}
<div class="grid-2-columns">
<div class="item-detail">
<label>{{localize 'SHADOWDARK.class-ability.available.label'}}</label>
{{numberInput
item.system.uses.available
name="system.uses.available"
placeholder="0"
}}
</div>
<div class="item-detail">
<label>{{localize 'SHADOWDARK.class-ability.maximum.label'}}</label>
{{numberInput
item.system.uses.max
name="system.uses.max"
placeholder="0"
}}
</div>
</div>
{{/if}}
</div>
<div class="item-detail">
<div class="checkbox">
<label>{{localize "SHADOWDARK.class-ability.lose_on_failure.label"}}</label>
<input type="checkbox" name="system.loseOnFailure" {{checked system.loseOnFailure}}>
<input type="checkbox" name="system.loseOnFailure" {{checked item.system.loseOnFailure}}>
</div>
{{#if system.loseOnFailure}}
<div class="checkbox">
<label>{{localize "SHADOWDARK.class-ability.lost.label"}}</label>
<input type="checkbox" name="system.lost" {{checked system.lost}}>
<input type="checkbox" name="system.lost" {{checked item.system.lost}}>
</div>
{{/if}}
</div>
Expand Down

0 comments on commit eb07e80

Please sign in to comment.