forked from public/foundryvtt-reve-de-dragon
110 lines
3.5 KiB
JavaScript
110 lines
3.5 KiB
JavaScript
import { RDD_CONFIG } from "../constants.js"
|
|
import { Misc } from "../misc.js"
|
|
import { ReglesOptionnelles } from "../settings/regles-optionnelles.js"
|
|
import { demiReveStatusEffect, StatusEffects } from "../settings/status-effects.js"
|
|
import { ROLL_TYPE_ATTAQUE, ROLL_TYPE_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_TYPE_ATTAQUE, ROLL_TYPE_DEFENSE].includes(rollData.type.current) || rollData.type.isCombat
|
|
}
|
|
|
|
prepareContext(rollData) {
|
|
this.setFromState(rollData)
|
|
}
|
|
|
|
setFromState(rollData) {
|
|
if (rollData.type.retry) {
|
|
return
|
|
}
|
|
const actor = rollData.active.actor;
|
|
const isCombat = this.isCombat(rollData)
|
|
const current = this.getCurrent(rollData)
|
|
current.armeDisparate = isCombat && current.armeDisparate
|
|
current.surprise = actor.getSurprise(isCombat, current.forceRequise ?? 0)
|
|
current.reasons = actor.getEffects(it => StatusEffects.niveauSurprise(it, isCombat) > 0, current.forceRequise ?? 0)
|
|
.map(it => { return { img: it.img, label: game.i18n.localize(it.name) } })
|
|
current.diviseur = 1
|
|
if (current.surprise == 'demi') {
|
|
current.diviseur *= 2
|
|
}
|
|
if (isCombat && actor.isDemiReve()) {
|
|
current.reasons.push({ img: RDD_CONFIG.icons.demiReve, label: 'Demi-rêve en combat' })
|
|
}
|
|
if (this.isParadeArmeDisparate(current)) {
|
|
current.diviseur *= 2
|
|
current.reasons.push({ img: RDD_CONFIG.icons.armesDisparates, label: 'Armes disparates' })
|
|
}
|
|
if (this.isAttaqueFinesse(rollData)) {
|
|
current.diviseur *= 2
|
|
current.reasons.push({ img: RDD_CONFIG.particuliere.finesse.img, label: 'Particulière en finesse' })
|
|
}
|
|
|
|
if (!ReglesOptionnelles.isUsing('tripleSignificative')) {
|
|
current.diviseur = Math.min(current.diviseur, 4);
|
|
}
|
|
|
|
current.reason = current.reasons.map(it => it.label).join(', ')
|
|
}
|
|
|
|
isAttaqueFinesse(rollData) {
|
|
return ROLL_TYPE_DEFENSE == rollData.type.current && rollData.attaque?.particuliere == 'finesse'
|
|
}
|
|
|
|
isParadeArmeDisparate(current) {
|
|
return current.armeDisparate
|
|
}
|
|
|
|
getAjustements(rollData) {
|
|
const current = this.getCurrent(rollData)
|
|
if (current.surprise == 'demi') {
|
|
return [
|
|
{
|
|
label: 'Significative requise ' + Misc.getFractionOneN(current.diviseur)
|
|
},
|
|
...current.reasons.map(it => {
|
|
return {
|
|
label: it.img
|
|
? `<img src="${it.img}"> ${it.label}`
|
|
: `<i class="fa-solid fa-triangle-exclamation"></i> ${it.label}`
|
|
}
|
|
})
|
|
]
|
|
}
|
|
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, armeDisparate, forceRequise) {
|
|
const current = this.getCurrent(rollData)
|
|
current.armeDisparate = armeDisparate
|
|
current.forceRequise = forceRequise
|
|
}
|
|
} |