Lancer de sorts V2

This commit is contained in:
2025-10-15 22:40:46 +02:00
parent 3e8963b20b
commit 6d7f66569a
6 changed files with 238 additions and 42 deletions

View File

@@ -22,9 +22,27 @@ export class RollPartSort extends RollPartSelect {
isValid(rollData) { return rollData.active.actor.isPersonnage() && rollData.active.actor.isHautRevant() }
visible(rollData) { return this.isRollType(rollData, ROLL_TYPE_SORT) }
restore(rollData) {
const saved = this.getSaved(rollData)
this.setCurrent(rollData, {
key: saved.key,
isReserve: saved.isReserve,
ptreve: saved.ptreve
})
}
store(rollData, targetData) {
const current = this.getCurrent(rollData)
this.setSaved(targetData, {
key: current.key,
isReserve: current.isReserve,
ptreve: current.ptreve
})
}
loadRefs(rollData) {
const refs = this.getRefs(rollData)
const coord = rollData.active.actor.system.reve.tmrpos.coord
const coord = this.getCoord(rollData)
const draconics = rollData.active.actor.getDraconics()
const sorts = rollData.active.actor.itemTypes[ITEM_TYPES.sort]
.map(s => RollPartSort.$extractSort(s, coord, draconics))
@@ -33,7 +51,7 @@ export class RollPartSort extends RollPartSelect {
{
coord: coord,
tmr: TMRUtility.getTMR(coord),
reve: rollData.active.actor.system.reve.reve.value,
reve: this.getReveActuel(rollData),
draconics: draconics,
all: sorts,
sorts: sorts.filter(it => RdDItemSort.isSortOnCoord(it.sort, coord))
@@ -41,10 +59,18 @@ export class RollPartSort extends RollPartSelect {
{ inplace: true }
)
if (refs.sorts.length > 0) {
this.$selectSort(rollData)
this.$selectSort(rollData, this.getSaved(rollData))
}
}
getReveActuel(rollData) {
return rollData.active.actor.system.reve.reve.value
}
getCoord(rollData) {
return rollData.active.actor.system.reve.tmrpos.coord
}
choices(refs) { return refs.sorts }
static $extractSort(sort, coord, draconics) {
@@ -56,11 +82,12 @@ export class RollPartSort extends RollPartSelect {
value: isDiffVariable ? -7 : parseInt(sort.system.difficulte),
ptreve: isReveVariable ? 1 : sort.system.ptreve,
caseTMR: RdDItemSort.getCaseTMR(sort),
bonusCase: RdDItemSort.getCaseBonus(sort, coord),
isDiffVariable: isDiffVariable,
isReveVariable: isReveVariable,
isReserve: false,
sort: sort,
draconics: RdDItemSort.getDraconicsSort(draconics, sort).map(it => it.name)
draconics: RdDItemSort.getDraconicsSort(draconics, sort).map(it => it.name),
}
}
@@ -68,25 +95,27 @@ export class RollPartSort extends RollPartSelect {
const current = this.getCurrent(rollData)
if (current) {
const reserve = current.isReserve ?
[{ label: `Mise en réserve en ${current.coord}` }] : []
[{ label: `Mise en réserve en ${this.getCoord(rollData)}` }] : []
const bonusCase = current.bonusCase ?
[{ label: `Bonus case +${current.bonusCase}%` }] : []
return [
{ label: current.label, diff: current.value },
{ label: `r${current.ptreve}` },
...bonusCase,
{ label: `Rêve ${current.ptreve}` },
...reserve
]
}
return []
}
$selectSort(rollData, key) {
const previous = this.getCurrent(rollData)
const current = this.selectByKey(rollData, key, -7)
if (current.key != previous.key) { }
current.bonusCase = RdDItemSort.getCaseBonus(current.sort,
rollData.active.actor.system.reve.tmrpos.coord)
$selectSort(rollData, values) {
const current = this.selectByKey(rollData, values.key)
if (values.ptreve) {
current.ptreve = values.ptreve
}
if (values.isReserve != undefined) {
current.isReserve = values.isReserve
}
}
async _onRender(rollDialog, context, options) {
@@ -99,7 +128,7 @@ export class RollPartSort extends RollPartSelect {
selectSort.addEventListener("change", e => {
const selectOptions = e.currentTarget.options
const index = selectOptions.selectedIndex
this.$selectSort(rollDialog.rollData, selectOptions[index]?.value)
this.$selectSort(rollDialog.rollData, { key: selectOptions[index]?.value })
rollDialog.render()
})