Core/Creatures: Move immunities to separate table and implemented setting immunties to dispel, spell effects, aura types, aoe and chain targeting

Port From (https://github.com/TrinityCore/TrinityCore/commit/f70a5817e1c07891185d716611d45f50b1c73b78)
This commit is contained in:
hondacrx
2024-02-06 17:21:07 -05:00
parent f3993521bc
commit 7c812ae904
15 changed files with 216 additions and 98 deletions
+65 -1
View File
@@ -1,6 +1,7 @@
// Copyright (c) CypherCore <http://github.com/CypherCore> All rights reserved.
// Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information.
using Framework.Collections;
using Framework.Constants;
using Framework.Database;
using Framework.Dynamic;
@@ -12,6 +13,7 @@ using Game.Miscellaneous;
using Game.Movement;
using Game.Spells;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
@@ -603,6 +605,11 @@ namespace Game.Entities
return mSpellAreaForAreaMap.LookupByKey(area_id);
}
public CreatureImmunities GetCreatureImmunities(int creatureImmunitiesId)
{
return mCreatureImmunities.LookupByKey(creatureImmunitiesId);
}
public SpellInfo GetSpellInfo(uint spellId, Difficulty difficulty)
{
var list = mSpellInfoMap.LookupByKey(spellId);
@@ -4502,6 +4509,52 @@ namespace Game.Entities
{
uint oldMSTime = Time.GetMSTime();
mCreatureImmunities.Clear();
// 0 1 2 3 4 5 6 7
SQLResult result = DB.World.Query("SELECT ID, SchoolMask, DispelTypeMask, MechanicsMask, Effects, Auras, ImmuneAoE, ImmuneChain FROM creature_immunities");
if (!result.IsEmpty())
{
do
{
int id = result.Read<int>(0);
byte school = result.Read<byte>(1);
ushort dispelType = result.Read<ushort>(2);
ulong mechanics = result.Read<ulong>(3);
CreatureImmunities immunities = mCreatureImmunities[id];
immunities.School = new BitSet(new uint[] { school });
immunities.DispelType = new BitSet(new uint[] { dispelType });
immunities.Mechanic = new BitSet(mechanics);
immunities.ImmuneAoE = result.Read<bool>(6);
immunities.ImmuneChain = result.Read<bool>(7);
if (immunities.School.ToUInt() != school)
Log.outError(LogFilter.Sql, $"Invalid value in `SchoolMask` {school} for creature immunities {id}, truncated");
if (immunities.DispelType.ToUInt() != dispelType)
Log.outError(LogFilter.Sql, $"Invalid value in `DispelTypeMask` {dispelType} for creature immunities {id}, truncated");
if (immunities.Mechanic.ToUInt() != mechanics)
Log.outError(LogFilter.Sql, $"Invalid value in `MechanicsMask` {mechanics} for creature immunities {id}, truncated");
foreach (string token in new StringArray(result.Read<string>(4), ','))
{
if (uint.TryParse(token, out uint effect) && effect != 0 && effect < (int)SpellEffectName.TotalSpellEffects)
immunities.Effect.Add((SpellEffectName)effect);
else
Log.outError(LogFilter.Sql, $"Invalid effect type in `Effects` {token} for creature immunities {id}, skipped");
}
foreach (string token in new StringArray(result.Read<string>(5), ','))
{
if (uint.TryParse(token, out uint aura) && aura != 0 && aura < (int)AuraType.Total)
immunities.Aura.Add((AuraType)aura);
else
Log.outError(LogFilter.Sql, $"Invalid aura type in `Auras` {token} for creature immunities {id}, skipped");
}
}
while (result.NextRow());
}
foreach (SpellInfo spellInfo in mSpellInfoMap.Values)
{
if (spellInfo == null)
@@ -4811,6 +4864,7 @@ namespace Game.Entities
MultiMap<SpellGroup, AuraType> mSpellSameEffectStack = new();
List<ServersideSpellName> mServersideSpellNames = new();
Dictionary<(uint id, Difficulty difficulty), SpellProcEntry> mSpellProcMap = new();
Dictionary<int, CreatureImmunities> mCreatureImmunities = new();
Dictionary<uint, SpellThreatEntry> mSpellThreatMap = new();
Dictionary<uint, PetAura> mSpellPetAuraMap = new();
MultiMap<(SpellLinkedType, uint), int> mSpellLinkedMap = new();
@@ -4920,7 +4974,6 @@ namespace Game.Entities
}
}
public class PetDefaultSpellsEntry
{
public uint[] spellid = new uint[4];
@@ -5097,4 +5150,15 @@ namespace Game.Entities
public float target_Z;
public float target_Orientation;
}
public class CreatureImmunities
{
public BitSet School = new((int)SpellSchools.Max);
public BitSet DispelType = new((int)Framework.Constants.DispelType.Max);
public BitSet Mechanic = new((int)Mechanics.Max);
public List<SpellEffectName> Effect = new();
public List<AuraType> Aura = new();
public bool ImmuneAoE; // NYI
public bool ImmuneChain; // NYI
}
}