/// <summary> /// Adds a new Aura with the given information to the Owner. /// Does not initialize the new Aura. /// If you use this method, make sure to call <see cref="M:WCell.RealmServer.Spells.Auras.Aura.Start" /> on the newly created Aura. /// Overrides any existing Aura that matches. /// </summary> /// <returns>null if Spell is not an Aura</returns> internal Aura CreateAura(ObjectReference casterReference, Spell spell, List <AuraEffectHandler> handlers, WCell.RealmServer.Entities.Item usedItem, bool beneficial) { byte freeIndex = this.GetFreeIndex(beneficial); if (freeIndex == byte.MaxValue) { return((Aura)null); } Aura aura = new Aura(this, casterReference, spell, handlers, freeIndex, beneficial); aura.UsedItem = usedItem; this.AddAura(aura, false); return(aura); }
/// <summary> /// Applies the given spell as a buff or debuff. /// Also initializes the new Aura. /// </summary> /// <returns>null if Spell is not an Aura or an already existing version of the Aura that was refreshed</returns> public Aura CreateAndStartAura(ObjectReference caster, Spell spell, bool noTimeout, WCell.RealmServer.Entities.Item usedItem = null) { try { Aura aura = this.CreateAura(caster, spell, usedItem); if (aura != null) { aura.Start((ITickTimer)null, noTimeout); return(aura); } } catch (Exception ex) { LogUtil.ErrorException(ex, "Unable to add new Aura \"{0}\" by \"{1}\" to: {2}", (object)spell, (object)caster, (object)this.m_owner); } return((Aura)null); }
/// <summary> /// Applies the given spell as a buff or debuff. /// Does not necessarily create /// Also, initializes new Auras. /// </summary> /// <returns>null if Spell is not an Aura or an already existing version of the Aura that was refreshed</returns> public Aura CreateAura(ObjectReference caster, Spell spell, WCell.RealmServer.Entities.Item usedItem = null) { try { bool flag = spell.IsBeneficialFor(caster, (WorldObject)this.m_owner); AuraIndexId auraUid = spell.GetAuraUID(flag); SpellFailedReason err = SpellFailedReason.Ok; Aura aura1 = this.GetAura(caster, auraUid, spell); if (aura1 != null && !this.PrepareStackOrOverride(caster, aura1, spell, ref err, (SpellCast)null)) { if (err == SpellFailedReason.Ok) { return(aura1); } if (caster.Object is Character) { SpellHandler.SendCastFailed((IPacketReceiver)caster.Object, spell, err); } return((Aura)null); } List <AuraEffectHandler> auraEffectHandlers = spell.CreateAuraEffectHandlers(caster, this.m_owner, flag); if (auraEffectHandlers != null) { Aura aura2 = this.CreateAura(caster, spell, auraEffectHandlers, usedItem, flag); if (aura2 != null) { this.OnCreated(aura2); } return(aura2); } } catch (Exception ex) { LogUtil.ErrorException(ex, "Unable to add new Aura \"{0}\" by \"{1}\" to: {2}", (object)spell, (object)caster, (object)this.m_owner); } return((Aura)null); }
private static void RemoveCombatSpell(Item item, ItemEnchantmentEffect effect) { item.OwningCharacter.RemoveProcHandler(handler => handler.ProcSpell != null && handler.ProcSpell.Id == effect.Misc); }
private bool CheckFreeSlots(IList<SimpleSlotId> myFreeSlots, Item[] items) { var hasSlots = true; var currentSlot = 0; for (var i = 0; i < TRADE_SLOT_TRADED_COUNT; i++) { if (items[i] == null) continue; if (myFreeSlots.Count <= currentSlot) { hasSlots = false; break; } var slot = myFreeSlots[currentSlot].Slot; var container = myFreeSlots[currentSlot].Container; var handler = container.GetHandler(slot); var err = InventoryError.OK; // Does not check if the slot is unoccupied, which is good handler.CheckAdd(slot, items[i].Amount, items[i], ref err); if (err != InventoryError.OK) { hasSlots = false; break; } var amount = items[i].Amount; container.CheckUniqueness(items[i], ref amount, ref err, true); if (err != InventoryError.OK) { hasSlots = false; break; } currentSlot++; } if (!hasSlots) { m_chr.SendSystemMessage("You don't have enough free slots"); Other.m_chr.SendSystemMessage("Other party doesn't have enough free slots"); SetTradeStatus(TradeStatus.StateChanged); } return hasSlots; }
bool CheckItemRestriction(Item item) { if (item.Template.Class != RequiredItemClass) { return false; } if (RequiredItemSubClassMask > 0 && !item.Template.SubClassMask.HasAnyFlag(RequiredItemSubClassMask)) { return false; } return true; }
/// <summary> /// Sends the Item's PushResult (required after adding items). /// </summary> public static void SendItemPushResult(Character owner, Item item, ItemTemplate templ, int amount, ItemReceptionType reception) { bool isStacked; int contSlot; uint propertySeed, randomPropid; if (item != null) { contSlot = item.Container.Slot; isStacked = item.Amount != amount; // item.Amount == amount means that it was not added to an existing stack propertySeed = item.PropertySeed; randomPropid = item.RandomPropertiesId; } else { contSlot = BaseInventory.INVALID_SLOT; isStacked = true; // we did not have an item -> stacked propertySeed = 0; randomPropid = 0; } using (var packet = new RealmPacketOut(RealmServerOpCode.SMSG_ITEM_PUSH_RESULT, 44)) { packet.Write(owner.EntityId); packet.Write((ulong)reception); //packet.Write(received ? 1 : 0); // 0 = "You looted...", 1 = "You received..." //packet.Write(isNew ? 1 : 0); // 0 = "You received/looted...", 1 = "You created..." packet.Write(1); // log message packet.Write((byte)contSlot); packet.Write(isStacked ? -1 : item.Slot); packet.Write(templ.Id); packet.Write(propertySeed); packet.Write(randomPropid); packet.Write(amount); // amount added packet.Write(owner.Inventory.GetAmount(templ.ItemId)); // amount of that type of item in inventory owner.Send(packet); } }
public static void SendEnchantTimeUpdate(IPacketReceivingEntity owner, Item item, int duration) { using (var packet = new RealmPacketOut(RealmServerOpCode.SMSG_ITEM_ENCHANT_TIME_UPDATE, 24)) { packet.Write(item.EntityId); packet.Write(item.Slot); packet.Write(duration); packet.Write(owner.EntityId); owner.Send(packet); } }
private static void RemoveDamageFromItem(Item item, ItemEnchantmentEffect effect) { item.BonusDamage -= effect.MaxAmount; if (item.IsEquippedItem) { item.Container.Owner.UpdateDamage((InventorySlot)item.Slot); } }
/// <summary> /// Is called after the given item is removed from the given slot /// </summary> public void Removed(int slot, Item item) { }
private static void RemoveResistance(Item item, ItemEnchantmentEffect effect) { item.OwningCharacter.RemoveResistanceBuff((DamageSchool)effect.Misc, effect.MaxAmount); }
private static void RemoveTotem(Item item, ItemEnchantmentEffect effect) { }
/// <summary> /// Applies the given spell as a buff or debuff. /// Also initializes the new Aura. /// </summary> /// <returns>null if Spell is not an Aura</returns> public Aura CreateAndStartAura(ObjectReference caster, SpellId spell, bool noTimeout, WCell.RealmServer.Entities.Item usedItem = null) { return(this.CreateAndStartAura(caster, SpellHandler.Get(spell), noTimeout, usedItem)); }
internal static void RemoveEnchantFromItem(Item item, ItemEnchantment enchant) { foreach (var effect in enchant.Entry.Effects) { var handler = RemoveEnchantFromItemHandlers[(uint)effect.Type]; if (handler != null) { handler(item, effect); } } }
private void TransferItems(IList<SimpleSlotId> simpleSlots, Item[] items) { var slotId = 0; for (var i = 0; i < items.Length; i++) { var item = items[i]; if (item == null) continue; var simpleSlot = simpleSlots[slotId]; var amount = item.Amount; simpleSlot.Container.Distribute(item.Template, ref amount); if (amount < item.Amount) { item.Remove(true); item.Amount -= amount; simpleSlot.Container.AddUnchecked(simpleSlot.Slot, item, true); } else { // The whole stack was added to the other stacks, so we can delete the item item.Destroy(); } slotId++; } }
/// <summary> /// Sends the Item's PushResult (required after adding items). /// </summary> public static void SendItemPushResult(Character owner, Item item, bool isNew, byte contSlot, int slot) { using (var packet = new RealmPacketOut(RealmServerOpCode.SMSG_ITEM_PUSH_RESULT, 44)) { packet.Write(owner.EntityId); packet.Write(isNew ? 1 : 0); packet.Write(isNew ? 0 : 1); packet.Write(1); packet.Write((byte)slot); packet.Write((int)contSlot); packet.Write(item.Template.Id); packet.Write(item.PropertySeed); packet.Write(item.RandomPropertiesId); packet.Write(item.Amount); packet.Write(item.Amount); owner.Send(packet); } }
private static void DoNothing(Item item, ItemEnchantmentEffect effect) { }
private static void RemoveDamage(Item item, ItemEnchantmentEffect effect) { var owner = item.OwningCharacter; owner.RemoveDamageDoneMod(DamageSchool.Physical, effect.MaxAmount); owner.UpdateAllDamages(); }
/// <summary> /// Removes the given EnchantEffect from the given Item and the wearer of the Item /// </summary> /// <param name="item"></param> /// <param name="effect"></param> internal static void RemoveEffect(Item item, ItemEnchantmentEffect effect) { RemoveEnchantHandlers[(uint)effect.Type](item, effect); }
private static void RemoveEquipSpell(Item item, ItemEnchantmentEffect effect) { item.OwningCharacter.Auras.Cancel((SpellId)effect.Misc); }
private static void ApplyEquipSpell(Item item, ItemEnchantmentEffect effect) { var owner = item.OwningCharacter; var spell = SpellHandler.Get((SpellId)effect.Misc); if (spell == null) { LogManager.GetCurrentClassLogger().Warn("{0} had invalid SpellId: {1}", effect, (SpellId)effect.Misc); return; } SpellCast.ValidateAndTriggerNew(spell, owner, owner, null, item); }
private static void RemoveStat(Item item, ItemEnchantmentEffect effect) { item.OwningCharacter.RemoveStatMod((ItemModType)effect.Misc, effect.MaxAmount); }
public abstract void AddCooldown(Spell spell, WCell.RealmServer.Entities.Item casterItem);
/// <summary> /// Applies the given EnchantEffect to the given Item and the wearer of the Item /// </summary> /// <param name="item"></param> /// <param name="effect"></param> internal static void ApplyEffect(Item item, ItemEnchantmentEffect effect) { ApplyEnchantHandlers[(uint)effect.Type](item, effect); }
internal void OnBeforeUnEquip(Item item) { if (itemRestrictedAuras != null) { var plr = (Character)m_owner; // PlayerAuraCollection always has Character owner foreach (var aura in itemRestrictedAuras) { if (aura.IsActivated) { aura.IsActivated = MayActivate(aura, false) && aura.Spell.CheckItemRestrictionsWithout(plr.Inventory, item) == SpellFailedReason.Ok; } } } }
/// <summary> /// Is called after the given item is added to the given slot /// </summary> public void Added(Item item) { }
private static void ApplyCombatSpell(Item item, ItemEnchantmentEffect effect) { var spell = SpellHandler.Get(effect.Misc); if (spell == null) { ContentMgr.OnInvalidClientData("Enchantment Effect {0} had invalid SpellId: {1}", effect, (SpellId)effect.Misc); } else { item.OwningCharacter.AddProcHandler(new ItemHitProcHandler(item, spell)); } }
public static void HandleSocketGem(IRealmClient client, RealmPacketIn packet) { var inv = client.ActiveCharacter.Inventory; if (inv.CheckInteract() == InventoryError.OK) { var itemId = packet.ReadEntityId(); var item = inv.GetItem(itemId); if (item == null) { return; } var gems = new Item[ItemConstants.MaxSocketCount]; for (var i = 0; i < ItemConstants.MaxSocketCount; i++) { var id = packet.ReadEntityId(); if (id != EntityId.Zero) { gems[i] = inv.GetItem(id); } } item.ApplyGems(gems); } }
private static void ApplyDamage(Item item, ItemEnchantmentEffect effect) { var owner = item.OwningCharacter; owner.AddDamageDoneMod(DamageSchool.Physical, effect.MaxAmount); }
/// <summary> /// item1 and item2 can be null, but item1 must be set in case of YOU_MUST_REACH_LEVEL_N. /// </summary> /// <param name="client"></param> /// <param name="item1"></param> /// <param name="item2"></param> /// <param name="error"></param> public static void SendInventoryError(IPacketReceiver client, Item item1, Item item2, InventoryError error) { using (var packet = new RealmPacketOut(RealmServerOpCode.SMSG_INVENTORY_CHANGE_FAILURE, error == InventoryError.YOU_MUST_REACH_LEVEL_N ? 22 : 18)) { packet.WriteByte((byte)error); if (item1 != null) { packet.Write(item1.EntityId.Full); } else { packet.Write((long)0); } if (item2 != null) { packet.Write(item2.EntityId.Full); } else { packet.Write((long)0); } packet.Write((byte)0); if (error == InventoryError.YOU_MUST_REACH_LEVEL_N && item1 != null) { packet.WriteUInt(item1.Template.RequiredLevel); } client.Send(packet); } }
private static void ApplyEquipSpell(Item item, ItemEnchantmentEffect effect) { var owner = item.OwningCharacter; owner.SpellCast.Trigger((SpellId)effect.Misc, owner); }
/// <summary> /// Sends the new state of the trading window to other party /// </summary> /// <param name="otherParty">Whether this is sending the own info to the other party (or, if false, to oneself)</param> /// <param name="client">receiving party</param> /// <param name="money">new amount of money</param> /// <param name="items">new items</param> public static void SendTradeUpdate(IPacketReceiver client, bool otherParty, uint money, Item[] items) { using (var pkt = new RealmPacketOut(RealmServerOpCode.SMSG_TRADE_STATUS_EXTENDED, 30 + 18 * 4 * items.Length)) { pkt.Write(otherParty); pkt.Write(0); // Trade id pkt.Write(items.Length); pkt.Write(items.Length); pkt.Write(money); pkt.Write(0); for (var i = 0; i < items.Length; i++) { pkt.WriteByte(i); var item = items[i]; if (item != null) { pkt.Write(item.EntryId); pkt.Write(item.Template.DisplayId); pkt.Write(item.Amount); pkt.Write(0); pkt.Write(item.GiftCreator); var enchant = item.GetEnchantment(EnchantSlot.Permanent); pkt.Write(enchant != null ? enchant.Entry.Id : 0); pkt.Zero(4 * 3); pkt.Write(item.Creator); pkt.Write(item.SpellCharges); pkt.Write(item.Template.RandomSuffixFactor); pkt.Write(item.RandomPropertiesId); var itemLock = item.Lock; pkt.Write(itemLock != null ? itemLock.Id : 0); pkt.Write(item.MaxDurability); pkt.Write(item.Durability); } else { pkt.Zero(18 * 4); } } client.Send(pkt); } }
private static void ApplyTotem(Item item, ItemEnchantmentEffect effect) { }
private void AddItems(IList<SimpleSlotId> simpleSlots, Item[] items) { var slotId = 0; for (var i = 0; i < items.Length; i++) { var item = items[i]; if (item == null) continue; var simpleSlot = simpleSlots[slotId]; var amount = item.Amount; simpleSlot.Container.Distribute(item.Template, ref amount); if (amount < item.Amount) { item.Amount -= amount; simpleSlot.Container.AddUnchecked(simpleSlot.Slot, item, true); } else { // The whole stack was added to the other stacks, we can dispose of the item. item.Amount = 0; // destroys the item. } slotId++; } }
/// <summary> /// Checks whether the given inventory satisfies this Spell's item restrictions /// </summary> public SpellFailedReason CheckItemRestrictionsWithout(PlayerInventory inv, Item exclude) { if (RequiredItemClass == ItemClass.Armor || RequiredItemClass == ItemClass.Weapon) { Item item; if (EquipmentSlot != EquipmentSlot.End) { item = inv[EquipmentSlot]; if (item == null || item == exclude) { return SpellFailedReason.EquippedItem; } if (!CheckItemRestriction(item)) { return SpellFailedReason.EquippedItemClass; } } else { if (inv.Iterate(ItemMgr.EquippableInvSlotsByClass[(int)RequiredItemClass], i => i == exclude || !CheckItemRestriction(i))) { return SpellFailedReason.EquippedItemClass; } } } if (RequiredItemInventorySlotMask != InventorySlotTypeMask.None) { if (inv.Iterate(RequiredItemInventorySlotMask, item => item == exclude || (item.Template.InventorySlotMask & RequiredItemInventorySlotMask) == 0 )) { // iterated over all matching items and did not find the right one return SpellFailedReason.EquippedItemClass; } } return CheckGeneralItemRestrictions(inv); }