Skip to content

Commit

Permalink
Apply saving throw flags from race template
Browse files Browse the repository at this point in the history
Removes hardcoded high elf immunity from FormulaHelper and uses flags set by RaceTemplate instead. Moves application of player racial flags up in the file so that the saving throw can be assigned to 100 before modification.
  • Loading branch information
numidium committed Aug 14, 2024
1 parent 7f059e7 commit 204e97a
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions Assets/Scripts/Game/Formulas/FormulaHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1460,14 +1460,24 @@ public static int SavingThrow(DFCareer.Elements elementType, DFCareer.EffectFlag
int biographyMod = 0;

PlayerEntity playerEntity = GameManager.Instance.PlayerEntity;

// Apply player racial flags
if (target == playerEntity)
{
var raceTemplate = playerEntity.GetLiveRaceTemplate();
if (SpellHasFlags(elementType, raceTemplate.ResistanceFlags, effectFlags))
savingThrow += 30;
if (SpellHasFlags(elementType, raceTemplate.ImmunityFlags, effectFlags))
savingThrow = 100;
if (SpellHasFlags(elementType, raceTemplate.LowToleranceFlags, effectFlags))
savingThrow -= 25;
if (SpellHasFlags(elementType, raceTemplate.CriticalWeaknessFlags, effectFlags))
savingThrow -= 50;
}

if ((effectFlags & DFCareer.EffectFlags.Paralysis) != 0)
{
toleranceFlags |= GetToleranceFlag(target.Career.Paralysis);
// Innate immunity if high elf. Start with 100 saving throw, but can be modified by
// tolerance flags. Note this differs from classic, where high elves have 100% immunity
// regardless of tolerance flags.
if (target == playerEntity && playerEntity.Race == Races.HighElf)
savingThrow = 100;
}
if ((effectFlags & DFCareer.EffectFlags.Magic) != 0)
{
Expand Down Expand Up @@ -1510,18 +1520,6 @@ public static int SavingThrow(DFCareer.Elements elementType, DFCareer.EffectFlag

savingThrow += biographyMod + modifier;

// Apply player racial resistances
if (target == playerEntity)
{
var raceTemplate = playerEntity.GetLiveRaceTemplate();
if ((elementType == DFCareer.Elements.Fire && (raceTemplate.ResistanceFlags & DFCareer.EffectFlags.Fire) != 0) ||
(elementType == DFCareer.Elements.Frost && (raceTemplate.ResistanceFlags & DFCareer.EffectFlags.Frost) != 0) ||
(elementType == DFCareer.Elements.DiseaseOrPoison && (raceTemplate.ResistanceFlags & effectFlags & (DFCareer.EffectFlags.Disease | DFCareer.EffectFlags.Poison)) != 0) ||
(elementType == DFCareer.Elements.Shock && (raceTemplate.ResistanceFlags & DFCareer.EffectFlags.Shock) != 0) ||
(elementType == DFCareer.Elements.Magic && (raceTemplate.ResistanceFlags & DFCareer.EffectFlags.Magic) != 0))
savingThrow += 30;
}

// Handle perfect immunity of 100% or greater
// Otherwise clamping to 5-95 allows a perfectly immune character to sometimes receive incoming payload
// This doesn't seem to match immunity intent or player expectations from classic
Expand All @@ -1548,6 +1546,16 @@ public static int SavingThrow(DFCareer.Elements elementType, DFCareer.EffectFlag
return Mathf.Clamp(percentDamageOrDuration, 0, 100);
}

private static bool SpellHasFlags(DFCareer.Elements elementType, DFCareer.EffectFlags checkFlags, DFCareer.EffectFlags spellEffectFlags)
{
return (elementType == DFCareer.Elements.Fire && (checkFlags & DFCareer.EffectFlags.Fire) != 0) ||
(elementType == DFCareer.Elements.Frost && (checkFlags & DFCareer.EffectFlags.Frost) != 0) ||
(elementType == DFCareer.Elements.DiseaseOrPoison && (checkFlags & spellEffectFlags & (DFCareer.EffectFlags.Disease | DFCareer.EffectFlags.Poison)) != 0) ||
(elementType == DFCareer.Elements.Shock && (checkFlags & DFCareer.EffectFlags.Shock) != 0) ||
(elementType == DFCareer.Elements.Magic && (checkFlags & DFCareer.EffectFlags.Magic) != 0) ||
(spellEffectFlags & DFCareer.EffectFlags.Paralysis) != 0 && (checkFlags & DFCareer.EffectFlags.Paralysis) != 0;
}

public static int SavingThrow(IEntityEffect sourceEffect, DaggerfallEntity target)
{
Func<IEntityEffect, DaggerfallEntity, int> del;
Expand Down

0 comments on commit 204e97a

Please sign in to comment.