Compute initiative
This commit is contained in:
		@@ -75,6 +75,14 @@ export class RdDActorSheet extends ActorSheet {
 | 
				
			|||||||
        if (melee.name == arme.data.competence ) 
 | 
					        if (melee.name == arme.data.competence ) 
 | 
				
			||||||
          arme.data.niveau = melee.data.niveau
 | 
					          arme.data.niveau = melee.data.niveau
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					      for ( const tir of data.competenceByCategory.tir ) {
 | 
				
			||||||
 | 
					        if (tir.name == arme.data.competence ) 
 | 
				
			||||||
 | 
					          arme.data.niveau = tir.data.niveau
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      for ( const lancer of data.competenceByCategory.lancer ) {
 | 
				
			||||||
 | 
					        if (lancer.name == arme.data.competence ) 
 | 
				
			||||||
 | 
					          arme.data.niveau = lancer.data.niveau
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    // To avoid armour and so on...
 | 
					    // To avoid armour and so on...
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,6 +18,68 @@ import { TMRUtility } from "./tmr-utility.js";
 | 
				
			|||||||
/*  Foundry VTT Initialization                  */
 | 
					/*  Foundry VTT Initialization                  */
 | 
				
			||||||
/* -------------------------------------------- */
 | 
					/* -------------------------------------------- */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/************************************************************************************/
 | 
				
			||||||
 | 
					const _patch_initiative = () => {
 | 
				
			||||||
 | 
					  Combat.prototype.rollInitiative = async function (
 | 
				
			||||||
 | 
					    ids,
 | 
				
			||||||
 | 
					    formula = null,
 | 
				
			||||||
 | 
					    messageOptions = {}
 | 
				
			||||||
 | 
					  ) {
 | 
				
			||||||
 | 
					    console.log(
 | 
				
			||||||
 | 
					      `${game.data.system.data.title} | Combat.rollInitiative()`,
 | 
				
			||||||
 | 
					      ids,
 | 
				
			||||||
 | 
					      formula,
 | 
				
			||||||
 | 
					      messageOptions
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    // Structure input data
 | 
				
			||||||
 | 
					    ids = typeof ids === "string" ? [ids] : ids;
 | 
				
			||||||
 | 
					    const currentId = this.combatant._id;
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					    // calculate initiative
 | 
				
			||||||
 | 
					    for ( let cId = 0; cId < ids.length; cId++) {
 | 
				
			||||||
 | 
					      const c = this.getCombatant( ids[cId] );
 | 
				
			||||||
 | 
					      //if (!c) return results;
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      let armeCombat;
 | 
				
			||||||
 | 
					      for (const item of c.actor.data.items) {
 | 
				
			||||||
 | 
					        if (item.type == "arme" && item.data.equipe) {
 | 
				
			||||||
 | 
					          armeCombat = duplicate(item);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      //console.log("Combatat", c);
 | 
				
			||||||
 | 
					      let compName = ( armeCombat == undefined ) ? "Corps à corps" : armeCombat.data.competence;
 | 
				
			||||||
 | 
					      let competence = RdDUtility.findCompetence( c.actor.data.items, compName );      
 | 
				
			||||||
 | 
					      //const cf = formula || this._getInitiativeFormula(c);
 | 
				
			||||||
 | 
					      let rollFormula =  "1d6+" + competence.data.niveau + "+" + Math.ceil(c.actor.data.data.carac[competence.data.defaut_carac].value/2);
 | 
				
			||||||
 | 
					      const roll = this._getInitiativeRoll(c, rollFormula);
 | 
				
			||||||
 | 
					      //console.log("Compute init for", armeCombat, competence, rollFormula, roll.total);
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      await this.updateEmbeddedEntity("Combatant",  { _id: c._id, initiative: roll.total });
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      // Send a chat message
 | 
				
			||||||
 | 
					      let rollMode =
 | 
				
			||||||
 | 
					        messageOptions.rollMode || game.settings.get("core", "rollMode");
 | 
				
			||||||
 | 
					      let messageData = mergeObject(
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          speaker: {
 | 
				
			||||||
 | 
					            scene: canvas.scene._id,
 | 
				
			||||||
 | 
					            actor: c.actor ? c.actor._id : null,
 | 
				
			||||||
 | 
					            token: c.token._id,
 | 
				
			||||||
 | 
					            alias: c.token.name,
 | 
				
			||||||
 | 
					            sound: CONFIG.sounds.dice,
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					          flavor: `${c.token.name} a fait son jet d'Initiative (Compétence ${competence.name})`,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        messageOptions
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					      roll.toMessage(messageData, { rollMode, create: true });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return this;
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/************************************************************************************/
 | 
				
			||||||
Hooks.once("init", async function() {
 | 
					Hooks.once("init", async function() {
 | 
				
			||||||
  console.log(`Initializing Reve de Dragon System`);
 | 
					  console.log(`Initializing Reve de Dragon System`);
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
@@ -60,6 +122,9 @@ Hooks.once("init", async function() {
 | 
				
			|||||||
  Actors.registerSheet("foundryvtt-reve-de-dragon", RdDActorSheet, { makeDefault: true });
 | 
					  Actors.registerSheet("foundryvtt-reve-de-dragon", RdDActorSheet, { makeDefault: true });
 | 
				
			||||||
  Items.unregisterSheet("core", ItemSheet);
 | 
					  Items.unregisterSheet("core", ItemSheet);
 | 
				
			||||||
  Items.registerSheet("foundryvtt-reve-de-dragon", RdDItemSheet, {makeDefault: true});
 | 
					  Items.registerSheet("foundryvtt-reve-de-dragon", RdDItemSheet, {makeDefault: true});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Patch the initiative formula
 | 
				
			||||||
 | 
					  _patch_initiative();
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* -------------------------------------------- */
 | 
					/* -------------------------------------------- */
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user