Class: Australium::Player
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Australium::Player
- 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
-
#nick ⇒ String
The player’s in-game nickname.
-
#steam_id ⇒ String
The player’s unique Steam ID, or ‘BOT’ if this player is a bot.
-
#team ⇒ String
The name of the team the player is on (can be an empty string).
-
#won_id ⇒ String
The player’s WONID.
Instance Method Summary collapse
-
#==(player) ⇒ Boolean
Compares players by steam IDs and bots by nicks.
-
#blu? ⇒ Boolean
Checks if the player is on the BLU team.
-
#bot? ⇒ Boolean
Checks if the player is a bot.
-
#eql?(player) ⇒ Boolean
Compares players by steam IDs and bots by nicks.
-
#has_team? ⇒ Boolean
Checks if the player is in the game as either a RED or BLU player.
-
#initialize(*args) ⇒ Player
constructor
A new instance of Player.
-
#red? ⇒ Boolean
Checks if the player is on the RED team.
-
#spectator? ⇒ Boolean
Checks if the player is a spectator.
-
#unassigned? ⇒ Boolean
Checks if the player is not assigned to any team.
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
#nick ⇒ String
Returns 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_id ⇒ String
Returns 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 |
#team ⇒ String
Returns 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_id ⇒ String
Returns 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.
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.
60 |
# File 'lib/australium/player.rb', line 60 def blu? ; self.team == 'Blue' end |
#bot? ⇒ Boolean
Checks 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.
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.
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.
64 |
# File 'lib/australium/player.rb', line 64 def red? ; self.team == 'Red' end |
#spectator? ⇒ Boolean
Checks 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.)
72 |
# File 'lib/australium/player.rb', line 72 def unassigned? ; self.team == 'Unassigned' end |