Fix armes 2m dans l'onglet Combat

Les armes 1 ou 2 mains n'étaient pas bien choisies dans l'onglet
combat de la feuille de personnage.

Un message d'erreur pour les dommages 1/2 mains était faux
depuis cet onglet
This commit is contained in:
Vincent Vandemeulebrouck 2021-11-20 01:19:29 +01:00
parent f91dfd04a2
commit a2f859a460
4 changed files with 44 additions and 21 deletions

View File

@ -344,24 +344,16 @@ export class RdDActorSheet extends ActorSheet {
// Roll Weapon1
html.find('.arme-label a').click(async event => {
let armeName = event.currentTarget.text;
let compName = event.currentTarget.attributes['data-competence-name'].value;
let arme = this.actor.data.items.find(it =>
it.name == armeName &&
RdDItemArme.isArme(it) &&
((compName || it.data.data.competence) == it.data.data.competence)
);
if (!arme) {
arme = { name: armeName, data: { competence: compName } };
}
const li = $(event.currentTarget).parents(".item");
let arme = this._getArmeCombat(li);
this.actor.rollArme( duplicate(arme) );
});
// Initiative pour l'arme
html.find('.arme-initiative a').click(async event => {
let combatant = game.combat.data.combatants.find(c => c.actor.data._id == this.actor.data._id);
if (combatant) {
let armeName = event.currentTarget.attributes['data-arme-name'].value;
let arme = this.armesList.find(a => a.name == armeName);
const li = $(event.currentTarget).parents(".item");
let arme = this._getArmeCombat(li);
RdDCombatManager.rollInitiativeCompetence(combatant._id, arme);
} else {
ui.notifications.info("Impossible de lancer l'initiative sans être dans un combat.");
@ -543,6 +535,16 @@ export class RdDActorSheet extends ActorSheet {
}
_getArmeCombat(li) {
let armeName = li.data("arme-name");
let compName = li.data('competence-name');
const arme = this.armesList.find(a => a.name == armeName && a.data.competence == compName);
if (!arme) {
return { name: armeName, data: { competence: compName } };
}
return arme;
}
/* -------------------------------------------- */
/** @override */
setPosition(options = {}) {

View File

@ -177,6 +177,7 @@ export class RdDItemArme extends Item {
static corpsACorps(actorData) {
const corpsACorps = {
name: 'Corps à corps',
img: 'systems/foundryvtt-reve-de-dragon/icons/competence_corps_a_corps.webp',
data: {
equipe: true,
rapide: true,

View File

@ -151,11 +151,12 @@ export class RdDCombatManager extends Combat {
// Gestion des armes 1/2 mains
let armesEquipe = [];
for (const arme of armes) {
let armeData = Misc.data(arme);
let armeData = duplicate(Misc.data(arme));
if (armeData.data.equipe) {
let compData = competences.map(c => Misc.data(c)).find(c => c.name == armeData.data.competence);
armesEquipe.push(armeData);
armeData.data.dommagesReels = Number(armeData.data.dommages);
armeData.data.niveau = compData.data.niveau;
armeData.data.initiative = RdDCombatManager.calculInitiative(compData.data.niveau, carac[compData.data.defaut_carac].value);
// Dupliquer les armes pouvant être à 1 main et 2 mains en patchant la compétence
@ -165,14 +166,25 @@ export class RdDCombatManager extends Combat {
armeData.data.mainInfo = "(2m)";
} else if (armeData.data.unemain && armeData.data.deuxmains) {
armeData.data.mainInfo = "(1m)";
let arme2main = duplicate(armeData);
const comp2m = armeData.data.competence.replace(" 1 main", " 2 mains"); // Replace !
const comp = Misc.data(competences.find(c => c.name == comp2m));
const arme2main = duplicate(armeData);
arme2main.data.mainInfo = "(2m)";
arme2main.data.dommages = arme2main.data.dommages.split("/")[1]; // Existence temporaire uniquement dans la liste des armes, donc OK
arme2main.data.competence = arme2main.data.competence.replace(" 1 main", " 2 mains"); // Replace !
let comp = Misc.data(competences.find(c => c.name == arme2main.data.competence));
arme2main.data.niveau = comp.data.niveau;
arme2main.data.competence = comp2m;
arme2main.data.initiative = RdDCombatManager.calculInitiative(arme2main.data.niveau, carac[comp.data.defaut_carac].value);
armesEquipe.push(arme2main);
const containsSlash = armeData.data.dommages.includes("/");
if (containsSlash) {
const tableauDegats = armeData.data.dommages.split("/");
armeData.data.dommagesReels = Number(tableauDegats[0]);
arme2main.data.dommagesReels = Number(tableauDegats[1]);
}
else{
ui.notifications.info("Les dommages de l'arme à 1/2 mains " + armeData.name + " ne sont pas corrects (ie sous la forme X/Y)");
}
}
}
}

View File

@ -274,12 +274,20 @@
<span class="competence-title competence-value">+dom</span>
</li>
{{#each combat as |arme key|}}
<li class="item flexrow list-item" data-item-id="{{arme._id}}">
<span class="arme-label"><a data-competence-name="{{arme.data.competence}}">{{arme.name}}</a></span>
<span class="arme-initiative"><a data-arme-name="{{arme.name}}" data-competence-name="{{arme.data.competence}}">{{arme.data.initiative}}</a></span>
<li class="item flexrow list-item" data-item-id="{{arme._id}}"
data-arme-name="{{arme.name}}" data-competence-name="{{arme.data.competence}}" >
<span class="arme-label">
<a>
{{#if arme.img}}
<img class="sheet-competence-img" src="{{arme.img}}"/>
{{/if}}
<span>{{arme.name}}</span>
</a>
</span>
<span class="arme-initiative"><a>{{arme.data.initiative}}</a></span>
<span class="competence-label">{{arme.data.competence}}</span>
<span class="competence-value">{{numberFormat arme.data.niveau decimals=0 sign=true}}</span>
<span class="competence-value">{{numberFormat arme.data.dommages decimals=0 sign=true}}</span>
<span class="competence-value">{{numberFormat arme.data.dommagesReels decimals=0 sign=true}}</span>
</li>
{{/each}}
<li class="item flexrow list-item">