Skip to content

Commit

Permalink
Prefer shields for parry button (optionally, via settings) (#34)
Browse files Browse the repository at this point in the history
Closes #31
  • Loading branch information
rayners authored Jun 2, 2024
1 parent cd301bb commit 8dc9c1b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"includeUnpreparedSpellsHint": "Include unprepared spells in spell list",
"groupSpellsByRank": "Group spells by rank",
"groupSpellsByRankHint": "",
"preferShieldParry": "Prefer shield for parry button",
"preferShieldParryHint": "Weight the automatic selection of parry item in favor of shields (via weapon features). Otherwise, sort on total of skill plus durability.",
"skillNameHealing": "Skill for First Aid button",
"skillNamePersuasion": "Skill for Rally button",
"skillNameEvade": "Skill for Dodge button"
Expand Down
18 changes: 12 additions & 6 deletions src/ts/dragonbane-defense-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ class DragonbaneEvadeButton extends ARGON.MAIN.BUTTONS.ActionButton {
}
}

function parrySortValue(item: DragonbaneItem): number {
return (
item.system.skill.value +
item.system.durability +
(game.settings.get(MODULE_NAME, "preferShieldParry") &&
item.hasWeaponFeature("shield")
? 25
: 0)
);
}

class DragonbaneParryButton extends ARGON.MAIN.BUTTONS.ActionButton {
_parryWeapon: DragonbaneItem;

Expand All @@ -55,12 +66,7 @@ class DragonbaneParryButton extends ARGON.MAIN.BUTTONS.ActionButton {
this._parryWeapon = this.actor
.getEquippedWeapons()
.filter((w) => !w.hasWeaponFeature("noparry"))
.sort(
(a, b) =>
b.system.skill.value +
b.system.durability -
(a.system.skill.value + a.system.durability),
)[0];
.sort((a, b) => parrySortValue(b) - parrySortValue(a))[0];
}

get classes() {
Expand Down
8 changes: 8 additions & 0 deletions src/ts/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ export function registerSettings(): void {
type: Boolean,
default: true,
});

game.settings.register(MODULE_NAME, "preferShieldParry", {
name: `${MODULE_NAME}.settings.preferShieldParry`,
hint: `${MODULE_NAME}.settings.preferShieldParryHint`,
config: true,
type: Boolean,
default: true,
});
}

export function registerSkillSettings(): void {
Expand Down

0 comments on commit 8dc9c1b

Please sign in to comment.