Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-lock-initiative
Browse files Browse the repository at this point in the history
  • Loading branch information
aMediocreDad authored Aug 21, 2023
2 parents f2d7038 + 246f6c9 commit 5994b64
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:

# Publishes the release to the FoundryVTT's package repository.
- name: 🚩 Publish Module to FoundryVTT Website
uses: Varriount/[email protected].0
uses: Varriount/[email protected].1
with:
username: ${{ secrets.FOUNDRY_ADMIN_USERNAME }}
password: ${{ secrets.FOUNDRY_ADMIN_PASSWORD }}
Expand Down
30 changes: 28 additions & 2 deletions src/combat/combat.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ export default class YearZeroCombat extends Combat {
for (const combatant of this.combatants) {
const speed = combatant.getSpeedFromActor();
if (speed > 1) {
const duplicatas = getCombatantsSharingToken(combatant);
const copyQty = speed - duplicatas.length;
const duplicates = getCombatantsSharingToken(combatant);
const copyQty = speed - duplicates.length;
if (copyQty > 0) await duplicateCombatant(combatant, copyQty);
}
}
Expand Down Expand Up @@ -403,4 +403,30 @@ export default class YearZeroCombat extends Combat {
await this.rollInitiative(ids, { newRound: true });
}
}

/* ------------------------------------------ */
/* Static Methods */
/* ------------------------------------------ */

/**
* Handles createCombatant hook called when a new combatant is added to the Combat instance.
* @param {Combat} combat
* @param {Combatant} combatant
* @returns {Promise.<Combatant>}
* @static
* @async
*/
static async createCombatant(combatant) {
if (!game.user.isGM) return;

// This handles cases where a combatant is added after combat started,
// and said combatant has a speed > 1.
const { parent: { started } } = combatant;
const speed = combatant.getSpeedFromActor();
if (started && speed > 1) {
const duplicates = getCombatantsSharingToken(combatant);
const copyQty = speed - duplicates.length;
if (copyQty > 0) await duplicateCombatant(combatant, copyQty);
}
}
}
2 changes: 2 additions & 0 deletions src/yze-combat.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,5 @@ Hooks.on('getCombatTrackerEntryContext', YearZeroCombatTracker.appendControlsToC

// Injects custom HTML in the combatant config.
Hooks.on('renderCombatantConfig', onRenderCombatantConfig);

Hooks.on('createCombatant', YearZeroCombat.createCombatant);

0 comments on commit 5994b64

Please sign in to comment.