From b2fe67ab05664b2b4435d36b62306846e23f0932 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Wed, 30 Nov 2022 12:12:44 +0100 Subject: [PATCH] Enhance tokens/actor management + auto effects --- module/actor/actor.js | 19 ++++++ module/bol.js | 2 +- module/controllers/bol-rolls.js | 17 ++--- module/system/bol-utility.js | 14 +++- module/system/config.js | 109 ++++++++++++++++++++++++++++++++ system.json | 4 +- 6 files changed, 153 insertions(+), 12 deletions(-) diff --git a/module/actor/actor.js b/module/actor/actor.js index 06b07fe..145c299 100644 --- a/module/actor/actor.js +++ b/module/actor/actor.js @@ -618,12 +618,31 @@ export class BoLActor extends Actor { let lastHP = await this.getFlag("world", hpID) if (lastHP != this.system.resources.hp.value && game.user.isGM) { // Only GM sends this await this.setFlag("world", hpID, this.system.resources.hp.value) + let prone = this.effects.find( ef => ef.label == "EFFECT.StatusProne") + let dead = this.effects.find( ef => ef.label == "EFFECT.StatusDead") if (this.system.resources.hp.value <= 0) { + if ( !prone) { + await this.createEmbeddedDocuments("ActiveEffect", [ + {label: 'EFFECT.StatusProne', icon: 'icons/svg/falling.svg', flags: { core: { statusId: 'prone' } } } + ]) + } + if ( this.system.resources.hp.value < -5 && !dead) { + await this.createEmbeddedDocuments("ActiveEffect", [ + {label: 'EFFECT.StatusDead', icon: 'icons/svg/skull.svg', flags: { core: { statusId: 'dead' } } } + ]) + } ChatMessage.create({ alias: this.name, whisper: BoLUtility.getWhisperRecipientsAndGMs(this.name), content: await renderTemplate('systems/bol/templates/chat/chat-vitality-zero.hbs', { name: this.name, img: this.img, hp: this.system.resources.hp.value }) }) + } else { + if ( prone ) { + await this.deleteEmbeddedDocuments("ActiveEffect", [ prone.id ] ) + } + if ( dead ) { + await this.deleteEmbeddedDocuments("ActiveEffect", [ dead.id ] ) + } } } } diff --git a/module/bol.js b/module/bol.js index 0b07158..87f6ae7 100644 --- a/module/bol.js +++ b/module/bol.js @@ -120,7 +120,7 @@ function welcomeMessage() { Hooks.once('ready', async function () { BoLUtility.ready() - BoLCharacterSummary.ready() + BoLCharacterSummary.ready() registerUsageCount('bol') diff --git a/module/controllers/bol-rolls.js b/module/controllers/bol-rolls.js index 28e9f0b..e9eed20 100644 --- a/module/controllers/bol-rolls.js +++ b/module/controllers/bol-rolls.js @@ -36,6 +36,7 @@ export class BoLRoll { let rollData = { mode: mode, actorId: actor.id, + tokenId: actor.token?.id, img: actor.img, attribute: attribute, attrValue: attribute.value, @@ -352,7 +353,7 @@ export class BoLRoll { html.find('#attr').change((event) => { let attrKey = event.currentTarget.value - let actor = game.actors.get( this.rollData.actorId) + let actor = BoLUtility.getActorFromRollData(this.rollData) this.rollData.attribute = duplicate(actor.system.attributes[attrKey]) this.rollData.attrValue = actor.system.attributes[attrKey].value this.rollData.bolApplicableEffects = this.updateApplicableEffects(this.rollData) @@ -360,7 +361,7 @@ export class BoLRoll { }) html.find('#apt').change((event) => { let aptKey = event.currentTarget.value - let actor = game.actors.get( this.rollData.actorId) + let actor = BoLUtility.getActorFromRollData(this.rollData) this.rollData.aptitude = duplicate(actor.system.aptitudes[aptKey]) this.rollData.aptValue = actor.system.aptitudes[aptKey].value this.rollData.bolApplicableEffects = this.updateApplicableEffects(this.rollData) @@ -432,7 +433,7 @@ export class BoLRoll { // initialize default flags/values const rollOptionTpl = `systems/bol/templates/dialogs/${rollData.mode}-roll-dialog.hbs` - let actor = game.actors.get( rollData.actorId ) + let actor = BoLUtility.getActorFromRollData(rollData) let defender if ( rollData.targetId) { let token = game.scenes.current.tokens.get(rollData.targetId) @@ -562,8 +563,8 @@ export class BoLDefaultRoll { //this.rollData.isRealCritical = true //this.rollData.isFumble = true - - let actor = game.actors.get( this.rollData.actorId) + + let actor = BoLUtility.getActorFromRollData(this.rollData) if (this.rollData.reroll == undefined) { this.rollData.reroll = actor.heroReroll() } @@ -586,7 +587,7 @@ export class BoLDefaultRoll { /* -------------------------------------------- */ async sendChatMessage() { - let actor = game.actors.get( this.rollData.actorId) + let actor = BoLUtility.getActorFromRollData(this.rollData) this._buildChatMessage(this.rollData).then( async msgFlavor => { let msg = await this.rollData.roll.toMessage({ user: game.user.id, @@ -633,7 +634,7 @@ export class BoLDefaultRoll { /* -------------------------------------------- */ async sendDamageMessage() { - let actor = game.actors.get( this.rollData.actorId) + let actor = BoLUtility.getActorFromRollData(this.rollData) this._buildDamageChatMessage(this.rollData).then(async msgFlavor => { let msg = await this.rollData.damageRoll.toMessage({ user: game.user.id, @@ -648,7 +649,7 @@ export class BoLDefaultRoll { /* -------------------------------------------- */ getDamageAttributeValue(attrDamage, actorId = undefined) { - let actor = game.actors.get( (actorId) ? actorId: this.rollData.actorId) + let actor = BoLUtility.getActorFromRollData(this.rollData) return actor.getDamageAttributeValue( attrDamage ) } diff --git a/module/system/bol-utility.js b/module/system/bol-utility.js index afeb6ff..f4a073a 100644 --- a/module/system/bol-utility.js +++ b/module/system/bol-utility.js @@ -76,12 +76,24 @@ export class BoLUtility { static getLogoTopLeft() { return this.logoTopLeft } + /* -------------------------------------------- */ + static getActorFromRollData(rollData) { + let actor = game.actors.get( rollData.actorId) + if (rollData.tokenId) { + let token = canvas.tokens.placeables.find(t => t.id == rollData.tokenId) + if (token) { + actor = token.actor + } + } + return actor + } /* -------------------------------------------- */ static async ready() { //$("#logo").attr("src", this.getLogoTopLeft() ) $("#logo").css("content", `url(${this.getLogoTopLeft()})`) - + + CONFIG.statusEffects = duplicate(game.bol.config.statusEffects) } /* -------------------------------------------- */ diff --git a/module/system/config.js b/module/system/config.js index 5abd946..3b80e6f 100644 --- a/module/system/config.js +++ b/module/system/config.js @@ -342,4 +342,113 @@ BOL.bolEffectModifier = { "+6": "+6", "+8": "+8", } + +BOL.statusEffects = [ + { + "id": "dead", + "label": "EFFECT.StatusDead", + "icon": "icons/svg/skull.svg" + }, + { + "id": "unconscious", + "label": "EFFECT.StatusUnconscious", + "icon": "icons/svg/unconscious.svg" + }, + { + "id": "sleep", + "label": "EFFECT.StatusAsleep", + "icon": "icons/svg/sleep.svg" + }, + { + "id": "stun", + "label": "EFFECT.StatusStunned", + "icon": "icons/svg/daze.svg" + }, + { + "id": "prone", + "label": "EFFECT.StatusProne", + "icon": "icons/svg/falling.svg" + }, + { + "id": "restrain", + "label": "EFFECT.StatusRestrained", + "icon": "icons/svg/net.svg" + }, + { + "id": "paralysis", + "label": "EFFECT.StatusParalysis", + "icon": "icons/svg/paralysis.svg" + }, + { + "id": "fly", + "label": "EFFECT.StatusFlying", + "icon": "icons/svg/wing.svg" + }, + { + "id": "blind", + "label": "EFFECT.StatusBlind", + "icon": "icons/svg/blind.svg" + }, + { + "id": "deaf", + "label": "EFFECT.StatusDeaf", + "icon": "icons/svg/deaf.svg" + }, + { + "id": "silence", + "label": "EFFECT.StatusSilenced", + "icon": "icons/svg/silenced.svg" + }, + { + "id": "fear", + "label": "EFFECT.StatusFear", + "icon": "icons/svg/terror.svg" + }, + { + "id": "burning", + "label": "EFFECT.StatusBurning", + "icon": "icons/svg/fire.svg" + }, + { + "id": "frozen", + "label": "EFFECT.StatusFrozen", + "icon": "icons/svg/frozen.svg" + }, + { + "id": "shock", + "label": "EFFECT.StatusShocked", + "icon": "icons/svg/lightning.svg" + }, + { + "id": "disease", + "label": "EFFECT.StatusDisease", + "icon": "icons/svg/biohazard.svg" + }, + { + "id": "poison", + "label": "EFFECT.StatusPoison", + "icon": "icons/svg/poison.svg" + }, + { + "id": "curse", + "label": "EFFECT.StatusCursed", + "icon": "icons/svg/sun.svg" + }, + { + "id": "invisible", + "label": "EFFECT.StatusInvisible", + "icon": "icons/svg/invisible.svg" + }, + { + "id": "target", + "label": "EFFECT.StatusTarget", + "icon": "icons/svg/target.svg" + }, + { + "id": "eye", + "label": "EFFECT.StatusMarked", + "icon": "icons/svg/eye.svg" + } +] + BOL.debug = false; \ No newline at end of file diff --git a/system.json b/system.json index 39892cb..b7b68bc 100644 --- a/system.json +++ b/system.json @@ -14,7 +14,7 @@ ], "url": "https://www.uberwald.me/gitea/public/bol", "license": "LICENSE.txt", - "version": "10.4.5", + "version": "10.4.6", "compatibility": { "minimum": "10", "verified": "10", @@ -203,7 +203,7 @@ ], "socket": true, "manifest": "https://www.uberwald.me/gitea/public/bol/raw/v10/system.json", - "download": "https://www.uberwald.me/gitea/public/bol/archive/bol-v10.4.5.zip", + "download": "https://www.uberwald.me/gitea/public/bol/archive/bol-v10.4.6.zip", "background": "systems/images/map_lemurie.webp", "gridDistance": 1.5, "gridUnits": "m",