hondacrx
2021-12-07 20:42:47 -05:00
parent b7e4c2fd76
commit c37e1c9f7d
17 changed files with 91 additions and 46 deletions
+6 -6
View File
@@ -28,7 +28,7 @@ namespace Game.AI
{ {
public class CreatureAI : UnitAI public class CreatureAI : UnitAI
{ {
bool _moveInLineOfSightLocked; bool _moveInLOSLocked;
List<AreaBoundary> _boundary = new(); List<AreaBoundary> _boundary = new();
bool _negateBoundary; bool _negateBoundary;
@@ -41,7 +41,7 @@ namespace Game.AI
public CreatureAI(Creature _creature) : base(_creature) public CreatureAI(Creature _creature) : base(_creature)
{ {
me = _creature; me = _creature;
_moveInLineOfSightLocked = false; _moveInLOSLocked = false;
} }
public override void OnCharmed(bool isNew) public override void OnCharmed(bool isNew)
@@ -101,12 +101,12 @@ namespace Game.AI
public virtual void MoveInLineOfSight_Safe(Unit who) public virtual void MoveInLineOfSight_Safe(Unit who)
{ {
if (_moveInLineOfSightLocked) if (_moveInLOSLocked)
return; return;
_moveInLineOfSightLocked = true; _moveInLOSLocked = true;
MoveInLineOfSight(who); MoveInLineOfSight(who);
_moveInLineOfSightLocked = false; _moveInLOSLocked = false;
} }
public virtual void MoveInLineOfSight(Unit who) public virtual void MoveInLineOfSight(Unit who)
@@ -366,7 +366,7 @@ namespace Game.AI
// Called when the creature summon successfully other creature // Called when the creature summon successfully other creature
public virtual void JustSummoned(Creature summon) { } public virtual void JustSummoned(Creature summon) { }
public virtual void IsSummonedBy(Unit summoner) { } public virtual void IsSummonedBy(WorldObject summoner) { }
public virtual void SummonedCreatureDespawn(Creature summon) { } public virtual void SummonedCreatureDespawn(Creature summon) { }
public virtual void SummonedCreatureDies(Creature summon, Unit killer) { } public virtual void SummonedCreatureDies(Creature summon, Unit killer) { }
+6
View File
@@ -101,5 +101,11 @@ namespace Game.AI
// Called when spell hits a target // Called when spell hits a target
public virtual void SpellHitTarget(Unit target, SpellInfo spellInfo) { } public virtual void SpellHitTarget(Unit target, SpellInfo spellInfo) { }
public virtual void SpellHitTargetGameObject(GameObject target, SpellInfo spellInfo) { } public virtual void SpellHitTargetGameObject(GameObject target, SpellInfo spellInfo) { }
// Called when the gameobject summon successfully other creature
public virtual void JustSummoned(Creature summon) { }
public virtual void SummonedCreatureDespawn(Creature summon) { }
public virtual void SummonedCreatureDies(Creature summon, Unit killer) { }
} }
} }
+1 -1
View File
@@ -119,7 +119,7 @@ namespace Game.AI
{ {
public TriggerAI(Creature c) : base(c) { } public TriggerAI(Creature c) : base(c) { }
public override void IsSummonedBy(Unit summoner) public override void IsSummonedBy(WorldObject summoner)
{ {
if (me.m_spells[0] != 0) if (me.m_spells[0] != 0)
{ {
+2 -2
View File
@@ -689,9 +689,9 @@ namespace Game.AI
GetScript().ProcessEventsFor(SmartEvents.ReceiveEmote, player, (uint)emoteId); GetScript().ProcessEventsFor(SmartEvents.ReceiveEmote, player, (uint)emoteId);
} }
public override void IsSummonedBy(Unit summoner) public override void IsSummonedBy(WorldObject summoner)
{ {
GetScript().ProcessEventsFor(SmartEvents.JustSummoned, summoner); GetScript().ProcessEventsFor(SmartEvents.JustSummoned, summoner.ToUnit(), 0, 0, false, null, summoner.ToGameObject());
} }
public override void DamageDealt(Unit victim, ref uint damage, DamageEffectType damageType) public override void DamageDealt(Unit victim, ref uint damage, DamageEffectType damageType)
+3 -3
View File
@@ -2944,7 +2944,7 @@ namespace Game.AI
TempSummon tempSummon = _me.ToTempSummon(); TempSummon tempSummon = _me.ToTempSummon();
if (tempSummon) if (tempSummon)
{ {
Unit summoner = tempSummon.GetSummoner(); WorldObject summoner = tempSummon.GetSummoner();
if (summoner) if (summoner)
charmerOrOwnerGuid = summoner.GetGUID(); charmerOrOwnerGuid = summoner.GetGUID();
} }
@@ -2953,7 +2953,7 @@ namespace Game.AI
if (charmerOrOwnerGuid.IsEmpty()) if (charmerOrOwnerGuid.IsEmpty())
charmerOrOwnerGuid = _me.GetCreatorGUID(); charmerOrOwnerGuid = _me.GetCreatorGUID();
Unit owner = Global.ObjAccessor.GetUnit(_me, charmerOrOwnerGuid); WorldObject owner = Global.ObjAccessor.GetWorldObject(_me, charmerOrOwnerGuid);
if (owner != null) if (owner != null)
targets.Add(owner); targets.Add(owner);
} }
@@ -2967,7 +2967,7 @@ namespace Game.AI
// Get owner of owner // Get owner of owner
if (e.Target.owner.useCharmerOrOwner != 0 && !targets.Empty()) if (e.Target.owner.useCharmerOrOwner != 0 && !targets.Empty())
{ {
Unit owner = targets.First().ToUnit(); WorldObject owner = targets.First();
targets.Clear(); targets.Clear();
Unit unitBase = Global.ObjAccessor.GetUnit(owner, owner.GetCharmerOrOwnerGUID()); Unit unitBase = Global.ObjAccessor.GetUnit(owner, owner.GetCharmerOrOwnerGUID());
+1 -1
View File
@@ -1415,7 +1415,7 @@ namespace Game.Entities
Map map = GetMap(); Map map = GetMap();
if (map != null) if (map != null)
{ {
TempSummon summon = map.SummonCreature(entry, pos, null, despawnTime, ToUnit(), spellId, vehId, privateObjectOwner); TempSummon summon = map.SummonCreature(entry, pos, null, despawnTime, this, spellId, vehId, privateObjectOwner);
if (summon != null) if (summon != null)
{ {
summon.SetTempSummonType(despawnType); summon.SetTempSummonType(despawnType);
+37 -12
View File
@@ -24,7 +24,7 @@ namespace Game.Entities
{ {
public class TempSummon : Creature public class TempSummon : Creature
{ {
public TempSummon(SummonPropertiesRecord properties, Unit owner, bool isWorldObject) : base(isWorldObject) public TempSummon(SummonPropertiesRecord properties, WorldObject owner, bool isWorldObject) : base(isWorldObject)
{ {
m_Properties = properties; m_Properties = properties;
m_type = TempSummonType.ManualDespawn; m_type = TempSummonType.ManualDespawn;
@@ -33,15 +33,33 @@ namespace Game.Entities
UnitTypeMask |= UnitTypeMask.Summon; UnitTypeMask |= UnitTypeMask.Summon;
} }
public Unit GetSummoner() public WorldObject GetSummoner()
{ {
return !m_summonerGUID.IsEmpty() ? Global.ObjAccessor.GetUnit(this, m_summonerGUID) : null; return !m_summonerGUID.IsEmpty() ? Global.ObjAccessor.GetWorldObject(this, m_summonerGUID) : null;
} }
public Unit GetSummonerUnit()
{
WorldObject summoner = GetSummoner();
if (summoner != null)
return summoner.ToUnit();
return null;
}
public Creature GetSummonerCreatureBase() public Creature GetSummonerCreatureBase()
{ {
return !m_summonerGUID.IsEmpty() ? ObjectAccessor.GetCreature(this, m_summonerGUID) : null; return !m_summonerGUID.IsEmpty() ? ObjectAccessor.GetCreature(this, m_summonerGUID) : null;
} }
public GameObject GetSummonerGameObject()
{
WorldObject summoner = GetSummoner();
if (summoner != null)
return summoner.ToGameObject();
return null;
}
public override void Update(uint diff) public override void Update(uint diff)
{ {
@@ -167,8 +185,7 @@ 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 = GetSummoner(); Unit owner = GetSummonerUnit();
if (owner != null && IsTrigger() && m_spells[0] != 0) if (owner != null && IsTrigger() && m_spells[0] != 0)
{ {
SetLevel(owner.GetLevel()); SetLevel(owner.GetLevel());
@@ -206,11 +223,14 @@ namespace Game.Entities
public virtual void InitSummon() public virtual void InitSummon()
{ {
Unit owner = GetSummoner(); WorldObject owner = GetSummoner();
if (owner != null) if (owner != null)
{ {
if (owner.IsTypeId(TypeId.Unit) && owner.ToCreature().IsAIEnabled()) if (owner.IsCreature())
owner.ToCreature().GetAI().JustSummoned(this); owner.ToCreature().GetAI()?.JustSummoned(this);
else if (owner.IsGameObject())
owner.ToGameObject().GetAI()?.JustSummoned(this);
if (IsAIEnabled()) if (IsAIEnabled())
GetAI().IsSummonedBy(owner); GetAI().IsSummonedBy(owner);
} }
@@ -244,9 +264,14 @@ namespace Game.Entities
return; return;
} }
Unit owner = GetSummoner(); WorldObject owner = GetSummoner();
if (owner != null && owner.IsTypeId(TypeId.Unit) && owner.ToCreature().IsAIEnabled()) if (owner != null)
owner.ToCreature().GetAI().SummonedCreatureDespawn(this); {
if (owner.IsCreature())
owner.ToCreature().GetAI()?.SummonedCreatureDespawn(this);
else if (owner.IsGameObject())
owner.ToGameObject().GetAI()?.SummonedCreatureDespawn(this);
}
AddObjectToRemoveList(); AddObjectToRemoveList();
} }
@@ -261,7 +286,7 @@ namespace Game.Entities
int slot = m_Properties.Slot; int slot = m_Properties.Slot;
if (slot > 0) if (slot > 0)
{ {
Unit owner = GetSummoner(); Unit owner = GetSummonerUnit();
if (owner != null) if (owner != null)
if (owner.m_SummonSlot[slot] == GetGUID()) if (owner.m_SummonSlot[slot] == GetGUID())
owner.m_SummonSlot[slot].Clear(); owner.m_SummonSlot[slot].Clear();
+7 -3
View File
@@ -876,10 +876,14 @@ namespace Game.Entities
TempSummon summon = creature.ToTempSummon(); TempSummon summon = creature.ToTempSummon();
if (summon != null) if (summon != null)
{ {
Unit summoner = summon.GetSummoner(); WorldObject summoner = summon.GetSummoner();
if (summoner != null) if (summoner != null)
if (summoner.IsTypeId(TypeId.Unit) && summoner.IsAIEnabled()) {
summoner.ToCreature().GetAI().SummonedCreatureDies(creature, attacker); if (summoner.IsCreature())
summoner.ToCreature().GetAI()?.SummonedCreatureDies(creature, attacker);
else if (summoner.IsGameObject())
summoner.ToGameObject().GetAI()?.SummonedCreatureDies(creature, attacker);
}
} }
// Dungeon specific stuff, only applies to players killing creatures // Dungeon specific stuff, only applies to players killing creatures
+1 -1
View File
@@ -10957,7 +10957,7 @@ namespace Game
Unit summoner = null; Unit summoner = null;
// Check summoners for party // Check summoners for party
if (clickee.IsSummon()) if (clickee.IsSummon())
summoner = clickee.ToTempSummon().GetSummoner(); summoner = clickee.ToTempSummon().GetSummonerUnit();
if (summoner == null) if (summoner == null)
summoner = clickee; summoner = clickee;
+1 -1
View File
@@ -75,7 +75,7 @@ namespace Game
response.CreatureID = summonedBattlePet.GetEntry(); response.CreatureID = summonedBattlePet.GetEntry();
response.Timestamp = summonedBattlePet.GetBattlePetCompanionNameTimestamp(); response.Timestamp = summonedBattlePet.GetBattlePetCompanionNameTimestamp();
Unit petOwner = summonedBattlePet.ToTempSummon().GetSummoner(); Unit petOwner = summonedBattlePet.ToTempSummon().GetSummonerUnit();
if (!petOwner.IsPlayer()) if (!petOwner.IsPlayer())
{ {
SendPacket(response); SendPacket(response);
+8 -6
View File
@@ -3947,7 +3947,7 @@ namespace Game.Maps
} }
} }
public TempSummon SummonCreature(uint entry, Position pos, SummonPropertiesRecord properties = null, uint duration = 0, Unit summoner = null, uint spellId = 0, uint vehId = 0, ObjectGuid privateObjectOwner = default) public TempSummon SummonCreature(uint entry, Position pos, SummonPropertiesRecord properties = null, uint duration = 0, WorldObject summoner = null, uint spellId = 0, uint vehId = 0, ObjectGuid privateObjectOwner = default)
{ {
var mask = UnitTypeMask.Summon; var mask = UnitTypeMask.Summon;
if (properties != null) if (properties != null)
@@ -3997,23 +3997,25 @@ namespace Game.Maps
} }
} }
Unit summonerUnit = summoner != null ? summoner.ToUnit() : null;
TempSummon summon; TempSummon summon;
switch (mask) switch (mask)
{ {
case UnitTypeMask.Summon: case UnitTypeMask.Summon:
summon = new TempSummon(properties, summoner, false); summon = new TempSummon(properties, summonerUnit, false);
break; break;
case UnitTypeMask.Guardian: case UnitTypeMask.Guardian:
summon = new Guardian(properties, summoner, false); summon = new Guardian(properties, summonerUnit, false);
break; break;
case UnitTypeMask.Puppet: case UnitTypeMask.Puppet:
summon = new Puppet(properties, summoner); summon = new Puppet(properties, summonerUnit);
break; break;
case UnitTypeMask.Totem: case UnitTypeMask.Totem:
summon = new Totem(properties, summoner); summon = new Totem(properties, summonerUnit);
break; break;
case UnitTypeMask.Minion: case UnitTypeMask.Minion:
summon = new Minion(properties, summoner, false); summon = new Minion(properties, summonerUnit, false);
break; break;
default: default:
return null; return null;
+2 -2
View File
@@ -916,7 +916,7 @@ namespace Game.Spells
TempSummon casterSummon = unitCaster.ToTempSummon(); TempSummon casterSummon = unitCaster.ToTempSummon();
if (casterSummon != null) if (casterSummon != null)
{ {
Unit summoner = casterSummon.GetSummoner(); WorldObject summoner = casterSummon.GetSummoner();
if (summoner != null) if (summoner != null)
dest = new SpellDestination(summoner); dest = new SpellDestination(summoner);
} }
@@ -1059,7 +1059,7 @@ namespace Game.Spells
Unit unitCaster = m_caster.ToUnit(); Unit unitCaster = m_caster.ToUnit();
if (unitCaster != null) if (unitCaster != null)
if (unitCaster.IsSummon()) if (unitCaster.IsSummon())
target = unitCaster.ToTempSummon().GetSummoner(); target = unitCaster.ToTempSummon().GetSummonerUnit();
break; break;
} }
case Targets.UnitVehicle: case Targets.UnitVehicle:
+1 -1
View File
@@ -1707,7 +1707,7 @@ namespace Game.Spells
uint faction = properties.Faction; uint faction = properties.Faction;
if (properties.GetFlags().HasFlag(SummonPropertiesFlags.UseSummonerFaction)) // TODO: Determine priority between faction and flag if (properties.GetFlags().HasFlag(SummonPropertiesFlags.UseSummonerFaction)) // TODO: Determine priority between faction and flag
{ {
Unit summoner = summon.GetSummoner(); WorldObject summoner = summon.GetSummoner();
if (summoner != null) if (summoner != null)
faction = summoner.GetFaction(); faction = summoner.GetFaction();
} }
+1 -1
View File
@@ -72,7 +72,7 @@ namespace Scripts.Pets
if (me.IsSummon() && !me.GetThreatManager().GetFixateTarget()) if (me.IsSummon() && !me.GetThreatManager().GetFixateTarget())
{ // find new target { // find new target
Unit summoner = me.ToTempSummon().GetSummoner(); Unit summoner = me.ToTempSummon().GetSummonerUnit();
List<Unit> targets = new(); List<Unit> targets = new();
foreach (var pair in summoner.GetCombatManager().GetPvPCombatRefs()) foreach (var pair in summoner.GetCombatManager().GetPvPCombatRefs())
+6 -2
View File
@@ -55,9 +55,13 @@ namespace Scripts.Pets
{ {
public npc_pet_pri_shadowfiend(Creature creature) : base(creature) { } public npc_pet_pri_shadowfiend(Creature creature) : base(creature) { }
public override void IsSummonedBy(Unit summoner) public override void IsSummonedBy(WorldObject summoner)
{ {
if (summoner.HasAura(SpellIds.GlyphOfShadowFiend)) Unit unitSummoner = summoner.ToUnit();
if (unitSummoner == null)
return;
if (unitSummoner.HasAura(SpellIds.GlyphOfShadowFiend))
DoCastAOE(SpellIds.ShadowFiendDeath); DoCastAOE(SpellIds.ShadowFiendDeath);
} }
} }
+6 -2
View File
@@ -311,10 +311,14 @@ namespace Scripts.World.EmeraldDragons
public npc_spirit_shade(Creature creature) : base(creature) { } public npc_spirit_shade(Creature creature) : base(creature) { }
public override void IsSummonedBy(Unit summoner) public override void IsSummonedBy(WorldObject summoner)
{ {
Unit unitSummoner = summoner.ToUnit();
if (unitSummoner == null)
return;
_summonerGuid = summoner.GetGUID(); _summonerGuid = summoner.GetGUID();
me.GetMotionMaster().MoveFollow(summoner, 0.0f, 0.0f); me.GetMotionMaster().MoveFollow(unitSummoner, 0.0f, 0.0f);
} }
public override void MovementInform(MovementGeneratorType moveType, uint data) public override void MovementInform(MovementGeneratorType moveType, uint data)
+2 -2
View File
@@ -522,7 +522,7 @@ namespace Scripts.World.NpcSpecial
return null; return null;
} }
public void UpdateAI(uint diff) public override void UpdateAI(uint diff)
{ {
base.UpdateAI(diff); base.UpdateAI(diff);
@@ -2044,7 +2044,7 @@ namespace Scripts.World.NpcSpecial
summonerGUID.Clear(); summonerGUID.Clear();
} }
public override void IsSummonedBy(Unit summoner) public override void IsSummonedBy(WorldObject summoner)
{ {
if (summoner.IsTypeId(TypeId.Player)) if (summoner.IsTypeId(TypeId.Player))
{ {