forked from public/foundryvtt-reve-de-dragon
Initiative dans RdDCombatManager
fonction _patch_initiative remplacée par surcharge de la méthode Combat.rollInitiative
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
|
||||
import { RdDRollTables } from "./rdd-rolltables.js";
|
||||
import { ChatUtility } from "./chat-utility.js";
|
||||
import { RdDCombat } from "./rdd-combat.js";
|
||||
import { RdDCombat, RdDCombatManager } from "./rdd-combat.js";
|
||||
import { RdDRollResolutionTable } from "./rdd-roll-resolution-table.js";
|
||||
import { RdDItemCompetenceCreature } from "./item-competencecreature.js";
|
||||
import { RdDItemArme } from "./item-arme.js";
|
||||
@ -24,18 +24,18 @@ const categorieCompetences = {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
const limitesArchetypes = [
|
||||
{ "niveau": 0, "nombreMax": 100, "nombre":0},
|
||||
{ "niveau": 1, "nombreMax": 10, "nombre":0},
|
||||
{ "niveau": 2, "nombreMax": 9, "nombre":0},
|
||||
{ "niveau": 3, "nombreMax": 8, "nombre":0},
|
||||
{ "niveau": 4, "nombreMax": 7, "nombre":0},
|
||||
{ "niveau": 5, "nombreMax": 6, "nombre":0},
|
||||
{ "niveau": 6, "nombreMax": 5, "nombre":0},
|
||||
{ "niveau": 7, "nombreMax": 4, "nombre":0},
|
||||
{ "niveau": 8, "nombreMax": 3, "nombre":0},
|
||||
{ "niveau": 9, "nombreMax": 2, "nombre":0},
|
||||
{ "niveau": 10, "nombreMax": 1, "nombre":0},
|
||||
{ "niveau": 11, "nombreMax": 1, "nombre":0}
|
||||
{ "niveau": 0, "nombreMax": 100, "nombre": 0 },
|
||||
{ "niveau": 1, "nombreMax": 10, "nombre": 0 },
|
||||
{ "niveau": 2, "nombreMax": 9, "nombre": 0 },
|
||||
{ "niveau": 3, "nombreMax": 8, "nombre": 0 },
|
||||
{ "niveau": 4, "nombreMax": 7, "nombre": 0 },
|
||||
{ "niveau": 5, "nombreMax": 6, "nombre": 0 },
|
||||
{ "niveau": 6, "nombreMax": 5, "nombre": 0 },
|
||||
{ "niveau": 7, "nombreMax": 4, "nombre": 0 },
|
||||
{ "niveau": 8, "nombreMax": 3, "nombre": 0 },
|
||||
{ "niveau": 9, "nombreMax": 2, "nombre": 0 },
|
||||
{ "niveau": 10, "nombreMax": 1, "nombre": 0 },
|
||||
{ "niveau": 11, "nombreMax": 1, "nombre": 0 }
|
||||
];
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -281,7 +281,7 @@ export class RdDUtility {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getLimitesArchetypes( ) {
|
||||
static getLimitesArchetypes() {
|
||||
return duplicate(limitesArchetypes);
|
||||
}
|
||||
|
||||
@ -460,50 +460,6 @@ export class RdDUtility {
|
||||
return tableCaracDerivee[targetValue]?.xp ?? 200;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** Retourne une liste triée d'armes avec le split arme1 main / arme 2 main */
|
||||
static _finalizeArmeList(armes, competences, carac) {
|
||||
// Gestion des armes 1/2 mains
|
||||
let armesEquipe = [];
|
||||
for (const arme of armes) {
|
||||
if (arme.data.equipe) {
|
||||
armesEquipe.push(arme);
|
||||
let comp = competences.find(c => c.name == arme.data.competence);
|
||||
arme.data.initiative = RdDUtility.calculInitiative(arme.data.niveau, carac[comp.data.defaut_carac].value);
|
||||
// Dupliquer les armes pouvant être à 1 main et 2 mains en patchant la compétence
|
||||
if (arme.data.unemain && !arme.data.deuxmains) {
|
||||
arme.data.mainInfo = "(1m)";
|
||||
} else if (!arme.data.unemain && arme.data.deuxmains) {
|
||||
arme.data.mainInfo = "(2m)";
|
||||
} else if (arme.data.unemain && arme.data.deuxmains) {
|
||||
arme.data.mainInfo = "(1m)";
|
||||
let arme2main = duplicate(arme);
|
||||
arme2main.data.mainInfo = "(2m)";
|
||||
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 !
|
||||
let comp = competences.find(c => c.name == arme2main.data.competence);
|
||||
arme2main.data.niveau = comp.data.niveau;
|
||||
arme2main.data.initiative = RdDUtility.calculInitiative(arme2main.data.niveau, carac[comp.data.defaut_carac].value);
|
||||
armesEquipe.push(arme2main);
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static calculInitiative(niveau, caracValue, bonusEcaille = 0) {
|
||||
let base = niveau + Math.floor(caracValue / 2);
|
||||
base += bonusEcaille;
|
||||
return "1d6" + (base >= 0 ? "+" : "") + base;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static computeCarac(data) {
|
||||
data.carac.force.value = Math.min(data.carac.force.value, parseInt(data.carac.taille.value) + 4);
|
||||
@ -711,173 +667,8 @@ export class RdDUtility {
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static processPremierRoundInit() {
|
||||
// Check if we have the whole init !
|
||||
if (game.user.isGM) {
|
||||
let initDone = true;
|
||||
for (let combatant of game.combat.data.combatants) {
|
||||
if (!combatant.initiative) initDone = false;
|
||||
}
|
||||
if (initDone && game.combat.current.round == 1) { // Premier round !
|
||||
for (let combatant of game.combat.data.combatants) {
|
||||
let arme = combatant.initiativeData.arme;
|
||||
//console.log("Parsed !!!", combatant, initDone, game.combat.current, arme);
|
||||
if (arme && arme.type == "arme") {
|
||||
for (let initData of premierRoundInit) {
|
||||
if (arme.data.initpremierround.toLowerCase().includes(initData.pattern)) {
|
||||
let msg = `<h4>L'initiative de ${combatant.actor.name} a été modifiée !</h4>
|
||||
<hr>
|
||||
<div>
|
||||
Etant donné son ${arme.name}, son initative pour ce premier round est désormais de ${initData.init}.
|
||||
</div>`
|
||||
ChatMessage.create({ content: msg });
|
||||
game.combat.setInitiative(combatant._id, initData.init);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static rollInitiativeCompetence(combatantId, arme) {
|
||||
const combatant = game.combat.getCombatant(combatantId);
|
||||
const actor = combatant.actor;
|
||||
|
||||
let initInfo = "";
|
||||
let initOffset = 0;
|
||||
let caracForInit = 0;
|
||||
let compNiveau = 0;
|
||||
let competence = { name: "Aucune"};
|
||||
if (actor.getSurprise() == "totale") {
|
||||
initOffset = -1; // To force 0
|
||||
initInfo = "Surprise Totale"
|
||||
} else if (actor.getSurprise() == "demi") {
|
||||
initOffset = 0;
|
||||
initInfo = "Demi Surprise"
|
||||
} else if (arme.name == "Autre action") {
|
||||
initOffset = 2;
|
||||
initInfo = "Autre Action"
|
||||
} else if (arme.name == "Draconic") {
|
||||
initOffset = 7;
|
||||
initInfo = "Draconic"
|
||||
} else {
|
||||
initOffset = 3; // Melée = 3.XX
|
||||
competence = RdDItemCompetence.findCompetence(combatant.actor.data.items, arme.data.competence);
|
||||
compNiveau = competence.data.niveau;
|
||||
initInfo = arme.name + " / " + arme.data.competence;
|
||||
|
||||
if (actor.data.type == 'creature' || actor.data.type == 'entite') {
|
||||
caracForInit = competence.data.carac_value;
|
||||
if (competence.data.categorie == "lancer") {
|
||||
initOffset = 5;
|
||||
}
|
||||
} else {
|
||||
caracForInit = actor.data.data.carac[competence.data.defaut_carac].value;
|
||||
if (competence.data.categorie == "lancer") { // Offset de principe pour les armes de jet
|
||||
initOffset = 4;
|
||||
}
|
||||
if (competence.data.categorie == "tir") { // Offset de principe pour les armes de jet
|
||||
initOffset = 5;
|
||||
}
|
||||
if (competence.data.categorie == "melee") { // Offset de principe pour les armes de jet
|
||||
initOffset = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
let malus = actor.getEtatGeneral(); // Prise en compte état général
|
||||
// Cas des créatures et entités vs personnages
|
||||
let rollFormula = initOffset + "+ ( (" + RdDUtility.calculInitiative(compNiveau, caracForInit) + " + " + malus + ") /100)";
|
||||
// Garder la trace de l'arme/compétence utilisée pour l'iniative
|
||||
combatant.initiativeData = { arme: arme } // pour reclasser l'init au round 0
|
||||
game.combat.rollInitiative(combatantId, rollFormula, { initInfo: initInfo});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static buildListeActionsCombat(combatant) {
|
||||
const actor = combatant.actor; // Easy access
|
||||
let items = actor.data.items;
|
||||
let actions = []
|
||||
if (actor.isCreature()) {
|
||||
actions = actions.concat(items.filter(it => RdDItemCompetenceCreature.isCompetenceAttaque(it))
|
||||
.map(competence => RdDItemCompetenceCreature.toArme(competence)));
|
||||
} else {
|
||||
// Recupération des items 'arme'
|
||||
let armes = items.filter(it => RdDItemArme.isArmeUtilisable(it))
|
||||
.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" } });
|
||||
}
|
||||
|
||||
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.buildListeActionsCombat(combatant);
|
||||
|
||||
// Build the relevant submenu
|
||||
if (armesList) {
|
||||
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, ".directory-list", menuItems).render();
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static incDecInit(combatantId, incDecValue) {
|
||||
const combatant = game.combat.getCombatant(combatantId);
|
||||
let initValue = combatant.initiative + incDecValue;
|
||||
game.combat.setInitiative(combatantId, initValue);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static pushInitiativeOptions(html, options) {
|
||||
for (let i = 0; i < options.length; i++) {
|
||||
let option = options[i];
|
||||
if (option.name == 'COMBAT.CombatantReroll') { // Replace !
|
||||
option.name = "Sélectionner l'initiative...";
|
||||
option.condition = true;
|
||||
option.icon = '<i class="far fa-question-circle"></i>';
|
||||
option.callback = target => {
|
||||
RdDUtility.displayInitiativeMenu(html, target.data('combatant-id'));
|
||||
}
|
||||
}
|
||||
}
|
||||
options.push({
|
||||
name: "Incrémenter initiative",
|
||||
condition: true,
|
||||
icon: '<i class="fas fa-plus"></i>',
|
||||
callback: target => {
|
||||
RdDUtility.incDecInit(target.data('combatant-id'), +0.01);
|
||||
}
|
||||
});
|
||||
options.push({
|
||||
name: "Décrémenter initiative",
|
||||
condition: true,
|
||||
icon: '<i class="fas fa-minus"></i>',
|
||||
callback: target => {
|
||||
RdDUtility.incDecInit(target.data('combatant-id'), -0.01);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async chatListeners(html) {
|
||||
|
Reference in New Issue
Block a user