Various fixes and enhancents

This commit is contained in:
2023-02-06 07:37:39 +01:00
parent bc7910a50d
commit 7d8791f675
19 changed files with 633 additions and 173 deletions

View File

@@ -24,7 +24,13 @@ export class WarheroActorSheet extends ActorSheet {
/* -------------------------------------------- */
async getData() {
this.actor.setLevel()
this.actor.computeDRTotal()
this.actor.computeParryBonusTotal()
this.actor.computeBonusLanguages()
const objectData = duplicate(this.object.system)
let race = this.actor.getRace()
let formData = {
title: this.title,
@@ -36,7 +42,9 @@ export class WarheroActorSheet extends ActorSheet {
cssClass: this.isEditable ? "editable" : "locked",
system: objectData,
limited: this.object.limited,
skills: this.actor.getSkills( ),
skills: this.actor.getNormalSkills( ),
classSkills: this.actor.getClassSkills( ),
languages: this.actor.getLanguages( ),
weapons: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getWeapons()) ),
armors: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getArmors())),
shields: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getShields())),
@@ -44,7 +52,7 @@ export class WarheroActorSheet extends ActorSheet {
equipments: this.actor.checkAndPrepareEquipments(duplicate(this.actor.getEquipmentsOnly()) ),
slotEquipments: this.actor.buildEquipmentsSlot(),
subActors: duplicate(this.actor.getSubActors()),
race: duplicate(this.actor.getRace()),
race: duplicate(race),
class: duplicate(this.actor.getClass()),
moneys: duplicate(this.actor.getMoneys()),
description: await TextEditor.enrichHTML(this.object.system.biodata.description, {async: true}),
@@ -54,8 +62,10 @@ export class WarheroActorSheet extends ActorSheet {
editScore: this.options.editScore,
isGM: game.user.isGM
}
this.formData = formData;
if ( race && race.name) {
formData.hpprogression = game.system.warhero.config.progressionList[race.system.hpprogresion]
}
this.formData = formData
console.log("PC : ", formData, this.object);
return formData;
}
@@ -136,6 +146,11 @@ export class WarheroActorSheet extends ActorSheet {
const statKey = $(event.currentTarget).data("key")
this.actor.rollFromType(rollType, statKey)
});
html.find('.roll-save').click((event) => {
const rollType = $(event.currentTarget).data("type")
const statKey = $(event.currentTarget).data("key")
this.actor.rollSaveFromType(rollType, statKey)
});
html.find('.roll-weapon').click((event) => {
const li = $(event.currentTarget).parents(".item")
const weaponId = li.data("item-id")

View File

@@ -170,7 +170,7 @@ export class WarheroActor extends Actor {
&& it.system.slotlocation == slotName )
let slotUsed = 0
for(let item of containers[slotName].content) {
slotUsed += item.system.slotused
slotUsed += item.system.slotused * ((item.system.quantity) ? item.system.quantity : 1)
}
containers[slotName].slotUsed = slotUsed
}
@@ -210,13 +210,25 @@ export class WarheroActor extends Actor {
}
return item;
}
/* -------------------------------------------- */
getLanguages() {
let comp = this.items.filter(it => it.type == "language")
WarheroUtility.sortArrayObjectsByName(comp)
return comp
}
/* -------------------------------------------- */
getNormalSkills() {
let comp = this.items.filter(it => it.type == "skill" && !it.system.classskill)
WarheroUtility.sortArrayObjectsByName(comp)
return comp
}
getClassSkills() {
let comp = this.items.filter(it => it.type == "skill" && it.system.classskill)
WarheroUtility.sortArrayObjectsByName(comp)
return comp
}
getSkills() {
let comp = duplicate(this.items.filter(item => item.type == 'skill') || [])
for (let skill of comp) {
WarheroUtility.updateSkill(skill)
}
WarheroUtility.sortArrayObjectsByName(comp)
return comp
}
@@ -534,7 +546,33 @@ export class WarheroActor extends Actor {
isAttackerAdvantage() {
return this.items.find(cond => cond.type == "condition" && cond.system.targetadvantage)
}
/* -------------------------------------------- */
setLevel() {
let xp = this.system.secondary.xp.value
this.system.secondary.xp.level = Math.floor(xp/10)
}
/* -------------------------------------------- */
computeDRTotal() {
let armors = this.items.filter(it => it.type == "armor")
let dr = 0
for (let armor of armors) {
dr += armor.system.damagereduction
}
this.system.secondary.drbonustotal.value = this.system.secondary.drbonus.value + dr
}
/* -------------------------------------------- */
computeParryBonusTotal() {
let shields = this.items.filter(it => it.type == "shield")
let parry = 0
for (let shield of shields) {
parry += shield.system.parrybonus
}
this.system.secondary.parrybonustotal.value = this.system.secondary.parrybonus.value + parry
}
/* -------------------------------------------- */
computeBonusLanguages() {
this.system.secondary.nblanguage.value = Math.floor(this.system.statistics.min.value / 2)
}
/* -------------------------------------------- */
spentMana( mana) {
if ( Number(mana) > this.system.attributes.mana.value) {
@@ -562,9 +600,21 @@ export class WarheroActor extends Actor {
let rollData = this.getCommonRollData()
rollData.mode = rollType
rollData.stat = stat
if ( rollKey == "parrybonustotal") {
WarheroUtility.rollParry(rollData)
return
}
this.startRoll(rollData)
}
/* -------------------------------------------- */
rollSaveFromType(rollType, rollKey) {
let stat = duplicate(this.system[rollType][rollKey])
let rollData = this.getCommonRollData()
rollData.mode = "save"
rollData.stat = stat
this.startRoll(rollData)
}
/* -------------------------------------------- */
rollWeapon(weaponId) {
let weapon = this.items.get(weaponId)
@@ -572,7 +622,13 @@ export class WarheroActor extends Actor {
weapon = duplicate(weapon)
let rollData = this.getCommonRollData()
rollData.mode = "weapon"
rollData.stat = duplicate(this.system.statistics.dex)
if (weapon.system.weapontype ==="shooting" || weapon.system.weapontype ==="throwing") {
rollData.stat = duplicate(this.system.attributes.txcr)
} else {
rollData.stat = duplicate(this.system.attributes.txcm)
}
rollData.usemWeaponMalus =
rollData.mWeaponMalus = this.system.secondary.malusmultiweapon.value
rollData.weapon = weapon
rollData.img = weapon.img
this.startRoll(rollData)

View File

@@ -21,22 +21,22 @@ export const WARHERO_CONFIG = {
},
slotNames : {
head: {nbslots: 1, label: "WH.conf.head"},
cloak: {nbslots: 1, label: "WH.conf.cloak"},
weapon1: {nbslots: 1, label: "WH.conf.weapon1"},
weapon2: {nbslots: 1, label: "WH.conf.weapon2"},
gloves: {nbslots: 1, label: "WH.conf.gloves"},
ring: {nbslots: 10, label: "WH.conf.ring"},
dress: {nbslots: 1, label: "WH.conf.dress"},
boots: {nbslots: 1, label: "WH.conf.boots"},
belt: {nbslots: 6, label: "WH.conf.belt"},
quiver: {nbslots: 20, label: "WH.conf.quiver"},
armor: {nbslots: 1, label: "WH.conf.armor"},
shield: {nbslots: 1, label: "WH.conf.shield"},
backpack: {nbslots: 12, label: "WH.conf.backpack"},
beltpouch1: {nbslots: 4, label: "WH.conf.beltpouch1"},
beltpouch2: {nbslots: 4, label: "WH.conf.beltpouch2"},
beltpouch3: {nbslots: 4, label: "WH.conf.beltpouch3"},
head: {nbslots: 1, itemtype:"armor", label: "WH.conf.head"},
cloak: {nbslots: 1, itemtype:"equipment", label: "WH.conf.cloak"},
weapon1: {nbslots: 1, itemtype:"weapon", label: "WH.conf.weapon1"},
weapon2: {nbslots: 1, itemtype:"weapon", label: "WH.conf.weapon2"},
gloves: {nbslots: 1, itemtype:"equipment",label: "WH.conf.gloves"},
ring: {nbslots: 10, itemtype:"equipment",label: "WH.conf.ring"},
dress: {nbslots: 1, itemtype:"equipment",label: "WH.conf.dress"},
boots: {nbslots: 1, itemtype:"equipment",label: "WH.conf.boots"},
belt: {nbslots: 6, itemtype:"equipment",label: "WH.conf.belt"},
quiver: {nbslots: 20, itemtype:"equipment",label: "WH.conf.quiver"},
armor: {nbslots: 1, itemtype:"armor",label: "WH.conf.armor"},
shield: {nbslots: 1, itemtype:"shield",label: "WH.conf.shield"},
backpack: {nbslots: 12, itemtype:"equipment",label: "WH.conf.backpack"},
beltpouch1: {nbslots: 4, itemtype:"equipment",label: "WH.conf.beltpouch1"},
beltpouch2: {nbslots: 4, itemtype:"equipment", label: "WH.conf.beltpouch2"},
beltpouch3: {nbslots: 4, itemtype:"equipment", label: "WH.conf.beltpouch3"},
},
progressionList: {

View File

@@ -49,9 +49,6 @@ export class WarheroItemSheet extends ItemSheet {
/* -------------------------------------------- */
async getData() {
if ( this.object.type == "skill") {
WarheroUtility.updateSkill(this.object)
}
let objectData = duplicate(this.object.system)
let itemData = objectData
@@ -66,6 +63,7 @@ export class WarheroItemSheet extends ItemSheet {
config: game.system.warhero.config,
description: await TextEditor.enrichHTML(this.object.system.description, {async: true}),
system: itemData,
statistics: duplicate(game.system.template.Actor.templates.core.statistics),
limited: this.object.limited,
options: this.options,
owner: this.document.isOwner,

View File

@@ -5,7 +5,7 @@ export class WarheroRollDialog extends Dialog {
/* -------------------------------------------- */
static async create(actor, rollData) {
let options = { classes: ["WarheroDialog"], width: 320, height: 'fit-content', 'z-index': 99999 };
let options = { classes: ["WarheroDialog"], width: 420, height: 'fit-content', 'z-index': 99999 };
let html = await renderTemplate('systems/fvtt-warhero/templates/roll-dialog-generic.html', rollData);
return new WarheroRollDialog(actor, rollData, html, options);
@@ -64,6 +64,10 @@ export class WarheroRollDialog extends Dialog {
html.find('#bonusMalus').change((event) => {
this.rollData.bonusMalus = Number(event.currentTarget.value)
})
html.find('#usemWeaponMalus').change((event) => {
this.rollData.usemWeaponMalus = event.currentTarget.checked
})
}
}

View File

@@ -208,23 +208,6 @@ export class WarheroUtility {
html.on("click", '.view-item-from-chat', event => {
game.system.crucible.creator.openItemView(event)
})
html.on("click", '.roll-defense-melee', event => {
let rollId = $(event.currentTarget).data("roll-id")
let rollData = WarheroUtility.getRollData(rollId)
rollData.defenseWeaponId = $(event.currentTarget).data("defense-weapon-id")
let actor = game.canvas.tokens.get(rollData.defenderTokenId).actor
if (actor && (game.user.isGM || actor.isOwner)) {
actor.rollDefenseMelee(rollData)
}
})
html.on("click", '.roll-defense-ranged', event => {
let rollId = $(event.currentTarget).data("roll-id")
let rollData = WarheroUtility.getRollData(rollId)
let defender = game.canvas.tokens.get(rollData.defenderTokenId).actor
if (defender && (game.user.isGM || defender.isOwner)) {
defender.rollDefenseRanged(rollData)
}
})
}
@@ -319,11 +302,6 @@ export class WarheroUtility {
this.updateRollData(rollData)
}
/* -------------------------------------------- */
static getRollData(id) {
return this.rollDataStore[id]
}
/* -------------------------------------------- */
static async displayDefenseMessage(rollData) {
if (rollData.mode == "weapon" && rollData.defenderTokenId) {
@@ -517,10 +495,6 @@ export class WarheroUtility {
}
}
/* -------------------------------------------- */
static updateSkill(skill) {
}
/* -------------------------------------------- */
static getDiceFromCover(cover) {
if (cover == "cover50") return 1
@@ -534,6 +508,30 @@ export class WarheroUtility {
if (cover == "engaged") return 1
return 0
}
/* -------------------------------------------- */
static async rollParry(rollData) {
let actor = game.actors.get(rollData.actorId)
// ability/save/size => 0
let diceFormula = "1d12+" + rollData.stat.value
let myRoll = rollData.roll
if (!myRoll) { // New rolls only of no rerolls
myRoll = new Roll(diceFormula).roll({ async: false })
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
}
rollData.roll = myRoll
rollData.isSuccess = false
if (myRoll.total >= 12 || myRoll.terms[0].results[0].result == 12) {
rollData.isSuccess = true
}
if (myRoll.terms[0].results[0].result == 1) {
rollData.isSuccess = false
}
let msg = await this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-warhero/templates/chat-parry-result.html`, rollData)
})
msg.setFlag("world", "rolldata", rollData)
console.log("Rolldata result", rollData)
}
/* -------------------------------------------- */
static async rollWarhero(rollData) {
@@ -569,6 +567,9 @@ export class WarheroUtility {
if ( rollData.stat) {
diceFormula += "+" + rollData.stat.value
}
if ( rollData.usemWeaponMalus) {
diceFormula += "+" + rollData.mWeaponMalus
}
diceFormula += "+" + rollData.bonusMalus
rollData.diceFormula = diceFormula
@@ -581,8 +582,6 @@ export class WarheroUtility {
}
rollData.roll = myRoll
actor.lastRoll = rollData
let msg = await this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-warhero/templates/chat-generic-result.html`, rollData)
})