Ejemplo n.º 1
0
 /// <summary>
 /// Sets or Gets the Item at the given slot (make sure that slot is valid and unoccupied).
 /// </summary>
 /// <remarks>Cannot set to null - Use <see cref="M:WCell.RealmServer.Items.BaseInventory.Remove(System.Int32,System.Boolean)" /> instead.</remarks>
 /// <param name="slot"></param>
 /// <returns></returns>
 public Item this[int slot]
 {
     get
     {
         if (slot < 0 || slot > this.m_Items.Length)
         {
             return((Item)null);
         }
         return(this.m_Items[slot]);
     }
     set
     {
         if (value == null)
         {
             throw new NullReferenceException(string.Format(
                                                  "Cannot set Slot {0} in Inventory \"{1}\" to null - Use the Remove-method instead.",
                                                  (object)slot, (object)this));
         }
         if (this.m_Items[slot] != null)
         {
             string msg =
                 string.Format(
                     "Cannot add Item \"{0}\" to Slot {1} in Inventory \"{2}\" to - Slot is occupied with Item \"{3}\".",
                     (object)value, (object)slot, (object)this, (object)this.m_Items[slot]);
             LogUtil.ErrorException(msg, new object[0]);
             value.Destroy();
             if (this.Owner == null)
             {
                 return;
             }
             this.Owner.SendSystemMessage(msg);
         }
         else
         {
             ++this.m_count;
             value.Container = this;
             value.Slot      = slot;
             this.SetContainerEntityId(value.EntityId, slot, this);
             this.m_Items[slot] = value;
             IItemSlotHandler handler = this.GetHandler(slot);
             if (handler == null)
             {
                 return;
             }
             handler.Added(value);
         }
     }
 }
Ejemplo n.º 2
0
        /// <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);
                }
            }
        }