#97 particulière pour armes lentes

Pas de particulières en rapidité pour les armes lentes.

Le corps à corps est considéré comme rapide.

Standardise le corps à corps:  centraliser la construction d'un objet
pour le corps à corps

Convertion de compétences de créature en arme

Petit fix sur HUD: le click est sur le div uniquement (au lieu
du label avant, ou d'un mix avec un fix précédent...)
This commit is contained in:
Vincent Vandemeulebrouck 2021-01-04 00:17:22 +01:00
parent 3d98d57fb5
commit 3ac2be74fd
11 changed files with 124 additions and 91 deletions

View File

@ -5,6 +5,8 @@
import { RdDUtility } from "./rdd-utility.js"; import { RdDUtility } from "./rdd-utility.js";
import { HtmlUtility } from "./html-utility.js"; import { HtmlUtility } from "./html-utility.js";
import { RdDItem } from "./item.js";
import { RdDItemArme } from "./item-arme.js";
/* -------------------------------------------- */ /* -------------------------------------------- */
export class RdDActorSheet extends ActorSheet { export class RdDActorSheet extends ActorSheet {
@ -34,7 +36,7 @@ export class RdDActorSheet extends ActorSheet {
data.data.montrerArchetype = this.options.montrerArchetype; data.data.montrerArchetype = this.options.montrerArchetype;
let compCategorieNiveau = RdDUtility.getLevelCategory(); // recup catégorie let compCategorieNiveau = RdDUtility.getLevelCategory(); // recup catégorie
data.itemsByType = RdDUtility.buildItemsClassification(data.items); data.itemsByType = RdDItem.buildItemsClassification(data.items);
// Competence per category // Competence per category
data.competenceByCategory = {}; data.competenceByCategory = {};
@ -92,16 +94,16 @@ export class RdDActorSheet extends ActorSheet {
// To avoid armour and so on... // To avoid armour and so on...
data.data.combat = duplicate( RdDUtility.checkNull(data.itemsByType['arme'])); data.data.combat = duplicate( RdDUtility.checkNull(data.itemsByType['arme']));
data.data.combat = RdDUtility.finalizeArmeList( data.data.combat, data.itemsByType.competence, data.data.carac ); data.data.combat = RdDUtility._finalizeArmeList( data.data.combat, data.itemsByType.competence, data.data.carac );
if (data.competenceByCategory && data.competenceByCategory.melee) { if (data.competenceByCategory && data.competenceByCategory.melee) {
//Specific case for Esquive and Corps à Corps //Specific case for Esquive and Corps à Corps
for ( const melee of data.competenceByCategory.melee ) { for ( const melee of data.competenceByCategory.melee ) {
if (melee.name == "Esquive") if (melee.name == "Esquive")
data.data.combat.push( { name: "Esquive", data: { niveau: melee.data.niveau, description: "", force: 6, initiative: "-", competence: "Esquive", dommages: 0} } ); data.data.combat.push( { name: "Esquive", data: { niveau: melee.data.niveau, description: "", force: 6, initiative: "", competence: "Esquive", dommages: 0} } );
if (melee.name == "Corps à corps") { if (melee.name == "Corps à corps") {
let cc_init = RdDUtility.calculInitiative(melee.data.niveau, data.data.carac['melee'].value); let cc_init = RdDUtility.calculInitiative(melee.data.niveau, data.data.carac['melee'].value);
data.data.combat.push( { name: "Corps à corps", data: { niveau: melee.data.niveau, description: "", force: 6, initiative: cc_init, competence: "Corps à corps", dommages: data.data.attributs.plusdom.value } } ); data.data.combat.push( RdDItemArme.mainsNues({ niveau: melee.data.niveau, initiative: cc_init }) );
} }
} }
} }

View File

@ -16,6 +16,7 @@ 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"; import { RdDItemCompetence } from "./item-competence.js";
import { RdDItemArme } from "./item-arme.js";
/* -------------------------------------------- */ /* -------------------------------------------- */
/** /**
@ -1985,14 +1986,12 @@ export class RdDActor extends Actor {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
rollArme(compName, armeName = undefined) { rollArme(compName, armeName = undefined) {
let arme = this.data.items.find( item => item.name == armeName && RdDItemArme.isArme(item));
let armeItem = this.data.items.find(item=>item.type==="arme" && (item.name === armeName)); let competence = this.getCompetence(compName);
if (armeItem && compName == undefined) compName = armeItem.data.competence;
let competence = this.getCompetence(compName == undefined? armeName : compName);
if (armeItem || armeName || (competence.type == 'competencecreature' && competence.data.iscombat)) { if (arme || armeName || (competence.type == 'competencecreature' && competence.data.iscombat)) {
RdDCombat.createUsingTarget(this).attaque(competence, armeItem); RdDCombat.createUsingTarget(this).attaque(competence, arme);
} else { } else {
this.rollCompetence( competence.name ); this.rollCompetence( competence.name );
} }

View File

@ -1,4 +1,4 @@
import { RdDItemCompetenceCreature } from "./item-competencecreature.js"
const nomCcategorieParade = { const nomCcategorieParade = {
"sans-armes": "Sans arme / armes naturelles", "sans-armes": "Sans arme / armes naturelles",
@ -13,34 +13,29 @@ const nomCcategorieParade = {
"lances": "Lances", "lances": "Lances",
} }
/* -------------------------------------------- */
export class RdDItemArme extends Item { export class RdDItemArme extends Item {
static isArme(item) {
return (item.type == 'competencecreature' && item.data.iscombat) || item.type == 'arme';
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static getArmeData(item) { static getArmeData(item) {
switch (item ? item.data.type : '') { switch (item ? item.data.type : '') {
case 'arme': return item.data; case 'arme': return item.data;
case 'competencecreature': case 'competencecreature':
return RdDItemArme._getArmeCompetenceCreature(item); return RdDItemCompetenceCreature.toArme(item);
} }
return RdDItemArme.mainsNues(); 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 getNomCategorieParade(it) { static getNomCategorieParade(it) {
const categorie = it.data? RdDItemArme.getCategorieParade(it) : it; const categorie = it.data ? RdDItemArme.getCategorieParade(it) : it;
return nomCcategorieParade[categorie]; return nomCcategorieParade[categorie];
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static getCategorieParade(arme) { static getCategorieParade(arme) {
if (arme.data.categorie_parade) { if (arme.data.categorie_parade) {
@ -134,11 +129,24 @@ export class RdDItemArme extends Item {
return arme; return arme;
} }
static mainsNues() {
static mainsNues(actorData={}) {
const mainsNues = { const mainsNues = {
name: 'Mains nues', name: 'Mains nues',
data: { unemain: true, deuxmains: false, dommages: 0, dommagesReels: 0, mortalite: 'non-mortel', competence: 'Corps à corps', categorie_parade: 'sans-armes' } data: {
equipe: true,
rapide: true,
force: 0,
dommages: 0,
dommagesReels: 0,
mortalite: 'non-mortel',
competence: 'Corps à corps',
categorie_parade: 'sans-armes'
}
}; };
if (actorData) {
mergeObject( mainsNues.data, actorData, {overwrite:false});
}
return mainsNues return mainsNues
} }
} }

View File

@ -0,0 +1,23 @@
/* -------------------------------------------- */
export class RdDItemCompetenceCreature extends Item {
/* -------------------------------------------- */
static toArme(item) {
if (item.type == 'competencecreature' && item.data.iscombat) {
let arme = { name: item.name, data: duplicate(item.data) };
mergeObject(arme.data,
{
competence: item.name,
resistance: 100,
equipe: true,
penetration: 0,
force: 0,
rapide: true
});
return arme;
}
console.error("RdDItem.toArme(", item, ") : impossible de transformer l'Item en arme");
return undefined;
}
}

18
module/item.js Normal file
View File

@ -0,0 +1,18 @@
/* -------------------------------------------- */
export class RdDItem {
/* -------------------------------------------- */
static buildItemsClassification( items ) {
let itemsByType = {};
for (const item of items) {
let list = itemsByType[item.type];
if (!list) {
list = [];
itemsByType[item.type] = list;
}
list.push(item);
}
return itemsByType;
}
}

View File

@ -212,7 +212,7 @@ export class RdDCombat {
} }
else { else {
// sans armes: à mains nues // sans armes: à mains nues
rollData.arme = RdDItemArme.mainsNues(); rollData.arme = RdDItemArme.mainsNues({niveau: competence.data.niveau});
} }
return rollData; return rollData;
} }
@ -221,15 +221,13 @@ export class RdDCombat {
_onAttaqueParticuliere(rollData) { _onAttaqueParticuliere(rollData) {
console.log("RdDCombat.onAttaqueParticuliere >>>", rollData); console.log("RdDCombat.onAttaqueParticuliere >>>", rollData);
// Finesse et Rapidité seulement en mêlée et si la difficulté libre est de -1 minimum // Finesse et Rapidité seulement en mêlée et si la difficulté libre est de -1 minimum
let message = ` let message = '<h4 class="rdd-roll-part"><strong>Réussite particulière en attaque</strong></h4>';
<h4 class="rdd-roll-part"><strong>Réussite particulière en attaque</strong></h4> message += `<br><a class='chat-card-button' id='particuliere-attaque' data-mode='force' data-attackerId='${this.attackerId}'>Attaquer en Force</a>`;
<br><a class='chat-card-button' id='particuliere-attaque' data-mode='force' data-attackerId='${this.attackerId}'>Attaquer en Force</a>
`;
if (rollData.selectedCarac.label == "Mêlée" && rollData.diffLibre < 0) { if (rollData.selectedCarac.label == "Mêlée" && rollData.diffLibre < 0) {
message += ` if (rollData.arme.data.rapide) {
<br><a class='chat-card-button' id='particuliere-attaque' data-mode='rapidite' data-attackerId='${this.attackerId}'>Attaquer en Rapidité</a> message += `<br><a class='chat-card-button' id='particuliere-attaque' data-mode='rapidite' data-attackerId='${this.attackerId}'>Attaquer en Rapidité</a>`;
<br><a class='chat-card-button' id='particuliere-attaque' data-mode='finesse' data-attackerId='${this.attackerId}'>Attaquer en Finesse</a> }
` message += `<br><a class='chat-card-button' id='particuliere-attaque' data-mode='finesse' data-attackerId='${this.attackerId}'>Attaquer en Finesse</a>`;
} }
game.system.rdd.rollDataHandler[this.attackerId] = rollData; game.system.rdd.rollDataHandler[this.attackerId] = rollData;
// TODO: use a dialog? // TODO: use a dialog?
@ -299,7 +297,7 @@ export class RdDCombat {
/* -------------------------------------------- */ /* -------------------------------------------- */
_filterArmesParade(items, competence) { _filterArmesParade(items, competence) {
items = items.filter(item => item.data.equipe == true ); items = items.filter(item => (item.type == 'arme' && item.data.equipe) || (item.type == 'competencecreature' && item.data.isparade));
switch (competence.data.categorie) { switch (competence.data.categorie) {
case 'tir': case 'tir':
case 'lancer': case 'lancer':

View File

@ -17,7 +17,7 @@ export class RdDTokenHud {
if (!token.inCombat) return; if (!token.inCombat) return;
if (!combatant) return; if (!combatant) return;
let armesList = RdDTokenHud.buildListeActionsCombat(combatant) ; let armesList = RdDUtility.buildListeActionsCombat(combatant) ;
const hudData = { combatant: combatant, armes: armesList }; const hudData = { combatant: combatant, armes: armesList };
// initiative // initiative
@ -38,16 +38,6 @@ export class RdDTokenHud {
}); });
} }
/* -------------------------------------------- */
static buildListeActionsCombat(combatant) {
let armesList = RdDUtility.buildArmeList(combatant);
for (let armeIndex = 0; armeIndex < armesList.length; armeIndex++) {
armesList[armeIndex] = duplicate(armesList[armeIndex]);
armesList[armeIndex].index = armeIndex;
}
return armesList;
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static async _configureSubMenu(insertionPoint, template, hudData, onMenuItem) { static async _configureSubMenu(insertionPoint, template, hudData, onMenuItem) {
const hud = $(await renderTemplate(template, hudData)); const hud = $(await renderTemplate(template, hudData));

View File

@ -5,6 +5,9 @@ import { ChatUtility } from "./chat-utility.js";
import { RdDItemCompetence } from "./item-competence.js"; import { RdDItemCompetence } from "./item-competence.js";
import { RdDCombat } from "./rdd-combat.js"; import { RdDCombat } from "./rdd-combat.js";
import { RdDRollResolutionTable } from "./rdd-roll-resolution-table.js"; import { RdDRollResolutionTable } from "./rdd-roll-resolution-table.js";
import { RdDItem } from "./item.js";
import { RdDItemCompetenceCreature } from "./item-competencecreature.js";
import { RdDItemArme } from "./item-arme.js";
/* -------------------------------------------- */ /* -------------------------------------------- */
const level_category = { const level_category = {
@ -464,11 +467,10 @@ export class RdDUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
/** Retourne une liste triée d'armes avec le split arme1 main / arme 2 main */ /** Retourne une liste triée d'armes avec le split arme1 main / arme 2 main */
static finalizeArmeList( armeList, competenceList, carac ) { static _finalizeArmeList( armes, competenceList, carac ) {
// Gestion des armes 1/2 mains // Gestion des armes 1/2 mains
let arme2mains = []; // Tableau contenant la duplication des armes 1m/2m
let armesEquipe = []; let armesEquipe = [];
for (const arme of armeList) { for (const arme of armes) {
if (arme.data.equipe) { if (arme.data.equipe) {
armesEquipe.push( arme ); armesEquipe.push( arme );
let comp = competenceList.find(c => c.name == arme.data.competence); let comp = competenceList.find(c => c.name == arme.data.competence);
@ -491,9 +493,13 @@ export class RdDUtility {
} }
} }
} }
//armeList = armeList.concat(arme2mains); // Merge all cases return armesEquipe.sort((a, b) => {
armesEquipe = armesEquipe.sort((a, b) => { if ( a.name > b.name) return 1; else return -1; } ); const nameA = a.name + (a.data.mainInfo ?? '');
return armesEquipe const nameB = b.name + (b.data.mainInfo ?? '');
if ( nameA > nameB) return 1;
if ( nameA < nameB) return -1;
return 0;
} );
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -796,20 +802,6 @@ export class RdDUtility {
} }
} }
/* -------------------------------------------- */
static buildItemsClassification( items ) {
let itemsByType = {};
for (const item of items) {
let list = itemsByType[item.type];
if (!list) {
list = [];
itemsByType[item.type] = list;
}
list.push(item);
}
return itemsByType;
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static rollInitiativeCompetence( combatantId, arme ) { static rollInitiativeCompetence( combatantId, arme ) {
const combatant = game.combat.getCombatant(combatantId); const combatant = game.combat.getCombatant(combatantId);
@ -843,33 +835,36 @@ export class RdDUtility {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static buildArmeList( combatant ) { static buildListeActionsCombat( combatant ) {
const actor = combatant.actor; // Easy access const actor = combatant.actor; // Easy access
let armesList = []; let items = actor.data.items;
if ( actor.data.type == 'creature' || actor.data.type == 'entite') { let actions = []
for (const competenceItem of actor.data.items) { if ( actor.isCreature()) {
if ( competenceItem.data.iscombat) { // Seul un item de type arme actions = actions.concat(items.filter(it => it.type =='competencecreature' && it.data.iscombat)
armesList.push( { name: competenceItem.name, data: { niveau: competenceItem.data.niveau, competence: competenceItem.name } } ); .map(competence => RdDItemCompetenceCreature.toArme(competence)));
}
}
} else { } else {
// Recupération des items 'arme' // Recupération des items 'arme'
let itemsByType = RdDUtility.buildItemsClassification( combatant.actor.data.items ); let armes = items.filter(it => it.type =='arme')
armesList = itemsByType['arme']; .map(arme => duplicate(arme)) /* pas de changements aux armes d'origine */
armesList = this.finalizeArmeList( armesList, itemsByType['competence'], actor.data.data.carac ); .concat(RdDItemArme.mainsNues());
// Force corps à corps et Draconic
let cc = RdDUtility.findCompetence( combatant.actor.data.items, "Corps à corps"); let competences = items.filter(it => it.type == 'competence');
armesList.push( { name: "Corps à corps", data: { niveau: cc.data.niveau, description: "", force: 6, competence: "Corps à corps", dommages: combatant.actor.data.data.attributs.plusdom.value } } ); actions = actions.concat(this._finalizeArmeList( armes, competences, actor.data.data.carac ));
armesList.push( { name: "Draconic", data: { initOnly: true, competence: "Draconic" } } );
actions.push( { name: "Draconic", data: { initOnly: true, competence: "Draconic" } } );
} }
armesList.push( { name: "Autre action", data: { initOnly: true, competence: "Autre action" } } );
return armesList; actions.push( { name: "Autre action", data: { initOnly: true, competence: "Autre action" } } );
for (let index = 0; index < actions.length; index++) {
actions[index].index = index;
}
return actions;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static displayInitiativeMenu( html, combatantId) { static displayInitiativeMenu( html, combatantId) {
const combatant = game.combat.getCombatant(combatantId); const combatant = game.combat.getCombatant(combatantId);
let armesList = this.buildArmeList( combatant ); let armesList = this.buildListeActionsCombat( combatant );
// Build the relevant submenu // Build the relevant submenu
if ( armesList ) { if ( armesList ) {

View File

@ -734,7 +734,7 @@ ul, li {
.control-icon.tokenhudicon.right { .control-icon.tokenhudicon.right {
margin-left: 8px; margin-left: 8px;
} }
.rdd-hud-menu { .rdd-hud-menu label {
font-size: 0.75rem; font-size: 0.75rem;
} }
/* ======================================== */ /* ======================================== */

View File

@ -4,7 +4,7 @@
{{#each armes as |arme key|}} {{#each armes as |arme key|}}
{{#unless arme.data.initOnly}} {{#unless arme.data.initOnly}}
<div class="control-icon tokenhudicon rdd-hud-menu rdd-attaque" data-combatant-id="{{../combatant._id}}" data-arme-id="{{arme.index}}" title="{{arme.name}}"> <div class="control-icon tokenhudicon rdd-hud-menu rdd-attaque" data-combatant-id="{{../combatant._id}}" data-arme-id="{{arme.index}}" title="{{arme.name}}">
<label class="rdd-hud-menu" ></i>C:{{arme.name}} {{arme.data.mainInfo}}</label> <label>C:{{arme.name}} {{arme.data.mainInfo}}</label>
</div> </div>
{{/unless}} {{/unless}}
{{/each}} {{/each}}

View File

@ -2,9 +2,9 @@
<img class="rdd-hud-togglebutton" src="icons/svg/sword.svg" width="36" height="36" title="Initiative" /> <img class="rdd-hud-togglebutton" src="icons/svg/sword.svg" width="36" height="36" title="Initiative" />
<div class="rdd-hud-list tokenhudext right"> <div class="rdd-hud-list tokenhudext right">
{{#each armes as |arme key|}} {{#each armes as |arme key|}}
<div class="control-icon tokenhudicon rdd-hud-menu" data-combatant-id="{{../combatant._id}}" data-arme-id="{{arme.index}}"title="{{arme.name}}"> <div class="control-icon tokenhudicon rdd-hud-menu" data-combatant-id="{{../combatant._id}}" data-arme-id="{{arme.index}}"title="{{arme.name}}">
<label class="rdd-hud-menu">I:{{arme.name}} {{arme.data.mainInfo}}</label> <label>I:{{arme.name}} {{arme.data.mainInfo}}</label>
</div> </div>
{{/each}} {{/each}}
</div> </div>
</div> </div>