Core/Pets: Updated pet summoning for latest client version (5 Call Pet spells and stable size 200)
Port From (https://github.com/TrinityCore/TrinityCore/commit/950db60435e7e513633ff5b22ad7f0ed8b1147e4)
This commit is contained in:
@@ -5148,13 +5148,20 @@ namespace Game.Spells
|
||||
}
|
||||
case SpellEffectName.ResurrectPet:
|
||||
{
|
||||
if (unitCaster == null)
|
||||
Player playerCaster = m_caster.ToPlayer();
|
||||
if (playerCaster == null || playerCaster.GetPetStable() == null)
|
||||
return SpellCastResult.BadTargets;
|
||||
|
||||
Creature pet = unitCaster.GetGuardianPet();
|
||||
Pet pet = playerCaster.GetPet();
|
||||
if (pet != null && pet.IsAlive())
|
||||
return SpellCastResult.AlreadyHaveSummon;
|
||||
|
||||
PetStable petStable = playerCaster.GetPetStable();
|
||||
var deadPetInfo = petStable.ActivePets.FirstOrDefault(petInfo => petInfo?.Health == 0);
|
||||
|
||||
if (deadPetInfo == null)
|
||||
return SpellCastResult.BadTargets;
|
||||
|
||||
break;
|
||||
}
|
||||
// This is generic summon effect
|
||||
@@ -5221,17 +5228,27 @@ namespace Game.Spells
|
||||
Player playerCaster = unitCaster.ToPlayer();
|
||||
if (playerCaster != null && playerCaster.GetPetStable() != null)
|
||||
{
|
||||
var info = Pet.GetLoadPetInfo(playerCaster.GetPetStable(), (uint)spellEffectInfo.MiscValue, 0, false);
|
||||
if (info.Item1 != null)
|
||||
PetSaveMode? petSlot = null;
|
||||
if (spellEffectInfo.MiscValue == 0)
|
||||
{
|
||||
if (info.Item1.Type == PetType.Hunter)
|
||||
petSlot = (PetSaveMode)spellEffectInfo.CalcValue();
|
||||
|
||||
// No pet can be summoned if any pet is dead
|
||||
foreach (var activePet in playerCaster.GetPetStable().ActivePets)
|
||||
{
|
||||
if (info.Item1.Health == 0)
|
||||
if (activePet?.Health == 0)
|
||||
{
|
||||
playerCaster.SendTameFailure(PetTameResult.Dead);
|
||||
return SpellCastResult.DontReport;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var info = Pet.GetLoadPetInfo(playerCaster.GetPetStable(), (uint)spellEffectInfo.MiscValue, 0, petSlot);
|
||||
if (info.Item1 != null)
|
||||
{
|
||||
if (info.Item1.Type == PetType.Hunter)
|
||||
{
|
||||
CreatureTemplate creatureInfo = Global.ObjectMgr.GetCreatureTemplate(info.Item1.CreatureId);
|
||||
if (creatureInfo == null || !creatureInfo.IsTameable(playerCaster.CanTameExoticPets()))
|
||||
{
|
||||
@@ -5253,6 +5270,21 @@ namespace Game.Spells
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SpellEffectName.DismissPet:
|
||||
{
|
||||
Player playerCaster = m_caster.ToPlayer();
|
||||
if (playerCaster == null)
|
||||
return SpellCastResult.BadTargets;
|
||||
|
||||
Pet pet = playerCaster.GetPet();
|
||||
if (pet == null)
|
||||
return SpellCastResult.NoPet;
|
||||
|
||||
if (!pet.IsAlive())
|
||||
return SpellCastResult.TargetsDead;
|
||||
|
||||
break;
|
||||
}
|
||||
case SpellEffectName.SummonPlayer:
|
||||
{
|
||||
if (!m_caster.IsTypeId(TypeId.Player))
|
||||
|
||||
@@ -2298,27 +2298,34 @@ namespace Game.Spells
|
||||
return;
|
||||
}
|
||||
|
||||
PetSaveMode? petSlot = null;
|
||||
if (petentry == 0)
|
||||
petSlot = (PetSaveMode)damage;
|
||||
|
||||
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);
|
||||
if (!pet)
|
||||
Pet pet = owner.SummonPet(petentry, petSlot, x, y, z, owner.Orientation, 0, out bool isNew);
|
||||
if (pet == null)
|
||||
return;
|
||||
|
||||
if (m_caster.IsTypeId(TypeId.Unit))
|
||||
if (isNew)
|
||||
{
|
||||
if (m_caster.ToCreature().IsTotem())
|
||||
pet.SetReactState(ReactStates.Aggressive);
|
||||
else
|
||||
pet.SetReactState(ReactStates.Defensive);
|
||||
if (m_caster.IsCreature())
|
||||
{
|
||||
if (m_caster.ToCreature().IsTotem())
|
||||
pet.SetReactState(ReactStates.Aggressive);
|
||||
else
|
||||
pet.SetReactState(ReactStates.Defensive);
|
||||
}
|
||||
|
||||
pet.SetCreatedBySpell(m_spellInfo.Id);
|
||||
|
||||
// generate new name for summon pet
|
||||
string new_name = Global.ObjectMgr.GeneratePetName(petentry);
|
||||
if (!string.IsNullOrEmpty(new_name))
|
||||
pet.SetName(new_name);
|
||||
}
|
||||
|
||||
pet.SetCreatedBySpell(m_spellInfo.Id);
|
||||
|
||||
// generate new name for summon pet
|
||||
string new_name = Global.ObjectMgr.GeneratePetName(petentry);
|
||||
if (!string.IsNullOrEmpty(new_name))
|
||||
pet.SetName(new_name);
|
||||
|
||||
ExecuteLogEffectSummonObject(effectInfo.Effect, pet);
|
||||
}
|
||||
|
||||
@@ -4012,42 +4019,68 @@ namespace Game.Spells
|
||||
}
|
||||
|
||||
[SpellEffectHandler(SpellEffectName.ResurrectPet)]
|
||||
void EffectSummonDeadPet()
|
||||
void EffectResurrectPet()
|
||||
{
|
||||
if (effectHandleMode != SpellEffectHandleMode.Hit)
|
||||
return;
|
||||
|
||||
if (damage < 0)
|
||||
return;
|
||||
|
||||
Player player = m_caster.ToPlayer();
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
Pet pet = player.GetPet();
|
||||
if (pet != null && pet.IsAlive())
|
||||
return;
|
||||
// Maybe player dismissed dead pet or pet despawned?
|
||||
bool hadPet = true;
|
||||
|
||||
if (damage < 0)
|
||||
return;
|
||||
|
||||
float x, y, z;
|
||||
player.GetPosition(out x, out y, out z);
|
||||
if (pet == null)
|
||||
if (player.GetPet() == null)
|
||||
{
|
||||
player.SummonPet(0, x, y, z, player.Orientation, PetType.Summon, 0);
|
||||
pet = player.GetPet();
|
||||
PetStable petStable = player.GetPetStable();
|
||||
var deadPetIndex = Array.FindIndex(petStable.ActivePets, petInfo => petInfo?.Health == 0);
|
||||
|
||||
PetSaveMode slot = (PetSaveMode)deadPetIndex;
|
||||
|
||||
player.SummonPet(0, slot, 0f, 0f, 0f, 0f, 0);
|
||||
hadPet = false;
|
||||
}
|
||||
if (pet == null)
|
||||
|
||||
// TODO: Better to fail Hunter's "Revive Pet" at cast instead of here when casting ends
|
||||
Pet pet = player.GetPet(); // Attempt to get current pet
|
||||
if (pet == null || pet.IsAlive())
|
||||
return;
|
||||
|
||||
player.GetMap().CreatureRelocation(pet, x, y, z, player.GetOrientation());
|
||||
// If player did have a pet before reviving, teleport it
|
||||
if (hadPet)
|
||||
{
|
||||
// Reposition the pet's corpse before reviving so as not to grab aggro
|
||||
// We can use a different, more accurate version of GetClosePoint() since we have a pet
|
||||
// Will be used later to reposition the pet if we have one
|
||||
player.GetClosePoint(out float x, out float y, out float z, pet.GetCombatReach(), SharedConst.PetFollowDist, pet.GetFollowAngle());
|
||||
pet.NearTeleportTo(x, y, z, player.GetOrientation());
|
||||
pet.Relocate(x, y, z, player.GetOrientation()); // This is needed so SaveStayPosition() will get the proper coords.
|
||||
}
|
||||
|
||||
pet.SetDynamicFlags(UnitDynFlags.HideModel);
|
||||
pet.SetDynamicFlags(UnitDynFlags.None);
|
||||
pet.RemoveUnitFlag(UnitFlags.Skinnable);
|
||||
pet.SetDeathState(DeathState.Alive);
|
||||
pet.ClearUnitState(UnitState.AllErasable);
|
||||
pet.SetHealth(pet.CountPctFromMaxHealth(damage));
|
||||
|
||||
pet.InitializeAI();
|
||||
player.PetSpellInitialize();
|
||||
// Reset things for when the AI to takes over
|
||||
CharmInfo ci = pet.GetCharmInfo();
|
||||
if (ci != null)
|
||||
{
|
||||
// In case the pet was at stay, we don't want it running back
|
||||
ci.SaveStayPosition();
|
||||
ci.SetIsAtStay(ci.HasCommandState(CommandStates.Stay));
|
||||
|
||||
ci.SetIsFollowing(false);
|
||||
ci.SetIsCommandAttack(false);
|
||||
ci.SetIsCommandFollow(false);
|
||||
ci.SetIsReturning(false);
|
||||
}
|
||||
|
||||
pet.SavePetToDB(PetSaveMode.AsCurrent);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user