Merge pull request #2 from sladecraven/master

Gestion attaque d'arme, step1
This commit is contained in:
ZigmundKreud 2021-12-27 23:45:37 +01:00 committed by GitHub
commit 3fe224f1b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 313 additions and 10 deletions

View File

@ -92,6 +92,8 @@
"BOL.ui.treasure" : "Trésor",
"BOL.ui.vehicles" : "Véhicules/Montures",
"BOL.ui.misc" : "Divers",
"BOL.ui.noWeaponName" : "Unknown Weapon",
"BOL.ui.targetDefence": "Defence",
"BOL.featureCategory.origins": "Origines",
"BOL.featureCategory.races": "Races",

View File

@ -94,6 +94,8 @@
"BOL.ui.misc" : "Divers",
"BOL.ui.vehicleProperties" : " Propriétés de véhicule",
"BOL.ui.speed" : "Vitesse",
"BOL.ui.noWeaponName" : "Arme Inconnue",
"BOL.ui.targetDefence": "Défense",
"BOL.featureCategory.origins": "Origines",
"BOL.featureCategory.races": "Races",

View File

@ -185,6 +185,9 @@ export class BoLActorSheet extends ActorSheet {
case "aptitude" :
BoLRoll.aptitudeCheck(this.actor, actorData, dataset, event);
break;
case "weapon":
BoLRoll.weaponCheck(this.actor, actorData, dataset, event);
break;
default : break;
}
}

View File

@ -41,6 +41,9 @@ export class BoLActor extends Actor {
get aptitudes() {
return Object.values(this.data.data.aptitudes);
}
get defenseValue() {
return this.data.data.aptitudes.def.value;
}
get resources() {
return Object.values(this.data.data.resources);
}
@ -84,7 +87,6 @@ export class BoLActor extends Actor {
get protections() {
return this.armors.concat(this.helms).concat(this.shields)
}
get melee() {
return this.weapons.filter(i => i.data.properties.melee === true);
}

View File

@ -1,3 +1,5 @@
import { BoLUtility } from "../system/bol-utility.js";
export class BoLRoll {
static options() {
return { classes: ["bol", "dialog"] };
@ -25,6 +27,40 @@ export class BoLRoll {
return this.aptitudeRollDialog(actor, actorData, aptitude, label, description, adv, 0);
}
static weaponCheck(actor, actorData, dataset, event) {
// 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 !");
return;
}
let weaponData = weapon.data.data;
let attackDef= {
id:randomID(16),
attacker: actor,
attackerData: actorData,
weapon :weapon,
mod: 0,
target : target,
defender: game.actors.get(target.data.actorId),
adv :dataset.adv || 0,
attribute : eval(`actor.data.data.attributes.${weaponData.properties.attackAttribute}`),
aptitude : eval(`actor.data.data.aptitudes.${weaponData.properties.attackAptitude}`),
label : (weapon.name) ? weapon.name : game.i18n.localize('BOL.ui.noWeaponName'),
description : actor.name + " - " + game.i18n.localize('BOL.ui.weaponAttack'),
}
console.log("WEAPON!", attackDef, weaponData);
return this.weaponRollDialog(attackDef);
}
/* -------------------------------------------- */
/* ROLL DIALOGS */
/* -------------------------------------------- */
@ -58,7 +94,7 @@ export class BoLRoll {
const adv = html.find('#adv').val();
const mod = html.find('#mod').val();
let careers = html.find('#career').val();
const career = (!careers) ? 0 : Math.max(...careers.map(i => parseInt(i)));
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(`actor.data.data.attributes.${attr}.value`);
@ -75,6 +111,59 @@ export class BoLRoll {
return d.render(true);
}
static async weaponRollDialog( attackDef) {
const rollOptionTpl = 'systems/bol/templates/dialogs/weapon-roll-dialog.hbs';
const dialogData = {
attr:attackDef.attribute,
adv:attackDef.adv,
mod: attackDef.mod,
apt:attackDef.aptitude,
weapon: attackDef.weapon,
attackId: attackDef.id,
careers: attackDef.attackerData.features.careers,
boons: attackDef.attackerData.features.boons,
flaws: attackDef.attackerData.features.flaws,
defence: attackDef.defender.defenseValue,
};
const rollOptionContent = await renderTemplate(rollOptionTpl, dialogData);
let d = new Dialog({
title: attackDef.label,
content: rollOptionContent,
buttons: {
cancel: {
icon: '<i class="fas fa-times"></i>',
label: game.i18n.localize("BOL.ui.cancel"),
callback: () => {
}
},
submit: {
icon: '<i class="fas fa-check"></i>',
label: game.i18n.localize("BOL.ui.submit"),
callback: (html) => {
const attr = html.find('#attr').val();
const apt = html.find('#apt').val();
const adv = html.find('#adv').val();
const mod = html.find('#mod').val() || 0;
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 formula = (isMalus) ? dicePool + "d6kl2 + " + modifiers : dicePool + "d6kh2 + " + modifiers;
attackDef.formula = formula;
let r = new BoLAttackRoll(attackDef);
r.roll();
}
}
},
default: 'submit',
close: () => {}
}, this.options());
return d.render(true);
}
static async aptitudeRollDialog(actor, actorData, aptitude, label, description, adv, mod, onEnter = "submit") {
const rollOptionTpl = 'systems/bol/templates/dialogs/aptitude-roll-dialog.hbs';
const dialogData = {
@ -104,7 +193,7 @@ export class BoLRoll {
const adv = html.find('#adv').val();
const mod = html.find('#mod').val();
let careers = html.find('#career').val();
const career = (!careers) ? 0 : Math.max(...careers.map(i => parseInt(i)));
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 aptValue = eval(`actor.data.data.aptitudes.${apt}.value`);
@ -123,12 +212,13 @@ export class BoLRoll {
}
export class BoLDefaultRoll {
constructor(label, formula, description){
constructor(label, formula, description, isWeapon=false){
this._label = label;
this._formula = formula;
this._isSuccess = false;
this._isCritical = false;
this._isFumble = false;
this._isWeapon = isWeapon;
this._description = description;
}
@ -148,6 +238,9 @@ export class BoLDefaultRoll {
flags : {msgType : "default"}
});
});
if (this._isSuccess && this._isWeapon) {
}
}
_buildChatMessage(actor) {
@ -167,6 +260,75 @@ export class BoLDefaultRoll {
}
export class BoLAttackRoll {
constructor(attackDef){
this.attackDef = attackDef;
this._isSuccess = false;
this._isCritical = false;
this._isFumble = false;
}
async roll(){
const r = new Roll(this.attackDef.formula);
await r.roll({"async": true});
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);
this._isCritical = (diceTotal === 12);
this._isFumble = (diceTotal === 2);
this._buildChatMessage(this.attackDef.attacker).then(msgFlavor => {
r.toMessage({
user: game.user.id,
flavor: msgFlavor,
speaker: ChatMessage.getSpeaker({actor: this.attackDef.attacker}),
flags : {msgType : "default"}
});
});
if (this._isSuccess ) {
let attrDamage = this.attackDef.weapon.data.data.properties.damageAttribute;
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});
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"}
});
});
}
}
_buildDamageChatMessage(actor, weapon, total) {
const rollMessageTpl = 'systems/bol/templates/chat/rolls/damage-roll-card.hbs';
const tplData = {
actor : actor,
label : this._label,
weapon: weapon,
damage: total,
};
return renderTemplate(rollMessageTpl, tplData);
}
_buildChatMessage(actor) {
const rollMessageTpl = 'systems/bol/templates/chat/rolls/default-roll-card.hbs';
const tplData = {
actor : actor,
label : this._label,
isSuccess : this._isSuccess,
isFailure : !this._isSuccess,
isCritical : this._isCritical,
isFumble : this._isFumble,
hasDescription : this._description && this._description.length > 0,
description : this._description
};
return renderTemplate(rollMessageTpl, tplData);
}
}
// export class BoLWeaponRoll {
// constructor(actor, label, formula, isCritical, description){
// this._label = label;

View File

@ -179,6 +179,30 @@ export class BoLUtility {
});
}
/* -------------------------------------------- */
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 modIndex = 3;
if ( res[3]) {
if ( res[3] == 'M') {
postForm = 'kl'+nbDice;
nbDice++;
modIndex = 4;
}
if ( res[3] == 'B') {
postForm = 'kh'+nbDice;
nbDice++;
modIndex = 4;
}
}
let formula = nbDice+"d"+res[2] + postForm + ((res[modIndex]) ? res[modIndex] : "");
return formula;
}
/* -------------------------------------------- */
static async confirmDelete(actorSheet, li) {
let itemId = li.data("item-id");

View File

@ -10,4 +10,14 @@ export const registerSystemSettings = function() {
onChange: lang => window.location.reload()
});
game.settings.register("bol", "rollArmor", {
name: "Effectuer des jets pour les armures",
hint: "Effectue un jet de dés pour les armures (valeur fixe si désactivé)",
scope: "world",
config: true,
default: true,
type: Boolean,
onChange: lang => window.location.reload()
});
};

View File

@ -5,3 +5,24 @@
<li class="item flexrow"><div class="item-image roll-weapon"><img src="icons/skills/melee/unarmed-punch-fist.webp" title="Attaque à mains nues"/></div><h4 class="item-name flex2"><a class="item-edit">Attaque à mains nues</a></h4></li>
</ol>
{{#each combat as |combatType id|}}
<ol class="items-list">
<li class="item flexrow item-header">
<div class="item-name flex2">{{localize combatType.label}}</div>
{{#if protection}}<div class="item-field">{{localize "BOL.ui.protection"}}</div>{{/if}}
{{#if blocking}}<div class="item-field">{{localize "BOL.ui.blocking"}}</div>{{/if}}
{{#if weapon}}<div class="item-field">{{localize "BOL.ui.damages"}}</div>{{/if}}
{{#if ranged}}<div class="item-field">{{localize "BOL.ui.range"}}</div>{{else}}<div class="item-field"></div>{{/if}}
</li>
{{#each combatType.items as |item id|}}
<li class="item flexrow" data-item-id="{{item._id}}">
<div class="item-image" ><img src="{{item.img}}" title="{{item.name}}"/></div>
<h4 class="item-name flex2">{{#if ../weapon}}<a class="rollable" data-roll-type="weapon">{{/if}}{{item.name}}{{#if ../weapon}}</a>{{/if}}</h4>
{{#if ../protection}}<div class="item-field">{{item.data.properties.soak.value}}</div>{{/if}}
{{#if ../blocking}}<div class="item-field">{{item.data.properties.blocking.malus}}</div>{{/if}}
{{#if ../weapon}}<div class="item-field">{{item.data.properties.damage}}</div>{{/if}}
{{#if ../ranged}}<div class="item-field">{{item.data.properties.range}}</div>{{else}}<div class="item-field"></div>{{/if}}
</li>
{{/each}}
</ol>
{{/each}}

View File

@ -8,17 +8,16 @@
</li>
</ol>
{{#each data.combat as | combat id|}}
{{#if (gt (count combat.items) 0)}}
{{#each combat as |combatType id|}}
<ol class="items-list">
<li class="item flexrow item-header">
<div class="item-name flex2">{{localize combat.label}}</div>
<div class="item-name flex2">{{localize combatType.label}}</div>
{{#if protection}}<div class="item-field">{{localize "BOL.ui.protection"}}</div>{{/if}}
{{#if blocking}}<div class="item-field">{{localize "BOL.ui.blocking"}}</div>{{/if}}
{{#if weapon}}<div class="item-field">{{localize "BOL.ui.damages"}}</div>{{/if}}
{{#if ranged}}<div class="item-field">{{localize "BOL.ui.range"}}</div>{{else}}<div class="item-field"></div>{{/if}}
</li>
{{#each combat.items as |item id|}}
{{#each combatType.items as |item id|}}
<li class="item flexrow" data-item-id="{{item._id}}">
<div class="item-image {{#if ../weapon}}roll-weapon{{/if}}"><img src="{{item.img}}" title="{{item.name}}"/></div>
<h4 class="item-name flex2"><a class="item-edit">{{item.name}}</a></h4>
@ -29,5 +28,4 @@
</li>
{{/each}}
</ol>
{{/if}}
{{/each}}

View File

@ -0,0 +1,7 @@
<img class="chat-icon" src="{{weapon.img}}" alt="{{weapon.name}}"/>
<h3><strong>Dommages de l'arme : {{damage}}</strong>
{{!#if hasDescription}}
<!--<h4>-->
<!-- <pre class="rollDescr-line">{{!description}}</pre>-->
<!--</h4>-->
{{!/if}}

View File

@ -0,0 +1,72 @@
<form class="{{cssClass}}" autocomplete="off">
{{!-- Sheet Header --}}
<header class="sheet-header">
<div class="row flexrow table-header">
<div class="flex1 center">
<h3>{{localize 'BOL.ui.weaponCheck'}}</h3>
</div>
</div>
</header>
<div class="flexrow" style="margin-bottom: 1px;">
<div class="flex1 center bg-darkred">
<label for="attr">{{localize 'BOL.ui.attribute'}}</label>
</div>
<div class="flex1 center cell">
<select class="flex1" name="attr" id="attr" data-type="String">
<option value="vigor" {{#if (equals attr.key "vigor")}}selected{{/if}}>{{localize 'BOL.attributes.vigor'}}</option>
<option value="agility" {{#if (equals attr.key "agility")}}selected{{/if}}>{{localize 'BOL.attributes.agility'}}</option>
<option value="mind" {{#if (equals attr.key "mind")}}selected{{/if}}>{{localize 'BOL.attributes.mind'}}</option>
<option value="appeal" {{#if (equals attr.key "appeal")}}selected{{/if}}>{{localize 'BOL.attributes.appeal'}}</option>
</select>
</div>
</div>
<div class="flexrow" style="margin-bottom: 1px;">
<div class="flex1 center bg-darkred">
<label for="apt">{{localize 'BOL.ui.aptitude'}}</label>
</div>
<div class="flex1 center cell">
<select class="flex1" name="apt" id="apt" data-type="String">
<option value="init" {{#if (equals apt.key "init")}}selected{{/if}}>{{localize 'BOL.aptitudes.init'}}</option>
<option value="melee" {{#if (equals apt.key "melee")}}selected{{/if}}>{{localize 'BOL.aptitudes.melee'}}</option>
<option value="ranged" {{#if (equals apt.key "ranged")}}selected{{/if}}>{{localize 'BOL.aptitudes.ranged'}}</option>
<option value="def" {{#if (equals apt.key "def")}}selected{{/if}}>{{localize 'BOL.aptitudes.def'}}</option>
</select>
</div>
</div>
<div class="flexrow" style="margin-bottom: 1px;">
<div class="flex1 center bg-darkred">
<label for="adv">{{localize 'BOL.ui.advantages'}}</label>
</div>
<div class="flex1 center cell">
<input type="text" class="field-value" name="adv" id="adv" value="{{adv}}" data-type="Number">
</div>
</div>
<div class="flexrow" style="margin-bottom: 1px;">
<div class="flex1 center bg-darkred">
<label for="mod">{{localize 'BOL.ui.modifiers'}}</label>
</div>
<div class="flex1 center cell">
<input type="text" class="field-value" name="mod" id="mod" value="{{mod}}" data-type="Number">
</div>
</div>
<div class="flexrow" style="margin-bottom: 1px;">
<div class="flex1 center bg-darkred">
<label for="mod">{{localize 'BOL.ui.targetDefence'}}</label>
</div>
<div class="flex1 center cell">{{defence}}</div>
</div>
{{#if careers.items}}
<div class="flexrow" style="margin-bottom: 1px;">
<div class="flex1 center bg-darkred">
<label for="mod">{{localize 'BOL.ui.careers'}}</label>
</div>
<div class="flex1 center cell">
<select class="flex1" name="career" id="career" data-type="String" multiple>
{{#each careers.items as | career id|}}
<option value="{{career.data.rank}}">{{career.name}} ({{numberFormat career.data.rank decimals=0 sign=true}})</option>
{{/each}}
</select>
</div>
</div>
{{/if}}
</form>