Acquiring the Enemy Target Causing Damage

Discuss modding questions and implementation details.
l3lessed
Posts: 336
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Acquiring the Enemy Target Causing Damage

Post by l3lessed » Fri May 22, 2020 6:46 pm

I honestly tried setting it up using your code setup, but it wasn't liking it. Let me try again, now that I have a better idea.

So, I think I found the underlying issue from a code logic perspective. Which puts me back at square one.

I can rebuild the adjustattackdamage, but the way it works, I think I have to reassign the target, since it is overriding the whole original formula and dumping out a whole new one. So, when I override it, I lose the original target that is passed from the calculateattackdamage routine.

That is adjustattackdamage was built to work with the calculateattackdamage, and by overriding it, I lose the target and break it from ever registering the enemy target to the adjustattackdamage routine.

Again, back to square one, how do I get the enemy entity that most recently hit the player without having to pull/push a request to the base engine?
My Skyrim Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
Magicono43
Posts: 279
Joined: Tue Nov 06, 2018 7:06 am

Re: Acquiring the Enemy Target Causing Damage

Post by Magicono43 » Fri May 22, 2020 7:02 pm

This is how Hazelnut did it for that method in Roleplay Realism mod:

Code: Select all

FormulaHelper.RegisterOverride(mod, "AdjustWeaponAttackDamage", (Func<DaggerfallEntity, DaggerfallEntity, int, int, DaggerfallUnityItem, int>)AdjustWeaponAttackDamage);

User avatar
Magicono43
Posts: 279
Joined: Tue Nov 06, 2018 7:06 am

Re: Acquiring the Enemy Target Causing Damage

Post by Magicono43 » Fri May 22, 2020 7:21 pm

Could try something like this as a hacky "Global variable"

Code: Select all

public static EnemyEntity VarName { get; set; }
And just set that to whenever you are getting the enemy object and then do something with it somewhere else.

l3lessed
Posts: 336
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Acquiring the Enemy Target Causing Damage

Post by l3lessed » Fri May 22, 2020 9:03 pm

I finally got it. Sucks that I have to hijack the adjust damagemodifier. Now I will have to provide a patch for any mods that touch this. Hopefully, it will only be rolepaly & realism, and one or two others.

Now, second problem. the adjustweapondamage only works for enemies attacking with a weapon, it was not built for monsters. I'm unsure why they would set this up for weapons only, but not have it effect monster attacks. Don't see why you would want to adjust only attack weapons, but not monster attacks with this routine.

It was embedded in this nested loop, which is triggered when the CalculateWeaponAttackDamage routine is hit.

Code: Select all

// Handle weapon attacks
            else if (weapon != null)
            {
                // Apply weapon material modifier.
                chanceToHitMod += CalculateWeaponToHit(weapon);

                // Mod hook for adjusting final hit chance mod and adding new elements to calculation. (no-op in DFU)
                chanceToHitMod = AdjustWeaponHitChanceMod(attacker, target, chanceToHitMod, weaponAnimTime, weapon);

                if (CalculateSuccessfulHit(attacker, target, chanceToHitMod, struckBodyPart))
                {
                    damage = CalculateWeaponAttackDamage(attacker, target, damageModifiers, weaponAnimTime, weapon);

                    damage = CalculateBackstabDamage(damage, backstabChance);
                }

                // Handle poisoned weapons
                if (damage > 0 && weapon.poisonType != Poisons.None)
                {
                    InflictPoison(target, weapon.poisonType, false);
                    weapon.poisonType = Poisons.None;
                }
            }
Lets see if I can find a way to get around this without have to also rebauilt the whole calculateattackdamage.
My Skyrim Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

l3lessed
Posts: 336
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Acquiring the Enemy Target Causing Damage

Post by l3lessed » Fri May 22, 2020 10:02 pm

Okay, so, I can get the monster hit from the onmonsterhit formula. Now, I need to find a way to stop the player damage using the object and move it to a var for shield damage use.
My Skyrim Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

l3lessed
Posts: 336
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Acquiring the Enemy Target Causing Damage

Post by l3lessed » Fri May 22, 2020 10:19 pm

Code: Select all

        public static void OnMonsterHit(EnemyEntity attacker, DaggerfallEntity target, int damage)
        {
            Func<EnemyEntity, DaggerfallEntity, int, bool> del;
            if (TryGetOverride("OnMonsterHit", out del))
                del(attacker, target, damage);
Is this a bug? This is a static void, and the override is using a fuct delegate that requires a bool return. However, you can't do a bool return, because the base routine is a static void, not a bool.

I can't seem to get the override setup, because the mismatch between the routine and the func<>.
My Skyrim Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
Magicono43
Posts: 279
Joined: Tue Nov 06, 2018 7:06 am

Re: Acquiring the Enemy Target Causing Damage

Post by Magicono43 » Fri May 22, 2020 10:26 pm

No I don't think so, I recall Hazelnut telling me at some point when I asked something similar on another method that he did that on purpose so the modder overriding it could return a true or false to the delegate method to tell it to run or not, something around those lines I believe.

l3lessed
Posts: 336
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Acquiring the Enemy Target Causing Damage

Post by l3lessed » Tue May 26, 2020 8:03 pm

Got it. As usual, I made it much harder than needed to try and ensure I didn't cause mod incompatibilities.

Once I threw that out the window, took me a whole 10 minutes to rewrite the calculateattackdamage formula. I'll leave all other formulas untouched so I have minimum patching to do in the future. You can see the video of most recent work on my combat overhaul thread.

Thanks everyone for the help.
My Skyrim Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
Ralzar
Posts: 1085
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Re: Acquiring the Enemy Target Causing Damage

Post by Ralzar » Tue May 26, 2020 9:46 pm

Good to hear it worked out :)


I am starting to think that at some point someone will make a formulahelper compatability mod.

Basically a mod that does all the overrides, sets itself to load after all mods
it's made for, checks which of those mods are loaded and adjusts the overridden formulas to use custom-built copies of those mods override code.

Alternatively would be a mod like that which then other mods used to get their code merged together.

Either way: jeez :D
My released mods

"I feel like Ralzar specifically wrote those mods for me and then said "Use them". Just so he could watch me die more."
-FuzzyBeanPlays

Post Reply