コード例 #1
0
 public SearchSlotId(bool inclBank)
 {
     Container = null;
     Slot      = 0;
     InclBank  = inclBank;
     SearchPos = 0;
 }
コード例 #2
0
ファイル: SearchSlotId.cs プロジェクト: uvbs/Asda2-Server
 public SearchSlotId(bool inclBank)
 {
     this.Container = (BaseInventory)null;
     this.Slot      = 0;
     this.InclBank  = inclBank;
     this.SearchPos = 0;
 }
コード例 #3
0
ファイル: BaseInventory.cs プロジェクト: uvbs/Asda2-Server
        /// <summary>Iterates over all Items within this Inventory.</summary>
        public virtual bool Iterate(Func <Item, bool> iterator)
        {
            for (int index = 0; index < this.m_Items.Length; ++index)
            {
                Item obj1 = this.m_Items[index];
                if (obj1 != null)
                {
                    if (obj1 is WCell.RealmServer.Entities.Container)
                    {
                        BaseInventory baseInventory = ((WCell.RealmServer.Entities.Container)obj1).BaseInventory;
                        if (!baseInventory.IsEmpty)
                        {
                            foreach (Item obj2 in baseInventory.Items)
                            {
                                obj1 = obj2;
                                if (obj1 != null && !iterator(obj1))
                                {
                                    return(false);
                                }
                            }
                        }
                    }

                    if (!iterator(obj1))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
コード例 #4
0
ファイル: PartialInventory.cs プロジェクト: uvbs/Asda2-Server
 /// <summary>
 /// Returns all existing inventories (only containers have them)
 /// </summary>
 /// <returns></returns>
 public IEnumerable <BaseInventory> GetInventories()
 {
     foreach (Item obj in this.m_inventory.Items)
     {
         if (obj is Container)
         {
             BaseInventory inv = ((Container)obj).BaseInventory;
             if (inv != null)
             {
                 yield return(inv);
             }
         }
     }
 }
コード例 #5
0
ファイル: BaseInventory.cs プロジェクト: uvbs/Asda2-Server
        internal void AddLoadedItem(Item item)
        {
            try
            {
                int           slot          = item.Slot;
                BaseInventory baseInventory = this;
                if (!this.IsValidSlot(slot))
                {
                    SimpleSlotId freeSlot = this.OwnerInventory.FindFreeSlot(item, false);
                    if (slot == (int)byte.MaxValue)
                    {
                        LogManager.GetCurrentClassLogger()
                        .Warn("Ignoring loaded Item {0} in {1} because it has an invalid Slot: {2}", (object)item,
                              (object)this, (object)item.Slot);
                        return;
                    }

                    LogManager.GetCurrentClassLogger().Warn("Loaded Item {0} in {1} has invalid Slot: {2}",
                                                            (object)item, (object)this, (object)item.Slot);
                    slot          = freeSlot.Slot;
                    baseInventory = freeSlot.Container;
                }

                if (baseInventory[slot] != null)
                {
                    LogManager.GetCurrentClassLogger()
                    .Warn("Ignoring Item {0} for {1} because slot is already occupied by: {2}", (object)item,
                          (object)this.Owner, (object)baseInventory[slot]);
                    item.Destroy();
                }
                else
                {
                    Character       owner          = this.Owner;
                    PlayerInventory ownerInventory = this.OwnerInventory;
                    baseInventory[slot] = item;
                    owner.AddItemToUpdate(item);
                    ownerInventory.OnAddDontNotify(item);
                }
            }
            catch (Exception ex)
            {
                LogUtil.ErrorException(ex, "Unable to add Item \"{0}\" to {1}", new object[2]
                {
                    (object)item,
                    (object)this
                });
            }
        }
コード例 #6
0
ファイル: ItemSet.cs プロジェクト: uvbs/Asda2-Server
        /// <summary>
        /// If there is a free equippable bag slot: Adds all items of this set to a new bag in that slot
        /// </summary>
        /// <returns>False if their was no space left or an internal error occured and not all items could be added</returns>
        public bool Create(Character owner)
        {
            EquippedContainerInventory equippedContainers = owner.Inventory.EquippedContainers;
            int freeSlot = equippedContainers.FindFreeSlot();

            if (freeSlot != (int)byte.MaxValue)
            {
                Container container = Item.CreateItem(Asda2ItemId.End, owner, 1) as Container;
                if (container == null)
                {
                    ItemSet.log.Error("Invalid container template id for ItemSet: " + (object)Asda2ItemId.End);
                }
                else
                {
                    InventoryError inventoryError =
                        equippedContainers.TryAdd(freeSlot, (Item)container, true, ItemReceptionType.Receive);
                    if (inventoryError == InventoryError.OK)
                    {
                        BaseInventory baseInventory = container.BaseInventory;
                        for (int index = 0; index < this.Templates.Length; ++index)
                        {
                            int            amount = 1;
                            InventoryError error  = baseInventory.TryAdd(this.Templates[index], ref amount,
                                                                         ItemReceptionType.Receive);
                            if (error != InventoryError.OK)
                            {
                                ItemHandler.SendInventoryError((IPacketReceiver)owner.Client, (Item)null, (Item)null,
                                                               error);
                                ItemSet.log.Error("Failed to add item (Template: {0}) to bag on {1} ({2})",
                                                  (object)this.Templates[index], (object)owner, (object)error);
                                return(false);
                            }
                        }

                        return(true);
                    }

                    ItemSet.log.Error("Failed to add ItemSet-bag to owner {0} ({1})", (object)owner,
                                      (object)inventoryError);
                    return(false);
                }
            }

            return(false);
        }
コード例 #7
0
ファイル: BaseInventory.cs プロジェクト: NecroSharper/WCell
        //private bool TryAdd(Item item, out InventoryError invError)
        //{
        //    invError = InventoryError.OK;

        //    return true;
        //}

        /// <summary>
        /// Swaps the items at the given slots without further checks.
        /// </summary>
        /// <param name="slot1"></param>
        /// <param name="slot2"></param>
        /// <remarks>Make sure the slots are valid before calling.</remarks>
        public void SwapUnchecked(BaseInventory cont1, int slot1, BaseInventory cont2, int slot2)
        {
            var item1 = cont1.m_Items[slot1];
            var item2 = cont2.m_Items[slot2];

            var handler1 = cont1.GetHandler(slot1);
            var handler2 = cont2.GetHandler(slot2);

            if (item2 != null &&
                item1.CanStackWith(item2) &&
                item2.Amount < item2.Template.MaxAmount)
            {
                var diff = item1.Template.MaxAmount - item2.Amount;
                diff          = Math.Min(diff, item1.Amount);
                item1.Amount -= diff;
                item2.Amount += diff;
            }
            else
            {
                // remove both Items
                if (item1 != null)
                {
                    item1.Slot = slot2;
                    if (handler1 != null)
                    {
                        handler1.Removed(slot1, item1);
                    }
                }

                if (item2 != null)
                {
                    item2.Slot = slot1;
                    if (handler2 != null)
                    {
                        handler2.Removed(slot2, item2);
                    }
                }


                // set new items, fields and tell the container about the change
                cont1.m_Items[slot1] = item2;
                cont2.m_Items[slot2] = item1;

                if (item1 != null)
                {
                    SetContainerEntityId(item1.EntityId, slot2, cont2);
                    item1.Container = cont2;
                    if (handler2 != null)
                    {
                        handler2.Added(item1);
                    }
                }
                else
                {
                    SetContainerEntityId(EntityId.Zero, slot2, cont2);
                }

                if (item2 != null)
                {
                    SetContainerEntityId(item2.EntityId, slot1, cont1);
                    item2.Container = cont1;
                    if (handler1 != null)
                    {
                        handler1.Added(item2);
                    }
                }
                else
                {
                    SetContainerEntityId(EntityId.Zero, slot1, cont1);
                }
            }
        }
コード例 #8
0
ファイル: BaseInventory.cs プロジェクト: NecroSharper/WCell
        public virtual void SetContainerEntityId(EntityId entityId, int slot, BaseInventory baseInventory)
        {
            var field = baseInventory.m_baseField + (slot * 2);

            baseInventory.Container.SetEntityId(field, entityId);
        }
コード例 #9
0
ファイル: BaseInventory.cs プロジェクト: uvbs/Asda2-Server
        /// <summary>
        /// Swaps the items at the given slots without further checks.
        /// </summary>
        /// <param name="slot1"></param>
        /// <param name="slot2"></param>
        /// <remarks>Make sure the slots are valid before calling.</remarks>
        public void SwapUnchecked(BaseInventory cont1, int slot1, BaseInventory cont2, int slot2)
        {
            Item             obj       = cont1.m_Items[slot1];
            Item             otherItem = cont2.m_Items[slot2];
            IItemSlotHandler handler1  = cont1.GetHandler(slot1);
            IItemSlotHandler handler2  = cont2.GetHandler(slot2);

            if (otherItem != null && obj.CanStackWith(otherItem) && otherItem.Amount < otherItem.Template.MaxAmount)
            {
                int num = Math.Min(obj.Template.MaxAmount - otherItem.Amount, obj.Amount);
                obj.Amount       -= num;
                otherItem.Amount += num;
            }
            else
            {
                if (obj != null)
                {
                    obj.Slot = slot2;
                    if (handler1 != null)
                    {
                        handler1.Removed(slot1, obj);
                    }
                }

                if (otherItem != null)
                {
                    otherItem.Slot = slot1;
                    if (handler2 != null)
                    {
                        handler2.Removed(slot2, otherItem);
                    }
                }

                cont1.m_Items[slot1] = otherItem;
                cont2.m_Items[slot2] = obj;
                if (obj != null)
                {
                    this.SetContainerEntityId(obj.EntityId, slot2, cont2);
                    obj.Container = cont2;
                    if (handler2 != null)
                    {
                        handler2.Added(obj);
                    }
                }
                else
                {
                    this.SetContainerEntityId(EntityId.Zero, slot2, cont2);
                }

                if (otherItem != null)
                {
                    this.SetContainerEntityId(otherItem.EntityId, slot1, cont1);
                    otherItem.Container = cont1;
                    if (handler1 == null)
                    {
                        return;
                    }
                    handler1.Added(otherItem);
                }
                else
                {
                    this.SetContainerEntityId(EntityId.Zero, slot1, cont1);
                }
            }
        }