114 lines
3.4 KiB
JavaScript
114 lines
3.4 KiB
JavaScript
import { Misc } from "../misc.js"
|
|
import { ReglesOptionnelles } from "../settings/regles-optionnelles.js"
|
|
import { StatusEffects } from "../settings/status-effects.js"
|
|
import { ROLL_MODE_ATTAQUE, ROLL_MODE_DEFENSE } from "./roll-constants.mjs"
|
|
import { ROLLDIALOG_SECTION, RollPart } from "./roll-part.mjs"
|
|
|
|
export const PART_SIGN = "sign"
|
|
|
|
export class RollPartSign extends RollPart {
|
|
|
|
get code() { return PART_SIGN }
|
|
get section() { return ROLLDIALOG_SECTION.AJUSTEMENTS }
|
|
|
|
loadRefs(rollData) {
|
|
this.setFromState(rollData)
|
|
}
|
|
|
|
restore(rollData) {
|
|
this.setCurrent(rollData, this.getSaved(rollData))
|
|
}
|
|
|
|
store(rollData, targetData) {
|
|
this.setSaved(targetData, this.getCurrent(rollData))
|
|
}
|
|
|
|
isCombat(rollData) {
|
|
return [ROLL_MODE_ATTAQUE, ROLL_MODE_DEFENSE].includes(rollData.mode.current) || rollData.mode.isCombat
|
|
}
|
|
|
|
prepareContext(rollData) {
|
|
this.setFromState(rollData)
|
|
}
|
|
|
|
setFromState(rollData) {
|
|
if (rollData.mode.retry) {
|
|
return
|
|
}
|
|
const actor = rollData.active.actor;
|
|
const isCombat = this.isCombat(rollData)
|
|
const current = this.getCurrent(rollData)
|
|
current.armeDisparate = isCombat && current.armeDisparate
|
|
current.forceRequise = current.forceRequise ?? 0
|
|
current.surprise = actor.getSurprise(isCombat)
|
|
current.reasons = actor.getEffects(it => StatusEffects.niveauSurprise(it) > 0).map(it => it.name)
|
|
current.diviseur = 1
|
|
if (current.surprise == 'demi') {
|
|
current.diviseur *= 2
|
|
}
|
|
if (isCombat && actor.isDemiReve()) {
|
|
current.reasons.push('Demi-rêve en combat')
|
|
}
|
|
if (this.isParadeArmeDisparate(current)) {
|
|
current.diviseur *= 2
|
|
current.reasons.push('Armes disparates')
|
|
}
|
|
if (this.isForceInsuffisante(actor, current)) {
|
|
current.diviseur *= 2
|
|
current.reasons.push('Force insuffisante')
|
|
}
|
|
if (this.isAttaqueFinesse(rollData)) {
|
|
current.diviseur *= 2
|
|
current.reasons.push('Particulière en finesse')
|
|
}
|
|
|
|
if (!ReglesOptionnelles.isUsing('tripleSignificative')) {
|
|
current.diviseur = Math.min(current.diviseur, 4);
|
|
}
|
|
|
|
current.reason = current.reasons.join(', ')
|
|
}
|
|
|
|
isAttaqueFinesse(rollData) {
|
|
return ROLL_MODE_DEFENSE == rollData.mode.current && rollData.attaque.particuliere == 'finesse'
|
|
}
|
|
|
|
isForceInsuffisante(actor, current) {
|
|
if (actor?.isPersonnage()) {
|
|
const requise = current.forceRequise
|
|
const force = parseInt(actor.system.carac.force.value)
|
|
return requise > force
|
|
}
|
|
return false
|
|
}
|
|
|
|
isParadeArmeDisparate(current) {
|
|
return current.armeDisparate
|
|
}
|
|
|
|
getAjustements(rollData) {
|
|
const current = this.getCurrent(rollData)
|
|
if (current.surprise == 'demi') {
|
|
return [
|
|
{ label: 'Significative requise ' + Misc.getFractionOneN(current.diviseur), diff: undefined },
|
|
...current.reasons.map(it => { return { label: '<i class="fa-solid fa-triangle-exclamation"></i> ' + it, diff: undefined } })
|
|
]
|
|
}
|
|
return []
|
|
}
|
|
|
|
async _onRender(rollDialog, context, options) {
|
|
const input = rollDialog.element.querySelector(`roll-section[name="${this.code}"] input[name="${this.code}"]`)
|
|
|
|
input?.addEventListener("change", e => {
|
|
this.getCurrent(rollDialog.rollData).value = parseInt(e.currentTarget.value)
|
|
rollDialog.render()
|
|
})
|
|
}
|
|
|
|
setArme(rollData, forceRequise, armeDisparate) {
|
|
const current = this.getCurrent(rollData)
|
|
current.armeDisparate = armeDisparate
|
|
current.forceRequise = forceRequise
|
|
}
|
|
} |