[0.10.24] Player And Enemy NPCs Die At 1 Attribute Score, Rather Than Only 0 [RESOLVED 0.10.26]

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

[0.10.24] Player And Enemy NPCs Die At 1 Attribute Score, Rather Than Only 0 [RESOLVED 0.10.26]

Post by Magicono43 »

Describe the bug
When the player or an enemy NPC goes below 2 in any attribute, they die instantly. Now at least for the player, this is intended behavior, but this is only supposed to happen when an attribute goes to 0 or lower, not 1 or lower. By consequence this causes another "bug" with the Drainstat effect, which can be seen in the code, that a drain stat effect is not supposed to be able to bring an entity below 1 in any attribute, as to prevent them from being killed by cumulative drain effects, but since they die at 1, this preventative code does not function. So any enemy can be instantly killed with a few applications of a drain effect, luck being generally the most effective since most enemies have an average luck overall.

To Reproduce
Steps to reproduce the behavior:

Example 1:
- Create a "Drain Attribute" spell, whichever you prefer, I like Target at Area.
- Start spamming casting at your feet with or without god mode active (you won't be killed while in god mode)
- If god mode is disabled, you will eventually die after hitting 1 in the drain attribute.
- If god mode enabled, once you exit god mode after your attribute hits 1, you will instantly die.

Example 2:
- The same can be reproduced for enemies. Cast this spell while in god-mode at any enemy, rat is good since they have generally low stats.
- Once you have cast the spell a few times and they don't resist, they will eventually die, no damage done, just drain effect.

Example 3:
- Another way to test, take any save-game, edit the character attributes to as low as 2, save the changes, load said file and notice your character is alive and will stay alive.
- Do the same process again, but instead change the attributes to as low as 1, save changes, load said file and notice your character instantly keels over and dies after the scene loads in.

Expected behavior
The player and enemies (I think) should only die if one of their attributes hits 0 or below, not 1 or below. Also, the drain spell effect should not be able to kill the player or enemies as it does.

Screenshots
No screenshots as it this can be fairly easily reproduced with console commands. If needed I can add some.

Desktop (please complete the following information):
OS: Windows
Version: Alpha 0.10.24
Additional context

Here is the code in the "DrainEffect.cs" that can be optionally altered to show that 1 attribute point is the limit for death, you can change the two "1's" in the if-statement to 2's and you nor enemies will die from the drain effect anymore, but this is not the root cause of the death, there is some other part of the process that is mistakenly having entities die from the wrong minimum attribute amount, and I still have not been able to pin-point where that is checked.

DrainEffects.cs

Code: Select all

public void IncreaseMagnitude(int amount)
        {
            DaggerfallEntityBehaviour host = GetPeeredEntityBehaviour(manager);

            // Do not allow magnitude to reduce stat below 1 relative to permanent value
            // Stats are clamped 1-100 and this prevents drain magnitude from going into invisible "healing debt"
            int permanentValue = host.Entity.Stats.GetPermanentStatValue(drainStat);
            if (permanentValue - (magnitude + amount) < 2)
                magnitude = permanentValue - 2;
            else
                magnitude += amount;

            SetStatMod(drainStat, -magnitude);
        }
Edit 1: Oh yeah, here is a save-file as well for even easier reproduction of steps, if needed:
SAVE354.rar
(185.87 KiB) Downloaded 126 times

User avatar
Interkarma
Posts: 7247
Joined: Sun Mar 22, 2015 1:51 am

Re: [0.10.24] Player And Enemy NPCs Die At 1 Attribute Score, Rather Than Only 0

Post by Interkarma »

This is by design to avoid underflow in the drain system. Entities will consequently perish when an attribute is reduced to 1 instead of 0.

I might look at re-engineering Drain later, but I don't see much issue at floor being 1 instead of 0.

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

Re: [0.10.24] Player And Enemy NPCs Die At 1 Attribute Score, Rather Than Only 0

Post by Magicono43 »

Interkarma wrote: Mon Jul 13, 2020 6:58 pm This is by design to avoid underflow in the drain system. Entities will consequently perish when an attribute is reduced to 1 instead of 0.

I might look at re-engineering Drain later, but I don't see much issue at floor being 1 instead of 0.
Yeah, after Burt explained Underflow a bit, and how it can become an issue with multi-threaded environments, I understand better why you did it like this.

Outside of the technical aspect of it though, did the drain spell effect used to be able to kill the player, just as poison or disease "drain effects" do? Burt said that he recalls the poison drain effect and spell drain effects to be linked together in classic, that I would assume that the drain spell could kill.

But after a test with many assassins it appears that in DFU these two drain effect "types" are no longer linked. So I guess in theory a mod or something could make it so the drain spell can't kill entities, but poison and disease still can. I have not tested in classic myself, because man, going back to DOSBOX after using DFU is such a pain now, lol.

User avatar
Interkarma
Posts: 7247
Joined: Sun Mar 22, 2015 1:51 am

Re: [0.10.24] Player And Enemy NPCs Die At 1 Attribute Score, Rather Than Only 0

Post by Interkarma »

Magicono43 wrote: Mon Jul 13, 2020 7:47 pm So I guess in theory a mod or something could make it so the drain spell can't kill entities, but poison and disease still can. I have not tested in classic myself, because man, going back to DOSBOX after using DFU is such a pain now, lol.
My memory is that Drain will kill player/enemies in classic if it reduces an attribute to 0, but years can pass and memory isn't reliable. I'm just as fallible as anyone and honestly appreciate the question. :)

I'll move this to bug reports and confirm whether Drain alone should be able to kill player/enemies by bottoming out attributes.

Edit: In classic - quickly created a Drain Agility area at range spell then blasted my poor test character several times. Drain alone does not result in character death and does not reduce attribute below 1. No further applications of Drain would reduce attribute below 1. I'll take a look at re-engineering this one later when I can.

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

Re: [0.10.24] Player And Enemy NPCs Die At 1 Attribute Score, Rather Than Only 0

Post by Magicono43 »

Interkarma wrote: Mon Jul 13, 2020 8:23 pm
Magicono43 wrote: Mon Jul 13, 2020 7:47 pm So I guess in theory a mod or something could make it so the drain spell can't kill entities, but poison and disease still can. I have not tested in classic myself, because man, going back to DOSBOX after using DFU is such a pain now, lol.
My memory is that Drain will kill player/enemies in classic if it reduces an attribute to 0, but years can pass and memory isn't reliable. I'm just as fallible as anyone and honestly appreciate the question. :)

I'll move this to bug reports and confirm whether Drain alone should be able to kill player/enemies by bottoming out attributes.

Edit: In classic - quickly created a Drain Agility area at range spell then blasted my poor test character several times. Drain alone does not result in character death and does not reduce attribute below 1. No further applications of Drain would reduce attribute below 1. I'll take a look at re-engineering this one later when I can.
Thanks for taking the time to do the testing. I'm glad my report was not in vein in this case. I think i'll have to do some testing with the speed bug report in classic as well and see how enemies react, my curiosity has been peaked somewhat here. :)

User avatar
Interkarma
Posts: 7247
Joined: Sun Mar 22, 2015 1:51 am

Re: [0.10.24] Player And Enemy NPCs Die At 1 Attribute Score, Rather Than Only 0 [RESOLVED 0.10.26]

Post by Interkarma »

I've refined this now.

https://github.com/Interkarma/daggerfal ... e062c5c3fe

As per most recent testing in classic, Drain effect will not lower attributes below 1 and by itself will not kill player/enemies.

Live attributes are now clamped between 0 to maximum. Entity will die if any attribute is reduced to 0 by any means. Most likely this will be from poison or disease lowering attributes to 0, or some combination of Drain/poison/disease. Just Drain by itself cannot lower attributes to 0.

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

Re: [0.10.24] Player And Enemy NPCs Die At 1 Attribute Score, Rather Than Only 0 [RESOLVED 0.10.26]

Post by Magicono43 »

Thanks for making the change IK. Now people will continue to not use the drain effect, and my desire for hard to cheese enemies can be validated. :lol:

Locked