コード例 #1
0
ファイル: IPackage.cs プロジェクト: t61789/Thunder
        public override void SortItem()
        {
            var curCell = 0;

            foreach (var info in _ItemManifest)
            {
                var maxStack = ItemSys.GetInfo(info.Key).MaxStackNum;
                //info.Value.FirstCell = curCell;
                var count = info.Value.Count;
                while (count > 0)
                {
                    var take = Mathf.Min(maxStack, count);
                    count -= take;
                    _Items[curCell].Id     = info.Key;
                    _Items[curCell].Count += take;
                    curCell++;
                }
            }

            while (curCell < _Items.Length)
            {
                _Items[curCell].Id    = 0;
                _Items[curCell].Count = 0;
                curCell++;
            }

            _ItemChangedDic.Clear();
            InvokeOnItemCellChanged(
                new PackageItemChangedInfo(
                    Tools.GetIndexEnum(0, _Items.Length),
                    ToChangedItemGroups(_ItemChangedDic)));
        }
コード例 #2
0
 public ItemSys()
 {
     Ins       = this;
     _ItemInfo = new Dictionary <int, ItemInfo>();
     QueryDicFromTable(_ItemInfo, Config.ItemInfoTableName);
     QueryDicFromJson(_ItemInfo, Config.ItemInfoValuePath);
 }
コード例 #3
0
ファイル: IPackage.cs プロジェクト: t61789/Thunder
        public override bool PutItemCheck(params ItemGroup[] groups)
        {
            _ItemChangedDic.Clear();
            _RemainingList.Clear();
            for (int i = 0; i < groups.Length; i++)
            {
                var g = groups[i].ToValid();
                if (!LimitItem(g.Id))
                {
                    return(false);
                }
                if (g.Id == 0)
                {
                    continue;
                }
                _RemainingList.Add(g);
                _ItemChangedDic.Add(g.Id, _RemainingList.Count - 1);
            }


            if (_RemainingList.Count == 0)
            {
                return(true);
            }

            var startIndex     = 0;
            var curIndex       = 0;
            var remainingItems = 0;

            do
            {
                var curCell = _Items[curIndex];

                if (curCell.Id == 0)
                {
                    curCell.Id = _RemainingList[remainingItems].Id;
                }

                if (_ItemChangedDic.TryGetValue(curCell.Id, out var num))
                {
                    var maxStack = ItemSys.GetInfo(curCell.Id).MaxStackNum;
                    var g        = _RemainingList[num];
                    if (g.Count != 0)
                    {
                        var take = Mathf.Min(g.Count, maxStack - curCell.Count);
                        g.Count            -= take;
                        _RemainingList[num] = g;
                        if (g.Count == 0 && num == remainingItems)
                        {
                            remainingItems = FindNextAvailableGroup(_RemainingList, num);
                        }
                    }
                }

                curIndex = (curIndex + 1) % _Items.Length;
            } while (remainingItems < _RemainingList.Count && startIndex != curIndex);

            return(remainingItems >= _RemainingList.Count);
        }
コード例 #4
0
ファイル: IPackage.cs プロジェクト: t61789/Thunder
 /// <summary>
 /// 目标物品可否纳入背包
 /// </summary>
 public bool CanPackage(ItemId itemId)
 {
     return(ItemSys.GetInfo(itemId).CanPackage);
 }
コード例 #5
0
ファイル: IPackage.cs プロジェクト: t61789/Thunder
        public override PackageOperation CostItem(params ItemGroup[] groups)
        {
            _ItemCellChangedList.Clear();
            _ItemChangedDic.Clear();
            _RemainingList.Clear();

            for (int i = 0; i < groups.Length; i++)
            {
                var g = groups[i].ToValid();
                if (g.Id == 0)
                {
                    continue;
                }
                _RemainingList.Add(g);
                _ItemChangedDic.Add(g.Id, _RemainingList.Count - 1);
            }

            var result = new PackageOperation(
                JumpOverInvalidItem(_RemainingList),
                _ItemCellChangedList,
                ToChangedItemGroups(_ItemChangedDic));

            if (_RemainingList.Count == 0)
            {
                return(result);
            }

            var curCellIndex   = 0;
            var remainingCount = _RemainingList.Count;

            do
            {
                var curCell = _Items[curCellIndex];

                if (_ItemChangedDic.TryGetValue(curCell.Id, out var curSrcItemIndex))
                {
                    var curSrcItem = _RemainingList[curSrcItemIndex];
                    if (curSrcItem.Count != 0)
                    {
                        var maxStack = ItemSys.GetInfo(curCell.Id).MaxStackNum;
                        var take     = Mathf.Min(maxStack - curCell.Count, curSrcItem.Count);

                        curCell.Count    -= take;
                        curSrcItem.Count -= take;

                        if (take != 0)
                        {
                            _ItemChangedDic.ModifyIntDic(curCell.Id, -take);
                            _ItemCellChangedList.Add(curCellIndex);
                            ModifyManifest(curCell.Id, -take);
                        }

                        if (curSrcItem.Count == 0)
                        {
                            remainingCount--;
                        }

                        _Items[curCellIndex]            = curCell;
                        _RemainingList[curSrcItemIndex] = curSrcItem;
                    }
                }

                curCellIndex = (curCellIndex + 1) % _RemainingList.Count;
            } while (remainingCount > 0 && curCellIndex != 0);

            if (_ItemCellChangedList.Count != 0)
            {
                InvokeOnItemCellChanged(
                    new PackageItemChangedInfo(
                        _ItemCellChangedList,
                        ToChangedItemGroups(_ItemChangedDic)));
            }

            return(result);
        }
コード例 #6
0
ファイル: IPackage.cs プロジェクト: t61789/Thunder
        public override ItemGroup PutItemInto(int index, ItemGroup itemGroup)
        {
            itemGroup = itemGroup.ToValid();

            if (!LimitItem(itemGroup.Id) || !CanPackage(itemGroup.Id)) // 不能放入背包则不能添加
            {
                return(itemGroup);
            }

            var maxStack = ItemSys.GetInfo(itemGroup.Id).MaxStackNum;

            if (_Items[index].Id == 0)
            {
                _Items[index].Id = itemGroup.Id;
            }

            // 源物品与目标物品不同则进行替换
            if (_Items[index].Id != itemGroup.Id)
            {
                // 如果源物品数量大于堆叠数,则无法将源物品全部放入单元格内进行替换
                // 所以在这种情况下判定为无法添加物品
                if (itemGroup.Count > maxStack)
                {
                    return(itemGroup);
                }

                var takeOut = _Items[index];
                SetItemAt(index, itemGroup);
                return(takeOut);
            }

            // 为空或是物品相同则直接添加

            // 源物品和目标物品均为空则不做修改
            if (itemGroup.Id == 0)
            {
                return(new ItemGroup());
            }

            var take = Mathf.Min(maxStack - _Items[index].Count, itemGroup.Count);

            _Items[index].Count += take;
            itemGroup.Count     -= take;

            if (take != 0)
            {
                _ItemCellChangedList.Clear();
                _ItemCellChangedList.Add(index);
                _ItemChangedDic.Clear();
                _ItemChangedDic.ModifyIntDic(itemGroup.Id, take);

                ModifyManifest(itemGroup.Id, take);

                InvokeOnItemCellChanged(
                    new PackageItemChangedInfo(
                        _ItemCellChangedList,
                        ToChangedItemGroups(_ItemChangedDic)));
            }

            return(itemGroup.Count == 0 ? new ItemGroup() : itemGroup);
        }