Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor FormulaHelper to read racial resistances #2676

Merged
merged 4 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Assets/Scripts/Game/Entities/RaceTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ public Breton()

PaperDollHeadsMale = "FACE00I0.CIF";
PaperDollHeadsFemale = "FACE10I0.CIF";

ResistanceFlags = DFCareer.EffectFlags.Magic;
}
}

Expand Down
34 changes: 25 additions & 9 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 @@ -1509,10 +1519,6 @@ public static int SavingThrow(DFCareer.Elements elementType, DFCareer.EffectFlag
savingThrow += 25;

savingThrow += biographyMod + modifier;
if (elementType == DFCareer.Elements.Frost && target == playerEntity && playerEntity.Race == Races.Nord)
savingThrow += 30;
else if (elementType == DFCareer.Elements.Magic && target == playerEntity && playerEntity.Race == Races.Breton)
savingThrow += 30;

// Handle perfect immunity of 100% or greater
// Otherwise clamping to 5-95 allows a perfectly immune character to sometimes receive incoming payload
Expand Down Expand Up @@ -1540,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