Merge pull request #3 from sladecraven/master

Attack process path
This commit is contained in:
ZigmundKreud 2021-12-29 20:53:46 +01:00 committed by GitHub
commit 5915b4a0ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 520 additions and 203 deletions

View File

@ -94,6 +94,10 @@
"BOL.ui.misc" : "Divers",
"BOL.ui.noWeaponName" : "Unknown Weapon",
"BOL.ui.targetDefence": "Defence",
"BOL.ui.applyShieldMalus": "Apply Small Shield Malus",
"BOL.ui.shieldMalus": "Shield Malus",
"BOL.ui.defenseScore": "Defense Score",
"BOL.ui.defender": "Defender",
"BOL.featureCategory.origins": "Origines",
"BOL.featureCategory.races": "Races",

View File

@ -96,6 +96,10 @@
"BOL.ui.speed" : "Vitesse",
"BOL.ui.noWeaponName" : "Arme Inconnue",
"BOL.ui.targetDefence": "Défense",
"BOL.ui.applyShieldMalus": "Appliquer le Malus de Petit Bouclier",
"BOL.ui.shieldMalus": "Malus de Bouclier",
"BOL.ui.defenseScore": "Score de Defense",
"BOL.ui.defender": "Défenseur",
"BOL.featureCategory.origins": "Origines",
"BOL.featureCategory.races": "Races",

View File

@ -28,6 +28,10 @@ export class BoLActor extends Actor {
}
}
/* -------------------------------------------- */
_onUpdate() {
this.manageHealthState()
}
/* -------------------------------------------- */
get itemData(){
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) {
const equipable = item.data.data.properties.equipable;

View File

@ -1,70 +1,80 @@
// Import Modules
import {BoLActor} from "./actor/actor.js";
import {BoLActorSheet} from "./actor/actor-sheet.js";
import {BoLItem} from "./item/item.js";
import {BoLItemSheet} from "./item/item-sheet.js";
import {System, BOL} from "./system/config.js";
import {preloadHandlebarsTemplates} from "./system/templates.js";
import {registerHandlebarsHelpers} from "./system/helpers.js";
import {registerSystemSettings} from "./system/settings.js";
import { BoLActor } from "./actor/actor.js";
import { BoLActorSheet } from "./actor/actor-sheet.js";
import { BoLItem } from "./item/item.js";
import { BoLItemSheet } from "./item/item-sheet.js";
import { System, BOL } from "./system/config.js";
import { preloadHandlebarsTemplates } from "./system/templates.js";
import { registerHandlebarsHelpers } from "./system/helpers.js";
import { registerSystemSettings } from "./system/settings.js";
import registerHooks from "./system/hooks.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 () {
game.bol = {
BoLActor,
BoLItem,
macros : Macros,
config:BOL
};
game.bol = {
BoLActor,
BoLItem,
macros: Macros,
config: BOL
};
/**
* Set an initiative formula for the system
* @type {String}
*/
CONFIG.Combat.initiative = {
formula: "2d6+@attributes.mind.value+@aptitudes.init.value",
decimals: 0
};
0
// Define custom Entity classes
CONFIG.Actor.documentClass = BoLActor;
CONFIG.Item.documentClass = BoLItem;
// Game socket
game.socket.on("system.bol", sockmsg => {
BoLUtility.onSocketMessage(sockmsg);
});
// Register sheet application classes
Actors.unregisterSheet("core", ActorSheet);
Actors.registerSheet("bol", BoLActorSheet, {makeDefault: true});
Items.unregisterSheet("core", ItemSheet);
Items.registerSheet("bol", BoLItemSheet, {makeDefault: true});
// Register System Settings
registerSystemSettings();
/**
* Set an initiative formula for the system
* @type {String}
*/
CONFIG.Combat.initiative = {
formula: "2d6+@attributes.mind.value+@aptitudes.init.value",
decimals: 0
};
0
// Define custom Entity classes
CONFIG.Actor.documentClass = BoLActor;
CONFIG.Item.documentClass = BoLItem;
// Preload Handlebars Templates
await preloadHandlebarsTemplates();
// Register sheet application classes
Actors.unregisterSheet("core", ActorSheet);
Actors.registerSheet("bol", BoLActorSheet, { makeDefault: true });
Items.unregisterSheet("core", ItemSheet);
Items.registerSheet("bol", BoLItemSheet, { makeDefault: true });
// Register Handlebars helpers
registerHandlebarsHelpers();
// Inot useful stuff
BoLUtility.init();
// Register hooks
registerHooks();
// Register System Settings
registerSystemSettings();
// // If you need to add Handlebars helpers, here are a few useful examples:
// Handlebars.registerHelper('concat', function() {
// var outStr = '';
// for (var arg in arguments) {
// if (typeof arguments[arg] != 'object') {
// outStr += arguments[arg];
// }
// }
// return outStr;
// });
//
// Handlebars.registerHelper('toLowerCase', function(str) {
// return str.toLowerCase();
// });
// Preload Handlebars Templates
await preloadHandlebarsTemplates();
// Register Handlebars helpers
registerHandlebarsHelpers();
// Register hooks
registerHooks();
// // If you need to add Handlebars helpers, here are a few useful examples:
// Handlebars.registerHelper('concat', function() {
// var outStr = '';
// for (var arg in arguments) {
// if (typeof arguments[arg] != 'object') {
// outStr += arguments[arg];
// }
// }
// return outStr;
// });
//
// Handlebars.registerHelper('toLowerCase', function(str) {
// return str.toLowerCase();
// });
});
@ -74,20 +84,20 @@ Hooks.once('init', async function () {
Hooks.once("ready", async () => {
console.debug("Importing data");
console.debug("Importing data");
// DataLoader.loadData("boons");
// DataLoader.loadData("flaws");
// DataLoader.loadData("careers");
// DataLoader.loadData("origins");
// DataLoader.loadData("races");
// DataLoader.loadData("equipment");
// DataLoader.loadData("boons");
// DataLoader.loadData("flaws");
// DataLoader.loadData("careers");
// DataLoader.loadData("origins");
// DataLoader.loadData("races");
// DataLoader.loadData("equipment");
// UpdateUtils.updatePacks();
// UpdateUtils.updatePaths();
// UpdateUtils.updateProfiles();
// UpdateUtils.updateSpecies();
// UpdateUtils.updateEncounters();
// UpdateUtils.updatePacks();
// UpdateUtils.updatePaths();
// UpdateUtils.updateProfiles();
// UpdateUtils.updateSpecies();
// UpdateUtils.updateEncounters();
console.info("BOL | System Initialized.");
console.info("BOL | System Initialized.");
});

View File

@ -31,12 +31,7 @@ export class BoLRoll {
// const elt = $(event.currentTarget)[0];
// let key = elt.attributes["data-rolling"].value;
let target = BoLUtility.getTarget()
if ( !target) {
ui.notifications.warn("No target selected for attack !");
return;
}
const li = $(event.currentTarget).parents(".item");
console.log("ITEM", target);
const weapon = actor.items.get(li.data("item-id"));
if (!weapon) {
ui.notifications.warn("Unable to find weapon !");
@ -50,7 +45,7 @@ export class BoLRoll {
weapon :weapon,
mod: 0,
target : target,
defender: game.actors.get(target.data.actorId),
defender: (target) ? game.actors.get(target.data.actorId) : undefined,
adv :dataset.adv || 0,
attribute : eval(`actor.data.data.attributes.${weaponData.properties.attackAttribute}`),
aptitude : eval(`actor.data.data.aptitudes.${weaponData.properties.attackAptitude}`),
@ -74,7 +69,7 @@ export class BoLRoll {
boons:actorData.features.boons,
flaws:actorData.features.flaws
};
console.log(dialogData.careers);
const rollOptionContent = await renderTemplate(rollOptionTpl, dialogData);
let d = new Dialog({
title: label,
@ -123,8 +118,17 @@ export class BoLRoll {
careers: attackDef.attackerData.features.careers,
boons: attackDef.attackerData.features.boons,
flaws: attackDef.attackerData.features.flaws,
defence: attackDef.defender.defenseValue,
};
if ( attackDef.defender) {
dialogData.defence = attackDef.defender.defenseValue,
dialogData.shieldBlock = 'none'
let shields = attackDef.defender.shields
for( let shield of shields) {
dialogData.shieldBlock = (shield.data.properties.blocking.blockingAll) ? 'blockall' : 'blockone';
dialogData.shieldAttackMalus = (shield.data.properties.blocking.malus)? shield.data.properties.blocking.malus : 1;
dialogData.applyShieldMalus = false
}
}
const rollOptionContent = await renderTemplate(rollOptionTpl, dialogData);
let d = new Dialog({
title: attackDef.label,
@ -144,13 +148,20 @@ export class BoLRoll {
const apt = html.find('#apt').val();
const adv = html.find('#adv').val();
const mod = html.find('#mod').val() || 0;
let shieldMalus = 0;
const applyShieldMalus = html.find('#applyShieldMalus').val() || false;
if (applyShieldMalus || dialogData.shieldBlock =='blockall') {
shieldMalus = dialogData.shieldAttackMalus;
}
let careers = html.find('#career').val();
const career = (careers.length == 0) ? 0 : Math.max(...careers.map(i => parseInt(i)));
const isMalus = adv < 0;
const dicePool = (isMalus) ? 2 - parseInt(adv) : 2 + parseInt(adv);
const attrValue = eval(`attackDef.attacker.data.data.attributes.${attr}.value`);
const aptValue = eval(`attackDef.attacker.data.data.aptitudes.${apt}.value`);
const modifiers = parseInt(attrValue) + parseInt(aptValue) + parseInt(mod) + parseInt(career) - dialogData.defence;
const modifiers = parseInt(attrValue) + parseInt(aptValue) + parseInt(mod) + parseInt(career) - dialogData.defence - shieldMalus;
const formula = (isMalus) ? dicePool + "d6kl2 + " + modifiers : dicePool + "d6kh2 + " + modifiers;
attackDef.formula = formula;
let r = new BoLAttackRoll(attackDef);
@ -270,7 +281,7 @@ export class BoLAttackRoll {
async roll(){
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 diceTotal = activeDice.map(r => r.result).reduce((a, b) => a + b);
this._isSuccess = (r.total >= 9);
@ -290,17 +301,30 @@ export class BoLAttackRoll {
let weaponFormula = BoLUtility.getDamageFormula(this.attackDef.weapon.data.data.properties.damage)
let damageFormula = weaponFormula + "+" + this.attackDef.attacker.data.data.attributes[attrDamage].value;
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.damageRoll.toMessage({
user: game.user.id,
flavor: msgFlavor,
speaker: ChatMessage.getSpeaker({actor: this.attackDef.attacker}),
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);
}
}
});
});
});
}
}
}
_buildDamageChatMessage(actor, weapon, total) {
const rollMessageTpl = 'systems/bol/templates/chat/rolls/damage-roll-card.hbs';

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() {
this.attackStore = {};
Hooks.on('renderChatLog', (log, html, data) => BoLUtility.chatListeners(html));
}
/* -------------------------------------------- */
@ -23,9 +26,9 @@ export class BoLUtility {
}
/* -------------------------------------------- */
static createDirectOptionList( min, max) {
static createDirectOptionList(min, max) {
let options = {};
for(let i=min; i<=max; i++) {
for (let i = min; i <= max; i++) {
options[`${i}`] = `${i}`;
}
return options;
@ -64,64 +67,165 @@ export class BoLUtility {
}
}
}
/* -------------------------------------------- */
static getUsers(filter) {
return game.users.filter(filter).map(user => user.data._id);
}
/* -------------------------------------------- */
static getWhisperRecipients(rollMode, name) {
switch (rollMode) {
case "blindroll": return this.getUsers(user => user.isGM);
case "gmroll": return this.getWhisperRecipientsAndGMs(name);
case "selfroll": return [game.user.id];
}
return undefined;
}
/* -------------------------------------------- */
static getWhisperRecipientsAndGMs(name) {
let recep1 = ChatMessage.getWhisperRecipients(name) || [];
return recep1.concat(ChatMessage.getWhisperRecipients('GM'));
}
/* -------------------------------------------- */
static blindMessageToGM(chatOptions) {
let chatGM = duplicate(chatOptions);
chatGM.whisper = this.getUsers(user => user.isGM);
chatGM.content = "Blinde message of " + game.user.name + "<br>" + chatOptions.content;
console.log("blindMessageToGM", chatGM);
game.socket.emit("system.fvtt-fragged-kingdom", { msg: "msg_gm_chat_message", data: chatGM });
}
/* -------------------------------------------- */
static createChatMessage(name, rollMode, chatOptions) {
switch (rollMode) {
case "blindroll": // GM only
if (!game.user.isGM) {
this.blindMessageToGM(chatOptions);
chatOptions.whisper = [game.user.id];
chatOptions.content = "Message only to the GM";
}
else {
chatOptions.whisper = this.getUsers(user => user.isGM);
}
break;
default:
chatOptions.whisper = this.getWhisperRecipients(rollMode, name);
break;
}
chatOptions.alias = chatOptions.alias || name;
ChatMessage.create(chatOptions);
}
/* -------------------------------------------- */
static createChatWithRollMode(name, chatOptions) {
this.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions);
}
/* -------------------------------------------- */
static isRangedWeapon( weapon) {
static getUsers(filter) {
return game.users.filter(filter).map(user => user.data._id);
}
/* -------------------------------------------- */
static getWhisperRecipients(rollMode, name) {
switch (rollMode) {
case "blindroll": return this.getUsers(user => user.isGM);
case "gmroll": return this.getWhisperRecipientsAndGMs(name);
case "selfroll": return [game.user.id];
}
return undefined;
}
/* -------------------------------------------- */
static getWhisperRecipientsAndGMs(name) {
let recep1 = ChatMessage.getWhisperRecipients(name) || [];
return recep1.concat(ChatMessage.getWhisperRecipients('GM'));
}
/* -------------------------------------------- */
static blindMessageToGM(chatOptions) {
let chatGM = duplicate(chatOptions);
chatGM.whisper = this.getUsers(user => user.isGM);
chatGM.content = "Blind message of " + game.user.name + "<br>" + chatOptions.content;
console.log("blindMessageToGM", 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) {
switch (rollMode) {
case "blindroll": // GM only
if (!game.user.isGM) {
this.blindMessageToGM(chatOptions);
chatOptions.whisper = [game.user.id];
chatOptions.content = "Message only to the GM";
}
else {
chatOptions.whisper = this.getUsers(user => user.isGM);
}
break;
default:
chatOptions.whisper = this.getWhisperRecipients(rollMode, name);
break;
}
chatOptions.alias = chatOptions.alias || name;
ChatMessage.create(chatOptions);
}
/* -------------------------------------------- */
static createChatWithRollMode(name, chatOptions) {
this.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions);
}
/* -------------------------------------------- */
static isRangedWeapon(weapon) {
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() {
if (game.user.targets && game.user.targets.size == 1) {
@ -133,38 +237,38 @@ export class BoLUtility {
}
/* -------------------------------------------- */
static async rollBoL( rollData ) {
static async rollBoL(rollData) {
// Dice bonus/malus selection
let nbDice = 2;
let d6BM = 0;
let mode = "";
if ( rollData.d6Malus > rollData.d6Bonus){
if (rollData.d6Malus > rollData.d6Bonus) {
d6BM = rollData.d6Malus - rollData.d6Bonus;
mode = "kl2";
}
if ( rollData.d6Bonus > rollData.d6Malus){
if (rollData.d6Bonus > rollData.d6Malus) {
d6BM = rollData.d6Bonus - rollData.d6Malus;
mode = "kh2";
}
nbDice += d6BM;
nbDice += d6BM;
// Final modifier
let modifier = Number(rollData.bonusMalus);
if ( rollData.mode == 'career') {
if (rollData.mode == 'career') {
modifier += Number(rollData.attributes[rollData.rollAttribute].value) + Number(rollData.career.data.rank);
} else if ( rollData.mode == 'attribute' ) {
} else if (rollData.mode == 'attribute') {
modifier += rollData.attribute.value;
} else if ( rollData.mode == 'weapon') {
} else if (rollData.mode == 'weapon') {
modifier += Number(rollData.attributes[rollData.rollAttribute].value) + Number(rollData.aptitude.value) + Number(rollData.rangeModifier);
modifier -= rollData.defender.data.aptitudes.def.value;
}
let formula = nbDice+"d6"+mode+"+"+modifier;
let formula = nbDice + "d6" + mode + "+" + modifier;
console.log("Going to roll ", formula, rollData.attributes, rollData.rollAttribute);
let myRoll = new Roll(formula).roll( { async: false});
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode") );
let myRoll = new Roll(formula).roll({ async: false });
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"));
rollData.roll = myRoll;
rollData.formula = formula;
rollData.modifier = modifier;
@ -172,34 +276,66 @@ export class BoLUtility {
rollData.finalScore = myRoll.total;
let actor = game.actors.get(rollData.actorId);
actor.saveRollData( rollData );
actor.saveRollData(rollData);
this.createChatWithRollMode( rollData.alias, {
this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/bol/templates/chat/chat-generic-result.hbs`, rollData)
});
}
/* -------------------------------------------- */
static getDamageFormula( damageString) {
if (damageString[0] == 'd') {damageString = "1" + damageString} // Help parsing
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) {
if (damageString[0] == 'd') { damageString = "1" + damageString } // Help parsing
var myReg = new RegExp('(\\d+)[dD]([\\d]+)([MB]*)?([\\+\\d]*)?', 'g');
let res = myReg.exec(damageString);
let nbDice = parseInt(res[1]);
let postForm = 'kh'+nbDice;
let postForm = 'kh' + nbDice;
let modIndex = 3;
if ( res[3]) {
if ( res[3] == 'M') {
postForm = 'kl'+nbDice;
if (res[3]) {
if (res[3] == 'M') {
postForm = 'kl' + nbDice;
nbDice++;
modIndex = 4;
}
if ( res[3] == 'B') {
postForm = 'kh'+nbDice;
if (res[3] == 'B') {
postForm = 'kh' + nbDice;
nbDice++;
modIndex = 4;
}
}
let formula = nbDice+"d"+res[2] + postForm + ((res[modIndex]) ? res[modIndex] : "");
let formula = nbDice + "d" + res[2] + postForm + ((res[modIndex]) ? res[modIndex] : "");
return formula;
}
@ -209,26 +345,26 @@ export class BoLUtility {
let msgTxt = "<p>Are you sure to remove this Item ?";
let buttons = {
delete: {
icon: '<i class="fas fa-check"></i>',
label: "Yes, remove it",
callback: () => {
actorSheet.actor.deleteEmbeddedDocuments( "Item", [itemId] );
li.slideUp(200, () => actorSheet.render(false));
}
},
cancel: {
icon: '<i class="fas fa-times"></i>',
label: "Cancel"
icon: '<i class="fas fa-check"></i>',
label: "Yes, remove it",
callback: () => {
actorSheet.actor.deleteEmbeddedDocuments("Item", [itemId]);
li.slideUp(200, () => actorSheet.render(false));
}
},
cancel: {
icon: '<i class="fas fa-times"></i>',
label: "Cancel"
}
msgTxt += "</p>";
let d = new Dialog({
title: "Confirm removal",
content: msgTxt,
buttons: buttons,
default: "cancel"
});
d.render(true);
}
msgTxt += "</p>";
let d = new Dialog({
title: "Confirm removal",
content: msgTxt,
buttons: buttons,
default: "cancel"
});
d.render(true);
}
}

View File

@ -2,14 +2,21 @@
"name": "bol",
"title": "Barbarians of Lemuria",
"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",
"minimumCoreVersion": "0.8.6",
"compatibleCoreVersion": "0.8.9",
"templateVersion": 8,
"author": "Zigmund",
"esmodules": ["module/bol.js"],
"styles": ["css/bol.css"],
"compatibleCoreVersion": "9",
"scripts": [],
"esmodules": [
"module/bol.js"
],
"styles": [
"css/bol.css"
],
"languages": [
{
"lang": "en",
@ -29,7 +36,9 @@
"system": "bol",
"path": "./packs/boons.db",
"entity": "Item",
"tag": "boon"
"tag": "boon",
"type": "Item",
"private": false
},
{
"name": "flaws",
@ -37,7 +46,9 @@
"system": "bol",
"path": "./packs/flaws.db",
"entity": "Item",
"tag": "flaw"
"tag": "flaw",
"type": "Item",
"private": false
},
{
"name": "careers",
@ -45,7 +56,9 @@
"system": "bol",
"path": "./packs/careers.db",
"entity": "Item",
"tag": "career"
"tag": "career",
"type": "Item",
"private": false
},
{
"name": "origins",
@ -53,7 +66,9 @@
"system": "bol",
"path": "./packs/origins.db",
"entity": "Item",
"tag": "origin"
"tag": "origin",
"type": "Item",
"private": false
},
{
"name": "races",
@ -61,7 +76,9 @@
"system": "bol",
"path": "./packs/races.db",
"entity": "Item",
"tag": "race"
"tag": "race",
"type": "Item",
"private": false
},
{
"name": "equipment",
@ -69,16 +86,20 @@
"system": "bol",
"path": "./packs/equipment.db",
"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",
"gridDistance": 1.5,
"gridUnits": "m",
"primaryTokenAttribute": "resources.hp",
"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"
"secondaryTokenAttribute": "resources.hero"
}

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>

View File

@ -55,6 +55,26 @@
</div>
<div class="flex1 center cell">{{defence}}</div>
</div>
{{#if (eq shieldBlock 'blockall')}}
<div class="flexrow" style="margin-bottom: 1px;">
<div class="flex1 center bg-darkred">
<label for="mod">{{localize 'BOL.ui.shieldMalus'}}</label>
</div>
<div class="flex1 center cell">{{shieldAttackMalus}}</div>
</div>
{{/if}}
{{#if (eq shieldBlock 'blockone')}}
<div class="flexrow" style="margin-bottom: 1px;">
<div class="flex1 center bg-darkred">
<label for="mod">{{localize 'BOL.ui.shieldMalus'}}</label>
</div>
<div class="flex1 center cell">
<label class="checkbox">
<input class="field-value" type="checkbox" id="applyShieldMalus" name="applyShieldMalus" {{checked applyShieldMalus}}> {{localize "BOL.ui.applyShieldMalus"}}
</label>
</div>
</div>
{{/if}}
{{#if careers.items}}
<div class="flexrow" style="margin-bottom: 1px;">
<div class="flex1 center bg-darkred">

View File

@ -1,11 +1,11 @@
<form class="skill-roll-dialog">
{{#if defender}}
<div class="property flexrow">
<label class="property-label">{{localize "Defender"}} : </label>
<label class="property-label">{{localize "BOL.ui.defender"}} : </label>
<label class="property-label">{{defender.name}}</label>
</div>
<div class="property flexrow">
<label class="property-label">{{localize "Defense score"}}</label>
<label class="property-label">{{localize "BOL.ui.defenseScore"}}</label>
<label class="property-label">{{defender.data.aptitudes.def.value}}</label>
</div>
{{/if}}