Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18Uruguay] Secondary capitalization #10247

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -282,6 +282,7 @@ def operating_round(round_num)
G18Uruguay::Step::TakeLoanBuyCompany,
Engine::Step::HomeToken,
G18Uruguay::Step::Track,
G18Uruguay::Step::DestinationBonus,
G18Uruguay::Step::Token,
G18Uruguay::Step::Route,
G18Uruguay::Step::RouteRptla,
Expand Down Expand Up @@ -460,6 +461,13 @@ def float_str(entity)
def can_par?(corporation, _parrer)
nationalized? || @nationalization_triggered || corporation != @fce
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 DestinationBonus < 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
Loading