Gestion opposition en combat melee
All checks were successful
Release Creation / build (release) Successful in 39s
All checks were successful
Release Creation / build (release) Successful in 39s
This commit is contained in:
@ -201,11 +201,13 @@ export class TeDeumUtility {
|
||||
ui.notifications.info("Opposition démarrée avec " + rollData.alias);
|
||||
} else {
|
||||
// Perform the opposition
|
||||
let rWinner = this.currentOpposition
|
||||
let isAttackWinner = true
|
||||
let rWinner = this.currentOpposition
|
||||
let rLooser = rollData
|
||||
if (rWinner.total < rLooser.total) {
|
||||
rWinner = rollData
|
||||
rLooser = this.currentOpposition
|
||||
isAttackWinner = false
|
||||
}
|
||||
this.currentOpposition = undefined // Reset opposition
|
||||
let oppositionData = {
|
||||
@ -216,14 +218,32 @@ export class TeDeumUtility {
|
||||
content: await renderTemplate(`systems/fvtt-te-deum/templates/chat/chat-opposition-result.hbs`, oppositionData)
|
||||
})
|
||||
await msg.setFlag("world", "te-deum-rolldata", rollData)
|
||||
|
||||
// Si le gagnant est l'attaquant, appliquer les dégats sur la victime
|
||||
if ( isAttackWinner && rWinner.isSuccess && rWinner.mode == "arme" && rWinner.arme?.system.typeArme == "melee" && rWinner.defenderTokenId) {
|
||||
this.appliquerDegats(rWinner)
|
||||
}
|
||||
|
||||
console.log("Rolldata result", rollData)
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */ /* -------------------------------------------- */
|
||||
static async appliquerDegats(rollData) {
|
||||
await this.processAttaqueMelee(rollData)
|
||||
let defenderToken = canvas.tokens.placeables.find(t => t.id == rollData.defenderTokenId)
|
||||
if (defenderToken) {
|
||||
let actor = defenderToken.actor
|
||||
await actor.appliquerDegats(rollData)
|
||||
} else {
|
||||
ui.notifications.error("Impossible de trouver la cible de l'attaque, aucun degats appliqué")
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */ /* -------------------------------------------- */
|
||||
static async chatListeners(html) {
|
||||
|
||||
html.on("click", '.chat-command-button', event => {
|
||||
html.on("click", '.chat-command-opposition', event => {
|
||||
let messageId = TeDeumUtility.findChatMessageId(event.currentTarget)
|
||||
let message = game.messages.get(messageId)
|
||||
let rollData = message.getFlag("world", "te-deum-rolldata")
|
||||
@ -231,6 +251,14 @@ export class TeDeumUtility {
|
||||
TeDeumUtility.manageOpposition(rollData, messageId)
|
||||
}
|
||||
})
|
||||
html.on("click", '.chat-command-appliquer-degats', event => {
|
||||
let messageId = TeDeumUtility.findChatMessageId(event.currentTarget)
|
||||
let message = game.messages.get(messageId)
|
||||
let rollData = message.getFlag("world", "te-deum-rolldata")
|
||||
if (rollData) {
|
||||
TeDeumUtility.appliquerDegats(rollData, messageId)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -466,18 +494,13 @@ export class TeDeumUtility {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async processAttaqueMelee(rollData) {
|
||||
if (rollData.arme?.system.typeArme != "melee") {
|
||||
return
|
||||
}
|
||||
if (rollData.isSuccess) {
|
||||
await this.getLocalisation(rollData)
|
||||
let actor = game.actors.get(rollData.actorId)
|
||||
let bDegats = actor.getBonusDegats()
|
||||
let degatsRoll = await new Roll(rollData.arme.system.degats + "+" + bDegats.value).roll()
|
||||
await this.showDiceSoNice(degatsRoll, game.settings.get("core", "rollMode"))
|
||||
rollData.degatsRoll = foundry.utils.duplicate(degatsRoll)
|
||||
rollData.degats = degatsRoll.total
|
||||
}
|
||||
await this.getLocalisation(rollData)
|
||||
let actor = game.actors.get(rollData.actorId)
|
||||
let bDegats = actor.getBonusDegats()
|
||||
let degatsRoll = await new Roll(rollData.arme.system.degats + "+" + bDegats.value).roll()
|
||||
await this.showDiceSoNice(degatsRoll, game.settings.get("core", "rollMode"))
|
||||
rollData.degatsRoll = foundry.utils.duplicate(degatsRoll)
|
||||
rollData.degats = degatsRoll.total
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -520,7 +543,6 @@ export class TeDeumUtility {
|
||||
await this.computeResults(rollData)
|
||||
|
||||
await this.processAttaqueDistance(rollData)
|
||||
await this.processAttaqueMelee(rollData)
|
||||
|
||||
let msg = await this.createChatWithRollMode(rollData.alias, {
|
||||
content: await renderTemplate(`systems/fvtt-te-deum/templates/chat/chat-generic-result.hbs`, rollData)
|
||||
@ -536,15 +558,6 @@ export class TeDeumUtility {
|
||||
if (rollData.isReussiteCritique || rollData.isEchecCritique) {
|
||||
actor.modifyXP(rollData.carac.key, 1)
|
||||
}
|
||||
|
||||
// gestion degats automatique
|
||||
if (rollData.arme && rollData.defenderTokenId) {
|
||||
let defenderToken = canvas.tokens.placeables.find(t => t.id == rollData.defenderTokenId)
|
||||
if (defenderToken) {
|
||||
let actor = defenderToken.actor
|
||||
await actor.appliquerDegats(rollData)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
Reference in New Issue
Block a user