From 477c86db0ed8d3c682dcf1bb63418a47cf064413 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Fri, 8 Apr 2022 23:42:01 +0200 Subject: [PATCH] Fix encaissement par joueur --- module/actor/actor.js | 2 +- module/controllers/bol-rolls.js | 58 ++++++++++-------- module/system/bol-utility.js | 74 +++++++++++++---------- system.json | 2 +- templates/chat/rolls/damage-roll-card.hbs | 2 +- 5 files changed, 78 insertions(+), 60 deletions(-) diff --git a/module/actor/actor.js b/module/actor/actor.js index ae89ba2..7b369be 100644 --- a/module/actor/actor.js +++ b/module/actor/actor.js @@ -513,7 +513,7 @@ export class BoLActor extends Actor { async manageHealthState() { let hpID = "lastHP" + this.id let lastHP = await this.getFlag("world", hpID) - if (lastHP != this.data.data.resources.hp.value) { + if (lastHP != this.data.data.resources.hp.value && this.isOwner ) { await this.setFlag("world", hpID, this.data.data.resources.hp.value) if (this.data.data.resources.hp.value <= 0) { ChatMessage.create({ diff --git a/module/controllers/bol-rolls.js b/module/controllers/bol-rolls.js index f683cd0..9827183 100644 --- a/module/controllers/bol-rolls.js +++ b/module/controllers/bol-rolls.js @@ -24,7 +24,7 @@ export class BoLRoll { let rollData = { mode: "attribute", - actor: actor, + actorId: actor.id, attribute: attribute, attrValue: attribute.value, aptValue: 0, @@ -35,6 +35,7 @@ export class BoLRoll { armorInitMalus: actor.getArmorInitMalus(), mod: 0 } + console.log(">>>>>>>>>>", rollData, actor) return this.displayRollDialog(rollData) } @@ -50,7 +51,7 @@ export class BoLRoll { return this.displayRollDialog( { mode: "aptitude", - actor: actor, + actorId: actor.id, attribute: attribute, aptitude: aptitude, attrValue: attribute.value, @@ -82,13 +83,13 @@ export class BoLRoll { // Build the roll structure let rolldata = { mode: "weapon", - actor: actor, + actorId: actor.id, weapon: weapon, isRanged: weaponData.properties.ranged || weaponData.properties.throwing, - target: target, + targetId: target?.id, fightOption: fightOption, careerBonus: 0, - defender: (target) ? game.actors.get(target.data.actorId) : undefined, + defenderId: target?.data?.actorId, attribute: attribute, aptitude: aptitude, attrValue: attribute.value, @@ -129,7 +130,7 @@ export class BoLRoll { let alchemyDef = { mode: "alchemy", - actor: actor, + actorId: actor.id, alchemy: alchemy, attribute: actor.data.data.attributes.mind, attrValue: actor.data.data.attributes.mind.value, @@ -152,7 +153,7 @@ export class BoLRoll { let spellData = spell.data.data let spellDef = { mode: "spell", - actor: actor, + actorId: actor.id, spell: spell, attribute: actor.data.data.attributes.mind, attrValue: actor.data.data.attributes.mind.value, @@ -277,14 +278,16 @@ export class BoLRoll { html.find('#attr').change((event) => { let attrKey = event.currentTarget.value - this.rollData.attribute = duplicate(this.rollData.actor.data.data.attributes[attrKey]) - this.rollData.attrValue = this.rollData.actor.data.data.attributes[attrKey].value + let actor = game.actors.get( this.rollData.actorId) + this.rollData.attribute = duplicate(actor.data.data.attributes[attrKey]) + this.rollData.attrValue = actor.data.data.attributes[attrKey].value this.updateTotalDice() }) html.find('#apt').change((event) => { let aptKey = event.currentTarget.value - this.rollData.aptitude = duplicate(this.rollData.actor.data.data.aptitudes[aptKey]) - this.rollData.aptValue = this.rollData.actor.data.data.aptitudes[aptKey].value + let actor = game.actors.get( this.rollData.actorId) + this.rollData.aptitude = duplicate(actor.data.data.aptitudes[aptKey]) + this.rollData.aptValue = actor.data.data.aptitudes[aptKey].value this.updateTotalDice() }) @@ -348,10 +351,12 @@ export class BoLRoll { // initialize default flags/values const rollOptionTpl = `systems/bol/templates/dialogs/${rollData.mode}-roll-dialog.hbs` - rollData.careers = rollData.actor.careers - rollData.boons = rollData.actor.bonusBoons - rollData.flaws = rollData.actor.malusFlaws - rollData.rollOwnerID = rollData.actor.id + + let actor = game.actors.get( rollData.actorId ) + rollData.careers = actor.careers + rollData.boons = actor.bonusBoons + rollData.flaws = actor.malusFlaws + rollData.rollOwnerID = actor.id rollData.defence = 0 rollData.attackModifier = 0 // Used for fight options rollData.modArmorMalus = 0 // Used for fight options @@ -464,18 +469,20 @@ export class BoLDefaultRoll { this.rollData.isLegendary = false this.rollData.isFumble = (diceTotal === 2) this.rollData.isFailure = !this.rollData.isSuccess - if (this.rollData.reroll == undefined) { - this.rollData.reroll = this.rollData.actor.heroReroll() - } + let actor = game.actors.get( this.rollData.actorId) + if (this.rollData.reroll == undefined) { + this.rollData.reroll = actor.heroReroll() + } + if (this.rollData.registerInit) { - this.rollData.actor.registerInit(r.total, this.rollData.isCritical, this.rollData.isFumble) + actor.registerInit(r.total, this.rollData.isCritical, this.rollData.isFumble) } if (this.rollData.isSuccess && this.rollData.mode == "spell") { // PP cost management - this.rollData.actor.spendPowerPoint(this.rollData.ppCost + this.rollData.ppCostArmor) + actor.spendPowerPoint(this.rollData.ppCost + this.rollData.ppCostArmor) } if (this.rollData.mode == "alchemy") { // PP cost management - this.rollData.actor.resetAlchemyStatus(this.rollData.alchemy.id) + actor.resetAlchemyStatus(this.rollData.alchemy.id) } await this.sendChatMessage() @@ -483,13 +490,14 @@ export class BoLDefaultRoll { /* -------------------------------------------- */ async sendChatMessage() { + let actor = game.actors.get( this.rollData.actorId) this._buildChatMessage(this.rollData).then(msgFlavor => { this.rollData.roll.toMessage({ user: game.user.id, rollMode: game.settings.get("core", "rollMode"), //whisper: BoLUtility.getWhisperRecipientsAndGMs(this.rollData.actor.name), flavor: msgFlavor, - speaker: ChatMessage.getSpeaker({ actor: this.rollData.actor }), + speaker: ChatMessage.getSpeaker({ actor: actor }), }) }) } @@ -528,11 +536,12 @@ export class BoLDefaultRoll { /* -------------------------------------------- */ async sendDamageMessage() { + let actor = game.actors.get( this.rollData.actorId) this._buildDamageChatMessage(this.rollData).then(msgFlavor => { this.rollData.damageRoll.toMessage({ user: game.user.id, flavor: msgFlavor, - speaker: ChatMessage.getSpeaker({ actor: this.rollData.actors }), + speaker: ChatMessage.getSpeaker({ actor: actor }), flags: { msgType: "default" } }) }); @@ -541,8 +550,9 @@ export class BoLDefaultRoll { /* -------------------------------------------- */ getDamageAttributeValue(attrDamage) { let attrDamageValue = 0 + let actor = game.actors.get( this.rollData.actorId) if (attrDamage.includes("vigor")) { - attrDamageValue = this.rollData.actor.data.data.attributes.vigor.value + attrDamageValue = actor.data.data.attributes.vigor.value if (attrDamage.includes("half")) { attrDamageValue = Math.floor(attrDamageValue / 2) } diff --git a/module/system/bol-utility.js b/module/system/bol-utility.js index 5abaae7..ed18c47 100644 --- a/module/system/bol-utility.js +++ b/module/system/bol-utility.js @@ -149,17 +149,17 @@ export class BoLUtility { chatGM.whisper = this.getUsers(user => user.isGM); chatGM.content = "Blind message of " + game.user.name + "
" + chatOptions.content; console.log("blindMessageToGM", chatGM); - game.socket.emit("system.bol", { msg: "msg_gm_chat_message", data: chatGM }); + game.socket.emit("system.bol", { name: "msg_gm_chat_message", data: chatGM }); } /* -------------------------------------------- */ static sendAttackSuccess(attackDef) { - if (attackDef.target) { + if (attackDef.targetId) { // Broadcast to GM or process it directly in case of GM defense if (!game.user.isGM) { - game.socket.emit("system.bol", { msg: "msg_attack_success", data: attackDef }); + game.socket.emit("system.bol", { name: "msg_attack_success", data: duplicate(attackDef) }) } else { - BoLUtility.processAttackSuccess(attackDef); + BoLUtility.processAttackSuccess(attackDef) } } } @@ -170,7 +170,7 @@ export class BoLUtility { if (chatCard.length > 0) { // If the user is the message author or the actor owner, proceed const actor = game.actors.get(data.message.speaker.actor) - console.log("FOUND 1!!! ", actor) + //console.log("FOUND 1!!! ", actor) if (actor && actor.isOwner) return else if (game.user.isGM || data.author.id === game.user.id) return @@ -201,7 +201,8 @@ export class BoLUtility { html.on("click", '.transform-legendary-roll', event => { event.preventDefault(); let rollData = BoLUtility.getLastRoll() - rollData.actor.subHeroPoints(1) + let actor = game.actors.get( rollData.actorId) + actor.subHeroPoints(1) let r = new BoLDefaultRoll(rollData) r.upgradeToLegendary() }) @@ -209,7 +210,8 @@ export class BoLUtility { html.on("click", '.transform-heroic-roll', event => { event.preventDefault(); let rollData = BoLUtility.getLastRoll() - rollData.actor.subHeroPoints(1) + let actor = game.actors.get( rollData.actorId) + actor.subHeroPoints(1) let r = new BoLDefaultRoll(rollData) r.upgradeToHeroic() }) @@ -217,7 +219,8 @@ export class BoLUtility { html.on("click", '.hero-reroll', event => { event.preventDefault(); let rollData = BoLUtility.getLastRoll() - rollData.actor.subHeroPoints(1) + let actor = game.actors.get( rollData.actorId) + actor.subHeroPoints(1) rollData.reroll = false // Disable reroll option for second roll let r = new BoLDefaultRoll(rollData) r.roll(); @@ -228,11 +231,12 @@ export class BoLUtility { let attackId = event.currentTarget.attributes['data-attack-id'].value let defenseMode = event.currentTarget.attributes['data-defense-mode'].value let weaponId = (event.currentTarget.attributes['data-weapon-id']) ? event.currentTarget.attributes['data-weapon-id'].value : -1 - console.log("Process handling !!! -> socket emit") if (game.user.isGM) { + console.log("Process handling !!! -> GM direct damage handling") BoLUtility.processDamageHandling(event, attackId, defenseMode, weaponId) } else { - game.socket.emit("system.bol", { msg: "msg_damage_handling", data: { event: event, attackId: attackId, defenseMode: defenseMode, weaponId: weaponId } }); + console.log("Process handling !!! -> socket emit") + game.socket.emit("system.bol", { name: "msg_damage_handling", data: { event: event, attackId: attackId, defenseMode: defenseMode, weaponId: weaponId } }); } }); } @@ -247,27 +251,30 @@ export class BoLUtility { console.log("Damage Handling", event, attackId, defenseMode, weaponId) // Only GM process this let attackDef = this.attackStore[attackId] - if (attackDef) { - if (attackDef.defenseDone) return; // ?? Why ??? + if (attackDef && attackDef.defenderId) { + if (attackDef.defenseDone) { + return + } // ?? Why ??? attackDef.defenseDone = true attackDef.defenseMode = defenseMode; + let defender = game.actors.get(attackDef.defenderId) if (defenseMode == 'damage-with-armor') { - let armorFormula = attackDef.defender.getArmorFormula() + let armorFormula = defender.getArmorFormula() attackDef.rollArmor = new Roll(armorFormula) attackDef.rollArmor.roll( { async: false } ) console.log("Armor roll ", attackDef.rollArmor) attackDef.armorProtect = (attackDef.rollArmor.total < 0) ? 0 : attackDef.rollArmor.total; attackDef.finalDamage = attackDef.damageRoll.total - attackDef.armorProtect; attackDef.finalDamage = (attackDef.finalDamage < 0) ? 0 : attackDef.finalDamage; - attackDef.defender.sufferDamage(attackDef.finalDamage); + defender.sufferDamage(attackDef.finalDamage); } if (defenseMode == 'damage-without-armor') { attackDef.finalDamage = attackDef.damageRoll.total; - attackDef.defender.sufferDamage(attackDef.finalDamage); + defender.sufferDamage(attackDef.finalDamage); } if (defenseMode == 'hero-reduce-damage') { - let armorFormula = attackDef.defender.getArmorFormula(); + let armorFormula = defender.getArmorFormula(); attackDef.rollArmor = new Roll(armorFormula) attackDef.rollArmor.roll({ async: false }); attackDef.armorProtect = (attackDef.rollArmor.total < 0) ? 0 : attackDef.rollArmor.total; @@ -275,17 +282,17 @@ export class BoLUtility { attackDef.rollHero.roll({ async: false }); attackDef.finalDamage = attackDef.damageRoll.total - attackDef.rollHero.total - attackDef.armorProtect; attackDef.finalDamage = (attackDef.finalDamage < 0) ? 0 : attackDef.finalDamage; - attackDef.defender.sufferDamage(attackDef.finalDamage); - attackDef.defender.subHeroPoints(1); + defender.sufferDamage(attackDef.finalDamage); + defender.subHeroPoints(1); } if (defenseMode == 'hero-in-extremis') { attackDef.finalDamage = 0; - attackDef.weaponHero = attackDef.defender.weapons.find(item => item._id == weaponId); - attackDef.defender.deleteEmbeddedDocuments("Item", [weaponId]); + attackDef.weaponHero = defender.weapons.find(item => item._id == weaponId); + defender.deleteEmbeddedDocuments("Item", [weaponId]); } ChatMessage.create({ - alias: attackDef.defender.name, - whisper: BoLUtility.getWhisperRecipientsAndGMs(attackDef.defender.name), + alias: defender.name, + whisper: BoLUtility.getWhisperRecipientsAndGMs(defender.name), content: await renderTemplate('systems/bol/templates/chat/rolls/defense-result-card.hbs', { attackId: attackDef.id, attacker: attackDef.attacker, @@ -293,7 +300,7 @@ export class BoLUtility { rollHero: attackDef.rollHero, weaponHero: attackDef.weaponHero, armorProtect: attackDef.armorProtect, - defender: attackDef.defender, + defender: defender, defenseMode: attackDef.defenseMode, finalDamage: attackDef.finalDamage }) @@ -365,7 +372,7 @@ export class BoLUtility { static getTarget() { if (game.user.targets && game.user.targets.size == 1) { for (let target of game.user.targets) { - return target; + return target } } return undefined; @@ -373,20 +380,22 @@ export class BoLUtility { /* -------------------------------------------- */ static async processAttackSuccess(attackDef) { - if (!game.user.isGM) { // Only GM process this - return; + console.log("Attack success processing", attackDef) + if (!game.user.isGM || !attackDef.defenderId) { // Only GM process this + return } // Build and send the defense message to the relevant people (ie GM + defender) - let defenderWeapons = attackDef.defender.weapons; + let defender = game.actors.get(attackDef.defenderId) + let defenderWeapons = defender.weapons console.log("DEF WEP", attackDef) - this.attackStore[attackDef.id] = attackDef; // Store ! + this.attackStore[attackDef.id] = attackDef // Store ! ChatMessage.create({ - alias: attackDef.defender.name, - whisper: BoLUtility.getWhisperRecipientsAndGMs(attackDef.defender.name), + alias: defender.name, + whisper: BoLUtility.getWhisperRecipientsAndGMs(defender.name), content: await renderTemplate('systems/bol/templates/chat/rolls/defense-request-card.hbs', { attackId: attackDef.id, attacker: attackDef.attacker, - defender: attackDef.defender, + defender: defender, defenderWeapons: defenderWeapons, damageTotal: attackDef.damageRoll.total, damagesIgnoresArmor: attackDef.damagesIgnoresArmor, @@ -397,10 +406,9 @@ export class BoLUtility { /* -------------------------------------------- */ static onSocketMessage(sockmsg) { if (sockmsg.name == "msg_attack_success") { - BoLUtility.processAttackSuccess(sockmsg.data); + BoLUtility.processAttackSuccess(sockmsg.data) } if (sockmsg.name == "msg_damage_handling") { - console.log("Msg received !!!!") BoLUtility.processDamageHandling(sockmsg.data.event, sockmsg.data.attackId, sockmsg.data.defenseMode) } } diff --git a/system.json b/system.json index 0c5e594..88ee7b8 100644 --- a/system.json +++ b/system.json @@ -14,7 +14,7 @@ "url": "https://github.com/ZigmundKreud/bol", "license": "LICENSE.txt", "flags": {}, - "version": "1.3.0", + "version": "1.3.1", "minimumCoreVersion": "0.8.6", "compatibleCoreVersion": "9", "scripts": [], diff --git a/templates/chat/rolls/damage-roll-card.hbs b/templates/chat/rolls/damage-roll-card.hbs index ee87853..08e2600 100644 --- a/templates/chat/rolls/damage-roll-card.hbs +++ b/templates/chat/rolls/damage-roll-card.hbs @@ -5,7 +5,7 @@ {{/if}}
- {{#if target}} + {{#if targetId}}