Skip to content

Commit

Permalink
Merge pull request dmdorman#1432 from phBalance/phBalance/automaton-c…
Browse files Browse the repository at this point in the history
…onfig-improvements

Automaton config improvements
  • Loading branch information
phBalance authored Nov 11, 2024
2 parents 0a5311d + 9730c78 commit 1bcf188
Show file tree
Hide file tree
Showing 9 changed files with 708 additions and 281 deletions.
3 changes: 2 additions & 1 deletion gulpfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function validateJavaScriptFilesByLint() {
function validateScssFilesByLint() {
return gulp.src(SASS_FILES).pipe(
gulpStylelint({
failAfterError: false,
failAfterError: true,
reporters: [{ formatter: "string", console: true }],
}),
);
Expand All @@ -50,6 +50,7 @@ function autoFixScssFilesByLint() {
return gulp.src(SASS_FILES).pipe(
gulpStylelint({
fix: true,
failAfterError: true,
reporters: [{ formatter: "string", console: true }],
}),
);
Expand Down
17 changes: 12 additions & 5 deletions module/actor/actor-sheet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ export class HeroSystemActorSheet extends ActorSheet {
const characteristicSet = [];

const powers = getCharacteristicInfoArrayForActor(this.actor);
const isAutomatonWithNoStun = !!this.actor.items.find(
(power) =>
power.system.XMLID === "AUTOMATON" &&
(power.system.OPTION === "NOSTUN1" || power.system.OPTION === "NOSTUN2"),
);

for (const powerInfo of powers) {
const characteristic = {
Expand All @@ -150,21 +155,22 @@ export class HeroSystemActorSheet extends ActorSheet {
}${getSystemDisplayUnits(data.actor.is5e)}`;
}

if (powerInfo.key === "LEAPING")
if (powerInfo.key === "LEAPING") {
characteristic.notes = `${Math.max(0, characteristic.value)}${getSystemDisplayUnits(
data.actor.system.is5e,
)} forward, ${Math.max(0, Math.round(characteristic.value / 2))}${getSystemDisplayUnits(
data.actor.system.is5e,
)} upward`;
}

characteristic.delta = 0;
if (data.actor.system.is5e) {
if (powerInfo.key.toLowerCase() === "pd") {
characteristic.notes = "5e figured STR/5";
characteristic.notes = `5e figured STR/5${isAutomatonWithNoStun ? " and /3 again" : ""}`;
}

if (powerInfo.key.toLowerCase() === "ed") {
characteristic.notes = "5e figured CON/5";
characteristic.notes = `5e figured CON/5${isAutomatonWithNoStun ? " and /3 again" : ""}`;
}

if (powerInfo.key.toLowerCase() === "spd") {
Expand Down Expand Up @@ -491,8 +497,9 @@ export class HeroSystemActorSheet extends ActorSheet {

if (dc > 0) {
let costPerDice =
Math.max(Math.floor((item.system.activePoints || 0) / dc) || item.baseInfo.costPerLevel) ||
(item.system.targets === "dcv" ? 5 : 10);
Math.max(
Math.floor((item.system.activePoints || 0) / dc) || item.baseInfo.costPerLevel(item),
) || (item.system.targets === "dcv" ? 5 : 10);
dc += csl.dc + Math.floor((csl.ocv + csl.dcv) / 2); // Assume CSL are converted to DCs
let ap = dc * costPerDice;

Expand Down
54 changes: 31 additions & 23 deletions module/actor/actor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getPowerInfo, getCharacteristicInfoArrayForActor, whisperUserTargetsFor
import { HeroProgressBar } from "../utility/progress-bar.mjs";
import { clamp } from "../utility/compatibility.mjs";
import { overrideCanAct } from "../settings/settings-helpers.mjs";
import { RoundFavorPlayerUp } from "../utility/round.mjs";

/**
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
Expand Down Expand Up @@ -1066,12 +1067,18 @@ export class HeroSystem6eActor extends Actor {

// Raw base is insufficient for 5e characters
getCharacteristicBase(key) {
let powerInfo = getPowerInfo({ xmlid: key.toUpperCase(), actor: this });

let base = parseInt(powerInfo?.base) || 0;
const powerInfo = getPowerInfo({ xmlid: key.toUpperCase(), actor: this });
const base = parseInt(powerInfo?.base) || 0;

if (!this.system.is5e) return base;

// TODO: Can this be combined with getCharacteristicInfoArrayForActor? See also actor-sheet.mjs changes
const isAutomatonWithNoStun = !!this.items.find(
(power) =>
power.system.XMLID === "AUTOMATON" &&
(power.system.OPTION === "NOSTUN1" || power.system.OPTION === "NOSTUN2"),
);

const _str = this.appliedEffects
.filter(
(o) =>
Expand Down Expand Up @@ -1154,13 +1161,17 @@ export class HeroSystem6eActor extends Actor {
};

switch (key.toLowerCase()) {
// Physical Defense (PD) STR/5
// Physical Defense (PD) STR/5, STR/5 and an extra /3 if the right type of automaton
case "pd":
return base + Math.round((charBase("STR") + _str) / 5);
return RoundFavorPlayerUp(
base + Math.round((charBase("STR") + _str) / 5) / (isAutomatonWithNoStun ? 3 : 1),
);

// Energy Defense (ED) CON/5
// Energy Defense (ED) CON/5, CON/5 and /3 if the right type of automaton
case "ed":
return base + Math.round((charBase("CON") + _con) / 5);
return RoundFavorPlayerUp(
base + Math.round((charBase("CON") + _con) / 5) / (isAutomatonWithNoStun ? 3 : 1),
);

// Speed (SPD) 1 + (DEX/10) can be fractional
case "spd":
Expand Down Expand Up @@ -1242,24 +1253,21 @@ export class HeroSystem6eActor extends Actor {

const base = this.getCharacteristicBase(key);
const levels = core - base;
let cost = Math.round(levels * (powerInfo.costPerLevel || 0));
let cost = Math.round(levels * (powerInfo.costPerLevel(this) || 0));

// 5e hack for fractional speed
if (key === "spd" && cost < 0) {
cost = Math.ceil(cost / 10);
}

if (characteristic.realCost != cost) {
if (characteristic.realCost !== cost) {
changes[`system.characteristics.${key}.realCost`] = cost;
this.system.characteristics[key].realCost = cost;
}
if (characteristic.core != core) {
if (characteristic.core !== core) {
changes[`system.characteristics.${key}.core`] = core;
this.system.characteristics[key].core = core;
}
// changes[`system.characteristics.${key}.basePointsPlusAdders`] = cost
// changes[`system.characteristics.${key}.realCost`] = cost
// changes[`system.characteristics.${key}.activePoints`] = cost
}
if (Object.keys(changes).length > 0 && this.id) {
await this.update(changes);
Expand Down Expand Up @@ -1423,7 +1431,7 @@ export class HeroSystem6eActor extends Actor {
// A few critical items.
this.system.CHARACTER = heroJson.CHARACTER;
this.system.versionHeroSystem6eUpload = game.system.version;
changes[`system.versionHeroSystem6eUpload`] = game.system.version;
changes["system.versionHeroSystem6eUpload"] = game.system.version;

// CHARACTERISTICS
if (heroJson.CHARACTER?.CHARACTERISTICS) {
Expand Down Expand Up @@ -2008,26 +2016,26 @@ export class HeroSystem6eActor extends Actor {
let changed = false;

// is5e
if (typeof this.system.CHARACTER?.TEMPLATE == "string") {
if (typeof this.system.CHARACTER?.TEMPLATE === "string") {
if (
this.system.CHARACTER.TEMPLATE.includes("builtIn.") &&
!this.system.CHARACTER.TEMPLATE.includes("6E.") &&
!this.system.is5e
) {
changes[`system.is5e`] = true;
changes["system.is5e"] = true;
this.system.is5e = true;
}
if (
this.system.CHARACTER.TEMPLATE.includes("builtIn.") &&
this.system.CHARACTER.TEMPLATE.includes("6E.") &&
this.system.is5e === undefined
) {
changes[`system.is5e`] = false;
changes["system.is5e"] = false;
this.system.is5e = false;
}
}
if (this.system.COM && !this.system.is5e) {
changes[`system.is5e`] = true;
changes["system.is5e"] = true;
this.system.is5e = true;
}

Expand All @@ -2053,8 +2061,8 @@ export class HeroSystem6eActor extends Actor {
} else if (JSON.stringify(this.system.CHARACTER?.TEMPLATE)?.match(/\.Superheroic/i)) {
isHeroic = false;
}
if (isHeroic != this.system.isHeroic) {
changes[`system.isHeroic`] = isHeroic;
if (isHeroic !== this.system.isHeroic) {
changes["system.isHeroic"] = isHeroic;
}
if (typeof isHeroic === "undefined") {
// Custom Templates
Expand All @@ -2077,7 +2085,7 @@ export class HeroSystem6eActor extends Actor {
newValue = Math.floor(newValue);
}

if (this.system.characteristics[key].max != newValue) {
if (this.system.characteristics[key].max !== newValue) {
if (this.id) {
//changes[`system.characteristics.${key.toLowerCase()}.max`] = Math.floor(newValue)
await this.update({
Expand All @@ -2090,7 +2098,7 @@ export class HeroSystem6eActor extends Actor {
changed = true;
}
if (
this.system.characteristics[key].value != this.system.characteristics[key.toLowerCase()].max &&
this.system.characteristics[key].value !== this.system.characteristics[key.toLowerCase()].max &&
overrideValues
) {
if (this.id) {
Expand All @@ -2107,7 +2115,7 @@ export class HeroSystem6eActor extends Actor {
}
changed = true;
}
if (this.system.characteristics[key].core != newValue && overrideValues) {
if (this.system.characteristics[key].core !== newValue && overrideValues) {
changes[`system.characteristics.${key.toLowerCase()}.core`] = newValue;
this.system.characteristics[key.toLowerCase()].core = newValue;
changed = true;
Expand Down
Loading

0 comments on commit 1bcf188

Please sign in to comment.