Class: Lairs

Inherits:
Object show all
Includes:
LairsData, XpDifficultyTable
Defined in:
lib/encounters/lairs.rb

Constant Summary collapse

AVAILABLE_ENCOUNTER_LEVEL =
REVERSED_XP_DIFFICULTY_TABLE.keys
MIN_PARTY_LEVEL_MUL =
0.4

Constants included from XpDifficultyTable

XpDifficultyTable::REVERSED_XP_DIFFICULTY_TABLE, XpDifficultyTable::XP_DIFFICULTY_TABLE

Constants included from LairsData

LairsData::LAIRS_DATA

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(encounter_level, hero_levels, lair_type = nil) ⇒ Lairs

encounter_level : :easy, :medium, :hard, :deadly



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/encounters/lairs.rb', line 15

def initialize( encounter_level, hero_levels, lair_type = nil)

  @encounters = Encounters.new
  @encounter_level = encounter_level
  @hero_levels = hero_levels
  check_params

  @party_xp_level = hero_levels.map{ |hl| XP_DIFFICULTY_TABLE[hl][@encounter_level] }.reduce(&:+)

  @lair_type = lair_type ? lair_type : get_available_lairs.sample
end

Instance Attribute Details

#lair_typeObject (readonly)

Returns the value of attribute lair_type.



12
13
14
# File 'lib/encounters/lairs.rb', line 12

def lair_type
  @lair_type
end

Class Method Details

.from_hash(hash) ⇒ Object



36
37
38
39
# File 'lib/encounters/lairs.rb', line 36

def self.from_hash( hash )
  hash = hash.map { |k, v| [k.to_sym, v] }.to_h
  Lairs.new( hash[ :encounter_level ].to_sym, hash[ :hero_levels ], hash[ :lair_type ].to_sym )
end

Instance Method Details

#encounterObject



27
28
29
30
# File 'lib/encounters/lairs.rb', line 27

def encounter
  encounter_id = get_available_encounters.sample
  @encounters.by_id encounter_id
end

#to_hashObject



32
33
34
# File 'lib/encounters/lairs.rb', line 32

def to_hash
  { encounter_level: @encounter_level, hero_levels: @hero_levels, lair_type: @lair_type }
end