diff --git a/module/rdd-empoignade.js b/module/rdd-empoignade.js index 3985e04d..e0bdd52d 100644 --- a/module/rdd-empoignade.js +++ b/module/rdd-empoignade.js @@ -104,6 +104,7 @@ export class RdDEmpoignade { } return undefined; } + /* -------------------------------------------- */ static getMalusTaille(emp, attacker, defender) { // Si pas empoigné, alors 0 @@ -116,11 +117,48 @@ export class RdDEmpoignade { const signDiff = diffTaille > 0 ? 1 : -1 if (diffTailleAbs > 2) { - return signDiff*(diffTailleAbs-1) + return signDiff * (diffTailleAbs - 1) } return 0 } + static isActionAutorisee(mode, attacker, defender) { + const acting = RdDEmpoignade.isActionDefenseur(mode) ? defender : attacker; + if (acting.getUserLevel(game.user) < CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER) { + ui.notifications.warn(`Vous n'êtes pas autorisé à choisir l'action de ${acting.name}`) + return false; + } + return true + } + + static isActionDefenseur(mode) { + switch (mode) { + case "liberer": + case "contrer-empoigner": + return true; + } + return false; + } + + /* -------------------------------------------- */ + static async onAttaqueEmpoignade(attacker, defender) { + if (!RdDEmpoignade.isActionAutorisee("empoigner", attacker, defender)) { + return + } + + let empoignade = RdDEmpoignade.getEmpoignade(attacker, defender) + const isNouvelle = empoignade == undefined; + empoignade = empoignade ?? (await RdDEmpoignade.createEmpoignade(attacker, defender)) + //console.log("W.", empoignade, defender.hasArmeeMeleeEquipee()) + if ((isNouvelle || empoignade.system.pointsemp == 0) && defender.hasArmeeMeleeEquipee()) { + ChatUtility.createChatWithRollMode(attacker.name, { + content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-empoignade-valider.html`, { attacker: attacker, defender: defender }) + }) + } else { + await this.onAttaqueEmpoignadeValidee(attacker, defender) + } + } + /* -------------------------------------------- */ static async onAttaqueEmpoignadeValidee(attacker, defender) { let empoignade = RdDEmpoignade.getEmpoignade(attacker, defender) @@ -129,6 +167,10 @@ export class RdDEmpoignade { let mode = (empoignade && empoignade.system.empoigneurid == attacker.id) ? "empoigner" : "liberer" + if (!RdDEmpoignade.isActionAutorisee(mode, attacker, defender)) { + return + } + let rollData = { mode, empoignade, attacker, defender, isEmpoignade: true, @@ -147,21 +189,6 @@ export class RdDEmpoignade { } } - /* -------------------------------------------- */ - static async onAttaqueEmpoignade(attacker, defender) { - let empoignade = RdDEmpoignade.getEmpoignade(attacker, defender) - const isNouvelle = empoignade == undefined; - empoignade = empoignade ?? (await RdDEmpoignade.createEmpoignade(attacker, defender)) - //console.log("W.", empoignade, defender.hasArmeeMeleeEquipee()) - if ((isNouvelle || empoignade.system.pointsemp == 0) && defender.hasArmeeMeleeEquipee()) { - ChatUtility.createChatWithRollMode(attacker.name, { - content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-empoignade-valider.html`, { attacker: attacker, defender: defender }) - }) - } else { - await this.onAttaqueEmpoignadeValidee(attacker, defender) - } - } - /* -------------------------------------------- */ static async onAttaqueEmpoignadeFromItem(empoignade) { let attacker = game.actors.get(empoignade.system.empoigneurid) @@ -206,6 +233,10 @@ export class RdDEmpoignade { static async onDefenseEmpoignade(attackerRoll, mode, competenceName = "Corps à corps", carac = "melee") { let attacker = game.actors.get(attackerRoll.attacker.id) let defender = game.actors.get(attackerRoll.defender.id) + if (!RdDEmpoignade.isActionAutorisee(mode, attacker, defender)) { + return + } + let empoignade = this.getEmpoignade(attacker, defender) if (!empoignade) { @@ -286,16 +317,15 @@ export class RdDEmpoignade { let defender = game.actors.get(empoignade.system.empoigneid) let emp = RdDEmpoignade.getEmpoignadeById(defender, empoignade.system.empoignadeid) await defender.deleteEmbeddedDocuments('Item', [emp._id]) - - //let attacker = game.actors.get(empoignade.system.empoigneurid) - //emp = RdDEmpoignade.getEmpoignadeById(attacker, empoignade.system.empoignadeid) - //await attacker.deleteEmbeddedDocuments('Item', [emp._id]) } /* -------------------------------------------- */ static async entrainerAuSol(rollData) { let attacker = game.actors.get(rollData.attacker.id) let defender = game.actors.get(rollData.defender.id) + if (!RdDEmpoignade.isActionAutorisee("attaquant", attacker, defender)) { + return + } let empoignade = this.getEmpoignade(attacker, defender) empoignade.system.ausol = true @@ -312,6 +342,9 @@ export class RdDEmpoignade { static async projeterAuSol(rollData) { let attacker = game.actors.get(rollData.attacker.id) let defender = game.actors.get(rollData.defender.id) + if (!RdDEmpoignade.isActionAutorisee("attaquant", attacker, defender)) { + return + } let empoignade = this.getEmpoignade(attacker, defender) await defender.setEffect(STATUSES.StatusProne, true); @@ -320,10 +353,14 @@ export class RdDEmpoignade { let msg = await RdDResolutionTable.displayRollData(rollData, attacker, 'chat-empoignade-projeter-sol.html'); RdDEmpoignade.storeRollEmpoignade(msg, rollData); } + /* -------------------------------------------- */ static async perteEndurance(rollData, perteMode) { let attacker = game.actors.get(rollData.attacker.id) let defender = game.actors.get(rollData.defender.id) + if (!RdDEmpoignade.isActionAutorisee("attaquant", attacker, defender)) { + return + } let empoignade = this.getEmpoignade(attacker, defender) //console.log("Perte d'endurance :!!!", perteMode)