Full SAN management
This commit is contained in:
@ -14,7 +14,8 @@ export default class CthulhuEternalProtagonist extends foundry.abstract.TypeData
|
||||
const characteristicField = (label) => {
|
||||
const schema = {
|
||||
value: new fields.NumberField({ ...requiredInteger, initial: 3, min: 0 }),
|
||||
feature: new fields.StringField({ required: true, nullable: false, initial: "" })
|
||||
feature: new fields.StringField({ required: true, nullable: false, initial: "" }),
|
||||
max: new fields.NumberField({ ...requiredInteger, initial: 3, min: 0 })
|
||||
}
|
||||
return new fields.SchemaField(schema, { label })
|
||||
}
|
||||
@ -47,6 +48,7 @@ export default class CthulhuEternalProtagonist extends foundry.abstract.TypeData
|
||||
violence: new fields.ArrayField(new fields.BooleanField(), { required: true, initial: [false, false, false], min: 3, max: 3 }),
|
||||
helplessness: new fields.ArrayField(new fields.BooleanField(), { required: true, initial: [false, false, false], min: 3, max: 3 }),
|
||||
breakingPoint: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
|
||||
breakingPointReached: new fields.BooleanField({ required: true, initial: false }),
|
||||
insanity: new fields.StringField({ required: true, nullable: false, initial: "none", choices: SYSTEM.INSANITY }),
|
||||
})
|
||||
|
||||
@ -132,6 +134,15 @@ export default class CthulhuEternalProtagonist extends foundry.abstract.TypeData
|
||||
updates[`system.damageBonus`] = dmgBonus
|
||||
}
|
||||
|
||||
// BP (Breaking Point) management
|
||||
if (!this.san.breakingPointReached && this.san.value <= this.san.breakingPoint) {
|
||||
updates[`system.san.breakingPointReached`] = true
|
||||
ChatMessage.create({
|
||||
content: `<p>${game.i18n.format("CTHULHUETERNAL.Label.breakingPointReached", { bp: this.san.breakingPoint, san: this.san.value })}</p>`,
|
||||
speaker: ChatMessage.getSpeaker({ actor: this.parent })
|
||||
})
|
||||
}
|
||||
|
||||
// Unconsciousness management
|
||||
if (!this.hp.unconscious && this.hp.value <= 2) {
|
||||
updates[`system.hp.unconscious`] = true
|
||||
@ -183,6 +194,108 @@ export default class CthulhuEternalProtagonist extends foundry.abstract.TypeData
|
||||
}
|
||||
}
|
||||
|
||||
async applySANConsequences(rollData) {
|
||||
// If sanType is "non", do nothing
|
||||
if (rollData.sanType === "none") {
|
||||
return
|
||||
}
|
||||
let msgData = {
|
||||
sanType: rollData.sanType,
|
||||
sanLoss: rollData.sanLoss,
|
||||
actorId: this.parent.id,
|
||||
actorName: this.parent.name,
|
||||
adaptedToHelplessness: this.biodata.adaptedToHelplessness,
|
||||
adaptedToViolence: this.biodata.adaptedToViolence,
|
||||
... rollData
|
||||
}
|
||||
let updates = {}
|
||||
let template = ""
|
||||
// Manage temporary insanity
|
||||
if (rollData.sanLoss >= 5) {
|
||||
rollData.resetMsg = false
|
||||
if (rollData.sanType === "violence" && !this.biodata.adaptedToViolence) {
|
||||
updates[`system.san.violence`] = [false, false, false]
|
||||
rollData.resetMsg = "CTHULHUETERNAL.Label.sanViolenceReset"
|
||||
}
|
||||
if (rollData.sanType === "helplessness" && !this.biodata.adaptedToHelplessness) {
|
||||
updates[`system.san.helplessness`] = [false, false, false]
|
||||
rollData.resetMsg = "CTHULHUETERNAL.Label.sanHelplessnessReset"
|
||||
}
|
||||
template = "systems/fvtt-cthulhu-eternal/templates/chat-san-temp-insanity.hbs"
|
||||
|
||||
} else if (rollData.sanLoss === 0) { // Manage if sanLoss is 0
|
||||
rollData.resetMsg = false
|
||||
if (rollData.sanType === "violence" && !this.biodata.adaptedToViolence) {
|
||||
updates[`system.san.violence`] = [false, false, false]
|
||||
rollData.resetMsg = "CTHULHUETERNAL.Label.sanViolenceReset"
|
||||
}
|
||||
if (rollData.sanType === "helplessness" && !this.biodata.adaptedToHelplessness) {
|
||||
updates[`system.san.helplessness`] = [false, false, false]
|
||||
rollData.resetMsg = "CTHULHUETERNAL.Label.sanHelplessnessReset"
|
||||
}
|
||||
template = "systems/fvtt-cthulhu-eternal/templates/chat-san-loss-0.hbs"
|
||||
|
||||
} else if (rollData.sanType === "violence" ) {
|
||||
// Set the first false element of the violence array to true
|
||||
let violence = this.san.violence.slice()
|
||||
let index = violence.findIndex(v => !v)
|
||||
if (index !== -1) {
|
||||
violence[index] = true
|
||||
updates[`system.san.violence`] = violence
|
||||
}
|
||||
template = "systems/fvtt-cthulhu-eternal/templates/chat-san-loss-1-4.hbs"
|
||||
// Check if all violence elements are true, if so, set adaptedToViolence to true
|
||||
if (violence.every(v => v)) {
|
||||
updates[`system.biodata.adaptedToViolence`] = true
|
||||
updates[`system.san.violence`] = [false, false, false]
|
||||
msgData.adaptedToViolence = true
|
||||
}
|
||||
} else if (rollData.sanType === "helplessness" ) {
|
||||
// If sanType is "helplessness" and adapted to helplessness, set the first false element of the helplessness array to true
|
||||
let helplessness = this.san.helplessness.slice()
|
||||
let index = helplessness.findIndex(h => !h)
|
||||
if (index !== -1) {
|
||||
helplessness[index] = true
|
||||
updates[`system.san.helplessness`] = helplessness
|
||||
}
|
||||
template = "systems/fvtt-cthulhu-eternal/templates/chat-san-loss-1-4.hbs"
|
||||
// Check if all helplessness elements are true, if so, set adaptedToHelplessness to true
|
||||
if (helplessness.every(h => h)) {
|
||||
updates[`system.biodata.adaptedToHelplessness`] = true
|
||||
updates[`system.san.helplessness`] = [false, false, false]
|
||||
msgData.adaptedToHelplessness = true
|
||||
}
|
||||
}
|
||||
|
||||
let content = await foundry.applications.handlebars.renderTemplate(template, msgData)
|
||||
let msg = await ChatMessage.create({
|
||||
content: content,
|
||||
speaker: ChatMessage.getSpeaker({ actor: this.parent })
|
||||
})
|
||||
msg.setFlag("fvtt-cthulhu-eternal", "rollData", msgData)
|
||||
if (Object.keys(updates).length > 0) {
|
||||
this.parent.update(updates)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async modifySAN(rollData) {
|
||||
let updates = {}
|
||||
let san = Math.max(Math.min(this.san.value + rollData.sanLoss, this.san.max), 0)
|
||||
if (this.san.value !== san) {
|
||||
updates[`system.san.value`] = san
|
||||
const content = await foundry.applications.handlebars.renderTemplate("systems/fvtt-cthulhu-eternal/templates/chat-san-type-request.hbs", rollData)
|
||||
let msg = await ChatMessage.create({
|
||||
content: content,
|
||||
speaker: ChatMessage.getSpeaker({ actor: this.parent })
|
||||
})
|
||||
msg.setFlag("fvtt-cthulhu-eternal", "rollData", rollData)
|
||||
}
|
||||
if (Object.keys(updates).length > 0) {
|
||||
this.parent.update(updates)
|
||||
}
|
||||
}
|
||||
|
||||
isStunned() {
|
||||
return this.hp.stunned
|
||||
}
|
||||
@ -215,6 +328,7 @@ export default class CthulhuEternalProtagonist extends foundry.abstract.TypeData
|
||||
let bp = Math.max(this.san.value - this.characteristics.pow.value, 0)
|
||||
if (this.san.breakingPoint !== bp) {
|
||||
updates[`system.san.breakingPoint`] = bp
|
||||
updates[`system.san.breakingPointReached`] = false // Reset breaking point reached
|
||||
}
|
||||
if (Object.keys(updates).length > 0) {
|
||||
this.parent.update(updates)
|
||||
|
Reference in New Issue
Block a user