Ranged Enemies Throw Their Weapons At You

Discuss modding questions and implementation details.
User avatar
Magicono43
Posts: 175
Joined: Tue Nov 06, 2018 7:06 am

Ranged Enemies Throw Their Weapons At You

Post by Magicono43 » Fri Mar 06, 2020 5:14 pm

Just an interesting thing I found while testing some things with the combat formulas. Since enemies that are carrying weapons will automatically use the most damaging weapon in their inventory, if said weapon exceeds the damage that their base unarmed attacks would normally do.

This also means that whatever weapon is best in their inventory, is the weapon that will be used by them for ALL attacks, funny enough this includes ranged attacks such that warrior humanoids enemies use, like the archer and warrior. So the damage roll that those arrows flying at you are doing is determined by whatever weapon in the inventory has the highest attack. So that archer is likely throwing elven flails at you, or the warrior is actually throwing dwarven katanas at you.

Just thought someone might find that interesting/funny. Also of actual useful note, said weapon being used also effects their chances of landing hits, meaning the weapon they are using also benefits from whatever material hit modifier it has. So that thief using an iron long-sword has a -1 modifier to hit you, while that orcish mace wielding knight has a +5 modifier to hit you, in both melee AND ranged combat.

BadLuckBurt
Posts: 433
Joined: Sun Nov 05, 2017 8:30 pm

Re: Ranged Enemies Throw Their Weapons At You

Post by BadLuckBurt » Fri Mar 06, 2020 5:28 pm

There is a BowDamage function and a MeleeDamage function in EnemyAttack.cs so it does seem to be handled separately?

So can you support that with a code example? I'm not saying you're wrong but I do have a hard time believing that until I see proof :)

User avatar
Hazelnut
Posts: 2138
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Ranged Enemies Throw Their Weapons At You

Post by Hazelnut » Fri Mar 06, 2020 5:33 pm

I think this is correct Burt, it always uses the weapon held in right (primary) hand of the enemy. Unless I also missed something.

Just a note to say that if you use the enemy equipment module of Loot Realism then archers use their bow damage ranges. :) Although when you get close and they melee it will use the bow damage still. :D
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

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

Re: Ranged Enemies Throw Their Weapons At You

Post by Magicono43 » Fri Mar 06, 2020 5:39 pm

BadLuckBurt wrote:
Fri Mar 06, 2020 5:28 pm
There is a BowDamage function and a MeleeDamage function in EnemyAttack.cs so it does seem to be handled separately?

So can you support that with a code example? I'm not saying you're wrong but I do have a hard time believing that until I see proof :)
I was mostly going by the fact (at least without mods like Loot Realism) that when I had the debug log output what skillID the enemy was currently using whenever it performed an attack, that I saw it did not change from say 29 being for long-sword to 33 for archery when they used their ranged attacks. Neither did their hit-chance mod, which would be based on the material of the weapon they were using.

BadLuckBurt
Posts: 433
Joined: Sun Nov 05, 2017 8:30 pm

Re: Ranged Enemies Throw Their Weapons At You

Post by BadLuckBurt » Fri Mar 06, 2020 6:11 pm

Alright but then this code doesn't work as intended? If they always use their 'best' weapon, that seems like a big bug to me :shock:

EnemyAttack.cs:

Code: Select all

	void Update()
        {
            // Unable to attack if paralyzed
            if (entityBehaviour.Entity.IsParalyzed)
                return;

            // If a melee attack has reached the damage frame we can run a melee attempt
            if (mobile.DoMeleeDamage)
            {
                MeleeDamage();
                mobile.DoMeleeDamage = false;
            }
            // If a bow attack has reached the shoot frame we can shoot an arrow
            else if (mobile.ShootArrow)
            {
                ShootBow();
                mobile.ShootArrow = false;

                DaggerfallAudioSource dfAudioSource = GetComponent<DaggerfallAudioSource>();
                if (dfAudioSource)
                    dfAudioSource.PlayOneShot((int)SoundClips.ArrowShoot, 1, 1.0f);
            }
        }

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

Re: Ranged Enemies Throw Their Weapons At You

Post by Magicono43 » Fri Mar 06, 2020 6:29 pm

BadLuckBurt wrote:
Fri Mar 06, 2020 6:11 pm
Alright but then this code doesn't work as intended? If they always use their 'best' weapon, that seems like a big bug to me :shock:

EnemyAttack.cs:

Code: Select all

	void Update()
        {
            // Unable to attack if paralyzed
            if (entityBehaviour.Entity.IsParalyzed)
                return;

            // If a melee attack has reached the damage frame we can run a melee attempt
            if (mobile.DoMeleeDamage)
            {
                MeleeDamage();
                mobile.DoMeleeDamage = false;
            }
            // If a bow attack has reached the shoot frame we can shoot an arrow
            else if (mobile.ShootArrow)
            {
                ShootBow();
                mobile.ShootArrow = false;

                DaggerfallAudioSource dfAudioSource = GetComponent<DaggerfallAudioSource>();
                if (dfAudioSource)
                    dfAudioSource.PlayOneShot((int)SoundClips.ArrowShoot, 1, 1.0f);
            }
        }
Hmm, I have not tested what I just did as a werewolf, so i'll probably have to give that a shot and see what the AI does, like see if they change to using HtH like the "MeleeDamage" method says they should do in that case.

The code that seems to determine whether an enemy uses a weapon or not seems to be this from
FormulaHelper.cs:

Code: Select all

// Choose whether weapon-wielding enemies use their weapons or weaponless attacks.
            // In classic, weapon-wielding enemies use the damage values of their weapons
            // instead of their weaponless values.
            // For some enemies this gives lower damage than similar-tier monsters
            // and the weaponless values seems more appropriate, so here
            // enemies will choose to use their weaponless attack if it is more damaging.
            EnemyEntity AIAttacker = attacker as EnemyEntity;
            if (AIAttacker != null && weapon != null)
            {
                int weaponAverage = (weapon.GetBaseDamageMin() + weapon.GetBaseDamageMax()) / 2;
                int noWeaponAverage = (AIAttacker.MobileEnemy.MinDamage + AIAttacker.MobileEnemy.MaxDamage) / 2;

                if (noWeaponAverage > weaponAverage)
                {
                    // Use hand-to-hand
                    weapon = null;
                }
            }

BadLuckBurt
Posts: 433
Joined: Sun Nov 05, 2017 8:30 pm

Re: Ranged Enemies Throw Their Weapons At You

Post by BadLuckBurt » Fri Mar 06, 2020 6:39 pm

The comment there seems to imply it's intentional. Feels weird to me, they should just hit you with whatever they're using, not whatever's the most damaging imo. But consider me convinced that your observation is correct, it just confuses the hell out of me :o

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

Re: Ranged Enemies Throw Their Weapons At You

Post by Magicono43 » Fri Mar 06, 2020 6:46 pm

Yeah, I personally have no clue how the inventory of enemies work, so I don't really know what tells them which weapon they happen to be holding is the one they should be using or not. In fact, I had no idea that enemies even had a system or "right-hand" "left-hand" like the player does with their inventory.

One definite bug that I may have found when trying to become a vampire/werewolf or even give myself any disease through the console command. I gave myself yellow-fever, and waited 8 hours like five times and my health and stats were all still perfect, so not sure if that command is known to be non-functional, or maybe I just did something wrong.

BadLuckBurt
Posts: 433
Joined: Sun Nov 05, 2017 8:30 pm

Re: Ranged Enemies Throw Their Weapons At You

Post by BadLuckBurt » Fri Mar 06, 2020 6:55 pm

Magicono43 wrote:
Fri Mar 06, 2020 6:46 pm
Yeah, I personally have no clue how the inventory of enemies work, so I don't really know what tells them which weapon they happen to be holding is the one they should be using or not. In fact, I had no idea that enemies even had a system or "right-hand" "left-hand" like the player does with their inventory.

One definite bug that I may have found when trying to become a vampire/werewolf or even give myself any disease through the console command. I gave myself yellow-fever, and waited 8 hours like five times and my health and stats were all still perfect, so not sure if that command is known to be non-functional, or maybe I just did something wrong.
If you're fresh out of Privateer's Hold, that might cause you to not be infected. There's some protection in place to save new characters. I've used the console before to give myself lycanthropy so that definitely works.

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

Re: Ranged Enemies Throw Their Weapons At You

Post by Magicono43 » Fri Mar 06, 2020 7:23 pm

BadLuckBurt wrote:
Fri Mar 06, 2020 6:55 pm
Magicono43 wrote:
Fri Mar 06, 2020 6:46 pm
Yeah, I personally have no clue how the inventory of enemies work, so I don't really know what tells them which weapon they happen to be holding is the one they should be using or not. In fact, I had no idea that enemies even had a system or "right-hand" "left-hand" like the player does with their inventory.

One definite bug that I may have found when trying to become a vampire/werewolf or even give myself any disease through the console command. I gave myself yellow-fever, and waited 8 hours like five times and my health and stats were all still perfect, so not sure if that command is known to be non-functional, or maybe I just did something wrong.
If you're fresh out of Privateer's Hold, that might cause you to not be infected. There's some protection in place to save new characters. I've used the console before to give myself lycanthropy so that definitely works.
I was thinking there was something like that, never really thought Privateer's Hold would pull some punches like that. Might even be some protection for level 1 characters since I left the hold and got infected by an actual wereboar, but still not seeing any changes. Will now have to try on a higher level character and see if it works.

Post Reply