Gestion initiative améliorée

This commit is contained in:
sladecraven 2020-11-24 16:41:15 +01:00
parent 136c7594d4
commit 78f07655e3
6 changed files with 121 additions and 43 deletions

View File

@ -26,15 +26,7 @@ export class RdDActorSheet extends ActorSheet {
getData() { getData() {
let data = super.getData(); let data = super.getData();
data.itemsByType = {}; data.itemsByType = RdDUtility.buildItemsClassification(data.items);
for (const item of data.items) {
let list = data.itemsByType[item.type];
if (!list) {
list = [];
data.itemsByType[item.type] = list;
}
list.push(item);
}
// Competence per category // Competence per category
data.competenceByCategory = {}; data.competenceByCategory = {};
let competenceXPTotal = 0; let competenceXPTotal = 0;
@ -80,22 +72,7 @@ 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']));
// Gestion des armes 1/2 mains data.data.combat = RdDUtility.finalizeArmeList( data.data.combat )
let arme2mains = []; // Tableau contenant la duplication des armes 1m/2m
for (const arme of data.data.combat) {
// Dupliquer les armes pouvant être à 1 main et 2 mains en patchant la compétence
if (arme.data.unemain && arme.data.deuxmains) {
let arme2main = duplicate(arme);
arme2main.data.competence = arme2main.data.competence.replace(" 1 main", " 2 mains"); // Replace !
for ( const melee of data.competenceByCategory.melee ) {
if (melee.name == arme2main.data.competence )
arme2main.data.niveau = melee.data.niveau
}
arme2mains.push(arme2main);
}
}
data.data.combat = data.data.combat.concat(arme2mains); // Merge all cases
data.data.combat = data.data.combat.sort((a, b) => { if ( a.name > b.name) return 1; else return -1; } );
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

View File

@ -217,3 +217,8 @@ Hooks.on("chatMessage", (html, content, msg) => {
return RdDUtility.processChatCommand( commands, content, msg ); return RdDUtility.processChatCommand( commands, content, msg );
} ); } );
/* -------------------------------------------- */
Hooks.on("getCombatTrackerEntryContext", (html, options) => {
RdDUtility.pushInitiativeOptions( html, options );
})

View File

@ -336,6 +336,29 @@ export class RdDUtility {
return xp; return xp;
} }
/* -------------------------------------------- */
/** Retourne une liste triée d'armes avec le split arme1 main / arme 2 main */
static finalizeArmeList( armeList ) {
// Gestion des armes 1/2 mains
let arme2mains = []; // Tableau contenant la duplication des armes 1m/2m
for (const arme of armeList) {
// Dupliquer les armes pouvant être à 1 main et 2 mains en patchant la compétence
if (arme.data.unemain && arme.data.deuxmains) {
let arme2main = duplicate(arme);
arme2main.data.dommages = arme2main.data.dommages.split("/")[1]; // Existence temporaire uniquement dans la liste des armes, donc OK
arme2main.data.competence = arme2main.data.competence.replace(" 1 main", " 2 mains"); // Replace !
for ( const melee of data.competenceByCategory.melee ) {
if (melee.name == arme2main.data.competence )
arme2main.data.niveau = melee.data.niveau
}
arme2mains.push(arme2main);
}
}
armeList = armeList.concat(arme2mains); // Merge all cases
armeList = armeList.sort((a, b) => { if ( a.name > b.name) return 1; else return -1; } );
return armeList
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static computeCarac( data) static computeCarac( data)
{ {
@ -387,12 +410,14 @@ export class RdDUtility {
data.compteurs.chance.max = data.carac.chance.value; data.compteurs.chance.max = data.carac.chance.value;
} }
/* -------------------------------------------- */
static getSegmentsFatigue(maxEnd) { static getSegmentsFatigue(maxEnd) {
maxEnd = Math.max(maxEnd, 1); maxEnd = Math.max(maxEnd, 1);
maxEnd = Math.min(maxEnd, fatigueMatrix.length); maxEnd = Math.min(maxEnd, fatigueMatrix.length);
return fatigueMatrix[maxEnd]; return fatigueMatrix[maxEnd];
} }
/* -------------------------------------------- */
static calculMalusFatigue(fatigue, maxEnd) static calculMalusFatigue(fatigue, maxEnd)
{ {
maxEnd = Math.max(maxEnd, 1); maxEnd = Math.max(maxEnd, 1);
@ -622,6 +647,64 @@ 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);
let competence = RdDUtility.findCompetence( combatant.actor.data.items, arme.data.competence);
let rollFormula = "1d6+" + competence.data.niveau + "+" + Math.ceil(combatant.actor.data.data.carac[competence.data.defaut_carac].value/2);
console.log("Roll !", combatantId, arme );
}
/* -------------------------------------------- */
static displayInitiativeMenu( html, combatantId) {
// Recupération du combatant et de l'acteur associé
const combatant = game.combat.getCombatant(combatantId);
const actor = combatant.actor;
console.log("Combattant : ", combatant);
// Recupération des items 'arme'
let itemsByType = RdDUtility.buildItemsClassification( combatant.actor.data.items );
let armesList = itemsByType['arme'];
if ( armesList ) { // Do something...
let menuItems = [];
for ( let arme of armesList ) {
menuItems.push( {
name: arme.data.competence,
icon: "<i class='fas fa-dice-d6'></i>",
callback: target => { RdDUtility.rollInitiativeCompetence( combatantId, arme ) } } );
}
new ContextMenu(html, "", menuItems, undefined, defaultMenuItem ).render();
}
}
/* -------------------------------------------- */
static pushInitiativeOptions( html, options ) {
options.push(
{
name: "Sélectionner l'initiative...",
condition: true,
icon: '<i class="far fa-question-circle"></i>',
callback: target => {
RdDUtility.displayInitiativeMenu( html, target.data('combatant-id') );
//WFRP_Utility.displayStatus(target.attr("data-token-id"));
//$(`#sidebar-tabs`).find(`.item[data-tab="chat"]`).click();
}
});
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static async chatListeners( html ) static async chatListeners( html )
{ {

File diff suppressed because one or more lines are too long

View File

@ -463,6 +463,22 @@ section.sheet-body:after, section.sheet-body div:after {
/* Global UI elements */ /* Global UI elements */
/* ======================================== */ /* ======================================== */
.inventory-list > .list-combat:nth-child(even) {
background-color: #7b733b29;
background: #7b733b29;
}
.inventory-list > .list-combat:nth-child(odd) {
background-color: #9e856a0d;
background: #9e856a0d;
}
.list-combat {
margin: 2px 2px 2px 2px;
box-shadow: inset 0px 0px 1px #00000096;
border-radius: 5px;
padding: 2px 5px 0px 5px;
}
.sheet-competence-img { .sheet-competence-img {
width: 24px; width: 24px;
height: 24px; height: 24px;

View File

@ -311,19 +311,19 @@
{{!-- Combat Tab --}} {{!-- Combat Tab --}}
<div class="tab combat" data-group="primary" data-tab="combat"> <div class="tab combat" data-group="primary" data-tab="combat">
<header class="competence-header flexrow"> <ol class="item-list inventory-list">
<span class="competence-title">Armes</span> <li class="competence-header flexrow">
<span class="competence-title">compétence</span> <span class="competence-title competence-label">Armes</span>
<span class="competence-title">Niveau</span> <span class="competence-title competence-label">Comp.</span>
<span class="competence-title">+dom</span> <span class="competence-title competence-value">Niveau</span>
</header> <span class="competence-title competence-value">+dom</span>
<ol class="item-list"> </li>
{{#each data.combat as |arme key|}} {{#each data.combat as |arme key|}}
<li class="item flexrow" data-item-id="{{arme._id}}"> <li class="item flexrow list-combat" data-item-id="{{arme._id}}">
<span class="arme-label" name="data.armes[{{key}}].name"><a data-competence-name="{{arme.data.competence}}">{{arme.name}}</a></span> <span class="arme-label competence-label" name="data.armes[{{key}}].name"><a data-competence-name="{{arme.data.competence}}">{{arme.name}}</a></span>
<span class="competence-label" name="data.armes[{{key}}].data.competence">{{arme.data.competence}}</span> <span class="competence-label" name="data.armes[{{key}}].data.competence">{{arme.data.competence}}</span>
<span class="competence-label" name="data.armes[{{key}}].data.niveau">{{numberFormat arme.data.niveau decimals=0 sign=true}}</span> <span class="competence-value" name="data.armes[{{key}}].data.niveau">{{numberFormat arme.data.niveau decimals=0 sign=true}}</span>
<span class="competence-label" name="data.armes[{{key}}].data.dommages">{{numberFormat arme.data.dommages decimals=0 sign=true}}</span> <span class="competence-value" name="data.armes[{{key}}].data.dommages">{{numberFormat arme.data.dommages decimals=0 sign=true}}</span>
</li> </li>
{{/each}} {{/each}}
</ol> </ol>