Class: CoopAl::EncounterGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/coop_al/encounter_generator.rb

Overview

EncounterGenerator

Instance Method Summary collapse

Constructor Details

#initialize(name, parent, bestiary) ⇒ EncounterGenerator

Returns a new instance of EncounterGenerator.



6
7
8
9
# File 'lib/coop_al/encounter_generator.rb', line 6

def initialize(name, parent, bestiary)
  @bestiary = bestiary
  @encounter = Encounter.new(name, parent)
end

Instance Method Details

#encounter(name, &blk) ⇒ Object



38
39
40
41
# File 'lib/coop_al/encounter_generator.rb', line 38

def encounter(name, &blk)
  generator = EncounterGenerator.new(name, @encounter, @bestiary)
  @encounter.add_sub_encounter(generator.generate_encounter(&blk))
end

#generate_encounter(&blk) ⇒ Object



11
12
13
14
# File 'lib/coop_al/encounter_generator.rb', line 11

def generate_encounter(&blk)
  instance_eval(&blk)
  @encounter
end

#item(description) ⇒ Object



34
35
36
# File 'lib/coop_al/encounter_generator.rb', line 34

def item(description)
  items(1, description)
end

#items(count, description) ⇒ Object



30
31
32
# File 'lib/coop_al/encounter_generator.rb', line 30

def items(count, description)
  @encounter.add_item(Item.new(expand_count(count), description, @encounter))
end

#monster(id, treasure = :default) ⇒ Object



22
23
24
# File 'lib/coop_al/encounter_generator.rb', line 22

def monster(id, treasure = :default)
  monsters(1, id, treasure)
end

#monsters(count, id, treasure = :default) ⇒ Object



16
17
18
19
20
# File 'lib/coop_al/encounter_generator.rb', line 16

def monsters(count, id, treasure = :default)
  expand_count(count).times do
    @encounter.add_monster(@bestiary.create(id, treasure, @encounter))
  end
end

#npc(cr) ⇒ Object



52
53
54
# File 'lib/coop_al/encounter_generator.rb', line 52

def npc(cr)
  xp(XpRewardTable.new[cr])
end

#npcs(count, cr) ⇒ Object



56
57
58
# File 'lib/coop_al/encounter_generator.rb', line 56

def npcs(count, cr)
  xp(count * XpRewardTable.new[cr])
end

#random(name, &blk) ⇒ Object



43
44
45
46
# File 'lib/coop_al/encounter_generator.rb', line 43

def random(name, &blk)
  generator = RandomEncounterGenerator.new(name, @encounter, @bestiary)
  @encounter.add_sub_encounter(generator.generate_encounter(&blk))
end

#treasure(value, description = nil) ⇒ Object



26
27
28
# File 'lib/coop_al/encounter_generator.rb', line 26

def treasure(value, description = nil)
  @encounter.add_treasure(Treasure.new(value, description))
end

#xp(amount) ⇒ Object



48
49
50
# File 'lib/coop_al/encounter_generator.rb', line 48

def xp(amount)
  @encounter.add_xp(amount)
end