Skip to content

Commit

Permalink
[18Uruguay] Secondary capitalization
Browse files Browse the repository at this point in the history
The corporation get the rest of the capitalization when the reach there destination tile
  • Loading branch information
patrikolesen committed Feb 8, 2024
1 parent 032b890 commit a9690f9
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/engine/game/g_18_uruguay/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ def operating_round(round_num)
G18Uruguay::Step::TakeLoanBuyCompany,
Engine::Step::HomeToken,
Engine::Step::Track,
G18Uruguay::Step::DestinationToken,
G18Uruguay::Step::Token,
Engine::Step::Route,
Engine::Step::Dividend,
Expand Down Expand Up @@ -403,6 +404,13 @@ def or_round_finished
def final_operating_round?
@final_turn == @turn
end

# Second capatilization
def second_capitalization!(corporation)
amount = corporation.par_price.price * 5
@bank.spend(amount, corporation)
@log << "#{corporation.name} connected to destination receives #{format_currency(amount)}"
end
end
end
end
Expand Down
62 changes: 62 additions & 0 deletions lib/engine/game/g_18_uruguay/step/destination_bonus.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# frozen_string_literal: true

module Engine
module Game
module G18Uruguay
module Step
class DestinationToken < Engine::Step::Base
ACTIONS = %w[destination_connection pass].freeze

def description
'Place the Destination Bonus'
end

def pass_description
'Skip (Destination Bonus)'
end

def actions(_entity)
self.class::ACTIONS
end

def auto_actions(entity)
corporations = @round.entities.select { |c| destination_node_check?(c) }
return [Engine::Action::Pass.new(entity)] if corporations.empty?

[Engine::Action::DestinationConnection.new(entity, corporations: corporations)]
end

def destination_node_check?(corporation)
return if corporation.destination_coordinates.nil?

ability = @game.abilities(corporation, :destination_bonus)
return if ability.nil?

destination_hex = @game.hex_by_id(corporation.destination_coordinates)
home_node = corporation.tokens.first.city
destination_hex.tile.nodes.first&.walk(corporation: corporation) do |path, _, _|
return true if path.nodes.include?(home_node)
end
false
end

def check_and_apply_destination_bonus(corporation)
apply_destination_bonus(corporation) if destination_node_check?(corporation)
end

def apply_destination_bonus(corporation)
ability = @game.abilities(corporation, :destination_bonus)
@game.second_capitalization!(corporation) unless ability.nil?
ability&.use!
end

def process_destination_connection(action)
action.corporations.each { |corporation| check_and_apply_destination_bonus(corporation) }

pass!
end
end
end
end
end
end

0 comments on commit a9690f9

Please sign in to comment.