Fix encaissement par joueur

This commit is contained in:
sladecraven 2022-04-08 23:42:01 +02:00
parent 38025666e9
commit 477c86db0e
5 changed files with 78 additions and 60 deletions

View File

@ -513,7 +513,7 @@ export class BoLActor extends Actor {
async manageHealthState() { async manageHealthState() {
let hpID = "lastHP" + this.id let hpID = "lastHP" + this.id
let lastHP = await this.getFlag("world", hpID) 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) await this.setFlag("world", hpID, this.data.data.resources.hp.value)
if (this.data.data.resources.hp.value <= 0) { if (this.data.data.resources.hp.value <= 0) {
ChatMessage.create({ ChatMessage.create({

View File

@ -24,7 +24,7 @@ export class BoLRoll {
let rollData = { let rollData = {
mode: "attribute", mode: "attribute",
actor: actor, actorId: actor.id,
attribute: attribute, attribute: attribute,
attrValue: attribute.value, attrValue: attribute.value,
aptValue: 0, aptValue: 0,
@ -35,6 +35,7 @@ export class BoLRoll {
armorInitMalus: actor.getArmorInitMalus(), armorInitMalus: actor.getArmorInitMalus(),
mod: 0 mod: 0
} }
console.log(">>>>>>>>>>", rollData, actor)
return this.displayRollDialog(rollData) return this.displayRollDialog(rollData)
} }
@ -50,7 +51,7 @@ export class BoLRoll {
return this.displayRollDialog( return this.displayRollDialog(
{ {
mode: "aptitude", mode: "aptitude",
actor: actor, actorId: actor.id,
attribute: attribute, attribute: attribute,
aptitude: aptitude, aptitude: aptitude,
attrValue: attribute.value, attrValue: attribute.value,
@ -82,13 +83,13 @@ export class BoLRoll {
// Build the roll structure // Build the roll structure
let rolldata = { let rolldata = {
mode: "weapon", mode: "weapon",
actor: actor, actorId: actor.id,
weapon: weapon, weapon: weapon,
isRanged: weaponData.properties.ranged || weaponData.properties.throwing, isRanged: weaponData.properties.ranged || weaponData.properties.throwing,
target: target, targetId: target?.id,
fightOption: fightOption, fightOption: fightOption,
careerBonus: 0, careerBonus: 0,
defender: (target) ? game.actors.get(target.data.actorId) : undefined, defenderId: target?.data?.actorId,
attribute: attribute, attribute: attribute,
aptitude: aptitude, aptitude: aptitude,
attrValue: attribute.value, attrValue: attribute.value,
@ -129,7 +130,7 @@ export class BoLRoll {
let alchemyDef = { let alchemyDef = {
mode: "alchemy", mode: "alchemy",
actor: actor, actorId: actor.id,
alchemy: alchemy, alchemy: alchemy,
attribute: actor.data.data.attributes.mind, attribute: actor.data.data.attributes.mind,
attrValue: actor.data.data.attributes.mind.value, attrValue: actor.data.data.attributes.mind.value,
@ -152,7 +153,7 @@ export class BoLRoll {
let spellData = spell.data.data let spellData = spell.data.data
let spellDef = { let spellDef = {
mode: "spell", mode: "spell",
actor: actor, actorId: actor.id,
spell: spell, spell: spell,
attribute: actor.data.data.attributes.mind, attribute: actor.data.data.attributes.mind,
attrValue: actor.data.data.attributes.mind.value, attrValue: actor.data.data.attributes.mind.value,
@ -277,14 +278,16 @@ export class BoLRoll {
html.find('#attr').change((event) => { html.find('#attr').change((event) => {
let attrKey = event.currentTarget.value let attrKey = event.currentTarget.value
this.rollData.attribute = duplicate(this.rollData.actor.data.data.attributes[attrKey]) let actor = game.actors.get( this.rollData.actorId)
this.rollData.attrValue = this.rollData.actor.data.data.attributes[attrKey].value this.rollData.attribute = duplicate(actor.data.data.attributes[attrKey])
this.rollData.attrValue = actor.data.data.attributes[attrKey].value
this.updateTotalDice() this.updateTotalDice()
}) })
html.find('#apt').change((event) => { html.find('#apt').change((event) => {
let aptKey = event.currentTarget.value let aptKey = event.currentTarget.value
this.rollData.aptitude = duplicate(this.rollData.actor.data.data.aptitudes[aptKey]) let actor = game.actors.get( this.rollData.actorId)
this.rollData.aptValue = this.rollData.actor.data.data.aptitudes[aptKey].value this.rollData.aptitude = duplicate(actor.data.data.aptitudes[aptKey])
this.rollData.aptValue = actor.data.data.aptitudes[aptKey].value
this.updateTotalDice() this.updateTotalDice()
}) })
@ -348,10 +351,12 @@ export class BoLRoll {
// initialize default flags/values // initialize default flags/values
const rollOptionTpl = `systems/bol/templates/dialogs/${rollData.mode}-roll-dialog.hbs` const rollOptionTpl = `systems/bol/templates/dialogs/${rollData.mode}-roll-dialog.hbs`
rollData.careers = rollData.actor.careers
rollData.boons = rollData.actor.bonusBoons let actor = game.actors.get( rollData.actorId )
rollData.flaws = rollData.actor.malusFlaws rollData.careers = actor.careers
rollData.rollOwnerID = rollData.actor.id rollData.boons = actor.bonusBoons
rollData.flaws = actor.malusFlaws
rollData.rollOwnerID = actor.id
rollData.defence = 0 rollData.defence = 0
rollData.attackModifier = 0 // Used for fight options rollData.attackModifier = 0 // Used for fight options
rollData.modArmorMalus = 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.isLegendary = false
this.rollData.isFumble = (diceTotal === 2) this.rollData.isFumble = (diceTotal === 2)
this.rollData.isFailure = !this.rollData.isSuccess this.rollData.isFailure = !this.rollData.isSuccess
let actor = game.actors.get( this.rollData.actorId)
if (this.rollData.reroll == undefined) { if (this.rollData.reroll == undefined) {
this.rollData.reroll = this.rollData.actor.heroReroll() this.rollData.reroll = actor.heroReroll()
} }
if (this.rollData.registerInit) { 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 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 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() await this.sendChatMessage()
@ -483,13 +490,14 @@ export class BoLDefaultRoll {
/* -------------------------------------------- */ /* -------------------------------------------- */
async sendChatMessage() { async sendChatMessage() {
let actor = game.actors.get( this.rollData.actorId)
this._buildChatMessage(this.rollData).then(msgFlavor => { this._buildChatMessage(this.rollData).then(msgFlavor => {
this.rollData.roll.toMessage({ this.rollData.roll.toMessage({
user: game.user.id, user: game.user.id,
rollMode: game.settings.get("core", "rollMode"), rollMode: game.settings.get("core", "rollMode"),
//whisper: BoLUtility.getWhisperRecipientsAndGMs(this.rollData.actor.name), //whisper: BoLUtility.getWhisperRecipientsAndGMs(this.rollData.actor.name),
flavor: msgFlavor, flavor: msgFlavor,
speaker: ChatMessage.getSpeaker({ actor: this.rollData.actor }), speaker: ChatMessage.getSpeaker({ actor: actor }),
}) })
}) })
} }
@ -528,11 +536,12 @@ export class BoLDefaultRoll {
/* -------------------------------------------- */ /* -------------------------------------------- */
async sendDamageMessage() { async sendDamageMessage() {
let actor = game.actors.get( this.rollData.actorId)
this._buildDamageChatMessage(this.rollData).then(msgFlavor => { this._buildDamageChatMessage(this.rollData).then(msgFlavor => {
this.rollData.damageRoll.toMessage({ this.rollData.damageRoll.toMessage({
user: game.user.id, user: game.user.id,
flavor: msgFlavor, flavor: msgFlavor,
speaker: ChatMessage.getSpeaker({ actor: this.rollData.actors }), speaker: ChatMessage.getSpeaker({ actor: actor }),
flags: { msgType: "default" } flags: { msgType: "default" }
}) })
}); });
@ -541,8 +550,9 @@ export class BoLDefaultRoll {
/* -------------------------------------------- */ /* -------------------------------------------- */
getDamageAttributeValue(attrDamage) { getDamageAttributeValue(attrDamage) {
let attrDamageValue = 0 let attrDamageValue = 0
let actor = game.actors.get( this.rollData.actorId)
if (attrDamage.includes("vigor")) { if (attrDamage.includes("vigor")) {
attrDamageValue = this.rollData.actor.data.data.attributes.vigor.value attrDamageValue = actor.data.data.attributes.vigor.value
if (attrDamage.includes("half")) { if (attrDamage.includes("half")) {
attrDamageValue = Math.floor(attrDamageValue / 2) attrDamageValue = Math.floor(attrDamageValue / 2)
} }

View File

@ -149,17 +149,17 @@ export class BoLUtility {
chatGM.whisper = this.getUsers(user => user.isGM); chatGM.whisper = this.getUsers(user => user.isGM);
chatGM.content = "Blind message of " + game.user.name + "<br>" + chatOptions.content; chatGM.content = "Blind message of " + game.user.name + "<br>" + chatOptions.content;
console.log("blindMessageToGM", chatGM); 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) { static sendAttackSuccess(attackDef) {
if (attackDef.target) { if (attackDef.targetId) {
// Broadcast to GM or process it directly in case of GM defense // Broadcast to GM or process it directly in case of GM defense
if (!game.user.isGM) { 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 { } else {
BoLUtility.processAttackSuccess(attackDef); BoLUtility.processAttackSuccess(attackDef)
} }
} }
} }
@ -170,7 +170,7 @@ export class BoLUtility {
if (chatCard.length > 0) { if (chatCard.length > 0) {
// If the user is the message author or the actor owner, proceed // If the user is the message author or the actor owner, proceed
const actor = game.actors.get(data.message.speaker.actor) const actor = game.actors.get(data.message.speaker.actor)
console.log("FOUND 1!!! ", actor) //console.log("FOUND 1!!! ", actor)
if (actor && actor.isOwner) return if (actor && actor.isOwner) return
else if (game.user.isGM || data.author.id === game.user.id) 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 => { html.on("click", '.transform-legendary-roll', event => {
event.preventDefault(); event.preventDefault();
let rollData = BoLUtility.getLastRoll() let rollData = BoLUtility.getLastRoll()
rollData.actor.subHeroPoints(1) let actor = game.actors.get( rollData.actorId)
actor.subHeroPoints(1)
let r = new BoLDefaultRoll(rollData) let r = new BoLDefaultRoll(rollData)
r.upgradeToLegendary() r.upgradeToLegendary()
}) })
@ -209,7 +210,8 @@ export class BoLUtility {
html.on("click", '.transform-heroic-roll', event => { html.on("click", '.transform-heroic-roll', event => {
event.preventDefault(); event.preventDefault();
let rollData = BoLUtility.getLastRoll() let rollData = BoLUtility.getLastRoll()
rollData.actor.subHeroPoints(1) let actor = game.actors.get( rollData.actorId)
actor.subHeroPoints(1)
let r = new BoLDefaultRoll(rollData) let r = new BoLDefaultRoll(rollData)
r.upgradeToHeroic() r.upgradeToHeroic()
}) })
@ -217,7 +219,8 @@ export class BoLUtility {
html.on("click", '.hero-reroll', event => { html.on("click", '.hero-reroll', event => {
event.preventDefault(); event.preventDefault();
let rollData = BoLUtility.getLastRoll() 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 rollData.reroll = false // Disable reroll option for second roll
let r = new BoLDefaultRoll(rollData) let r = new BoLDefaultRoll(rollData)
r.roll(); r.roll();
@ -228,11 +231,12 @@ export class BoLUtility {
let attackId = event.currentTarget.attributes['data-attack-id'].value let attackId = event.currentTarget.attributes['data-attack-id'].value
let defenseMode = event.currentTarget.attributes['data-defense-mode'].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 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) { if (game.user.isGM) {
console.log("Process handling !!! -> GM direct damage handling")
BoLUtility.processDamageHandling(event, attackId, defenseMode, weaponId) BoLUtility.processDamageHandling(event, attackId, defenseMode, weaponId)
} else { } 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) console.log("Damage Handling", event, attackId, defenseMode, weaponId)
// Only GM process this // Only GM process this
let attackDef = this.attackStore[attackId] let attackDef = this.attackStore[attackId]
if (attackDef) { if (attackDef && attackDef.defenderId) {
if (attackDef.defenseDone) return; // ?? Why ??? if (attackDef.defenseDone) {
return
} // ?? Why ???
attackDef.defenseDone = true attackDef.defenseDone = true
attackDef.defenseMode = defenseMode; attackDef.defenseMode = defenseMode;
let defender = game.actors.get(attackDef.defenderId)
if (defenseMode == 'damage-with-armor') { if (defenseMode == 'damage-with-armor') {
let armorFormula = attackDef.defender.getArmorFormula() let armorFormula = defender.getArmorFormula()
attackDef.rollArmor = new Roll(armorFormula) attackDef.rollArmor = new Roll(armorFormula)
attackDef.rollArmor.roll( { async: false } ) attackDef.rollArmor.roll( { async: false } )
console.log("Armor roll ", attackDef.rollArmor) console.log("Armor roll ", attackDef.rollArmor)
attackDef.armorProtect = (attackDef.rollArmor.total < 0) ? 0 : attackDef.rollArmor.total; attackDef.armorProtect = (attackDef.rollArmor.total < 0) ? 0 : attackDef.rollArmor.total;
attackDef.finalDamage = attackDef.damageRoll.total - attackDef.armorProtect; attackDef.finalDamage = attackDef.damageRoll.total - attackDef.armorProtect;
attackDef.finalDamage = (attackDef.finalDamage < 0) ? 0 : attackDef.finalDamage; attackDef.finalDamage = (attackDef.finalDamage < 0) ? 0 : attackDef.finalDamage;
attackDef.defender.sufferDamage(attackDef.finalDamage); defender.sufferDamage(attackDef.finalDamage);
} }
if (defenseMode == 'damage-without-armor') { if (defenseMode == 'damage-without-armor') {
attackDef.finalDamage = attackDef.damageRoll.total; attackDef.finalDamage = attackDef.damageRoll.total;
attackDef.defender.sufferDamage(attackDef.finalDamage); defender.sufferDamage(attackDef.finalDamage);
} }
if (defenseMode == 'hero-reduce-damage') { if (defenseMode == 'hero-reduce-damage') {
let armorFormula = attackDef.defender.getArmorFormula(); let armorFormula = defender.getArmorFormula();
attackDef.rollArmor = new Roll(armorFormula) attackDef.rollArmor = new Roll(armorFormula)
attackDef.rollArmor.roll({ async: false }); attackDef.rollArmor.roll({ async: false });
attackDef.armorProtect = (attackDef.rollArmor.total < 0) ? 0 : attackDef.rollArmor.total; attackDef.armorProtect = (attackDef.rollArmor.total < 0) ? 0 : attackDef.rollArmor.total;
@ -275,17 +282,17 @@ export class BoLUtility {
attackDef.rollHero.roll({ async: false }); attackDef.rollHero.roll({ async: false });
attackDef.finalDamage = attackDef.damageRoll.total - attackDef.rollHero.total - attackDef.armorProtect; attackDef.finalDamage = attackDef.damageRoll.total - attackDef.rollHero.total - attackDef.armorProtect;
attackDef.finalDamage = (attackDef.finalDamage < 0) ? 0 : attackDef.finalDamage; attackDef.finalDamage = (attackDef.finalDamage < 0) ? 0 : attackDef.finalDamage;
attackDef.defender.sufferDamage(attackDef.finalDamage); defender.sufferDamage(attackDef.finalDamage);
attackDef.defender.subHeroPoints(1); defender.subHeroPoints(1);
} }
if (defenseMode == 'hero-in-extremis') { if (defenseMode == 'hero-in-extremis') {
attackDef.finalDamage = 0; attackDef.finalDamage = 0;
attackDef.weaponHero = attackDef.defender.weapons.find(item => item._id == weaponId); attackDef.weaponHero = defender.weapons.find(item => item._id == weaponId);
attackDef.defender.deleteEmbeddedDocuments("Item", [weaponId]); defender.deleteEmbeddedDocuments("Item", [weaponId]);
} }
ChatMessage.create({ ChatMessage.create({
alias: attackDef.defender.name, alias: defender.name,
whisper: BoLUtility.getWhisperRecipientsAndGMs(attackDef.defender.name), whisper: BoLUtility.getWhisperRecipientsAndGMs(defender.name),
content: await renderTemplate('systems/bol/templates/chat/rolls/defense-result-card.hbs', { content: await renderTemplate('systems/bol/templates/chat/rolls/defense-result-card.hbs', {
attackId: attackDef.id, attackId: attackDef.id,
attacker: attackDef.attacker, attacker: attackDef.attacker,
@ -293,7 +300,7 @@ export class BoLUtility {
rollHero: attackDef.rollHero, rollHero: attackDef.rollHero,
weaponHero: attackDef.weaponHero, weaponHero: attackDef.weaponHero,
armorProtect: attackDef.armorProtect, armorProtect: attackDef.armorProtect,
defender: attackDef.defender, defender: defender,
defenseMode: attackDef.defenseMode, defenseMode: attackDef.defenseMode,
finalDamage: attackDef.finalDamage finalDamage: attackDef.finalDamage
}) })
@ -365,7 +372,7 @@ export class BoLUtility {
static getTarget() { static getTarget() {
if (game.user.targets && game.user.targets.size == 1) { if (game.user.targets && game.user.targets.size == 1) {
for (let target of game.user.targets) { for (let target of game.user.targets) {
return target; return target
} }
} }
return undefined; return undefined;
@ -373,20 +380,22 @@ export class BoLUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static async processAttackSuccess(attackDef) { static async processAttackSuccess(attackDef) {
if (!game.user.isGM) { // Only GM process this console.log("Attack success processing", attackDef)
return; if (!game.user.isGM || !attackDef.defenderId) { // Only GM process this
return
} }
// Build and send the defense message to the relevant people (ie GM + defender) // 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) console.log("DEF WEP", attackDef)
this.attackStore[attackDef.id] = attackDef; // Store ! this.attackStore[attackDef.id] = attackDef // Store !
ChatMessage.create({ ChatMessage.create({
alias: attackDef.defender.name, alias: defender.name,
whisper: BoLUtility.getWhisperRecipientsAndGMs(attackDef.defender.name), whisper: BoLUtility.getWhisperRecipientsAndGMs(defender.name),
content: await renderTemplate('systems/bol/templates/chat/rolls/defense-request-card.hbs', { content: await renderTemplate('systems/bol/templates/chat/rolls/defense-request-card.hbs', {
attackId: attackDef.id, attackId: attackDef.id,
attacker: attackDef.attacker, attacker: attackDef.attacker,
defender: attackDef.defender, defender: defender,
defenderWeapons: defenderWeapons, defenderWeapons: defenderWeapons,
damageTotal: attackDef.damageRoll.total, damageTotal: attackDef.damageRoll.total,
damagesIgnoresArmor: attackDef.damagesIgnoresArmor, damagesIgnoresArmor: attackDef.damagesIgnoresArmor,
@ -397,10 +406,9 @@ export class BoLUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static onSocketMessage(sockmsg) { static onSocketMessage(sockmsg) {
if (sockmsg.name == "msg_attack_success") { if (sockmsg.name == "msg_attack_success") {
BoLUtility.processAttackSuccess(sockmsg.data); BoLUtility.processAttackSuccess(sockmsg.data)
} }
if (sockmsg.name == "msg_damage_handling") { if (sockmsg.name == "msg_damage_handling") {
console.log("Msg received !!!!")
BoLUtility.processDamageHandling(sockmsg.data.event, sockmsg.data.attackId, sockmsg.data.defenseMode) BoLUtility.processDamageHandling(sockmsg.data.event, sockmsg.data.attackId, sockmsg.data.defenseMode)
} }
} }

View File

@ -14,7 +14,7 @@
"url": "https://github.com/ZigmundKreud/bol", "url": "https://github.com/ZigmundKreud/bol",
"license": "LICENSE.txt", "license": "LICENSE.txt",
"flags": {}, "flags": {},
"version": "1.3.0", "version": "1.3.1",
"minimumCoreVersion": "0.8.6", "minimumCoreVersion": "0.8.6",
"compatibleCoreVersion": "9", "compatibleCoreVersion": "9",
"scripts": [], "scripts": [],

View File

@ -5,7 +5,7 @@
{{/if}} {{/if}}
<div class="actions-section"> <div class="actions-section">
{{#if target}} {{#if targetId}}
<div id="{{applyId}}"> <div id="{{applyId}}">
<button class="chat-damage-apply" data-attack-id="{{id}}">Appliquer les dommages à la cible</button> <button class="chat-damage-apply" data-attack-id="{{id}}">Appliquer les dommages à la cible</button>
</div> </div>