Class: Hlockey::Mod::Handholding

Inherits:
Object
  • Object
show all
Includes:
Moddable
Defined in:
lib/hlockey/mod/handholding.rb

Overview

Specified player follows the player this mod is applied to when they are swapped in/out

Constant Summary collapse

DESCRIPTION =
"This player is holding another player's hand.".freeze

Instance Attribute Summary

Attributes included from Moddable

#game

Instance Method Summary collapse

Methods included from Moddable

#on_action, #on_got_hit, #on_join_fight

Methods included from SelfDescribable

#to_s

Constructor Details

#initialize(player, other_player) ⇒ Handholding

Returns a new instance of Handholding.

Parameters:

  • other_player (String)

    name of other player



14
15
16
17
# File 'lib/hlockey/mod/handholding.rb', line 14

def initialize(player, other_player)
  super(player)
  @other_player = other_player
end

Instance Method Details

#on_swap(into_roster, pos, _prev_pos) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/hlockey/mod/handholding.rb', line 21

def on_swap(into_roster, pos, _prev_pos)
  unless @other_player.is_a?(Team::Player)
    @other_player = @team.players.find { _1.name == @other_player }
  end

  swap_player = nil
  if into_roster
    prev_pos = @team.shadows.index(@other_player)
    return if prev_pos.nil?

    swap_pos = sample_with_deleted(@team.roster.keys, pos)
    swap_player = @team.roster[swap_pos]

    @team.shadows[prev_pos] = swap_player
    @team.roster[swap_pos] = @other_player
  else
    prev_pos = @team.roster.key(@other_player)
    return if prev_pos.nil?

    swap_pos = sample_with_deleted(@team.shadows.each_index.to_a, pos)
    swap_player = @team.shadows[swap_pos]

    @team.roster[prev_pos] = swap_player
    @team.shadows[swap_pos] = @other_player
  end

  send_game_message(:mod_handholding_event,
                    player: @player, other_player: @other_player, swap_player:)
end

#to_dataObject



19
# File 'lib/hlockey/mod/handholding.rb', line 19

def to_data = [to_s, @other_player.to_s]