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; return arme;
} }
static isArmeUtilisable(item) {
return item.type == 'arme' && item.data.resistance > 0;
}
static mainsNues(actorData={}) { static mainsNues(actorData={}) {
const mainsNues = { const mainsNues = {

View File

@ -1,7 +1,6 @@
/* -------------------------------------------- */ /* -------------------------------------------- */
export class RdDItemCompetenceCreature extends Item { export class RdDItemCompetenceCreature extends Item {
/* -------------------------------------------- */ /* -------------------------------------------- */
static setRollDataCreature(rollData) { static setRollDataCreature(rollData) {
rollData.carac = { "carac_creature": { label: rollData.competence.name, value: rollData.competence.data.carac_value } }; 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) { static toArme(item) {
if (item.type == 'competencecreature' && item.data.iscombat) { if (RdDItemCompetenceCreature.isCompetenceAttaque(item)) {
let arme = { name: item.name, data: duplicate(item.data) }; let arme = { name: item.name, data: duplicate(item.data) };
mergeObject(arme.data, mergeObject(arme.data,
{ {
@ -34,4 +33,11 @@ export class RdDItemCompetenceCreature extends Item {
return undefined; 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) { _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) { switch (competence.data.categorie) {
case 'tir': case 'tir':
case 'lancer': case 'lancer':
@ -743,20 +743,20 @@ export class RdDCombat {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async computeDeteriorationArme(rollData) { async computeDeteriorationArme(defenderRoll) {
if (!ReglesOptionelles.isUsing('resistanceArmeParade')) { if (!ReglesOptionelles.isUsing('resistanceArmeParade')) {
return; return;
} }
const attackerRoll = rollData.attackerRoll; const attackerRoll = defenderRoll.attackerRoll;
// Est-ce une parade normale? // 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 // 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; 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 = ""; let msg = "";
// Jet de résistance de l'arme de parade (p.132) // Jet de résistance de l'arme de parade (p.132)
let resistRoll = await RdDResolutionTable.rollData({ let resistRoll = await RdDResolutionTable.rollData({
@ -765,26 +765,21 @@ export class RdDCombat {
showDice: false showDice: false
}); });
if (resistRoll.rolled.isSuccess) { // Perte de résistance if (resistRoll.rolled.isSuccess) { // Perte de résistance
rollData.show.deteriorationArme = 'resiste'; defenderRoll.show.deteriorationArme = 'resiste';
} else { } else {
resistance -= dmg; resistance -= dmg;
if (resistance <= 0) { defenderRoll.show.deteriorationArme = resistance <= 0 ? 'brise': 'perte';
this.defender.deleteEmbeddedEntity("OwnedItem", rollData.arme._id); defenderRoll.show.perteResistance = dmg;
rollData.show.deteriorationArme = 'brise'; this.defender.updateEmbeddedEntity("OwnedItem", { _id: defenderRoll.arme._id, 'data.resistance': resistance });
} else {
this.defender.updateEmbeddedEntity("OwnedItem", { _id: rollData.arme._id, 'data.resistance': resistance });
rollData.show.deteriorationArme = 'perte';
rollData.show.perteResistance = dmg;
}
} }
// Si l'arme de parade n'est pas un bouclier, jet de désarmement (p.132) // 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({ let desarme = await RdDResolutionTable.rollData({
caracValue: this.defender.getForce(), caracValue: this.defender.getForce(),
finalLevel: Misc.toInt(rollData.competence.data.niveau) - dmg, finalLevel: Misc.toInt(defenderRoll.competence.data.niveau) - dmg,
showDice: false 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) async computeRecul(defenderRoll) { // Calcul du recul (p. 132)
const attackerRoll = defenderRoll.attackerRoll; const attackerRoll = defenderRoll.attackerRoll;
if (ReglesOptionelles.isUsing('recul') && this._isAttaqueCauseRecul(attackerRoll)) { if (ReglesOptionelles.isUsing('recul') && this._isForceOuCharge(attackerRoll)) {
const impact = this._computeImpactRecul(attackerRoll); const impact = this._computeImpactRecul(attackerRoll);
const rollRecul = await RdDResolutionTable.rollData({ caracValue: 10, finalLevel: impact }); const rollRecul = await RdDResolutionTable.rollData({ caracValue: 10, finalLevel: impact });
if (rollRecul.rolled.isSuccess) { if (rollRecul.rolled.isSuccess) {
@ -816,7 +811,7 @@ export class RdDCombat {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_isAttaqueCauseRecul(attaque) { _isForceOuCharge(attaque) {
return attaque.particuliere == 'force' || attaque.tactique == 'charge'; return attaque.particuliere == 'force' || attaque.tactique == 'charge';
} }

View File

@ -715,11 +715,11 @@ export class RdDUtility {
let items = actor.data.items; let items = actor.data.items;
let actions = [] let actions = []
if (actor.isCreature()) { 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))); .map(competence => RdDItemCompetenceCreature.toArme(competence)));
} else { } else {
// Recupération des items 'arme' // 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 */ .map(arme => duplicate(arme)) /* pas de changements aux armes d'origine */
.concat(RdDItemArme.mainsNues()); .concat(RdDItemArme.mainsNues());