コード例 #1
0
        /// <summary>
        /// Is called before adding to check whether the item may be added to the corresponding slot
        /// (given the case that the corresponding slot is valid and unoccupied)
        /// </summary>
        public virtual void CheckAdd(int slot, int amount, IMountableItem item, ref InventoryError err)
        {
            ItemTemplate template = item.Template;

            err = template.CheckEquip(this.Owner);
            if (err != InventoryError.OK)
            {
                return;
            }
            if (!template.IsBag)
            {
                err = InventoryError.NOT_A_BAG;
            }
            else if (this.m_inventory[slot] != null)
            {
                err = InventoryError.NONEMPTY_BAG_OVER_OTHER_BAG;
            }
            else
            {
                if (item.IsEquipped)
                {
                    return;
                }
                err = this.m_inventory.CheckEquipCount(item);
            }
        }
コード例 #2
0
 /// <summary>
 /// Is called before adding to check whether the item may be added to the corresponding slot
 /// (given the case that the corresponding slot is valid and unoccupied)
 /// </summary>
 public void CheckAdd(int slot, int amount, IMountableItem item, ref InventoryError err)
 {
     if (!m_inventory.IsBankOpen)
     {
         err = InventoryError.TOO_FAR_AWAY_FROM_BANK;
     }
 }
コード例 #3
0
ファイル: BaseInventory.cs プロジェクト: uvbs/Asda2-Server
        /// <summary>
        /// Tries to add an item with the given template and amount
        /// </summary>
        /// <param name="amount">Amount of items to be added: Will be set to the amount of Items that have actually been added.</param>
        /// <returns>The result (InventoryError.OK in case that it worked)</returns>
        public InventoryError TryAdd(ItemTemplate template, ref int amount,
                                     ItemReceptionType reception = ItemReceptionType.Receive)
        {
            int            amount1 = amount;
            InventoryError err     = InventoryError.OK;
            Item           obj     = (Item)null;

            if (!this.Distribute(template, ref amount1))
            {
                amount -= amount1;
                this.CheckUniqueness((IMountableItem)template, ref amount, ref err, true);
                if (err == InventoryError.OK)
                {
                    SimpleSlotId freeSlot = this.FindFreeSlot((IMountableItem)template, amount);
                    if (freeSlot.Slot == (int)byte.MaxValue)
                    {
                        return(this.FullError);
                    }
                    obj = freeSlot.Container.AddUnchecked(freeSlot.Slot, template, amount, true);
                }
            }

            this.OnAdded(obj, template, amount1 + (obj != null ? obj.Amount : 0), reception);
            return(err);
        }
コード例 #4
0
        public void GetItemTest()
        {
            InventoryService target = new InventoryService();

            Assert.AreEqual(target.ItemCount, 0);

            // add new item to inventory
            string            label      = "Reagent1";
            DateTime          expiration = new DateTime(2020, 12, 31);
            InventoryItemType type       = InventoryItemType.Liquid;
            InventoryError    error      = target.AddItem(label, expiration, type);

            Assert.AreEqual(error.ErrorCode, ErrorCode.Success);
            Assert.AreEqual(target.ItemCount, 1);

            // get existing item
            InventoryItem item = target.GetItem(label);

            Assert.IsNotNull(item);
            Assert.AreEqual(item.Label, label);
            Assert.AreEqual(item.ExpirationDate, expiration);
            Assert.AreEqual(item.ItemType, type);

            // get non existing item
            item = target.GetItem("Reagent2");
            Assert.IsNull(item);
        }
コード例 #5
0
ファイル: BaseInventory.cs プロジェクト: uvbs/Asda2-Server
        /// <summary>
        /// Tries to add the given item to the given slot (make sure the slot is valid and not occupied).
        /// Fails if not all items of this stack can be added.
        /// </summary>
        /// <returns>InventoryError.OK in case that it worked</returns>
        public InventoryError TryAdd(int slot, Item item, bool isNew,
                                     ItemReceptionType reception = ItemReceptionType.Receive)
        {
            int            amount = item.Amount;
            InventoryError err    = this.CheckAdd(slot, (IMountableItem)item, amount);

            if (err == InventoryError.OK)
            {
                this.CheckUniqueness((IMountableItem)item, ref amount, ref err, isNew);
                if (err == InventoryError.OK && amount != item.Amount)
                {
                    err = InventoryError.CANT_CARRY_MORE_OF_THIS;
                }
                else
                {
                    this.AddUnchecked(slot, item, isNew);
                    if (isNew)
                    {
                        this.OnAdded(item, item.Template, amount, reception);
                    }
                }
            }

            return(err);
        }
コード例 #6
0
 /// <summary>
 /// Is called before adding to check whether the item may be added to the corresponding slot
 /// (given the case that the corresponding slot is valid and unoccupied)
 /// </summary>
 public void CheckAdd(int slot, int amount, IMountableItem item, ref InventoryError err)
 {
     if (item.Template.IsKey)
     {
         err = InventoryError.ITEM_DOESNT_GO_INTO_BAG;
     }
 }
コード例 #7
0
ファイル: BaseInventory.cs プロジェクト: uvbs/Asda2-Server
        /// <summary>
        /// Tries to distribute the given amount of the given Item over all available stacks and add the remainder to a free slot.
        /// Parts of the stack might have distributed over existing stacks, even if adding the remainder failed.
        /// </summary>
        /// <returns>InventoryError.OK in case that it could be added</returns>
        public InventoryError TryAddAmount(Item item, int amount, bool isNew,
                                           ItemReceptionType reception = ItemReceptionType.Receive)
        {
            int            amount1 = amount;
            InventoryError err     = InventoryError.OK;

            if (!this.Distribute(item.Template, ref amount1))
            {
                this.CheckUniqueness((IMountableItem)item, ref amount, ref err, isNew);
                if (err == InventoryError.OK)
                {
                    amount     -= amount1;
                    item.Amount = amount;
                    SimpleSlotId freeSlot = this.FindFreeSlot((IMountableItem)item, amount);
                    if (freeSlot.Slot == (int)byte.MaxValue)
                    {
                        return(InventoryError.BAG_FULL);
                    }
                    freeSlot.Container.AddUnchecked(freeSlot.Slot, item.Template, amount, isNew);
                }
            }
            else
            {
                amount     -= amount1;
                item.Amount = amount;
            }

            if (isNew)
            {
                this.OnAdded(item, item.Template, amount1 + amount, reception);
            }
            return(err);
        }
コード例 #8
0
 /// <summary>
 /// Is called before adding to check whether the item may be added to the corresponding slot
 /// (given the case that the corresponding slot is valid and unoccupied)
 /// </summary>
 public void CheckAdd(int slot, int amount, IMountableItem item, ref InventoryError err)
 {
     if (item.Template.Class != ItemClass.Key)
     {
         err = InventoryError.ITEM_DOESNT_GO_TO_SLOT;
     }
 }
コード例 #9
0
        /// <summary>
        /// Is called before adding to check whether the item may be added to the corresponding slot
        /// (given the case that the corresponding slot is valid and unoccupied)
        /// </summary>
        public virtual void CheckAdd(int slot, int amount, IMountableItem item, ref InventoryError err)
        {
            var templ = item.Template;

            err = templ.CheckEquip(Owner);
            if (err == InventoryError.OK)
            {
                if (!templ.IsBag)
                {
                    err = InventoryError.NOT_A_BAG;
                }
                else
                {
                    var oldBag = m_inventory[slot];
                    if (oldBag != null)
                    {
                        err = InventoryError.NONEMPTY_BAG_OVER_OTHER_BAG;
                    }
                    else if (!item.IsEquipped)
                    {
                        err = m_inventory.CheckEquipCount(item);
                    }
                }
            }
        }
コード例 #10
0
ファイル: BaseInventory.cs プロジェクト: uvbs/Asda2-Server
        /// <summary>
        /// Tries to distribute the given item over all available stacks and add the remainder to a free slot.
        /// IMPORTANT:
        /// 1. The Item will be destroyed if it could successfully be distributed over existing stacks of Items.
        /// 2. If item.Container == null, parts of the item-stack might have distributed over other stacks of the same type
        /// but the remainder did not find a free slot or exceeded the max count of the item.
        /// item.Amount will hold the remaining amount.
        /// </summary>
        /// <returns>The result (InventoryError.OK in case that it worked)</returns>
        public InventoryError TryAdd(Item item, bool isNew, ItemReceptionType reception = ItemReceptionType.Receive)
        {
            int            amount1 = item.Amount;
            InventoryError err     = InventoryError.OK;
            int            amount2 = amount1;

            if (!this.Distribute(item.Template, ref amount2))
            {
                int amount3 = amount1 - amount2;
                item.Amount = amount3;
                this.CheckUniqueness((IMountableItem)item, ref amount3, ref err, isNew);
                if (err == InventoryError.OK)
                {
                    SimpleSlotId freeSlot = this.FindFreeSlot((IMountableItem)item, amount3);
                    if (freeSlot.Slot == (int)byte.MaxValue)
                    {
                        return(this.FullError);
                    }
                    freeSlot.Container.AddUnchecked(freeSlot.Slot, item, isNew);
                }
            }
            else
            {
                int num = amount1 - amount2;
                item.Amount = num;
            }

            if (isNew)
            {
                this.OnAdded(item, item.Template, amount2 + item.Amount, reception);
            }
            return(err);
        }
コード例 #11
0
ファイル: BaseInventory.cs プロジェクト: uvbs/Asda2-Server
        /// <summary>
        /// Tries to add a new item with the given template and amount ot the given slot.
        /// Make sure the given targetSlot is valid before calling this method.
        /// </summary>
        /// <returns>The result (InventoryError.OK in case that it worked)</returns>
        public InventoryError TryAdd(ItemTemplate template, ref int amount, int slot,
                                     ItemReceptionType reception = ItemReceptionType.Receive)
        {
            if (this.m_Items[slot] != null)
            {
                LogManager.GetCurrentClassLogger().Warn("Tried to add Item {0} to {1} in occupied slot {2}",
                                                        (object)template, (object)this, (object)slot);
                return(InventoryError.ITEM_DOESNT_GO_TO_SLOT);
            }

            InventoryError err = InventoryError.OK;

            this.CheckUniqueness((IMountableItem)template, ref amount, ref err, true);
            if (err == InventoryError.OK)
            {
                IItemSlotHandler handler = this.GetHandler(slot);
                if (handler != null)
                {
                    err = InventoryError.OK;
                    handler.CheckAdd(slot, amount, (IMountableItem)template, ref err);
                    if (err != InventoryError.OK)
                    {
                        return(err);
                    }
                }

                this.OnAdded(this.AddUnchecked(slot, template, amount, true), template, amount, reception);
            }

            return(err);
        }
コード例 #12
0
        /// <summary>
        /// Try to loot the item at the given index of the current loot
        /// </summary>
        /// <returns>The looted Item or null if Item could not be taken</returns>
        public void TakeItem(LooterEntry entry, uint index, BaseInventory targetCont, int targetSlot)
        {
            LootItem lootItem = (LootItem)null;

            try
            {
                Character owner = entry.Owner;
                if (owner == null || (long)index >= (long)this.Items.Length)
                {
                    return;
                }
                lootItem = this.Items[index];
                InventoryError itemConditions = this.CheckTakeItemConditions(entry, lootItem);
                if (itemConditions == InventoryError.OK)
                {
                    this.HandoutItem(owner, lootItem, targetCont, targetSlot);
                }
                else
                {
                    ItemHandler.SendInventoryError((IPacketReceiver)owner.Client, (Item)null, (Item)null,
                                                   itemConditions);
                }
            }
            catch (Exception ex)
            {
                LogUtil.ErrorException(ex, "{0} threw an Exception while looting \"{1}\" (index = {2}) from {3}",
                                       (object)entry.Owner, (object)lootItem, (object)index, (object)targetCont);
            }
        }
コード例 #13
0
 /// <summary>
 /// Is called before adding to check whether the item may be added to the corresponding slot
 /// (given the case that the corresponding slot is valid and unoccupied)
 /// </summary>
 public void CheckAdd(int slot, int amount, IMountableItem item, ref InventoryError err)
 {
     if (item.Template.IsKey)
     {
         err = InventoryError.ITEM_DOESNT_GO_INTO_BAG;
     }
     else if (item.Template.IsContainer)
     {
         err = InventoryError.NONEMPTY_BAG_OVER_OTHER_BAG;
     }
     else
     {
         if (err == InventoryError.OK)
         {
             if (m_container is Item)
             {
                 var bag = (Item)m_container;
                 if (!bag.Template.MayAddToContainer(item.Template))
                 {
                     err = InventoryError.ITEM_DOESNT_GO_INTO_BAG;
                 }
             }
         }
     }
 }
コード例 #14
0
    /// <summary>
    /// Swap the location of items across separate inventories.
    /// </summary>
    /// <param name="index">The index to swap into.</param>
    /// <param name="otherItem">The item to swap in.</param>
    /// <returns>An error representing the result of this operation.</returns>
    private InventoryError Swap(int index, PortableItem otherItem)
    {
        Inventory    otherInventory = otherItem.inventory;
        PortableItem thisItem       = this.items[index];

        int otherIndex = otherInventory.IndexOf(otherItem);

        // This item does not exist in the other inventory...?
        if (otherIndex == -1)
        {
            return(InventoryError.Unknown);
        }

        // We set these values to null to act like we're trying to insert an
        // element that doesn't belong to an inventory into an empty inventory
        // slot.
        otherInventory[otherIndex] = null;
        thisItem.inventory         = null;
        InventoryError err = otherInventory.Set(otherIndex, thisItem);

        if (err != InventoryError.NoError)
        {
            // Failed to set this item in the other inventory. Revert.
            otherInventory[otherIndex] = otherItem;
            thisItem.inventory         = this;
            return(err);
        }

        this.UpdateIndex(index, otherItem);
        return(InventoryError.NoError);
    }
コード例 #15
0
 /// <summary>
 /// Is called before adding to check whether the item may be added to the corresponding slot
 /// (given the case that the corresponding slot is valid and unoccupied)
 /// </summary>
 public void CheckAdd(int slot, int amount, IMountableItem item, ref InventoryError err)
 {
     if (item.Template.IsKey)
     {
         err = InventoryError.ITEM_DOESNT_GO_INTO_BAG;
     }
     else if (item.Template.IsContainer)
     {
         err = InventoryError.NONEMPTY_BAG_OVER_OTHER_BAG;
     }
     else
     {
         if (err == InventoryError.OK)
         {
             if (m_container is Item)
             {
                 var bag = (Item)m_container;
                 if (!bag.Template.MayAddToContainer(item.Template))
                 {
                     err = InventoryError.ITEM_DOESNT_GO_INTO_BAG;
                 }
             }
         }
     }
 }
コード例 #16
0
 /// <summary>
 /// Is called before removing the given item to check whether it may actually be removed
 /// </summary>
 public void CheckRemove(int slot, IMountableItem templ, ref InventoryError err)
 {
     // Disarmed
     if (templ is IWeapon && templ.Template.IsWeapon && !Owner.MayCarry(templ.Template.InventorySlotMask))
     {
         err = InventoryError.CANT_DO_WHILE_DISARMED;
     }
 }
コード例 #17
0
 public bool PeekGet(IEnumerable <ItemInfoBase> infos, out InventoryError errorType, params ItemWithAmount[] simulLoseItems)
 {
     if (infos == null)
     {
         errorType = InventoryError.Invalid;
         return(false);
     }
     return(PeekGet(ItemWithAmount.Convert(infos), out errorType, simulLoseItems));
 }
コード例 #18
0
 /// <summary>
 /// 窥探性获取而不是真正获取
 /// </summary>
 /// <param name="model">道具原型</param>
 /// <param name="amount">数量</param>
 /// <param name="errorType">错误类型</param>
 /// <param name="simulLoseItems">同时失去的道具</param>
 /// <returns>是否可以获取</returns>
 public bool PeekGet(ItemBase model, int amount, out InventoryError errorType, params ItemWithAmount[] simulLoseItems)
 {
     if (!model || amount <= 0)
     {
         errorType = InventoryError.Invalid;
         return(false);
     }
     return(PeekGet(model.CreateData(false), amount, out errorType, simulLoseItems));
 }
コード例 #19
0
        /// <summary>
        /// </summary>
        /// <param name="character">
        /// </param>
        /// <param name="target">
        /// </param>
        /// <param name="args">
        /// </param>
        public override void ExecuteCommand(ICharacter character, Identity target, string[] args)
        {
            IInstancedEntity targetEntity = null;

            // Fall back to self it no target is selected
            if ((targetEntity = character.Playfield.FindByIdentity(target)) == null)
            {
                targetEntity = character;
            }

            IItemContainer container = targetEntity as IItemContainer;

            // Does this entity have a BaseInventory?
            if (container != null)
            {
                int lowId;
                int highId;
                int ql;
                if (!int.TryParse(args[1], out lowId))
                {
                    character.Playfield.Publish(ChatText.CreateIM(character, "LowId is no number"));
                    return;
                }

                if (!int.TryParse(args[2], out ql))
                {
                    character.Playfield.Publish(ChatText.CreateIM(character, "QualityLevel is no number"));
                    return;
                }

                // Determine low and high id depending on ql
                lowId  = ItemLoader.ItemList[lowId].GetLowId(ql);
                highId = ItemLoader.ItemList[lowId].GetHighId(ql);

                Item item = new Item(ql, lowId, highId);
                if (ItemLoader.ItemList[lowId].IsStackable())
                {
                    item.MultipleCount = ItemLoader.ItemList[lowId].getItemAttribute(212);
                }

                InventoryError err = container.BaseInventory.TryAdd(item);
                if (err != InventoryError.OK)
                {
                    character.Playfield.Publish(
                        ChatText.CreateIM(character, "Could not add to inventory. (" + err + ")"));
                }

                if (targetEntity as Character != null)
                {
                    AddTemplate.Send((targetEntity as Character).Client, item);
                }
            }
            else
            {
                character.Playfield.Publish(ChatText.CreateIM(character, "Target has no Inventory."));
            }
        }
コード例 #20
0
 /// <inheritdoc />
 protected override void HandleDropError(InventoryError error)
 {
     switch (error)
     {
     case InventoryError.InvalidItem:
         this.SayInvalidItem();
         return;
     }
 }
コード例 #21
0
 /// <summary>
 /// Is called before removing the given item to check whether it may actually be removed
 /// </summary>
 public void CheckRemove(int slot, IMountableItem templ, ref InventoryError err)
 {
     if (!(templ is IWeapon) || !templ.Template.IsWeapon ||
         this.Owner.MayCarry(templ.Template.InventorySlotMask))
     {
         return;
     }
     err = InventoryError.CANT_DO_WHILE_DISARMED;
 }
コード例 #22
0
        /// <summary>
        /// </summary>
        /// <param name="client">
        /// </param>
        /// <param name="quality">
        /// </param>
        public static void TradeSkillBuildPressed(ZoneClient client, int quality)
        {
            TradeSkillInfo source = client.Character.TradeSkillSource;
            TradeSkillInfo target = client.Character.TradeSkillTarget;

            Item sourceItem = client.Character.BaseInventory.GetItemInContainer(source.Container, source.Placement);
            Item targetItem = client.Character.BaseInventory.GetItemInContainer(target.Container, target.Placement);

            TradeSkillEntry ts = TradeSkill.Instance.GetTradeSkillEntry(sourceItem.HighID, targetItem.HighID);

            quality = Math.Min(quality, ItemLoader.ItemList[ts.ResultHighId].Quality);
            if (ts != null)
            {
                if (WindowBuild(client, quality, ts, sourceItem, targetItem))
                {
                    Item           newItem        = new Item(quality, ts.ResultLowId, ts.ResultHighId);
                    InventoryError inventoryError = client.Character.BaseInventory.TryAdd(newItem);
                    if (inventoryError == InventoryError.OK)
                    {
                        AddTemplate.Send(client, newItem);

                        // Delete source?
                        if ((ts.DeleteFlag & 1) == 1)
                        {
                            client.Character.BaseInventory.RemoveItem(source.Container, source.Placement);
                            DeleteItem.Send(client, source.Container, source.Placement);
                        }

                        // Delete target?
                        if ((ts.DeleteFlag & 2) == 2)
                        {
                            client.Character.BaseInventory.RemoveItem(target.Container, target.Placement);
                            DeleteItem.Send(client, target.Container, target.Placement);
                        }

                        client.Character.Playfield.Publish(
                            ChatText.CreateIM(
                                client.Character,
                                SuccessMessage(
                                    sourceItem,
                                    targetItem,
                                    new Item(quality, ts.ResultLowId, ts.ResultHighId))));

                        client.Character.Stats[StatIds.xp].Value += CalculateXP(quality, ts);
                    }
                }
            }
            else
            {
                client.Character.Playfield.Publish(
                    ChatText.CreateIM(
                        client.Character,
                        "It is not possible to assemble those two items. Maybe the order was wrong?"));
                client.Character.Playfield.Publish(ChatText.CreateIM(client.Character, "No combination found!"));
            }
        }
コード例 #23
0
        /// <summary>Is called before a bag is removed</summary>
        public void CheckRemove(int slot, IMountableItem item, ref InventoryError err)
        {
            Container container = item as Container;

            if (container == null || container.BaseInventory.IsEmpty)
            {
                return;
            }
            err = InventoryError.CAN_ONLY_DO_WITH_EMPTY_BAGS;
        }
コード例 #24
0
 public override void CheckAdd(int slot, int amount, IMountableItem item, ref InventoryError err)
 {
     if (!m_inventory.IsBankOpen)
     {
         err = InventoryError.TOO_FAR_AWAY_FROM_BANK;
     }
     else if (slot < m_inventory.Owner.BankBagSlots)
     {
         err = InventoryError.MUST_PURCHASE_THAT_BAG_SLOT;
     }
 }
コード例 #25
0
ファイル: BaseInventory.cs プロジェクト: uvbs/Asda2-Server
        /// <summary>
        /// Tries to add all given Items to this Inventory.
        /// Does not add any if not all could be added.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="items"></param>
        /// <returns></returns>
        public InventoryError TryAddAll <T>(T[] items) where T : IItemStack
        {
            SimpleSlotId[] slots1;
            InventoryError slots2 = this.GetSlots <T>(items, out slots1);

            if (slots2 == InventoryError.OK)
            {
                this.AddAllUnchecked <T>(items, slots1);
            }
            return(slots2);
        }
コード例 #26
0
        /// <summary>
        /// Is called before a bag is removed
        /// </summary>
        public void CheckRemove(int slot, IMountableItem item, ref InventoryError err)
        {
            var cont = item as Container;

            if (cont != null)
            {
                if (!cont.BaseInventory.IsEmpty)
                {
                    err = InventoryError.CAN_ONLY_DO_WITH_EMPTY_BAGS;
                }
            }
        }
コード例 #27
0
ファイル: MailHandler.cs プロジェクト: uvbs/Asda2-Server
 /// <summary>
 /// Sends a responce detailing the results of the client's mail request.
 /// </summary>
 public static void SendResult(IPacketReceiver client, uint mailId, MailResult result, MailError err,
                               InventoryError invErr)
 {
     using (RealmPacketOut packet = new RealmPacketOut((PacketId)RealmServerOpCode.SMSG_SEND_MAIL_RESULT, 16))
     {
         packet.Write(mailId);
         packet.Write((uint)result);
         packet.Write((uint)err);
         packet.Write((uint)invErr);
         client.Send(packet, false);
     }
 }
コード例 #28
0
    /// <inheritdoc />
    /// <remarks>
    /// Raises dialog events based on the <c>Error</c>
    /// </remarks>
    protected override void HandleDropError(InventoryError error)
    {
        switch (error)
        {
        case InventoryError.InvalidItem:
            this.SayInvalidItem();
            break;

        case InventoryError.OutOfSpace:
            this.SayInventoryFull();
            break;
        }
    }
コード例 #29
0
ファイル: BaseInventory.cs プロジェクト: uvbs/Asda2-Server
        /// <summary>
        ///
        /// </summary>
        /// <param name="slot"></param>
        /// <param name="item"></param>
        /// <param name="amount"></param>
        /// <returns></returns>
        public InventoryError CheckAdd(int slot, IMountableItem item, int amount)
        {
            IItemSlotHandler handler = this.GetHandler(slot);

            if (handler == null)
            {
                return(InventoryError.OK);
            }
            InventoryError err = InventoryError.OK;

            handler.CheckAdd(slot, amount, item, ref err);
            return(err);
        }
コード例 #30
0
 /// <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="error"></param>
 public static void SendInventoryError(IPacketReceiver client, InventoryError error)
 {
     using (RealmPacketOut packet = new RealmPacketOut(
                (PacketId)RealmServerOpCode.SMSG_INVENTORY_CHANGE_FAILURE,
                error == InventoryError.YOU_MUST_REACH_LEVEL_N ? 22 : 18))
     {
         packet.WriteByte((byte)error);
         packet.WriteULong(0);
         packet.WriteULong(0);
         packet.WriteByte(0);
         client.Send(packet, false);
     }
 }
コード例 #31
0
ファイル: GiveItem.cs プロジェクト: Algorithman/TestCellAO
        /// <summary>
        /// </summary>
        /// <param name="client">
        /// </param>
        /// <param name="target">
        /// </param>
        /// <param name="args">
        /// </param>
        public override void ExecuteCommand(Client client, Identity target, string[] args)
        {
            IInstancedEntity targetEntity = null;

            if ((targetEntity = client.Playfield.FindByIdentity(target)) != null)
            {
                IItemContainer container = targetEntity as IItemContainer;

                // Does this entity have a BaseInventory?
                if (container != null)
                {
                    int lowId;
                    int highId;
                    int ql;
                    if (!int.TryParse(args[1], out lowId))
                    {
                        client.SendChatText("LowId is no number");
                        return;
                    }

                    if (!int.TryParse(args[2], out highId))
                    {
                        client.SendChatText("HighId is no number");
                        return;
                    }

                    if (!int.TryParse(args[3], out ql))
                    {
                        client.SendChatText("QualityLevel is no number");
                        return;
                    }

                    Item           item = new Item(ql, lowId, highId);
                    InventoryError err  = container.BaseInventory.TryAdd(item);
                    if (err != InventoryError.OK)
                    {
                        client.SendChatText("Could not add to inventory." + (int)err);
                    }

                    if (targetEntity as Character != null)
                    {
                        AddTemplate.Send((targetEntity as Character).Client, item);
                    }
                }
                else
                {
                    client.SendChatText("Target has no Inventory.");
                    return;
                }
            }
        }
コード例 #32
0
ファイル: PlayerInventory.cs プロジェクト: NVN/WCell
		/// <summary>
		/// Finds a free slot after checking for uniqueness
		/// </summary>
		/// <param name="templ"></param>
		/// <param name="amount"></param>
		/// <returns></returns>
		public SimpleSlotId FindFreeSlotCheck(ItemTemplate templ, int amount, out InventoryError err)
		{
			err = InventoryError.OK;
			var possibleAmount = amount;
			CheckUniqueness(templ, ref possibleAmount, ref err, true);
			if (possibleAmount != amount)
			{
				return SimpleSlotId.Default;
			}

			var slot = FindFreeSlot(templ, amount);
			if (slot.Slot == INVALID_SLOT)
			{
				err = InventoryError.INVENTORY_FULL;
			}
			return slot;
		}
コード例 #33
0
 /// <summary>
 /// </summary>
 /// <param name="slotFrom">
 /// </param>
 /// <param name="slotTo">
 /// </param>
 /// <param name="err">
 /// </param>
 /// <exception cref="NotImplementedException">
 /// </exception>
 public void TryHotSwap(int slotFrom, int slotTo, ref InventoryError err)
 {
     throw new NotImplementedException();
 }
コード例 #34
0
ファイル: PartialInventories.cs プロジェクト: pallmall/WCell
		/// <summary>
		/// Is called before removing the given item to check whether it may actually be removed
		/// </summary>
		public void CheckRemove(int slot, IMountableItem item, ref InventoryError err)
		{
		}
コード例 #35
0
 /// <summary>
 /// </summary>
 /// <param name="slot">
 /// </param>
 /// <param name="item">
 /// </param>
 /// <param name="err">
 /// </param>
 /// <exception cref="NotImplementedException">
 /// </exception>
 public void CheckAdd(int slot, ItemTemplate item, ref InventoryError err)
 {
     throw new NotImplementedException();
 }
コード例 #36
0
ファイル: PartialInventories.cs プロジェクト: pallmall/WCell
		/// <summary>
		/// Is called before adding to check whether the item may be added to the corresponding slot 
		/// (given the case that the corresponding slot is valid and unoccupied)
		/// </summary>
		public void CheckAdd(int slot, int amount, IMountableItem item, ref InventoryError err)
		{
		}
コード例 #37
0
ファイル: PartialInventories.cs プロジェクト: pallmall/WCell
		/// <summary>
		/// Is called before adding to check whether the item may be added to the corresponding slot 
		/// (given the case that the corresponding slot is valid and unoccupied)
		/// </summary>
		public void CheckAdd(int slot, int amount, IMountableItem item, ref InventoryError err)
		{
			if (item.Template.Class != ItemClass.Key)
			{
				err = InventoryError.ITEM_DOESNT_GO_TO_SLOT;
			}
		}
コード例 #38
0
ファイル: PartialInventories.cs プロジェクト: pallmall/WCell
		/// <summary>
		/// Is called before adding to check whether the item may be added to the corresponding slot 
		/// (given the case that the corresponding slot is valid and unoccupied)
		/// </summary>
		public void CheckAdd(int slot, int amount, IMountableItem item, ref InventoryError err)
		{
			if (!m_inventory.IsBankOpen)
			{
				err = InventoryError.TOO_FAR_AWAY_FROM_BANK;
			}
		}
コード例 #39
0
		/// <summary>
		/// Is called before removing the given item to check whether it may actually be removed
		/// </summary>
		public void CheckRemove(int slot, IMountableItem templ, ref InventoryError err)
		{
			// Disarmed
			if (templ is IWeapon && templ.Template.IsWeapon && !Owner.MayCarry(templ.Template.InventorySlotMask))
			{
				err = InventoryError.CANT_DO_WHILE_DISARMED;
			}
		}
コード例 #40
0
ファイル: PartialInventories.cs プロジェクト: pallmall/WCell
		/// <summary>
		/// Is called before adding to check whether the item may be added to the corresponding slot 
		/// (given the case that the corresponding slot is valid and unoccupied)
		/// </summary>
		public virtual void CheckAdd(int slot, int amount, IMountableItem item, ref InventoryError err)
		{
			var templ = item.Template;
			err = templ.CheckEquip(Owner);
			if (err == InventoryError.OK)
			{
				if (!templ.IsBag)
				{
					err = InventoryError.NOT_A_BAG;
				}
				else
				{
					var oldBag = m_inventory[slot];
					if (oldBag != null)
					{
						err = InventoryError.NONEMPTY_BAG_OVER_OTHER_BAG;
					}
					else if (!item.IsEquipped)
					{
						err = m_inventory.CheckEquipCount(item);
					}
				}
			}
		}
コード例 #41
0
ファイル: PartialInventories.cs プロジェクト: pallmall/WCell
		/// <summary>
		/// Is called before a bag is removed
		/// </summary>
		public void CheckRemove(int slot, IMountableItem item, ref InventoryError err)
		{
			var cont = item as Container;
			if (cont != null)
			{
				if (!cont.BaseInventory.IsEmpty)
				{
					err = InventoryError.CAN_ONLY_DO_WITH_EMPTY_BAGS;
				}
			}
		}
コード例 #42
0
ファイル: PartialInventories.cs プロジェクト: pallmall/WCell
		/// <summary>
		/// Is called before adding to check whether the item may be added to the corresponding slot 
		/// (given the case that the corresponding slot is valid and unoccupied)
		/// </summary>
		public void CheckAdd(int slot, int amount, IMountableItem item, ref InventoryError err)
		{
			if (item.Template.IsKey)
			{
				err = InventoryError.ITEM_DOESNT_GO_INTO_BAG;
			}
		}
コード例 #43
0
ファイル: PartialInventories.cs プロジェクト: pallmall/WCell
		/// <summary>
		/// Is called before adding to check whether the item may be added to the corresponding slot 
		/// (given the case that the corresponding slot is valid and unoccupied)
		/// </summary>
		public void CheckAdd(int slot, int amount, IMountableItem item, ref InventoryError err)
		{
			var templ = item.Template;
			err = templ.CheckEquip(m_inventory.Owner);
			if (err == InventoryError.OK)
			{
				if (templ.EquipmentSlots == null)
				{
					err = InventoryError.ITEM_CANT_BE_EQUIPPED;
				}
				else if (!templ.EquipmentSlots.Contains((EquipmentSlot)slot))
				{
					// client won't ever let you equip an item in a slot that it doesn't go to anyway
					err = InventoryError.ITEM_DOESNT_GO_TO_SLOT;
				}
				else if (slot == (int)InventorySlot.OffHand)
				{
					var mainHandWeapon = m_inventory[InventorySlot.MainHand];
					if (mainHandWeapon != null && mainHandWeapon.Template.IsTwoHandWeapon)
					{
						err = InventoryError.CANT_EQUIP_WITH_TWOHANDED;
					}
					else if (templ.IsWeapon && !m_inventory.Owner.Skills.Contains(SkillId.DualWield))
					{
						err = InventoryError.CANT_DUAL_WIELD;
					}
				}
				else if (templ.IsTwoHandWeapon && m_inventory[EquipmentSlot.OffHand] != null)
				//|| ((slot == (int)InventorySlot.OffHand && m_inventory[EquipmentSlot.MainHand] != null))
				{
					err = InventoryError.CANT_EQUIP_WITH_TWOHANDED;
				}
				else if (!item.IsEquipped)
				{
					err = m_inventory.CheckEquipCount(item);
				}
			}
		}
コード例 #44
0
 /// <summary>
 /// </summary>
 /// <param name="slot">
 /// </param>
 /// <param name="templ">
 /// </param>
 /// <param name="err">
 /// </param>
 /// <exception cref="NotImplementedException">
 /// </exception>
 public void CheckRemove(int slot, ItemTemplate templ, ref InventoryError err)
 {
     throw new NotImplementedException();
 }
コード例 #45
0
ファイル: ItemHandler.cs プロジェクト: Zakkgard/WCell
        /// <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);
            }
        }
コード例 #46
0
ファイル: PartialInventories.cs プロジェクト: pallmall/WCell
		public override void CheckAdd(int slot, int amount, IMountableItem item, ref InventoryError err)
		{
			if (!m_inventory.IsBankOpen)
			{
				err = InventoryError.TOO_FAR_AWAY_FROM_BANK;
			}
			else if (slot < m_inventory.Owner.BankBagSlots)
			{
				err = InventoryError.MUST_PURCHASE_THAT_BAG_SLOT;
			}
		}
コード例 #47
0
ファイル: ItemHandler.cs プロジェクト: Zakkgard/WCell
        /// <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="error"></param>
        public static void SendInventoryError(IPacketReceiver client, 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);

                packet.WriteULong(0);
                packet.WriteULong(0);
                packet.WriteByte(0);

                client.Send(packet);
            }
        }
コード例 #48
0
ファイル: MailHandler.cs プロジェクト: ebakkedahl/WCell
 /// <summary>
 /// Sends a responce detailing the results of the client's mail request.
 /// </summary>
 public static void SendResult(IPacketReceiver client, uint mailId, MailResult result, MailError err, InventoryError invErr)
 {
     using (var packet = new RealmPacketOut(RealmServerOpCode.SMSG_SEND_MAIL_RESULT, 12 + 4))
     {
         packet.Write(mailId);
         packet.Write((uint)result);
         packet.Write((uint)err);
         packet.Write((uint)invErr);
         client.Send(packet);
     }
 }