예제 #1
0
        private static bool AddComposeItemsToHideBag(GamePlayer player, ItemInfo item)
        {
            int place = -1;

            if (item.TemplateID >= 11001 && item.TemplateID <= 11016)
            {
                place = 2;
            }
            if (item.TemplateID == 11018)
            {
                place = 0;
            }
            bool result;

            if (place != -1 && player.HideBag.IsEmpty(place))
            {
                if (item.Count > 1)
                {
                    ItemInfo copyitem = item.Clone();
                    copyitem.Count = 1;
                    item.Count--;
                    result = (player.HideBag.AddItemTo(copyitem, place) && player.AddItem(item));
                }
                else
                {
                    result = player.HideBag.AddItemTo(item, place);
                }
            }
            else
            {
                result = player.AddItem(item);
            }
            return(result);
        }
예제 #2
0
        /// <summary>
        /// 拆分物品
        /// </summary>
        /// <param name="item"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public bool SplitItem(ItemInfo item, int count, int toSlot)
        {
            if (_bagType == 11)
            {
                ConsortiaInfo info = ConsortiaMgr.FindConsortiaInfo(_player.PlayerCharacter.ConsortiaID);
                if (info != null || toSlot >= info.StoreLevel * 10)
                {
                    _player.Out.SendUpdateInventorySlot(item.Place, true, item, _bagType);
                    return(false);
                }
            }

            if (item.Count > count && m_items[toSlot] == null)
            {
                ItemInfo clone = item.Clone();
                clone.ItemID = -1;
                clone.Count  = count;
                if (AddItemTo(clone, toSlot) != -1)
                {
                    item.Count -= count;
                    _player.Out.SendUpdateInventorySlot(item.Place, true, item, _bagType);
                    _player.Out.SendUpdateInventorySlot(clone.Place, true, clone, _bagType);
                    return(true);
                }
            }
            else
            {
                _player.Out.SendUpdateInventorySlot(item.Place, true, item, _bagType);
            }

            return(false);
        }
예제 #3
0
        public static List <ItemInfo> SpiltGoodsMaxCount(ItemInfo itemInfo)
        {
            List <ItemInfo> Infos = new List <ItemInfo>();

            for (int maxItem = 0; maxItem < itemInfo.Count; maxItem += itemInfo.Template.MaxCount)
            {
                int      tempCount = (itemInfo.Count < itemInfo.Template.MaxCount) ? itemInfo.Count : itemInfo.Template.MaxCount;
                ItemInfo item      = itemInfo.Clone();
                item.Count = tempCount;
                Infos.Add(item);
            }
            return(Infos);
        }
예제 #4
0
        private void gridMain_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left || e.RowIndex < 0 || e.RowIndex >= this.gridMain.RowCount)
            {
                return;
            }
            ItemInfo info = this.gridMain.Rows[e.RowIndex].DataBoundItem as ItemInfo;

            if (info != null)
            {
                this.BeginInvoke((MethodInvoker) delegate
                                 { this.gridMain.DoDragDrop(info.Clone() as ItemInfo, DragDropEffects.Copy); });
            }
            return;
        }
예제 #5
0
        protected virtual bool StackItems(int fromSlot, int toSlot, int itemCount)
        {
            ItemInfo fromItem = m_items[fromSlot] as ItemInfo;
            ItemInfo toItem   = m_items[toSlot] as ItemInfo;

            if (itemCount == 0)
            {
                if (fromItem.Count > 0)
                {
                    itemCount = fromItem.Count;
                }
                else
                {
                    itemCount = 1;
                }
            }

            if (toItem != null && toItem.TemplateID == fromItem.TemplateID && toItem.CanStackedTo(fromItem))
            {
                if (fromItem.Count + toItem.Count > fromItem.Template.MaxCount)
                {
                    fromItem.Count -= (toItem.Template.MaxCount - toItem.Count);
                    toItem.Count    = toItem.Template.MaxCount;
                }
                else
                {
                    toItem.Count += itemCount;
                    RemoveItem(fromItem);
                }
                return(true);
            }
            else if (toItem == null && fromItem.Count > itemCount)
            {
                ItemInfo newItem = (ItemInfo)fromItem.Clone();
                newItem.Count = itemCount;
                if (AddItemTo(newItem, toSlot))
                {
                    fromItem.Count -= itemCount;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            return(false);
        }
예제 #6
0
        protected virtual bool StackItems(int fromSlot, int toSlot, int itemCount)
        {
            ItemInfo itemInfo  = this.m_items[fromSlot];
            ItemInfo itemInfo2 = this.m_items[toSlot];

            if (itemCount == 0)
            {
                if (itemInfo.Count > 0)
                {
                    itemCount = itemInfo.Count;
                }
                else
                {
                    itemCount = 1;
                }
            }
            if (itemInfo2 != null && itemInfo2.TemplateID == itemInfo.TemplateID && itemInfo2.CanStackedTo(itemInfo))
            {
                if (itemInfo.Count + itemInfo2.Count > itemInfo.Template.MaxCount)
                {
                    itemInfo.Count -= itemInfo2.Template.MaxCount - itemInfo2.Count;
                    itemInfo2.Count = itemInfo2.Template.MaxCount;
                }
                else
                {
                    itemInfo2.Count += itemCount;
                    this.RemoveItem(itemInfo);
                }
                return(true);
            }
            if (itemInfo2 != null || itemInfo.Count <= itemCount)
            {
                return(false);
            }
            ItemInfo itemInfo3 = itemInfo.Clone();

            itemInfo3.Count = itemCount;
            if (this.AddItemTo(itemInfo3, toSlot))
            {
                itemInfo.Count -= itemCount;
                return(true);
            }
            return(false);
        }
예제 #7
0
        /// <summary>
        /// 拆分物品
        /// </summary>
        /// <param name="item"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public bool SplitItem(ItemInfo item, int count, int toSlot)
        {
            if (item.Count > count && _items[toSlot] == null)
            {
                ItemInfo clone = item.Clone();
                clone.ItemID = -1;
                clone.Count  = count;
                //clone.Place = toSlot;
                if (AddItem(clone) != -1)
                {
                    UseItem(item);
                    UseItem(clone);
                    item.Count -= count;
                    _player.Out.SendUpdateInventorySlot(item.Place, true, item, _bagType);
                    _player.Out.SendUpdateInventorySlot(clone.Place, true, clone, _bagType);
                    return(true);
                }
            }

            return(false);
        }
예제 #8
0
        private static bool AddFusionItemsToHideBag(GamePlayer player, ItemInfo item)
        {
            bool result;

            if (player.HideBag.IsEmpty(0))
            {
                if (item.Count > 1)
                {
                    ItemInfo copyitem = item.Clone();
                    copyitem.Count = 1;
                    item.Count--;
                    result = (player.HideBag.AddItemTo(copyitem, 0) && player.AddItem(item));
                }
                else
                {
                    result = player.HideBag.AddItemTo(item, 0);
                }
            }
            else
            {
                result = player.AddItem(item);
            }
            return(result);
        }
예제 #9
0
        public virtual bool AddTemplate(ItemInfo cloneItem, int count, int minSlot, int maxSlot)
        {
            if (cloneItem == null)
            {
                return(false);
            }
            ItemTemplateInfo template = cloneItem.Template;

            if (template == null)
            {
                return(false);
            }
            if (count <= 0)
            {
                return(false);
            }
            if (minSlot < this.m_beginSlot || minSlot > this.m_capalility - 1)
            {
                return(false);
            }
            if (maxSlot < this.m_beginSlot || maxSlot > this.m_capalility - 1)
            {
                return(false);
            }
            if (minSlot > maxSlot)
            {
                return(false);
            }
            object @lock;

            Monitor.Enter(@lock = this.m_lock);
            bool result;

            try
            {
                List <int> list = new List <int>();
                int        num  = count;
                for (int i = minSlot; i <= maxSlot; i++)
                {
                    ItemInfo itemInfo = this.m_items[i];
                    if (itemInfo == null)
                    {
                        num -= template.MaxCount;
                        list.Add(i);
                    }
                    else
                    {
                        if (this.m_autoStack && cloneItem.CanStackedTo(itemInfo))
                        {
                            num -= template.MaxCount - itemInfo.Count;
                            list.Add(i);
                        }
                    }
                    if (num <= 0)
                    {
                        break;
                    }
                }
                if (num <= 0)
                {
                    this.BeginChanges();
                    try
                    {
                        num = count;
                        foreach (int current in list)
                        {
                            ItemInfo itemInfo2 = this.m_items[current];
                            if (itemInfo2 == null)
                            {
                                itemInfo2       = cloneItem.Clone();
                                itemInfo2.Count = ((num < template.MaxCount) ? num : template.MaxCount);
                                num            -= itemInfo2.Count;
                                this.AddItemTo(itemInfo2, current);
                            }
                            else
                            {
                                if (itemInfo2.TemplateID == template.TemplateID)
                                {
                                    int num2 = (itemInfo2.Count + num < template.MaxCount) ? num : (template.MaxCount - itemInfo2.Count);
                                    itemInfo2.Count += num2;
                                    num             -= num2;
                                    this.OnPlaceChanged(current);
                                }
                                else
                                {
                                    AbstractInventory.log.Error("Add template erro: select slot's TemplateId not equest templateId");
                                }
                            }
                        }
                        if (num != 0)
                        {
                            AbstractInventory.log.Error("Add template error: last count not equal Zero.");
                        }
                    }
                    finally
                    {
                        this.CommitChanges();
                    }
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            finally
            {
                Monitor.Exit(@lock);
            }
            return(result);
        }
예제 #10
0
파일: DataGrid.cs 프로젝트: JianwenSun/cc
        /// <summary>
        ///     Adds or Removes from SelectedItems when deferred selection is not handled by the caller.
        /// </summary>
        private void UpdateSelectedItems(ItemInfo info, bool add)
        {
            bool updatingSelectedItems = IsUpdatingSelectedItems;
            if (!updatingSelectedItems)
            {
                BeginUpdateSelectedItems();
            }

            try
            {
                if (add)
                {
                    SelectedItemCollection.Add(info.Clone());
                }
                else
                {
                    SelectedItemCollection.Remove(info);
                }
            }
            finally
            {
                if (!updatingSelectedItems)
                {
                    EndUpdateSelectedItems();
                }
            }
        }
예제 #11
0
파일: DataGrid.cs 프로젝트: JianwenSun/cc
        /// <summary>
        ///     Processes selection for a row.
        ///     Depending on the current keyboard state, this may mean
        ///     - Selecting the row
        ///     - Deselecting the row
        ///     - Deselecting other rows
        ///     - Extending selection to the row
        /// </summary>
        /// <remarks>
        ///     ADO.Net has a bug (#524977) where if the row is in edit mode
        ///     and atleast one of the cells are edited and committed without
        ///     commiting the row itself, DataView.IndexOf for that row returns -1
        ///     and DataView.Contains returns false. The Workaround to this problem
        ///     is to try to use the previously computed row index if the operations
        ///     are in the same row scope.
        /// </remarks>
        private void MakeFullRowSelection(ItemInfo info, bool allowsExtendSelect, bool allowsMinimalSelect)
        {
            bool extendSelection = allowsExtendSelect && ShouldExtendSelection;

            // minimalModify means that previous selections should not be cleared
            // or that the particular item should be toggled.
            bool minimalModify = allowsMinimalSelect && ShouldMinimallyModifySelection;

            using (UpdateSelectedCells())
            {
                bool alreadyUpdating = IsUpdatingSelectedItems;
                if (!alreadyUpdating)
                {
                    BeginUpdateSelectedItems();
                }

                try
                {
                    if (extendSelection)
                    {
                        // Extend selection from the anchor to the item
                        int numColumns = _columns.Count;
                        if (numColumns > 0)
                        {
                            int startIndex = _selectionAnchor.Value.ItemInfo.Index;
                            int endIndex = info.Index;
                            if (startIndex > endIndex)
                            {
                                // Ensure that startIndex is before endIndex
                                int temp = startIndex;
                                startIndex = endIndex;
                                endIndex = temp;
                            }

                            if ((startIndex >= 0) && (endIndex >= 0))
                            {
                                int numItemsSelected = _selectedItems.Count;

                                if (!minimalModify)
                                {
                                    bool clearedCells = false;

                                    // Unselect items not within the selection range
                                    for (int index = 0; index < numItemsSelected; index++)
                                    {
                                        ItemInfo itemInfo = _selectedItems[index];
                                        int itemIndex = itemInfo.Index;

                                        if ((itemIndex < startIndex) || (endIndex < itemIndex))
                                        {
                                            // Selector has been signaled to delay updating the
                                            // collection until we have finished the entire update.
                                            // The item will actually remain in the collection
                                            // until EndUpdateSelectedItems.
                                            SelectionChange.Unselect(itemInfo);

                                            if (!clearedCells)
                                            {
                                                // We only want to clear if something is actually being removed.
                                                _selectedCells.Clear();
                                                clearedCells = true;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    // If we hold Control key - unselect only the previous drag selection (between CurrentCell and endIndex)
                                    int currentCellIndex = CurrentCell.ItemInfo.Index;
                                    int removeRangeStartIndex = -1;
                                    int removeRangeEndIndex = -1;
                                    if (currentCellIndex < startIndex)
                                    {
                                        removeRangeStartIndex = currentCellIndex;
                                        removeRangeEndIndex = startIndex - 1;
                                    }
                                    else if (currentCellIndex > endIndex)
                                    {
                                        removeRangeStartIndex = endIndex + 1;
                                        removeRangeEndIndex = currentCellIndex;
                                    }

                                    if (removeRangeStartIndex >= 0 && removeRangeEndIndex >= 0)
                                    {
                                        for (int index = 0; index < numItemsSelected; index++)
                                        {
                                            ItemInfo itemInfo = _selectedItems[index];
                                            int itemIndex = itemInfo.Index;

                                            if ((removeRangeStartIndex <= itemIndex) && (itemIndex <= removeRangeEndIndex))
                                            {
                                                // Selector has been signaled to delay updating the
                                                // collection until we have finished the entire update.
                                                // The item will actually remain in the collection
                                                // until EndUpdateSelectedItems.
                                                SelectionChange.Unselect(itemInfo);
                                            }
                                        }

                                        _selectedCells.RemoveRegion(removeRangeStartIndex, 0, removeRangeEndIndex - removeRangeStartIndex + 1, Columns.Count);
                                    }
                                }

                                // Select the children in the selection range
                                IEnumerator enumerator = ((IEnumerable)Items).GetEnumerator();
                                for (int index = 0; index <= endIndex; index++)
                                {
                                    if (!enumerator.MoveNext())
                                    {
                                        // In case the enumerator ends unexpectedly
                                        break;
                                    }

                                    if (index >= startIndex)
                                    {
                                        SelectionChange.Select(ItemInfoFromIndex(index), true);
                                    }
                                }

                                IDisposable d = enumerator as IDisposable;
                                if (d != null)
                                {
                                    d.Dispose();
                                }

                                _selectedCells.AddRegion(startIndex, 0, endIndex - startIndex + 1, _columns.Count);
                            }
                        }
                    }
                    else
                    {
                        if (minimalModify && _selectedItems.Contains(info))
                        {
                            // Unselect the one item
                            UnselectItem(info);
                        }
                        else
                        {
                            if (!minimalModify || !CanSelectMultipleItems)
                            {
                                // Unselect the other items
                                if (_selectedCells.Count > 0)
                                {
                                    // Pre-emptively clear the SelectedCells collection, which is O(1),
                                    // instead of waiting for the selection change notification to clear
                                    // SelectedCells row by row, which is O(n).
                                    _selectedCells.Clear();
                                }

                                if (SelectedItems.Count > 0)
                                {
                                    SelectedItems.Clear();
                                }
                            }

                            if (_editingRowInfo == info)
                            {
                                // ADO.Net bug workaround, see remarks.
                                int numColumns = _columns.Count;
                                if (numColumns > 0)
                                {
                                    _selectedCells.AddRegion(_editingRowInfo.Index, 0, 1, numColumns);
                                }

                                SelectItem(info, false);
                            }
                            else
                            {
                                // Select the item
                                SelectItem(info);
                            }
                        }

                        _selectionAnchor = new DataGridCellInfo(info.Clone(), ColumnFromDisplayIndex(0), this);
                    }
                }
                finally
                {
                    if (!alreadyUpdating)
                    {
                        EndUpdateSelectedItems();
                    }
                }
            }
        }
예제 #12
0
        private static bool AddStrengthItemsToHideBag(GamePlayer player, ItemInfo item)
        {
            int place      = -1;
            int templateID = item.TemplateID;

            switch (templateID)
            {
            case 11018:
                place = 4;
                break;

            case 11019:
                break;

            case 11020:
                place = 3;
                break;

            default:
                if (templateID == 11023)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        if (player.HideBag.IsEmpty(i) && item.Count >= 1)
                        {
                            ItemInfo copyitem = item.Clone();
                            copyitem.Count = 1;
                            player.HideBag.AddItemTo(copyitem, i);
                            item.Count--;
                        }
                    }
                    place = -1;
                }
                break;
            }
            bool result;

            if (item.Count <= 0)
            {
                result = true;
            }
            else
            {
                if (place != -1 && player.HideBag.IsEmpty(place))
                {
                    if (item.Count > 1)
                    {
                        ItemInfo copyitem = item.Clone();
                        copyitem.Count = 1;
                        item.Count--;
                        result = (player.HideBag.AddItemTo(copyitem, place) && player.AddItem(item));
                    }
                    else
                    {
                        result = player.HideBag.AddItemTo(item, place);
                    }
                }
                else
                {
                    result = player.AddItem(item);
                }
            }
            return(result);
        }
예제 #13
0
        protected virtual bool StackItems(int fromSlot, int toSlot, int itemCount)
        {
            bool result;

            if (fromSlot == toSlot)
            {
                result = false;
            }
            else
            {
                ItemInfo fromItem = this.m_items[fromSlot];
                ItemInfo toItem   = this.m_items[toSlot];
                if (fromItem == null)
                {
                    result = false;
                }
                else
                {
                    if (itemCount < 0)
                    {
                        result = false;
                    }
                    else
                    {
                        if (itemCount == 0)
                        {
                            if (fromItem.Count > 0)
                            {
                                itemCount = fromItem.Count;
                            }
                            else
                            {
                                itemCount = 1;
                            }
                        }
                        if (fromItem.Count < itemCount)
                        {
                            result = false;
                        }
                        else
                        {
                            if (toItem != null && toItem.TemplateID == fromItem.TemplateID && toItem.CanStackedTo(fromItem))
                            {
                                if (itemCount + toItem.Count > fromItem.Template.MaxCount)
                                {
                                    fromItem.Count -= toItem.Template.MaxCount - toItem.Count;
                                    toItem.Count    = toItem.Template.MaxCount;
                                }
                                else
                                {
                                    toItem.Count += itemCount;
                                    if (itemCount == fromItem.Count)
                                    {
                                        this.RemoveItem(fromItem, eItemRemoveType.Stack);
                                    }
                                    else
                                    {
                                        fromItem.Count -= itemCount;
                                        this.UpdateItem(fromItem);
                                    }
                                }
                                result = true;
                            }
                            else
                            {
                                if (toItem == null && fromItem.Count > itemCount)
                                {
                                    ItemInfo newItem = fromItem.Clone();
                                    newItem.Count = itemCount;
                                    if (this.AddItemTo(newItem, toSlot))
                                    {
                                        fromItem.Count -= itemCount;
                                        result          = true;
                                    }
                                    else
                                    {
                                        result = false;
                                    }
                                }
                                else
                                {
                                    result = false;
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
예제 #14
0
        public virtual bool AddTemplate(ItemInfo cloneItem, int count, int minSlot, int maxSlot)
        {
            bool result;

            if (cloneItem == null)
            {
                result = false;
            }
            else
            {
                ItemTemplateInfo template = cloneItem.Template;
                if (template == null)
                {
                    result = false;
                }
                else
                {
                    if (count <= 0)
                    {
                        result = false;
                    }
                    else
                    {
                        if (minSlot < this.m_beginSlot || minSlot > this.m_capalility - 1)
                        {
                            result = false;
                        }
                        else
                        {
                            if (maxSlot < this.m_beginSlot || 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)
                                            {
                                                itemcount -= template.MaxCount;
                                                changedSlot.Add(i);
                                            }
                                            else
                                            {
                                                if (this.m_autoStack && cloneItem.CanStackedTo(item))
                                                {
                                                    itemcount -= template.MaxCount - item.Count;
                                                    changedSlot.Add(i);
                                                }
                                            }
                                            if (itemcount <= 0)
                                            {
                                                break;
                                            }
                                        }
                                        if (itemcount <= 0)
                                        {
                                            this.BeginChanges();
                                            try
                                            {
                                                itemcount = count;
                                                foreach (int i in changedSlot)
                                                {
                                                    ItemInfo item = this.m_items[i];
                                                    if (item == null)
                                                    {
                                                        item       = cloneItem.Clone();
                                                        item.Count = ((itemcount < template.MaxCount) ? itemcount : template.MaxCount);
                                                        itemcount -= item.Count;
                                                        this.AddItemTo(item, i);
                                                    }
                                                    else
                                                    {
                                                        if (item.TemplateID == template.TemplateID)
                                                        {
                                                            int add = (item.Count + itemcount < template.MaxCount) ? itemcount : (template.MaxCount - item.Count);
                                                            item.Count += add;
                                                            itemcount  -= add;
                                                            this.OnPlaceChanged(i);
                                                        }
                                                        else
                                                        {
                                                            AbstractInventory.log.Error("Add template erro: select slot's TemplateId not equest templateId");
                                                        }
                                                    }
                                                }
                                                if (itemcount != 0)
                                                {
                                                    AbstractInventory.log.Error("Add template error: last count not equal Zero.");
                                                }
                                            }
                                            finally
                                            {
                                                this.CommitChanges();
                                            }
                                            result = true;
                                        }
                                        else
                                        {
                                            result = false;
                                        }
                                    }
                                    finally
                                    {
                                        Monitor.Exit(@lock);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
예제 #15
0
        public virtual bool AddTemplate(ItemInfo cloneItem, int count, int minSlot, int maxSlot)
        {
            if (cloneItem == null)
            {
                return(false);
            }
            ItemTemplateInfo template = cloneItem.Template;

            if (template == null)
            {
                return(false);
            }
            if (count <= 0)
            {
                return(false);
            }
            if (minSlot < m_beginSlot || minSlot > m_capalility - 1)
            {
                return(false);
            }
            if (maxSlot < m_beginSlot || maxSlot > m_capalility - 1)
            {
                return(false);
            }
            if (minSlot > maxSlot)
            {
                return(false);
            }


            lock (m_lock)
            {
                List <int> changedSlot = new List <int>();
                int        itemcount   = count;

                for (int i = minSlot; i <= maxSlot; i++)
                {
                    ItemInfo item = m_items[i];
                    if (item == null)
                    {
                        itemcount -= template.MaxCount;
                        changedSlot.Add(i);
                    }
                    else if (m_autoStack && cloneItem.CanStackedTo(item))
                    {
                        itemcount -= (template.MaxCount - item.Count);
                        changedSlot.Add(i);
                    }
                    if (itemcount <= 0)
                    {
                        break;
                    }
                }

                if (itemcount <= 0)
                {
                    BeginChanges();
                    try
                    {
                        itemcount = count;
                        foreach (int i in changedSlot)
                        {
                            ItemInfo item = m_items[i];
                            if (item == null)
                            {
                                item = cloneItem.Clone();

                                item.Count = itemcount < template.MaxCount ? itemcount : template.MaxCount;

                                itemcount -= item.Count;

                                AddItemTo(item, i);
                            }
                            else
                            {
                                if (item.TemplateID == template.TemplateID)
                                {
                                    int add = (item.Count + itemcount < template.MaxCount ? itemcount : template.MaxCount - item.Count);
                                    item.Count += add;
                                    itemcount  -= add;

                                    OnPlaceChanged(i);
                                }
                                else
                                {
                                    log.Error("Add template erro: select slot's TemplateId not equest templateId");
                                }
                            }
                        }

                        if (itemcount != 0)
                        {
                            log.Error("Add template error: last count not equal Zero.");
                        }
                    }
                    finally
                    {
                        CommitChanges();
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
 public void MoveToHide(GamePlayer player, PlayerInventory bag, ItemInfo item, int toSlot, PlayerInventory hideBag, int count)
 {
     if (player != null && bag != null && item != null && hideBag != null)
     {
         int      oldplace = item.Place;
         ItemInfo toItem   = hideBag.GetItemAt(toSlot);
         if (toItem != null)
         {
             if (toItem.CanStackedTo(item))
             {
                 return;
             }
             if (item.Count == 1 && item.BagType == toItem.BagType)
             {
                 bag.TakeOutItem(item);
                 hideBag.TakeOutItem(toItem);
                 bag.AddItemTo(toItem, oldplace);
                 hideBag.AddItemTo(item, toSlot);
                 return;
             }
             string          key = string.Format("temp_place_{0}", toItem.ItemID);
             PlayerInventory tb  = player.GetItemInventory(toItem.Template);
             if (player.TempProperties.ContainsKey(key) && tb.BagType == 0)
             {
                 int tempSlot = (int)player.TempProperties[key];
                 player.TempProperties.Remove(key);
                 if (tb.AddItemTo(toItem, tempSlot))
                 {
                     hideBag.TakeOutItem(toItem);
                 }
             }
             else
             {
                 if (tb.StackItemToAnother(toItem))
                 {
                     hideBag.RemoveItem(toItem, eItemRemoveType.Stack);
                 }
                 else
                 {
                     if (tb.AddItem(toItem))
                     {
                         hideBag.TakeOutItem(toItem);
                     }
                     else
                     {
                         player.Out.SendMessage(eMessageType.ERROR, LanguageMgr.GetTranslation("UserChangeItemPlaceHandler.full", new object[0]));
                     }
                 }
             }
         }
         if (hideBag.IsEmpty(toSlot))
         {
             if (item.Count == 1)
             {
                 if (hideBag.AddItemTo(item, toSlot))
                 {
                     bag.TakeOutItem(item);
                     if (item.Template.BagType == eBageType.MainBag)
                     {
                         string key = string.Format("temp_place_{0}", item.ItemID);
                         if (player.TempProperties.ContainsKey(key))
                         {
                             player.TempProperties[key] = oldplace;
                         }
                         else
                         {
                             player.TempProperties.Add(key, oldplace);
                         }
                     }
                 }
             }
             else
             {
                 ItemInfo newItem = item.Clone();
                 newItem.Count = 1;
                 if (bag.RemoveCountFromStack(item, 1, eItemRemoveType.Stack))
                 {
                     if (!hideBag.AddItemTo(newItem, toSlot))
                     {
                         bag.AddCountToStack(item, 1);
                     }
                 }
             }
         }
     }
 }
예제 #17
0
 public void MoveToStore(GameClient client, PlayerInventory bag, ItemInfo item, int toSlot, PlayerInventory storeBag, int count)
 {
     if (client.Player != null && bag != null && item != null && storeBag != null)
     {
         int      place  = item.Place;
         ItemInfo itemAt = storeBag.GetItemAt(toSlot);
         if (itemAt != null)
         {
             if (itemAt.CanStackedTo(item))
             {
                 return;
             }
             if (item.Count == 1 && item.BagType == itemAt.BagType)
             {
                 bag.TakeOutItem(item);
                 storeBag.TakeOutItem(itemAt);
                 bag.AddItemTo(itemAt, place);
                 storeBag.AddItemTo(item, toSlot);
                 return;
             }
             string          key           = string.Format("temp_place_{0}", itemAt.ItemID);
             PlayerInventory itemInventory = client.Player.GetItemInventory(itemAt.Template);
             if (client.Player.TempProperties.ContainsKey(key) && itemInventory.BagType == 0)
             {
                 int place2 = (int)client.Player.TempProperties[key];
                 client.Player.TempProperties.Remove(key);
                 if (itemInventory.AddItemTo(itemAt, place2))
                 {
                     storeBag.TakeOutItem(itemAt);
                 }
             }
             else
             {
                 if (itemInventory.StackItemToAnother(itemAt))
                 {
                     storeBag.RemoveItem(itemAt, eItemRemoveType.Stack);
                 }
                 else
                 {
                     if (itemInventory.AddItem(itemAt))
                     {
                         storeBag.TakeOutItem(itemAt);
                     }
                     else
                     {
                         client.Player.Out.SendMessage(eMessageType.ERROR, LanguageMgr.GetTranslation("UserChangeItemPlaceHandler.full", new object[0]));
                     }
                 }
             }
         }
         if (storeBag.IsEmpty(toSlot))
         {
             if (item.Count == 1)
             {
                 if (storeBag.AddItemTo(item, toSlot))
                 {
                     bag.TakeOutItem(item);
                     if (item.Template.BagType == eBageType.MainBag && place < 31)
                     {
                         string key = string.Format("temp_place_{0}", item.ItemID);
                         if (client.Player.TempProperties.ContainsKey(key))
                         {
                             client.Player.TempProperties[key] = place;
                             return;
                         }
                         client.Player.TempProperties.Add(key, place);
                         return;
                     }
                 }
             }
             else
             {
                 ItemInfo itemInfo = item.Clone();
                 itemInfo.Count = count;
                 if (bag.RemoveCountFromStack(item, count, eItemRemoveType.Stack) && !storeBag.AddItemTo(itemInfo, toSlot))
                 {
                     bag.AddCountToStack(item, count);
                 }
             }
         }
     }
 }