Class: Gloomhaven::Player

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  validate!(options)
  @character = Character.new(options[:character_class])
  @deck = Deck.new
  @name = options[:name]
  @gold = options[:gold] || 0
  @xp = options[:xp] || 0
  @items = []
  @perks = []
end

Instance Attribute Details

#characterObject (readonly)

Returns the value of attribute character.



4
5
6
# File 'lib/gloomhaven/player.rb', line 4

def character
  @character
end

#deckObject (readonly)

Returns the value of attribute deck.



4
5
6
# File 'lib/gloomhaven/player.rb', line 4

def deck
  @deck
end

#goldObject

Returns the value of attribute gold.



5
6
7
# File 'lib/gloomhaven/player.rb', line 5

def gold
  @gold
end

#itemsObject (readonly)

Returns the value of attribute items.



4
5
6
# File 'lib/gloomhaven/player.rb', line 4

def items
  @items
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/gloomhaven/player.rb', line 4

def name
  @name
end

#perksObject (readonly)

Returns the value of attribute perks.



4
5
6
# File 'lib/gloomhaven/player.rb', line 4

def perks
  @perks
end

#xpObject

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

Raises:

  • (TypeError)


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