ne pas proposer les armes inutilisables

This commit is contained in:
Vincent Vandemeulebrouck 2021-01-28 00:27:44 +01:00
parent 96d55a7cad
commit 4825ae9b0b
4 changed files with 29 additions and 25 deletions

View File

@ -144,6 +144,9 @@ export class RdDItemArme extends Item {
return arme;
}
static isArmeUtilisable(item) {
return item.type == 'arme' && item.data.resistance > 0;
}
static mainsNues(actorData={}) {
const mainsNues = {

View File

@ -1,7 +1,6 @@
/* -------------------------------------------- */
export class RdDItemCompetenceCreature extends Item {
/* -------------------------------------------- */
static setRollDataCreature(rollData) {
rollData.carac = { "carac_creature": { label: rollData.competence.name, value: rollData.competence.data.carac_value } };
@ -17,7 +16,7 @@ export class RdDItemCompetenceCreature extends Item {
/* -------------------------------------------- */
static toArme(item) {
if (item.type == 'competencecreature' && item.data.iscombat) {
if (RdDItemCompetenceCreature.isCompetenceAttaque(item)) {
let arme = { name: item.name, data: duplicate(item.data) };
mergeObject(arme.data,
{
@ -34,4 +33,11 @@ export class RdDItemCompetenceCreature extends Item {
return undefined;
}
static isCompetenceAttaque(item) {
return item.type == 'competencecreature' && item.data.iscombat;
}
static isCompetenceParade(item) {
return item.type == 'competencecreature' && item.data.isparade;
}
}

View File

@ -510,7 +510,7 @@ export class RdDCombat {
/* -------------------------------------------- */
_filterArmesParade(items, competence) {
items = items.filter(item => (item.type == 'arme' && item.data.equipe) || (item.type == 'competencecreature' && item.data.isparade));
items = items.filter(item => RdDItemArme.isArmeUtilisable(item) || RdDItemCompetenceCreature.isCompetenceParade(item));
switch (competence.data.categorie) {
case 'tir':
case 'lancer':
@ -743,20 +743,20 @@ export class RdDCombat {
}
/* -------------------------------------------- */
async computeDeteriorationArme(rollData) {
async computeDeteriorationArme(defenderRoll) {
if (!ReglesOptionelles.isUsing('resistanceArmeParade')) {
return;
}
const attackerRoll = rollData.attackerRoll;
const attackerRoll = defenderRoll.attackerRoll;
// Est-ce une parade normale?
if (rollData.arme && attackerRoll && !rollData.rolled.isPart) {
if (defenderRoll.arme && attackerRoll && !defenderRoll.rolled.isPart) {
// Est-ce que l'attaque est une particulière en force ou une charge
if (rollData.needResist || attackerRoll.particuliere == 'force' || attackerRoll.tactique == 'charge') {
if (defenderRoll.needResist || this._isForceOuCharge(attackerRoll)) {
rollData.show = rollData.show || {}
defenderRoll.show = defenderRoll.show || {}
const dmg = attackerRoll.dmg.dmgArme + attackerRoll.dmg.dmgActor;
let resistance = Misc.toInt(rollData.arme.data.resistance);
let resistance = Misc.toInt(defenderRoll.arme.data.resistance);
let msg = "";
// Jet de résistance de l'arme de parade (p.132)
let resistRoll = await RdDResolutionTable.rollData({
@ -765,26 +765,21 @@ export class RdDCombat {
showDice: false
});
if (resistRoll.rolled.isSuccess) { // Perte de résistance
rollData.show.deteriorationArme = 'resiste';
defenderRoll.show.deteriorationArme = 'resiste';
} else {
resistance -= dmg;
if (resistance <= 0) {
this.defender.deleteEmbeddedEntity("OwnedItem", rollData.arme._id);
rollData.show.deteriorationArme = 'brise';
} else {
this.defender.updateEmbeddedEntity("OwnedItem", { _id: rollData.arme._id, 'data.resistance': resistance });
rollData.show.deteriorationArme = 'perte';
rollData.show.perteResistance = dmg;
}
defenderRoll.show.deteriorationArme = resistance <= 0 ? 'brise': 'perte';
defenderRoll.show.perteResistance = dmg;
this.defender.updateEmbeddedEntity("OwnedItem", { _id: defenderRoll.arme._id, 'data.resistance': resistance });
}
// Si l'arme de parade n'est pas un bouclier, jet de désarmement (p.132)
if (ReglesOptionelles.isUsing('defenseurDesarme') && resistance > 0 && RdDItemArme.getCategorieParade(rollData.arme) != 'boucliers') {
if (ReglesOptionelles.isUsing('defenseurDesarme') && resistance > 0 && RdDItemArme.getCategorieParade(defenderRoll.arme) != 'boucliers') {
let desarme = await RdDResolutionTable.rollData({
caracValue: this.defender.getForce(),
finalLevel: Misc.toInt(rollData.competence.data.niveau) - dmg,
finalLevel: Misc.toInt(defenderRoll.competence.data.niveau) - dmg,
showDice: false
});
rollData.show.desarme = desarme.rolled.isEchec;
defenderRoll.show.desarme = desarme.rolled.isEchec;
}
}
}
@ -793,7 +788,7 @@ export class RdDCombat {
/* -------------------------------------------- */
async computeRecul(defenderRoll) { // Calcul du recul (p. 132)
const attackerRoll = defenderRoll.attackerRoll;
if (ReglesOptionelles.isUsing('recul') && this._isAttaqueCauseRecul(attackerRoll)) {
if (ReglesOptionelles.isUsing('recul') && this._isForceOuCharge(attackerRoll)) {
const impact = this._computeImpactRecul(attackerRoll);
const rollRecul = await RdDResolutionTable.rollData({ caracValue: 10, finalLevel: impact });
if (rollRecul.rolled.isSuccess) {
@ -816,7 +811,7 @@ export class RdDCombat {
}
/* -------------------------------------------- */
_isAttaqueCauseRecul(attaque) {
_isForceOuCharge(attaque) {
return attaque.particuliere == 'force' || attaque.tactique == 'charge';
}

View File

@ -715,11 +715,11 @@ export class RdDUtility {
let items = actor.data.items;
let actions = []
if (actor.isCreature()) {
actions = actions.concat(items.filter(it => it.type == 'competencecreature' && it.data.iscombat)
actions = actions.concat(items.filter(it => RdDItemCompetenceCreature.isCompetenceAttaque(it))
.map(competence => RdDItemCompetenceCreature.toArme(competence)));
} else {
// Recupération des items 'arme'
let armes = items.filter(it => it.type == 'arme')
let armes = items.filter(it => RdDItemArme.isArmeUtilisable(it))
.map(arme => duplicate(arme)) /* pas de changements aux armes d'origine */
.concat(RdDItemArme.mainsNues());