Enemies can cast infinite spells...

Post here if you need help getting started with Daggerfall Unity or just want to clarify a potential bug. Questions about playing or modding classic Daggerfall should be posted to Community.
Post Reply
User avatar
DunnyOfPenwick
Posts: 275
Joined: Wed Apr 14, 2021 1:58 am
Location: Southeast US

Enemies can cast infinite spells...

Post by DunnyOfPenwick »

Enemies can cast spells even if they have zero magicka. I assume this is a bug(?) and not intended.
There is no spell cost check in EntityEffectManager.SetReadySpell() for enemies, only the player.

Also, the call to CalculateTotalEffectCosts() in EntityEffectManager.SetReadySpell() line 320 passes a caster value of null, which causes the spell cost to be calculated based on the player character's skill values instead of the enemy caster's.

User avatar
pango
Posts: 3347
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Enemies can cast infinite spells...

Post by pango »

DunnyOfPenwick wrote: Sat Nov 19, 2022 8:37 pm Enemies can cast spells even if they have zero magicka. I assume this is a bug(?) and not intended.
Looking at the comments, it seems intended to me:

Code: Select all

// Classic does not enforce this for enemies, they can cast any spell as long as they still have at least 1 spell point.
// Doing the same here. This also matters for classic AI combat logic, as it uses the existence of any remaining spell points
// to determine whether or not it can still cast spells.
https://github.com/Interkarma/daggerfal ... er.cs#L326
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

User avatar
DunnyOfPenwick
Posts: 275
Joined: Wed Apr 14, 2021 1:58 am
Location: Southeast US

Re: Enemies can cast infinite spells...

Post by DunnyOfPenwick »

According to the comment, classic allows enemies to cast as long as magicka is greater than zero.
In the current build, the enemy magicka isn't checked at all.
Spells that drain magicka are useless, and a strategy of depleting an enemy's magicka is not possible.

<edit>I'm currently working on a mod that alters enemy spellcasting. This bug might make some enemies almost unkillable due to infinite heal spells.

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

Re: Enemies can cast infinite spells...

Post by Interkarma »

DunnyOfPenwick wrote: Sun Nov 20, 2022 4:04 pm According to the comment, classic allows enemies to cast as long as magicka is greater than zero.
In the current build, the enemy magicka isn't checked at all.
Spells that drain magicka are useless, and a strategy of depleting an enemy's magicka is not possible.
Enemy spellpoints are checked by their AI and they will stop casting spells once their spell points reach 0. Relevant code is in EnemyMotor CanCastRangedSpell/CanCastTouchSpell. I just tested this with multiple enemies and they stopped casting at 0 spell points as intended. This is not a bug in base DFU that I can reproduce. Maybe an edge case or result of other mod changes?

The code linked by Pango applies only to player spell point checks which is why enemies aren't evaluated there. The comment correctly describes the behaviour however and why code block only applies to player.

DunnyOfPenwick wrote: Sat Nov 19, 2022 8:37 pm Also, the call to CalculateTotalEffectCosts() in EntityEffectManager.SetReadySpell() line 320 passes a caster value of null, which causes the spell cost to be calculated based on the player character's skill values instead of the enemy caster's.
Yes, this is apparently accurate. I can't find the discussion with Allofich right now, but my understanding is this matches classic. Enemy casting skill essentially scales with player.

User avatar
DunnyOfPenwick
Posts: 275
Joined: Wed Apr 14, 2021 1:58 am
Location: Southeast US

Re: Enemies can cast infinite spells...

Post by DunnyOfPenwick »

...Relevant code is in EnemyMotor CanCastRangedSpell/CanCastTouchSpell.
Yep, I see it. I added additional spellcasting code in my mod and didn't realize I should check magicka myself.
...Enemy casting skill essentially scales with player.
That's rather strange. So enemy spellcasters get nerfed if the player-character has low magic skills?
I might have to calculate and reset enemy magicka myself.

Post Reply