public void SetMinion(Minion minion, bool apply) { Log.outDebug(LogFilter.Unit, "SetMinion {0} for {1}, apply {2}", minion.GetEntry(), GetEntry(), apply); if (apply) { if (!minion.GetOwnerGUID().IsEmpty()) { Log.outFatal(LogFilter.Unit, "SetMinion: Minion {0} is not the minion of owner {1}", minion.GetEntry(), GetEntry()); return; } minion.SetOwnerGUID(GetGUID()); m_Controlled.Add(minion); if (IsTypeId(TypeId.Player)) { minion.m_ControlledByPlayer = true; minion.SetFlag(UnitFields.Flags, UnitFlags.PvpAttackable); } // Can only have one pet. If a new one is summoned, dismiss the old one. if (minion.IsGuardianPet()) { Guardian oldPet = GetGuardianPet(); if (oldPet) { if (oldPet != minion && (oldPet.IsPet() || minion.IsPet() || oldPet.GetEntry() != minion.GetEntry())) { // remove existing minion pet if (oldPet.IsPet()) { ((Pet)oldPet).Remove(PetSaveMode.AsCurrent); } else { oldPet.UnSummon(); } SetPetGUID(minion.GetGUID()); SetMinionGUID(ObjectGuid.Empty); } } else { SetPetGUID(minion.GetGUID()); SetMinionGUID(ObjectGuid.Empty); } } if (minion.HasUnitTypeMask(UnitTypeMask.Guardian)) { AddGuidValue(UnitFields.Summon, minion.GetGUID()); } if (minion.m_Properties != null && minion.m_Properties.Type == SummonType.Minipet) { SetCritterGUID(minion.GetGUID()); if (GetTypeId() == TypeId.Player) { minion.SetGuidValue(UnitFields.BattlePetCompanionGuid, GetGuidValue(PlayerFields.SummonedBattlePetId)); } } // PvP, FFAPvP minion.SetByteValue(UnitFields.Bytes2, UnitBytes2Offsets.PvpFlag, GetByteValue(UnitFields.Bytes2, UnitBytes2Offsets.PvpFlag)); // FIXME: hack, speed must be set only at follow if (IsTypeId(TypeId.Player) && minion.IsPet()) { for (UnitMoveType i = 0; i < UnitMoveType.Max; ++i) { minion.SetSpeedRate(i, m_speed_rate[(int)i]); } } // Send infinity cooldown - client does that automatically but after relog cooldown needs to be set again SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(minion.GetUInt32Value(UnitFields.CreatedBySpell)); if (spellInfo != null && spellInfo.IsCooldownStartedOnEvent()) { GetSpellHistory().StartCooldown(spellInfo, 0, null, true); } } else { if (minion.GetOwnerGUID() != GetGUID()) { Log.outFatal(LogFilter.Unit, "SetMinion: Minion {0} is not the minion of owner {1}", minion.GetEntry(), GetEntry()); return; } m_Controlled.Remove(minion); if (minion.m_Properties != null && minion.m_Properties.Type == SummonType.Minipet) { if (GetCritterGUID() == minion.GetGUID()) { SetCritterGUID(ObjectGuid.Empty); } } if (minion.IsGuardianPet()) { if (GetPetGUID() == minion.GetGUID()) { SetPetGUID(ObjectGuid.Empty); } } else if (minion.IsTotem()) { // All summoned by totem minions must disappear when it is removed. SpellInfo spInfo = Global.SpellMgr.GetSpellInfo(minion.ToTotem().GetSpell()); if (spInfo != null) { foreach (SpellEffectInfo effect in spInfo.GetEffectsForDifficulty(Difficulty.None)) { if (effect == null || effect.Effect != SpellEffectName.Summon) { continue; } RemoveAllMinionsByEntry((uint)effect.MiscValue); } } } SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(minion.GetUInt32Value(UnitFields.CreatedBySpell)); // Remove infinity cooldown if (spellInfo != null && spellInfo.IsCooldownStartedOnEvent()) { GetSpellHistory().SendCooldownEvent(spellInfo); } if (RemoveGuidValue(UnitFields.Summon, minion.GetGUID())) { // Check if there is another minion foreach (var unit in m_Controlled) { // do not use this check, creature do not have charm guid if (GetGUID() == unit.GetCharmerGUID()) { continue; } Contract.Assert(unit.GetOwnerGUID() == GetGUID()); if (unit.GetOwnerGUID() != GetGUID()) { Contract.Assert(false); } Contract.Assert(unit.IsTypeId(TypeId.Unit)); if (!unit.HasUnitTypeMask(UnitTypeMask.Guardian)) { continue; } if (AddGuidValue(UnitFields.Summon, unit.GetGUID())) { // show another pet bar if there is no charm bar if (IsTypeId(TypeId.Player) && GetCharmGUID().IsEmpty()) { if (unit.IsPet()) { ToPlayer().PetSpellInitialize(); } else { ToPlayer().CharmSpellInitialize(); } } } break; } } } }
public void SetMinion(Minion minion, bool apply) { Log.outDebug(LogFilter.Unit, "SetMinion {0} for {1}, apply {2}", minion.GetEntry(), GetEntry(), apply); if (apply) { if (!minion.GetOwnerGUID().IsEmpty()) { Log.outFatal(LogFilter.Unit, "SetMinion: Minion {0} is not the minion of owner {1}", minion.GetEntry(), GetEntry()); return; } minion.SetOwnerGUID(GetGUID()); if (!m_Controlled.Contains(minion)) { m_Controlled.Add(minion); } if (IsTypeId(TypeId.Player)) { minion.m_ControlledByPlayer = true; minion.AddUnitFlag(UnitFlags.PlayerControlled); } // Can only have one pet. If a new one is summoned, dismiss the old one. if (minion.IsGuardianPet()) { Guardian oldPet = GetGuardianPet(); if (oldPet) { if (oldPet != minion && (oldPet.IsPet() || minion.IsPet() || oldPet.GetEntry() != minion.GetEntry())) { // remove existing minion pet if (oldPet.IsPet()) { ((Pet)oldPet).Remove(PetSaveMode.AsCurrent); } else { oldPet.UnSummon(); } SetPetGUID(minion.GetGUID()); SetMinionGUID(ObjectGuid.Empty); } } else { SetPetGUID(minion.GetGUID()); SetMinionGUID(ObjectGuid.Empty); } } if (minion.HasUnitTypeMask(UnitTypeMask.Guardian)) { if (GetMinionGUID().IsEmpty()) { SetMinionGUID(minion.GetGUID()); } } var properties = minion.m_Properties; if (properties != null && properties.Title == SummonTitle.Companion) { SetCritterGUID(minion.GetGUID()); Player thisPlayer = ToPlayer(); if (thisPlayer != null) { if (properties.GetFlags().HasFlag(SummonPropertiesFlags.SummonFromBattlePetJournal)) { var pet = thisPlayer.GetSession().GetBattlePetMgr().GetPet(thisPlayer.GetSummonedBattlePetGUID()); if (pet != null) { minion.SetBattlePetCompanionGUID(thisPlayer.GetSummonedBattlePetGUID()); minion.SetBattlePetCompanionNameTimestamp((uint)pet.NameTimestamp); minion.SetWildBattlePetLevel(pet.PacketInfo.Level); uint display = pet.PacketInfo.DisplayID; if (display != 0) { minion.SetDisplayId(display); minion.SetNativeDisplayId(display); } } } } } // PvP, FFAPvP minion.SetPvpFlags(GetPvpFlags()); // FIXME: hack, speed must be set only at follow if (IsTypeId(TypeId.Player) && minion.IsPet()) { for (UnitMoveType i = 0; i < UnitMoveType.Max; ++i) { minion.SetSpeedRate(i, m_speed_rate[(int)i]); } } // Send infinity cooldown - client does that automatically but after relog cooldown needs to be set again SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(minion.m_unitData.CreatedBySpell, GetMap().GetDifficultyID()); if (spellInfo != null && spellInfo.IsCooldownStartedOnEvent()) { GetSpellHistory().StartCooldown(spellInfo, 0, null, true); } } else { if (minion.GetOwnerGUID() != GetGUID()) { Log.outFatal(LogFilter.Unit, "SetMinion: Minion {0} is not the minion of owner {1}", minion.GetEntry(), GetEntry()); return; } m_Controlled.Remove(minion); if (minion.m_Properties != null && minion.m_Properties.Title == SummonTitle.Companion) { if (GetCritterGUID() == minion.GetGUID()) { SetCritterGUID(ObjectGuid.Empty); } } if (minion.IsGuardianPet()) { if (GetPetGUID() == minion.GetGUID()) { SetPetGUID(ObjectGuid.Empty); } } else if (minion.IsTotem()) { // All summoned by totem minions must disappear when it is removed. SpellInfo spInfo = Global.SpellMgr.GetSpellInfo(minion.ToTotem().GetSpell(), GetMap().GetDifficultyID()); if (spInfo != null) { foreach (var spellEffectInfo in spInfo.GetEffects()) { if (spellEffectInfo == null || !spellEffectInfo.IsEffect(SpellEffectName.Summon)) { continue; } RemoveAllMinionsByEntry((uint)spellEffectInfo.MiscValue); } } } SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(minion.m_unitData.CreatedBySpell, GetMap().GetDifficultyID()); // Remove infinity cooldown if (spellInfo != null && spellInfo.IsCooldownStartedOnEvent()) { GetSpellHistory().SendCooldownEvent(spellInfo); } if (GetMinionGUID() == minion.GetGUID()) { SetMinionGUID(ObjectGuid.Empty); // Check if there is another minion foreach (var unit in m_Controlled) { // do not use this check, creature do not have charm guid if (GetGUID() == unit.GetCharmerGUID()) { continue; } Cypher.Assert(unit.GetOwnerGUID() == GetGUID()); if (unit.GetOwnerGUID() != GetGUID()) { Cypher.Assert(false); } Cypher.Assert(unit.IsTypeId(TypeId.Unit)); if (!unit.HasUnitTypeMask(UnitTypeMask.Guardian)) { continue; } SetMinionGUID(unit.GetGUID()); // show another pet bar if there is no charm bar if (GetTypeId() == TypeId.Player && GetCharmedGUID().IsEmpty()) { if (unit.IsPet()) { ToPlayer().PetSpellInitialize(); } else { ToPlayer().CharmSpellInitialize(); } } break; } } } UpdatePetCombatState(); }