Core/Unit: Inline some unnecessary helpers.
Port From (https://github.com/TrinityCore/TrinityCore/commit/395f58d651c7c370522ead6ba9a3c684d91e3a66)
This commit is contained in:
@@ -551,8 +551,9 @@ namespace Game.Entities
|
|||||||
{
|
{
|
||||||
if (IsTypeId(TypeId.Player))
|
if (IsTypeId(TypeId.Player))
|
||||||
{
|
{
|
||||||
if (!SetCharmedData(charm))
|
Cypher.Assert(GetCharmedGUID().IsEmpty(), $"Player {GetName()} is trying to charm unit {charm.GetEntry()}, but it already has a charmed unit {GetCharmedGUID()}");
|
||||||
Log.outFatal(LogFilter.Unit, "Player {0} is trying to charm unit {1}, but it already has a charmed unit {2}", GetName(), charm.GetEntry(), GetCharmedGUID());
|
SetUpdateFieldValue(m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.Charm), charm.GetGUID());
|
||||||
|
m_charmed = charm;
|
||||||
|
|
||||||
charm.m_ControlledByPlayer = true;
|
charm.m_ControlledByPlayer = true;
|
||||||
// @todo maybe we can use this flag to check if controlled by player
|
// @todo maybe we can use this flag to check if controlled by player
|
||||||
@@ -564,8 +565,9 @@ namespace Game.Entities
|
|||||||
// PvP, FFAPvP
|
// PvP, FFAPvP
|
||||||
charm.SetPvpFlags(GetPvpFlags());
|
charm.SetPvpFlags(GetPvpFlags());
|
||||||
|
|
||||||
if (!charm.SetCharmerData(this))
|
Cypher.Assert(charm.GetCharmerGUID().IsEmpty(), $"Unit {charm.GetEntry()} is being charmed, but it already has a charmer {charm.GetCharmerGUID()}");
|
||||||
Log.outFatal(LogFilter.Unit, "Unit {0} is being charmed, but it already has a charmer {1}", charm.GetEntry(), charm.GetCharmerGUID());
|
charm.SetUpdateFieldValue(m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.CharmedBy), GetGUID());
|
||||||
|
charm.m_charmer = this;
|
||||||
|
|
||||||
_isWalkingBeforeCharm = charm.IsWalking();
|
_isWalkingBeforeCharm = charm.IsWalking();
|
||||||
if (_isWalkingBeforeCharm)
|
if (_isWalkingBeforeCharm)
|
||||||
@@ -578,14 +580,16 @@ namespace Game.Entities
|
|||||||
{
|
{
|
||||||
charm.ClearUnitState(UnitState.Charmed);
|
charm.ClearUnitState(UnitState.Charmed);
|
||||||
|
|
||||||
if (IsTypeId(TypeId.Player))
|
if (IsPlayer())
|
||||||
{
|
{
|
||||||
if (!ClearCharmedData(charm))
|
Cypher.Assert(GetCharmedGUID() == charm.GetGUID(), $"Player {GetName()} is trying to uncharm unit {charm.GetEntry()}, but it has another charmed unit {GetCharmedGUID()}");
|
||||||
Log.outFatal(LogFilter.Unit, "Player {0} is trying to uncharm unit {1}, but it has another charmed unit {2}", GetName(), charm.GetEntry(), GetCharmedGUID());
|
SetUpdateFieldValue(m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.Charm), ObjectGuid.Empty);
|
||||||
|
m_charmed = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!charm.ClearCharmerData(this))
|
Cypher.Assert(charm.GetCharmerGUID() == GetGUID(), $"Unit {charm.GetEntry()} is being uncharmed, but it has another charmer {charm.GetCharmerGUID()}");
|
||||||
Log.outFatal(LogFilter.Unit, "Unit {0} is being uncharmed, but it has another charmer {1}", charm.GetEntry(), charm.GetCharmerGUID());
|
charm.SetUpdateFieldValue(m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.CharmedBy), ObjectGuid.Empty);
|
||||||
|
charm.m_charmer = null;
|
||||||
|
|
||||||
Player player = charm.GetCharmerOrOwnerPlayerOrPlayerItself();
|
Player player = charm.GetCharmerOrOwnerPlayerOrPlayerItself();
|
||||||
if (charm.IsTypeId(TypeId.Player))
|
if (charm.IsTypeId(TypeId.Player))
|
||||||
|
|||||||
@@ -1871,49 +1871,10 @@ namespace Game.Entities
|
|||||||
public ObjectGuid GetBattlePetCompanionGUID() { return m_unitData.BattlePetCompanionGUID; }
|
public ObjectGuid GetBattlePetCompanionGUID() { return m_unitData.BattlePetCompanionGUID; }
|
||||||
public void SetBattlePetCompanionGUID(ObjectGuid guid) { SetUpdateFieldValue(m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.BattlePetCompanionGUID), guid); }
|
public void SetBattlePetCompanionGUID(ObjectGuid guid) { SetUpdateFieldValue(m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.BattlePetCompanionGUID), guid); }
|
||||||
|
|
||||||
public bool SetCharmerData(Unit unit)
|
|
||||||
{
|
|
||||||
if (!GetCharmerGUID().IsEmpty())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
SetUpdateFieldValue(m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.CharmedBy), unit.GetGUID());
|
|
||||||
m_charmer = unit;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool ClearCharmerData(Unit verify)
|
|
||||||
{
|
|
||||||
if (GetCharmerGUID() != verify.GetGUID())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
SetUpdateFieldValue(m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.CharmedBy), ObjectGuid.Empty);
|
|
||||||
m_charmer = null;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObjectGuid GetCharmerGUID() { return m_unitData.CharmedBy; }
|
public ObjectGuid GetCharmerGUID() { return m_unitData.CharmedBy; }
|
||||||
|
|
||||||
public Unit GetCharmer() { return m_charmer; }
|
public Unit GetCharmer() { return m_charmer; }
|
||||||
|
|
||||||
public bool SetCharmedData(Unit unit)
|
|
||||||
{
|
|
||||||
if (!GetCharmedGUID().IsEmpty())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
m_charmed = unit;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool ClearCharmedData(Unit verify)
|
|
||||||
{
|
|
||||||
if (GetCharmedGUID() != verify.GetGUID())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
SetUpdateFieldValue(m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.Charm), ObjectGuid.Empty);
|
|
||||||
m_charmed = null;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObjectGuid GetCharmedGUID() { return m_unitData.Charm; }
|
public ObjectGuid GetCharmedGUID() { return m_unitData.Charm; }
|
||||||
|
|
||||||
public Unit GetCharmed() { return m_charmed; }
|
public Unit GetCharmed() { return m_charmed; }
|
||||||
|
|||||||
Reference in New Issue
Block a user