Acquiring the Enemy Target Causing Damage

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

Re: Acquiring the Enemy Target Causing Damage

Post by l3lessed » Fri May 22, 2020 7:28 am

I give up for now. Outside rebuilding the whole formula helper, like you have done, I don't see an easy way to intercept the damage value, dump it into a var, and set it to 0. I also don't want to rebuild it because then this will start to conflict with yours and others mods. Either I have to find some unknown way of retrieving non-public vars or I'm overlooking a public accessible var or object that can help with this.

Guess, its time for cheesy work around. I'll just set player health to infinite, intercept the damage done, and reset player health to previous levels when block is done.
Last edited by l3lessed on Fri May 22, 2020 7:52 am, edited 1 time in total.
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: 1069
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Re: Acquiring the Enemy Target Causing Damage

Post by Ralzar » Fri May 22, 2020 7:35 am

I think you're overcomplicating things. Me and Magicono is pretty much programming noobs and this was soemthing we could pick right up wihtout much effort.

All you need is to override one part of the combat formula that already checks who is attacking and what damage they cause and have your override version of the method do whatever you need it to.
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

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

Re: Acquiring the Enemy Target Causing Damage

Post by Ralzar » Fri May 22, 2020 7:45 am

I would reccommend just overriding this:

https://github.com/Interkarma/daggerfal ... r.cs#L1030

As it is made specifically to be used by mods to change the damage claculation at the end to adjust the result before passing the resulting damage back to the game.


And it takes

DaggerfallEntity attacker, DaggerfallEntity target, int damage, DaggerfallUnityItem weapon, int struckBodyPart

So you wind up with most or all of the values you were looking for.
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

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

Re: Acquiring the Enemy Target Causing Damage

Post by l3lessed » Fri May 22, 2020 7:54 am

Oh jesus, there it was. I have been banging my head against the formula helper for an easy one to override, so as to ensure not to screw with anything and ensure max compatibility, and here it is. Thank you so much, this will be very helpful for future modding.

However, I'm stuck with one lost issue. How can I retrieve the amount of damage calculated before I override it using that method?

Nevermind. I will use the target pulled from the overriden formula and then use the formula helper calculateattackdamage to get how much the enemy would have done, if i hadn't zeroed it.

The idea is to use the damage to allow for dynamic fatigue costs, and then zero them out afterwards. But, I can't grab the original damage before zeroing it out.
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: 1069
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Re: Acquiring the Enemy Target Causing Damage

Post by Ralzar » Fri May 22, 2020 8:24 am

Only problem with mod compatability is that only the last override counts. And if someone overrides an earlier method with code that no longer passes the result through your code.

There's unfortunately a lot of potantial of incompatible code with the formula override. Unless we make sure to get stuff to match up (and potentially insert parts of eachotehers code into our own mods) there is a high chance of combat mods breaking eachother. There is already a bit of friction between Hazelnuts "RP&R: Items" mod and Magiconos combat mod. This will only get worse as more mods appear.
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

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

Re: Acquiring the Enemy Target Causing Damage

Post by Magicono43 » Fri May 22, 2020 10:28 am

As Ralzar said with compatibility thing, sometimes people will just have to realize that not everything they put in their mod list is going to meld well together. Probably the "best" way to get around this would be for modders with basically feature complete mods to make compatibility patches or something if the demand for something around those lines is that high.

Something I did, (that is admittedly not a very good way) is take parts of other mods code that I know won't be compatible with mine, and just make a setting with that code and try and give some option to make the best of both worlds, but it's not pretty most of the time.

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

Re: Acquiring the Enemy Target Causing Damage

Post by l3lessed » Fri May 22, 2020 4:22 pm

My exact fear. I didn't want to have to go down patching road. I've been modding for years. I know how this goes.

However, I'll use the formula override method for now.

Modders need to be able to pull the target of the enemy hitting the player easily. This could be done by making the target object in the enemy attack script a public { get; set private instance }, then either the modders could if then switch for the player themselves, or a switch could be added to enemyattack.cs.

Without this, it is going to be hard to create certain things easily.
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: 271
Joined: Tue Nov 06, 2018 7:06 am

Re: Acquiring the Enemy Target Causing Damage

Post by Magicono43 » Fri May 22, 2020 5:17 pm

l3lessed wrote:
Fri May 22, 2020 4:22 pm
My exact fear. I didn't want to have to go down patching road. I've been modding for years. I know how this goes.

However, I'll use the formula override method for now.

Modders need to be able to pull the target of the enemy hitting the player easily. This could be done by making the target object in the enemy attack script a public { get; set private instance }, then either the modders could if then switch for the player themselves, or a switch could be added to enemyattack.cs.

Without this, it is going to be hard to create certain things easily.
Can always try and put a Pull-Request through if you know what you need in that case and it could get approved for modding ease. I'll be having to this myself for the mod i'm currently working on for multiple base-scripts, making previously private methods and parameters protected or public and such.

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

Re: Acquiring the Enemy Target Causing Damage

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

Yep, until then, I hit another snag.

My code seems to be setup for the override, but it doesn't seem to be actually doing the override/submitting it to formula helper. To check I dropped in a quick screen popup message, and it isn't appearing when I take damage and the override should kick in.

Here is the code setting it up based off numerous scripts I looked at already working. I need to get to work for my job, so I'm taking a break from this. If someone can take a quick look at this code, and tell me what is wrong.

Code: Select all

namespace DaggerfallWorkshop.Game.FPSShield
{
    public class FPSShield : MonoBehaviour
    {

        #region UI Rects
        Rect shieldPos = new Rect(0, Screen.height - 400, 850, 850 );
        #endregion     

        //initiates mod instances for mod manager.
        static Mod mod;
        static FPSShield instance;
        static ModSettings settings;
        string blockKey;

        //initiates 2d textures for storing texture data.
        static Texture2D shieldTex;

        WeaponAnimation[] weaponAnims;
        Rect curAnimRect;
        Rect[] weaponRects;
        // Get weapon scale
        float shieldScaleX;
        float shieldScaleY;
        //used for storing texture path for shield.
        string shieldTexture_Path;

        //used for lerp calculator. Need to create custom mod scripting hook files for myself and others.
        bool lerpfinished;
        bool isBlocking;
        bool cycled;
        bool blockFinished;
        bool breatheTrigger;
        float TimeCovered = 0;
        float xPos;
        float yPos;
        float size;
        float lastxPost;
        float lastyPost;
        float lastSize;
        float lastTimeCovered;
        float endTime;
        float shieldSize;
        float totalTime;
        float shieldDamage;
        float playerDamage;
        int cycleNum = 0;

        //sets up different class properties.
        #region Properties
        DaggerfallEntityBehaviour entityBehaviour;
        //sets up player entity class for easy retrieval and manipulation of player character.
        PlayerEntity playerEntity;
        //sets up player class instance properties for manipulation.
        public PlayerEntity PlayerEntity
        {
            get { return (playerEntity != null) ? playerEntity : playerEntity = GameManager.Instance.PlayerEntity; }
        }
        #endregion

        //starts mod manager on game begin. Grabs mod initializing paramaters.
        //ensures SateTypes is set to .Start for proper save data restore values.
        [Invoke(StateManager.StateTypes.Start, 0)]
        public static void Init(InitParams initParams)
        {
            Debug.Log("SHIELD MODULE STARTED!");
            //sets up instance of class/script/mod.
            GameObject go = new GameObject("FPSShield");
            instance = go.AddComponent<FPSShield>();
            //initiates mod paramaters for class/script.
            mod = initParams.Mod;
            //loads mods settings.
            settings = mod.GetSettings();
            //initiates save paramaters for class/script.
            //mod.SaveDataInterface = instance;
            //after finishing, set the mod's IsReady flag to true.
            mod.IsReady = true;

            Func<DaggerfallEntity, DaggerfallEntity, int, int, DaggerfallUnityItem, int> attack = (a, b, c, d, e) => {
                Debug.Log("**********Override hit: 100%");
                int? dam = AdjustWeaponAttackDamage(a, b, c, d, e);

                if (dam == null)
                    return 0;

                if (dam <= 0)
                    dam = 1;

                DaggerfallUI.Instance.PopupMessage("Blocked: " + dam);

                return (int)dam;
            };
            FormulaHelper.RegisterOverride(mod, "AdjustWeaponAttackDamage", attack);
        }
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: 271
Joined: Tue Nov 06, 2018 7:06 am

Re: Acquiring the Enemy Target Causing Damage

Post by Magicono43 » Fri May 22, 2020 6:29 pm

From my uses of them:

Code: Select all

FormulaHelper.RegisterOverride(mod, "DamageModifier", (Func<int, int>)DamageModifier);
It looks like you forgot the "Func<int, int>" parts, that's the main thing I see that might be causing a problem with the delegate thing.

Post Reply