Class: CoopAl::Bestiary
- Inherits:
-
Object
- Object
- CoopAl::Bestiary
- Includes:
- Singleton
- Defined in:
- lib/coop_al/bestiary.rb
Overview
Bestiary
Instance Method Summary collapse
- #add(monster) ⇒ Object
- #create(id, treasure, encounter) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ Bestiary
constructor
A new instance of Bestiary.
- #monster(id) ⇒ Object
- #monster?(id) ⇒ Boolean
Constructor Details
#initialize ⇒ Bestiary
Returns a new instance of Bestiary.
10 11 12 13 14 |
# File 'lib/coop_al/bestiary.rb', line 10 def initialize @monsters = {} @xp_lookup = XpRewardTable.new @loot_generator = LootGenerator.new end |
Instance Method Details
#add(monster) ⇒ Object
20 21 22 |
# File 'lib/coop_al/bestiary.rb', line 20 def add(monster) @monsters[monster.id] = monster end |
#create(id, treasure, encounter) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/coop_al/bestiary.rb', line 32 def create(id, treasure, encounter) raise "Invalid monster ID (#{id})" unless @monsters.key?(id) monster = @monsters[id] xp = calculate_xp(monster) loot = generate_loot(monster, treasure) Monster.new(id, xp, loot, encounter) end |
#empty? ⇒ Boolean
16 17 18 |
# File 'lib/coop_al/bestiary.rb', line 16 def empty? @monsters.empty? end |
#monster(id) ⇒ Object
28 29 30 |
# File 'lib/coop_al/bestiary.rb', line 28 def monster(id) @monsters[id] end |
#monster?(id) ⇒ Boolean
24 25 26 |
# File 'lib/coop_al/bestiary.rb', line 24 def monster?(id) @monsters.key?(id) end |