67 lines
2.8 KiB
JavaScript
67 lines
2.8 KiB
JavaScript
import { SoSCardDeck } from "./sos-card-deck.js";
|
|
import { SoSUtility } from "./sos-utility.js";
|
|
import { SoSFlipDialog } from "./sos-flip-dialog.js";
|
|
import { SoSDialogCombatActions } from "./sos-dialog-combat-actions.js";
|
|
|
|
/* -------------------------------------------- */
|
|
export class SoSCombat extends Combat {
|
|
|
|
/* -------------------------------------------- */
|
|
async nextRound() {
|
|
console.log("NEXT ROUND !!!!");
|
|
|
|
if ( game.user.isGM ) {
|
|
for( let combatant of this.combatants) {
|
|
let uniq = randomID(16);
|
|
if ( combatant.players[0]) {
|
|
// A player controls this combatant -> message !
|
|
ChatMessage.create( { content: `New round ! Click on the button below to declare the actions of ${combatant.actor.data.name} for round ${this.round} !<br>
|
|
<a class='chat-card-button' id='button-declare-actions' data-uniq-id='${uniq}' data-combatant-id='${combatant._id}' data-combat-id='${this._id}' data-round='${this.round}'>Declare actions</a>`,
|
|
whisper: [ combatant.players[0].data._id] } );
|
|
} else {
|
|
ChatMessage.create( { content: `New round ! Click on the button below to declare the actions of ${combatant.actor.data.name} for round ${this.round} !<br>
|
|
<a class='chat-card-button' id='button-declare-actions' data-uniq-id='${uniq}' data-combatant-id='${combatant._id}' data-combat-id='${this._id}' data-round='${this.round}'>Declare actions</a>`,
|
|
whisper: [ ChatMessage.getWhisperRecipients("GM") ] } );
|
|
}
|
|
}
|
|
}
|
|
super.nextRound();
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
getPhaseRank( actionConf) {
|
|
for (let i=2; i>=0; i--) {
|
|
let action = actionConf.phaseArray[i];
|
|
if (action.name != "No Action") {
|
|
console.log("Init is : ", i+1);
|
|
return i+1;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
setupActorActions(actionConf) {
|
|
console.log("Setting combat for phase : ", actionConf);
|
|
|
|
if ( !this.phaseSetup) this.phaseSetup = []; // Opportunistic init
|
|
if ( !this.phaseSetup[this.round] ) this.phaseSetup[this.round] = {}; // Bis
|
|
|
|
// Keep track
|
|
this.phaseSetup[this.round][actionConf.combatantId] = actionConf;
|
|
console.log( this.combatants);
|
|
let combatant = this.combatants.find( comb => comb._id == actionConf.combatantId);
|
|
this.setInitiative( actionConf.combatantId, this.getPhaseRank( actionConf ) );
|
|
|
|
let actionsDone = true
|
|
for( let combatant of this.combatants) {
|
|
if ( !combatant.initiative ) actionsDone = false;
|
|
}
|
|
if ( actionsDone ) {
|
|
ChatMessage.create( { content: `Action phase has been completed ! Now proceeding with actions.`,
|
|
whisper: [ ChatMessage.getWhisperRecipients("GM") ] } );
|
|
}
|
|
}
|
|
|
|
}
|