예제 #1
0
        private bool tryTransferToDestination(IVoxelHandle road, TargetedItem item)
        {
            if (!road.Get4Connected().Contains(haxorIVoxelHandelize(road, item.Destination)))
            {
                return(false);
            }

            item.Source.Data.Inventory.DestroyItems(itemTypesFactory.GetOutgoingKanban(item.ItemType), 1);
            item.Destination.Data.Inventory.DestroyItems(itemTypesFactory.GetIncomingKanban(item.ItemType), 1);
            road.Data.Inventory.TransferItemsTo(item.Destination.Data.Inventory, item.ItemType, 1);
            road.Data.Road.Items.Remove(item);
            return(true);
        }
예제 #2
0
        private void tryTransfer(IVoxelHandle road, TargetedItem item)
        {
            if (tryTransferToDestination(road, item))
            {
                return;
            }

            if (tryMoveCloserTo(road, haxorIVoxelHandelize(road, item.Destination), item))
            {
                return;
            }
            if (tryMoveCloserTo(road, haxorIVoxelHandelize(road, item.Source), item))
            {
                return;
            }

            destroyTargetedItem(road, item);
        }
예제 #3
0
        private bool tryMoveCloserTo(IVoxelHandle road, IVoxelHandle target, TargetedItem item)
        {
            if (!FindConnectedVoxels(road, v => v.Equals(target)).Any())
            {
                return(false);                                                         // target not reacheable
            }
            var neighbours = getNeighbourRoads(road);
            var options    = neighbours.Select(
                n =>
                new { Road = n, Target = FindConnectedVoxels(n, v => v.Equals(target)).FirstOrDefault() });
            var bestNextRoad = options.Where(o => o.Target != null).OrderBy(o => o.Target.Item2).First().Road;


            road.Data.Inventory.TransferItemsTo(bestNextRoad.Data.Inventory, item.ItemType, 1);
            road.Data.Road.Items.Remove(item);
            bestNextRoad.Data.Road.Items.Add(item);

            return(true);
        }
예제 #4
0
 /// <summary>
 /// This causes permanent removal of an in game item, used when the user somehow causes an in-transport item to have nowhere to go
 /// </summary>
 /// <param name="item"></param>
 private void destroyTargetedItem(IVoxelHandle handle, TargetedItem item)
 {
     handle.Data.Inventory.DestroyItems(item.ItemType, 1);
     item.Source.Data.Inventory.DestroyItems(itemTypesFactory.GetOutgoingKanban(item.ItemType), 1);
     item.Destination.Data.Inventory.DestroyItems(itemTypesFactory.GetIncomingKanban(item.ItemType), 1);
 }