feat: add Settlement actor type with Overview/Buildings/Inventory tabs

- New TypeDataModel: archetype, territory, renown, currency (gp/sp/cp),
  garrison, underSiege, isCapital, founded, taxNotes, description, notes
- 3-tab ApplicationV2 sheet with drag & drop for building/weapon/armor/equipment
- Currency steppers (+/−), building constructed toggle, qty controls
- LESS-based CSS (settlement-sheet.less) + base.less updated for shared styles
- Full i18n keys in lang/en.json (8 settlement archetypes)
- system.json: registered settlement actor type

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-03-20 17:01:38 +01:00
parent b67d85c6be
commit b3fd7e1aa1
28 changed files with 966 additions and 270 deletions

View File

@@ -11,6 +11,7 @@ export { default as OathHammerTraitSheet } from "./sheets/trait-sheet.mjs"
export { default as OathHammerOathSheet } from "./sheets/oath-sheet.mjs"
export { default as OathHammerClassSheet } from "./sheets/class-sheet.mjs"
export { default as OathHammerBuildingSheet } from "./sheets/building-sheet.mjs"
export { default as OathHammerSettlementSheet } from "./sheets/settlement-sheet.mjs"
export { default as OathHammerRollDialog } from "./roll-dialog.mjs"
export { default as OathHammerWeaponDialog } from "./weapon-dialog.mjs"
export { default as OathHammerSpellDialog } from "./spell-dialog.mjs"

View File

@@ -67,7 +67,7 @@ export default class OathHammerArmorDialog {
)
const result = await foundry.applications.api.DialogV2.wait({
window: { title: game.i18n.format("OATHHAMMER.Dialog.ArmorRollTitle", { armor: armor.name }) },
window: { title: game.i18n.format("OATHHAMMER.Dialog.ArmorRollTitle", { armor: armor.name }), resizable: true },
classes: ["fvtt-oath-hammer"],
position: { width: 420 },
content,

View File

@@ -68,7 +68,7 @@ export default class OathHammerDefenseDialog {
)
const result = await foundry.applications.api.DialogV2.wait({
window: { title: game.i18n.format("OATHHAMMER.Dialog.DefenseTitle", { actor: actor.name }) },
window: { title: game.i18n.format("OATHHAMMER.Dialog.DefenseTitle", { actor: actor.name }), resizable: true },
classes: ["fvtt-oath-hammer"],
position: { width: 420 },
content,

View File

@@ -30,6 +30,15 @@ export default class OathHammerMiracleDialog {
return { value: v, label: v > 0 ? `+${v}` : String(v), selected: v === 0 }
})
const availableLuck = actorSys.luck?.value ?? 0
const isHuman = (actorSys.lineage?.name ?? "").toLowerCase() === "human"
const luckDicePerPoint = isHuman ? 3 : 2
const luckOptions = Array.from({ length: availableLuck + 1 }, (_, i) => ({
value: i,
label: i === 0 ? "0" : `${i} (+${i * luckDicePerPoint}d)`,
selected: i === 0,
}))
const rollModes = foundry.utils.duplicate(CONFIG.Dice.rollModes)
const context = {
@@ -47,6 +56,9 @@ export default class OathHammerMiracleDialog {
basePool,
miracleCountOptions,
bonusOptions,
availableLuck,
isHuman,
luckOptions,
rollModes,
visibility: game.settings.get("core", "rollMode"),
}
@@ -84,6 +96,8 @@ export default class OathHammerMiracleDialog {
bonus: parseInt(result.bonus) || 0,
visibility: result.visibility ?? game.settings.get("core", "rollMode"),
explodeOn5: result.explodeOn5 === "true",
luckSpend: Math.min(Math.max(0, parseInt(result.luckSpend) || 0), availableLuck),
luckIsHuman: result.luckIsHuman === "true",
}
}
}

View File

@@ -124,7 +124,7 @@ export default class OathHammerRollDialog {
const title = game.i18n.format("OATHHAMMER.Dialog.SkillCheckTitle", { skill: context.skillLabel })
const result = await foundry.applications.api.DialogV2.wait({
window: { title },
window: { title, resizable: true },
classes: ["fvtt-oath-hammer"],
position: { width: 420 },
content,

View File

@@ -37,6 +37,8 @@ export default class OathHammerCharacterSheet extends OathHammerActorSheet {
rollInitiative: OathHammerCharacterSheet.#onRollInitiative,
adjustQty: OathHammerCharacterSheet.#onAdjustQty,
adjustCurrency: OathHammerCharacterSheet.#onAdjustCurrency,
adjustStress: OathHammerCharacterSheet.#onAdjustStress,
clearStress: OathHammerCharacterSheet.#onClearStress,
},
}
@@ -201,6 +203,7 @@ export default class OathHammerCharacterSheet extends OathHammerActorSheet {
break
case "magic":
context.tab = context.tabs.magic
context.stressBlocked = doc.system.arcaneStress.value >= doc.system.arcaneStress.threshold
context.spells = doc.itemTypes.spell.map(s => ({
id: s.id, uuid: s.uuid, img: s.img, name: s.name, system: s.system,
_descTooltip: _stripHtml(s.system.effect)
@@ -404,6 +407,17 @@ export default class OathHammerCharacterSheet extends OathHammerActorSheet {
const current = foundry.utils.getProperty(this.document, field) ?? 0
await this.document.update({ [field]: Math.max(0, current + delta) })
}
static async #onAdjustStress(event, target) {
const delta = parseInt(target.dataset.delta, 10)
const current = this.document.system.arcaneStress.value ?? 0
const max = this.document.system.arcaneStress.threshold
await this.document.update({ "system.arcaneStress.value": Math.max(0, Math.min(max, current + delta)) })
}
static async #onClearStress(_event, _target) {
await this.document.update({ "system.arcaneStress.value": 0 })
}
}
/** Strip HTML tags and collapse whitespace for use in data-tooltip attributes. */

View File

@@ -0,0 +1,132 @@
import OathHammerActorSheet from "./base-actor-sheet.mjs"
const ALLOWED_ITEM_TYPES = new Set(["building", "equipment", "weapon", "armor"])
export default class OathHammerSettlementSheet extends OathHammerActorSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["settlement"],
position: {
width: 840,
height: "auto",
},
window: {
contentClasses: ["settlement-content"],
},
actions: {
adjustCurrency: OathHammerSettlementSheet.#onAdjustCurrency,
adjustQty: OathHammerSettlementSheet.#onAdjustQty,
toggleConstructed: OathHammerSettlementSheet.#onToggleConstructed,
},
}
/** @override */
static PARTS = {
main: {
template: "systems/fvtt-oath-hammer/templates/actor/settlement-sheet.hbs",
},
tabs: {
template: "templates/generic/tab-navigation.hbs",
},
overview: {
template: "systems/fvtt-oath-hammer/templates/actor/settlement-overview.hbs",
},
buildings: {
template: "systems/fvtt-oath-hammer/templates/actor/settlement-buildings.hbs",
},
inventory: {
template: "systems/fvtt-oath-hammer/templates/actor/settlement-inventory.hbs",
},
}
/** @override */
tabGroups = {
sheet: "overview",
}
#getTabs() {
const tabs = {
overview: { id: "overview", group: "sheet", icon: "fa-solid fa-city", label: "OATHHAMMER.Tab.Overview" },
buildings: { id: "buildings", group: "sheet", icon: "fa-solid fa-building", label: "OATHHAMMER.Tab.Buildings" },
inventory: { id: "inventory", group: "sheet", icon: "fa-solid fa-boxes-stacked", label: "OATHHAMMER.Tab.Inventory" },
}
for (const v of Object.values(tabs)) {
v.active = this.tabGroups[v.group] === v.id
v.cssClass = v.active ? "active" : ""
}
return tabs
}
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
context.tabs = this.#getTabs()
context.archetypeChoices = Object.fromEntries(
Object.entries(SYSTEM.SETTLEMENT_ARCHETYPES).map(([k, v]) => [k, game.i18n.localize(v)])
)
return context
}
/** @override */
async _preparePartContext(partId, context) {
const doc = this.document
switch (partId) {
case "main":
break
case "overview":
context.tab = context.tabs.overview
context.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
doc.system.description, { async: true }
)
break
case "buildings":
context.tab = context.tabs.buildings
context.buildings = doc.itemTypes.building
break
case "inventory": {
context.tab = context.tabs.inventory
context.weapons = doc.itemTypes.weapon
context.armors = doc.itemTypes.armor
context.equipments = doc.itemTypes.equipment
break
}
}
return context
}
/** @override */
async _onDrop(event) {
if (!this.isEditable || !this.isEditMode) return
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event)
if (data.type !== "Item") return
const item = await fromUuid(data.uuid)
if (!item || !ALLOWED_ITEM_TYPES.has(item.type)) return
return this._onDropItem(item)
}
static async #onAdjustCurrency(event, target) {
const field = target.dataset.field
const delta = parseInt(target.dataset.delta, 10)
if (!field || isNaN(delta)) return
const current = foundry.utils.getProperty(this.document, field) ?? 0
await this.document.update({ [field]: Math.max(0, current + delta) })
}
static async #onAdjustQty(event, target) {
const itemId = target.dataset.itemId
const delta = parseInt(target.dataset.delta, 10)
if (!itemId || isNaN(delta)) return
const item = this.document.items.get(itemId)
if (!item) return
const current = item.system.quantity ?? 0
await item.update({ "system.quantity": Math.max(0, current + delta) })
}
static async #onToggleConstructed(event, target) {
const itemId = target.dataset.itemId
if (!itemId) return
const item = this.document.items.get(itemId)
if (!item) return
await item.update({ "system.constructed": !item.system.constructed })
}
}

View File

@@ -52,6 +52,22 @@ export default class OathHammerSpellDialog {
return { value: v, label: v > 0 ? `+${v}` : String(v), selected: v === 0 }
})
const availableLuck = actorSys.luck?.value ?? 0
const isHuman = (actorSys.lineage?.name ?? "").toLowerCase() === "human"
const luckDicePerPoint = isHuman ? 3 : 2
const luckOptions = Array.from({ length: availableLuck + 1 }, (_, i) => ({
value: i,
label: i === 0 ? "0" : `${i} (+${i * luckDicePerPoint}d)`,
selected: i === 0,
}))
// Pool size selector: casters may roll fewer dice to reduce Arcane Stress (p.101)
const poolSizeOptions = Array.from({ length: basePool }, (_, i) => ({
value: i + 1,
label: `${i + 1}d`,
selected: i + 1 === basePool,
}))
const rollModes = foundry.utils.duplicate(CONFIG.Dice.rollModes)
const context = {
@@ -70,11 +86,15 @@ export default class OathHammerSpellDialog {
intRank,
magicRank,
basePool,
poolSizeOptions,
currentStress,
stressThreshold,
isOverThreshold,
enhancementOptions,
bonusOptions,
availableLuck,
isHuman,
luckOptions,
rollModes,
visibility: game.settings.get("core", "rollMode"),
}
@@ -116,9 +136,12 @@ export default class OathHammerSpellDialog {
noStress: enh.noStress,
elementalBonus: parseInt(result.elementalBonus) || 0,
bonus: parseInt(result.bonus) || 0,
poolSize: Math.min(Math.max(1, parseInt(result.poolSize) || basePool), basePool),
grimPenalty: parseInt(result.noGrimoire) || 0,
visibility: result.visibility ?? game.settings.get("core", "rollMode"),
explodeOn5: result.explodeOn5 === "true",
luckSpend: Math.min(Math.max(0, parseInt(result.luckSpend) || 0), availableLuck),
luckIsHuman: result.luckIsHuman === "true",
}
}
}

View File

@@ -120,7 +120,7 @@ export default class OathHammerWeaponDialog {
)
const result = await foundry.applications.api.DialogV2.wait({
window: { title: game.i18n.format("OATHHAMMER.Dialog.AttackTitle", { weapon: weapon.name }) },
window: { title: game.i18n.format("OATHHAMMER.Dialog.AttackTitle", { weapon: weapon.name }), resizable: true },
classes: ["fvtt-oath-hammer"],
position: { width: 420 },
content,
@@ -268,7 +268,7 @@ export default class OathHammerWeaponDialog {
)
const result = await foundry.applications.api.DialogV2.wait({
window: { title: game.i18n.format("OATHHAMMER.Dialog.WeaponDefenseTitle", { weapon: weapon.name }) },
window: { title: game.i18n.format("OATHHAMMER.Dialog.WeaponDefenseTitle", { weapon: weapon.name }), resizable: true },
classes: ["fvtt-oath-hammer"],
position: { width: 420 },
content,
@@ -375,7 +375,7 @@ export default class OathHammerWeaponDialog {
)
const result = await foundry.applications.api.DialogV2.wait({
window: { title: game.i18n.format("OATHHAMMER.Dialog.DamageTitle", { weapon: weapon.name }) },
window: { title: game.i18n.format("OATHHAMMER.Dialog.DamageTitle", { weapon: weapon.name }), resizable: true },
classes: ["fvtt-oath-hammer"],
position: { width: 420 },
content,

View File

@@ -362,6 +362,17 @@ export const BUILDING_SKILL_CHOICES = {
masonry: "OATHHAMMER.BuildingSkill.Masonry"
}
export const SETTLEMENT_ARCHETYPES = {
"center-of-learning": "OATHHAMMER.SettlementArchetype.CenterOfLearning",
"dwarven-borough": "OATHHAMMER.SettlementArchetype.DwarvenBorough",
"free-city": "OATHHAMMER.SettlementArchetype.FreeCity",
"guild-municipality": "OATHHAMMER.SettlementArchetype.GuildMunicipality",
"nocklander-outpost": "OATHHAMMER.SettlementArchetype.NocklanderOutpost",
"pilgrim-mission": "OATHHAMMER.SettlementArchetype.PilgrimMission",
"port-town": "OATHHAMMER.SettlementArchetype.PortTown",
"velathi-colony": "OATHHAMMER.SettlementArchetype.VelathiColony"
}
export const SYSTEM = {
id: SYSTEM_ID,
ATTRIBUTES,
@@ -389,6 +400,7 @@ export const SYSTEM = {
TRAIT_TYPE_CHOICES,
TRAIT_USAGE_PERIOD,
BUILDING_SKILL_CHOICES,
SETTLEMENT_ARCHETYPES,
STATUS_EFFECTS,
ATTRIBUTE_RANK_CHOICES,
ASCII

View File

@@ -11,3 +11,4 @@ export { default as OathHammerTrait } from "./trait.mjs"
export { default as OathHammerOath } from "./oath.mjs"
export { default as OathHammerClass } from "./class.mjs"
export { default as OathHammerBuilding } from "./building.mjs"
export { default as OathHammerSettlement } from "./settlement.mjs"

View File

@@ -78,8 +78,9 @@ export default class OathHammerCharacter extends foundry.abstract.TypeDataModel
})
schema.arcaneStress = new fields.SchemaField({
value: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
threshold: new fields.NumberField({ ...requiredInteger, initial: 10, min: 0 })
value: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
threshold: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
thresholdBonus: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
})
schema.miracleBlocked = new fields.BooleanField({ required: true, initial: false })
@@ -130,5 +131,7 @@ export default class OathHammerCharacter extends foundry.abstract.TypeDataModel
this.luck.max = this.attributes.fate.rank
// Defense score = 10 + Agility + Armor Rating + bonus
this.defense.value = 10 + this.attributes.agility.rank + this.defense.armorRating + this.defense.bonus
// Stress Threshold = Willpower rank + Magic rank + bonus (rulebook p.101)
this.arcaneStress.threshold = this.attributes.willpower.rank + this.skills.magic.rank + this.arcaneStress.thresholdBonus
}
}

View File

@@ -0,0 +1,40 @@
import { SYSTEM } from "../config/system.mjs"
export default class OathHammerSettlement extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields
const requiredInteger = { required: true, nullable: false, integer: true }
const schema = {}
schema.description = new fields.HTMLField({ required: true, textSearch: true })
schema.notes = new fields.HTMLField({ required: false, textSearch: true })
schema.archetype = new fields.StringField({
required: true,
nullable: false,
initial: "free-city",
choices: SYSTEM.SETTLEMENT_ARCHETYPES
})
schema.territory = new fields.StringField({ required: true, nullable: false, initial: "" })
schema.founded = new fields.StringField({ required: true, nullable: false, initial: "" })
schema.population = new fields.StringField({ required: true, nullable: false, initial: "" })
schema.renown = new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
schema.currency = new fields.SchemaField({
gold: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
silver: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
copper: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
})
schema.garrison = new fields.StringField({ required: true, nullable: false, initial: "" })
schema.underSiege = new fields.BooleanField({ required: true, initial: false })
schema.isCapital = new fields.BooleanField({ required: true, initial: false })
schema.taxNotes = new fields.StringField({ required: true, nullable: false, initial: "" })
return schema
}
static LOCALIZATION_PREFIXES = ["OATHHAMMER.Settlement"]
}

View File

@@ -411,9 +411,12 @@ export async function rollSpellCast(actor, spell, options = {}) {
noStress = false,
elementalBonus = 0,
bonus = 0,
poolSize = null,
grimPenalty = 0,
visibility,
explodeOn5 = false,
luckSpend = 0,
luckIsHuman = false,
} = options
const sys = spell.system
@@ -421,7 +424,12 @@ export async function rollSpellCast(actor, spell, options = {}) {
const intRank = actorSys.attributes.intelligence.rank
const magicRank = actorSys.skills.magic.rank
const totalDice = Math.max(intRank + magicRank + bonus + poolPenalty + elementalBonus + grimPenalty, 1)
const luckDicePerPoint = luckIsHuman ? 3 : 2
const baseDice = intRank + magicRank + bonus + poolPenalty + elementalBonus + grimPenalty + (luckSpend * luckDicePerPoint)
// poolSize: voluntary reduction (p.101) — clamped to [1, baseDice]
const totalDice = poolSize !== null
? Math.max(1, Math.min(poolSize + bonus + poolPenalty + elementalBonus + grimPenalty + (luckSpend * luckDicePerPoint), baseDice))
: Math.max(baseDice, 1)
const threshold = redDice ? 3 : 4
const colorEmoji = redDice ? "🔴" : "⬜"
@@ -439,6 +447,10 @@ export async function rollSpellCast(actor, spell, options = {}) {
await actor.update({ "system.arcaneStress.value": currentStress + totalStressGain })
}
if (luckSpend > 0) {
await actor.update({ "system.luck.value": Math.max(0, (actorSys.luck?.value ?? 0) - luckSpend) })
}
const newStress = (actorSys.arcaneStress.value ?? 0) + totalStressGain
const stressMax = actorSys.arcaneStress.threshold
const isBlocked = newStress >= stressMax
@@ -451,10 +463,12 @@ export async function rollSpellCast(actor, spell, options = {}) {
: game.i18n.localize("OATHHAMMER.Roll.Failure")
const modParts = []
if (poolSize !== null && poolSize < intRank + magicRank) modParts.push(`🎲 ${poolSize}d ${game.i18n.localize("OATHHAMMER.Dialog.PoolSizeReduced")}`)
if (bonus !== 0) modParts.push(`${bonus > 0 ? "+" : ""}${bonus} ${game.i18n.localize("OATHHAMMER.Dialog.Modifier")}`)
if (poolPenalty !== 0) modParts.push(`${poolPenalty} ${game.i18n.localize("OATHHAMMER.Enhancement." + _cap(enhancement))}`)
if (elementalBonus > 0) modParts.push(`+${elementalBonus} ${game.i18n.localize("OATHHAMMER.Dialog.ElementMet")}`)
if (grimPenalty < 0) modParts.push(`${grimPenalty} ${game.i18n.localize("OATHHAMMER.Dialog.GrimoireNo")}`)
if (luckSpend > 0) modParts.push(`+${luckSpend * luckDicePerPoint} ${game.i18n.localize("OATHHAMMER.Dialog.LuckSpend")} (${luckSpend}LP${luckIsHuman ? " 👤" : ""})`)
const explodedCountSpell = diceResults.filter(d => d.exploded).length
if (explodedCountSpell > 0) modParts.push(`💥 ${explodedCountSpell} ${game.i18n.localize("OATHHAMMER.Roll.Exploded")}`)
const modLine = modParts.length ? `<div class="oh-roll-mods">${modParts.join(" · ")}</div>` : ""
@@ -517,6 +531,8 @@ export async function rollMiracleCast(actor, miracle, options = {}) {
bonus = 0,
visibility,
explodeOn5 = false,
luckSpend = 0,
luckIsHuman = false,
} = options
const sys = miracle.system
@@ -524,7 +540,8 @@ export async function rollMiracleCast(actor, miracle, options = {}) {
const wpRank = actorSys.attributes.willpower.rank
const magicRank = actorSys.skills.magic.rank
const totalDice = Math.max(wpRank + magicRank + bonus, 1)
const luckDicePerPoint = luckIsHuman ? 3 : 2
const totalDice = Math.max(wpRank + magicRank + bonus + (luckSpend * luckDicePerPoint), 1)
const threshold = 4
const colorEmoji = "⬜"
@@ -532,6 +549,10 @@ export async function rollMiracleCast(actor, miracle, options = {}) {
const diceHtml = _diceHtml(diceResults, threshold)
const isSuccess = successes >= dv
if (luckSpend > 0) {
await actor.update({ "system.luck.value": Math.max(0, (actorSys.luck?.value ?? 0) - luckSpend) })
}
const skillLabel = game.i18n.localize("OATHHAMMER.Skill.Magic")
const attrLabel = game.i18n.localize("OATHHAMMER.Attribute.Willpower")
const resultClass = isSuccess ? "roll-success" : "roll-failure"
@@ -541,6 +562,7 @@ export async function rollMiracleCast(actor, miracle, options = {}) {
const modParts = []
if (bonus !== 0) modParts.push(`${bonus > 0 ? "+" : ""}${bonus} ${game.i18n.localize("OATHHAMMER.Dialog.Modifier")}`)
if (luckSpend > 0) modParts.push(`+${luckSpend * luckDicePerPoint} ${game.i18n.localize("OATHHAMMER.Dialog.LuckSpend")} (${luckSpend}LP${luckIsHuman ? " 👤" : ""})`)
const explodedCountMiracle = diceResults.filter(d => d.exploded).length
if (explodedCountMiracle > 0) modParts.push(`💥 ${explodedCountMiracle} ${game.i18n.localize("OATHHAMMER.Roll.Exploded")}`)
const modLine = modParts.length ? `<div class="oh-roll-mods">${modParts.join(" · ")}</div>` : ""