Skip to content

Commit

Permalink
Merge pull request dmdorman#759 from phBalance/phBalance/dc-fixes
Browse files Browse the repository at this point in the history
Add support for 1d6-1 damage adder
  • Loading branch information
phBalance authored Feb 24, 2024
2 parents 13be71b + f118c54 commit e45d066
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 184 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Implement basic automatic absorption.
- Fix combat tracker where changing combatant SPD caused issues. Initiative is now DEX.SPD instead of DEX.INT. [#736](https://github.com/dmdorman/hero6e-foundryvtt/issues/736)
- Adjustment powers now prefer characteristics over powers with the same name. [#747](https://github.com/dmdorman/hero6e-foundryvtt/issues/747)
- Add support for the 1d6-1 damage adder.

## Version 3.0.58

Expand Down
3 changes: 2 additions & 1 deletion module/actor/actor-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,14 @@ export class HeroSystemActorSheet extends ActorSheet {
);

// text description of damage
item.system.damage = convertFromDC(item, dc).replace(/ /g, "");
item.system.damage = convertFromDC(item, dc);

// Standard Effect
if (item.system.USESTANDARDEFFECT) {
let stun = parseInt(item.system.value * 3);
if (
item.findModsByXmlid("PLUSONEHALFDIE") ||
item.findModsByXmlid("MINUSONEPIP") ||
item.findModsByXmlid("PLUSONEPIP")
) {
stun += 1;
Expand Down
3 changes: 2 additions & 1 deletion module/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ HERO.bool = {
HERO.extraDice = {
zero: "+0",
pip: "+1",
half: "+1/2D6",
half: "+½D6",
"one-pip": "+1D6-1",
};

HERO.attacksWith = {
Expand Down
9 changes: 5 additions & 4 deletions module/item/item-attack.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
calculateDiceFormulaParts,
CombatSkillLevelsForAttack,
convertToDcFromItem,
determineExtraDiceDamage,
} from "../utility/damage.js";
import {
performAdjustment,
Expand Down Expand Up @@ -1046,6 +1045,7 @@ export async function _onRollDamage(event) {
)
.addDice(formulaParts.d6Count)
.addHalfDice(formulaParts.halfDieCount)
.addDiceMinus1(formulaParts.d6Less1DieCount)
.addNumber(formulaParts.constant)
.modifyToStandardEffect(useStandardEffect)
.modifyToNoBody(
Expand Down Expand Up @@ -1766,14 +1766,15 @@ async function _performAbsorptionForToken(
let maxAbsorption;
if (actor.system.is5e) {
const dice = absorptionItem.system.dice;
const extraDice = determineExtraDiceDamage(absorptionItem);
const extraDice = absorptionItem.system.extraDice;

// Absorption allowed based on a roll with the usual requirements
const absorptionRoller = new HeroRoller()
.makeAdjustmentRoll()
.addDice(dice)
.addHalfDice(extraDice === "+1d3" ? 1 : 0)
.addNumber(extraDice === "+1" ? 1 : 0);
.addHalfDice(extraDice === "half" ? 1 : 0)
.addDiceMinus1(extraDice === "one-pip" ? 1 : 0)
.addNumber(extraDice === "pip" ? 1 : 0);
await absorptionRoller.roll();
maxAbsorption = absorptionRoller.getAdjustmentTotal();

Expand Down
60 changes: 30 additions & 30 deletions module/item/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -1867,11 +1867,11 @@ export class HeroSystem6eItem extends Item {

case "MINDSCAN":
{
const dice = convertFromDC(
const diceFormula = convertFromDC(
this,
convertToDcFromItem(this).dc,
).replace("d6 + 1d3", " 1/2d6");
system.description = `${dice} ${system.ALIAS}`;
);
system.description = `${diceFormula} ${system.ALIAS}`;
}
break;

Expand Down Expand Up @@ -1926,13 +1926,13 @@ export class HeroSystem6eItem extends Item {
{
const reduceAndEnhanceTargets =
this.splitAdjustmentSourceAndTarget();
const dice = convertFromDC(
const diceFormula = convertFromDC(
this,
convertToDcFromItem(this).dc,
).replace("d6 + 1d3", " 1/2d6");
);

system.description = `${system.ALIAS} ${
is5e ? `${dice}` : `${system.value} BODY`
is5e ? `${diceFormula}` : `${system.value} BODY`
} (${system.OPTION_ALIAS}) to ${
reduceAndEnhanceTargets.valid
? reduceAndEnhanceTargets.enhances ||
Expand All @@ -1950,30 +1950,30 @@ export class HeroSystem6eItem extends Item {
{
const reduceAndEnhanceTargets =
this.splitAdjustmentSourceAndTarget();
const dice = convertFromDC(
const diceFormula = convertFromDC(
this,
convertToDcFromItem(this).dc,
).replace("d6 + 1d3", " 1/2d6");
);

system.description = `${system.ALIAS} ${
reduceAndEnhanceTargets.valid
? reduceAndEnhanceTargets.enhances ||
reduceAndEnhanceTargets.reduces
: "unknown"
} ${dice}`;
} ${diceFormula}`;
}
break;

case "TRANSFER":
{
const reduceAndEnhanceTargets =
this.splitAdjustmentSourceAndTarget();
const dice = convertFromDC(
const diceFormula = convertFromDC(
this,
convertToDcFromItem(this).dc,
).replace("d6 + 1d3", " 1/2d6");
);

system.description = `${system.ALIAS} ${dice} from ${
system.description = `${system.ALIAS} ${diceFormula} from ${
reduceAndEnhanceTargets.valid
? reduceAndEnhanceTargets.reduces
: "unknown"
Expand Down Expand Up @@ -2121,11 +2121,11 @@ export class HeroSystem6eItem extends Item {
case "MINDCONTROL":
case "HANDTOHANDATTACK":
{
const dice = convertFromDC(
const diceFormula = convertFromDC(
this,
convertToDcFromItem(this).dc,
).replace("d6 + 1d3", " 1/2d6");
system.description = `${system.ALIAS} ${dice}`;
);
system.description = `${system.ALIAS} ${diceFormula}`;
}
break;

Expand Down Expand Up @@ -2180,8 +2180,8 @@ export class HeroSystem6eItem extends Item {
if (system.EFFECT) {
let dc = convertToDcFromItem(this).dc;
if (dc) {
let damageDice = convertFromDC(this, dc);
if (damageDice) {
const damageDiceFormula = convertFromDC(this, dc);
if (damageDiceFormula) {
system.description += `,`;

if (
Expand All @@ -2192,11 +2192,8 @@ export class HeroSystem6eItem extends Item {
}
system.description += ` ${system.EFFECT.replace(
"[NORMALDC]",
damageDice,
).replace(
"[KILLINGDC]",
damageDice.replace("+ 1", "+1"),
)}`;
damageDiceFormula,
).replace("[KILLINGDC]", damageDiceFormula)}`;
}
} else {
system.description += ", " + system.EFFECT;
Expand Down Expand Up @@ -2286,7 +2283,7 @@ export class HeroSystem6eItem extends Item {
}

// singles
let _singles = [];
const _singles = [];
for (let addr of (system.ADDER || []).filter(
(o) =>
o.XMLID.indexOf("GROUP") === -1 &&
Expand All @@ -2304,11 +2301,11 @@ export class HeroSystem6eItem extends Item {
system.description += " and " + _singles.slice(-1);
}

const dice = convertFromDC(
const diceFormula = convertFromDC(
this,
convertToDcFromItem(this).dc,
).replace("d6 + 1d3", " 1/2d6");
system.description += ` ${system.ALIAS} ${dice}`;
);
system.description += ` ${system.ALIAS} ${diceFormula}`;
}
break;

Expand Down Expand Up @@ -2478,8 +2475,10 @@ export class HeroSystem6eItem extends Item {
}
break;

case "PLUSONEPIP":
case "MINUSONEPIP":
case "PLUSONEHALFDIE":
//system.description = system.description.replace(/d6$/, " ") + adder.ALIAS.replace("+", "").replace(" ", "");
// Don't show the +1, 1/2d6, 1d6-1 modifier as it's already included in the description's dice formula
break;

case "COMMONMOTORIZED":
Expand Down Expand Up @@ -2593,6 +2592,7 @@ export class HeroSystem6eItem extends Item {

if (
this.findModsByXmlid("PLUSONEHALFDIE") ||
this.findModsByXmlid("MINUSONEPIP") ||
this.findModsByXmlid("PLUSONEPIP")
) {
stun += 1;
Expand Down Expand Up @@ -3184,16 +3184,16 @@ export class HeroSystem6eItem extends Item {
}

if (this.findModsByXmlid("MINUSONEPIP")) {
// Typically only allowed for killing attacks.
// Appears that +1d6-1 is roughly equal to +1/2 d6
this.system.extraDice = "half";
// +1d6-1 is equal to +1/2 d6 DC-wise but is uncommon.
this.system.extraDice = "one-pip";
}

const aoeModifier = this.getAoeModifier();
if (aoeModifier) {
this.buildAoeAttackParameters(aoeModifier);
}

// TODO: Investigate why this is required. It is wrong for 1/2d6 vs d6-1.
if (xmlid === "HKA" || this.system.EFFECT?.indexOf("KILLING") > -1) {
this.system.killing = true;

Expand Down
21 changes: 21 additions & 0 deletions module/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ export async function migrateWorld() {

// if lastMigration < 3.0.59
// Active Effects for adjustments changed format
// d6-1 and 1/2d6 are now distinctly different extra dice
if (foundry.utils.isNewerVersion("3.0.59", lastMigration)) {
const queue = getAllActorsInGame();
let dateNow = new Date();
Expand All @@ -370,6 +371,7 @@ export async function migrateWorld() {
}

await migrate_actor_active_effects_to_3_0_59(actor);
await migrate_actor_items_to_3_0_59(actor);
}
}

Expand Down Expand Up @@ -432,6 +434,25 @@ async function migrateActorCostDescription(actor) {
}
}

// 1/2 d6 and 1d6-1 are not the same roll but are the same DC - make them distinct
async function migrate_actor_items_to_3_0_59(actor) {
for (const item of actor.items) {
let newValue;
if (item.findModsByXmlid("PLUSONEHALFDIE")) {
newValue = "half";
} else if (item.findModsByXmlid("MINUSONEPIP")) {
// +1d6-1 is equal to +1/2 d6 DC-wise but is uncommon.
newValue = "one-pip";
}

if (item.system.extraDice && newValue) {
await item.update({
"system.extraDice": newValue,
});
}
}
}

async function migrate_actor_active_effects_to_3_0_59(actor) {
for (const activeEffect of actor.temporaryEffects) {
if (
Expand Down
Loading

0 comments on commit e45d066

Please sign in to comment.