Nouvelle fenêtre de jets de dés
This commit is contained in:
93
module/roll/roll-part-sign.mjs
Normal file
93
module/roll/roll-part-sign.mjs
Normal file
@@ -0,0 +1,93 @@
|
||||
import { Misc } from "../misc.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))
|
||||
}
|
||||
|
||||
// visible(rollData) {
|
||||
// const current = this.getCurrent(rollData)
|
||||
// return current.surprise != ''
|
||||
// }
|
||||
|
||||
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.surprise = actor.getSurprise(isCombat)
|
||||
current.reasons = actor.getEffects(it => StatusEffects.niveauSurprise(it) > 0).map(it => it.name)
|
||||
current.diviseur = 1
|
||||
if (isCombat && actor.isDemiReve()) {
|
||||
current.reasons.push('Demi-rêve en combat')
|
||||
}
|
||||
if (current.surprise == 'demi') {
|
||||
current.diviseur *= 2
|
||||
}
|
||||
|
||||
if (this.isAttaqueFinesse(rollData)) {
|
||||
current.diviseur *= 2
|
||||
current.reasons.push('Attaque en finesse')
|
||||
}
|
||||
if (this.isForceInsuffisante(rollData)) {
|
||||
current.diviseur *= 2
|
||||
current.reasons.push('Force insuffisante')
|
||||
}
|
||||
current.reason = current.reasons.join(', ')
|
||||
}
|
||||
|
||||
isForceInsuffisante(rollData) {
|
||||
//this.isCombat(rollData) && ... arme avec force min
|
||||
return this.isCombat(rollData) && true
|
||||
}
|
||||
|
||||
isAttaqueFinesse(rollData) {
|
||||
// this.rollData.selected[PART_DEFENSE] && attaquant avec particulière en finesse
|
||||
return ROLL_MODE_DEFENSE == rollData.mode.current && true
|
||||
}
|
||||
|
||||
getAjustements(rollData) {
|
||||
const current = this.getCurrent(rollData)
|
||||
if (current.surprise == 'demi') {
|
||||
return [{ label: 'Significative requise ' + Misc.getFractionOneN(current.diviseur), 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()
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user