Class: Hengband::Player

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

Constant Summary collapse

EQUIP_PLACES =
[:r_arm, :l_arm, :bow, :r_finger, :l_finger,
:neck, :light, :body, :outer, :head, :hands, :feet]
EQUIPPABLES =
[[:weapon, :shield], [:weapon, :shield], [:bow],
[:ring], [:ring], [:neck], [:light], [:armor], [:cloak],
[:head], [:hands], [:feet]]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inventory = []) ⇒ Player

Returns a new instance of Player.



11
12
13
14
15
16
# File 'lib/hengband/player.rb', line 11

def initialize(inventory = [])
  @inventory = inventory
  @equips = {}.tap{|h|
    EQUIP_PLACES.each{|name| h[name] = nil}
  }
end

Instance Attribute Details

#equipsObject (readonly)

Returns the value of attribute equips.



17
18
19
# File 'lib/hengband/player.rb', line 17

def equips
  @equips
end

Instance Method Details

#resistsObject



35
36
37
# File 'lib/hengband/player.rb', line 35

def resists
  @equips.map{|name, x| x.flags[:res] + x.flags[:imm]}.inject(:+).uniq.join
end

#wear_randomObject



19
20
21
22
23
24
25
# File 'lib/hengband/player.rb', line 19

def wear_random
  EQUIP_PLACES.zip(EQUIPPABLES).each do |name, types|
    item = @inventory.find_all{|x| types.include? x.type}.sample
    @equips[name] = item
  end
  self
end

#wearingsObject



27
28
29
30
31
32
33
# File 'lib/hengband/player.rb', line 27

def wearings
  i = "`"
  EQUIP_PLACES.map{|name|
    i.succ!
    "#{i}) #{@equips[name]}"
  }.join("\n")
end