Fixed a crash with AISpellInfoType having cooldown default to 0 should be default 5000.

This commit is contained in:
hondacrx
2021-07-03 11:37:20 -04:00
parent 2bc0446de2
commit 1d5337d3f7
6 changed files with 40 additions and 22 deletions
+1 -1
View File
@@ -45,7 +45,7 @@ namespace Framework.Constants
Unknown = 5 // found in 2.2.3 for 2 mobs Unknown = 5 // found in 2.2.3 for 2 mobs
} }
[System.Flags] [Flags]
public enum UnitFlags : uint public enum UnitFlags : uint
{ {
ServerControlled = 0x01, ServerControlled = 0x01,
@@ -189,6 +189,7 @@ namespace Framework.Constants
public const int BoundaryVisualizeStepSize = 1; public const int BoundaryVisualizeStepSize = 1;
public const int BoundaryVisualizeFailsafeLimit = 750; public const int BoundaryVisualizeFailsafeLimit = 750;
public const int BoundaryVisualizeSpawnHeight = 5; public const int BoundaryVisualizeSpawnHeight = 5;
public const uint AIDefaultCooldown = 5000;
/// <summary> /// <summary>
/// GameObject Const /// GameObject Const
+10 -2
View File
@@ -46,7 +46,7 @@ namespace Game.AI
foreach (var id in Spells) foreach (var id in Spells)
{ {
AISpellInfoType info = GetAISpellInfo(id, me.GetMap().GetDifficultyID()); AISpellInfoType info = GetAISpellInfo(id, me.GetMap().GetDifficultyID());
if (info.condition == AICondition.Die) if (info != null && info.condition == AICondition.Die)
me.CastSpell(killer, id, true); me.CastSpell(killer, id, true);
} }
} }
@@ -56,12 +56,15 @@ namespace Game.AI
foreach (var id in Spells) foreach (var id in Spells)
{ {
AISpellInfoType info = GetAISpellInfo(id, me.GetMap().GetDifficultyID()); AISpellInfoType info = GetAISpellInfo(id, me.GetMap().GetDifficultyID());
if (info != null)
{
if (info.condition == AICondition.Aggro) if (info.condition == AICondition.Aggro)
me.CastSpell(victim, id, false); me.CastSpell(victim, id, false);
else if (info.condition == AICondition.Combat) else if (info.condition == AICondition.Combat)
_events.ScheduleEvent(id, info.cooldown + RandomHelper.Rand32() % info.cooldown); _events.ScheduleEvent(id, info.cooldown + RandomHelper.Rand32() % info.cooldown);
} }
} }
}
public override void UpdateAI(uint diff) public override void UpdateAI(uint diff)
{ {
@@ -78,6 +81,7 @@ namespace Game.AI
{ {
DoCast(spellId); DoCast(spellId);
AISpellInfoType info = GetAISpellInfo(spellId, me.GetMap().GetDifficultyID()); AISpellInfoType info = GetAISpellInfo(spellId, me.GetMap().GetDifficultyID());
if (info != null)
_events.ScheduleEvent(spellId, info.cooldown + RandomHelper.Rand32() % info.cooldown); _events.ScheduleEvent(spellId, info.cooldown + RandomHelper.Rand32() % info.cooldown);
} }
else else
@@ -121,7 +125,7 @@ namespace Game.AI
foreach (var id in Spells) foreach (var id in Spells)
{ {
AISpellInfoType info = GetAISpellInfo(id, me.GetMap().GetDifficultyID()); AISpellInfoType info = GetAISpellInfo(id, me.GetMap().GetDifficultyID());
if (info.condition == AICondition.Combat && _attackDist > info.maxRange) if (info != null && info.condition == AICondition.Combat && _attackDist > info.maxRange)
_attackDist = info.maxRange; _attackDist = info.maxRange;
} }
@@ -144,6 +148,8 @@ namespace Game.AI
foreach (var id in Spells) foreach (var id in Spells)
{ {
AISpellInfoType info = GetAISpellInfo(id, me.GetMap().GetDifficultyID()); AISpellInfoType info = GetAISpellInfo(id, me.GetMap().GetDifficultyID());
if (info != null)
{
if (info.condition == AICondition.Aggro) if (info.condition == AICondition.Aggro)
me.CastSpell(victim, id, false); me.CastSpell(victim, id, false);
else if (info.condition == AICondition.Combat) else if (info.condition == AICondition.Combat)
@@ -158,6 +164,7 @@ namespace Game.AI
} }
} }
} }
}
public override void UpdateAI(uint diff) public override void UpdateAI(uint diff)
{ {
@@ -181,6 +188,7 @@ namespace Game.AI
DoCast(spellId); DoCast(spellId);
uint casttime = (uint)me.GetCurrentSpellCastTime(spellId); uint casttime = (uint)me.GetCurrentSpellCastTime(spellId);
AISpellInfoType info = GetAISpellInfo(spellId, me.GetMap().GetDifficultyID()); AISpellInfoType info = GetAISpellInfo(spellId, me.GetMap().GetDifficultyID());
if (info != null)
_events.ScheduleEvent(spellId, (casttime != 0 ? casttime : 500) + info.realCooldown); _events.ScheduleEvent(spellId, (casttime != 0 ? casttime : 500) + info.realCooldown);
} }
} }
+8 -1
View File
@@ -491,8 +491,15 @@ namespace Game.AI
public List<AreaBoundary> GetBoundary() { return _boundary; } public List<AreaBoundary> GetBoundary() { return _boundary; }
} }
public struct AISpellInfoType public class AISpellInfoType
{ {
public AISpellInfoType()
{
target = AITarget.Self;
condition = AICondition.Combat;
cooldown = SharedConst.AIDefaultCooldown;
}
public AITarget target; public AITarget target;
public AICondition condition; public AICondition condition;
public uint cooldown; public uint cooldown;
+5 -3
View File
@@ -252,9 +252,13 @@ namespace Game.AI
public void DoCast(uint spellId) public void DoCast(uint spellId)
{ {
Unit target = null; Unit target = null;
AITarget aiTargetType = AITarget.Self;
AISpellInfoType info = GetAISpellInfo(spellId, me.GetMap().GetDifficultyID()); AISpellInfoType info = GetAISpellInfo(spellId, me.GetMap().GetDifficultyID());
switch (info.target) if (info != null)
aiTargetType = info.target;
switch (aiTargetType)
{ {
default: default:
case AITarget.Self: case AITarget.Self:
@@ -321,8 +325,6 @@ namespace Game.AI
public static void FillAISpellInfo() public static void FillAISpellInfo()
{ {
//AISpellInfo = new AISpellInfoType[spellStorage.Keys.Max() + 1];
Global.SpellMgr.ForEachSpellInfo(spellInfo => Global.SpellMgr.ForEachSpellInfo(spellInfo =>
{ {
AISpellInfoType AIInfo = new(); AISpellInfoType AIInfo = new();
+1 -1
View File
@@ -223,7 +223,7 @@ namespace Game.AI
AISpellInfoType aiSpell = GetAISpellInfo(me.m_spells[i], me.GetMap().GetDifficultyID()); AISpellInfoType aiSpell = GetAISpellInfo(me.m_spells[i], me.GetMap().GetDifficultyID());
//This spell doesn't exist //This spell doesn't exist
if (tempSpell == null) if (tempSpell == null || aiSpell == null)
continue; continue;
// Targets and Effects checked first as most used restrictions // Targets and Effects checked first as most used restrictions