Merge branch 'amelioration-diverses' into 'v1.2'

#97 particulière pour armes lentes, #99 ne pas ouvrir la feuille sur encaissement, icône sonné pour daltoniens

See merge request LeRatierBretonnien/foundryvtt-reve-de-dragon!101
This commit is contained in:
Leratier Bretonnien 2021-01-04 07:31:37 +00:00
commit 7dd46da730
14 changed files with 135 additions and 99 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 competence = this.getCompetence(compName);
let armeItem = this.data.items.find(item=>item.type==="arme" && (item.name === armeName)); if (arme || armeName || (competence.type == 'competencecreature' && competence.data.iscombat)) {
if (armeItem && compName == undefined) compName = armeItem.data.competence; RdDCombat.createUsingTarget(this).attaque(competence, arme);
let competence = this.getCompetence(compName == undefined? armeName : compName);
if (armeItem || armeName || (competence.type == 'competencecreature' && competence.data.iscombat)) {
RdDCombat.createUsingTarget(this).attaque(competence, armeItem);
} else { } else {
this.rollCompetence( competence.name ); this.rollCompetence( competence.name );
} }
@ -2113,7 +2112,7 @@ export class RdDActor extends Actor {
} }
this.computeEtatGeneral(); this.computeEtatGeneral();
this.sheet.render(true); this.sheet.render(false);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

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,31 +13,26 @@ 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];
} }
@ -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

@ -245,18 +245,18 @@ table {border: 1px solid #7a7971;}
height: 8%; height: 8%;
border-width: 0; border-width: 0;
} }
.small-button-container { .small-button-container {
height: 16px; height: 16px;
width: 16px;
border: 0; border: 0;
vertical-align: bottom;
} }
.small-button-container img { .img-sonne {
max-height: 100%; vertical-align: baseline;
max-width: 100%; max-height: 16px;
} border: 0;
.small-button-img {
max-height: 24;
border-width: 0;
} }
.foundryvtt-reve-de-dragon .sheet-header .header-fields { .foundryvtt-reve-de-dragon .sheet-header .header-fields {
@ -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

@ -83,6 +83,7 @@
<span class="competence-label flexrow" name="data.sante.sonne.label">Sonné : </span> <span class="competence-label flexrow" name="data.sante.sonne.label">Sonné : </span>
<input class="resource-content" type="checkbox" name="data.sante.sonne.value" <input class="resource-content" type="checkbox" name="data.sante.sonne.value"
value="{{data.sante.sonne.value}}" {{#if data.sante.sonne.value}}checked{{/if}} /> value="{{data.sante.sonne.value}}" {{#if data.sante.sonne.value}}checked{{/if}} />
<img class="img-sonne" {{#if data.sante.sonne.value}}style="opacity: 1;"{{else}}style="opacity: 0;"{{/if}} src="icons/svg/stoned.svg" height="16" width="16"/>
</li> </li>
<li class="competence flexrow list-item" data-attribute="etat"> <li class="competence flexrow list-item" data-attribute="etat">
<span class="competence-label flexrow" name="data.compteurs.etat.label">Etat Général : </span> <span class="competence-label flexrow" name="data.compteurs.etat.label">Etat Général : </span>

View File

@ -83,6 +83,7 @@
<span class="competence-label flexrow" name="data.sante.sonne.label">Sonné : </span> <span class="competence-label flexrow" name="data.sante.sonne.label">Sonné : </span>
<input class="resource-content" type="checkbox" name="data.sante.sonne.value" <input class="resource-content" type="checkbox" name="data.sante.sonne.value"
value="{{data.sante.sonne.value}}" {{#if data.sante.sonne.value}}checked{{/if}} /> value="{{data.sante.sonne.value}}" {{#if data.sante.sonne.value}}checked{{/if}} />
<img class="img-sonne" {{#if data.sante.sonne.value}}style="opacity: 1;"{{else}}style="opacity: 0;"{{/if}} src="icons/svg/stoned.svg" height="16" width="16"/>
</li> </li>
<li class="competence flexrow list-item" data-attribute="etat"> <li class="competence flexrow list-item" data-attribute="etat">
<span class="competence-label flexrow" name="data.compteurs.etat.label">Etat Général : </span> <span class="competence-label flexrow" name="data.compteurs.etat.label">Etat Général : </span>

View File

@ -41,6 +41,7 @@
<label class="ctn-sonne"> <label class="ctn-sonne">
Sonné : Sonné :
<input class="resource-content" type="checkbox" name="data.sante.sonne.value" value="{{data.sante.sonne.value}}" {{#if data.sante.sonne.value}}checked{{/if}} /> <input class="resource-content" type="checkbox" name="data.sante.sonne.value" value="{{data.sante.sonne.value}}" {{#if data.sante.sonne.value}}checked{{/if}} />
<img class="img-sonne" {{#if data.sante.sonne.value}}style="opacity: 1;"{{else}}style="opacity: 0;"{{/if}} src="icons/svg/stoned.svg" height="16" width="16"/>
</label> </label>
</li> </li>
<li> <li>

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>