Ehance UI and weapon damages

This commit is contained in:
2021-04-08 13:58:51 +02:00
parent 1403e058df
commit 773d06f8d5
10 changed files with 218 additions and 50 deletions

View File

@@ -18,11 +18,22 @@ export class VadentisUtility extends Entity {
return loadTemplates(templatePaths);
}
/* -------------------------------------------- */
static updateCombat( combat, round, diff, id ) {
if (game.user.isGM && combat.data.round != 0 && combat.turns && combat.data.active) {
let turn = combat.turns.find(t => t.tokenId == combat.current.tokenId);
ChatMessage.create( { content: `Round ${combat.data.round} : C'est au tour de ${turn.actor.name}<br>` } );
canvas.tokens.get(turn.token._id).control();
canvas.tokens.cycleTokens(1, true);
}
}
/* -------------------------------------------- */
static createOptionList( min, max) {
let options = ""
for(let i=min; i<=max; i++) {
options+= `<option value="${i}">${i}</option>\n`;
options += `<option value="${i}">${i}</option>\n`;
}
return options;
}
@@ -31,10 +42,18 @@ export class VadentisUtility extends Entity {
static createDirectOptionList( min, max) {
let options = {};
for(let i=min; i<=max; i++) {
options[i] = i;
options[`${i}`] = `${i}`;
}
return options;
}
/* -------------------------------------------- */
static createDirectReverseOptionList( min, max) {
let options = {};
for(let i=max; i>=min; i--) {
options[`${i}`] = `${i}`;
}
return options;
}
/* -------------------------------------------- */
static getTarget() {
@@ -46,6 +65,25 @@ export class VadentisUtility extends Entity {
return undefined;
}
/* -------------------------------------------- */
static processDamageString( formula, actor ) {
let workFormula = formula.toLowerCase();
if ( workFormula.includes('bonus de force')) {
workFormula = workFormula.replace('bonus de force', actor.getForceScore());
}
return workFormula;
}
/* -------------------------------------------- */
static async processRoll( formula ) {
let myRoll = new Roll(formula);
myRoll.evaluate();
if (game.modules.get("dice-so-nice") && game.modules.get("dice-so-nice").active) {
await game.dice3d.showForRoll(myRoll, game.user, true);
}
return myRoll;
}
/* -------------------------------------------- */
static async performAttack( combatData) {
let attacker = game.actors.get(combatData.attackerActorId);
@@ -53,16 +91,27 @@ export class VadentisUtility extends Entity {
if( attacker && defender) {
let defense = defender.getDefenseScore();
let attaque = attacker.getAttaqueScore();
console.log("Attaque : ", attaque);
let myRoll = new Roll("1d20"+attaque);
myRoll.evaluate()
if (game.modules.get("dice-so-nice") && game.modules.get("dice-so-nice").active) {
await game.dice3d.showForRoll(myRoll, game.user, true);
}
if (myRoll.total >= defense) { // Success !
ChatMessage.create( { content: `${attacker.name} a réussi son attaque sur ${defender.name} (${myRoll.total} / ${defense}) !<br> Les dégâts sont de : ${combatData.arme.data.damage}`});
let myRoll = await this.processRoll("1d20+"+attaque);
if (myRoll.results[0] > 1 && myRoll.total >= defense) { // Success !
let degats = `normaux : ${combatData.arme.data.damage}`;
let formula = combatData.arme.data.damage.toLowerCase();
if ( myRoll.results[0] == 20) {
degats = `critiques : ${combatData.arme.data.criticaldamage}`;
formula = combatData.arme.data.criticaldamage.toLowerCase();
}
ChatMessage.create( { content: `${attacker.name} a réussi son attaque sur ${defender.name} (${myRoll.total} / ${defense}) !<br> Les dégâts sont ${degats}`});
formula = this.processDamageString( formula, attacker );
let degatsRoll = await this.processRoll(formula);
ChatMessage.create( { content: `Et les dégats infligés sont de ${degatsRoll.total} (${formula}) à appliquer à ${defender.name}`});
defender.applyDamage( degatsRoll.total );
} else { //Echec
ChatMessage.create( { content: `${attacker.name} a raté son attaque sur ${defender.name} (${myRoll.total} / ${defense}) !` });
if ( myRoll.results[0] == 1) {
ChatMessage.create( { content: `${attacker.name} a fait un <strong>échec critique</strong> et a raté son attaque sur ${defender.name} (${myRoll.total} / ${defense}) !` });
} else {
ChatMessage.create( { content: `${attacker.name} a raté son attaque sur ${defender.name} (${myRoll.total} / ${defense}) !` });
}
}
} else {
ui.notifications.warn("Impossible de trouver l'attaquant et le défenseur.")