Class: Australium::Player

Inherits:
OpenStruct
  • Object
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

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
# File 'lib/australium/player.rb', line 17

def initialize(*args)
  super(*args)

  # @!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 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
# File 'lib/australium/player.rb', line 17

def initialize(*args)
  super(*args)

  # @!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 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
# File 'lib/australium/player.rb', line 17

def initialize(*args)
  super(*args)

  # @!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 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
# File 'lib/australium/player.rb', line 17

def initialize(*args)
  super(*args)

  # @!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 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
# File 'lib/australium/player.rb', line 17

def initialize(*args)
  super(*args)

  # @!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 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)


37
38
39
40
41
42
43
# File 'lib/australium/player.rb', line 37

def ==(player)
  if [self, player].all?(&:bot?)
    self.nick == player.nick
  else
    self.steam_id == player.steam_id
  end
end

#blu?Boolean

Checks if the player is on the BLU team.

Returns:

  • (Boolean)

    true if the player is on the BLU team



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

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

#bot?Boolean

Checks if the player is a bot.

Returns:

  • (Boolean)

    true if the player is a bot



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

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)


46
47
48
49
50
51
52
# File 'lib/australium/player.rb', line 46

def eql?(player)
  if [self, player].all?(&:bot?)
    self.nick.eql?(player.nick)
  else
    self.steam_id.eql?(player.steam_id)
  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



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

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



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

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

#spectator?Boolean

Checks if the player is a spectator.

Returns:

  • (Boolean)

    true if the player is a spectator



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

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



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

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