Exemple #1
0
        public override void SetItemAt(int index, ItemGroup itemGroup)
        {
            itemGroup = itemGroup.ToValid();

            _ItemChangedDic.Clear();
            _ItemCellChangedList.Clear();

            var desItem = _Items[index];

            if (!desItem.Equals(itemGroup))
            {
                _ItemCellChangedList.Add(index);
            }

            if (desItem.Id != 0)
            {
                ModifyManifest(desItem.Id, -desItem.Count);
            }

            _Items[index] = itemGroup;
            if (itemGroup.Id != 0)
            {
                _ItemChangedDic.ModifyIntDic(itemGroup.Id, itemGroup.Count);
            }

            ModifyManifest(itemGroup.Id, itemGroup.Count);

            if (_ItemCellChangedList.Count != 0)
            {
                InvokeOnItemCellChanged(
                    new PackageItemChangedInfo(
                        _ItemCellChangedList,
                        ToChangedItemGroups(_ItemChangedDic)));
            }
        }
Exemple #2
0
        public override void SetItemAt(int index, ItemGroup itemGroup)
        {
            itemGroup = itemGroup.ToValid();

            _ItemCellChangedList.Clear();
            _ItemChangedDic.Clear();

            if (itemGroup.Id != 0 &&
                (!_WeaponInfoDic.TryGetValue(itemGroup.Id, out var info) ||
                 info.Type != _Belt[index].Type))
            {
                return;
            }

            if (!_Belt[index].Group.Equals(itemGroup))
            {
                _ItemCellChangedList.Add(index);
            }
            else
            {
                return;
            }

            if (_Belt[index].Group.Id != 0)
            {
                DestroyWeapon(index);
                var group = _Belt[index].Group;

                _ItemChangedDic.ModifyIntDic(group.Id, -group.Count);
            }

            _Belt[index].Group = itemGroup;
            if (itemGroup.Id != 0)
            {
                _ItemChangedDic.ModifyIntDic(itemGroup.Id, itemGroup.Count);
                _Belt[index].Weapon = CreateWeaponObj(_Belt[index].Group.Id);
            }
            if (index == _CurWeapon)
            {
                TakeOutWeapon(index);
            }

            if (_ItemCellChangedList.Count != 0)
            {
                InvokeOnItemCellChanged(
                    new PackageItemChangedInfo(
                        _ItemCellChangedList,
                        ToChangedItemGroups(_ItemChangedDic)));
            }
        }
Exemple #3
0
        public override ItemGroup PutItemInto(int index, ItemGroup itemGroup)
        {
            itemGroup = itemGroup.ToValid();

            var result = _Belt[index].Group;

            if (itemGroup.IsEmpty())
            {
                DestroyWeapon(index);
                return(result);
            }

            // 源物品非武器不能添加
            // 目标单元格类型不正确不能添加
            if (!_WeaponInfoDic.TryGetValue(itemGroup.Id, out var info) ||
                info.Type != _Belt[index].Type)
            {
                return(itemGroup);
            }

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

            if (_Belt[index].Group.Id != 0)
            {
                _Belt[index].Group.Id = itemGroup.Id;
            }

            _ItemCellChangedList.Clear();
            _ItemChangedDic.Clear();
            if (_Belt[index].Group.Id != itemGroup.Id)
            {
                // 交换操作无法完成不能添加
                if (itemGroup.Count > maxStack)
                {
                    return(itemGroup);
                }

                result = _Belt[index].Group;
                _ItemChangedDic.ModifyIntDic(result.Id, -result.Count);
                _Belt[index].Group = itemGroup;

                _ItemCellChangedList.Add(index);
            }
            else
            {
                var take = Mathf.Min(maxStack - _Belt[index].Group.Count, itemGroup.Count);
                _Belt[index].Group.Count += take;
                itemGroup.Count          -= take;

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

            if (preId != _Belt[index].Group.Id)
            {
                DestroyWeapon(index);
                _Belt[index].Weapon = CreateWeaponObj(_Belt[index].Group.Id);
                if (_CurWeapon == index)
                {
                    TakeOutWeapon(index);
                }
            }

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

            return(result);
        }
Exemple #4
0
        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);
        }