Enhance and bugfixes for combat

This commit is contained in:
sladecraven 2022-01-01 23:32:48 +01:00
parent 5915b4a0ac
commit 721cb08059
6 changed files with 425 additions and 330 deletions

View File

@ -217,7 +217,7 @@ export class BoLActor extends Actor {
for (let protect of protectWorn) { for (let protect of protectWorn) {
if ( protect.data.subtype == 'helm') { if ( protect.data.subtype == 'helm') {
formula += "+1" formula += "+1"
} else { } else if ( protect.data.subtype == 'armor') {
formula += "+" + protect.data.properties.soak.formula; formula += "+" + protect.data.properties.soak.formula;
} }
} }

View File

@ -282,6 +282,7 @@ export class BoLAttackRoll {
async roll() { async roll() {
const r = new Roll(this.attackDef.formula); const r = new Roll(this.attackDef.formula);
await r.roll({ "async": false }); await r.roll({ "async": false });
//await BoLUtility.showDiceSoNice(r);
const activeDice = r.terms[0].results.filter(r => r.active); const activeDice = r.terms[0].results.filter(r => r.active);
const diceTotal = activeDice.map(r => r.result).reduce((a, b) => a + b); const diceTotal = activeDice.map(r => r.result).reduce((a, b) => a + b);
this._isSuccess = (r.total >= 9); this._isSuccess = (r.total >= 9);
@ -302,6 +303,7 @@ export class BoLAttackRoll {
let damageFormula = weaponFormula + "+" + this.attackDef.attacker.data.data.attributes[attrDamage].value; let damageFormula = weaponFormula + "+" + this.attackDef.attacker.data.data.attributes[attrDamage].value;
this.damageRoll = new Roll(damageFormula); this.damageRoll = new Roll(damageFormula);
await this.damageRoll.roll({ "async": false }); await this.damageRoll.roll({ "async": false });
//await BoLUtility.showDiceSoNice(this.damageRoll);
// Update attackDef object // Update attackDef object
this.attackDef.damageFormula = damageFormula; this.attackDef.damageFormula = damageFormula;
this.attackDef.damageRoll = this.damageRoll; this.attackDef.damageRoll = this.damageRoll;
@ -312,18 +314,24 @@ export class BoLAttackRoll {
flavor: msgFlavor, flavor: msgFlavor,
speaker: ChatMessage.getSpeaker({ actor: this.attackDef.attacker }), speaker: ChatMessage.getSpeaker({ actor: this.attackDef.attacker }),
flags: { msgType: "default" } flags: { msgType: "default" }
}).then( result => { });
if (this.attackDef.target) { });
// Broadcast to GM or process it directly in case of GM defense if (this._isCritical) {
if ( !game.user.isGM) { ChatMessage.create({
game.socket.emit("system.bol", { msg: "msg_attack_success", data: this.attackDef }); alias: this.attackDef.attacker.name,
whisper: BoLUtility.getWhisperRecipientsAndGMs(this.attackDef.attacker.name),
content: await renderTemplate('systems/bol/templates/chat/rolls/attack-heroic-card.hbs', {
attackId: attackDef.id,
attacker: attackDef.attacker,
defender: attackDef.defender,
defenderWeapons: defenderWeapons,
damageTotal: attackDef.damageRoll.total
})
})
} else { } else {
BoLUtility.processAttackSuccess( this.attackDef); BoLUtility.sendAttackSuccess( this.attackDef);
} }
} }
});
});
}
} }
_buildDamageChatMessage(actor, weapon, total) { _buildDamageChatMessage(actor, weapon, total) {
@ -333,6 +341,7 @@ export class BoLAttackRoll {
label: this._label, label: this._label,
weapon: weapon, weapon: weapon,
damage: total, damage: total,
isCritical: this._isCritical,
}; };
return renderTemplate(rollMessageTpl, tplData); return renderTemplate(rollMessageTpl, tplData);
} }

View File

@ -95,9 +95,31 @@ export class BoLUtility {
game.socket.emit("system.fvtt-fragged-kingdom", { msg: "msg_gm_chat_message", data: chatGM }); game.socket.emit("system.fvtt-fragged-kingdom", { msg: "msg_gm_chat_message", data: chatGM });
} }
/* -------------------------------------------- */
static sendAttackSuccess(attackDef) {
if (attackDef.target) {
// 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 });
} else {
BoLUtility.processAttackSuccess(attackDef);
}
}
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static async chatListeners(html) { static async chatListeners(html) {
// Damage handling // Damage handling
html.on("click", '.damage-increase', event => {
let attackId = event.currentTarget.attributes['data-attack-id'].value;
let damageMode = event.currentTarget.attributes['data-damage-mode'].value;
if ( game.user.isGM) {
BoLUtility.processDamageIncrease(event, attackId, damageMode)
} else {
game.socket.emit("system.bol", { msg: "msg_damage_increase", data: {event: event, attackId: attackId, damageMode: damageMode} });
}
});
html.on("click", '.damage-handling', event => { html.on("click", '.damage-handling', event => {
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;
@ -111,6 +133,31 @@ export class BoLUtility {
}); });
} }
/* -------------------------------------------- */
static async processDamageIncrease(event, attackId, damageMode ) {
if ( !game.user.isGM) {
return;
}
BoLUtility.removeChatMessageId(BoLUtility.findChatMessageId(event.currentTarget));
// Only GM process this
let attackDef = this.attackStore[attackId];
if (attackDef) {
attackDef.damageMode = damageMode;
if (defenseMode == 'damage-plus-6') {
attackDef.damageRoll.total += 6;
}
if (defenseMode == 'damage-plus-12') {
attackDef.damageRoll.total += 12;
attackDef.defender.subHeroPoints(1);
}
if (defenseMode == 'damage-normal') {
// Do nothing !
}
BoLUtility.sendAttackSuccess( this.attackDef);
}
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static async processDamageHandling(event, attackId, defenseMode, weaponId=-1) { static async processDamageHandling(event, attackId, defenseMode, weaponId=-1) {
if ( !game.user.isGM) { if ( !game.user.isGM) {
@ -120,14 +167,14 @@ export class BoLUtility {
// Only GM process this // Only GM process this
let attackDef = this.attackStore[attackId]; let attackDef = this.attackStore[attackId];
console.log("DEFENSE2", attackId, defenseMode, weaponId, attackDef);
if (attackDef) { if (attackDef) {
attackDef.defenseMode = defenseMode; attackDef.defenseMode = defenseMode;
if (defenseMode == 'damage-with-armor') { if (defenseMode == 'damage-with-armor') {
let armorFormula = attackDef.defender.getArmorFormula(); let armorFormula = attackDef.defender.getArmorFormula();
attackDef.rollArmor = new Roll(armorFormula) attackDef.rollArmor = new Roll(armorFormula)
attackDef.rollArmor.roll( {async: false} ); attackDef.rollArmor.roll( {async: false} );
attackDef.finalDamage = attackDef.damageRoll.total - attackDef.rollArmor.total; 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.finalDamage = (attackDef.finalDamage<0) ? 0 : attackDef.finalDamage;
attackDef.defender.sufferDamage(attackDef.finalDamage); attackDef.defender.sufferDamage(attackDef.finalDamage);
} }
@ -136,9 +183,13 @@ export class BoLUtility {
attackDef.defender.sufferDamage(attackDef.finalDamage); attackDef.defender.sufferDamage(attackDef.finalDamage);
} }
if (defenseMode == 'hero-reduce-damage') { if (defenseMode == 'hero-reduce-damage') {
let armorFormula = attackDef.defender.getArmorFormula();
attackDef.rollArmor = new Roll(armorFormula)
attackDef.rollArmor.roll( {async: false} );
attackDef.armorProtect = (attackDef.rollArmor.total<0) ? 0 : attackDef.rollArmor.total;
attackDef.rollHero = new Roll("1d6"); attackDef.rollHero = new Roll("1d6");
attackDef.rollHero.roll( {async: false} ); attackDef.rollHero.roll( {async: false} );
attackDef.finalDamage = attackDef.damageRoll.total - attackDef.rollHero.total; 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); attackDef.defender.sufferDamage(attackDef.finalDamage);
attackDef.defender.subHeroPoints(1); attackDef.defender.subHeroPoints(1);
@ -157,6 +208,7 @@ export class BoLUtility {
rollArmor: attackDef.rollArmor, rollArmor: attackDef.rollArmor,
rollHero: attackDef.rollHero, rollHero: attackDef.rollHero,
weaponHero : attackDef.weaponHero, weaponHero : attackDef.weaponHero,
armorProtect: attackDef.armorProtect,
defender: attackDef.defender, defender: attackDef.defender,
defenseMode: attackDef.defenseMode, defenseMode: attackDef.defenseMode,
finalDamage: attackDef.finalDamage finalDamage: attackDef.finalDamage
@ -313,6 +365,9 @@ export class BoLUtility {
if (sockmsg.name == "msg_damage_handling") { if (sockmsg.name == "msg_damage_handling") {
BoLUtility.processDamageHandling(sockmsg.data.event, sockmsg.data.attackId, sockmsg.data.defenseMode) BoLUtility.processDamageHandling(sockmsg.data.event, sockmsg.data.attackId, sockmsg.data.defenseMode)
} }
if (sockmsg.name == "msg_damage_increase") {
BoLUtility.processDamageIncrease(sockmsg.data.event, sockmsg.data.attackId, sockmsg.data.damageMode)
}
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -338,6 +393,30 @@ export class BoLUtility {
let formula = nbDice + "d" + res[2] + postForm + ((res[modIndex]) ? res[modIndex] : ""); let formula = nbDice + "d" + res[2] + postForm + ((res[modIndex]) ? res[modIndex] : "");
return formula; return formula;
} }
/* -------------------------------------------- */
static async showDiceSoNice(roll, rollMode) {
if (game.modules.get("dice-so-nice")?.active) {
if (game.dice3d) {
let whisper = null;
let blind = false;
rollMode = rollMode ?? game.settings.get("core", "rollMode");
switch (rollMode) {
case "blindroll": //GM only
blind = true;
case "gmroll": //GM + rolling player
whisper = BoLUtility.getUsers(user => user.isGM);
break;
case "roll": //everybody
whisper = BoLUtility.getUsers(user => user.active);
break;
case "selfroll":
whisper = [game.user.id];
break;
}
await game.dice3d.showForRoll(roll, game.user, true, whisper, blind);
}
}
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static async confirmDelete(actorSheet, li) { static async confirmDelete(actorSheet, li) {

View File

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

View File

@ -0,0 +1,6 @@
<img class="chat-icon" src="{{attacker.img}}" alt="{{attacker.name}}"/>
Jet Héroïque !
<button class="damage-increase" data-damage-mode="damage-plus-6" data-attack-id="{{attackId}}">Augmenter les dommages de 6</button>
<button class="damage-increase" data-damage-mode="damage-plus-12" data-attack-id="{{attackId}}">Augmenter les dommages de 12 (1 point d'Heroisme)</button>
<button class="damage-increase" data-damage-mode="damage-normal" data-attack-id="{{attackId}}">Laisser les dommages inchangés</button>

View File

@ -3,13 +3,14 @@
<ul> <ul>
<li> <li>
{{#if (eq defenseMode "damage-with-armor")}} {{#if (eq defenseMode "damage-with-armor")}}
Protection de l'armure : {{rollArmor.total}}. Protection de l'armure : {{armorProtect}}.
{{/if}} {{/if}}
{{#if (eq defenseMode "damage-without-armor")}} {{#if (eq defenseMode "damage-without-armor")}}
Aucune protection d'armure ! Aucune protection d'armure !
{{/if}} {{/if}}
{{#if (eq defenseMode "hero-reduce-damage")}} {{#if (eq defenseMode "hero-reduce-damage")}}
Un point d'héroisme dépensé, pour une réduction des dommages de {{rollHero.total}}. Protection de l'armure : {{armorProtect}}.
Un point d'héroisme dépensé, pour une réduction des dommages supplémentaire de {{rollHero.total}}.
{{/if}} {{/if}}
{{#if (eq defenseMode "hero-in-extremis")}} {{#if (eq defenseMode "hero-in-extremis")}}
Aucun dommage encaissé, grâce à la parade in-extremis avec {{weaponHero.name}}. L'arme a été détruite pendant cette parade ! Aucun dommage encaissé, grâce à la parade in-extremis avec {{weaponHero.name}}. L'arme a été détruite pendant cette parade !