moo-man / ImpMal-FoundryVTT

Warhammer 40,000: Imperium Maledictum roleplaying game system for Foundry Virtual Tabletop
Apache License 2.0
11 stars 4 forks source link

Unable to apply Effect for Seal Wounds #64

Open Bogster13 opened 1 day ago

Bogster13 commented 1 day ago

Describe the bug When using Seal Wounds the effect will fail to apply to the target.

To Reproduce Use Foundry 12, use seal wound with a target attempt to apply.

Uncaught (in promise) TypeError: this.effect.sourceTest.actor is undefined [Detected 1 package: warhammer-lib(1.2.2)]

I think the problem might be in the WarhammerLibrary-FVTT - src/document/effect.js

If i understand it correctly we should use this.effect.sourceActor to get the source actor now instead of this.effect.sourceTest.actor.system.characteristics.wil.bonus; because sourceTest no longer has an actor in Foundry 12.

But this.effect.sourceActor will fail because it relies on sourceTest that will return test.data instead of just test.

    get sourceTest() 
    {
        let test = this.system.sourceData.test;
        if (test instanceof WarhammerTestBase)
        {
            return test;
        }
        else 
        {
            return test.data;
        }
    }
    get sourceActor() 
    {
        return this.sourceTest ? CONFIG.ChatMessage.documentClass.getSpeakerActor(this.sourceTest.context.speaker) : this.sourceItem?.actor;
    }

might need to be this

    get sourceActor() 
    {
        return this.sourceTest ? CONFIG.ChatMessage.documentClass.getSpeakerActor(this.effect.system.sourceData.test.context.speaker) : this.sourceItem?.actor;
    }

this.effect.system.sourceData.test.context.speakerreturns an object that should be usable by the function

Object { scene: "NUEDEFAULTSCENE0", token: "NAbITbQYjYA5fK4K", actor: "QiMSgysDqIaNjdGp", alias: "Primaris Biomancer" }

while this.sourceTest.context.speaker will return an error because sourceTest return test.data and there is no test.data.context, context is one step up in test.context.

Bogster13 commented 21 hours ago

Here is an updated script for Seal Wounds that seems to works with Foundry 12

        let sourceActor = game.actors.get(this.effect.system.sourceData.test.context.speaker.actor);

        let healed = this.actor.system.characteristics.tgh.bonus + this.effect.system.sourceData.test.result.SL + sourceActor.system.characteristics.wil.bonus;

        this.script.scriptMessage("<strong>" + this.actor.name + "</strong> healed " + healed + " wounds");
        await this.actor.update({"system.combat.wounds.value" : this.actor.system.combat.wounds.value - healed});
        await this.actor.hasCondition("bleeding")?.delete()

        let existing = this.actor.effects.find(e => e.getFlag("impmal", "sealWounds"))

        if (existing)
        {
            await this.actor.addCondition("fatigued")
            this.script.options.immediate.deleteEffect = true;
        }
        else 
        {
            this.effect.updateSource({"flags.impmal.sealWounds" : true})
        } 
moo-man commented 21 hours ago

Thanks, but editing the script probably isn't ideal. If the sourceActor getter isn't working then many other scripts are likely broken.

This is probably because of the Warhammer Library integration where things aren't lining up correctly.

Bogster13 commented 21 hours ago

Oh I agree that it's not ideal, mostly wrote it as a temporary solution to use in my own game until it can get fixed.