Class: Sc2::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/sc2/wrappers/player.rb

Constant Summary collapse

OUTCOMES =
[:unknown, :win, :loss]
ATTRIBUTES =
{ :player_race => { "RAND" => :random, "Terr" => 'terran', "Prot" => 'protoss', "Zerg" => 'zerg' } }

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Player

Returns a new instance of Player.



5
6
7
8
9
10
# File 'lib/sc2/wrappers/player.rb', line 5

def initialize params
  @params = params
  @params[:outcome] = OUTCOMES[@params[:outcome]]
  @params[:attrs].compact!
  @params[:attrs].each { |attr| attr[:value].reverse! }
end

Instance Method Details

#idObject



18
19
20
# File 'lib/sc2/wrappers/player.rb', line 18

def id
  @params[:id]
end

#loss?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/sc2/wrappers/player.rb', line 30

def loss?
  @params[:outcome] == :loss
end

#nameObject



22
23
24
# File 'lib/sc2/wrappers/player.rb', line 22

def name
  @params[:name]
end

#raceObject



12
13
14
15
16
# File 'lib/sc2/wrappers/player.rb', line 12

def race
  @params[:attrs].each do |attr|
    return ATTRIBUTES[:player_race][attr[:value]] if attr[:attr_id] == 3001
  end
end

#win?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/sc2/wrappers/player.rb', line 26

def win?
  @params[:outcome] == :win
end