void HandleUseCritterItem(UseCritterItem useCritterItem) { Item item = GetPlayer().GetItemByGuid(useCritterItem.ItemGuid); if (!item) { return; } foreach (var itemEffect in item.GetEffects()) { if (itemEffect.TriggerType != ItemSpelltriggerType.LearnSpellId) { continue; } var speciesEntry = Global.SpellMgr.GetBattlePetSpecies((uint)itemEffect.SpellID); if (speciesEntry != null) { GetBattlePetMgr().AddPet(speciesEntry.Id, BattlePetMgr.SelectPetDisplay(speciesEntry), BattlePetMgr.RollPetBreed(speciesEntry.Id), BattlePetMgr.GetDefaultPetQuality(speciesEntry.Id)); } } GetPlayer().DestroyItem(item.GetBagSlot(), item.GetSlot(), true); }
void HandleUseItem(UseItem packet) { Player user = GetPlayer(); // ignore for remote control state if (user.GetUnitBeingMoved() != user) { return; } Item item = user.GetUseableItemByPos(packet.PackSlot, packet.Slot); if (item == null) { user.SendEquipError(InventoryResult.ItemNotFound); return; } if (item.GetGUID() != packet.CastItem) { user.SendEquipError(InventoryResult.ItemNotFound); return; } ItemTemplate proto = item.GetTemplate(); if (proto == null) { user.SendEquipError(InventoryResult.ItemNotFound, item); return; } // some item classes can be used only in equipped state if (proto.GetInventoryType() != InventoryType.NonEquip && !item.IsEquipped()) { user.SendEquipError(InventoryResult.ItemNotFound, item); return; } InventoryResult msg = user.CanUseItem(item); if (msg != InventoryResult.Ok) { user.SendEquipError(msg, item); return; } // only allow conjured consumable, bandage, poisons (all should have the 2^21 item flag set in DB) if (proto.GetClass() == ItemClass.Consumable && !proto.HasFlag(ItemFlags.IgnoreDefaultArenaRestrictions) && user.InArena()) { user.SendEquipError(InventoryResult.NotDuringArenaMatch, item); return; } // don't allow items banned in arena if (proto.HasFlag(ItemFlags.NotUseableInArena) && user.InArena()) { user.SendEquipError(InventoryResult.NotDuringArenaMatch, item); return; } if (user.IsInCombat()) { foreach (ItemEffectRecord effect in item.GetEffects()) { SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo((uint)effect.SpellID, user.GetMap().GetDifficultyID()); if (spellInfo != null) { if (!spellInfo.CanBeUsedInCombat()) { user.SendEquipError(InventoryResult.NotInCombat, item); return; } } } } // check also BIND_WHEN_PICKED_UP and BIND_QUEST_ITEM for .additem or .additemset case by GM (not binded at adding to inventory) if (item.GetBonding() == ItemBondingType.OnUse || item.GetBonding() == ItemBondingType.OnAcquire || item.GetBonding() == ItemBondingType.Quest) { if (!item.IsSoulBound()) { item.SetState(ItemUpdateState.Changed, user); item.SetBinding(true); GetCollectionMgr().AddItemAppearance(item); } } user.RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags.ItemUse); SpellCastTargets targets = new(user, packet.Cast); // Note: If script stop casting it must send appropriate data to client to prevent stuck item in gray state. if (!Global.ScriptMgr.OnItemUse(user, item, targets, packet.Cast.CastID)) { // no script or script not process request by self user.CastItemUseSpell(item, targets, packet.Cast.CastID, packet.Cast.Misc); } }