Add spell management and improve actor sheet

This commit is contained in:
2022-12-20 14:10:58 +01:00
parent 96ba97f503
commit 28e8edc867
12 changed files with 713 additions and 104 deletions

View File

@@ -47,6 +47,7 @@ export class Avd12ActorSheet extends ActorSheet {
equippedShield: this.actor.getEquippedShield(),
subActors: duplicate(this.actor.getSubActors()),
moneys: duplicate(this.actor.getMoneys()),
focusData: this.actor.computeFinalFocusData(),
encCurrent: this.actor.encCurrent,
options: this.options,
owner: this.document.isOwner,
@@ -89,17 +90,6 @@ export class Avd12ActorSheet extends ActorSheet {
this.actor.createEmbeddedDocuments('Item', [{ name: "NewItem", type: dataType }], { renderSheet: true })
})
html.find('.equip-activate').click(ev => {
const li = $(ev.currentTarget).parents(".item")
let itemId = li.data("item-id")
this.actor.equipActivate( itemId)
});
html.find('.equip-deactivate').click(ev => {
const li = $(ev.currentTarget).parents(".item")
let itemId = li.data("item-id")
this.actor.equipDeactivate( itemId)
});
html.find('.subactor-edit').click(ev => {
const li = $(ev.currentTarget).parents(".item");
let actorId = li.data("actor-id");
@@ -135,26 +125,16 @@ export class Avd12ActorSheet extends ActorSheet {
let skillKey = $(event.currentTarget).data("skill-key")
this.actor.rollSkill(attrKey, skillKey)
});
html.find('.roll-spell').click((event) => {
const li = $(event.currentTarget).parents(".item");
this.actor.rollSpell( li.data("item-id") )
});
html.find('.roll-weapon').click((event) => {
const li = $(event.currentTarget).parents(".item");
const skillId = li.data("item-id")
this.actor.rollWeapon(skillId)
});
html.find('.roll-armor-die').click((event) => {
this.actor.rollArmorDie()
});
html.find('.roll-shield-die').click((event) => {
this.actor.rollShieldDie()
});
html.find('.roll-target-die').click((event) => {
this.actor.rollDefenseRanged()
});
html.find('.roll-save').click((event) => {
const saveKey = $(event.currentTarget).data("save-key")
this.actor.rollSave(saveKey)
});
html.find('.lock-unlock-sheet').click((event) => {
@@ -191,12 +171,18 @@ export class Avd12ActorSheet extends ActorSheet {
/* -------------------------------------------- */
async _onDropItem(event, dragData) {
console.log(">>>>>> DROPPED!!!!")
const item = fromUuidSync(dragData.uuid)
let itemFull
if (item == undefined) {
item = this.actor.items.get( item.id )
itemFull = this.actor.items.get( dragData.uuid )
} else {
if (item && item.system) {
itemFull = item
} else {
itemFull = await Avd12Utility.searchItem( item )
}
}
let ret = await this.actor.preprocessItem( event, item, true )
let ret = await this.actor.preprocessItem( event, itemFull, true )
if ( ret ) {
super._onDropItem(event, dragData)
}

View File

@@ -351,12 +351,47 @@ export class Avd12Actor extends Actor {
/* -------------------------------------------- */
async preprocessItem(event, item, onDrop = false) {
//console.log('ITEM', item)
if ( item.system.focus && item.system.focus?.isfocus) {
let focusItem = this.items.find(it => it.system.focus?.isfocus)
if (focusItem) {
ui.notifications.warn("You already have a Focus Item in your equipment.")
return false
}
}
let dropID = $(event.target).parents(".item").attr("data-item-id") // Only relevant if container drop
let objectID = item.id || item._id
this.addObjectToContainer(objectID, dropID)
return true
}
/* -------------------------------------------- */
computeFinalFocusData() {
let focus = this.items.find(it => it.system.focus?.isfocus)
if (focus) {
let focusData = Avd12Utility.computeFocusData(focus.system.focus)
let focusBonus = this.items.filter( it => it.system.focuspointsbonus > 0).reduce((sum, item2) => sum = item2.system.focuspointsbonus, 0)
let focusregenbonus = this.items.filter( it => it.system.focusregenbonus > 0).reduce((sum, item2) => sum = item2.system.focusregenbonus, 0)
let burnchancebonus = this.items.filter( it => it.system.burnchancebonus > 0).reduce((sum, item2) => sum = item2.system.burnchancebonus, 0)
console.log("FINAL BONUS", focusBonus, focusregenbonus, burnchancebonus)
return {
focusPoints : focusData.focusPoints + focusBonus,
burnChance: focusData.burnChance + burnchancebonus,
focusRegen: focusData.focusRegen + focusregenbonus,
spellAttackBonus: focusData.spellAttackBonus,
spellDamageBonus: focusData.spellDamageBonus,
currentFocusPoints: this.system.focus.currentFocusPoints
}
}
return {
focusPoints : 0,
burnChance: 0,
focusRegen: 0,
spellAttackBonus: 0,
spellDamageBonus: 0
}
}
/* -------------------------------------------- */
async equipGear(equipmentId) {
let item = this.items.find(item => item.id == equipmentId);
@@ -545,6 +580,27 @@ export class Avd12Actor extends Actor {
}
}
/* -------------------------------------------- */
rollSpell(spellId) {
let spell = this.items.get(spellId)
if (spell) {
spell = duplicate(spell)
if (spell.system.spelltype != "utility") {
let rollData = this.getCommonRollData()
rollData.mode = "spell"
rollData.spell = spell
rollData.spellAttack = this.system.bonus.spell.attack
rollData.spellDamage = this.system.bonus.spell.damage
rollData.spellCost = Avd12Utility.getSpellCost(spell)
rollData.title = "Roll Spell " + spell.name
rollData.img = spell.img
this.startRoll(rollData)
}
} else {
ui.notifications.warn("Unable to find the relevant spell.")
}
}
/* -------------------------------------------- */
rollWeapon(weaponId) {
let weapon = this.items.get(weaponId)

View File

@@ -76,6 +76,11 @@ export class Avd12ItemSheet extends ItemSheet {
isGM: game.user.isGM
}
// Specific focus case
if (this.object.system.focus?.isfocus) {
formData.focusData = Avd12Utility.computeFocusData( this.object.system.focus)
}
this.options.editable = !(this.object.origin == "embeddedItem");
console.log("ITEM DATA", formData, this);
return formData;

View File

@@ -4,6 +4,13 @@ import { Avd12Commands } from "./avd12-commands.js";
/* -------------------------------------------- */
const __ALLOWED_MODULE_TYPES = { "action": 1, "reaction": 1, "freeaction": 1, "trait": 1 }
const __focusCore = { "corenone": 0, "core1gp": 6, "core5gp": 8, "core50gp": 10, "core100gp": 12, "core300gp": 16, "core500gp": 20, "core800gp": 26, "core1000gp": 32 }
const __burnChanceTreatment = { "treatmentnone": 0, "treatment1gp": 8, "treatment4gp": 7, "treatment20gp": 6, "treatment50gp": 5, "treatment500gp": 4, "treatment1000gp": 3, "treatment5000gp": 2, "treatment10000gp": 1 }
const __focusPointTreatment = { "treatmentnone": 0, "treatment1gp": 0, "treatment4gp": 1, "treatment20gp": 2, "treatment50gp": 4, "treatment500gp": 6, "treatment1000gp": 8, "treatment5000gp": 14, "treatment10000gp": 20 }
const __focusRegenBond = { "bondnone": 6, "bondeasy": 8, "bondcommon": 12, "bonduncommon": 16, "bondrare": 22, "bondlegendary": 26, "bondmythic": 36, "bonddivine": 48 }
const __bonusSpellDamageBond = { "bondnone": 0, "bondeasy": 1, "bondcommon": 1, "bonduncommon": 1, "bondrare": 2, "bondlegendary": 2, "bondmythic": 3, "bonddivine": 4 }
const __bonusSpellAttackBond = { "bondnone": 0, "bondeasy": 0, "bondcommon": 1, "bonduncommon": 1, "bondrare": 2, "bondlegendary": 2, "bondmythic": 3, "bonddivine": 4 }
const __spellCost = { "beginner": 1, "novice": 2, "expert": 4, "master": 6, "grandmaster": 8 }
/* -------------------------------------------- */
@@ -76,20 +83,20 @@ export class Avd12Utility {
/* -------------------------------------------- */
static buildBonusList() {
let bonusList = []
for(let key in game.system.model.Actor.character.bonus) {
for (let key in game.system.model.Actor.character.bonus) {
let bonuses = game.system.model.Actor.character.bonus[key]
for (let bonus in bonuses) {
bonusList.push( key + "." + bonus )
bonusList.push(key + "." + bonus)
}
}
for(let key in game.system.model.Actor.character.attributes) {
for (let key in game.system.model.Actor.character.attributes) {
let attrs = game.system.model.Actor.character.attributes[key]
for(let skillKey in attrs.skills) {
bonusList.push( key + ".skills." + skillKey + ".modifier" )
for (let skillKey in attrs.skills) {
bonusList.push(key + ".skills." + skillKey + ".modifier")
}
}
for(let key in game.system.model.Actor.character.universal.skills) {
bonusList.push( "universal.skills." + key + ".modifier" )
for (let key in game.system.model.Actor.character.universal.skills) {
bonusList.push("universal.skills." + key + ".modifier")
}
return bonusList
}
@@ -277,14 +284,14 @@ export class Avd12Utility {
/* -------------------------------------------- */
static getSuccessResult(rollData) {
if (rollData.sumSuccess <= -3) {
if (rollData.attackRollData.weapon.system.isranged ) {
if (rollData.attackRollData.weapon.system.isranged) {
return { result: "miss", fumble: true, hpLossType: "melee" }
} else {
return { result: "miss", fumble: true, attackerHPLoss: "2d3", hpLossType: "melee" }
}
}
if (rollData.sumSuccess == -2) {
if (rollData.attackRollData.weapon.system.isranged ) {
if (rollData.attackRollData.weapon.system.isranged) {
return { result: "miss", dangerous_fumble: true }
} else {
return { result: "miss", dangerous_fumble: true, attackerHPLoss: "1d3", hpLossType: "melee" }
@@ -403,6 +410,35 @@ export class Avd12Utility {
}
}
/* -------------------------------------------- */
static computeFocusData(focus) {
let focusData = {
focusPoints: __focusCore[focus.core] + __focusPointTreatment[focus.treatment],
burnChance: __burnChanceTreatment[focus.treatment],
focusRegen: __focusRegenBond[focus.bond],
spellAttackBonus: __bonusSpellAttackBond[focus.bond],
spellDamageBonus: __bonusSpellDamageBond[focus.bond]
}
return focusData
}
/* -------------------------------------------- */
static async searchItem(dataItem) {
let item
if (dataItem.pack) {
let id = dataItem.id || dataItem._id
let items = await this.loadCompendium(dataItem.pack, item => item.id == id)
item = items[0] || undefined
} else {
item = game.items.get(dataItem.id)
}
return item
}
/* -------------------------------------------- */
static getSpellCost(spell) {
return __spellCost[spell.system.level]
}
/* -------------------------------------------- */
static chatDataSetup(content, modeOverride, isRoll = false, forceWhisper) {
let chatData = {
@@ -477,10 +513,13 @@ export class Avd12Utility {
// Build the dice formula
let diceFormula = "1d12"
if (rollData.skill) {
diceFormula += "+"+rollData.skill.finalvalue
diceFormula += "+" + rollData.skill.finalvalue
}
diceFormula += "+"+rollData.bonusMalusRoll
if (rollData.spellAttack) {
diceFormula += "+" + rollData.spellAttack
}
diceFormula += "+" + rollData.bonusMalusRoll
if (rollData.skill && rollData.skill.good) {
diceFormula += "+1d4"
}
@@ -494,10 +533,10 @@ export class Avd12Utility {
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
}
rollData.roll = myRoll
rollData.isSuccess = false
if ( rollData.targetCheck != "none") {
if( myRoll.total >= Number(rollData.targetCheck)) {
if (rollData.targetCheck != "none") {
if (myRoll.total >= Number(rollData.targetCheck)) {
rollData.isSuccess = true
}
}
@@ -554,17 +593,6 @@ export class Avd12Utility {
}
/* -------------------------------------------- */
static async searchItem(dataItem) {
let item
if (dataItem.pack) {
item = await fromUuid("Compendium." + dataItem.pack + "." + dataItem.id)
} else {
item = game.items.get(dataItem.id)
}
return item
}
/* -------------------------------------------- */
static split3Columns(data) {
@@ -609,7 +637,7 @@ export class Avd12Utility {
let rollData = {
rollId: randomID(16),
bonusMalusRoll: 0,
targetCheck : "none",
targetCheck: "none",
rollMode: game.settings.get("core", "rollMode")
}
Avd12Utility.updateWithTarget(rollData)