From 253b7ec69c294c4eb8c5aa67830614640c667a91 Mon Sep 17 00:00:00 2001 From: Patrik Olesen Date: Sun, 28 Jan 2024 18:49:55 +0100 Subject: [PATCH] [18Uruguay] Secondary capitalization The corporation get the rest of the capitalization when the reach there destination tile --- lib/engine/game/g_18_uruguay/game.rb | 9 +++- lib/engine/game/g_18_uruguay/step/track.rb | 63 ++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 lib/engine/game/g_18_uruguay/step/track.rb diff --git a/lib/engine/game/g_18_uruguay/game.rb b/lib/engine/game/g_18_uruguay/game.rb index 74fc70823a..5b2fab3f52 100644 --- a/lib/engine/game/g_18_uruguay/game.rb +++ b/lib/engine/game/g_18_uruguay/game.rb @@ -266,7 +266,7 @@ def operating_round(round_num) Engine::Step::SpecialToken, G18Uruguay::Step::TakeLoanBuyCompany, Engine::Step::HomeToken, - Engine::Step::Track, + G18Uruguay::Step::Track, G18Uruguay::Step::Token, Engine::Step::Route, Engine::Step::Dividend, @@ -403,6 +403,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 << "Connected to destination #{corporation.name} receives #{format_currency(amount)}" + end end end end diff --git a/lib/engine/game/g_18_uruguay/step/track.rb b/lib/engine/game/g_18_uruguay/step/track.rb new file mode 100644 index 0000000000..42c054bdd3 --- /dev/null +++ b/lib/engine/game/g_18_uruguay/step/track.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +require_relative '../../../step/tracker' +require_relative '../../../step/track' + +module Engine + module Game + module G18Uruguay + module Step + class Track < Engine::Step::Track + def actions(entity) + return [] if entity == @game.rptla + return [] if @game.final_operating_round? + + @round.loan_taken |= false + actions = super.map(&:clone) + actions << 'take_loan' if @game.can_take_loan?(entity) && !@round.loan_taken && !@game.nationalized? + actions + end + + def destination_node_check?(entity) + return if entity.destination_coordinates.nil? + + destination_hex = @game.hex_by_id(entity.destination_coordinates) + home_node = entity.tokens.first.city + destination_hex.tile.nodes.first&.walk(corporation: entity) do |path, _, _| + return true if path.nodes.include?(home_node) + end + false + end + + def check_and_apply_destination_bonus + corporation = current_entity.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 lay_tile(action, extra_cost: 0, entity: nil, spender: nil) + ret = super + check_and_apply_destination_bonus + ret + end + + def pass! + check_and_apply_destination_bonus + super + end + + def process_take_loan(action) + entity = action.entity + @game.take_loan(entity, action.loan) unless @round.loan_taken + @round.loan_taken = true + end + end + end + end + end +end