Skip to content

Commit 84aaa0b

Browse files
authored
Merge pull request #71 from asacolips-projects/feature/asacolips/token-improvements
Add support for Token Initiative variant
2 parents cb73ecb + c3ff9b8 commit 84aaa0b

5 files changed

Lines changed: 62 additions & 7 deletions

File tree

src/lang/en.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ GRIMWILD:
2828
slowXp:
2929
name: "Slow XP"
3030
hint: Enable to use half-rate XP where it takes two pips per XP checkbox to be filled.
31+
tokenActions:
32+
name: "[Variant] Token Initiative"
33+
hint: Enable the variant <strong>Token Initiative</strong> rule that gives each players 2 tokens per "round" of combat/scenes. Otherwise, a simple action counter will be used to count how many actions have been taken.
3134
Stat:
3235
bra:
3336
long: Brawn
@@ -248,6 +251,7 @@ GRIMWILD:
248251
ActionCount: 'Rolls'
249252
ResetActionCount: Reset Action Count
250253
SpotlightActor: Spotlight
254+
TokenActions: 'Actions'
251255
TYPES:
252256
Actor:
253257
character: Character

src/module/data/actor-character.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,20 @@ export default class GrimwildCharacter extends GrimwildActorBase {
128128
})
129129
);
130130

131+
schema.tokenActions = new fields.SchemaField({
132+
value: new fields.NumberField({
133+
...requiredInteger,
134+
max: 2,
135+
initial: 2,
136+
min: 0
137+
}),
138+
max: new fields.NumberField({
139+
...requiredInteger,
140+
initial: 2,
141+
min: 0
142+
})
143+
});
144+
131145
return schema;
132146
}
133147

@@ -354,6 +368,9 @@ export default class GrimwildCharacter extends GrimwildActorBase {
354368
const actionCount = Number(combatant.flags?.grimwild?.actionCount ?? 0);
355369
await combatant.setFlag("grimwild", "actionCount", actionCount + 1);
356370

371+
const actor = combatant.actor;
372+
await actor.update({"system.tokenActions.value": Math.max(actor.system.tokenActions.value - 1, 0)});
373+
357374
// Update the active turn.
358375
const combatantTurn = combat.turns.findIndex((c) => c.id === combatant.id);
359376
if (combatantTurn !== undefined) {

src/module/documents/combat.mjs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,15 @@ export class GrimwildCombat extends foundry.documents.Combat {
4040

4141
/** @inheritdoc */
4242
async _onStartRound(context) {
43+
if (game.settings.get("grimwild", "tokenActions")) {
44+
this.resetActions();
45+
}
4346
}
4447

4548
resetActions() {
4649
for (let combatant of this.combatants) {
4750
combatant.setFlag("grimwild", "actionCount", 0);
51+
combatant.actor.update({"system.tokenActions.value": 2});
4852
}
4953
}
5054

@@ -111,6 +115,9 @@ export class GrimwildCombatTracker extends foundry.applications.sidebar.tabs.Com
111115
}
112116
}
113117

118+
context.tokenActions = game.settings.get("grimwild", "tokenActions");
119+
context.enableHarmPools = game.settings.get("grimwild", "enableHarmPools");
120+
114121
if (!turns.character.length) delete turns.character;
115122
if (!turns.monster.length) delete turns.monster;
116123
if (!turns.other.length) delete turns.other;
@@ -131,7 +138,9 @@ export class GrimwildCombatTracker extends foundry.applications.sidebar.tabs.Com
131138
turn.spark = combatant.actor.system.spark;
132139
turn.bloodied = combatant.actor.system.bloodied;
133140
turn.rattled = combatant.actor.system.rattled;
134-
turn.actionCount = combatant.flags?.grimwild?.actionCount ?? 0;
141+
turn.actionCount = game.settings.get("grimwild", "tokenActions")
142+
? combatant.actor.system.tokenActions.value ?? 0
143+
: combatant.flags?.grimwild?.actionCount ?? 0;
135144
}
136145

137146
return turn;
@@ -173,7 +182,13 @@ export class GrimwildCombatTracker extends foundry.applications.sidebar.tabs.Com
173182
name: "GRIMWILD.Combat.ResetActionCount",
174183
icon: '<i class="fa-solid fa-arrow-rotate-left"></i>',
175184
condition: (li) => game.user.isGM,
176-
callback: (li) => getCombatant(li)?.setFlag("grimwild", "actionCount", 0)
185+
callback: (li) => {
186+
const combatant = getCombatant(li);
187+
if (combatant) {
188+
combatant?.setFlag("grimwild", "actionCount", 0)
189+
combatant?.actor.update({"system.tokenActions.value": 2});
190+
}
191+
}
177192
}, {
178193
name: "COMBAT.CombatantRemove",
179194
icon: '<i class="fa-solid fa-trash"></i>',
@@ -200,11 +215,16 @@ export class GrimwildCombatTracker extends foundry.applications.sidebar.tabs.Com
200215
const { combatantId } = event.target.closest(".combatant[data-combatant-id]")?.dataset ?? {};
201216
const { harm } = target.dataset ?? false;
202217
const combatant = this.viewed.combatants.get(combatantId);
218+
const update = {};
203219
if (!combatant || !harm) return;
204220
const actor = combatant.actor;
205221
if (!actor.isOwner) return;
206-
const harmValue = actor.system?.[harm].marked;
207-
actor.update({ [`system.${harm}.marked`]: !harmValue });
222+
let harmValue = actor.system?.[harm].marked;
223+
update[`system.${harm}.marked`] = !harmValue;
224+
if (game.settings.get("grimwild", "enableHarmPools")) {
225+
update[`system.${harm}.pool.diceNum`] = actor.system?.[harm].pool.diceNum > 0 ? 0 : 1;
226+
}
227+
actor.update(update);
208228
}
209229

210230
static #onToggleSpark(...args) {

src/module/grimwild.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ Hooks.once("init", function () {
146146
requiresReload: true
147147
});
148148

149+
game.settings.register("grimwild", "tokenActions", {
150+
name: game.i18n.localize("GRIMWILD.Settings.tokenActions.name"),
151+
hint: game.i18n.localize("GRIMWILD.Settings.tokenActions.hint"),
152+
scope: "world",
153+
config: true,
154+
type: Boolean,
155+
default: false,
156+
requiresReload: true
157+
});
158+
149159
// Override 3d dice.
150160
if (game.modules.get("dice-so-nice")) {
151161
game.settings.register("grimwild", "diceSoNiceOverride", {

src/templates/combat/tracker.hbs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
<div class="combatant combatant-header">
66
<div class="token-image"></div>
77
<div class="token-name">{{localize "Name"}}</div>
8-
<div class="token-initiative">{{localize "GRIMWILD.Combat.ActionCount"}}</div>
8+
{{#if @root.tokenActions}}
9+
<div class="token-initiative">{{localize "GRIMWILD.Combat.TokenActions"}}</div>
10+
{{else}}
11+
<div class="token-initiative">{{localize "GRIMWILD.Combat.ActionCount"}}</div>
12+
{{/if}}
913
</div>
1014
{{/if}}
1115
{{#each turnsOfType}}
@@ -47,8 +51,8 @@
4751
{{#if (eq type "character")}}
4852
<div class="token-resources">
4953
<span class="resource resource-spark" data-action="toggleSpark" data-tooltip="{{localize 'GRIMWILD.Actor.Character.FIELDS.spark.label'}}"><i class="fas fa-bolt"></i>{{spark.value}}</span>
50-
<span class="resource resource-bloodied {{#if bloodied.marked}}active{{/if}}" data-action="toggleHarm" data-harm="bloodied" data-tooltip="{{localize 'GRIMWILD.Damage.bloodied'}}"><i class="fas fa-droplet"></i></span>
51-
<span class="resource resource-rattled {{#if rattled.marked}}active{{/if}}" data-action="toggleHarm" data-harm="rattled" data-tooltip="{{localize 'GRIMWILD.Damage.rattled'}}"><i class="fas fa-brain"></i></span>
54+
<span class="resource resource-bloodied {{#if bloodied.marked}}active{{/if}}" data-action="toggleHarm" data-harm="bloodied" data-tooltip="{{localize 'GRIMWILD.Damage.bloodied'}}"><i class="fas fa-droplet"></i>{{#if @root.enableHarmPools}}{{bloodied.pool.diceNum}}{{/if}}</span>
55+
<span class="resource resource-rattled {{#if rattled.marked}}active{{/if}}" data-action="toggleHarm" data-harm="rattled" data-tooltip="{{localize 'GRIMWILD.Damage.rattled'}}"><i class="fas fa-brain"></i>{{#if @root.enableHarmPools}}{{rattled.pool.diceNum}}{{/if}}</span>
5256
</div>
5357
{{/if}}
5458
</div>

0 commit comments

Comments
 (0)