Class: Gloomhaven::Player
- Inherits:
-
Object
- Object
- Gloomhaven::Player
- Defined in:
- lib/gloomhaven/player.rb
Instance Attribute Summary collapse
-
#character ⇒ Object
readonly
Returns the value of attribute character.
-
#deck ⇒ Object
readonly
Returns the value of attribute deck.
-
#gold ⇒ Object
Returns the value of attribute gold.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#perks ⇒ Object
readonly
Returns the value of attribute perks.
-
#xp ⇒ Object
Returns the value of attribute xp.
Instance Method Summary collapse
- #add_perk!(perk) ⇒ Object
-
#initialize(options = {}) ⇒ Player
constructor
A new instance of Player.
Constructor Details
#initialize(options = {}) ⇒ Player
Returns a new instance of Player.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/gloomhaven/player.rb', line 7 def initialize( = {}) validate!() @character = Character.new([:character_class]) @deck = Deck.new @name = [:name] @gold = [:gold] || 0 @xp = [:xp] || 0 @items = [] @perks = [] end |
Instance Attribute Details
#character ⇒ Object (readonly)
Returns the value of attribute character.
4 5 6 |
# File 'lib/gloomhaven/player.rb', line 4 def character @character end |
#deck ⇒ Object (readonly)
Returns the value of attribute deck.
4 5 6 |
# File 'lib/gloomhaven/player.rb', line 4 def deck @deck end |
#gold ⇒ Object
Returns the value of attribute gold.
5 6 7 |
# File 'lib/gloomhaven/player.rb', line 5 def gold @gold end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
4 5 6 |
# File 'lib/gloomhaven/player.rb', line 4 def items @items end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/gloomhaven/player.rb', line 4 def name @name end |
#perks ⇒ Object (readonly)
Returns the value of attribute perks.
4 5 6 |
# File 'lib/gloomhaven/player.rb', line 4 def perks @perks end |
#xp ⇒ Object
Returns the value of attribute xp.
5 6 7 |
# File 'lib/gloomhaven/player.rb', line 5 def xp @xp end |
Instance Method Details
#add_perk!(perk) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/gloomhaven/player.rb', line 18 def add_perk!(perk) raise TypeError.new('Perk must be a Gloomhaven::Perk') unless perk.is_a?(Gloomhaven::Perk) raise ArgumentError.new("#{character} cannot select #{perk.description}. Must be one of the following: #{class_perks}") unless class_perks.include?(perk.key) raise ArgumentError.new("#{character} has the maximum number of #{perk.description} perks") if existing_perk_count(perk) >= character_perk_limit(perk) update_attack_modifier_deck_from!(perk) @perks << perk end |