Class: CoopAl::Bestiary

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/coop_al/bestiary.rb

Overview

Bestiary

Instance Method Summary collapse

Constructor Details

#initializeBestiary

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

Returns:

  • (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

Returns:

  • (Boolean)


24
25
26
# File 'lib/coop_al/bestiary.rb', line 24

def monster?(id)
  @monsters.key?(id)
end