예제 #1
0
        public override bool RemoveItem(ItemInfo item, eItemRemoveType type)
        {
            bool result;

            if (base.RemoveItem(item, type))
            {
                item.IsExist    = false;
                item.RemoveType = (int)type;
                if (this.m_saveToDb)
                {
                    List <ItemInfo> removedList;
                    Monitor.Enter(removedList = this.m_removedList);
                    try
                    {
                        this.m_removedList.Add(item);
                    }
                    finally
                    {
                        Monitor.Exit(removedList);
                    }
                }
                result = true;
            }
            else
            {
                result = false;
            }
            return(result);
        }
예제 #2
0
        public virtual bool RemoveItem(ItemInfo item, eItemRemoveType type)
        {
            bool result;

            if (item == null)
            {
                result = false;
            }
            else
            {
                int    place = -1;
                object @lock;
                Monitor.Enter(@lock = this.m_lock);
                try
                {
                    for (int i = 0; i < this.m_capalility; i++)
                    {
                        if (this.m_items[i] == item)
                        {
                            place           = i;
                            this.m_items[i] = null;
                            break;
                        }
                    }
                }
                finally
                {
                    Monitor.Exit(@lock);
                }
                if (place != -1)
                {
                    this.OnPlaceChanged(place);
                    if (item.BagType == this.BagType && item.Place == place)
                    {
                        item.Place   = -1;
                        item.BagType = -1;
                    }
                }
                result = (place != -1);
            }
            return(result);
        }
예제 #3
0
 public virtual bool RemoveCountFromStack(ItemInfo item, int count, eItemRemoveType type)
 {
     if (item == null)
     {
         return(false);
     }
     if (count <= 0 || item.BagType != this.m_type)
     {
         return(false);
     }
     if (item.Count < count)
     {
         return(false);
     }
     if (item.Count == count)
     {
         return(this.RemoveItem(item));
     }
     item.Count -= count;
     this.OnPlaceChanged(item.Place);
     return(true);
 }
예제 #4
0
        public void ClearBag(eItemRemoveType type)
        {
            this.BeginChanges();
            object @lock;

            Monitor.Enter(@lock = this.m_lock);
            try
            {
                for (int i = this.m_beginSlot; i < this.m_capalility; i++)
                {
                    if (this.m_items[i] != null)
                    {
                        this.RemoveItem(this.m_items[i], type);
                    }
                }
            }
            finally
            {
                Monitor.Exit(@lock);
            }
            this.CommitChanges();
        }
예제 #5
0
        public virtual bool RemoveItem(ItemInfo item, eItemRemoveType type)
        {
            if (item == null)
            {
                return(false);
            }
            int    num = -1;
            object @lock;

            Monitor.Enter(@lock = this.m_lock);
            try
            {
                for (int i = 0; i < this.m_capalility; i++)
                {
                    if (this.m_items[i] == item)
                    {
                        num             = i;
                        this.m_items[i] = null;
                        break;
                    }
                }
            }
            finally
            {
                Monitor.Exit(@lock);
            }
            if (num != -1)
            {
                this.OnPlaceChanged(num);
                if (item.BagType == this.BagType && item.Place == num)
                {
                    item.Place   = -1;
                    item.BagType = -1;
                }
            }
            return(num != -1);
        }
예제 #6
0
        public virtual bool RemoveCountFromStack(ItemInfo item, int count, eItemRemoveType type)
        {
            bool result;

            if (item == null)
            {
                result = false;
            }
            else
            {
                if (count <= 0 || item.BagType != this.m_type)
                {
                    result = false;
                }
                else
                {
                    if (item.Count < count)
                    {
                        result = false;
                    }
                    else
                    {
                        if (item.Count == count)
                        {
                            result = this.RemoveItem(item, type);
                        }
                        else
                        {
                            item.Count -= count;
                            this.OnPlaceChanged(item.Place);
                            result = true;
                        }
                    }
                }
            }
            return(result);
        }
예제 #7
0
        public virtual bool RemoveTemplate(int templateId, int count, int minSlot, int maxSlot, eItemRemoveType type)
        {
            bool result;

            if (count <= 0)
            {
                result = false;
            }
            else
            {
                if (minSlot < 0 || minSlot > this.m_capalility - 1)
                {
                    result = false;
                }
                else
                {
                    if (maxSlot <= 0 || maxSlot > this.m_capalility - 1)
                    {
                        result = false;
                    }
                    else
                    {
                        if (minSlot > maxSlot)
                        {
                            result = false;
                        }
                        else
                        {
                            object @lock;
                            Monitor.Enter(@lock = this.m_lock);
                            try
                            {
                                List <int> changedSlot = new List <int>();
                                int        itemcount   = count;
                                for (int i = minSlot; i <= maxSlot; i++)
                                {
                                    ItemInfo item = this.m_items[i];
                                    if (item != null && item.TemplateID == templateId)
                                    {
                                        changedSlot.Add(i);
                                        itemcount -= item.Count;
                                        if (itemcount <= 0)
                                        {
                                            break;
                                        }
                                    }
                                }
                                if (itemcount <= 0)
                                {
                                    this.BeginChanges();
                                    itemcount = count;
                                    try
                                    {
                                        foreach (int i in changedSlot)
                                        {
                                            ItemInfo item = this.m_items[i];
                                            if (item != null && item.TemplateID == templateId)
                                            {
                                                if (item.Count <= itemcount)
                                                {
                                                    this.RemoveItem(item, type);
                                                    itemcount -= item.Count;
                                                }
                                                else
                                                {
                                                    int dec = (item.Count - itemcount < item.Count) ? itemcount : 0;
                                                    item.Count -= dec;
                                                    itemcount  -= dec;
                                                    this.OnPlaceChanged(i);
                                                }
                                            }
                                        }
                                        if (itemcount != 0)
                                        {
                                            AbstractInventory.log.Error("Remove template error:last item cout not equal Zero.");
                                        }
                                    }
                                    finally
                                    {
                                        this.CommitChanges();
                                    }
                                    result = true;
                                }
                                else
                                {
                                    result = false;
                                }
                            }
                            finally
                            {
                                Monitor.Exit(@lock);
                            }
                        }
                    }
                }
            }
            return(result);
        }
예제 #8
0
 public virtual bool RemoveTemplate(int templateId, int count, eItemRemoveType type)
 {
     return(this.RemoveTemplate(templateId, count, 0, this.m_capalility - 1, type));
 }
예제 #9
0
 public bool RemoveItemAt(int place, eItemRemoveType type)
 {
     return(this.RemoveItem(this.GetItemAt(place), type));
 }