Core: Combat/threat system rewrite

Port From (https://github.com/TrinityCore/TrinityCore/commit/34c7810fe507eca1b8b9389630db5d5d26d92e77)
This commit is contained in:
hondacrx
2021-05-18 12:25:40 -04:00
parent 891c3b6478
commit 9851142796
37 changed files with 3454 additions and 3345 deletions
+28 -3
View File
@@ -274,6 +274,8 @@ namespace Game.Entities
}
}
}
UpdatePetCombatState();
}
public bool SetCharmedBy(Unit charmer, CharmType type, AuraApplication aurApp = null)
@@ -314,7 +316,6 @@ namespace Game.Entities
CastStop();
CombatStop(); // @todo CombatStop(true) may cause crash (interrupt spells)
GetThreatManager().ClearAllThreat();
Player playerCharmer = charmer.ToPlayer();
@@ -463,8 +464,6 @@ namespace Game.Entities
CastStop();
CombatStop(); // @todo CombatStop(true) may cause crash (interrupt spells)
GetHostileRefManager().DeleteReferences();
GetThreatManager().ClearAllThreat();
if (_oldFactionId != 0)
{
@@ -545,6 +544,8 @@ namespace Game.Entities
player.SetClientControl(this, true);
}
EngageWithTarget(charmer);
// a guardian should always have charminfo
if (playerCharmer && this != charmer.GetFirstControlled())
playerCharmer.SendRemoveControlBar();
@@ -651,6 +652,8 @@ namespace Game.Entities
m_Controlled.Remove(charm);
}
}
UpdatePetCombatState();
}
public Unit GetFirstControlled()
@@ -698,6 +701,8 @@ namespace Game.Entities
Log.outFatal(LogFilter.Unit, "Unit {0} is not able to release its minion {1}", GetEntry(), GetMinionGUID());
if (!GetCharmGUID().IsEmpty())
Log.outFatal(LogFilter.Unit, "Unit {0} is not able to release its charm {1}", GetEntry(), GetCharmGUID());
if (!IsPet()) // pets don't use the flag for this
RemoveUnitFlag(UnitFlags.PetInCombat); // m_controlled is now empty, so we know none of our minions are in combat
}
public void SendPetActionFeedback(PetActionFeedback msg, uint spellId)
@@ -794,5 +799,25 @@ namespace Game.Entities
pet.SetFullHealth();
return true;
}
public void UpdatePetCombatState()
{
Cypher.Assert(!IsPet()); // player pets do not use UNIT_FLAG_PET_IN_COMBAT for this purpose - but player pets should also never have minions of their own to call this
bool state = false;
foreach (Unit minion in m_Controlled)
{
if (minion.IsInCombat())
{
state = true;
break;
}
}
if (state)
AddUnitFlag(UnitFlags.PetInCombat);
else
RemoveUnitFlag(UnitFlags.PetInCombat);
}
}
}