2020-07-05 21:45:25 +02:00
/ * *
* Extend the base Dialog entity by defining a custom window to perform spell .
* @ extends { Dialog }
* /
2021-01-29 15:13:59 +01:00
import { RollDataAjustements } from "./rolldata-ajustements.js" ;
2020-07-06 09:03:21 +02:00
import { RdDUtility } from "./rdd-utility.js" ;
2020-07-17 22:04:35 +02:00
import { TMRUtility } from "./tmr-utility.js" ;
2021-01-29 15:13:59 +01:00
import { tmrConstants } from "./tmr-utility.js" ;
2020-11-12 16:35:51 +01:00
import { RdDResolutionTable } from "./rdd-resolution-table.js" ;
2020-11-29 18:21:34 +01:00
import { RdDTMRRencontreDialog } from "./rdd-tmr-rencontre-dialog.js" ;
2021-01-29 15:13:59 +01:00
import { TMRRencontres } from "./tmr-rencontres.js" ;
import { ChatUtility } from "./chat-utility.js" ;
2020-11-14 03:16:03 +01:00
2020-11-18 23:49:05 +01:00
/* -------------------------------------------- */
2020-07-05 21:45:25 +02:00
export class RdDTMRDialog extends Dialog {
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
2020-11-29 18:06:19 +01:00
constructor ( html , actor , tmrData , mode ) {
2020-11-14 03:16:03 +01:00
const dialogConf = {
title : "Terres Médianes de Rêve" ,
2020-07-05 21:45:25 +02:00
content : html ,
2020-11-14 03:16:03 +01:00
buttons : {
closeButton : { label : "Fermer" , callback : html => this . close ( html ) }
} ,
default : "closeButton"
}
const dialogOptions = {
classes : [ "tmrdialog" ] ,
width : 920 , height : 980 ,
'z-index' : 20
}
2020-07-05 21:45:25 +02:00
super ( dialogConf , dialogOptions ) ;
2020-11-14 03:16:03 +01:00
this . tmrdata = duplicate ( tmrData ) ;
2020-07-14 22:19:29 +02:00
this . actor = actor ;
2020-11-17 18:08:19 +01:00
this . actor . tmrApp = this ; // reference this app in the actor structure
2020-11-29 18:06:19 +01:00
this . viewOnly = mode == "visu"
2020-11-14 20:46:39 +01:00
this . nbFatigue = this . viewOnly ? 0 : 1 ; // 1 premier point de fatigue du à la montée
2020-07-21 23:51:24 +02:00
this . rencontresExistantes = duplicate ( this . actor . data . data . reve . rencontre . list ) ;
2020-07-26 18:44:03 +02:00
this . sortReserves = duplicate ( this . actor . data . data . reve . reserve . list ) ;
2021-01-29 15:13:59 +01:00
this . casesSpeciales = this . actor . data . items . filter ( item => item . type == 'casetmr' ) ;
2020-11-17 18:08:19 +01:00
this . allTokens = [ ] ;
2020-11-20 13:46:43 +01:00
this . rencontreState = 'aucune' ;
2020-11-14 03:16:03 +01:00
this . pixiApp = new PIXI . Application ( { width : 720 , height : 860 } ) ;
2021-01-29 15:13:59 +01:00
if ( ! this . viewOnly ) {
2021-01-13 03:42:13 +01:00
this . actor . setStatusDemiReve ( true ) ;
2020-11-29 18:06:19 +01:00
this . _tellToGM ( this . actor . name + " monte dans les terres médianes (" + mode + ")" ) ;
}
2020-07-14 22:19:29 +02:00
}
2021-01-29 15:13:59 +01:00
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
2020-07-25 10:29:28 +02:00
close ( ) {
2020-11-14 03:16:03 +01:00
this . actor . santeIncDec ( "fatigue" , this . nbFatigue ) . then ( super . close ( ) ) ; // moving 1 cell costs 1 fatigue
2020-11-17 18:08:19 +01:00
this . actor . tmrApp = undefined ; // Cleanup reference
2021-01-13 03:42:13 +01:00
this . actor . setStatusDemiReve ( false ) ;
2021-01-29 15:13:59 +01:00
if ( ! this . viewOnly ) {
2021-01-20 19:29:02 +01:00
this . _tellToGM ( this . actor . name + " a quitté les terres médianes" ) ;
}
2020-07-25 10:29:28 +02:00
}
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
2020-07-26 18:44:03 +02:00
displaySortReserve ( ) {
2020-11-14 03:16:03 +01:00
console . debug ( "displaySortReserve" , this . sortReserves ) ;
for ( let sort of this . sortReserves ) {
this . _trackToken ( this . _tokenSortEnReserve ( sort ) ) ;
2020-07-26 18:44:03 +02:00
}
}
2020-11-14 03:16:03 +01:00
2020-12-30 18:12:01 +01:00
/* -------------------------------------------- */
displaySpecificCase ( ) {
for ( let caseTMR of this . casesSpeciales ) {
console . log ( "SPEC CASE " , caseTMR ) ;
2021-01-29 15:13:59 +01:00
if ( caseTMR . data . specific == 'trounoir' ) {
this . _trackToken ( this . _tokenTrouNoir ( caseTMR . data . coord ) ) ;
} else if ( caseTMR . data . specific == 'attache' ) {
this . _trackToken ( this . _tokenTerreAttache ( caseTMR . data . coord ) ) ;
} else if ( caseTMR . data . specific == 'debordement' ) {
this . _trackToken ( this . _tokenDebordement ( caseTMR . data . coord ) ) ;
} else if ( caseTMR . data . specific == 'maitrisee' ) {
this . _trackToken ( this . _tokenMaitrisee ( caseTMR . data . coord ) ) ;
2020-12-30 18:12:01 +01:00
}
}
}
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
2020-07-21 23:51:24 +02:00
displayPreviousRencontres ( ) {
2020-11-14 03:16:03 +01:00
console . debug ( "displayPreviousRencontres" , this . rencontresExistantes ) ;
2020-07-21 23:51:24 +02:00
for ( let rencontre of this . rencontresExistantes ) {
2020-11-14 03:16:03 +01:00
this . _trackToken ( this . _tokenRencontre ( rencontre ) ) ;
2020-07-21 23:51:24 +02:00
}
}
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
2020-07-21 23:51:24 +02:00
updatePreviousRencontres ( ) {
2020-11-14 03:16:03 +01:00
this . _removeTokens ( t => t . rencontre != undefined ) ;
this . rencontresExistantes = duplicate ( this . actor . data . data . reve . rencontre . list ) ;
this . displayPreviousRencontres ( ) ;
2020-07-21 23:51:24 +02:00
}
2020-07-26 18:44:03 +02:00
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
2020-07-26 18:44:03 +02:00
updateSortReserve ( ) {
2020-11-14 03:16:03 +01:00
this . _removeTokens ( t => t . sort != undefined ) ;
this . sortReserves = duplicate ( this . actor . data . data . reve . reserve . list ) ;
2020-07-26 18:44:03 +02:00
this . displaySortReserve ( ) ;
}
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
2020-07-17 22:04:35 +02:00
async derober ( ) {
2020-11-14 03:16:03 +01:00
await this . actor . addTMRRencontre ( this . currentRencontre ) ;
2020-07-17 22:04:35 +02:00
console . log ( "-> derober" , this . currentRencontre ) ;
2020-11-14 03:16:03 +01:00
this . _tellToGM ( this . actor . name + " s'est dérobé et quitte les TMR." ) ;
2020-07-21 23:51:24 +02:00
this . close ( ) ;
2020-07-14 22:19:29 +02:00
}
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
2021-01-29 15:13:59 +01:00
async refouler ( ) {
this . _tellToGM ( this . actor . name + " a refoulé : " + this . currentRencontre . name ) ;
2020-11-14 03:16:03 +01:00
await this . actor . deleteTMRRencontreAtPosition ( ) ; // Remove the stored rencontre if necessary
2021-01-29 15:13:59 +01:00
await this . actor . ajouterRefoulement ( this . currentRencontre . refoulement ? ? 1 ) ;
2020-07-21 23:51:24 +02:00
this . updatePreviousRencontres ( ) ;
2020-07-14 22:19:29 +02:00
console . log ( "-> refouler" , this . currentRencontre )
2020-07-17 22:04:35 +02:00
this . updateValuesDisplay ( ) ;
2020-11-20 13:46:43 +01:00
this . nettoyerRencontre ( ) ;
2020-07-14 22:19:29 +02:00
}
2020-11-20 12:06:54 +01:00
/* -------------------------------------------- */
2021-01-29 15:13:59 +01:00
async ignorerRencontre ( ) {
this . _tellToGM ( this . actor . name + " a ignoré : " + this . currentRencontre . name ) ;
await this . actor . deleteTMRRencontreAtPosition ( ) ; // Remove the stored rencontre if necessary
this . updatePreviousRencontres ( ) ;
this . updateValuesDisplay ( ) ;
this . nettoyerRencontre ( ) ;
}
/* -------------------------------------------- */
colorierZoneRencontre ( locList ) {
2020-11-20 12:06:54 +01:00
this . currentRencontre . graphics = [ ] ; // Keep track of rectangles to delete it
this . currentRencontre . locList = duplicate ( locList ) ; // And track of allowed location
for ( let loc of locList ) {
2021-01-29 15:13:59 +01:00
let rect = this . _getCaseRectangleCoord ( loc ) ;
2020-11-20 12:06:54 +01:00
var rectDraw = new PIXI . Graphics ( ) ;
rectDraw . beginFill ( 0xFFFF00 , 0.3 ) ;
// set the line style to have a width of 5 and set the color to red
rectDraw . lineStyle ( 5 , 0xFF0000 ) ;
// draw a rectangle
rectDraw . drawRect ( rect . x , rect . y , rect . w , rect . h ) ;
this . pixiApp . stage . addChild ( rectDraw ) ;
this . currentRencontre . graphics . push ( rectDraw ) ; // garder les objets pour gestion post-click
}
}
2020-11-21 14:30:00 +01:00
/* -------------------------------------------- */
2021-01-29 15:13:59 +01:00
// garder la trace de l'état en cours
setStateRencontre ( state ) {
this . rencontreState = state ;
2020-11-21 14:30:00 +01:00
}
2021-01-29 15:13:59 +01:00
async choisirCasePortee ( coord , portee ) {
// Récupère la liste des cases à portées
let locList = TMRUtility . getTMRPortee ( coord , portee ) ;
this . colorierZoneRencontre ( locList ) ;
2020-12-30 15:18:58 +01:00
}
2020-11-21 08:27:28 +01:00
2021-01-29 15:13:59 +01:00
async choisirCaseType ( type ) {
const locList = TMRUtility . getListCoordTMR ( type ) ;
this . colorierZoneRencontre ( locList ) ;
2020-11-21 08:27:28 +01:00
}
2021-01-29 15:13:59 +01:00
2020-11-21 08:27:28 +01:00
/* -------------------------------------------- */
2020-11-21 23:24:00 +01:00
checkQuitterTMR ( ) {
2021-01-29 15:13:59 +01:00
if ( this . actor . isDead ( ) ) {
this . _tellToGM ( "Vous êtes mort : vous quittez les Terres médianes !" ) ;
2020-11-21 08:27:28 +01:00
this . close ( ) ;
2021-01-29 15:13:59 +01:00
return true ;
2020-11-21 08:27:28 +01:00
}
2021-01-29 15:13:59 +01:00
const resteAvantInconscience = this . actor . getFatigueMax ( ) - this . actor . getFatigueActuelle ( ) - this . nbFatigue ;
if ( resteAvantInconscience <= 0 ) {
2020-11-29 18:06:19 +01:00
this . _tellToGM ( "Vous vous écroulez de fatigue : vous quittez les Terres médianes !" ) ;
2021-01-29 15:13:59 +01:00
this . quitterLesTMRInconscient ( ) ;
return true ;
2020-11-21 08:27:28 +01:00
}
2021-01-29 15:13:59 +01:00
if ( this . actor . getReveActuel ( ) == 0 ) {
this . _tellToGM ( "Vos Points de Rêve sont à 0 : vous quittez les Terres médianes !" ) ;
this . quitterLesTMRInconscient ( ) ;
return true ;
}
return false ;
}
async quitterLesTMRInconscient ( ) {
if ( this . currentRencontre ? . isPersistant ) {
await this . refouler ( ) ;
2020-11-21 08:27:28 +01:00
}
2021-01-29 15:13:59 +01:00
this . close ( ) ;
2020-11-20 12:06:54 +01:00
}
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
2021-01-29 15:13:59 +01:00
async maitriser ( ) {
this . actor . deleteTMRRencontreAtPosition ( ) ;
2020-07-21 23:51:24 +02:00
this . updatePreviousRencontres ( ) ;
2020-11-14 03:16:03 +01:00
2021-01-29 15:13:59 +01:00
let rencontreData = {
actor : this . actor ,
alias : this . actor . name ,
reveDepart : this . actor . getReveActuel ( ) ,
competence : this . actor . getBestDraconic ( ) ,
rencontre : this . currentRencontre ,
nbRounds : 1 ,
tmr : TMRUtility . getTMR ( this . actor . data . data . reve . tmrpos . coord )
}
await this . _tentativeMaitrise ( rencontreData ) ;
}
2020-11-14 03:16:03 +01:00
2021-01-29 15:13:59 +01:00
async _tentativeMaitrise ( rencontreData ) {
console . log ( "-> matriser" , rencontreData ) ;
2020-11-29 18:06:19 +01:00
2021-01-29 15:13:59 +01:00
rencontreData . reve = this . actor . getReveActuel ( ) ;
rencontreData . etat = this . actor . getEtatGeneral ( ) ;
2020-11-20 12:06:54 +01:00
2021-01-29 15:13:59 +01:00
RollDataAjustements . calcul ( rencontreData , this . actor ) ;
rencontreData . rolled = await RdDResolutionTable . roll ( rencontreData . reve , RollDataAjustements . sum ( rencontreData . ajustements ) ) ;
let postProcess = await TMRRencontres . gererRencontre ( this , rencontreData ) ;
ChatMessage . create ( {
whisper : ChatUtility . getWhisperRecipientsAndGMs ( game . user . name ) ,
content : await renderTemplate ( ` systems/foundryvtt-reve-de-dragon/templates/chat-rencontre-tmr.html ` , rencontreData )
} ) ;
if ( postProcess ) {
/** Gère les rencontres avec du post-processing (passeur, messagers, tourbillons, ...) */
await postProcess ( this , rencontreData ) ;
}
else {
this . currentRencontre = undefined ;
}
2020-11-20 12:06:54 +01:00
2020-07-17 22:04:35 +02:00
this . updateValuesDisplay ( ) ;
2021-01-29 15:13:59 +01:00
if ( this . checkQuitterTMR ( ) ) {
return ;
}
else if ( rencontreData . rolled . isEchec && rencontreData . rencontre . isPersistant ) {
setTimeout ( ( ) => {
rencontreData . nbRounds ++ ;
this . nbFatigue += 1 ;
this . _tentativeMaitrise ( rencontreData ) ;
2021-02-05 01:38:40 +01:00
this . _deleteTmrMessages ( rencontreData . actor , rencontreData . nbRounds ) ;
2021-01-29 15:13:59 +01:00
} , 2000 ) ;
}
}
_deleteTmrMessages ( actor , nbRounds = - 1 ) {
2021-02-05 01:38:40 +01:00
setTimeout ( ( ) => {
if ( nbRounds < 0 ) {
ChatUtility . removeChatMessageContaining ( ` <h4 data-categorie="tmr" data-actor-id=" ${ actor . _id } " ` ) ;
2021-01-29 15:13:59 +01:00
}
2021-02-05 01:38:40 +01:00
else {
for ( let i = 1 ; i < nbRounds ; i ++ ) {
ChatUtility . removeChatMessageContaining ( ` <h4 data-categorie="tmr" data-actor-id=" ${ actor . _id } " data-rencontre-round=" ${ i } "> ` ) ;
}
}
} , 500 ) ;
2020-07-14 22:19:29 +02:00
}
2020-11-12 23:35:29 +01:00
2020-11-17 16:30:03 +01:00
/* -------------------------------------------- */
2020-11-14 03:16:03 +01:00
_tellToUser ( message ) {
2020-11-29 18:06:19 +01:00
ChatMessage . create ( { content : message , user : game . user . _id , whisper : [ game . user . _id ] } ) ;
2020-11-14 03:16:03 +01:00
}
2020-11-18 23:49:05 +01:00
/* -------------------------------------------- */
_tellToGM ( message ) {
2020-11-24 15:43:03 +01:00
ChatMessage . create ( { content : message , user : game . user . _id , whisper : ChatMessage . getWhisperRecipients ( "GM" ) } ) ;
2020-11-18 23:49:05 +01:00
}
2021-01-29 15:13:59 +01:00
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
2021-02-05 01:38:40 +01:00
async manageRencontre ( tmr , postRencontre ) {
2020-11-14 20:46:39 +01:00
if ( this . viewOnly ) {
return ;
}
2020-11-14 03:16:03 +01:00
this . currentRencontre = undefined ;
2021-02-05 01:38:40 +01:00
let rencontre = await this . _jetDeRencontre ( tmr ) ;
2021-01-29 15:13:59 +01:00
2020-07-14 22:19:29 +02:00
if ( rencontre ) { // Manages it
2020-11-18 18:11:01 +01:00
if ( rencontre . rencontre ) rencontre = rencontre . rencontre ; // Manage stored rencontres
2020-12-30 18:12:01 +01:00
console . log ( "manageRencontre" , rencontre ) ;
2020-07-21 23:51:24 +02:00
this . currentRencontre = duplicate ( rencontre ) ;
2020-11-16 04:01:36 +01:00
2021-02-05 01:38:40 +01:00
let dialog = new RdDTMRRencontreDialog ( "" , this , this . currentRencontre , postRencontre ) ;
2020-11-12 23:35:29 +01:00
dialog . render ( true ) ;
2020-07-14 22:19:29 +02:00
}
}
2020-11-14 03:16:03 +01:00
2020-12-30 15:18:58 +01:00
/* -------------------------------------------- */
2021-02-05 01:38:40 +01:00
async _jetDeRencontre ( tmr ) {
2020-11-29 18:06:19 +01:00
if ( TMRUtility . isForceRencontre ( ) ) {
2021-02-05 01:38:40 +01:00
return await TMRUtility . rencontreTMRRoll ( tmr . coord , tmr ) ;
2020-11-29 18:06:19 +01:00
}
2021-02-05 01:38:40 +01:00
let rencontre = this . rencontresExistantes . find ( prev => prev . coord == tmr . coord ) ;
2021-01-29 15:13:59 +01:00
if ( rencontre ) {
return rencontre ;
}
let myRoll = new Roll ( "1d7" ) . evaluate ( ) ;
if ( myRoll . total == 7 ) {
let isMauvaise = this . actor . isRencontreSpeciale ( ) ;
2021-02-05 01:38:40 +01:00
return await TMRUtility . rencontreTMRRoll ( tmr . coord , tmr , isMauvaise ) ;
2021-01-29 15:13:59 +01:00
}
2021-02-05 01:38:40 +01:00
this . _tellToUser ( myRoll . total + ": Pas de rencontre en " + tmr . label + " (" + tmr . coord + ")" ) ;
2020-11-29 18:06:19 +01:00
}
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
2020-07-17 22:04:35 +02:00
updateValuesDisplay ( ) {
2020-11-20 16:45:20 +01:00
let ptsreve = document . getElementById ( "tmr-pointsreve-value" ) ;
2020-07-17 22:04:35 +02:00
ptsreve . innerHTML = this . actor . data . data . reve . reve . value ;
2020-11-14 03:16:03 +01:00
2020-07-17 22:04:35 +02:00
let tmrpos = document . getElementById ( "tmr-pos" ) ;
2021-01-29 15:13:59 +01:00
let tmr = TMRUtility . getTMR ( this . actor . data . data . reve . tmrpos . coord ) ;
2020-11-14 03:16:03 +01:00
tmrpos . innerHTML = this . actor . data . data . reve . tmrpos . coord + " (" + tmr . label + ")" ;
2020-11-20 16:45:20 +01:00
let etat = document . getElementById ( "tmr-etatgeneral-value" ) ;
2021-01-05 18:43:13 +01:00
etat . innerHTML = this . actor . getEtatGeneral ( ) ;
2020-07-17 22:04:35 +02:00
2020-11-20 16:45:20 +01:00
let refoulement = document . getElementById ( "tmr-refoulement-value" ) ;
2020-07-17 22:04:35 +02:00
refoulement . innerHTML = this . actor . data . data . reve . refoulement . value ;
2020-11-14 03:16:03 +01:00
2020-11-20 16:45:20 +01:00
let fatigueItem = document . getElementById ( "tmr-fatigue-table" ) ;
2020-12-30 19:27:35 +01:00
//console.log("Refresh : ", this.actor.data.data.sante.fatigue.value);
2020-11-14 03:16:03 +01:00
fatigueItem . innerHTML = "<table class='table-fatigue'>" + RdDUtility . makeHTMLfatigueMatrix ( this . actor . data . data . sante . fatigue . value , this . actor . data . data . sante . endurance . max ) . html ( ) + "</table>" ;
2020-07-17 22:04:35 +02:00
}
2020-12-30 18:12:01 +01:00
/* -------------------------------------------- */
2021-02-05 01:38:40 +01:00
async manageCaseSpeciale ( tmr ) {
2021-01-29 15:13:59 +01:00
for ( let caseTMR of this . casesSpeciales ) {
2021-02-05 01:38:40 +01:00
if ( caseTMR . data . coord == tmr . coord ) { // Match !
2020-12-30 18:12:01 +01:00
if ( caseTMR . data . specific == 'trounoir' ) {
let newTMR = TMRUtility . getTMRAleatoire ( ) ;
let tmrPos = duplicate ( this . actor . data . data . reve . tmrpos ) ;
2021-02-05 01:38:40 +01:00
tmrPos . coord = newTMR . coord ;
2021-01-29 15:13:59 +01:00
await this . actor . update ( { "data.reve.tmrpos" : tmrPos } ) ;
ChatMessage . create ( {
2020-12-30 18:12:01 +01:00
content : "Vous êtes rentré sur un Trou Noir : ré-insertion aléatoire." ,
2021-01-29 15:13:59 +01:00
whisper : ChatMessage . getWhisperRecipients ( game . user . name )
} ) ;
2020-12-30 18:12:01 +01:00
}
}
}
}
2020-12-30 21:11:01 +01:00
/* -------------------------------------------- */
2021-01-29 15:13:59 +01:00
isCaseMaitrisee ( coordTMR ) {
2021-02-05 01:38:40 +01:00
return this . casesSpeciales . find ( it => it . data . coord = coordTMR && it . data . specific == 'maitrisee' ) ;
2020-12-30 21:11:01 +01:00
}
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
2020-07-17 22:04:35 +02:00
manageCaseHumideResult ( ) {
2020-11-14 03:16:03 +01:00
if ( this . toclose )
2020-07-17 22:04:35 +02:00
this . close ( ) ;
}
2020-11-12 16:35:51 +01:00
/* -------------------------------------------- */
2021-02-05 01:38:40 +01:00
async manageCaseHumide ( tmr ) {
2021-01-29 15:13:59 +01:00
if ( this . viewOnly || this . currentRencontre ) {
2020-11-14 20:46:39 +01:00
return ;
}
2021-02-05 01:38:40 +01:00
if ( this . isCaseHumide ( tmr ) ) {
2020-12-15 02:20:24 +01:00
// TODO: permettre de choisir la voie de draconic?
2020-07-17 22:04:35 +02:00
let draconic = this . actor . getBestDraconic ( ) ;
2020-11-14 03:16:03 +01:00
2020-11-16 04:01:36 +01:00
let carac = this . actor . getReveActuel ( ) ;
2021-01-05 18:43:13 +01:00
const etatGeneral = this . actor . getEtatGeneral ( ) ;
2020-11-14 03:16:03 +01:00
let difficulte = draconic . data . niveau - 7 ;
2020-11-29 18:21:34 +01:00
let rolled = await RdDResolutionTable . roll ( carac , difficulte ) ;
2021-01-29 15:13:59 +01:00
2020-12-30 16:49:07 +01:00
// Gestion du souffle Double Résistance du Fleuve
2021-01-29 15:13:59 +01:00
if ( this . actor . isDoubleResistanceFleuve ( ) ) {
2020-12-30 16:49:07 +01:00
let rolled2 = await RdDResolutionTable . roll ( carac , difficulte ) ;
2021-01-29 15:13:59 +01:00
if ( rolled2 . isEchec )
2020-12-30 16:49:07 +01:00
rolled = rolled ;
}
2020-11-13 15:40:53 +01:00
console . log ( "manageCaseHumide >>" , rolled ) ;
2020-11-12 16:35:51 +01:00
2020-11-14 03:16:03 +01:00
let explication = "" ;
2020-11-29 18:21:34 +01:00
let msg2MJ = "" ;
2020-11-13 15:40:53 +01:00
this . toclose = rolled . isEchec ;
if ( rolled . isEchec ) {
2020-11-14 03:16:03 +01:00
explication += "Vous êtes entré sur une case humide, et vous avez <strong>raté</strong> votre maîtrise ! Vous <strong>quittez les Terres Médianes</strong> !"
2020-11-29 18:21:34 +01:00
msg2MJ += game . user . name + " est rentré sur une case humides : Echec !" ;
2020-11-12 16:35:51 +01:00
}
else {
2020-11-14 03:16:03 +01:00
explication += "Vous êtes entré sur une case humide, et vous avez <strong>réussi</strong> votre maîtrise !"
2020-11-29 18:21:34 +01:00
msg2MJ += game . user . name + " est rentré sur une case humides : Réussite !" ;
2020-11-12 16:35:51 +01:00
}
2021-02-05 01:38:40 +01:00
explication += "<br><strong>Test : Rêve actuel / " + draconic . name + " / " + tmr . type + "</strong>"
2020-11-16 04:32:42 +01:00
+ RdDResolutionTable . explain ( rolled ) ;
2020-11-12 16:35:51 +01:00
if ( rolled . isETotal ) {
2021-01-29 15:13:59 +01:00
let souffle = await this . actor . ajouterSouffle ( { chat : false } ) ;
2020-11-14 03:16:03 +01:00
explication += "<br>Vous avez fait un Echec Total. Vous subissez un Souffle de Dragon : " + souffle . name ;
2020-11-29 18:21:34 +01:00
msg2MJ += "<br>Et a reçu un Souffle de Dragon : " + souffle . name ;
2020-11-12 16:35:51 +01:00
}
if ( rolled . isPart ) {
2020-11-14 03:16:03 +01:00
explication += "<br>Vous avez fait une Réussite Particulière" ;
2021-02-05 01:38:40 +01:00
this . actor . _appliquerAjoutExperience ( { rolled : rolled , selectedCarac : { label : 'reve' } , competence : draconic . name } )
2020-11-29 18:21:34 +01:00
msg2MJ += "<br>Et a fait une réussite particulière" ;
2020-11-12 16:35:51 +01:00
}
2020-11-29 18:21:34 +01:00
// Notification au MJ
2021-01-29 15:13:59 +01:00
ChatMessage . create ( { content : msg2MJ , whisper : ChatMessage . getWhisperRecipients ( "GM" ) } ) ;
2020-11-29 18:21:34 +01:00
// Et au joueur (ca pourrait être un message de tchat d'ailleurs)
2020-11-12 16:35:51 +01:00
let humideDiag = new Dialog ( {
title : "Case humide" ,
2020-11-14 03:16:03 +01:00
content : explication ,
2020-11-12 16:35:51 +01:00
buttons : {
2020-11-14 03:16:03 +01:00
choice : { icon : '<i class="fas fa-check"></i>' , label : "Fermer" , callback : ( ) => this . manageCaseHumideResult ( ) }
2020-07-25 10:29:28 +02:00
}
2020-07-17 22:04:35 +02:00
}
2020-11-12 16:35:51 +01:00
) ;
2020-07-17 22:04:35 +02:00
humideDiag . render ( true ) ;
}
}
2021-02-05 01:38:40 +01:00
isCaseHumide ( tmr ) {
if ( this . isCaseMaitrisee ( tmr . coord ) ) {
ChatMessage . create ( {
content : tmr . label + ": cette case humide est déja maitrisée grâce à votre Tête <strong>Quête des Eaux</strong>" ,
whisper : ChatMessage . getWhisperRecipients ( game . user . name )
} ) ;
return false ;
}
if ( this . actor . isCaseHumideAdditionelle ( tmr ) ) {
return true ;
}
return tmr . type == "lac" || tmr . type == "fleuve" || tmr . type == "marais" ;
}
2020-12-30 19:18:07 +01:00
/* -------------------------------------------- */
2021-01-29 15:13:59 +01:00
isReserveExtensible ( coordTMR ) {
for ( let caseTMR of this . casesSpeciales ) {
if ( caseTMR . data . specific == 'reserve_extensible' && caseTMR . data . coord == coordTMR )
2020-12-30 19:18:07 +01:00
return true ;
}
return false ;
}
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
async declencheSortEnReserve ( coordTMR ) {
2020-11-14 20:46:39 +01:00
if ( this . viewOnly ) {
return ;
}
2021-01-29 15:13:59 +01:00
let sortReserveList = TMRUtility . getSortReserveList ( this . sortReserves , coordTMR ) ;
if ( sortReserveList . length > 0 ) {
if ( this . actor . isReserveEnSecurite ( ) || this . isReserveExtensible ( coordTMR ) ) {
let msg = "Vous êtes sur une case avec un Sort en Réserve. Grâce à votre Tête <strong>Reserve en Sécurité</strong> ou <strong>Réserve Exensible</strong>, vous pouvez contrôler le déclenchement. Cliquez si vous souhaitez le déclencher : <ul>" ;
2020-12-30 19:18:07 +01:00
for ( let sortReserve of sortReserveList ) {
2021-01-29 15:13:59 +01:00
msg += "<li><a class='chat-card-button' id='sort-reserve' data-actor-id='" + this . actor . _id + "' data-tmr-coord='" + coordTMR + "' data-sort-id='" + sortReserve . sort . _id + "'>" + sortReserve . sort . name + "</a></li>" ;
2020-12-30 19:18:07 +01:00
}
msg += "</ol>" ;
2021-01-29 15:13:59 +01:00
ChatMessage . create ( {
2020-12-30 19:18:07 +01:00
content : msg ,
2021-01-29 15:13:59 +01:00
whisper : ChatMessage . getWhisperRecipients ( game . user . name )
} ) ;
2020-12-30 19:18:07 +01:00
} else {
2021-01-29 15:13:59 +01:00
await this . processSortReserve ( sortReserveList [ 0 ] ) ;
2020-12-30 19:18:07 +01:00
}
}
}
/* -------------------------------------------- */
2021-01-29 15:13:59 +01:00
lancerSortEnReserve ( coordTMR , sortId ) {
let sortReserveList = TMRUtility . getSortReserveList ( this . sortReserves , coordTMR ) ;
let sortReserve = sortReserveList . find ( sortReserve => sortReserve . sort . _id == sortId ) ;
2020-12-30 19:18:07 +01:00
//console.log("SORT RESA", sortReserveList, coordTMR, sortId, sortReserve);
2021-01-29 15:13:59 +01:00
if ( sortReserve ) {
this . processSortReserve ( sortReserve ) ;
2020-12-30 19:18:07 +01:00
} else {
2021-01-29 15:13:59 +01:00
ChatMessage . create ( {
2020-12-30 19:18:07 +01:00
content : "Une erreur est survenue : impossible de récupérer le sort en réserve demandé." ,
2021-01-29 15:13:59 +01:00
whisper : ChatMessage . getWhisperRecipients ( game . user . name )
} ) ;
2020-07-26 18:44:03 +02:00
}
}
2020-12-30 19:18:07 +01:00
/* -------------------------------------------- */
2021-01-29 15:13:59 +01:00
async processSortReserve ( sortReserve ) {
2020-12-30 19:18:07 +01:00
await this . actor . deleteSortReserve ( sortReserve ) ;
this . updateSortReserve ( ) ;
console . log ( "declencheSortEnReserve" , sortReserve )
const declenchementSort = "Vous avez déclenché le sort <strong>" + sortReserve . sort . name
2021-01-29 15:13:59 +01:00
+ "</strong> en réserve en " + sortReserve . coord + " (" + TMRUtility . getTMR ( sortReserve . coord ) . label
2020-12-30 19:18:07 +01:00
+ ") avec " + sortReserve . sort . data . ptreve _reel + " points de Rêve" ;
this . _tellToGM ( declenchementSort ) ;
this . close ( ) ;
}
2020-11-20 13:46:43 +01:00
/* -------------------------------------------- */
2021-01-29 15:13:59 +01:00
nettoyerRencontre ( ) {
if ( ! this . currentRencontre ) return ; // Sanity check
if ( this . currentRencontre . graphics ) {
2020-11-20 13:46:43 +01:00
for ( let drawRect of this . currentRencontre . graphics ) { // Suppression des dessins des zones possibles
2021-01-29 15:13:59 +01:00
this . pixiApp . stage . removeChild ( drawRect ) ;
2020-11-20 13:46:43 +01:00
}
}
this . currentRencontre = undefined ; // Nettoyage de la structure
this . rencontreState = 'aucune' ; // Et de l'état
}
2020-11-20 12:06:54 +01:00
/* -------------------------------------------- */
2021-01-29 15:13:59 +01:00
processClickPostRencontre ( coord ) {
2020-11-21 08:27:28 +01:00
if ( this . rencontreState == 'passeur' || this . rencontreState == 'messager' || this . rencontreState == 'changeur' ) {
2020-11-20 13:46:43 +01:00
console . log ( "Searching" , this . currentRencontre . locList , coord ) ;
2021-01-29 15:13:59 +01:00
let isInArea = this . currentRencontre . locList . find ( locCoord => locCoord == coord ) ;
if ( isInArea ) { // OK !
return ( this . rencontreState == 'messager' ) ? 'messager' : 'saut' ;
}
}
return "erreur" ;
2020-11-20 12:06:54 +01:00
}
2020-12-30 19:18:07 +01:00
/* -------------------------------------------- */
2021-01-29 15:13:59 +01:00
isTerreAttache ( coordTMR ) {
for ( let caseTMR of this . casesSpeciales ) {
2020-12-30 19:18:07 +01:00
if ( caseTMR . data . specific == 'attache' && caseTMR . data . coord == coordTMR ) { // Match !
return true ;
}
}
return false ;
}
2020-12-30 21:11:01 +01:00
/* -------------------------------------------- */
2021-01-29 15:13:59 +01:00
checkConnaissanceFleuve ( currentTMR , nextTMR ) {
if ( this . actor . isConnaissanceFleuve ( ) ) {
2020-12-30 21:11:01 +01:00
//console.log(currentTMR, nextTMR );
2021-01-29 15:13:59 +01:00
if ( TMRUtility . getTMR ( currentTMR ) . type == 'fleuve' && TMRUtility . getTMR ( nextTMR ) . type == 'fleuve' ) {
2020-12-30 21:11:01 +01:00
return true ;
}
}
return false ;
}
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
2021-02-05 01:38:40 +01:00
async onClickTMR ( event ) {
2020-11-14 20:46:39 +01:00
if ( this . viewOnly ) {
return ;
}
2020-11-21 23:24:00 +01:00
2020-07-14 22:19:29 +02:00
let origEvent = event . data . originalEvent ;
2021-02-05 01:38:40 +01:00
let tmrObject = event . target . tmrObject ;
let eventPos = RdDTMRDialog . _computeEventPos ( origEvent ) ;
await tmrObject . _onClickTMRPos ( eventPos ) ; // Vérifier l'état des compteurs reve/fatigue/vie
}
async _onClickTMRPos ( eventPos ) {
let currentPos = TMRUtility . convertToCellPos ( this . actor . data . data . reve . tmrpos . coord ) ;
2020-11-14 03:16:03 +01:00
2021-02-05 01:38:40 +01:00
console . log ( "deplacerDemiReve >>>>" , currentPos , eventPos ) ;
let targetCoordTMR = TMRUtility . convertToTMRCoord ( eventPos ) ;
let currentCoordTMR = TMRUtility . convertToTMRCoord ( currentPos ) ;
2020-12-30 21:11:01 +01:00
2020-11-20 12:06:54 +01:00
// Validation de la case de destination (gestion du cas des rencontres qui peuvent téléporter)
2020-11-20 13:46:43 +01:00
let deplacementType = 'erreur' ;
2021-02-05 01:38:40 +01:00
if ( this . rencontreState == 'aucune' ) { // Pas de recontre en post-processing, donc deplacement normal
if ( ! RdDTMRDialog . _horsDePortee ( currentPos , eventPos ) || this . isTerreAttache ( targetCoordTMR ) || this . checkConnaissanceFleuve ( currentCoordTMR , targetCoordTMR ) ) {
2020-11-20 13:46:43 +01:00
deplacementType = 'normal' ;
2020-11-20 12:06:54 +01:00
}
2020-07-14 22:19:29 +02:00
} else {
2021-02-05 01:38:40 +01:00
deplacementType = this . processClickPostRencontre ( targetCoordTMR ) ;
2020-11-20 12:06:54 +01:00
}
// Si le deplacement est valide
2021-01-29 15:13:59 +01:00
if ( deplacementType == 'normal' || deplacementType == 'saut' ) {
2021-02-05 01:38:40 +01:00
await this . _deplacerDemiReve ( targetCoordTMR , deplacementType ) ;
2020-11-20 13:46:43 +01:00
} else if ( deplacementType == 'messager' ) { // Dans ce cas, ouverture du lancement de sort sur la case visée
2020-11-29 18:06:19 +01:00
/ *
TODO : si la case a un sort en réserve , lancer ce sort .
Si la case est le demi - rêve , ne pas lancer de sort .
Si un lancement de sort est en cours , trouver un moyen de réafficher cette fenêtre si on essaie de lancer un sort ( ou bloquer le lancer de sort )
* /
2021-02-05 01:38:40 +01:00
await this . _messagerDemiReve ( targetCoordTMR ) ;
2021-01-29 15:13:59 +01:00
2020-11-20 12:06:54 +01:00
} else {
ui . notifications . error ( "Vous ne pouvez vous déplacer que sur des cases adjacentes à votre position ou valides dans le cas d'une rencontre" ) ;
2021-02-05 01:38:40 +01:00
console . log ( "STATUS :" , this . rencontreState , this . currentRencontre ) ;
}
this . checkQuitterTMR ( ) ;
}
async _messagerDemiReve ( targetCoordTMR ) {
await this . actor . rollUnSort ( targetCoordTMR ) ;
this . nettoyerRencontre ( ) ;
}
async _deplacerDemiReve ( targetCoord , deplacementType ) {
if ( this . currentRencontre != 'normal' ) {
this . nettoyerRencontre ( ) ;
}
let tmr = TMRUtility . getTMR ( targetCoord ) ;
await this . manageCaseSpeciale ( tmr ) ; // Gestion cases spéciales type Trou noir, etc
console . log ( "deplacerDemiReve: TMR is" , tmr , this ) ;
let tmrPos = duplicate ( this . actor . data . data . reve . tmrpos ) ;
tmrPos . coord = targetCoord ;
await this . actor . update ( { "data.reve.tmrpos" : tmrPos } ) ;
this . _updateDemiReve ( ) ;
this . nbFatigue += 1 ;
this . updateValuesDisplay ( ) ;
game . socket . emit ( "system.foundryvtt-reve-de-dragon" , {
msg : "msg_tmr_move" , data : {
actorId : this . actor . data . _id ,
tmrPos : tmrPos
}
} ) ;
if ( deplacementType == 'normal' ) { // Pas de rencontres après un saut de type passeur/changeur/...
await this . manageRencontre ( tmr , ( ) => this . postRencontre ( tmr ) ) ;
2020-07-14 22:19:29 +02:00
}
2021-02-05 01:38:40 +01:00
else {
await this . postRencontre ( tmr ) ;
}
}
2020-11-21 08:27:28 +01:00
2021-02-05 01:38:40 +01:00
async postRencontre ( tmr ) {
await this . manageCaseHumide ( tmr ) ;
await this . declencheSortEnReserve ( tmr . coord ) ;
await this . actor . checkSoufflePeage ( tmr ) ;
2020-07-05 22:35:18 +02:00
}
2020-11-14 03:16:03 +01:00
2021-01-23 23:56:43 +01:00
/* -------------------------------------------- */
2021-01-29 15:13:59 +01:00
async forceDemiRevePositionView ( coordTMR ) {
2021-02-05 01:38:40 +01:00
this . _updateDemiReve ( ) ;
2021-01-23 23:56:43 +01:00
}
2021-01-29 15:13:59 +01:00
2020-11-17 18:08:19 +01:00
/* -------------------------------------------- */
2021-01-29 15:13:59 +01:00
async forceDemiRevePosition ( coordTMR ) {
2020-11-18 18:11:01 +01:00
await this . actor . updateCoordTMR ( coordTMR ) ;
2021-02-05 01:38:40 +01:00
this . _updateDemiReve ( ) ;
let tmr = TMRUtility . getTMR ( coordTMR ) ;
this . manageCaseHumide ( tmr ) ;
await this . declencheSortEnReserve ( tmr . coord ) ;
2020-11-17 18:08:19 +01:00
}
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
async activateListeners ( html ) {
2020-07-05 21:45:25 +02:00
super . activateListeners ( html ) ;
2020-11-14 03:16:03 +01:00
2020-07-14 22:19:29 +02:00
var row = document . getElementById ( "tmrrow1" ) ;
var cell1 = row . insertCell ( 1 ) ;
2020-11-14 03:16:03 +01:00
cell1 . append ( this . pixiApp . view ) ;
2020-11-14 20:46:39 +01:00
if ( this . viewOnly ) {
html . find ( '#lancer-sort' ) . remove ( ) ;
}
else {
// Roll Sort
html . find ( '#lancer-sort' ) . click ( ( event ) => {
this . actor . rollUnSort ( this . actor . data . data . reve . tmrpos . coord ) ;
} ) ;
}
2020-11-14 03:16:03 +01:00
2020-07-14 22:19:29 +02:00
// load the texture we need
2020-11-14 03:16:03 +01:00
await this . pixiApp . loader
2020-11-17 18:10:54 +01:00
. add ( 'tmr' , 'systems/foundryvtt-reve-de-dragon/styles/img/ui/tmp_main_r1.webp' )
2020-11-14 03:16:03 +01:00
. add ( 'demi-reve' , "icons/svg/sun.svg" )
. load ( ( loader , resources ) => {
// This creates a texture from a TMR image
const mytmr = new PIXI . Sprite ( resources . tmr . texture ) ;
// Setup the position of the TMR
mytmr . x = 0 ;
mytmr . y = 0 ;
mytmr . width = 720 ;
mytmr . height = 860 ;
// Rotate around the center
mytmr . anchor . x = 0 ;
mytmr . anchor . y = 0 ;
mytmr . interactive = true ;
mytmr . buttonMode = true ;
mytmr . tmrObject = this ;
2020-11-14 20:46:39 +01:00
if ( ! this . viewOnly ) {
2021-02-05 01:38:40 +01:00
mytmr . on ( 'pointerdown' , this . onClickTMR ) ;
2020-11-14 20:46:39 +01:00
}
2020-11-14 03:16:03 +01:00
this . pixiApp . stage . addChild ( mytmr ) ;
this . _addDemiReve ( ) ;
this . displayPreviousRencontres ( ) ;
this . displaySortReserve ( ) ;
2020-12-30 18:12:01 +01:00
this . displaySpecificCase ( ) ;
2020-11-14 03:16:03 +01:00
} ) ;
2020-11-14 20:46:39 +01:00
if ( this . viewOnly ) {
return ;
}
2020-12-30 15:56:17 +01:00
2020-12-30 21:11:01 +01:00
// Gestion du cout de montée en points de rêve
2021-02-05 01:38:40 +01:00
let reveCout = ( this . tmrdata . isRapide && ! this . actor . checkTeteDeplacementAccelere ( ) ) ? - 2 : - 1 ;
2020-12-30 21:11:01 +01:00
reveCout -= this . actor . checkMonteeLaborieuse ( ) ;
2021-01-29 15:13:59 +01:00
await this . actor . reveActuelIncDec ( reveCout ) ;
2020-12-30 21:11:01 +01:00
// Le reste...
2020-07-17 22:04:35 +02:00
this . updateValuesDisplay ( ) ;
2021-02-05 01:38:40 +01:00
let tmr = TMRUtility . getTMR ( this . actor . data . data . reve . tmrpos . coord ) ;
await this . manageRencontre ( tmr , ( ) => {
this . postRencontre ( tmr ) ;
this . nbFatigue = this . actor . getTMRFatigue ( ) ;
this . actor . displayTMRQueueSouffleInformation ( ) ;
} ) ;
2020-11-14 03:16:03 +01:00
}
/* -------------------------------------------- */
2021-02-05 01:38:40 +01:00
static _computeEventPos ( origEvent ) {
2020-11-14 03:16:03 +01:00
let canvasRect = origEvent . target . getBoundingClientRect ( ) ;
let x = origEvent . clientX - canvasRect . left ;
let y = origEvent . clientY - canvasRect . top ;
let cellx = Math . floor ( x / tmrConstants . cellw ) ; // [From 0 -> 12]
y -= ( cellx % 2 == 0 ) ? tmrConstants . col1 _y : tmrConstants . col2 _y ;
let celly = Math . floor ( y / tmrConstants . cellh ) ; // [From 0 -> 14]
2021-02-05 01:38:40 +01:00
return { x : cellx , y : celly } ;
2020-11-14 03:16:03 +01:00
}
2020-11-17 18:08:19 +01:00
/* -------------------------------------------- */
2021-02-05 01:38:40 +01:00
static _horsDePortee ( origin , target ) {
return Math . abs ( target . x - origin . x ) > 1
|| Math . abs ( target . y - origin . y ) > 1
|| ( origin . y == 0 && target . y > origin . y && target . x != origin . x && origin . x % 2 == 0 )
|| ( target . y == 0 && target . y < origin . y && target . x != origin . x && origin . x % 2 == 1 ) ;
2020-11-14 03:16:03 +01:00
}
2020-11-17 18:08:19 +01:00
/* -------------------------------------------- */
2020-11-14 03:16:03 +01:00
_tokenRencontre ( rencontre ) {
let sprite = new PIXI . Graphics ( ) ;
sprite . beginFill ( 0x767610 , 0.6 ) ;
sprite . drawCircle ( 0 , 0 , 6 ) ;
sprite . endFill ( ) ;
sprite . decallage = {
x : ( tmrConstants . cellw / 2 ) - 16 ,
y : 16 - ( tmrConstants . cellh / 2 )
} ;
return { sprite : sprite , rencontre : rencontre , coordTMR : ( ) => rencontre . coord } ;
}
2020-12-30 19:18:07 +01:00
/* -------------------------------------------- */
2021-01-29 15:13:59 +01:00
_tokenTrouNoir ( coord ) {
2020-12-30 19:18:07 +01:00
let sprite = new PIXI . Graphics ( ) ;
sprite . beginFill ( 0x050505 , 0.8 ) ;
sprite . drawCircle ( 0 , 0 , ( tmrConstants . cellw / 2 ) - 2 ) ;
sprite . endFill ( ) ;
sprite . decallage = {
x : 0 ,
y : 2
}
return { sprite : sprite , coordTMR : ( ) => coord }
}
2020-12-30 19:27:35 +01:00
/* -------------------------------------------- */
2021-01-29 15:13:59 +01:00
_tokenDebordement ( coord ) {
2020-12-30 19:27:35 +01:00
let sprite = new PIXI . Graphics ( ) ;
sprite . beginFill ( 0x0101FE , 0.3 ) ;
sprite . drawCircle ( 0 , 0 , ( tmrConstants . cellw / 2 ) - 2 ) ;
sprite . endFill ( ) ;
sprite . decallage = {
x : 0 ,
y : 2
}
return { sprite : sprite , coordTMR : ( ) => coord }
}
2020-12-30 21:11:01 +01:00
/* -------------------------------------------- */
_tokenMaitrisee ( coord ) {
let sprite = new PIXI . Graphics ( ) ;
sprite . beginFill ( 0x1010F0 , 0.8 ) ;
sprite . drawCircle ( 0 , 0 , 6 ) ;
sprite . endFill ( ) ;
sprite . decallage = {
x : 16 - ( tmrConstants . cellw / 2 ) ,
y : 16 - ( tmrConstants . cellh / 2 )
}
return { sprite : sprite , coordTMR : ( ) => coord }
}
2020-12-30 19:18:07 +01:00
/* -------------------------------------------- */
_tokenTerreAttache ( coord ) {
let sprite = new PIXI . Graphics ( ) ;
sprite . beginFill ( 0x10F010 , 0.8 ) ;
sprite . drawCircle ( 0 , 0 , 6 ) ;
sprite . endFill ( ) ;
sprite . decallage = {
x : 16 - ( tmrConstants . cellw / 2 ) ,
y : 16 - ( tmrConstants . cellh / 2 )
2020-12-30 18:12:01 +01:00
}
2020-12-30 19:18:07 +01:00
return { sprite : sprite , coordTMR : ( ) => coord }
}
2021-01-29 15:13:59 +01:00
2020-11-17 18:08:19 +01:00
/* -------------------------------------------- */
2020-11-14 03:16:03 +01:00
_tokenSortEnReserve ( sort ) {
let sprite = new PIXI . Graphics ( ) ;
sprite . beginFill ( 0x101010 , 0.8 ) ;
sprite . drawCircle ( 0 , 0 , 6 ) ;
sprite . endFill ( ) ;
sprite . decallage = {
x : 16 - ( tmrConstants . cellw / 2 ) ,
y : 16 - ( tmrConstants . cellh / 2 )
}
2020-11-14 20:46:39 +01:00
return { sprite : sprite , sort : sort , coordTMR : ( ) => sort . coord }
2020-11-14 03:16:03 +01:00
}
2020-11-17 18:08:19 +01:00
/* -------------------------------------------- */
2020-11-14 03:16:03 +01:00
_tokenDemiReve ( ) {
let texture = PIXI . utils . TextureCache [ 'demi-reve' ] ;
let sprite = new PIXI . Sprite ( texture ) ;
sprite . width = tmrConstants . cellw * 0.7 ;
sprite . height = tmrConstants . cellh * 0.7 ;
sprite . anchor . set ( 0.5 ) ;
sprite . tint = 0x00FFEE ;
return { sprite : sprite , actor : this . actor , coordTMR : ( ) => this . actor . data . data . reve . tmrpos . coord }
}
/* -------------------------------------------- */
_addDemiReve ( ) {
this . demiReve = this . _tokenDemiReve ( ) ;
this . _setTokenPosition ( this . demiReve ) ;
this . pixiApp . stage . addChild ( this . demiReve . sprite ) ;
}
2020-11-17 18:08:19 +01:00
/* -------------------------------------------- */
2021-02-05 01:38:40 +01:00
_updateDemiReve ( ) {
this . _setTokenPosition ( this . demiReve ) ;
2020-11-14 03:16:03 +01:00
}
2020-11-17 18:08:19 +01:00
/* -------------------------------------------- */
2020-11-20 12:06:54 +01:00
/** Retourne les coordonnées x, h, w, h du rectangle d'une case donnée */
2021-01-29 15:13:59 +01:00
_getCaseRectangleCoord ( coord ) {
2021-02-05 01:38:40 +01:00
let coordXY = TMRUtility . convertToCellPos ( coord ) ;
2020-11-20 12:06:54 +01:00
let decallagePairImpair = ( coordXY . x % 2 == 0 ) ? tmrConstants . col1 _y : tmrConstants . col2 _y ;
2021-01-29 15:13:59 +01:00
let x = tmrConstants . gridx + ( coordXY . x * tmrConstants . cellw ) - ( tmrConstants . cellw / 2 ) ;
let y = tmrConstants . gridy + ( coordXY . y * tmrConstants . cellh ) - ( tmrConstants . cellh / 2 ) + decallagePairImpair ;
return { x : x , y : y , w : tmrConstants . cellw , h : tmrConstants . cellh }
2020-11-20 12:06:54 +01:00
}
/* -------------------------------------------- */
2020-11-14 03:16:03 +01:00
_setTokenPosition ( token ) {
2021-02-05 01:38:40 +01:00
let coordXY = TMRUtility . convertToCellPos ( token . coordTMR ( ) ) ;
2020-11-14 03:16:03 +01:00
let decallagePairImpair = ( coordXY . x % 2 == 0 ) ? tmrConstants . col1 _y : tmrConstants . col2 _y ;
let dx = ( token . sprite . decallage == undefined ) ? 0 : token . sprite . decallage . x ;
let dy = ( token . sprite . decallage == undefined ) ? 0 : token . sprite . decallage . y ;
token . sprite . x = tmrConstants . gridx + ( coordXY . x * tmrConstants . cellw ) + dx ;
token . sprite . y = tmrConstants . gridy + ( coordXY . y * tmrConstants . cellh ) + dy + decallagePairImpair ;
}
2020-11-17 18:08:19 +01:00
/* -------------------------------------------- */
2020-11-14 03:16:03 +01:00
_removeTokens ( filter ) {
const tokensToRemove = this . allTokens . filter ( filter ) ;
for ( let token of tokensToRemove ) {
this . pixiApp . stage . removeChild ( token . sprite ) ;
}
}
2020-11-17 18:08:19 +01:00
/* -------------------------------------------- */
2020-11-14 03:16:03 +01:00
_trackToken ( token ) {
this . allTokens . push ( token )
this . _setTokenPosition ( token ) ;
this . pixiApp . stage . addChild ( token . sprite ) ;
2020-07-05 21:45:25 +02:00
}
2020-11-18 23:49:05 +01:00
2020-07-05 21:45:25 +02:00
}
2020-11-14 03:16:03 +01:00