Skip to content

Commit

Permalink
Make army strikes optional (#11850)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosFdez authored Nov 29, 2023
1 parent 0560855 commit bb212ab
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 76 deletions.
17 changes: 8 additions & 9 deletions src/module/actor/army/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import {
BaseActorSourcePF2e,
BaseHitPointsSource,
} from "@actor/data/base.ts";
import { ARMY_TYPES } from "./values.ts";
import { ActorSizePF2e } from "@actor/data/size.ts";
import { ValueAndMax, ValueAndMaybeMax } from "@module/data.ts";
import { Alignment } from "./types.ts";
import { ARMY_TYPES } from "./values.ts";

type ArmySource = BaseActorSourcePF2e<"army", ArmySystemSource>;

Expand All @@ -35,17 +35,16 @@ interface ArmySystemSource extends ActorSystemSource {
};

weapons: {
ranged: {
name: string;
potency: number;
};
melee: {
name: string;
potency: number;
};
ranged: ArmyWeaponData | null;
melee: ArmyWeaponData | null;
};
}

interface ArmyWeaponData {
name: string;
potency: number;
}

interface ArmyArmorClass {
value: number;
potency: number;
Expand Down
41 changes: 20 additions & 21 deletions src/module/actor/army/document.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { ItemSourcePF2e, ItemType } from "@item/base/data/index.ts";
import { TokenDocumentPF2e } from "@scene/index.ts";
import { ActorPF2e, HitPointsSummary } from "../base.ts";
import { ArmySource, ArmySystemData } from "./data.ts";
import { ArmorStatistic, Statistic, StatisticDifficultyClass } from "@system/statistic/index.ts";
import { ARMY_STATS, ARMY_TYPES } from "./values.ts";
import { signedInteger, tupleHasValue } from "@util";
import { Kingdom } from "@actor/party/kingdom/model.ts";
import { ModifierPF2e } from "@actor/modifiers.ts";
import * as R from "remeda";
import { ActorInitiative } from "@actor/initiative.ts";
import { ArmyStrike } from "./types.ts";
import { AttackRollParams, DamageRollParams } from "@system/rolls.ts";
import { eventToRollParams } from "@scripts/sheet-util.ts";
import { ModifierPF2e } from "@actor/modifiers.ts";
import { Kingdom } from "@actor/party/kingdom/model.ts";
import type { ItemSourcePF2e, ItemType } from "@item/base/data/index.ts";
import { extractModifierAdjustments } from "@module/rules/helpers.ts";
import type { TokenDocumentPF2e } from "@scene/index.ts";
import { eventToRollParams } from "@scripts/sheet-util.ts";
import { DamagePF2e } from "@system/damage/damage.ts";
import { DamageRollContext, SimpleDamageTemplate } from "@system/damage/types.ts";
import { DamageRoll } from "@system/damage/roll.ts";
import type { DamageRollContext, SimpleDamageTemplate } from "@system/damage/types.ts";
import type { AttackRollParams, DamageRollParams } from "@system/rolls.ts";
import { ArmorStatistic, Statistic, StatisticDifficultyClass } from "@system/statistic/index.ts";
import { signedInteger, tupleHasValue } from "@util";
import * as R from "remeda";
import { ActorPF2e, HitPointsSummary } from "../base.ts";
import type { ArmySource, ArmySystemData } from "./data.ts";
import type { ArmyStrike } from "./types.ts";
import { ARMY_STATS, ARMY_TYPES } from "./values.ts";

class ArmyPF2e<TParent extends TokenDocumentPF2e | null = TokenDocumentPF2e | null> extends ActorPF2e<TParent> {
declare armorClass: StatisticDifficultyClass<ArmorStatistic>;
declare scouting: Statistic;
declare maneuver: Statistic;
declare morale: Statistic;

declare strikes: Record<string, ArmyStrike>;
declare strikes: Record<string, ArmyStrike | null>;

override get allowedItemTypes(): (ItemType | "physical")[] {
return ["campaignFeature", "effect"];
Expand Down Expand Up @@ -133,16 +133,15 @@ class ArmyPF2e<TParent extends TokenDocumentPF2e | null = TokenDocumentPF2e | nu
}

this.initiative = new ActorInitiative(this, { statistic: "scouting" });

this.strikes = {
melee: this.prepareArmyStrike("melee"),
ranged: this.prepareArmyStrike("ranged"),
};
this.strikes = R.flatMapToObj(["melee", "ranged"] as const, (t) =>
this.system.weapons[t] ? [[t, this.prepareArmyStrike(t)]] : [],
);
}

prepareArmyStrike(type: "melee" | "ranged"): ArmyStrike {
prepareArmyStrike(type: "melee" | "ranged"): ArmyStrike | null {
const synthetics = this.synthetics;
const data = this.system.weapons[type];
if (data === null) return null;

const attackDomains = ["army-attack-roll"];

Expand Down
38 changes: 25 additions & 13 deletions src/module/actor/army/sheet.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ActorSheetPF2e } from "@actor/sheet/base.ts";
import { ArmyPF2e } from "./document.ts";
import { ActorSheetDataPF2e } from "@actor/sheet/data-types.ts";
import { Alignment } from "./types.ts";
import { ALIGNMENTS, ARMY_TYPES } from "./values.ts";
import { kingmakerTraits } from "@scripts/config/traits.ts";
import * as R from "remeda";
import { htmlClosest, htmlQuery, htmlQueryAll, objectHasKey, tupleHasValue } from "@util";
import { CampaignFeaturePF2e } from "@item";
import { AdjustedValue, getAdjustedValue, getAdjustment } from "@module/sheet/helpers.ts";
import { kingmakerTraits } from "@scripts/config/traits.ts";
import { eventToRollParams } from "@scripts/sheet-util.ts";
import { CampaignFeaturePF2e } from "@item";
import { htmlClosest, htmlQuery, htmlQueryAll, objectHasKey, tupleHasValue } from "@util";
import * as R from "remeda";
import { ArmyPF2e } from "./document.ts";
import { Alignment } from "./types.ts";
import { ALIGNMENTS, ARMY_TYPES } from "./values.ts";

class ArmySheetPF2e extends ActorSheetPF2e<ArmyPF2e> {
static override get defaultOptions(): ActorSheetOptions {
Expand Down Expand Up @@ -102,14 +102,26 @@ class ArmySheetPF2e extends ActorSheetPF2e<ArmyPF2e> {
for (const gearElement of htmlQueryAll(html, "[data-action=change-magic-weapon]")) {
const gear = gearElement.dataset.weapon;
if (!tupleHasValue(["melee", "ranged"], gear)) return;
const data = this.actor.system.weapons[gear];
gearElement.addEventListener("click", () => {
const newValue = Math.clamped(this.actor.system.weapons[gear].potency + 1, 0, 3);
this.actor.update({ [`system.weapons.${gear}.potency`]: newValue });
if (data) {
const newValue = Math.clamped(data.potency + 1, 0, 3);
this.actor.update({ [`system.weapons.${gear}.potency`]: newValue });
} else {
const newData = { name: "", potency: 0 };
this.actor.update({ [`system.weapons.${gear}`]: newData });
}
});
gearElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
const newValue = Math.clamped(this.actor.system.weapons[gear].potency - 1, 0, 3);
this.actor.update({ [`system.weapons.${gear}.potency`]: newValue });
if (!data) return;

if (data.potency === 0) {
this.actor.update({ [`system.weapons.${gear}`]: null });
} else {
const newValue = Math.clamped(data.potency - 1, 0, 3);
this.actor.update({ [`system.weapons.${gear}.potency`]: newValue });
}
});
}

Expand All @@ -123,7 +135,7 @@ class ArmySheetPF2e extends ActorSheetPF2e<ArmyPF2e> {
if (!objectHasKey(this.actor.strikes, type)) continue;

strikeAttack.addEventListener("click", (event) => {
this.actor.strikes[type].variants[variant]?.roll({ event });
this.actor.strikes[type]?.variants[variant]?.roll({ event });
});
}

Expand All @@ -133,7 +145,7 @@ class ArmySheetPF2e extends ActorSheetPF2e<ArmyPF2e> {
if (!objectHasKey(this.actor.strikes, type)) continue;

strikeDamage.addEventListener("click", (event) => {
this.actor.strikes[type][outcome]({ event });
this.actor.strikes[type]?.[outcome]({ event });
});
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/styles/actor/army/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ $color: rgb(68, 0, 0); // Was previously "rarity-common" but now that throws an
gap: 1rem;
overflow: hidden scroll;
padding: 0.5rem;
width: 10.5rem;
width: 11rem;

input[type="text"],
input[type="number"] {
Expand Down Expand Up @@ -362,18 +362,22 @@ $color: rgb(68, 0, 0); // Was previously "rarity-common" but now that throws an
padding: 0 0.25rem;
}

.pips {
.pips, .pips span {
align-items: center;
width: 3.5rem;
height: 24px;
display: flex;
flex-flow: row nowrap;
justify-content: center;
.empty {
i {
color: darkgrey;
}
.filled {
color: black;
}
.split + * {
margin-left: 0.25rem;
}
}

button {
Expand Down
9 changes: 0 additions & 9 deletions static/lang/kingmaker-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,6 @@
"recruitmentDC": "Recruitment DC",
"ammunition": "Ammunition",
"ammunitionMax": "Max Ammunition",
"Tooltip": {
"tooltipPotion" : "Potions Info",
"tooltipRanged" : "Ranged Weapons Info",
"tooltipMelee" : "Melee Weapons Info",
"tooltipArmour" : "Armour Info",
"levelLabel": "Level: ",
"priceLabel": "Price: ",
"resourceLabel": " RP"
},
"Potions": {
"label": "Potion(s)",
"drinkTooltip": "Use Potion (+1 HP)",
Expand Down
10 changes: 2 additions & 8 deletions static/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -479,14 +479,8 @@
"morale": 4
},
"weapons": {
"melee": {
"name": "Melee Strike",
"potency": 0
},
"ranged": {
"name": "Ranged Strike",
"potency": 0
}
"melee": null,
"ranged": null
}
}
},
Expand Down
37 changes: 24 additions & 13 deletions static/templates/actors/army/sheet.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@
<input type="number" class="{{hitPoints.routThreshold.adjustmentClass}}" data-property="system.attributes.hp.routThreshold" value="{{hitPoints.routThreshold.value}}" data-dtype="Number"/>
</label>
<div class="row">
{{#if (eq @root.data.attributes.hp.potions 0)}}
{{#if (eq @root.data.resources.potions.value 0)}}
<button data-tooltip="{{localize "PF2E.Kingmaker.ArmySheet.Potions.drinkErrorNoPotions"}}" class="disabled" type="button"><i class="fal fa-champagne-glasses"></i>
{{else if (eq @root.document.hitPoints.value @root.document.hitPoints.max)}}
<button data-tooltip="{{localize "PF2E.Kingmaker.ArmySheet.Potions.drinkErrorFullHP"}}" class="disabled" type="button"><i class="fal fa-champagne-glasses"></i>
{{else}}
<button data-tooltip="{{localize "PF2E.Kingmaker.ArmySheet.Potions.drinkTooltip"}}" class="usepotion" type="button"><i class="fas fa-champagne-glasses"></i>
<button data-tooltip="{{localize "PF2E.Kingmaker.ArmySheet.Potions.drinkTooltip"}}" data-action="use-potion" type="button"><i class="fas fa-champagne-glasses"></i>
{{/if}}
</button>
<button data-tooltip="{{data.attributes.hp.potions}} {{localize "PF2E.Kingmaker.ArmySheet.Potions.label"}}" class="potion pips" type="button">
{{#times 3}}
<i class="{{#if (gt @root.data.attributes.hp.potions this)}}far fa-flask-round-potion filled{{else}}fal fa-flask-round-potion empty{{/if}}"></i>
<button class="pips" data-action="change-potions" type="button">
{{#times @root.data.resources.potions.max as |idx|}}
<i class="{{#if (gt @root.data.attributes.hp.potions idx)}}far fa-flask-round-potion filled{{else}}fal fa-flask-round-potion empty{{/if}}"></i>
{{/times}}
</button>
<button data-tooltip="{{localize "PF2E.Kingmaker.Army.Tooltip.tooltipPotion"}}" class="info" data-info="potions" type="button">
Expand Down Expand Up @@ -133,9 +133,12 @@
<div class="row gear">
<span>Melee</span>
<button type="button" class="pips" data-action="change-magic-weapon" data-weapon="melee">
{{#times 3}}
<i class="{{#if (gt @root.data.weapons.melee.potency this)}}far fa-sword filled{{else}}fal fa-sword empty{{/if}}"></i>
{{/times}}
<i class="{{#if data.weapons.melee}}fa-solid filled{{else}}fa-regular{{/if}} fa-circle split"></i>
<span>
{{#times 3}}
<i class="{{#if (gt @root.data.weapons.melee.potency this)}}far fa-sword filled{{else}}fal fa-sword{{/if}}"></i>
{{/times}}
</span>
</button>
<button data-tooltip="{{localize "PF2E.Kingmaker.Army.Tooltip.tooltipMelee"}}" class="info" data-info="melee" type="button">
<i class="far fa-comment-alt"></i>
Expand All @@ -144,9 +147,12 @@
<div class="row gear">
<span>Ranged</span>
<button type="button" class="pips" data-action="change-magic-weapon" data-weapon="ranged">
{{#times 3}}
<i class="{{#if (gt @root.data.weapons.ranged.potency this)}}far fa-bow-arrow filled{{else}}fal fa-bow-arrow empty{{/if}}"></i>
{{/times}}
<i class="{{#if data.weapons.ranged}}fa-solid filled{{else}}fa-regular{{/if}} fa-circle split"></i>
<span>
{{#times 3}}
<i class="{{#if (gt @root.data.weapons.ranged.potency this)}}far fa-bow-arrow filled{{else}}fal fa-bow-arrow{{/if}}"></i>
{{/times}}
</span>
</button>
<button data-tooltip="{{localize "PF2E.Kingmaker.Army.Tooltip.tooltipRanged"}}" class="info" data-info="ranged" type="button">
<i class="far fa-comment-alt"></i>
Expand Down Expand Up @@ -175,6 +181,11 @@
</legend>
{{#each document.strikes as |strike type|}}
<div class="strike" data-strike="{{type}}">
{{#if (eq type "melee")}}
<i class="fa-solid fa-fw fa-sword"></i>
{{else}}
<i class="fa-solid fa-fw fa-bow-arrow"></i>
{{/if}}
{{#each strike.variants as |variant index|}}
<button type="button" data-action="strike-attack" data-variant-index="{{index}}" class="attack">
{{#if (eq index 0)}}
Expand All @@ -186,9 +197,9 @@
{{/each}}
<button type="button" data-action="strike-damage" class="damage">{{localize "PF2E.DamageLabel"}}</button>
<button type="button" data-action="strike-damage" data-outcome="criticalSuccess" class="damage critical">{{localize "PF2E.CriticalDamageLabel"}}</button>
<input class="name" type="text" name="system.weapons.{{type}}.name" value="{{strike.label}}" placeholder="{{localize "PF2E.Kingmaker.Strikes.{{type}}"}}" />
<input class="name" type="text" name="system.weapons.{{type}}.name" value="{{strike.label}}" />
{{#if (eq type "ranged")}}
<button data-tooltip="{{localize "PF2E.Kingmaker.Army.Strikes.ammunitionLabel"}} {{data.resources.ammunition.value}}" class="ammunition pips" type="button">
<button type="button" class="pips" data-action="change-ammunition" data-tooltip="{{localize "PF2E.Kingmaker.Army.Strikes.ammunitionLabel"}} {{data.resources.ammunition.value}}">
{{#times @root.data.resources.ammunition.max}}
<i class="{{#if (gt @root.data.resources.ammunition.value this)}}far fa-dagger filled{{else}}fal fa-dagger empty{{/if}}"></i>
{{/times}}
Expand Down

0 comments on commit bb212ab

Please sign in to comment.