#42 Tchat message attaque

This commit is contained in:
Vincent Vandemeulebrouck 2021-01-01 22:25:32 +01:00
parent be90e0c032
commit cd36331702
7 changed files with 71 additions and 81 deletions

View File

@ -15,6 +15,7 @@ import { RdDEncaisser } from "./rdd-roll-encaisser.js";
import { RdDCombat } from "./rdd-combat.js"; import { RdDCombat } from "./rdd-combat.js";
import { DeDraconique } from "./de-draconique.js"; import { DeDraconique } from "./de-draconique.js";
import { RdDAudio } from "./rdd-audio.js"; import { RdDAudio } from "./rdd-audio.js";
import { RdDItemCompetence } from "./item-competence.js";
/* -------------------------------------------- */ /* -------------------------------------------- */
/** /**
@ -1556,14 +1557,13 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async rollCompetence( name ) { async rollCompetence( name ) {
let rollData = { let rollData = {
competence: duplicate(this.getCompetence(name)), competence: this.getCompetence(name),
needSignificative : !this.isEntiteCauchemar() && this.data.data.sante.sonne.value needSignificative : !this.isEntiteCauchemar() && this.data.data.sante.sonne.value
} }
if (rollData.competence.type == 'competencecreature') { if (rollData.competence.type == 'competencecreature') {
// Fake competence pour créature // Fake competence pour créature
rollData.competence.data = { defaut_carac: "carac_creature", categorie: "creature" }; RdDItemCompetence.setRollDataCreature(rollData);
rollData.carac = { carac_creature: { label: competence.name, value: competence.data.carac_value } };
} }
else { else {
rollData.carac = this.data.data.carac; rollData.carac = this.data.data.carac;
@ -1889,7 +1889,7 @@ export class RdDActor extends Actor {
RdDCombat.createUsingTarget(this).attaque(competence, armeItem); RdDCombat.createUsingTarget(this).attaque(competence, armeItem);
} }
else { else {
this.rollCompetence(name); this.rollCompetence(competence.name);
} }
} }

View File

@ -2,6 +2,24 @@
export class RdDItemArme extends Item { export class RdDItemArme extends Item {
/* -------------------------------------------- */ /* -------------------------------------------- */
static getArmeData(item) {
switch (item ? item.data.type : '') {
case 'arme': return item.data;
case 'competencecreature':
return RdDItemArme._getArmeCompetenceCreature(item);
}
return RdDItemArme.mainsNues();
}
/* -------------------------------------------- */
static _getArmeCompetenceCreature(competenceCreature) {
let armeData = duplicate(competenceCreature.data);
armeData.data.resistance = 100;
armeData.data.competence = armeData.name;
armeData.data.dommagesReels = armeData.data.dommagesReels || armeData.data.dommages;
return armeData;
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static getCategorieParade(arme) { static getCategorieParade(arme) {
if (arme.data.categorie_parade) { if (arme.data.categorie_parade) {
@ -38,6 +56,11 @@ export class RdDItemArme extends Item {
return 'sans-armes'; return 'sans-armes';
} }
/* -------------------------------------------- */
static isArmeParade(arme) {
return RdDItemArme.getCategorieParade(arme);
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static needParadeSignificative(armeAttaque, armeParade) { static needParadeSignificative(armeAttaque, armeParade) {
let attCategory = RdDItemArme.getCategorieParade(armeAttaque); let attCategory = RdDItemArme.getCategorieParade(armeAttaque);

View File

@ -11,4 +11,12 @@ export class RdDItemCompetence extends Item {
static isMalusEncombrementTotal(competence) { static isMalusEncombrementTotal(competence) {
return competence && competence.name.toLowerCase().match(/(natation|acrobatie)/); return competence && competence.name.toLowerCase().match(/(natation|acrobatie)/);
} }
static setRollDataCreature(rollData) {
rollData.carac = { "carac_creature": { label: rollData.competence.name, value: rollData.competence.data.carac_value } };
rollData.competence = duplicate(rollData.competence);
rollData.competence.data.defaut_carac = "carac_creature";
rollData.competence.data.categorie = "creature";
rollData.selectedCarac = rollData.carac.carac_creature
}
} }

View File

@ -192,7 +192,7 @@ export class RdDCombat {
}; };
if (this.attacker.isCreature()) { if (this.attacker.isCreature()) {
this._modifieRollDataCreature(rollData, competence); RdDItemCompetence.setRollDataCreature(rollData);
} }
else if (arme) { else if (arme) {
// Usual competence // Usual competence
@ -205,22 +205,6 @@ export class RdDCombat {
return rollData; return rollData;
} }
/* -------------------------------------------- */
_modifieRollDataCreature(rollData, competence) {
competence = duplicate(competence);
competence.data.defaut_carac = "carac_creature";
competence.data.categorie = "creature";
rollData.competence = competence;
rollData.carac = { "carac_creature": { label: competence.name, value: competence.data.carac_value } };
rollData.arme = {
name: competence.name, data: {
dommages: competence.data.dommages,
dommagesReels: competence.data.dommages
}
};
}
/* -------------------------------------------- */ /* -------------------------------------------- */
_onAttaqueParticuliere(rollData) { _onAttaqueParticuliere(rollData) {
console.log("RdDCombat.onAttaqueParticuliere >>>", rollData); console.log("RdDCombat.onAttaqueParticuliere >>>", rollData);
@ -243,31 +227,12 @@ export class RdDCombat {
/* -------------------------------------------- */ /* -------------------------------------------- */
async _onAttaqueNormale(rollData) { async _onAttaqueNormale(rollData) {
console.log("RdDCombat.onAttaqueNormale >>>", rollData); console.log("RdDCombat.onAttaqueNormale >>>", rollData);
let explications = "";
rollData.dmg = RdDBonus.dmg(rollData, this.attacker.getBonusDegat(), this.defender.isEntiteCauchemar()); rollData.dmg = RdDBonus.dmg(rollData, this.attacker.getBonusDegat(), this.defender.isEntiteCauchemar());
if (this.target) {
explications += "<br><strong>Cible</strong> : " + this.defender.data.name;
}
explications += "<br>Encaissement à " + Misc.toSignedString(rollData.dmg.total) + " (" + rollData.dmg.loc.label + ")";
// Save rollData for defender // Save rollData for defender
game.system.rdd.rollDataHandler[this.attackerId] = duplicate(rollData); game.system.rdd.rollDataHandler[this.attackerId] = duplicate(rollData);
// Message spécial pour la rapidité, qui reste difficile à gérer automatiquement
if (rollData.particuliereAttaque == 'rapidite') {
explications += "<br>Vous avez attaqué en Rapidité. Vous pourrez faire une deuxième attaque, ou utiliser votre arme pour vous défendre.";
}
// Final chat message
let chatOptions = {
content: "<strong>Test : " + rollData.selectedCarac.label + " / " + rollData.competence.name + "</strong>"
+ RdDResolutionTable.explainRollData(rollData)
+ explications
}
ChatUtility.chatWithRollMode(chatOptions, this.attacker.name)
rollData.show = { rollData.show = {
cible: this.target ? this.defender.data.name : 'la cible', cible: this.target ? this.defender.data.name : 'la cible',
isRecul: (rollData.particuliereAttaque == 'force' || rollData.tactique == 'charge') isRecul: (rollData.particuliereAttaque == 'force' || rollData.tactique == 'charge')
@ -306,7 +271,7 @@ export class RdDCombat {
message += "<br><a class='chat-card-button' id='parer-button' data-attackerId='" + this.attackerId + "' data-defenderTokenId='" + this.defenderTokenId + "' data-armeid='" + arme._id + "'>Parer avec " + arme.name + "</a>"; message += "<br><a class='chat-card-button' id='parer-button' data-attackerId='" + this.attackerId + "' data-defenderTokenId='" + this.defenderTokenId + "' data-armeid='" + arme._id + "'>Parer avec " + arme.name + "</a>";
} }
// corps à corps // corps à corps
if (rollData.dmg.mortalite != 'mortel') { if (rollData.dmg.mortalite != 'mortel' && this.defender.getCompetence("Corps à corps")) {
message += "<br><a class='chat-card-button' id='parer-button' data-attackerId='" + this.attackerId + "' data-defenderTokenId='" + this.defenderTokenId + "'>Parer à mains nues</a>"; message += "<br><a class='chat-card-button' id='parer-button' data-attackerId='" + this.attackerId + "' data-defenderTokenId='" + this.defenderTokenId + "'>Parer à mains nues</a>";
} }
// esquive // esquive
@ -327,20 +292,9 @@ export class RdDCombat {
switch (categorie) { switch (categorie) {
case 'tir': case 'tir':
case 'lancer': case 'lancer':
return items.filter(item => return items.filter(item => RdDItemArme.getCategorieParade(item) == 'boucliers')
item.type == 'arme' &&
item.data.competence.toLowerCase().match("bouclier"));
default: default:
return items.filter(item => { return items.filter(item => RdDItemArme.getCategorieParade(item));
if (item.type == 'competencecreature') {
return item.data.isparade;
}
if (item.type == 'arme') {
const comp = this.defender.getCompetence(item.data.competence);
return comp && comp.data.categorie == 'melee';
}
return false;
});
} }
} }
@ -349,7 +303,7 @@ export class RdDCombat {
console.log("RdDCombat.onEchecTotal >>>", rollData); console.log("RdDCombat.onEchecTotal >>>", rollData);
let chatOptions = { let chatOptions = {
content: "<strong>Echec total à l'attaque!</strong> " content: "<strong>Echec total à l'attaque!</strong> "
+ await RdDRollTables.getMaladresse({ arme: rollData.arme && !rollData.arme.data.sansArme }) + await RdDRollTables.getMaladresse({ arme: rollData.arme && rollData.arme.data.categorie_parade != 'sans-armes' })
} }
ChatUtility.chatWithRollMode(chatOptions, this.attacker.name) ChatUtility.chatWithRollMode(chatOptions, this.attacker.name)
} }
@ -400,17 +354,12 @@ export class RdDCombat {
} }
_findArmeParade(armeParadeId) { _findArmeParade(armeParadeId) {
if (armeParadeId) { return RdDItemArme.getArmeData(armeParadeId ? this.defender.getOwnedItem(armeParadeId) : null);
const armeItem = this.defender.getOwnedItem(armeParadeId);
return armeItem.data;
}
return RdDItemArme.mainsNues()
} }
_prepareParade(attackerRoll, armeParade) { _prepareParade(attackerRoll, armeParade) {
const isCreature = this.defender.isCreature(); const isCreature = this.defender.isCreature();
const compName = isCreature ? armeParade.name : armeParade.data.competence; const compName = armeParade.data.competence;
const competence = this.defender.getCompetence(compName); const competence = this.defender.getCompetence(compName);
const armeAttaque = attackerRoll.arme; const armeAttaque = attackerRoll.arme;
@ -432,7 +381,7 @@ export class RdDCombat {
carac: this.defender.data.data.carac carac: this.defender.data.data.carac
}; };
if (isCreature) { if (isCreature) {
this._modifieRollDataCreature(rollData, competence); RdDItemCompetence.setRollDataCreature(rollData);
} }
return rollData; return rollData;
} }
@ -444,11 +393,11 @@ export class RdDCombat {
/* -------------------------------------------- */ /* -------------------------------------------- */
_needResist(armeAttaque, armeParade) { _needResist(armeAttaque, armeParade) {
// Manage weapon categories when parrying (cf. page 115 ) // Epées parant une arme de bois (cf. page 115 ), une résistance est nécessaire
let attCategory = RdDItemArme.getCategorieArme(armeAttaque); let attCategory = RdDItemArme.getCategorieParade(armeAttaque);
let defCategory = RdDItemArme.getCategorieArme(armeParade); let defCategory = RdDItemArme.getCategorieParade(armeParade);
return (attCategory.match("epee") && (defCategory == "hache" || defCategory == "lance")); return attCategory.match(/epees-/) && defCategory.match(/(haches|lances)/);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -482,7 +431,7 @@ export class RdDCombat {
console.log("RdDCombat._onParadeEchecTotal >>>", rollData); console.log("RdDCombat._onParadeEchecTotal >>>", rollData);
let chatOptions = { let chatOptions = {
content: "<strong>Echec total à la parade!</strong> " content: "<strong>Echec total à la parade!</strong> "
+ await RdDRollTables.getMaladresse({ arme: rollData.arme && !rollData.arme.data.sansArme }) + await RdDRollTables.getMaladresse({ arme: rollData.arme && rollData.arme.data.categorie_parade != 'sans-armes' })
} }
ChatUtility.chatWithRollMode(chatOptions, this.defender.name) ChatUtility.chatWithRollMode(chatOptions, this.defender.name)
} }
@ -550,7 +499,7 @@ export class RdDCombat {
}; };
if (this.defender.isCreature()) { if (this.defender.isCreature()) {
this._modifieRollDataCreature(rollData, competence); RdDItemCompetence.setRollDataCreature(rollData);
} }
return rollData; return rollData;
} }

View File

@ -197,8 +197,14 @@ export class RdDUtility {
// HUD // HUD
'systems/foundryvtt-reve-de-dragon/templates/hud-actor-init.html', 'systems/foundryvtt-reve-de-dragon/templates/hud-actor-init.html',
'systems/foundryvtt-reve-de-dragon/templates/hud-actor-attaque.html', 'systems/foundryvtt-reve-de-dragon/templates/hud-actor-attaque.html',
// POST // messages tchat
'systems/foundryvtt-reve-de-dragon/templates/post-item.html' 'systems/foundryvtt-reve-de-dragon/templates/chat-resultat-appelchance.html',
'systems/foundryvtt-reve-de-dragon/templates/chat-resultat-attaque.html',
'systems/foundryvtt-reve-de-dragon/templates/chat-resultat-competence.html',
'systems/foundryvtt-reve-de-dragon/templates/chat-resultat-general.html',
'systems/foundryvtt-reve-de-dragon/templates/chat-resultat-tache.html',
'systems/foundryvtt-reve-de-dragon/templates/chat-resultat-sort.html',
]; ];
return loadTemplates(templatePaths); return loadTemplates(templatePaths);

View File

@ -813,6 +813,10 @@ ul, li {
background: rgba(220,220,210,0.75); background: rgba(220,220,210,0.75);
border: 2px solid #545469; border: 2px solid #545469;
} }
.chat-message .chat-icon {
border: 0;
float: left;
}
#sidebar-tabs { #sidebar-tabs {
flex: 0 0 32px; flex: 0 0 32px;

View File

@ -23,24 +23,24 @@
{{#if tactique}} {{#if tactique}}
<div> <div>
{{#if (eq tactique 'charge')}} {{#if (eq tactique 'charge')}}
<img style="float: left; border: 0;" src="icons/svg/thrust.svg" alt="charge" height="32" width="32" /> <img class="chat-icon" src="icons/svg/thrust.svg" alt="charge" height="32" width="32" />
C'est une charge, vos parades auront un C'est une charge, vos parades auront un -4 et vous ne pouvez pas esquiver!
-4 et vous ne pouvez pas esquiver!
{{ else if (eq tactique 'feinte')}} {{ else if (eq tactique 'feinte')}}
<img class="chat-icon" src="systems/foundryvtt-reve-de-dragon/icons/heures/hd06.svg" alt="feinte" height="32" width="32" />
Votre feinte peut faire mouche! Votre feinte peut faire mouche!
{{/if}} {{/if}}
</div> </div>
{{/if}} {{/if}}
<div> <div>
<span><strong>{{show.cible}}</strong> doit se défendre, ou encaisser à <span><strong>{{show.cible}}</strong> doit se défendre à <strong>{{diffLibre}}</strong>, ou encaisser à
{{~#if (eq dmg.mortalite 'non-mortel')}} {{~#if (eq dmg.mortalite 'non-mortel')}}
<span class="rdd-roll-norm">({{numberFormat dmg.total decimals=0 sign=true}})</span> (dommages non-mortel) <span class="rdd-roll-norm">({{numberFormat dmg.total decimals=0 sign=true}})</span> (dommages non-mortel)
{{else if (eq dmg.mortalite 'mortel')}} {{else if (eq dmg.mortalite 'mortel')}}
<span class="rdd-need-echec">{{numberFormat dmg.total decimals=0 sign=true}}</span>. <span class="rdd-roll-echec">{{numberFormat dmg.total decimals=0 sign=true}}</span>.
{{else}} {{else}}
<span class="rdd-roll-etotal">{{numberFormat dmg.total decimals=0 sign=true}}</span> (entités de cauchemar) <span class="rdd-roll-etotal">{{numberFormat dmg.total decimals=0 sign=true}}</span> (entités de cauchemar)
{{~/if}}. {{~/if}}.
{{#if show.isRecul}}Si votre adversaire ne fait pas une esquive, il devra reculer sous le choc!{{/if}} {{#if show.isRecul}}Si votre adversaire n'esquive pas, il devra résister à l'impact ou reculer sous le choc!{{/if}}
Le coup vise: {{dmg.loc.label}}. Le coup vise: {{dmg.loc.label}}.
</span> </span>
</div> </div>