From 1f0506f5c27abc49e7895e4f6ae22181301ca4c8 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Sun, 17 Jul 2022 20:53:25 +0200 Subject: [PATCH] v10 compatibility --- module/actor.js | 8 +- module/sos-combat.js | 150 +++++++++++++++------------- module/sos-dialog-combat-actions.js | 2 +- module/sos-gm-deck.js | 2 +- 4 files changed, 86 insertions(+), 76 deletions(-) diff --git a/module/actor.js b/module/actor.js index 2cfc82f..6978a34 100644 --- a/module/actor.js +++ b/module/actor.js @@ -335,7 +335,7 @@ export class SoSActor extends Actor { totalWounds: this.system.scores.wound.value } let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/chat-character-death.html', woundData ); - ChatMessage.create( { content: html, whisper: [ChatMessage.getWhisperRecipients(this.name), ChatMessage.getWhisperRecipients("GM") ] } ); + ChatMessage.create( { content: html, whisper: ChatMessage.getWhisperRecipients(this.name).concat(ChatMessage.getWhisperRecipients("GM") ) } ) } } @@ -369,7 +369,7 @@ export class SoSActor extends Actor { totalWounds: this.system.scores.wound.value } let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/chat-damage-consequence.html', woundData ); - ChatMessage.create( { content: html, whisper: ChatMessage.getWhisperRecipients(this.name).concat(ChatMessage.getWhisperRecipients("GM")) } ); + ChatMessage.create( { content: html, whisper: ChatMessage.getWhisperRecipients(this.name).concat(ChatMessage.getWhisperRecipients("GM")) } ) this.checkDeath(); } @@ -399,7 +399,7 @@ export class SoSActor extends Actor { async applyWounds( flipData ) { if ( flipData.damageStatus == 'no_damage') { let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/chat-nodamage-taken.html', flipData ); - ChatMessage.create( { content: html, whisper: [ChatMessage.getWhisperRecipients(this.name), ChatMessage.getWhisperRecipients("GM") ] } ); + ChatMessage.create( { content: html, whisper: ChatMessage.getWhisperRecipients(this.name).concat(ChatMessage.getWhisperRecipients("GM")) } ); return; } @@ -437,7 +437,7 @@ export class SoSActor extends Actor { flipData.currentWounds = sumWound; flipData.totalWounds = this.system.scores.wound.value; let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/chat-damage-taken.html', flipData ); - ChatMessage.create( { content: html, whisper: [ChatMessage.getWhisperRecipients(this.name), ChatMessage.getWhisperRecipients("GM") ] } ); + ChatMessage.create( { content: html, whisper: ChatMessage.getWhisperRecipients(this.name).concat(ChatMessage.getWhisperRecipients("GM")) } ); this.checkDeath(); } diff --git a/module/sos-combat.js b/module/sos-combat.js index f35d452..24c5db7 100644 --- a/module/sos-combat.js +++ b/module/sos-combat.js @@ -5,26 +5,30 @@ import { SoSDialogCombatActions } from "./sos-dialog-combat-actions.js"; /* -------------------------------------------- */ export class SoSCombat extends Combat { - + /* -------------------------------------------- */ requestActions() { - if ( game.user.isGM && !this.actionsRequested) { - console.log("REQUEST ACTIONS !!!"); + if (game.user.isGM && !this.actionsRequested) { + console.log("REQUEST ACTIONS !!!") this.actionsRequested = true; this.phaseSetup = {}; // Reset each new round/update - for( let combatant of this.combatants) { - this.setInitiative(combatant._id, -1 ); // Reset init - let uniq = randomID(16); + for (let combatant of this.combatants) { + this.setInitiative(combatant.id, -1); // Reset init + let uniq = randomID(16) const name = combatant.actor ? combatant.actor.name : combatant.name; - if ( combatant.players[0]) { + if (combatant.players && combatant.players[0]) { // A player controls this combatant -> message ! - ChatMessage.create( { content: `New round ! Click on the button below to declare the actions of ${name} for round ${this.round} !
- Declare actions`, - whisper: [ combatant.players[0].data._id] } ); + ChatMessage.create({ + content: `New round ! Click on the button below to declare the actions of ${name} for round ${this.round} !
+ Declare actions`, + whisper: [combatant.players[0].id] + }); } else { - ChatMessage.create( { content: `New round ! Click on the button below to declare the actions of ${name} for round ${this.round} !
- Declare actions`, - whisper: [ ChatMessage.getWhisperRecipients("GM") ] } ); + ChatMessage.create({ + content: `New round ! Click on the button below to declare the actions of ${name} for round ${this.round} !
+ Declare actions`, + whisper: ChatMessage.getWhisperRecipients("GM"), + }); } } } @@ -39,56 +43,61 @@ export class SoSCombat extends Combat { /* -------------------------------------------- */ gotoNextTurn() { this.phaseNumber -= 1; - if ( this.phaseNumber <= 0) { + if (this.phaseNumber <= 0) { this.applyConsequences(); this.nextRound(); // Auto-switch to next round - } else { + } else { this.nextTurn(); } } /* -------------------------------------------- */ async nextTurn() { - console.log("Going to phase !", this.phaseNumber ); + console.log("Going to phase !", this.phaseNumber); // Get all actions for this phase let phaseIndex = this.phaseNumber - 1; let actionList = []; let actionMsg = `

Actions for phase ${this.phaseNumber}

`; - for (let combatantId in this.phaseSetup ) { + for (let combatantId in this.phaseSetup) { let actionData = this.phaseSetup[combatantId]; - if ( actionData.phaseArray[phaseIndex].name != 'No Action' ) { - let combatant = this.combatants.find( comb => comb._id == actionData.combatantId); - const name = combatant.actor ? combatant.actor.data.name : combatant.name; - actionList.push( { combatant: combatant, - action: actionData.phaseArray[phaseIndex], - isDone: false - }); + if (actionData.phaseArray[phaseIndex].name != 'No Action') { + let combatant = this.combatants.find(comb => comb._id == actionData.combatantId); + const name = combatant.actor ? combatant.actor.name : combatant.name; + actionList.push({ + combatant: combatant, + action: actionData.phaseArray[phaseIndex], + isDone: false + }); actionMsg += `
${name} is going to : ${actionData.phaseArray[phaseIndex].name}`; } } - if ( actionList.length == 0) { + if (actionList.length == 0) { actionMsg += "
No actions for the phase !"; this.gotoNextTurn(); } // Display a nice message - ChatMessage.create( { content: actionMsg }); + ChatMessage.create({ content: actionMsg }); // Now push specific messages - for ( let action of actionList) { + for (let action of actionList) { let uniq = randomID(16); action.uniqId = uniq; // Easy tracking with chat messages - const name = action.combatant.actor ? action.combatant.actor.data.name : action.combatant.name; - if ( action.combatant.players[0]) { + const name = action.combatant.actor ? action.combatant.actor.name : action.combatant.name; + if (action.combatant.players[0]) { // A player controls this combatant -> message ! - ChatMessage.create( { content: `Phase ${this.phaseNumber} ! ${name} must perform a ${action.action.name} action. + ChatMessage.create({ + content: `Phase ${this.phaseNumber} ! ${name} must perform a ${action.action.name} action. When done, click on the button below to close the action. - Action is done !`, - whisper: [ action.combatant.players[0].data._id] } ); + Action is done !`, + whisper: [action.combatant.players[0].id] + }); } else { - ChatMessage.create( { content: `Phase ${this.phaseNumber} ! ${name} must perform a ${action.action.name} action.
+ ChatMessage.create({ + content: `Phase ${this.phaseNumber} ! ${name} must perform a ${action.action.name} action.
When done, click on the button below to close the action. - Action is done !`, - whisper: [ ChatMessage.getWhisperRecipients("GM") ] } ); + Action is done !`, + whisper: ChatMessage.getWhisperRecipients("GM") + }); } } // Save for easy access @@ -96,28 +105,28 @@ export class SoSCombat extends Combat { } /* -------------------------------------------- */ - applyConsequences( ) { - if (game.user.isGM ) { - for( let combatant of this.combatants) { + applyConsequences() { + if (game.user.isGM) { + for (let combatant of this.combatants) { if (!combatant.actor) continue; // Can't check tokens without assigned actors, Maybe print chat message about bleeding happening so that the GM can manually track this? - let bleeding = combatant.actor.data.items.find( item => item.type == 'consequence' && item.name == 'Bleeding'); - combatant.actor.applyConsequenceWound( bleeding.data.severity, "bleeding" ); + let bleeding = combatant.actor.items.find(item => item.type == 'consequence' && item.name == 'Bleeding'); + combatant.actor.applyConsequenceWound(bleeding.system.severity, "bleeding"); } } } /* -------------------------------------------- */ - closeAction( uniqId) { + closeAction(uniqId) { // Delete message ! - const toDelete = game.messages.filter(it => it.data.content.includes( uniqId )); - toDelete.forEach(it => it.delete()); + const toDelete = game.messages.filter(it => it.content.includes(uniqId)); + toDelete.forEach(it => it.delete()) - let action = this.currentActions.find( _action => _action.uniqId == uniqId ); + let action = this.currentActions.find(_action => _action.uniqId == uniqId); if (action) { action.isDone = true; - let filtered = this.currentActions.filter( _action => action.isDone ); - if ( filtered.length == this.currentActions.length) { // All actions closed ! + let filtered = this.currentActions.filter(_action => action.isDone); + if (filtered.length == this.currentActions.length) { // All actions closed ! console.log("Going next turn !!!"); this.gotoNextTurn(); } @@ -125,22 +134,22 @@ export class SoSCombat extends Combat { } /* -------------------------------------------- */ - getPhaseRank( actionConf) { - for (let i=2; i>=0; i--) { + getPhaseRank(actionConf) { + for (let i = 2; i >= 0; i--) { let action = actionConf.phaseArray[i]; if (action.name != "No Action") { - return i+1; + return i + 1; } } return 0; } /* -------------------------------------------- */ - getAPFromActor( actorId ) { - for( let combatant of this.combatants) { + getAPFromActor(actorId) { + for (let combatant of this.combatants) { //console.log(combatant); - if ( combatant.actor.data._id == actorId ) { - let phase = this.phaseSetup[combatant._id]; + if (combatant.actor.id == actorId) { + let phase = this.phaseSetup[combatant.id]; return phase.remainingAP; } } @@ -148,42 +157,43 @@ export class SoSCombat extends Combat { } /* -------------------------------------------- */ - decreaseAPFromActor( actorId ) { - for( let combatant of this.combatants) { + decreaseAPFromActor(actorId) { + for (let combatant of this.combatants) { //console.log(combatant); - if ( combatant.actor.data._id == actorId ) { - let phase = this.phaseSetup[combatant._id]; + if (combatant.actor.id == actorId) { + let phase = this.phaseSetup[combatant.id]; phase.remainingAP -= 1; - if ( phase.remainingAP < 0 ) phase.remainingAP = 0; + if (phase.remainingAP < 0) phase.remainingAP = 0; } } } - + /* -------------------------------------------- */ async setupActorActions(actionConf) { console.log("Setting combat for phase : ", actionConf, actionConf.uniqId); // Delete message ! - const toDelete = game.messages.filter(it => it.data.content.includes( actionConf.uniqId )); - console.log("MESSAGE : ", toDelete); + const toDelete = game.messages.filter(it => it.content.includes(actionConf.uniqId)); toDelete.forEach(it => it.delete()); - if ( !this.phaseSetup) this.phaseSetup = {}; // Opportunistic init - + if (!this.phaseSetup) this.phaseSetup = {}; // Opportunistic init + // Keep track this.phaseSetup[actionConf.combatantId] = actionConf; - console.log( this.combatants ); + console.log(this.combatants); //let combatant = this.combatants.find( comb => comb._id == actionConf.combatantId); - await this.setInitiative( actionConf.combatantId, this.getPhaseRank( actionConf ) ); + await this.setInitiative(actionConf.combatantId, this.getPhaseRank(actionConf)); let actionsDone = true - for( let combatant of this.combatants) { - if ( combatant.initiative == -1 ) actionsDone = false; + for (let combatant of this.combatants) { + if (combatant.initiative == -1) actionsDone = false; } - if ( actionsDone ) { + if (actionsDone) { this.actionsRequested = false; - ChatMessage.create( { content: `Action declaration has been completed ! Now proceeding with actions.`, - whisper: [ ChatMessage.getWhisperRecipients("GM") ] } ); + ChatMessage.create({ + content: `Action declaration has been completed ! Now proceeding with actions.`, + whisper: ChatMessage.getWhisperRecipients("GM") + }) this.phaseNumber = 3; this.nextTurn(); } diff --git a/module/sos-dialog-combat-actions.js b/module/sos-dialog-combat-actions.js index 3fba332..823e539 100644 --- a/module/sos-dialog-combat-actions.js +++ b/module/sos-dialog-combat-actions.js @@ -12,7 +12,7 @@ export class SoSDialogCombatActions extends Dialog { actionPoints: SoSUtility.fillRange(0, 6), combatId: combatId, combatantId: combatantId, - combatantsList: combat.data.combatants, + combatantsList: combat.combatants, uniqId: uniqId, round: round } diff --git a/module/sos-gm-deck.js b/module/sos-gm-deck.js index 5320885..915a210 100644 --- a/module/sos-gm-deck.js +++ b/module/sos-gm-deck.js @@ -60,7 +60,7 @@ export class SoSGMDeck extends Dialog { let cardPath = `systems/foundryvtt-shadows-over-sol/img/cards/${card.cardName}.webp`; let cardData = { card: card, cardPath: cardPath }; let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/chat-card.html', cardData ); - ChatMessage.create( { content: html, whisper: [ ChatMessage.getWhisperRecipients("GM") ] }); + ChatMessage.create( { content: html, whisper: ChatMessage.getWhisperRecipients("GM") } ); //dialog.onFlipClose(); }