Gestion reserve

This commit is contained in:
2020-07-26 18:44:03 +02:00
parent dc57b46db5
commit c1a6ee1e92
3 changed files with 77 additions and 13 deletions

View File

@ -40,9 +40,10 @@ export class RdDTMRDialog extends Dialog {
this.actor = actor;
this.nbFatigue = 1; // 1 premier point de fatigue du à la montée
this.rencontresExistantes = duplicate(this.actor.data.data.reve.rencontre.list);
this.sortReserves = duplicate(this.actor.data.data.reve.reserve.list);
//console.log(this.rencontresExistantes);
this.pixiApp = new PIXI.Application( {width: 720, height: 860 } );
this.pixiApp = new PIXI.Application( {width: 720, height: 860 } );
}
/* -------------------------------------------- */
@ -50,6 +51,24 @@ export class RdDTMRDialog extends Dialog {
this.actor.santeIncDec("fatigue", this.nbFatigue).then( super.close() ); // moving 1 cell costs 1 fatigue
}
/* -------------------------------------------- */
displaySortReserve() {
console.log(this.sortReserves);
for (let sortReserve of this.sortReserves) {
sortReserve.circle = new PIXI.Graphics();
sortReserve.circle.beginFill(0x767610, 0.6);
sortReserve.circle.drawCircle(0, 0, 6);
sortReserve.circle.endFill();
let coordXY = TMRUtility.convertToCellCoord( sortReserve.coord );
let basey = (coordXY.x % 2 == 0) ? this.col1_y : this.col2_y;
let myx = 28+(coordXY.x * this.cellw);
let myy = basey+28+(coordXY.y * this.cellh);
sortReserve.circle.x = myx - (this.cellw/2)+16;
sortReserve.circle.y = myy - (this.cellh/2)+16;
this.pixiApp.stage.addChild(sortReserve.circle);
}
}
/* -------------------------------------------- */
displayPreviousRencontres() {
for (let rencontre of this.rencontresExistantes) {
@ -75,6 +94,15 @@ export class RdDTMRDialog extends Dialog {
this.rencontresExistantes = duplicate(this.actor.data.data.reve.rencontre.list);
this.displayPreviousRencontres();
}
/* -------------------------------------------- */
updateSortReserve() {
for (let sortReserve of this.sortReserves) { //cleanup pixi icons
this.pixiApp.stage.removeChild( sortReserve.circle );
}
this.sortReserves = duplicate(this.actor.data.data.reve.reserve.list); // Then do it again!
this.displaySortReserve();
}
/* -------------------------------------------- */
async derober() {
@ -105,10 +133,9 @@ export class RdDTMRDialog extends Dialog {
let level = draconic.data.niveau - this.currentRencontre.force;
console.log("Maitriser", carac, draconic.data.niveau, this.currentRencontre.force);
let scoreDef = CONFIG.RDD.resolutionTable[carac][level+10];
let myroll = new Roll("d100");
myroll.roll();
if ( myroll.total > scoreDef.score ) {
TMRUtility.processRencontreEchec( this.actor, this.rencontre);
let result = new Roll("d100").roll().total;
if ( result > scoreDef.score ) {
TMRUtility.processRencontreEchec( this.actor, this.currentRencontre);
ChatMessage.create( { title: "TMR", content: "Vous avez <strong>échoué</strong> à votre maîtrise d'un " . this.currentRencontre.name + " de force " +
this.currentRencontre.force +
"<br>Vous quittez brutalement les Terres Médianes !",
@ -260,6 +287,19 @@ export class RdDTMRDialog extends Dialog {
myself.circle.y = myy;
}
/* -------------------------------------------- */
async declencheSortEnReserve( coordTMR )
{
for (let sortReserve of this.sortReserves ) {
if ( sortReserve.coord == coordTMR) {
await this.actor.deleteSortReserve(coordTMR);
this.updateSortReserve();
ChatMessage.create( { title: "Sort en réserve", content: "Vous avez déclenché le sort en réserve " + sortReserve.sort.name, user: game.user._id } );
this.close();
}
}
}
/* -------------------------------------------- */
async getCursorPosition(event) {
let origEvent = event.data.originalEvent;
@ -294,8 +334,8 @@ export class RdDTMRDialog extends Dialog {
myself.nbFatigue += 1;
myself.updateValuesDisplay();
myself.manageRencontre(coordTMR, cellDescr);
myself.manageCaseHumide( cellDescr );
myself.manageCaseHumide( cellDescr );
await myself.declencheSortEnReserve( coordTMR );
}
}
@ -340,6 +380,7 @@ export class RdDTMRDialog extends Dialog {
this.pixiApp.stage.addChild(this.circle);
this.displayPreviousRencontres();
this.displaySortReserve();
} );
await this.actor.updatePointsDeReve( (this.tmrdata.isRapide) ? -2 : -1); // 1 point defatigue