Class: Scroll

Inherits:
Exist show all
Defined in:
lib/Olib/core/scroll.rb

Constant Summary collapse

SPELL =
%r[\((?<num>\d+)\)\s(?<name>(\w|\s)+)$]

Constants inherited from Exist

Exist::GETTER, Exist::PATTERN

Instance Attribute Summary

Attributes inherited from Exist

#gameobj, #id

Instance Method Summary collapse

Methods inherited from Exist

#==, #deconstruct_keys, #effects, #exists?, #fetch, fetch, #gone?, #method_missing, normalize_type_data, #respond_to_missing?, scan, #tags, #to_h, #to_s

Constructor Details

#initialize(obj, container = nil) ⇒ Scroll

Returns a new instance of Scroll.



4
5
6
7
8
# File 'lib/Olib/core/scroll.rb', line 4

def initialize(obj, container = nil)
  super(obj.id)
  @knowledge = nil
  @container = container
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Exist

Instance Method Details

#_parse_spell(spells, line) ⇒ Object



33
34
35
36
# File 'lib/Olib/core/scroll.rb', line 33

def _parse_spell(spells, line)
  return unless line =~ SPELL
  spells << OpenStruct.new(line.match(SPELL).to_h)
end

#_readObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/Olib/core/scroll.rb', line 19

def _read()
  Script.current.want_downstream_xml = true
  dothistimeout("read ##{id}", 5, /It takes you a moment to focus on the/)
  spells = []
  @knowledge = false
  while line = get
    @knowledge = true if line.include?(%[in vibrant ink])
    break if line =~ %r[<prompt]
    _parse_spell(spells, line.strip)
  end
  Script.current.want_downstream_xml = false
  return spells
end

#knowledge?Boolean

Returns:

  • (Boolean)


14
15
16
17
# File 'lib/Olib/core/scroll.rb', line 14

def knowledge?
  spells
  @knowledge.eql?(true)
end

#spellsObject



10
11
12
# File 'lib/Olib/core/scroll.rb', line 10

def spells()
  @_spells ||= _read()
end