Skip to content

Commit

Permalink
feat: Add option to automatically move combatant that hits 0 hp outsi…
Browse files Browse the repository at this point in the history
…de of it's turn to just before the current combatant's turn.
  • Loading branch information
xdy committed Dec 27, 2021
1 parent cbd5a73 commit 50c73ce
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/module/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ export function registerSettings() {
type: Boolean,
});

settings.register(MODULENAME, "enableAutomaticMoveBeforeCurrentCombatantOnReaching0HP", {
name: "SETTINGS.enableAutomaticMoveBeforeCurrentCombatantOnReaching0HP.name",
hint: "SETTINGS.enableAutomaticMoveBeforeCurrentCombatantOnReaching0HP.hint",
scope: "world",
config: true,
default: false,
type: Boolean,
});

//Mystification below this
settings.register(MODULENAME, "npcMystifier", {
name: "SETTINGS.npcMystifier.name",
Expand Down
15 changes: 15 additions & 0 deletions src/module/xdy-pf2e-workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,18 @@ Hooks.on("updateCombat", () => {
(game as Game).pf2e.effectTracker.removeExpired();
}
});

Hooks.on("preUpdateActor", async (actor: Actor, update: Record<string, string>) => {
if ((game as Game).settings.get(MODULENAME, "enableAutomaticMoveBeforeCurrentCombatantOnReaching0HP")) {
const combatant = <Combatant>(game as Game)?.combat?.getCombatantByToken(<string>actor.token?.id);
if (
combatant &&
combatant !== (game as Game).combat?.combatant &&
// @ts-ignore
actor.data.data.attributes.hp.value > 0 &&
getProperty(update, "data.attributes.hp.value") <= 0
) {
await moveSelectedAheadOfCurrent(combatant);
}
}
});
8 changes: 6 additions & 2 deletions static/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
"name": "Purge all expired effects each turn.",
"hint": "Purge all expired effects each turn in combat."
},
"enableAutomaticMoveBeforeCurrentCombatantOnReaching0HP": {
"name": "Enable automatically moving combatant that goes unconscious outside it's own turn to just before the current combatant.",
"hint": "Enable automatically moving combatant that goes unconscious outside it's own turn to just before the current combatant."
},
"enableMoveBeforeCurrentCombatant": {
"name": "Enable moving selected combatant before the current combatant.",
"hint": "Enable moving selected combatant to before the current combatant, normally because the current combatant has killed the selected combatant. Due to rounding several combatants may show the same initiative in the list."
"name": "Enable manually moving selected combatant before the current combatant.",
"hint": "Enable manually moving selected combatant to before the current combatant, normally because the current combatant has killed the selected combatant. Due to rounding several combatants may show the same initiative in the list."
},
"moveBeforeCurrentCombatantContextMenu": {
"name": "Move selected combatant before the current combatant."
Expand Down
8 changes: 6 additions & 2 deletions static/lang/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
"name": "Ta bort alla utgångna effekter varje runda.",
"hint": "Ta bort alla utgångna effekter varje runda i strid."
},
"enableAutomaticMoveBeforeCurrentCombatantOnReaching0HP": {
"name": "Aktivera automatiskt flytt av stridande som blir medvetslös utanför sin egen tur till strax före nuvarande stridande.",
"hint": "Aktivera automatiskt flytt av stridande som blir medvetslös utanför sin egen tur till strax före nuvarande stridande."
},
"enableMoveBeforeCurrentCombatant": {
"name": "Möjliggör att vald stridande flyttas före den nuvarande kombattanten.",
"hint": "Möjliggör att flytta utvald stridande till före den nuvarande kombattanten, normalt eftersom nuvarande stridande har dödat vald stridande."
"name": "Möjliggör att vald stridande flyttas före nuvarande stridande.",
"hint": "Möjliggör att flytta utvald stridande till före nuvarande stridande, normalt eftersom nuvarande stridande har dödat vald stridande."
},
"moveBeforeCurrentCombatantContextMenu": {
"name": "Flytta vald stridande före nuvarande stridande."
Expand Down

0 comments on commit 50c73ce

Please sign in to comment.