diff --git a/Source/Framework/Constants/PetConst.cs b/Source/Framework/Constants/PetConst.cs index 153ed9a30..213ec42e7 100644 --- a/Source/Framework/Constants/PetConst.cs +++ b/Source/Framework/Constants/PetConst.cs @@ -123,4 +123,23 @@ namespace Framework.Constants CantControlExotic = 11, // "you are unable to control exotic creatures" InternalError = 12, // "Internal pet error" } + + public enum PetTameResult + { + Ok = 0, + InvalidCreature = 1, + TooMany = 2, + CreatureAlreadyOwned = 3, + NotTameable = 4, + AnotherSummonActive = 5, + UnitsCantTame = 6, + NoPetAvailable = 7, + InternalError = 8, + TooHighLevel = 9, + Dead = 10, + NotDead = 11, + CantControlExotic = 12, + InvalidSlot = 13, + EliteTooHighLevel = 14 + } } diff --git a/Source/Game/Entities/Player/Player.cs b/Source/Game/Entities/Player/Player.cs index ea6a79b49..2184b3d23 100644 --- a/Source/Game/Entities/Player/Player.cs +++ b/Source/Game/Entities/Player/Player.cs @@ -17,11 +17,13 @@ using Framework.Constants; using Framework.Database; +using Framework.Dynamic; using Game.Achievements; using Game.AI; using Game.Arenas; using Game.BattleFields; using Game.BattleGrounds; +using Game.BattlePets; using Game.Chat; using Game.DataStorage; using Game.Garrisons; @@ -38,7 +40,6 @@ using Game.Spells; using System; using System.Collections.Generic; using System.Linq; -using Framework.Dynamic; namespace Game.Entities { @@ -952,7 +953,7 @@ namespace Game.Entities return null; } - public void SetBattlePetData(BattlePets.BattlePetMgr.BattlePet pet = null) + public void SetBattlePetData(BattlePet pet = null) { if (pet != null) { @@ -4683,11 +4684,18 @@ namespace Game.Entities return null; } - public Pet SummonPet(uint entry, float x, float y, float z, float ang, PetType petType, uint duration) + public Pet SummonPet(uint entry, float x, float y, float z, float ang, PetType petType, uint duration, bool aliveOnly = false) { Pet pet = new(this, petType); if (petType == PetType.Summon && pet.LoadPetFromDB(this, entry)) { + if (aliveOnly && !pet.IsAlive()) + { + pet.DespawnOrUnsummon(); + SendTameFailure(PetTameResult.Dead); + return null; + } + if (duration > 0) pet.SetDuration(duration); @@ -4836,6 +4844,13 @@ namespace Game.Entities } } + void SendTameFailure(PetTameResult result) + { + PetTameFailure petTameFailure = new(); + petTameFailure.Result = result; + SendPacket(petTameFailure); + } + public void AddPetAura(PetAura petSpell) { m_petAuras.Add(petSpell); diff --git a/Source/Game/Networking/Packets/PetPackets.cs b/Source/Game/Networking/Packets/PetPackets.cs index 189f353fa..74df76ec2 100644 --- a/Source/Game/Networking/Packets/PetPackets.cs +++ b/Source/Game/Networking/Packets/PetPackets.cs @@ -354,6 +354,18 @@ namespace Game.Networking.Packets public PetTalk Action; } + class PetTameFailure : ServerPacket + { + public PetTameFailure() : base(ServerOpcodes.PetTameFailure) { } + + public override void Write() + { + _worldPacket.WriteUInt8(Result); + } + + public byte Result; + } + //Structs public class PetSpellCooldown { diff --git a/Source/Game/Spells/SpellEffects.cs b/Source/Game/Spells/SpellEffects.cs index 9b20ef478..796985e78 100644 --- a/Source/Game/Spells/SpellEffects.cs +++ b/Source/Game/Spells/SpellEffects.cs @@ -2309,7 +2309,7 @@ namespace Game.Spells float x, y, z; owner.GetClosePoint(out x, out y, out z, owner.GetCombatReach()); - Pet pet = owner.SummonPet(petentry, x, y, z, owner.Orientation, PetType.Summon, 0); + Pet pet = owner.SummonPet(petentry, x, y, z, owner.Orientation, PetType.Summon, 0, true); if (!pet) return;