Skip to content

Commit

Permalink
Combine the best updates from the last day
Browse files Browse the repository at this point in the history
  • Loading branch information
ryandriskel committed Oct 28, 2020
1 parent 6fcc6ec commit 5393a53
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
40 changes: 26 additions & 14 deletions lib/engine/game/g_18_co.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,9 @@ def imc

def setup
setup_company_price_50_to_150_percent
setup_companies
setup_corporations
end

def setup_companies
imc.add_ability(Engine::Ability::Base.new(
type: :mine_multiplier,
description: 'Mine values are doubled',
count_per_or: 2
))
end

def setup_corporations
# The DSNG comes with a 2P train
train = @depot.upcoming[0]
Expand All @@ -114,11 +105,15 @@ def mines_count(entity)
end

def mine_multiplier(entity)
entity.abilities(:mine_multiplier).map(&:count_per_or).reject(&:zero?).reduce(1, :*)
imc.owner == entity ? 2 : 1
end

def mine_value(entity)
BASE_MINE_VALUE * mine_multiplier(entity)
end

def mines_total(entity)
BASE_MINE_VALUE * mines_count(entity) * mine_multiplier(entity)
mine_value(entity) * mine_multiplier(entity)
end

def mines_remove(entity)
Expand All @@ -128,12 +123,20 @@ def mines_remove(entity)
end

def mine_add(entity)
mine_count = mines_count(entity) + 1
mine_create(entity, mines_count(entity) + 1)
end

def mine_update_text(entity)
mine_create(entity, mines_count(entity))
end

def mine_create(entity, count)
mines_remove(entity)
total = count * mine_value(entity)
entity.add_ability(Engine::Ability::Base.new(
type: :mine_income,
description: "Corporation owns #{mine_count} mines",
count_per_or: mine_count,
description: "#{count} mines x #{format_currency(mine_value(entity))} = #{format_currency(total)} to treasury",
count_per_or: count,
remove: '6'
))
end
Expand Down Expand Up @@ -167,6 +170,15 @@ def new_auction_round
])
end

def action_processed(action)
super

case action
when Action::BuyCompany
mine_update_text(action.entity) if action.company == imc && action.entity.corporation?
end
end

def revenue_for(route, stops)
revenue = super

Expand Down
16 changes: 7 additions & 9 deletions lib/engine/step/g_18_co/dividend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ def share_price_change(entity, revenue = 0)
{ share_direction: %i[right up], share_times: [1, 1] }
end

def change_share_price(entity, payout)
tfm = @game.mines_total(entity)

# Only pay mines if a train produce revenue regardless of withhold or pay
if tfm.positive? && (payout[:corporation].positive? || payout[:per_share].positive?)
@game.bank.spend(tfm, entity)
def process_dividend(action)
super

@log << "#{entity.name} collects #{@game.format_currency(tfm)} from mines"
end
entity = action.entity
return unless (mine_revenue = @game.mines_total(entity)).positive?
return unless (entity.operating_history[[@game.turn, @round.round_num]].revenue).positive?

super
@game.bank.spend(mine_revenue, entity)
@log << "#{entity.name} collects #{@game.format_currency(mine_revenue)} from mines"
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions lib/engine/step/g_18_co/track.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ def process_lay_tile(action)
# Add mine to corporation data
@game.mine_add(action.entity)

@log << "#{action.entity.name} collects a mine token from
#{action.hex.name} for a total of
#{@game.format_currency(@game.mines_total(action.entity))} from mines"
@log << "#{action.entity.name} collects a mine token from #{action.hex.name}"
end

pass! unless can_lay_tile?(action.entity)
Expand Down

0 comments on commit 5393a53

Please sign in to comment.