Update combat tab

This commit is contained in:
2023-03-24 10:17:20 +01:00
parent 4ca23257cb
commit 0368be050b
11 changed files with 163 additions and 97 deletions

View File

@@ -44,8 +44,8 @@ export class Hero6ActorSheet extends ActorSheet {
powers: await this.actor.getPowers( ),
talents: this.actor.getTalents( ),
complications: this.actor.getComplications( ),
martialarts: this.actor.getMartialArts( ),
maneuvers: this.actor.getManeuvers( ),
nonstockmaneuvers: this.actor.getNonStockManeuvers(),
weapons: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getWeapons()) ),
armors: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getArmors())),
shields: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getShields())),
@@ -153,9 +153,9 @@ export class Hero6ActorSheet extends ActorSheet {
this.actor.rollCharac(characKey);
});
html.find('.roll-direct').click((event) => {
const rollFormula = $(event.currentTarget).data("roll-formula");
let roll = new Roll(rollFormula).roll({async: false})
roll.toMessage()
const rollFormula = $(event.currentTarget).data("roll-formula")
const rollSource = $(event.currentTarget).data("roll-source")
Hero6Utility.processDirectRoll( { actorId: this.actor.id, rollFormula: rollFormula, rollSource: rollSource, mode:"directroll"} )
});
html.find('.roll-item').click((event) => {

View File

@@ -67,8 +67,8 @@ export class Hero6Actor extends Actor {
}
}
computeDicesValue() {
this.system.biodata.presenceattack = Hero6Utility.getDerivatedDiceValue(this.system.characteristics.pre.value )
this.system.characteristics.str.strdice = Hero6Utility.getDerivatedDiceValue(this.system.characteristics.str.value )
this.system.biodata.presenceattack = Hero6Utility.getDerivatedDiceFormulas(this.system.characteristics.pre.value )
this.system.characteristics.str.strdice = Hero6Utility.getDerivatedDiceFormulas(this.system.characteristics.str.value )
}
/* -------------------------------------------- */
prepareDerivedData() {
@@ -235,11 +235,6 @@ export class Hero6Actor extends Actor {
Hero6Utility.sortArrayObjectsByName(comp)
return comp
}
getMartialArts() {
let comp = duplicate(this.items.filter(item => item.type == 'martialart') || [])
Hero6Utility.sortArrayObjectsByName(comp)
return comp
}
getComplications() {
let comp = duplicate(this.items.filter(item => item.type == 'complication') || [])
Hero6Utility.sortArrayObjectsByName(comp)
@@ -285,25 +280,45 @@ export class Hero6Actor extends Actor {
offensive: this.items.filter(item => item.type == "maneuver" && item.system.maneuvertype == "offensive"),
defensive: this.items.filter(item => item.type == "maneuver" && item.system.maneuvertype == "defensive")
}
Hero6Utility.sortArrayObjectsByName(maneuvers.general)
Hero6Utility.sortArrayObjectsByName(maneuvers.offensive)
Hero6Utility.sortArrayObjectsByName(maneuvers.defensive)
return maneuvers
}
getNonStockManeuvers() {
let maneuvers = this.items.filter(item => item.type == "maneuver" && !item.system.isstock)
Hero6Utility.sortArrayObjectsByName(maneuvers)
return maneuvers
}
getEquipments() {
return this.items.filter(item => item.type == "equipment" && item.system.subtype == "equipment");
let list = this.items.filter(item => item.type == "equipment" && item.system.subtype == "equipment");
Hero6Utility.sortArrayObjectsByName(list)
return list
}
getWeapons() {
return this.items.filter(item => item.type == "equipment" && item.system.subtype == "weapon");
let list = this.items.filter(item => item.type == "equipment" && item.system.subtype == "weapon");
Hero6Utility.sortArrayObjectsByName(list)
return list
}
getArmors() {
return this.items.filter(item => item.type == "equipment" && item.system.subtype == "armor");
let list = this.items.filter(item => item.type == "equipment" && item.system.subtype == "armor");
Hero6Utility.sortArrayObjectsByName(list)
return list
}
getShields() {
return this.items.filter(item => item.type == "equipment" && item.system.subtype == "shield");
let list = this.items.filter(item => item.type == "equipment" && item.system.subtype == "shield");
Hero6Utility.sortArrayObjectsByName(list)
return list
}
getEquipmentsMoneys() {
return duplicate(this.items.filter(item => item.type == "equipment" && (item.system.subtype == "equipment" || item.system.subtype == "money")) || [])
let list = duplicate(this.items.filter(item => item.type == "equipment" && (item.system.subtype == "equipment" || item.system.subtype == "money")) || [])
Hero6Utility.sortArrayObjectsByName(list)
return list
}
getEquipmentsOnly() {
return duplicate(this.items.filter(item => item.type == "equipment" && item.system.subtype == "equipment") || [])
let list = duplicate(this.items.filter(item => item.type == "equipment" && item.system.subtype == "equipment") || [])
Hero6Utility.sortArrayObjectsByName(list)
return list
}
/* ------------------------------------------- */

View File

@@ -20,6 +20,9 @@ export class Hero6Utility {
Handlebars.registerHelper('count', function (list) {
return list.length;
})
Handlebars.registerHelper('exists', function (val) {
return val != null && val != undefined;
});
Handlebars.registerHelper('includes', function (array, val) {
return array.includes(val);
})
@@ -78,12 +81,16 @@ export class Hero6Utility {
/*-------------------------------------------- */
static getDerivatedDiceValue(value) {
let dices = Math.floor(value/5) +"d6"
static getDerivatedDiceFormulas(value) {
let rollFormula = Math.floor(value/5) +"d6"
let displayFormula = Math.floor(value/5)
if ( value % 5 > 2) {
dices += "+1d3"
rollFormula += "+round(1d6/2)"
displayFormula += " 1/2d6"
} else {
displayFormula += "d6"
}
return dices
return {rollFormula:rollFormula, displayFormula: displayFormula}
}
/*-------------------------------------------- */
static upperFirst(text) {
@@ -340,15 +347,53 @@ export class Hero6Utility {
}
rollData.margin = target - rollData.result
this.outputRollMessage(rollData)
}
/* -------------- ----------------------------- */
static processDirectRoll(rollData ) {
let roll = new Roll(rollData.rollFormula).roll({async: false})
rollData.roll = roll
// Compute BODY
let bodyValue = 0
for (let term of roll.terms) {
if ( term.constructor.name == "Die") {
for (let value of term.values) {
if (value > 1) {
bodyValue +=1
}
if (value == 6) {
bodyValue +=1
}
}
}
if ( term.constructor.name == "NumericTerm") {
if (term.total > 1) {
bodyValue +=1
}
if (term.total == 6) {
bodyValue +=1
}
}
}
rollData.result = roll.total
rollData.bodyValue = bodyValue
this.outputRollMessage(rollData)
}
/* -------------- ----------------------------- */
static async outputRollMessage(rollData) {
let msg = await this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-hero-system-6/templates/chat/chat-generic-result.hbs`, rollData)
})
msg.setFlag("world", "rolldata", rollData)
console.log("Rolldata result", rollData)
}
/* -------------------------------------------- */
/* -------------- ----------------------------- */
static sortArrayObjectsByName(myArray) {
myArray.sort((a, b) => {
let fa = a.name.toLowerCase();