Core/Creatures: Allow summons to be initialized properly when summoner is not in world yet
Port From (https://github.com/TrinityCore/TrinityCore/commit/7881f0ef5ff79b691a5abb9cd727755f49afba47)
This commit is contained in:
@@ -164,7 +164,7 @@ namespace Game.Entities
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void InitStats(uint duration)
|
public virtual void InitStats(WorldObject summoner, uint duration)
|
||||||
{
|
{
|
||||||
Cypher.Assert(!IsPet());
|
Cypher.Assert(!IsPet());
|
||||||
|
|
||||||
@@ -174,13 +174,11 @@ namespace Game.Entities
|
|||||||
if (m_type == TempSummonType.ManualDespawn)
|
if (m_type == TempSummonType.ManualDespawn)
|
||||||
m_type = (duration == 0) ? TempSummonType.DeadDespawn : TempSummonType.TimedDespawn;
|
m_type = (duration == 0) ? TempSummonType.DeadDespawn : TempSummonType.TimedDespawn;
|
||||||
|
|
||||||
Unit owner = GetSummonerUnit();
|
if (summoner != null && summoner.IsPlayer())
|
||||||
if (owner != null && IsTrigger() && m_spells[0] != 0)
|
|
||||||
if (owner.IsTypeId(TypeId.Player))
|
|
||||||
m_ControlledByPlayer = true;
|
|
||||||
|
|
||||||
if (owner != null && owner.IsPlayer())
|
|
||||||
{
|
{
|
||||||
|
if (IsTrigger() && m_spells[0] != 0)
|
||||||
|
m_ControlledByPlayer = true;
|
||||||
|
|
||||||
CreatureSummonedData summonedData = Global.ObjectMgr.GetCreatureSummonedData(GetEntry());
|
CreatureSummonedData summonedData = Global.ObjectMgr.GetCreatureSummonedData(GetEntry());
|
||||||
if (summonedData != null)
|
if (summonedData != null)
|
||||||
{
|
{
|
||||||
@@ -196,27 +194,28 @@ namespace Game.Entities
|
|||||||
if (m_Properties == null)
|
if (m_Properties == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (owner != null)
|
Unit unitSummoner = summoner?.ToUnit();
|
||||||
|
if (unitSummoner != null)
|
||||||
{
|
{
|
||||||
int slot = m_Properties.Slot;
|
int slot = m_Properties.Slot;
|
||||||
if (slot > 0)
|
if (slot > 0)
|
||||||
{
|
{
|
||||||
if (!owner.m_SummonSlot[slot].IsEmpty() && owner.m_SummonSlot[slot] != GetGUID())
|
if (!unitSummoner.m_SummonSlot[slot].IsEmpty() && unitSummoner.m_SummonSlot[slot] != GetGUID())
|
||||||
{
|
{
|
||||||
Creature oldSummon = GetMap().GetCreature(owner.m_SummonSlot[slot]);
|
Creature oldSummon = GetMap().GetCreature(unitSummoner.m_SummonSlot[slot]);
|
||||||
if (oldSummon != null && oldSummon.IsSummon())
|
if (oldSummon != null && oldSummon.IsSummon())
|
||||||
oldSummon.ToTempSummon().UnSummon();
|
oldSummon.ToTempSummon().UnSummon();
|
||||||
}
|
}
|
||||||
owner.m_SummonSlot[slot] = GetGUID();
|
unitSummoner.m_SummonSlot[slot] = GetGUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_Properties.GetFlags().HasFlag(SummonPropertiesFlags.UseCreatureLevel))
|
if (!m_Properties.GetFlags().HasFlag(SummonPropertiesFlags.UseCreatureLevel))
|
||||||
SetLevel(owner.GetLevel());
|
SetLevel(unitSummoner.GetLevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
uint faction = m_Properties.Faction;
|
uint faction = m_Properties.Faction;
|
||||||
if (owner && m_Properties.GetFlags().HasFlag(SummonPropertiesFlags.UseSummonerFaction)) // TODO: Determine priority between faction and flag
|
if (summoner != null && m_Properties.GetFlags().HasFlag(SummonPropertiesFlags.UseSummonerFaction)) // TODO: Determine priority between faction and flag
|
||||||
faction = owner.GetFaction();
|
faction = summoner.GetFaction();
|
||||||
|
|
||||||
if (faction != 0)
|
if (faction != 0)
|
||||||
SetFaction(faction);
|
SetFaction(faction);
|
||||||
@@ -225,18 +224,17 @@ namespace Game.Entities
|
|||||||
RemoveNpcFlag(NPCFlags.WildBattlePet);
|
RemoveNpcFlag(NPCFlags.WildBattlePet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void InitSummon()
|
public virtual void InitSummon(WorldObject summoner)
|
||||||
{
|
{
|
||||||
WorldObject owner = GetSummoner();
|
if (summoner != null)
|
||||||
if (owner != null)
|
|
||||||
{
|
{
|
||||||
if (owner.IsCreature())
|
if (summoner.IsCreature())
|
||||||
owner.ToCreature().GetAI()?.JustSummoned(this);
|
summoner.ToCreature().GetAI()?.JustSummoned(this);
|
||||||
else if (owner.IsGameObject())
|
else if (summoner.IsGameObject())
|
||||||
owner.ToGameObject().GetAI()?.JustSummoned(this);
|
summoner.ToGameObject().GetAI()?.JustSummoned(this);
|
||||||
|
|
||||||
if (IsAIEnabled())
|
if (IsAIEnabled())
|
||||||
GetAI().IsSummonedBy(owner);
|
GetAI().IsSummonedBy(summoner);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -396,9 +394,9 @@ namespace Game.Entities
|
|||||||
InitCharmInfo();
|
InitCharmInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void InitStats(uint duration)
|
public override void InitStats(WorldObject summoner, uint duration)
|
||||||
{
|
{
|
||||||
base.InitStats(duration);
|
base.InitStats(summoner, duration);
|
||||||
|
|
||||||
SetReactState(ReactStates.Passive);
|
SetReactState(ReactStates.Passive);
|
||||||
|
|
||||||
@@ -490,9 +488,9 @@ namespace Game.Entities
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void InitStats(uint duration)
|
public override void InitStats(WorldObject summoner, uint duration)
|
||||||
{
|
{
|
||||||
base.InitStats(duration);
|
base.InitStats(summoner, duration);
|
||||||
|
|
||||||
InitStatsForLevel(GetOwner().GetLevel());
|
InitStatsForLevel(GetOwner().GetLevel());
|
||||||
|
|
||||||
@@ -502,9 +500,9 @@ namespace Game.Entities
|
|||||||
SetReactState(ReactStates.Aggressive);
|
SetReactState(ReactStates.Aggressive);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void InitSummon()
|
public override void InitSummon(WorldObject summoner)
|
||||||
{
|
{
|
||||||
base.InitSummon();
|
base.InitSummon(summoner);
|
||||||
|
|
||||||
if (GetOwner().IsTypeId(TypeId.Player) && GetOwner().GetMinionGUID() == GetGUID()
|
if (GetOwner().IsTypeId(TypeId.Player) && GetOwner().GetMinionGUID() == GetGUID()
|
||||||
&& GetOwner().GetCharmedGUID().IsEmpty())
|
&& GetOwner().GetCharmedGUID().IsEmpty())
|
||||||
@@ -1086,17 +1084,17 @@ namespace Game.Entities
|
|||||||
UnitTypeMask |= UnitTypeMask.Puppet;
|
UnitTypeMask |= UnitTypeMask.Puppet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void InitStats(uint duration)
|
public override void InitStats(WorldObject summoner, uint duration)
|
||||||
{
|
{
|
||||||
base.InitStats(duration);
|
base.InitStats(summoner, duration);
|
||||||
|
|
||||||
SetLevel(GetOwner().GetLevel());
|
SetLevel(GetOwner().GetLevel());
|
||||||
SetReactState(ReactStates.Passive);
|
SetReactState(ReactStates.Passive);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void InitSummon()
|
public override void InitSummon(WorldObject summoner)
|
||||||
{
|
{
|
||||||
base.InitSummon();
|
base.InitSummon(summoner);
|
||||||
if (!SetCharmedBy(GetOwner(), CharmType.Possess))
|
if (!SetCharmedBy(GetOwner(), CharmType.Possess))
|
||||||
Cypher.Assert(false);
|
Cypher.Assert(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace Game.Entities
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void InitStats(uint duration)
|
public override void InitStats(WorldObject summoner, uint duration)
|
||||||
{
|
{
|
||||||
// client requires SMSG_TOTEM_CREATED to be sent before adding to world and before removing old totem
|
// client requires SMSG_TOTEM_CREATED to be sent before adding to world and before removing old totem
|
||||||
Player owner = GetOwner().ToPlayer();
|
Player owner = GetOwner().ToPlayer();
|
||||||
@@ -61,7 +61,7 @@ namespace Game.Entities
|
|||||||
Log.outDebug(LogFilter.Misc, $"Totem with entry {GetEntry()}, does not have a specialized model for spell {m_unitData.CreatedBySpell} and race {owner.GetRace()}. Set to default.");
|
Log.outDebug(LogFilter.Misc, $"Totem with entry {GetEntry()}, does not have a specialized model for spell {m_unitData.CreatedBySpell} and race {owner.GetRace()}. Set to default.");
|
||||||
}
|
}
|
||||||
|
|
||||||
base.InitStats(duration);
|
base.InitStats(summoner, duration);
|
||||||
|
|
||||||
// Get spell cast by totem
|
// Get spell cast by totem
|
||||||
SpellInfo totemSpell = Global.SpellMgr.GetSpellInfo(GetSpell(), GetMap().GetDifficultyID());
|
SpellInfo totemSpell = Global.SpellMgr.GetSpellInfo(GetSpell(), GetMap().GetDifficultyID());
|
||||||
@@ -72,7 +72,7 @@ namespace Game.Entities
|
|||||||
m_duration = duration;
|
m_duration = duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void InitSummon()
|
public override void InitSummon(WorldObject summoner)
|
||||||
{
|
{
|
||||||
if (m_type == TotemType.Passive && GetSpell() != 0)
|
if (m_type == TotemType.Passive && GetSpell() != 0)
|
||||||
CastSpell(this, GetSpell(), true);
|
CastSpell(this, GetSpell(), true);
|
||||||
|
|||||||
@@ -532,14 +532,14 @@ namespace Game.Entities
|
|||||||
// because the current GameObjectModel cannot be moved without recreating
|
// because the current GameObjectModel cannot be moved without recreating
|
||||||
summon.AddUnitState(UnitState.IgnorePathfinding);
|
summon.AddUnitState(UnitState.IgnorePathfinding);
|
||||||
|
|
||||||
summon.InitStats(duration);
|
summon.InitStats(summoner, duration);
|
||||||
|
|
||||||
if (!map.AddToMap(summon))
|
if (!map.AddToMap(summon))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
_staticPassengers.Add(summon);
|
_staticPassengers.Add(summon);
|
||||||
|
|
||||||
summon.InitSummon();
|
summon.InitSummon(summoner);
|
||||||
summon.SetTempSummonType(summonType);
|
summon.SetTempSummonType(summonType);
|
||||||
|
|
||||||
return summon;
|
return summon;
|
||||||
|
|||||||
@@ -3679,7 +3679,7 @@ namespace Game.Maps
|
|||||||
|
|
||||||
summon.SetCreatedBySpell(spellId);
|
summon.SetCreatedBySpell(spellId);
|
||||||
summon.SetHomePosition(pos);
|
summon.SetHomePosition(pos);
|
||||||
summon.InitStats(duration);
|
summon.InitStats(summoner, duration);
|
||||||
summon.SetPrivateObjectOwner(privateObjectOwner);
|
summon.SetPrivateObjectOwner(privateObjectOwner);
|
||||||
|
|
||||||
if (smoothPhasingInfo != null)
|
if (smoothPhasingInfo != null)
|
||||||
@@ -3710,7 +3710,7 @@ namespace Game.Maps
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
summon.InitSummon();
|
summon.InitSummon(summoner);
|
||||||
|
|
||||||
// call MoveInLineOfSight for nearby creatures
|
// call MoveInLineOfSight for nearby creatures
|
||||||
AIRelocationNotifier notifier = new(summon);
|
AIRelocationNotifier notifier = new(summon);
|
||||||
|
|||||||
Reference in New Issue
Block a user