Class: Hengband::Player
- Inherits:
-
Object
- Object
- Hengband::Player
- 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
-
#equips ⇒ Object
readonly
Returns the value of attribute equips.
Instance Method Summary collapse
-
#initialize(inventory = []) ⇒ Player
constructor
A new instance of Player.
- #resists ⇒ Object
- #wear_random ⇒ Object
- #wearings ⇒ Object
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
#equips ⇒ Object (readonly)
Returns the value of attribute equips.
17 18 19 |
# File 'lib/hengband/player.rb', line 17 def equips @equips end |
Instance Method Details
#resists ⇒ Object
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_random ⇒ Object
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 |
#wearings ⇒ Object
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 |