Class: Australium::Player

Inherits:
TimedOpenStruct show all
Defined in:
lib/australium/player.rb

Overview

Represents a Player playing a Game.

Constant Summary collapse

LOG_REGEX =
/(?<nick>.*)<(?<won_id>.*)><(?<steam_id>.*)><(?<team>.*)>/

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from TimedOpenStruct

#[], #[]=, #durations, #initialize_clone

Methods inherited from OpenStruct

#initialize_clone

Constructor Details

#initialize(*args) ⇒ Player

Returns a new instance of Player


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/australium/player.rb', line 17

def initialize(*args)
  super(*args)

  # Change steamIDs from the old format to the new one
  match = self[:steam_id].match(/STEAM_0:([0-9]+):([0-9]+)/)
  unless match.nil?
    begin
      self[:steam_id] = "[U:1:#{match[2].to_i * 2 + match[1].to_i}]"
    rescue nil ; end
  end

  # @!attribute address
  #   @return [String, NilClass] the player's IP address, or nil if not known
  self[:address] = nil

  # @!attribute in_game?
  #   @return [Boolean] true if the player is in the game (as determined by a triggered {PlayerEnterGame} event).
  self[:in_game?] = false

  # @!attribute connected?
  #   @return [Boolean] true if the player is currently connected to the server
  self[:connected?] = false

  # @!attribute role
  #   @return [String, NilClass] the name of the role the player is playing, or nil if none yet
  self[:role] = nil

end

Instance Attribute Details

#nickString

Returns the player's in-game nickname.

Returns:

  • (String)

    the player's in-game nickname.


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/australium/player.rb', line 17

def initialize(*args)
  super(*args)

  # Change steamIDs from the old format to the new one
  match = self[:steam_id].match(/STEAM_0:([0-9]+):([0-9]+)/)
  unless match.nil?
    begin
      self[:steam_id] = "[U:1:#{match[2].to_i * 2 + match[1].to_i}]"
    rescue nil ; end
  end

  # @!attribute address
  #   @return [String, NilClass] the player's IP address, or nil if not known
  self[:address] = nil

  # @!attribute in_game?
  #   @return [Boolean] true if the player is in the game (as determined by a triggered {PlayerEnterGame} event).
  self[:in_game?] = false

  # @!attribute connected?
  #   @return [Boolean] true if the player is currently connected to the server
  self[:connected?] = false

  # @!attribute role
  #   @return [String, NilClass] the name of the role the player is playing, or nil if none yet
  self[:role] = nil

end

#steam_idString

Returns the player's unique Steam ID, or 'BOT' if this player is a bot.

Returns:

  • (String)

    the player's unique Steam ID, or 'BOT' if this player is a bot.


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/australium/player.rb', line 17

def initialize(*args)
  super(*args)

  # Change steamIDs from the old format to the new one
  match = self[:steam_id].match(/STEAM_0:([0-9]+):([0-9]+)/)
  unless match.nil?
    begin
      self[:steam_id] = "[U:1:#{match[2].to_i * 2 + match[1].to_i}]"
    rescue nil ; end
  end

  # @!attribute address
  #   @return [String, NilClass] the player's IP address, or nil if not known
  self[:address] = nil

  # @!attribute in_game?
  #   @return [Boolean] true if the player is in the game (as determined by a triggered {PlayerEnterGame} event).
  self[:in_game?] = false

  # @!attribute connected?
  #   @return [Boolean] true if the player is currently connected to the server
  self[:connected?] = false

  # @!attribute role
  #   @return [String, NilClass] the name of the role the player is playing, or nil if none yet
  self[:role] = nil

end

#teamString

Returns the name of the team the player is on (can be an empty string).

Returns:

  • (String)

    the name of the team the player is on (can be an empty string).


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/australium/player.rb', line 17

def initialize(*args)
  super(*args)

  # Change steamIDs from the old format to the new one
  match = self[:steam_id].match(/STEAM_0:([0-9]+):([0-9]+)/)
  unless match.nil?
    begin
      self[:steam_id] = "[U:1:#{match[2].to_i * 2 + match[1].to_i}]"
    rescue nil ; end
  end

  # @!attribute address
  #   @return [String, NilClass] the player's IP address, or nil if not known
  self[:address] = nil

  # @!attribute in_game?
  #   @return [Boolean] true if the player is in the game (as determined by a triggered {PlayerEnterGame} event).
  self[:in_game?] = false

  # @!attribute connected?
  #   @return [Boolean] true if the player is currently connected to the server
  self[:connected?] = false

  # @!attribute role
  #   @return [String, NilClass] the name of the role the player is playing, or nil if none yet
  self[:role] = nil

end

#won_idString

Returns the player's WONID.

Returns:

  • (String)

    the player's WONID.


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/australium/player.rb', line 17

def initialize(*args)
  super(*args)

  # Change steamIDs from the old format to the new one
  match = self[:steam_id].match(/STEAM_0:([0-9]+):([0-9]+)/)
  unless match.nil?
    begin
      self[:steam_id] = "[U:1:#{match[2].to_i * 2 + match[1].to_i}]"
    rescue nil ; end
  end

  # @!attribute address
  #   @return [String, NilClass] the player's IP address, or nil if not known
  self[:address] = nil

  # @!attribute in_game?
  #   @return [Boolean] true if the player is in the game (as determined by a triggered {PlayerEnterGame} event).
  self[:in_game?] = false

  # @!attribute connected?
  #   @return [Boolean] true if the player is currently connected to the server
  self[:connected?] = false

  # @!attribute role
  #   @return [String, NilClass] the name of the role the player is playing, or nil if none yet
  self[:role] = nil

end

Instance Method Details

#==(player) ⇒ Boolean

Compares players by steam IDs and bots by nicks.

Parameters:

  • player (Player)

    the player to compare against

Returns:

  • (Boolean)

51
52
53
54
55
56
57
58
59
# File 'lib/australium/player.rb', line 51

[:==, :eql?].each do |method|
  define_method(method) do |player|
    if [self, player].all?(&:bot?)
      self.nick.send(method, player.nick)
    else
      self.steam_id.send(method, player.steam_id)
    end
  end
end

#blu?Boolean

Checks if the player is on the BLU team.

Returns:

  • (Boolean)

    true if the player is on the BLU team


67
# File 'lib/australium/player.rb', line 67

def blu? ; self.team == 'Blue' end

#bot?Boolean

Checks if the player is a bot.

Returns:

  • (Boolean)

    true if the player is a bot


63
# File 'lib/australium/player.rb', line 63

def bot? ; self.steam_id == 'BOT' end

#eql?(player) ⇒ Boolean

Compares players by steam IDs and bots by nicks.

Parameters:

  • player (Player)

    the player to compare against

Returns:

  • (Boolean)

51
52
53
54
55
56
57
58
59
# File 'lib/australium/player.rb', line 51

[:==, :eql?].each do |method|
  define_method(method) do |player|
    if [self, player].all?(&:bot?)
      self.nick.send(method, player.nick)
    else
      self.steam_id.send(method, player.steam_id)
    end
  end
end

#has_team?Boolean

Checks if the player is in the game as either a RED or BLU player.

Returns:

  • (Boolean)

    true if the player is either on RED or BLU


83
# File 'lib/australium/player.rb', line 83

def has_team? ; blu? || red? end

#red?Boolean

Checks if the player is on the RED team.

Returns:

  • (Boolean)

    true if the player is on the RED team


71
# File 'lib/australium/player.rb', line 71

def red? ; self.team == 'Red' end

#spectator?Boolean

Checks if the player is a spectator.

Returns:

  • (Boolean)

    true if the player is a spectator


75
# File 'lib/australium/player.rb', line 75

def spectator? ; self.team == 'Spectator' end

#unassigned?Boolean

Checks if the player is not assigned to any team. (This can be considered a fourth team in some contexts.)

Returns:

  • (Boolean)

    true if the player is unassigned


79
# File 'lib/australium/player.rb', line 79

def unassigned? ; self.team == 'Unassigned' end