Improve confrontation management

This commit is contained in:
2023-06-01 22:13:04 +02:00
parent b3cbe7b31a
commit 88385d2307
11 changed files with 289 additions and 110 deletions

View File

@ -314,7 +314,7 @@ export class EcrymeActor extends Actor {
rollData.actorId = this.id
rollData.img = this.img
rollData.isReroll = false
rollData.traits = this.getRollTraits()
rollData.traits = duplicate(this.getRollTraits())
rollData.spleen = this.getSpleen()
rollData.ideal = this.getIdeal()
@ -351,8 +351,9 @@ export class EcrymeActor extends Actor {
let rollData = this.getCommonSkill(categKey, skillKey)
rollData.mode = "skill"
rollData.title = game.i18n.localize("ECRY.ui.confrontation") + " : " + game.i18n.localize(rollData.skill.name)
rollData.executionDices = []
rollData.preservationDices = []
rollData.executionTotal = rollData.skill.value
rollData.preservationTotal = rollData.skill.value
rollData.applyTranscendence = "execution"
let confrontStartDialog = await EcrymeConfrontStartDialog.create(this, rollData)
confrontStartDialog.render(true)
}

View File

@ -157,7 +157,8 @@ export class EcrymeUtility {
'systems/fvtt-ecryme/templates/items/partial-item-equipment.hbs',
'systems/fvtt-ecryme/templates/items/partial-item-description.hbs',
'systems/fvtt-ecryme/templates/dialogs/partial-common-roll-dialog.hbs',
'systems/fvtt-ecryme/templates/actors/partial-impacts.hbs'
'systems/fvtt-ecryme/templates/dialogs/partial-confront-dice-area.hbs',
'systems/fvtt-ecryme/templates/actors/partial-impacts.hbs',
]
return loadTemplates(templatePaths);
}
@ -386,10 +387,7 @@ export class EcrymeUtility {
let msg = await this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-ecryme/templates/chat/chat-generic-result.hbs`, rollData)
})
msg.setFlag("world", "rolldata", rollData)
if (rollData.mode == "initiative") {
actor.setFlag("world", "initiative", myRoll.total)
}
msg.setFlag("world", "ecryme-rolldata", rollData)
console.log("Rolldata result", rollData)
}
@ -407,7 +405,7 @@ export class EcrymeUtility {
let msg = await this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-ecryme/templates/chat/chat-generic-result.hbs`, rollData)
})
msg.setFlag("world", "rolldata", rollData)
msg.setFlag("world", "ecryme-rolldata", rollData)
}
/* -------------------------------------------- */

View File

@ -22,10 +22,10 @@ export class EcrymeConfrontDialog extends Dialog {
title: game.i18n.localize("ECRY.ui.confront"),
content: html,
buttons: {
rollNormal: {
launchConfront: {
icon: '<i class="fas fa-check"></i>',
label: game.i18n.localize("ECRY.ui.rollnormal"),
callback: () => { this.rollConfront("4d6") }
label: game.i18n.localize("ECRY.ui.launchconfront"),
callback: () => { this.launchConfront().catch("Error when launching Confrontation") }
},
cancel: {
icon: '<i class="fas fa-times"></i>',
@ -40,51 +40,159 @@ export class EcrymeConfrontDialog extends Dialog {
this.actor = actor;
this.rollData = rollData;
// Ensure button is disabled
setTimeout(function () { $(".launchConfront").attr("disabled", true) }, 180)
}
/* -------------------------------------------- */
async roll() {
async launchConfront() {
let msg = await EcrymeUtility.createChatMessage(this.rollData.alias, "blindroll", {
content: await renderTemplate(`systems/fvtt-ecryme/templates/chat/chat-confrontation-pending.hbs`, this.rollData)
})
msg.setFlag("world", "ecryme-rolldata", this.rollData)
}
/* -------------------------------------------- */
async refreshDialog() {
const content = await renderTemplate("systems/fvtt-ecryme/templates/dialogs/confront-dialog.hbs", this.rollData)
this.data.content = content
this.render(true)
let button = this.buttonDisabled
setTimeout(function () { $(".launchConfront").attr("disabled", button) }, 180)
}
/* ------------------ -------------------------- */
_onDragStart(event) {
super._onDragStart(event)
console.log("DRAG", event)
const diceData = {
diceIndex : $(event.srcElement).data("dice-idx"),
diceValue : $(event.srcElement).data("dice-value"),
}
event.dataTransfer.setData("text/plain", JSON.stringify( diceData ));
console.log(">>>>> DRAG START!!!!", event)
}
/* ------------------ -------------------------- */
async refreshDialog() {
const content = await renderTemplate("systems/fvtt-ecryme/templates/dialogs/confront-dialog.hbs", this.rollData)
this.data.content = content
this.render(true)
diceIndex: $(event.srcElement).data("dice-idx"),
diceValue: $(event.srcElement).data("dice-value"),
}
event.dataTransfer.setData("text/plain", JSON.stringify(diceData));
}
/* -------------------------------------------- */
_onDrop(event) {
let dataJSON = event.dataTransfer.getData('text/plain')
console.log("DICEDATA", dataJSON)
let data = JSON.parse(dataJSON)
let idx = Number(data.diceIndex)
//console.log("DATA", data, event, event.srcElement.className)
if ( event.srcElement.className.includes("execution")) {
this.rollData.availableDices[idx].location = "execution"
if (event.srcElement.className.includes("execution")) {
this.rollData.availableDices[idx].location = "execution"
}
if ( event.srcElement.className.includes("preservation")) {
this.rollData.availableDices[idx].location = "preservation"
if (event.srcElement.className.includes("preservation")) {
this.rollData.availableDices[idx].location = "preservation"
}
if ( event.srcElement.className.includes("dice-list")) {
this.rollData.availableDices[idx].location = "mainpool"
if (event.srcElement.className.includes("dice-list")) {
this.rollData.availableDices[idx].location = "mainpool"
}
this.refreshDialog()
if (this.rollData.availableDices.filter(d => d.location == "execution").length == 2 && this.rollData.availableDices.filter(d => d.location == "preservation").length == 2) {
this.buttonDisabled = false
} else {
this.buttonDisabled = true
}
// Manage total values
this.computeTotals().catch("Error on dice pools")
}
/* -------------------------------------------- */
processTranscendence() {
// Apply Transcend if needed
if (this.rollData.skillTranscendence > 0) {
if (this.rollData.applyTranscendence == "execution") {
this.rollData.executionTotal += this.rollData.skillTranscendence
} else {
this.rollData.preservationTotal += this.rollData.skillTranscendence
}
}
}
/* -------------------------------------------- */
async computeTotals() {
let rollData = this.rollData
let actor = game.actors.get(rollData.actorId)
rollData.executionTotal = rollData.availableDices.filter(d => d.location == "execution").reduce((previous, current) => {
return previous + current.result
}, rollData.skill.value)
rollData.preservationTotal = rollData.availableDices.filter(d => d.location == "preservation").reduce((previous, current) => {
return previous + current.result
}, rollData.skill.value)
this.processTranscendence()
if (rollData.selectedSpecs && rollData.selectedSpecs.length > 0) {
rollData.spec = actor.getSpecialization(rollData.selectedSpecs[0])
this.rollData.executionTotal += "+2"
this.rollData.preservationTotal += "+2"
}
rollData.bonusMalusTraits = 0
for (let t of rollData.traits) {
t.isBonus = false
t.isMalus = false
}
if (rollData.traitsBonus && rollData.traitsBonus.length > 0) {
rollData.traitsBonusList = []
for (let id of rollData.traitsBonus) {
let trait = rollData.traits.find(t => t._id == id)
trait.isBonus = true
rollData.traitsBonusList.push(trait)
rollData.bonusMalusTraits += trait.system.level
}
}
if (rollData.traitsMalus && rollData.traitsMalus.length > 0) {
rollData.traitsMalusList = []
for (let id of rollData.traitsMalus) {
let trait = rollData.traits.find(t => t._id == id)
trait.isMalus = true
rollData.traitsMalusList.push(trait)
rollData.bonusMalusTraits -= trait.system.level
}
}
rollData.executionTotal += rollData.bonusMalusTraits
rollData.executionTotal += rollData.bonusMalusPerso
rollData.preservationTotal += rollData.bonusMalusTraits
rollData.preservationTotal += rollData.bonusMalusPerso
this.refreshDialog()
}
/* -------------------------------------------- */
activateListeners(html) {
super.activateListeners(html);
html.find('#bonusMalusPerso').change((event) => {
this.rollData.bonusMalusPerso = Number(event.currentTarget.value)
this.computeTotals()
})
html.find('#roll-specialization').change((event) => {
this.rollData.selectedSpecs = $('#roll-specialization').val()
this.computeTotals()
})
html.find('#roll-trait-bonus').change((event) => {
this.rollData.traitsBonus = $('#roll-trait-bonus').val()
this.computeTotals()
})
html.find('#roll-trait-malus').change((event) => {
this.rollData.traitsMalus = $('#roll-trait-malus').val()
this.computeTotals()
})
html.find('#roll-select-transcendence').change((event) => {
this.rollData.skillTranscendence = Number($('#roll-select-transcendence').val())
this.computeTotals()
})
html.find('#roll-apply-transcendence').change((event) => {
this.rollData.applyTranscendence = $('#roll-apply-transcendence').val()
this.computeTotals()
})
}
}