Fixes from 29th of june

This commit is contained in:
2023-06-30 21:11:29 +02:00
parent b535a86116
commit 297c94adb7
8 changed files with 109 additions and 41 deletions

View File

@@ -185,6 +185,13 @@ export class Hero6ActorSheet extends ActorSheet {
this.actor.rollWeapon(skillId)
});
html.find('.hold-action').click((event) => {
this.actor.holdAction()
});
html.find('.abort-action').click((event) => {
this.actor.abortAction()
});
html.find('.lock-unlock-sheet').click((event) => {
this.options.editScore = !this.options.editScore;
this.render(true);

View File

@@ -385,11 +385,39 @@ export class Hero6Actor extends Actor {
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
}
}
/* -------------------------------------------- */
async cleanCombat() {
await this.setFlag("world", "hold-action", false)
await this.setFlag("world", "abort-action", false)
}
async holdAction() {
if (this.getFlag("world", "hold-action")) {
await this.setFlag("world", "hold-action", false)
} else {
await this.setFlag("world", "hold-action", true)
}
game.combat.rebuildInitiative()
}
async abortAction() {
if (this.getFlag("world", "abort-action")) {
await this.setFlag("world", "abort-action", false)
} else {
await this.setFlag("world", "abort-action", true)
}
game.combat.rebuildInitiative()
}
getHoldAction() {
return this.getFlag("world", "hold-action")
}
getAbortAction() {
return this.getFlag("world", "abort-action")
}
/* -------------------------------------------- */
hasPhase(segmentNumber) {
let index = Math.min(Math.max(this.system.characteristics.spd.value, 1), 12) // Security bounds
let phases = __speed2Segments[index]
console.log("index", segmentNumber, index, phases, phases.includes(segmentNumber))
return phases.includes(segmentNumber)
}
/* -------------------------------------------- */

View File

@@ -16,47 +16,33 @@ export class Hero6CombatTracker extends CombatTracker {
export class Hero6Combat extends Combat {
/* -------------------------------------------- */
static init() {
static ready() {
Hooks.on("getCombatTrackerEntryContext", (html, options) => { Hero6Combat.pushMenuOptions(html, options); });
game.combat.settings.resource = "characteristics.spd.value";
}
/* -------------------------------------------- */
static pushMenuOptions(html, options) {
console.log(">>>>>>>>>>>>>>>>>>>>>>>< MENU OPTIONS!!!!!")
let newOpt
for (let i = 0; i < options.length; i++) {
let option = options[i];
if (option.name == 'COMBAT.CombatantReroll') { // Replace !
option.name = "Hold action";
option.name = "Hold/Unhold action";
option.condition = true;
option.icon = '<i class="far fa-question-circle"></i>';
option.callback = target => {
Hero6Combat.holdAction(target.data('combatant-id'));
}
newOpt = duplicate(option)
//newOpt = duplicate(option)
}
}
newOpt.name = "Abort action"
newOpt.callback = target => {
Hero6Combat.abortAction(target.data('combatant-id'));
}
options.push( newOpt)
//options.push(newOpt)
}
/* -------------------------------------------- */
static holdAction(combatantId) {
console.log("Combatant HOLD : ", combatantId)
const combatant = game.combat.combatants.get(combatantId)
combatant.setFlag("world", "hero6-hold-action", true)
combatant.update({name: combatant.name + " (H)"})
console.log("HOLD", combatant)
}
/* -------------------------------------------- */
static abortAction(html, combatantId) {
console.log("Combatant ABORT : ", combatantId);
const combatant = game.combat.combatants.get(combatantId);
combatant.setFlag("world", "hero6-abort-action", true)
combatant.update({name: combatant.name + " (A)"})
console.log("ABORT", combatant)
combatant.actor.holdAction()
}
/* -------------------------------------------- */
@@ -68,27 +54,69 @@ export class Hero6Combat extends Combat {
}
/* -------------------------------------------- */
async computeInitiative(c) {
let id = c._id || c.id
if (c.actor.hasPhase(this.segmentNumber)) {
let baseInit = c.actor ? c.actor.getBaseInit() : - 1;
await this.updateEmbeddedDocuments("Combatant", [{ _id: id, initiative: baseInit }]);
} else {
await this.updateEmbeddedDocuments("Combatant", [{ _id: id, initiative: -1, visible: false, active: false }]);
async startCombat() {
game.combat.settings.resource = "characteristics.spd.value";
let updList = []
for (let c of this.combatants) {
this.computeInitiative(c, updList)
await c.actor.cleanCombat()
}
console.log("Combatant", c)
if (updList.length > 0) {
await this.updateEmbeddedDocuments("Combatant", updList);
}
super.startCombat();
}
/* -------------------------------------------- */
computeInitiative(c, updList) {
let id = c._id || c.id
if (c.actor.hasPhase(this.segmentNumber) || c.actor.getHoldAction()) {
let baseInit = c.actor ? c.actor.getBaseInit() : 0;
let name = c.actor.name
if (c.actor.getHoldAction()) {
name = c.actor.name + " (H)"
}
if (c.actor.getAbortAction()) {
name = c.actor.name + " (A)"
}
updList.push({ _id: id, name: name, initiative: baseInit, holdAction: c.holdAction })
} else {
updList.push({ _id: id, name: name, initiative: 0, holdAction: c.holdAction })
}
}
/* -------------------------------------------- */
async rollInitiative(ids, formula = undefined, messageOptions = {}) {
ids = typeof ids === "string" ? [ids] : ids;
console.log("Roll INIT")
let updList = []
for (let cId = 0; cId < ids.length; cId++) {
const c = this.combatants.get(ids[cId])
await this.computeInitiative(c)
this.computeInitiative(c, updList)
}
if (updList.length > 0) {
await this.updateEmbeddedDocuments("Combatant", updList);
}
return this;
}
/* -------------------------------------------- */
async rebuildInitiative() {
let updList = []
for (let c of this.combatants) {
this.computeInitiative(c, updList)
}
console.log(this.combatants, updList)
if (updList.length > 0) {
await this.updateEmbeddedDocuments("Combatant", updList);
}
}
/* -------------------------------------------- */
nextRound() {
let turn = this.turn === null ? null : 0; // Preserve the fact that it's no-one's turn currently.
@@ -119,9 +147,7 @@ export class Hero6Combat extends Combat {
this.segmentNumber = turnData.segmentNumber;
// Re-compute init of actors
for (let c of this.combatants) {
this.computeInitiative(c)
}
this.rebuildInitiative()
// Update the document, passing data through a hook first
const updateData = { round: nextRound, turn, segmentNumber: turnData.segmentNumber, turnNumber: turnData.turnNumber };
@@ -133,7 +159,6 @@ export class Hero6Combat extends Combat {
/* -------------------------------------------- */
async _onCreateEmbeddedDocuments(type, documents, result, options, userId) {
console.log(">>>>", documents)
super._onCreateEmbeddedDocuments(type, documents, result, options, userId)
}

View File

@@ -43,8 +43,8 @@ Hooks.once("init", async function () {
formula: "1d6",
decimals: 3
};
/* -------------------------------------------- */
/* ------------------------------- ------------- */
game.socket.on("system.fvtt-hero-system-6", data => {
Hero6Utility.onSocketMesssage(data)
});
@@ -96,7 +96,7 @@ Hooks.once("ready", function () {
welcomeMessage();
Hero6Utility.ready()
Hero6Commands.ready()
Hero6Combat.init()
Hero6Combat.ready()
})

View File

@@ -52,6 +52,11 @@ export class Hero6Utility {
}
return false
})
Handlebars.registerHelper('checkInit', function (value) {
let myValue = Number(value) || 0
return myValue > 0
})
this.gameSettings()