Attack process path

This commit is contained in:
sladecraven 2021-12-29 19:15:06 +01:00
parent 3fe224f1b4
commit 420390eed7
8 changed files with 470 additions and 197 deletions

View File

@ -28,6 +28,10 @@ export class BoLActor extends Actor {
} }
} }
/* -------------------------------------------- */
_onUpdate() {
this.manageHealthState()
}
/* -------------------------------------------- */ /* -------------------------------------------- */
get itemData(){ get itemData(){
return Array.from(this.data.items.values()).map(i => i.data); return Array.from(this.data.items.values()).map(i => i.data);
@ -184,6 +188,43 @@ export class BoLActor extends Actor {
} }
}; };
} }
/*-------------------------------------------- */
manageHealthState() {
if (this.data.data.resources.hp.value == 0 ) {
// TODO : Message pour depense heroisme
}
}
/*-------------------------------------------- */
async subHeroPoints( nb) {
let newHeroP = this.data.data.resources.hero.value - nb;
newHeroP = (newHeroP < 0 ) ? 0 : newHeroP;
await this.update( { 'data.resources.hero.value': newHeroP} );
}
/*-------------------------------------------- */
async sufferDamage( damage) {
let newHP = this.data.data.resources.hp.value - damage;
await this.update( { 'data.resources.hp.value': newHP} );
}
/* -------------------------------------------- */
getArmorFormula( ) {
let protectWorn = this.protections.filter( item => item.data.worn);
let formula = ""
console.log("Protections: ", protectWorn)
for (let protect of protectWorn) {
if ( protect.data.subtype == 'helm') {
formula += "+1"
} else {
formula += "+" + protect.data.properties.soak.formula;
}
}
console.log("Protect Formula", formula)
return (formula == "") ? 0 :formula;
}
/* -------------------------------------------- */ /* -------------------------------------------- */
toggleEquipItem(item) { toggleEquipItem(item) {
const equipable = item.data.data.properties.equipable; const equipable = item.data.data.properties.equipable;

View File

@ -10,6 +10,7 @@ import {registerSystemSettings} from "./system/settings.js";
import registerHooks from "./system/hooks.js"; import registerHooks from "./system/hooks.js";
// import {DataLoader} from "./system/data.js"; // import {DataLoader} from "./system/data.js";
import { Macros } from "./system/macros.js"; import { Macros } from "./system/macros.js";
import { BoLUtility } from "./system/bol-utility.js";
Hooks.once('init', async function () { Hooks.once('init', async function () {
@ -20,6 +21,12 @@ Hooks.once('init', async function () {
config: BOL config: BOL
}; };
// Game socket
game.socket.on("system.bol", sockmsg => {
BoLUtility.onSocketMessage(sockmsg);
});
/** /**
* Set an initiative formula for the system * Set an initiative formula for the system
* @type {String} * @type {String}
@ -39,6 +46,9 @@ Hooks.once('init', async function () {
Items.unregisterSheet("core", ItemSheet); Items.unregisterSheet("core", ItemSheet);
Items.registerSheet("bol", BoLItemSheet, { makeDefault: true }); Items.registerSheet("bol", BoLItemSheet, { makeDefault: true });
// Inot useful stuff
BoLUtility.init();
// Register System Settings // Register System Settings
registerSystemSettings(); registerSystemSettings();

View File

@ -31,12 +31,7 @@ export class BoLRoll {
// const elt = $(event.currentTarget)[0]; // const elt = $(event.currentTarget)[0];
// let key = elt.attributes["data-rolling"].value; // let key = elt.attributes["data-rolling"].value;
let target = BoLUtility.getTarget() let target = BoLUtility.getTarget()
if ( !target) {
ui.notifications.warn("No target selected for attack !");
return;
}
const li = $(event.currentTarget).parents(".item"); const li = $(event.currentTarget).parents(".item");
console.log("ITEM", target);
const weapon = actor.items.get(li.data("item-id")); const weapon = actor.items.get(li.data("item-id"));
if (!weapon) { if (!weapon) {
ui.notifications.warn("Unable to find weapon !"); ui.notifications.warn("Unable to find weapon !");
@ -50,7 +45,7 @@ export class BoLRoll {
weapon :weapon, weapon :weapon,
mod: 0, mod: 0,
target : target, target : target,
defender: game.actors.get(target.data.actorId), defender: (target) ? game.actors.get(target.data.actorId) : undefined,
adv :dataset.adv || 0, adv :dataset.adv || 0,
attribute : eval(`actor.data.data.attributes.${weaponData.properties.attackAttribute}`), attribute : eval(`actor.data.data.attributes.${weaponData.properties.attackAttribute}`),
aptitude : eval(`actor.data.data.aptitudes.${weaponData.properties.attackAptitude}`), aptitude : eval(`actor.data.data.aptitudes.${weaponData.properties.attackAptitude}`),
@ -123,7 +118,7 @@ export class BoLRoll {
careers: attackDef.attackerData.features.careers, careers: attackDef.attackerData.features.careers,
boons: attackDef.attackerData.features.boons, boons: attackDef.attackerData.features.boons,
flaws: attackDef.attackerData.features.flaws, flaws: attackDef.attackerData.features.flaws,
defence: attackDef.defender.defenseValue, defence: (attackDef.defender) ? attackDef.defender.defenseValue : 0,
}; };
const rollOptionContent = await renderTemplate(rollOptionTpl, dialogData); const rollOptionContent = await renderTemplate(rollOptionTpl, dialogData);
let d = new Dialog({ let d = new Dialog({
@ -270,7 +265,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": true}); await r.roll({"async": false});
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);
@ -290,13 +285,26 @@ export class BoLAttackRoll {
let weaponFormula = BoLUtility.getDamageFormula(this.attackDef.weapon.data.data.properties.damage) let weaponFormula = BoLUtility.getDamageFormula(this.attackDef.weapon.data.data.properties.damage)
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": true}); await this.damageRoll.roll({"async": false});
// Update attackDef object
this.attackDef.damageFormula = damageFormula;
this.attackDef.damageRoll = this.damageRoll;
this._buildDamageChatMessage(this.attackDef.attacker, this.attackDef.weapon, this.damageRoll.total).then(msgFlavor => { this._buildDamageChatMessage(this.attackDef.attacker, this.attackDef.weapon, this.damageRoll.total).then(msgFlavor => {
this.damageRoll.toMessage({ this.damageRoll.toMessage({
user: game.user.id, user: game.user.id,
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 ( !game.user.isGM) {
game.socket.emit("system.bol", { msg: "msg_attack_success", data: this.attackDef });
} else {
BoLUtility.processAttackSuccess( this.attackDef);
}
}
}); });
}); });
} }

View File

@ -0,0 +1,21 @@
export class RdDCombatManager extends Combat {
/************************************************************************************/
async rollInitiative(ids, formula = undefined, messageOptions = {}) {
console.log(`${game.data.system.data.title} | Combat.rollInitiative()`, ids, formula, messageOptions);
// Structure input data
ids = typeof ids === "string" ? [ids] : ids;
const currentId = this.combatant._id;
// calculate initiative
if ( game.combat.current.round == 1) {
for (let cId = 0; cId < ids.length; cId++) {
const combatant = this.combatants.get(ids[cId]);
// TODO
console.log("TODO : Compute init for actor");
}
}
}
}

View File

@ -1,8 +1,11 @@
export class BoLUtility { export class BoLUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static async init() { static async init() {
this.attackStore = {};
Hooks.on('renderChatLog', (log, html, data) => BoLUtility.chatListeners(html));
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -87,10 +90,81 @@ export class BoLUtility {
static blindMessageToGM(chatOptions) { static blindMessageToGM(chatOptions) {
let chatGM = duplicate(chatOptions); let chatGM = duplicate(chatOptions);
chatGM.whisper = this.getUsers(user => user.isGM); chatGM.whisper = this.getUsers(user => user.isGM);
chatGM.content = "Blinde 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.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 async chatListeners(html) {
// Damage handling
html.on("click", '.damage-handling', event => {
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("DEFENSE1", event.currentTarget, attackId, defenseMode, weaponId);
if ( game.user.isGM) {
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} });
}
});
}
/* -------------------------------------------- */
static async processDamageHandling(event, attackId, defenseMode, weaponId=-1) {
if ( !game.user.isGM) {
return;
}
BoLUtility.removeChatMessageId(BoLUtility.findChatMessageId(event.currentTarget));
// Only GM process this
let attackDef = this.attackStore[attackId];
console.log("DEFENSE2", attackId, defenseMode, weaponId, attackDef);
if (attackDef) {
attackDef.defenseMode = defenseMode;
if (defenseMode == 'damage-with-armor') {
let armorFormula = attackDef.defender.getArmorFormula();
attackDef.rollArmor = new Roll(armorFormula)
attackDef.rollArmor.roll( {async: false} );
attackDef.finalDamage = attackDef.damageRoll.total - attackDef.rollArmor.total;
attackDef.finalDamage = (attackDef.finalDamage<0) ? 0 : attackDef.finalDamage;
attackDef.defender.sufferDamage(attackDef.finalDamage);
}
if (defenseMode == 'damage-without-armor') {
attackDef.finalDamage = attackDef.damageRoll.total;
attackDef.defender.sufferDamage(attackDef.finalDamage);
}
if (defenseMode == 'hero-reduce-damage') {
attackDef.rollHero = new Roll("1d6");
attackDef.rollHero.roll( {async: false} );
attackDef.finalDamage = attackDef.damageRoll.total - attackDef.rollHero.total;
attackDef.finalDamage = (attackDef.finalDamage<0) ? 0 : attackDef.finalDamage;
attackDef.defender.sufferDamage(attackDef.finalDamage);
attackDef.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 ]);
}
ChatMessage.create({
alias: attackDef.defender.name,
whisper: BoLUtility.getWhisperRecipientsAndGMs(attackDef.defender.name),
content: await renderTemplate('systems/bol/templates/chat/rolls/defense-result-card.hbs', {
attackId: attackDef.id,
attacker: attackDef.attacker,
rollArmor: attackDef.rollArmor,
rollHero: attackDef.rollHero,
weaponHero : attackDef.weaponHero,
defender: attackDef.defender,
defenseMode: attackDef.defenseMode,
finalDamage: attackDef.finalDamage
})
})
}
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static createChatMessage(name, rollMode, chatOptions) { static createChatMessage(name, rollMode, chatOptions) {
switch (rollMode) { switch (rollMode) {
@ -122,6 +196,36 @@ export class BoLUtility {
return weapon.data.type == 'ranged' || weapon.data.thrown; return weapon.data.type == 'ranged' || weapon.data.thrown;
} }
/* -------------------------------------------- */
static removeChatMessageId(messageId) {
if (messageId){
game.messages.get(messageId)?.delete();
}
}
static findChatMessageId(current) {
return BoLUtility.getChatMessageId(BoLUtility.findChatMessage(current));
}
static getChatMessageId(node) {
return node?.attributes.getNamedItem('data-message-id')?.value;
}
static findChatMessage(current) {
return BoLUtility.findNodeMatching(current, it => it.classList.contains('chat-message') && it.attributes.getNamedItem('data-message-id'));
}
static findNodeMatching(current, predicate) {
if (current) {
if (predicate(current)) {
return current;
}
return BoLUtility.findNodeMatching(current.parentElement, predicate);
}
return undefined;
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static getTarget() { static getTarget() {
if (game.user.targets && game.user.targets.size == 1) { if (game.user.targets && game.user.targets.size == 1) {
@ -179,6 +283,38 @@ export class BoLUtility {
}); });
} }
/* -------------------------------------------- */
static async processAttackSuccess(attackDef) {
if (!game.user.isGM) { // Only GM process this
return;
}
// Build and send the defense message to the relevant people (ie GM + defender)
let defenderWeapons = attackDef.defender.weapons;
console.log("DEF WEP", attackDef)
this.attackStore[attackDef.id] = attackDef; // Store !
ChatMessage.create({
alias: attackDef.defender.name,
whisper: BoLUtility.getWhisperRecipientsAndGMs(attackDef.defender.name),
content: await renderTemplate('systems/bol/templates/chat/rolls/defense-request-card.hbs', {
attackId: attackDef.id,
attacker: attackDef.attacker,
defender: attackDef.defender,
defenderWeapons: defenderWeapons,
damageTotal: attackDef.damageRoll.total
})
});
}
/* -------------------------------------------- */
static onSocketMessage(sockmsg) {
if (sockmsg.name == "msg_attack_success") {
BoLUtility.processAttackSuccess(sockmsg.data);
}
if (sockmsg.name == "msg_damage_handling") {
BoLUtility.processDamageHandling(sockmsg.data.event, sockmsg.data.attackId, sockmsg.data.defenseMode)
}
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static getDamageFormula(damageString) { static getDamageFormula(damageString) {
if (damageString[0] == 'd') { damageString = "1" + damageString } // Help parsing if (damageString[0] == 'd') { damageString = "1" + damageString } // Help parsing

View File

@ -2,14 +2,21 @@
"name": "bol", "name": "bol",
"title": "Barbarians of Lemuria", "title": "Barbarians of Lemuria",
"description": "The Barbarians of Lemuria system for FoundryVTT!", "description": "The Barbarians of Lemuria system for FoundryVTT!",
"author": "Zigmund",
"authors": [],
"url": "https://github.com/ZigmundKreud/bol",
"license": "LICENSE.txt",
"flags": {},
"version": "0.8.9.0", "version": "0.8.9.0",
"minimumCoreVersion": "0.8.6", "minimumCoreVersion": "0.8.6",
"compatibleCoreVersion": "0.8.9", "compatibleCoreVersion": "0.8.9",
"templateVersion": 8,
"author": "Zigmund",
"esmodules": ["module/bol.js"],
"styles": ["css/bol.css"],
"scripts": [], "scripts": [],
"esmodules": [
"module/bol.js"
],
"styles": [
"css/bol.css"
],
"languages": [ "languages": [
{ {
"lang": "en", "lang": "en",
@ -29,7 +36,9 @@
"system": "bol", "system": "bol",
"path": "./packs/boons.db", "path": "./packs/boons.db",
"entity": "Item", "entity": "Item",
"tag": "boon" "tag": "boon",
"type": "Item",
"private": false
}, },
{ {
"name": "flaws", "name": "flaws",
@ -37,7 +46,9 @@
"system": "bol", "system": "bol",
"path": "./packs/flaws.db", "path": "./packs/flaws.db",
"entity": "Item", "entity": "Item",
"tag": "flaw" "tag": "flaw",
"type": "Item",
"private": false
}, },
{ {
"name": "careers", "name": "careers",
@ -45,7 +56,9 @@
"system": "bol", "system": "bol",
"path": "./packs/careers.db", "path": "./packs/careers.db",
"entity": "Item", "entity": "Item",
"tag": "career" "tag": "career",
"type": "Item",
"private": false
}, },
{ {
"name": "origins", "name": "origins",
@ -53,7 +66,9 @@
"system": "bol", "system": "bol",
"path": "./packs/origins.db", "path": "./packs/origins.db",
"entity": "Item", "entity": "Item",
"tag": "origin" "tag": "origin",
"type": "Item",
"private": false
}, },
{ {
"name": "races", "name": "races",
@ -61,7 +76,9 @@
"system": "bol", "system": "bol",
"path": "./packs/races.db", "path": "./packs/races.db",
"entity": "Item", "entity": "Item",
"tag": "race" "tag": "race",
"type": "Item",
"private": false
}, },
{ {
"name": "equipment", "name": "equipment",
@ -69,16 +86,20 @@
"system": "bol", "system": "bol",
"path": "./packs/equipment.db", "path": "./packs/equipment.db",
"entity": "Item", "entity": "Item",
"tag": "item" "tag": "item",
"type": "Item",
"private": false
} }
], ],
"system": [],
"dependencies": [],
"socket": true,
"manifest": "https://raw.githubusercontent.com/ZigmundKreud/bol/master/system.json",
"download": "https://github.com/ZigmundKreud/bol/archive/refs/heads/master.zip",
"protected": false,
"background": "ui/splash-page.webp", "background": "ui/splash-page.webp",
"gridDistance": 1.5, "gridDistance": 1.5,
"gridUnits": "m", "gridUnits": "m",
"primaryTokenAttribute": "resources.hp", "primaryTokenAttribute": "resources.hp",
"secondaryTokenAttribute": "resources.hero", "secondaryTokenAttribute": "resources.hero"
"url": "https://github.com/ZigmundKreud/bol",
"manifest": "https://raw.githubusercontent.com/ZigmundKreud/bol/master/system.json",
"download": "https://github.com/ZigmundKreud/bol/archive/refs/heads/master.zip",
"license": "LICENSE.txt"
} }

View File

@ -0,0 +1,14 @@
<img class="chat-icon" src="{{defender.img}}" alt="{{defender.name}}"/>
Va encaisser {{damageTotal}} dégats !
<button class="damage-handling" data-defense-mode="damage-with-armor" data-attack-id="{{attackId}}">Encaisser avec la protection de l'armure</button>
<button class="damage-handling" data-defense-mode="damage-without-armor" data-attack-id="{{attackId}}">Encaisser sans la protection de l'armure</button>
{{#if defender.data.data.resources.hero.value}}
<button class="damage-handling" data-defense-mode="hero-reduce-damage" data-attack-id="{{attackId}}">Juste une égratignure (1 Point d'Héroisme)</button>
{{#each defenderWeapons as |weapon idx|}}
<button class="damage-handling" data-defense-mode="hero-in-extremis" data-attack-id="{{@root.attackId}}" data-weapon-id="{{weapon._id}}">Parade in Extremis avec {{weapon.name}} (1 Point d'Héroisme)</button>
{{/each}}
{{/if}}

View File

@ -0,0 +1,22 @@
<img class="chat-icon" src="{{defender.img}}" alt="{{defender.name}}"/>
<h3>Dégats subis par {{defender.name}}</h3>
<ul>
<li>
{{#if (eq defenseMode "damage-with-armor")}}
Protection de l'armure : {{rollArmor.total}}.
{{/if}}
{{#if (eq defenseMode "damage-without-armor")}}
Aucune protection d'armure !
{{/if}}
{{#if (eq defenseMode "hero-reduce-damage")}}
Un point d'héroisme dépensé, pour une réduction des dommages de {{rollHero.total}}.
{{/if}}
{{#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 !
Un point d'héroisme a également été dépensé.
{{/if}}
</li>
<li>
Encaissement final : {{finalDamage}} dégats !
</li>
</ul>