Module: Lich::Gemstone::Infomon::XMLParser

Defined in:
documented/gemstone/infomon/xmlparser.rb

Overview

The XMLParser module handles parsing of XML data related to game events.

Defined Under Namespace

Modules: Pattern

Class Method Summary collapse

Class Method Details

.parse(line) ⇒ Symbol

Parses a line of XML data to extract relevant game information.

Examples:

Parsing a death message

parse("The fire in the goblin's body as it rises, disappearing into the heavens.") # => :ok

Parameters:

  • line (String)

    the line of XML data to parse

Returns:

  • (Symbol)

    the result of the parsing operation, either :ok, :noop, or :error



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'documented/gemstone/infomon/xmlparser.rb', line 194

def self.parse(line)
  # O(1) vs O(N)
  return :noop unless line =~ Pattern::All

  begin
    case line
    # this detects for death messages in XML that are not matched with appropriate combat attributes above
    when Pattern::NpcDeathMessage
      match = Regexp.last_match
      if (npc = GameObj.npcs.find { |obj| obj.id == match[:npc_id] && obj.status !~ /\b(?:dead|gone)\b/ })
        npc.status = 'dead'
      end
      :ok
    when Pattern::Group_Short
      return :noop unless (match_data = Group::Observer.wants?(line))
      Group::Observer.consume(line.strip, match_data)
      :ok
    when Pattern::Overwatch_Short
      return :noop unless (match_data = Overwatch::Observer.wants?(line))
      Overwatch::Observer.consume(line, match_data)
      :ok
    when Pattern::Also_Here_Arrival
      return :noop unless Lich::Claim::Lock.locked?
      line.scan(%r{<a exist=(?:'|")(?<id>.*?)(?:'|") noun=(?:'|")(?<noun>.*?)(?:'|")>(?<name>.*?)</a>}).each { |player_found|
        next unless player_found[0].to_s.start_with?('-')
        next if XMLData.arrival_pcs.include?(player_found[1])

        XMLData.arrival_pcs.push(player_found[1])
      }
      :ok
    when Pattern::StowListOutputStart
      StowList.reset
      :ok
    when Pattern::StowListContainer, Pattern::StowSetContainer1, Pattern::StowSetContainer2
      match = Regexp.last_match
      StowList.__send__("#{match[:type].downcase}=", GameObj.index_or_create(match[:id], match[:noun], match[:name], (match[:before].nil? ? nil : match[:before].strip), (match[:after].nil? ? nil : match[:after].strip)))
      StowList.checked = true if line =~ Pattern::StowListContainer
      :ok
    when Pattern::ReadyListOutputStart
      ReadyList.reset
      :ok
    when Pattern::ReadyListNormal, Pattern::ReadyListAmmo2, Pattern::ReadyListSheathsSet, Pattern::ReadyItemSet
      match = Regexp.last_match
      unless match[:id].nil?
        ReadyList.__send__("#{Lich::Util.normalize_name(match[:type].downcase)}=", GameObj.index_or_create(match[:id], match[:noun], match[:name], (match[:before].nil? ? nil : match[:before].strip), (match[:after].nil? ? nil : match[:after].strip)))
      end
      if match.named_captures.include?("store")
        ReadyList.__send__("store_#{Lich::Util.normalize_name(match[:type].downcase)}=", match[:store])
      end
      :ok
    when Pattern::ReadyListFinished
      ReadyList.checked = true
      :ok
    when Pattern::ReadyItemClear
      match = Regexp.last_match
      ReadyList.__send__("#{Lich::Util.normalize_name(match[:type].downcase)}=", nil)
      :ok
    when Pattern::ReadyStoreSet
      match = Regexp.last_match
      ReadyList.__send__("store_#{Lich::Util.normalize_name(match[:type].downcase)}=", match[:store])
      :ok
    when Pattern::StatusPrompt
      Infomon::Parser::State.set(Infomon::Parser::State::Ready) unless Infomon::Parser::State.get.eql?(Infomon::Parser::State::Ready)
      :ok
    else
      :noop
    end
  rescue StandardError
    respond "--- Lich: error: Infomon::XMLParser.parse: #{$!}"
    respond "--- Lich: error: line: #{line}"
    Lich.log "error: Infomon::XMLParser.parse: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
    Lich.log "error: line: #{line}\n\t"
  end
end