Lancer de sorts V2
This commit is contained in:
@@ -173,6 +173,8 @@ const ROLL_PARTS = [
|
||||
/* -------------------------------------------- */
|
||||
export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2)
|
||||
{
|
||||
static onCloseDoNothing() {
|
||||
}
|
||||
static onRollDoneDoNothing(dialog) {
|
||||
dialog.render()
|
||||
}
|
||||
@@ -181,7 +183,6 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2
|
||||
dialog.close()
|
||||
}
|
||||
|
||||
|
||||
static init() {
|
||||
}
|
||||
|
||||
@@ -236,6 +237,7 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2
|
||||
static async create(rollData, rollOptions = {}) {
|
||||
const rollDialog = new RollDialog(rollData, rollOptions)
|
||||
rollDialog.render(true)
|
||||
return rollDialog
|
||||
}
|
||||
|
||||
static get PARTS() {
|
||||
@@ -322,7 +324,8 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2
|
||||
...(rollOptions.callbacks ?? [])
|
||||
],
|
||||
customChatMessage: rollOptions.customChatMessage,
|
||||
onRollDone: rollOptions.onRollDone ?? RollDialog.onRollDoneDoNothing
|
||||
onRollDone: rollOptions.onRollDone ?? RollDialog.onRollDoneDoNothing,
|
||||
onClose: rollOptions.onClose ?? RollDialog.onCloseDoNothing
|
||||
}
|
||||
this.chatRollResult = new ChatRollResult();
|
||||
this.selectType()
|
||||
@@ -440,6 +443,13 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2
|
||||
return ALL_ROLL_TYPES.find(m => m.code == this.rollData.type.current)
|
||||
}
|
||||
|
||||
async close(options){
|
||||
if (this.rollOptions.onClose){
|
||||
this.rollOptions.onClose()
|
||||
}
|
||||
return await super.close(options)
|
||||
}
|
||||
|
||||
async roll() {
|
||||
|
||||
const roll = RollDialog.saveParts(this.rollData)
|
||||
|
@@ -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()
|
||||
})
|
||||
|
||||
|
@@ -1,4 +1,9 @@
|
||||
import { RdDItemCompetence } from "../item-competence.js"
|
||||
import { RdDItemSort } from "../item-sort.js"
|
||||
import { RdDResolutionTable } from "../rdd-resolution-table.js"
|
||||
import { DIFF, ROLL_TYPE_SORT } from "./roll-constants.mjs"
|
||||
import { PART_COMP } from "./roll-part-comp.mjs"
|
||||
import { PART_SORT } from "./roll-part-sort.mjs"
|
||||
import { RollType } from "./roll-type.mjs"
|
||||
|
||||
export class RollTypeSort extends RollType {
|
||||
@@ -11,4 +16,69 @@ export class RollTypeSort extends RollType {
|
||||
onSelect(rollData) {
|
||||
this.setDiffType(rollData, DIFF.AUCUN)
|
||||
}
|
||||
|
||||
getResult(rollData, impacts) {
|
||||
const rolled = rollData.rolled
|
||||
const actor = rollData.active.actor
|
||||
const coord = actor.system.reve.tmrpos.coord
|
||||
const reveActuel = parseInt(actor.system.reve.reve.value)
|
||||
const draconic = rollData.current[PART_COMP].comp
|
||||
|
||||
const current = rollData.current[PART_SORT]
|
||||
const sort = current.sort
|
||||
const isReserve = current.isReserve
|
||||
const reveSort = current.ptreve
|
||||
const isThanatos = RdDItemCompetence.isThanatos(draconic)
|
||||
|
||||
actor.tmrApp?.restoreTMRAfterAction()
|
||||
|
||||
current.depenseReve = reveSort
|
||||
if (isThanatos) { // Si Thanatos
|
||||
impacts.addActorUpdate("system.reve.reve.thanatosused", true)
|
||||
}
|
||||
|
||||
if (rolled.isSuccess) { // Réussite du sort !
|
||||
if (rolled.isPart) {
|
||||
current.depenseReve = Math.max(Math.floor(current.depenseReve / 2), 1)
|
||||
}
|
||||
if (isReserve) {
|
||||
current.depenseReve++
|
||||
}
|
||||
|
||||
if (reveActuel > current.depenseReve) {
|
||||
// Incrémenter/gére le bonus de case
|
||||
impacts.addUpdate('Item', sort, 'system.bonuscase', RdDItemSort.calculBonuscase(sort, coord))
|
||||
|
||||
if (isReserve) {
|
||||
impacts.addCreated('Item', RdDItemSort.prepareSortEnReserve(sort, draconic, reveSort, coord))
|
||||
}
|
||||
else {
|
||||
rollData.closeTMR = true
|
||||
if (sort.system.isrituel) {
|
||||
impacts.addUpdate('Item', sort, 'system.lancements', RdDItemSort.prepareSortAddLancement(sort, reveSort))
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
current.depenseReve = 0;
|
||||
rollData.show.reveInsuffisant = true
|
||||
foundry.utils.mergeObject(rollData.rolled, RdDResolutionTable.getResultat("echec"), { overwrite: true })
|
||||
}
|
||||
} else {
|
||||
rollData.closeTMR = true
|
||||
if (rolled.isETotal) { // Echec total !
|
||||
current.depenseReve = Math.min(reveActuel, Math.floor(current.depenseReve * 1.5))
|
||||
// TODO: mise en réserve d'un échec total...
|
||||
} else {
|
||||
current.depenseReve = 0
|
||||
}
|
||||
}
|
||||
|
||||
impacts.addActorDelta("system.reve.reve.value", - Math.min(current.depenseReve, reveActuel))
|
||||
|
||||
if (current.depenseReve >= reveActuel) { // 0 points de reve
|
||||
rollData.show.zeroReve = true
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user