Class: Hlockey::Game::Weather::Chicken

Inherits:
Object
  • Object
show all
Includes:
Actions, Weatherable
Defined in:
lib/hlockey/game/weather/chicken.rb

Overview

Chicken weather Swaps a random roster player with a random shadow player for the rest of the game

Instance Method Summary collapse

Methods included from Weatherable

#initialize, #on_goal, #on_period_end

Methods included from SelfDescribable

#to_s

Instance Method Details

#on_actionObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/hlockey/game/weather/chicken.rb', line 19

def on_action
  return unless random_event_occurs?(5)

  team = rand_team
  pos, shadows_idx = get_swap(team)
  if pos.nil? || shadows_idx.nil?
    team = team == :home ? :away : :home
    pos, shadows_idx = get_swap(team)
    return if pos.nil? || shadows_idx.nil?
  end

  @chickened_out[team][pos] = shadows_idx

  @game.stream << Message.new(:weather_chicken_event,
                              **swap(team, pos, shadows_idx))
end

#on_game_endObject



36
37
38
39
40
# File 'lib/hlockey/game/weather/chicken.rb', line 36

def on_game_end
  @chickened_out.each do |team, swaps|
    swaps.each { |pos, shadows_idx| swap(team, pos, shadows_idx) }
  end
end

#on_game_startObject



15
16
17
# File 'lib/hlockey/game/weather/chicken.rb', line 15

def on_game_start
  @chickened_out = { home: {}, away: {} }
end