コード例 #1
0
ファイル: Transfer.cs プロジェクト: vitamink/InfiniteWorlds
        bool ITransferToSyntax.To(IItemStore storage)
        {
            bool canTransferFrom = false;
            bool canTransferTo = false;

            int fromPartitionIndex = -1;
            IItemContainer fromPartition = null;

            IItemContainer toPartition = null;

            if (_from != null)
            {
                fromPartitionIndex = _from.Partitions.IndexOf(x => x.Item.Name == _item.Name);
                if (fromPartitionIndex > -1)
                {
                    fromPartition = _from.Partitions[fromPartitionIndex];
                    canTransferFrom = fromPartition.Used >= _quantity;
                }
            }
            else
            {
                canTransferFrom = true;
            }

            if (canTransferFrom)
            {
                toPartition = storage.Partitions.SingleOrDefault(x => x.Item.Name == _item.Name);

                if (toPartition != null)
                {
                    canTransferTo = toPartition.Used + _quantity <= toPartition.Capacity;
                }
                else
                {
                    int width = (int) Math.Ceiling(_item.UnitSize*_quantity);
                    if (width <= storage.SlotsAvaliable)
                    {
                        toPartition = new ItemStorePartition(_item, width);
                        storage.Partitions.Add(toPartition);
                        canTransferTo = true;
                    }
                }
            }

            if (canTransferFrom && canTransferTo)
            {
                if (fromPartition != null)
                {
                    UpdateFromPartition(fromPartition, fromPartitionIndex);
                }

                toPartition.Used += _quantity;

                return true;
            }

            return false;
        }
コード例 #2
0
        public void ensure_partition_Width_is_functioning_correctly()
        {
            ICanStore grain = new Commodity("Grain1", "Grain", UnitOfMeasurement.Kilogram, 0.001, false);

            ItemStorePartition partition = new ItemStorePartition(grain);
            Assert.AreEqual(1000, partition.Capacity);

            partition.Slots++;
            Assert.AreEqual(2000, partition.Capacity);

            partition.Slots--;
            Assert.AreEqual(1000, partition.Capacity);
        }