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 { HtmlUtility } from "./html-utility.js";
import { RdDItem } from "./item.js";
import { RdDItemArme } from "./item-arme.js";
/* -------------------------------------------- */
export class RdDActorSheet extends ActorSheet {
@ -34,7 +36,7 @@ export class RdDActorSheet extends ActorSheet {
data.data.montrerArchetype = this.options.montrerArchetype;
let compCategorieNiveau = RdDUtility.getLevelCategory(); // recup catégorie
data.itemsByType = RdDUtility.buildItemsClassification(data.items);
data.itemsByType = RdDItem.buildItemsClassification(data.items);
// Competence per category
data.competenceByCategory = {};
@ -92,16 +94,16 @@ export class RdDActorSheet extends ActorSheet {
// To avoid armour and so on...
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) {
//Specific case for Esquive and Corps à Corps
for ( const melee of data.competenceByCategory.melee ) {
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") {
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 { RdDAudio } from "./rdd-audio.js";
import { RdDItemCompetence } from "./item-competence.js";
import { RdDItemArme } from "./item-arme.js";
/* -------------------------------------------- */
/**
@ -1986,13 +1987,11 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
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 (armeItem && compName == undefined) compName = armeItem.data.competence;
let competence = this.getCompetence(compName == undefined? armeName : compName);
if (armeItem || armeName || (competence.type == 'competencecreature' && competence.data.iscombat)) {
RdDCombat.createUsingTarget(this).attaque(competence, armeItem);
if (arme || armeName || (competence.type == 'competencecreature' && competence.data.iscombat)) {
RdDCombat.createUsingTarget(this).attaque(competence, arme);
} else {
this.rollCompetence( competence.name );
}
@ -2113,7 +2112,7 @@ export class RdDActor extends Actor {
}
this.computeEtatGeneral();
this.sheet.render(true);
this.sheet.render(false);
}
/* -------------------------------------------- */

View File

@ -1,4 +1,4 @@
import { RdDItemCompetenceCreature } from "./item-competencecreature.js"
const nomCcategorieParade = {
"sans-armes": "Sans arme / armes naturelles",
@ -13,31 +13,26 @@ const nomCcategorieParade = {
"lances": "Lances",
}
/* -------------------------------------------- */
export class RdDItemArme extends Item {
static isArme(item) {
return (item.type == 'competencecreature' && item.data.iscombat) || item.type == 'arme';
}
/* -------------------------------------------- */
static getArmeData(item) {
switch (item ? item.data.type : '') {
case 'arme': return item.data;
case 'competencecreature':
return RdDItemArme._getArmeCompetenceCreature(item);
return RdDItemCompetenceCreature.toArme(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 getNomCategorieParade(it) {
const categorie = it.data? RdDItemArme.getCategorieParade(it) : it;
const categorie = it.data ? RdDItemArme.getCategorieParade(it) : it;
return nomCcategorieParade[categorie];
}
@ -134,11 +129,24 @@ export class RdDItemArme extends Item {
return arme;
}
static mainsNues() {
static mainsNues(actorData={}) {
const mainsNues = {
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
}
}

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 {
// sans armes: à mains nues
rollData.arme = RdDItemArme.mainsNues();
rollData.arme = RdDItemArme.mainsNues({niveau: competence.data.niveau});
}
return rollData;
}
@ -221,15 +221,13 @@ export class 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
let message = `
<h4 class="rdd-roll-part"><strong>Réussite particulière en attaque</strong></h4>
<br><a class='chat-card-button' id='particuliere-attaque' data-mode='force' data-attackerId='${this.attackerId}'>Attaquer en Force</a>
`;
let message = '<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>`;
if (rollData.selectedCarac.label == "Mêlée" && rollData.diffLibre < 0) {
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>
`
if (rollData.arme.data.rapide) {
message += `<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='finesse' data-attackerId='${this.attackerId}'>Attaquer en Finesse</a>`;
}
game.system.rdd.rollDataHandler[this.attackerId] = rollData;
// TODO: use a dialog?
@ -299,7 +297,7 @@ export class RdDCombat {
/* -------------------------------------------- */
_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) {
case 'tir':
case 'lancer':

View File

@ -17,7 +17,7 @@ export class RdDTokenHud {
if (!token.inCombat) return;
if (!combatant) return;
let armesList = RdDTokenHud.buildListeActionsCombat(combatant) ;
let armesList = RdDUtility.buildListeActionsCombat(combatant) ;
const hudData = { combatant: combatant, armes: armesList };
// 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) {
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 { RdDCombat } from "./rdd-combat.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 = {
@ -464,11 +467,10 @@ export class RdDUtility {
/* -------------------------------------------- */
/** 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
let arme2mains = []; // Tableau contenant la duplication des armes 1m/2m
let armesEquipe = [];
for (const arme of armeList) {
for (const arme of armes) {
if (arme.data.equipe) {
armesEquipe.push( arme );
let comp = competenceList.find(c => c.name == arme.data.competence);
@ -491,9 +493,13 @@ export class RdDUtility {
}
}
}
//armeList = armeList.concat(arme2mains); // Merge all cases
armesEquipe = armesEquipe.sort((a, b) => { if ( a.name > b.name) return 1; else return -1; } );
return armesEquipe
return armesEquipe.sort((a, b) => {
const nameA = a.name + (a.data.mainInfo ?? '');
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 ) {
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
let armesList = [];
if ( actor.data.type == 'creature' || actor.data.type == 'entite') {
for (const competenceItem of actor.data.items) {
if ( competenceItem.data.iscombat) { // Seul un item de type arme
armesList.push( { name: competenceItem.name, data: { niveau: competenceItem.data.niveau, competence: competenceItem.name } } );
}
}
let items = actor.data.items;
let actions = []
if ( actor.isCreature()) {
actions = actions.concat(items.filter(it => it.type =='competencecreature' && it.data.iscombat)
.map(competence => RdDItemCompetenceCreature.toArme(competence)));
} else {
// Recupération des items 'arme'
let itemsByType = RdDUtility.buildItemsClassification( combatant.actor.data.items );
armesList = itemsByType['arme'];
armesList = this.finalizeArmeList( armesList, itemsByType['competence'], actor.data.data.carac );
// Force corps à corps et Draconic
let cc = RdDUtility.findCompetence( combatant.actor.data.items, "Corps à corps");
armesList.push( { name: "Corps à corps", data: { niveau: cc.data.niveau, description: "", force: 6, competence: "Corps à corps", dommages: combatant.actor.data.data.attributs.plusdom.value } } );
armesList.push( { name: "Draconic", data: { initOnly: true, competence: "Draconic" } } );
let armes = items.filter(it => it.type =='arme')
.map(arme => duplicate(arme)) /* pas de changements aux armes d'origine */
.concat(RdDItemArme.mainsNues());
let competences = items.filter(it => it.type == 'competence');
actions = actions.concat(this._finalizeArmeList( armes, competences, actor.data.data.carac ));
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) {
const combatant = game.combat.getCombatant(combatantId);
let armesList = this.buildArmeList( combatant );
let armesList = this.buildListeActionsCombat( combatant );
// Build the relevant submenu
if ( armesList ) {

View File

@ -245,18 +245,18 @@ table {border: 1px solid #7a7971;}
height: 8%;
border-width: 0;
}
.small-button-container {
height: 16px;
width: 16px;
border: 0;
vertical-align: bottom;
}
.small-button-container img {
max-height: 100%;
max-width: 100%;
}
.small-button-img {
max-height: 24;
border-width: 0;
.img-sonne {
vertical-align: baseline;
max-height: 16px;
border: 0;
}
.foundryvtt-reve-de-dragon .sheet-header .header-fields {
@ -734,7 +734,7 @@ ul, li {
.control-icon.tokenhudicon.right {
margin-left: 8px;
}
.rdd-hud-menu {
.rdd-hud-menu label {
font-size: 0.75rem;
}
/* ======================================== */

View File

@ -83,6 +83,7 @@
<span class="competence-label flexrow" name="data.sante.sonne.label">Sonné : </span>
<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"/>
</li>
<li class="competence flexrow list-item" data-attribute="etat">
<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>
<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"/>
</li>
<li class="competence flexrow list-item" data-attribute="etat">
<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">
Sonné :
<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>
</li>
<li>

View File

@ -4,7 +4,7 @@
{{#each armes as |arme key|}}
{{#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}}">
<label class="rdd-hud-menu" ></i>C:{{arme.name}} {{arme.data.mainInfo}}</label>
<label>C:{{arme.name}} {{arme.data.mainInfo}}</label>
</div>
{{/unless}}
{{/each}}

View File

@ -3,7 +3,7 @@
<div class="rdd-hud-list tokenhudext right">
{{#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}}">
<label class="rdd-hud-menu">I:{{arme.name}} {{arme.data.mainInfo}}</label>
<label>I:{{arme.name}} {{arme.data.mainInfo}}</label>
</div>
{{/each}}
</div>