Fix infinite loop + dices

This commit is contained in:
sladecraven 2022-01-11 18:19:13 +01:00
parent 1eb5c5ecb3
commit 96e02cdb7a
4 changed files with 81 additions and 32 deletions

View File

@ -197,8 +197,9 @@ export class YggdrasillActor extends Actor {
if ( changed.data.caracsecondaire.pv.value < 0 )
changed.data.caracsecondaire.pv.value = 0;
if ( changed.data.caracsecondaire.pv.value > this.data.data.caracsecondaire.pv.max )
changed.data.caracsecondaire.pv.value = this.data.data.caracsecondaire.pv.max;
changed.data.caracsecondaire.pv.value = this.data.data.caracsecondaire.pv.max;
}
if ( changed.data?.furor?.value ) {
if ( changed.data.furor.value < 0 )
changed.data.furor.value = 0;
@ -303,8 +304,10 @@ export class YggdrasillActor extends Actor {
/* -------------------------------------------- */
async setEpuise( ) {
await this.update({ 'data.status.epuise': true});
this.data.data.status.epuise = true;
if (!this.data.data.status.epuise) {
await this.update({ 'data.status.epuise': true});
this.data.data.status.epuise = true;
}
/*let effect = this.getEffectByLabel('Epuisé');
if ( !effect ) {
let effect = statusEffects.find( ef => ef.id == 'epuise');
@ -313,8 +316,10 @@ export class YggdrasillActor extends Actor {
}
/* -------------------------------------------- */
async cleanEpuise() {
await this.update({ 'data.status.epuise': false});
this.data.data.status.epuise = false;
if (this.data.data.status.epuise) {
await this.update({ 'data.status.epuise': false});
this.data.data.status.epuise = false;
}
/*let effect = this.getEffectByLabel('Epuisé');
if ( effect ) {
await this.deleteEmbeddedDocuments("ActiveEffect", [ effect.id ]);
@ -335,9 +340,10 @@ export class YggdrasillActor extends Actor {
/* -------------------------------------------- */
async setBlesse( ) {
await this.update({ 'data.status.blesse': true} );
this.data.data.status.blesse = true;
console.log("BLESSSE !!!!");
if (!this.data.data.status.blesse) {
await this.update({ 'data.status.blesse': true} );
this.data.data.status.blesse = true;
}
/*let effect = this.getEffectByLabel('Blessé');
if ( !effect ) {
let effect = statusEffects.find( ef => ef.id == 'blesse');
@ -346,8 +352,10 @@ export class YggdrasillActor extends Actor {
}
/* -------------------------------------------- */
async cleanBlesse() {
await this.update({ 'data.status.blesse': false} );
this.data.data.status.blesse = false;
if (this.data.data.status.blesse) {
await this.update({ 'data.status.blesse': false} );
this.data.data.status.blesse = false;
}
/*let effect = this.getEffectByLabel('Blessé');
if ( effect ) {
await this.deleteEmbeddedDocuments("ActiveEffect", [ effect.id ]);
@ -362,13 +370,17 @@ export class YggdrasillActor extends Actor {
/* -------------------------------------------- */
async setMeurtri( ) {
await this.setBlesse();
await this.update({ 'data.status.meurtri': true});
this.data.data.status.meurtri = true;
if (!this.data.data.status.meurtri) {
await this.update({ 'data.status.meurtri': true});
this.data.data.status.meurtri = true;
}
}
/* -------------------------------------------- */
async cleanMeurtri() {
await this.update({ 'data.status.meurtri': false});
this.data.data.status.meurtri = false;
if (this.data.data.status.meurtri) {
await this.update({ 'data.status.meurtri': false});
this.data.data.status.meurtri = false;
}
}
/* -------------------------------------------- */
isMeurtri() {

View File

@ -183,31 +183,66 @@ export class YggdrasillUtility {
rollData.finalBM -= 3;
}
rollData.rawDices = []
if (sumDice > nbDice) sumDice = nbDice;
let myRoll = new Roll(nbDice+"d10x10kh"+sumDice+"+"+rollData.furorUsage+"d10+"+niveauCompetence+"+"+rollData.finalBM).roll( { async: false} );
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode") );
let rolls = []
let maxTab = [ {idx: 0, value: 0}, {idx: 0, value:0}]
for (let i=0; i<nbDice; i++) {
rolls[i] = new Roll("1d10x10").roll( {async: false}) //+sumDice+"+"+rollData.furorUsage+"d10+"+niveauCompetence+"+"+rollData.finalBM).roll( { async: false} );
if ( i == nbDice-1 ) {
await this.showDiceSoNice(rolls[nbDice-1], game.settings.get("core", "rollMode") );
} else {
this.showDiceSoNice(rolls[i], game.settings.get("core", "rollMode") );
}
rollData.rawDices.push({ 'result': rolls[i].total});
if ( rolls[i].total > maxTab[0].value) {
if ( maxTab[0].value > maxTab[1].value) {
maxTab[1].value = maxTab[0].value
maxTab[1].idx = maxTab[0].idx
}
maxTab[0].value = rolls[i].total
maxTab[0].idx = i
} else {
if ( rolls[i].total > maxTab[1].value) {
maxTab[1].value = rolls[i].total
maxTab[1].idx = i
}
}
}
let bonusRoll = new Roll(rollData.furorUsage+"d10x10+"+niveauCompetence+"+"+rollData.finalBM).roll( {async: false})
if ( rollData.furorUsage > 0) {
this.showDiceSoNice(bonusRoll, game.settings.get("core", "rollMode") );
}
rollData.finalTotal = (sumDice ==1) ? maxTab[0].value : maxTab[0].value + maxTab[1].value;
rollData.finalTotal += bonusRoll.total;
rollData.furorResult = (rollData.furorUsage >0 ) ? bonusRoll.dice[0].results[0].result : 0;
rollData.maxTab = maxTab
// Compute total SR
rollData.srFinal = rollData.sr;
if ( rollData.bonusdefense ) {
rollData.srFinal += rollData.bonusdefense;
}
}
if ( rollData.srFinal > 0 ) {
isCritical = myRoll.total >= rollData.srFinal*2;
isSuccess = myRoll.total >= rollData.srFinal;
marge = myRoll.total - rollData.srFinal;
isCritical = myRoll.finalTotal >= rollData.srFinal*2;
isSuccess = myRoll.finalTotal >= rollData.srFinal;
marge = myRoll.finalTotal - rollData.srFinal;
}
rollData.rawDices = duplicate(myRoll.dice[0].results);
if (nbDice == 1 && myRoll.dice[0].results[0].result == 1) {
if (nbDice == 1 && rolls[0].dice[0].results[0].result == 1) {
isFailure = true;
}
if (nbDice == 2 && myRoll.dice[0].results[0].result == 1 && myRoll.dice[0].results[1].result == 1) {
if (nbDice == 2 && rolls[0].dice[0].results[0].result == 1 && rolls[1].dice[0].results[0].result == 1) {
isFailure = true;
}
if (nbDice >= 3 ) {
let nbOnes = myRoll.dice[0].results.filter( dice => dice.result == 1);
isFailure = nbOnes.length >= 3;
let nbOnes = 0
for (let roll of rolls) {
if (roll.dice[0].results[0].result == 1 ) nbOnes++;
}
isFailure = nbOnes >= 3;
}
if ( rollData.furorUsage > 0 ) {
let actor = game.actors.get(rollData.actorId);
@ -221,12 +256,12 @@ export class YggdrasillUtility {
}
// Stockage resultats
rollData.rolls = rolls
rollData.sumDice = sumDice;
rollData.isFailure = isFailure;
rollData.isSuccess = isSuccess;
rollData.isCritical = isCritical;
rollData.marge = marge;
rollData.roll = myRoll
// Specific GALDR
if ( rollData.sort?.type == "sortgaldr" && rollData.isSuccess) {

View File

@ -2,7 +2,7 @@
"name": "fvtt-yggdrasill",
"title": "Yggdrasill",
"description": "Système non-officiel Yggdrasill (7ièm Cercle) pour FoundryVTT",
"version": "1.1.1",
"version": "1.1.2",
"manifestPlusVersion": "1.0.0",
"minimumCoreVersion": "0.8.0",
"compatibleCoreVersion": "9",

View File

@ -43,21 +43,23 @@
<div>
<ul>
<li>Dés :
{{#each rawDices as |dice key|}}
{{dice.result}}&nbsp;
{{#each rawDices as |roll key|}}
{{roll.result}}&nbsp;
{{/each}}
</li>
{{#if sumDice}}
<li>Nombre de dés additionnés : {{sumDice}}</li>
{{/if}}
<li>{{#if (eq mode "carac")}}Carac{{else}}Competence{{/if}} : {{niveauCompetence}}</li>
<li>Bonus/Malus Final : {{finalBM}}</li>
{{#if sr}}
<li>Seuil de Réussite final : {{srFinal}}</li>
{{/if}}
{{#if furorUsage}}
<li>Furor : {{furorUsage}}</li>
<li>Furor dépensée : {{furorUsage}}</li>
<li>Resultat de la Furor : {{furorResult}}</li>
{{/if}}
<li><h3>Total : {{roll.total}}</h3></li>
<li><h3>Total : {{finalTotal}}</h3></li>
</ul>
{{#if dureeGaldrText}}