Gestion initiative améliorée
This commit is contained in:
parent
136c7594d4
commit
78f07655e3
@ -26,15 +26,7 @@ export class RdDActorSheet extends ActorSheet {
|
||||
getData() {
|
||||
let data = super.getData();
|
||||
|
||||
data.itemsByType = {};
|
||||
for (const item of data.items) {
|
||||
let list = data.itemsByType[item.type];
|
||||
if (!list) {
|
||||
list = [];
|
||||
data.itemsByType[item.type] = list;
|
||||
}
|
||||
list.push(item);
|
||||
}
|
||||
data.itemsByType = RdDUtility.buildItemsClassification(data.items);
|
||||
// Competence per category
|
||||
data.competenceByCategory = {};
|
||||
let competenceXPTotal = 0;
|
||||
@ -80,22 +72,7 @@ export class RdDActorSheet extends ActorSheet {
|
||||
|
||||
// To avoid armour and so on...
|
||||
data.data.combat = duplicate( RdDUtility.checkNull(data.itemsByType['arme']));
|
||||
// Gestion des armes 1/2 mains
|
||||
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; } );
|
||||
data.data.combat = RdDUtility.finalizeArmeList( data.data.combat )
|
||||
|
||||
if (data.competenceByCategory && data.competenceByCategory.melee) {
|
||||
//Specific case for Esquive and Corps à Corps
|
||||
|
@ -217,3 +217,8 @@ Hooks.on("chatMessage", (html, content, msg) => {
|
||||
|
||||
return RdDUtility.processChatCommand( commands, content, msg );
|
||||
} );
|
||||
|
||||
/* -------------------------------------------- */
|
||||
Hooks.on("getCombatTrackerEntryContext", (html, options) => {
|
||||
RdDUtility.pushInitiativeOptions( html, options );
|
||||
})
|
||||
|
@ -336,6 +336,29 @@ export class RdDUtility {
|
||||
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)
|
||||
{
|
||||
@ -387,12 +410,14 @@ export class RdDUtility {
|
||||
data.compteurs.chance.max = data.carac.chance.value;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getSegmentsFatigue(maxEnd) {
|
||||
maxEnd = Math.max(maxEnd, 1);
|
||||
maxEnd = Math.min(maxEnd, fatigueMatrix.length);
|
||||
return fatigueMatrix[maxEnd];
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static calculMalusFatigue(fatigue, maxEnd)
|
||||
{
|
||||
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 )
|
||||
{
|
||||
|
File diff suppressed because one or more lines are too long
@ -463,6 +463,22 @@ section.sheet-body:after, section.sheet-body div:after {
|
||||
/* 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 {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
|
@ -311,19 +311,19 @@
|
||||
|
||||
{{!-- Combat Tab --}}
|
||||
<div class="tab combat" data-group="primary" data-tab="combat">
|
||||
<header class="competence-header flexrow">
|
||||
<span class="competence-title">Armes</span>
|
||||
<span class="competence-title">compétence</span>
|
||||
<span class="competence-title">Niveau</span>
|
||||
<span class="competence-title">+dom</span>
|
||||
</header>
|
||||
<ol class="item-list">
|
||||
<ol class="item-list inventory-list">
|
||||
<li class="competence-header flexrow">
|
||||
<span class="competence-title competence-label">Armes</span>
|
||||
<span class="competence-title competence-label">Comp.</span>
|
||||
<span class="competence-title competence-value">Niveau</span>
|
||||
<span class="competence-title competence-value">+dom</span>
|
||||
</li>
|
||||
{{#each data.combat as |arme key|}}
|
||||
<li class="item flexrow" 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>
|
||||
<li class="item flexrow list-combat" data-item-id="{{arme._id}}">
|
||||
<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.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.niveau">{{numberFormat arme.data.niveau 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>
|
||||
{{/each}}
|
||||
</ol>
|
||||
|
Loading…
Reference in New Issue
Block a user