Skip to content

Commit

Permalink
Publish 3.0.94
Browse files Browse the repository at this point in the history
  • Loading branch information
aeauseth committed Sep 8, 2024
1 parent bdd4703 commit 7fb72b2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 136 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Releases

## Version 3.0.93 [Hero System 6e (Unofficial) v2](https://github.com/dmdorman/hero6e-foundryvtt)
## Version 3.0.94 [Hero System 6e (Unofficial) v2](https://github.com/dmdorman/hero6e-foundryvtt)
- Fix for Combat Tracker

## Version 3.0.93

- Fixed HKA calculation when Double Damage Limit rule is enabled.
- Fix for DRAINs and likely other adjustment powers. [#1188](https://github.com/dmdorman/hero6e-foundryvtt/issues/1188)
Expand All @@ -15,7 +18,7 @@
- Fixed DC calculations with advantaged powers to not included reduced endurance advantages. [#1210](https://github.com/dmdorman/hero6e-foundryvtt/issues/1210)
- Knocked Out actors take x2 STUN. [#1205](https://github.com/dmdorman/hero6e-foundryvtt/issues/1205)

## Version 3.0.92 [Hero System 6e (Unofficial) v2](https://github.com/dmdorman/hero6e-foundryvtt)
## Version 3.0.92

- Fixed FLASH to use the flash defense of the target and not the attacker. [#1174](https://github.com/dmdorman/hero6e-foundryvtt/issues/1174)
- Fixed TELEKINESIS damage. [#1177](https://github.com/dmdorman/hero6e-foundryvtt/issues/1177)
Expand Down
145 changes: 25 additions & 120 deletions module/combat.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,7 @@ export class HeroSystem6eCombat extends Combat {

async rollInitiative(ids) {
// Only run this once regardless of how many GM's
// Only run this once regardless of how many GM's
if (!game.users.activeGM?.isSelf) {
// Setup new turns with now deleted combatant
this.setupTurns();

// Find turn that matches current combatant
this.setMyTurn(this.combatant, null); //this.turn = this.turns.findIndex((o) => o.id === (oldCombatant.id || nextCombatant.id));

if (this.active) await this.collection.render();
return this;
}
if (game.users.find((o) => o.active && o.isGM).id !== game.user.id) return;

// Structure input data
ids = typeof ids === "string" ? [ids] : ids;
Expand Down Expand Up @@ -180,15 +170,6 @@ export class HeroSystem6eCombat extends Combat {
initiative: initiativeValue,
"-flags.lightningReflexesAlias": null,
});

// Remove holding
if (tokenCombatants[idx].actor.statuses.has("holding")) {
const holding = tokenCombatants[idx].actor.effects.contents.find((o) =>
o.statuses.has("holding"),
);
await holding.delete();
console.info(`Removed holding status: ${tokenCombatants[idx].actor.name}`);
}
} catch (ex) {
console.error(ex);
return;
Expand Down Expand Up @@ -325,20 +306,8 @@ export class HeroSystem6eCombat extends Combat {

/** @inheritdoc */
async _onCreateDescendantDocuments(parent, collection, documents, data, options, userId) {
// Get current combatant
const oldCombatant = this.combatant;

// Only run this once regardless of how many GM's
if (!game.users.activeGM?.isSelf) {
// Setup new turns with now deleted combatant
this.setupTurns();

// Find turn that matches current combatant
this.setMyTurn(oldCombatant, null); //this.turn = this.turns.findIndex((o) => o.id === (oldCombatant.id || nextCombatant.id));

if (this.active) await this.collection.render();
return;
}
if (game.users.find((o) => o.active && o.isGM).id !== game.user.id) return;

if (CONFIG.debug.combat) {
console.debug(`Hero | _onCreateDescendantDocuments`, this);
Expand All @@ -357,6 +326,9 @@ export class HeroSystem6eCombat extends Combat {
// documents = documents.filter((o) => o.actor);
// if (documents.length === 0) return;

// Get current combatant
const oldCombatant = this.combatant;

// Super
await super._onCreateDescendantDocuments(parent, collection, documents, data, options, userId);

Expand All @@ -378,38 +350,23 @@ export class HeroSystem6eCombat extends Combat {
//if (this.active) this.collection.render();
}

setMyTurn(oldCombatant, nextCombatant) {
this.turn = this.turns.findIndex((o) => o.id === (oldCombatant.id || nextCombatant.id));
}

/* -------------------------------------------- */

/** @inheritdoc */
async _onDeleteDescendantDocuments(parent, collection, documents, ids, options, userId) {
// Get current (active) combatant
const oldCombatant = this.combatants.find((o) => o.id === options.oldCombatant?._id) || this.combatant;
const nextCombatant =
this.combatants.find((o) => o.id === options.nextCombatant?._id) ||
this.turns[this.turn + 1 > this.turns.length ? 0 : this.turn + 1];

// Only run this once regardless of how many GM's
if (!game.users.activeGM?.isSelf) {
// Setup new turns with now deleted combatant
this.setupTurns();

// Find turn that matches current combatant
this.setMyTurn(oldCombatant, nextCombatant); //this.turn = this.turns.findIndex((o) => o.id === (oldCombatant.id || nextCombatant.id));

if (this.active) await this.collection.render();
return;
}
if (game.users.find((o) => o.active && o.isGM).id !== game.user.id) return;

if (CONFIG.debug.combat) {
console.debug(`Hero | _onDeleteDescendantDocuments`, this);
}

// Update the heroTurn order and adjust the combat to keep the combatant the same (unless they were deleted)

// Get current (active) combatant
const oldCombatant = this.combatant;
const nextCombatant = this.turns[this.turn + 1 > this.turns.length ? 0 : this.turn + 1];

// Super
await super._onDeleteDescendantDocuments(parent, collection, documents, ids, options, userId);

Expand All @@ -423,7 +380,6 @@ export class HeroSystem6eCombat extends Combat {
await this.deleteEmbeddedDocuments(
"Combatant",
toDelete.map((c) => c.id),
{ oldCombatant, nextCombatant },
);
}
}
Expand Down Expand Up @@ -478,19 +434,7 @@ export class HeroSystem6eCombat extends Combat {
userId,
) {
// Only run this once regardless of how many GM's
//if (!game.users.activeGM?.isSelf) {
// Setup new turns with now deleted combatant
//this.setupTurns();

// const nextCombatant =
// this.combatants.find((o) => o.id === options.nextCombatant?._id) ||
// this.turns[this.turn + 1 > this.turns.length ? 0 : this.turn + 1];

//this.setMyTurn(this.combatant, nextCombatant); //this.turn = this.turns.findIndex((o) => o.id === (oldCombatant.id || nextCombatant.id));

// if (this.active) await this.collection.render();
// return;
// }
if (game.users.find((o) => o.active && o.isGM).id !== game.user.id) return;

if (CONFIG.debug.combat) {
console.debug(`Hero | _onUpdateDescendantDocuments`, this);
Expand All @@ -512,37 +456,22 @@ export class HeroSystem6eCombat extends Combat {
const priorState = foundry.utils.deepClone(this.current);
const combatant = this.combatant;
this.setupTurns();

this.#recordPreviousState(priorState);

// Find turn that matches current segment, not necessarily the same combatant (but maybe)
//const combatant = documents?.[0];
// console.log(
// combatant.name,
// this.turns.find((o) => o.flags.segment >= combatant.flags.segment && o.initiative <= combatant.initiative)
// .name,
// );
// const sameTurn = this.turns.findIndex(
// (o) => o.flags.segment >= combatant.flags.segment && o.initiative >= combatant.initiative,
// );

this.setMyTurn(combatant);

// When token (turns) are added or deleted this.turns likely points to the wrong turn.
// Adjust turn order to keep the current Combatant the same (SEGMENT is important for HeroSystem)
// let sameTurn = this.turns.findIndex(
// (t) =>
// t.id === combatant?.id &&
// t.flags.segment === combatant?.flags.segment &&
// t.initiative === combatant?.initiative,
// );
// if (sameTurn < 0) sameTurn = this.turn;
let sameTurn = this.turns.findIndex(
(t) =>
t.id === combatant?.id &&
t.flags.segment === combatant?.flags.segment &&
t.initiative === combatant?.initiative,
);
if (sameTurn < 0) sameTurn = this.turn;

// const adjustedTurn = sameTurn !== this.turn ? sameTurn : undefined;
// if (options.turnEvents !== false && adjustedTurn) {
// this._manageTurnEvents(adjustedTurn);
// console.log("adjustedTurn", adjustedTurn);
// }
const adjustedTurn = sameTurn !== this.turn ? sameTurn : undefined;
if (options.turnEvents !== false && adjustedTurn) {
this._manageTurnEvents(adjustedTurn);
}

// Render the Collection
if (this.active && options.render !== false) {
Expand All @@ -567,20 +496,7 @@ export class HeroSystem6eCombat extends Combat {

async _onActorDataUpdate(...args) {
// Only run this once regardless of how many GM's
if (!game.users.activeGM?.isSelf) {
// Setup new turns with now deleted combatant
this.setupTurns();

const nextCombatant = this.combatants.find(
(o) => o.id === this.turns[this.turn + 1 > this.turns.length ? 0 : this.turn + 1],
);

// Find turn that matches current combatant
this.setMyTurn(this.combatant, nextCombatant); //this.turn = this.turns.findIndex((o) => o.id === (oldCombatant.id || nextCombatant.id));

if (this.active) await this.collection.render();
return;
}
if (game.users.find((o) => o.active && o.isGM).id !== game.user.id) return;

if (CONFIG.debug.combat) {
console.debug(`Hero | _onActorDataUpdate`, this);
Expand Down Expand Up @@ -615,12 +531,6 @@ export class HeroSystem6eCombat extends Combat {
await dragRuler.resetMovementHistory(this, combatant.id);
}

if (combatant.actor.statuses.has("holding")) {
const holding = combatant.actor.effects.contents.find((o) => o.statuses.has("holding"));
await holding.delete();
ui.notifications.info(`Removed holding status: ${combatant.actor.name}`);
}

// STUNNING
// The character remains Stunned and can take no
// Actions (not even Aborting to a defensive action) until their next
Expand Down Expand Up @@ -942,9 +852,7 @@ export class HeroSystem6eCombat extends Combat {
* @returns {Promise<Combat>}
*/
async previousRound() {
if (CONFIG.debug.combat) {
console.debug(`Hero | previousRound`);
}
//console.log("previousRound");
let turn = this.round === 0 ? 0 : Math.max(this.turns.length - 1, 0);
if (this.turn === null) turn = null;
let round = Math.max(this.round - 1, 0);
Expand Down Expand Up @@ -1028,7 +936,7 @@ export class HeroSystem6eCombat extends Combat {

Hooks.callAll("combatTurn", this, updateData, updateOptions);
let x = await this.update(updateData, updateOptions);
//console.log(x);
console.log(x);
return x;
}

Expand All @@ -1037,9 +945,6 @@ export class HeroSystem6eCombat extends Combat {
* @returns {Promise<Combat>}
*/
async nextRound() {
if (CONFIG.debug.combat) {
console.debug(`Hero | nextRound`);
}
let turn = this.turn === null ? null : 0; // Preserve the fact that it's no-one's turn currently.
if (this.settings.skipDefeated && turn !== null) {
turn = this.turns.findIndex((t) => !t.isDefeated);
Expand Down
15 changes: 2 additions & 13 deletions module/combatTracker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ export class HeroSystem6eCombatTracker extends CombatTracker {

// Looks like super.getData returns a minimal combatant, need to add flags.
// Handle segments while were at it (as it is stored in flags.segment)
if (context.combat.combatant && !context.combat.combatant.flags.segment) {
console.error("Combatant segment is not defined");
}
let activeSegment = context.combat.combatant?.flags.segment || 12;
let activeSegment = 12;
for (let t = 0; t < context.turns.length; t++) {
const turn = context.turns[t];
turn.flags = context.combat.combatants.find((c) => c.id === turn.id)?.flags;
Expand All @@ -65,23 +62,15 @@ export class HeroSystem6eCombatTracker extends CombatTracker {

// Active Segment
if (turn.active) {
activeSegment = turn.flags?.segment || 0;
if (!activeSegment) {
console.error("Unable to determine Active Segment");
}
activeSegment = turn.flags.segment;
}

// Alpha testing debugging
if (context.alphaTesting) {
turn.name += ` [${t}]`;
}

if (turn.effects.has("icons/svg/clockwork.svg")) {
turn.css = "holding";
}
}
context.segments[activeSegment].active = true;
context.combat.segment = activeSegment;

// for (const combatant of context.combat.turns) {
// if (!combatant.visible) continue;
Expand Down
2 changes: 1 addition & 1 deletion system.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "hero6e-foundryvtt-v2",
"title": "Hero System 6e (Unofficial) v2",
"description": "The Hero System 6e for FoundryVTT!",
"version": "3.0.93",
"version": "3.0.94",
"compatibility": {
"minimum": "11",
"verified": "12.331",
Expand Down

0 comments on commit 7fb72b2

Please sign in to comment.