Class: Hlockey::Game::Weather::Waves

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

Overview

Waves weather Swaps a roster player (worst most likely) with a random shadow player permanently

Instance Method Summary collapse

Methods included from Weatherable

#initialize, #on_game_end, #on_game_start, #on_goal, #on_period_end

Methods included from SelfDescribable

#to_s

Instance Method Details

#on_actionObject



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/hlockey/game/weather/waves.rb', line 15

def on_action
  return unless random_event_occurs?

  team_sym = rand_team
  team = @game.send(team_sym)
  player_leaving_pos = if @prng.rand(5).zero?
                         team.roster.keys.sample(random: @prng)
                       else
                         team.worst_player_pos
                       end
  swap_res = swap(team_sym, player_leaving_pos, @prng.rand(team.shadows.length))
  @game.stream << Message.new(:weather_waves_event, **swap_res)
end