Initiative from PHASE OK
This commit is contained in:
@@ -10,21 +10,57 @@ export class SoSCombat extends Combat {
|
||||
async nextRound() {
|
||||
console.log("NEXT ROUND !!!!");
|
||||
|
||||
if ( game.user.isGM ) {
|
||||
ChatMessage.create( { content: `New round !! Click on the button below to declare your actions for round ${this.round} !<br>
|
||||
<a class='chat-card-button' id='button-declare-actions' data-combat-id='${this._id} data-round='${this.round}'>Declare actions</a>`,
|
||||
whisper: game.users.map(user => user.data._id) } );
|
||||
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.userId] = actionConf;
|
||||
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") ] } );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -4,12 +4,14 @@ import { SoSUtility } from "./sos-utility.js";
|
||||
export class SoSDialogCombatActions extends Dialog {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async create( combatId, round ) {
|
||||
static async create( combatId, combatantId, round, uniqId ) {
|
||||
|
||||
let combatActions = {
|
||||
actionsList: await SoSUtility.loadCompendium( 'foundryvtt-shadows-over-sol.combat-actions' ),
|
||||
actionPoints: SoSUtility.fillRange(0, 6),
|
||||
combatId: combatId,
|
||||
combatantId: combatantId,
|
||||
uniqId: uniqId,
|
||||
round: round
|
||||
}
|
||||
for ( let i=0; i<combatActions.actionsList.length; i++) {
|
||||
@@ -54,13 +56,26 @@ export class SoSDialogCombatActions extends Dialog {
|
||||
let action2 = duplicate(this.combatActions.actionsList[action2Index]._id);
|
||||
let action1Index = $('#action1').val();
|
||||
let action1 = duplicate(this.combatActions.actionsList[action1Index]._id);
|
||||
|
||||
game.socket.emit("system.foundryvtt-reve-de-dragon", {
|
||||
name: "msg_declare_actions", data: {
|
||||
userId: game.userId,
|
||||
phaseArray: [ action1, action2, action3],
|
||||
remainingAP: ap
|
||||
} } );
|
||||
|
||||
let msgdata = {
|
||||
combatId: this.combatActions.combatId,
|
||||
combatantId: this.combatActions.combatantId,
|
||||
uniqId: this.combatActions.uniqId,
|
||||
userId: game.userId,
|
||||
phaseArray: [ action1, action2, action3],
|
||||
remainingAP: ap
|
||||
}
|
||||
|
||||
if ( game.user.isGM ) {
|
||||
let combat = game.combats.get( this.combatActions.combatId ); // Get the associated combat
|
||||
combat.setupActorActions( msgdata );
|
||||
} else {
|
||||
game.socket.emit("system.foundryvtt-reve-de-dragon", {
|
||||
name: "msg_declare_actions", data: msgdata } );
|
||||
}
|
||||
// Delete message !
|
||||
const toDelete = game.messages.filter(it => it.data.content.includes( this.combatActions.uniqId ));
|
||||
toDelete.forEach(it => it.delete());
|
||||
} else {
|
||||
ui.notifications.warn("Action Points are below 0 ! Please check your phases !");
|
||||
}
|
||||
@@ -68,6 +83,7 @@ export class SoSDialogCombatActions extends Dialog {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
validateActions( html ) {
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
@@ -18,16 +18,6 @@ import { SoSCombat } from "./sos-combat.js";
|
||||
/* Foundry VTT Initialization */
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/************************************************************************************/
|
||||
const _patch_initiative = () => {
|
||||
Combat.prototype.rollInitiative = async function (
|
||||
ids,
|
||||
formula = undefined,
|
||||
messageOptions = {}
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************************/
|
||||
Hooks.once("init", async function () {
|
||||
console.log(`Initializing Shadows over Sol System`);
|
||||
@@ -40,7 +30,7 @@ Hooks.once("init", async function () {
|
||||
/* -------------------------------------------- */
|
||||
// Set an initiative formula for the system
|
||||
CONFIG.Combat.initiative = {
|
||||
formula: "1+(1d6/10)",
|
||||
formula: "1d3",
|
||||
decimals: 2
|
||||
};
|
||||
|
||||
@@ -68,9 +58,6 @@ Hooks.once("init", async function () {
|
||||
SoSUtility.registerChatCallbacks(html);
|
||||
});
|
||||
|
||||
// Patch the initiative formula
|
||||
_patch_initiative();
|
||||
|
||||
});
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
@@ -64,8 +64,10 @@ import { SoSDialogCombatActions } from "./sos-dialog-combat-actions.js";
|
||||
static async openDeclareActions( event) {
|
||||
event.preventDefault();
|
||||
let round = event.currentTarget.attributes['data-round'].value;
|
||||
let combatantId = event.currentTarget.attributes['data-combatant-id'].value;
|
||||
let combatId = event.currentTarget.attributes['data-combat-id'].value;
|
||||
let d = await SoSDialogCombatActions.create( combatId, round );
|
||||
let uniqId = event.currentTarget.attributes['data-uniq-id'].value;
|
||||
let d = await SoSDialogCombatActions.create( combatId, combatantId, round, uniqId );
|
||||
d.render(true);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user