Change mine command with storehouse calc
This commit is contained in:
parent
d15aeaedc4
commit
e8f7453a8f
@ -13,7 +13,7 @@ module Game::TestCommand
|
||||
Point.new(0, 0),
|
||||
Building.new(
|
||||
Building::Type::StartPoint,
|
||||
storage: 200
|
||||
storage: 200, roles: [Building::Role::Storehouse]
|
||||
)
|
||||
)
|
||||
map.set DepositTile.new(
|
||||
@ -79,8 +79,10 @@ module Game::TestCommand
|
||||
it "should complete mining command" do
|
||||
world = World.new create_map_with_resource
|
||||
command = MineCommand.new Point.new(0, 1), once: true
|
||||
world.push command
|
||||
world.run 20
|
||||
time_point = (20 + 1 * 2 + 1 * 2).to_i64
|
||||
done_at = world.push command
|
||||
done_at.should eq time_point
|
||||
world.run time_point
|
||||
# Check world resources
|
||||
world.resources[Resource::Type::Crystals].should eq 40
|
||||
# Check tile deposit
|
||||
|
@ -63,7 +63,7 @@ module Game
|
||||
storage : Capacity | Nil = nil
|
||||
)
|
||||
@name = name != "" ? name : @type.to_s
|
||||
@roles = roles.nil? ? Array(Role).new : roles
|
||||
@roles = roles.nil? ? Array(Role).new : roles.as(Array(Role))
|
||||
@construction = construction.nil? ? Construction.immediatly : construction.as(Construction)
|
||||
@production = production
|
||||
@mining = mining
|
||||
@ -79,5 +79,9 @@ module Game
|
||||
getter mining
|
||||
getter restoration
|
||||
getter storage
|
||||
|
||||
def has_role(role : Role) : Bool
|
||||
@roles.includes? role
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -59,11 +59,14 @@ module Game
|
||||
end
|
||||
resource = mining.resource
|
||||
deposit_tile = nearest_deposit(world, resource.type)
|
||||
if deposit_tile
|
||||
stock_tile = nearest_stock(world)
|
||||
if deposit_tile && stock_tile
|
||||
mined_amount = deposit_tile.dep.dec(resource.amount)
|
||||
@holded = resource.type.to_res mined_amount
|
||||
mining.ts + 2 * tile.point.distance(stock_tile.point) + 2 * tile.point.distance(deposit_tile.point)
|
||||
else
|
||||
mining.ts
|
||||
end
|
||||
mining.ts
|
||||
end
|
||||
|
||||
def finish(world : World)
|
||||
@ -82,6 +85,13 @@ module Game
|
||||
end
|
||||
tile.as?(DepositTile)
|
||||
end
|
||||
|
||||
private def nearest_stock(world : World) : BuildingTile?
|
||||
tile = world.map.nearest_tile @point do |tile|
|
||||
tile.is_a?(BuildingTile) && tile.building.has_role Building::Role::Storehouse
|
||||
end
|
||||
tile.as?(BuildingTile)
|
||||
end
|
||||
end
|
||||
|
||||
class RestoreCommand < Command
|
||||
|
Loading…
Reference in New Issue
Block a user