Class: Lich::Common::XMLParser

Inherits:
Object
  • Object
show all
Includes:
REXML::StreamListener
Defined in:
documented/common/xmlparser.rb

Overview

Parses XML data from the game. This class is responsible for extracting and managing game state information from XML streams.

Examples:

Creating an XML parser

parser = Lich::Common::XMLParser.new

Constant Summary collapse

DECADE =

Constant representing the number of seconds in a decade.

10 * 31_536_000
PSM_3_DIALOG_IDS =
["Buffs", "Active Spells", "Debuffs", "Cooldowns"]
@@warned_deprecated_spellfront =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeXMLParser

Initializes a new XMLParser instance. Sets up the necessary instance variables for parsing XML data.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'documented/common/xmlparser.rb', line 62

def initialize
  @buffer = String.new
  # @unescape = { 'lt' => '<', 'gt' => '>', 'quot' => '"', 'apos' => "'", 'amp' => '&' }
  @bold = false
  @active_tags = Array.new
  @active_ids = Array.new
  @last_tag = String.new
  @last_id = String.new
  @current_stream = String.new
  @current_style = String.new
  @stow_container_id = nil
  @obj_location = nil
  @obj_exist = nil
  @obj_noun = nil
  @obj_before_name = nil
  @obj_name = nil
  @obj_after_name = nil
  @pc = nil
  @last_obj = nil
  @in_stream = false
  @player_status = nil
  @fam_mode = String.new
  @room_window_disabled = false
  @wound_gsl = String.new
  @scar_gsl = String.new
  @send_fake_tags = false
  @prompt = String.new
  @nerve_tracker_num = 0
  @nerve_tracker_active = 'no'
  @server_time = Time.now.to_i
  @server_time_offset = 0
  @roundtime_end = 0
  @cast_roundtime_end = 0
  @last_pulse = Time.now.to_i
  @level = 0
  @next_level_value = 0
  @next_level_text = String.new
  @current_target_ids = Array.new

  @room_count = 0
  @room_title = String.new
  @room_name = String.new
  @room_description = String.new
  @room_exits = Array.new
  @room_exits_string = String.new

  @familiar_room_title = String.new
  @familiar_room_description = String.new
  @familiar_room_exits = Array.new

  @bounty_task = String.new
  @society_task = String.new

  @dr_active_spells = Hash.new
  @dr_active_spells_clear = false
  @dr_active_spells_tmp = Hash.new
  @dr_active_spell_tracking = false
  @dr_active_spells_stellar_percentage = 0
  @dr_active_spells_slivers = false
  @name = String.new
  @game = String.new
  @player_id = String.new
  @mana = 0
  @max_mana = 0
  @health = 0
  @max_health = 0
  @spirit = 0
  @max_spirit = 0
  @last_spirit = nil
  @stamina = 0
  @max_stamina = 0
  @concentration = 0
  @max_concentration = 0
  @stance_text = String.new
  @stance_value = 0
  @mind_text = String.new
  @mind_value = 0
  @prepared_spell = 'None'
  @encumbrance_text = String.new
  @encumbrance_full_text = String.new
  @encumbrance_value = 0
  @indicator = Hash.new
  @injuries = { 'back' => { 'scar' => 0, 'wound' => 0 }, 'leftHand' => { 'scar' => 0, 'wound' => 0 }, 'rightHand' => { 'scar' => 0, 'wound' => 0 }, 'head' => { 'scar' => 0, 'wound' => 0 }, 'rightArm' => { 'scar' => 0, 'wound' => 0 }, 'abdomen' => { 'scar' => 0, 'wound' => 0 }, 'leftEye' => { 'scar' => 0, 'wound' => 0 }, 'leftArm' => { 'scar' => 0, 'wound' => 0 }, 'chest' => { 'scar' => 0, 'wound' => 0 }, 'leftFoot' => { 'scar' => 0, 'wound' => 0 }, 'rightFoot' => { 'scar' => 0, 'wound' => 0 }, 'rightLeg' => { 'scar' => 0, 'wound' => 0 }, 'neck' => { 'scar' => 0, 'wound' => 0 }, 'leftLeg' => { 'scar' => 0, 'wound' => 0 }, 'nsys' => { 'scar' => 0, 'wound' => 0 }, 'rightEye' => { 'scar' => 0, 'wound' => 0 } }
  @injury_mode = 0

  # psm 3.0 dialogdata updates
  @dialogs = {}

  # real id updates
  @room_id = nil
  @previous_nav_rm = nil

  # Lich::Claim update
  @arrival_pcs = []
  @check_obvious_hiding = false
  @room_player_hidden = false
end

Instance Attribute Details

#arrival_pcsObject (readonly)

Returns the value of attribute arrival_pcs.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def arrival_pcs
  @arrival_pcs
end

#bounty_taskObject (readonly)

Returns the value of attribute bounty_task.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def bounty_task
  @bounty_task
end

#cast_roundtime_endObject (readonly)

Returns the value of attribute cast_roundtime_end.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def cast_roundtime_end
  @cast_roundtime_end
end

#concentrationObject (readonly)

Returns the value of attribute concentration.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def concentration
  @concentration
end

#current_target_idObject (readonly)

Returns the value of attribute current_target_id.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def current_target_id
  @current_target_id
end

#current_target_idsObject (readonly)

Returns the value of attribute current_target_ids.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def current_target_ids
  @current_target_ids
end

#dialogsObject (readonly)

Returns the value of attribute dialogs.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def dialogs
  @dialogs
end

#dr_active_spellsObject (readonly)

Returns the value of attribute dr_active_spells.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def dr_active_spells
  @dr_active_spells
end

#dr_active_spells_sliversObject (readonly)

Returns the value of attribute dr_active_spells_slivers.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def dr_active_spells_slivers
  @dr_active_spells_slivers
end

#dr_active_spells_stellar_percentageObject (readonly)

Returns the value of attribute dr_active_spells_stellar_percentage.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def dr_active_spells_stellar_percentage
  @dr_active_spells_stellar_percentage
end

#encumbrance_full_textObject (readonly)

Returns the value of attribute encumbrance_full_text.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def encumbrance_full_text
  @encumbrance_full_text
end

#encumbrance_textObject (readonly)

Returns the value of attribute encumbrance_text.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def encumbrance_text
  @encumbrance_text
end

#encumbrance_valueObject (readonly)

Returns the value of attribute encumbrance_value.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def encumbrance_value
  @encumbrance_value
end

#familiar_room_descriptionObject (readonly)

Returns the value of attribute familiar_room_description.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def familiar_room_description
  @familiar_room_description
end

#familiar_room_exitsObject (readonly)

Returns the value of attribute familiar_room_exits.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def familiar_room_exits
  @familiar_room_exits
end

#familiar_room_titleObject (readonly)

Returns the value of attribute familiar_room_title.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def familiar_room_title
  @familiar_room_title
end

#gameObject (readonly)

Returns the value of attribute game.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def game
  @game
end

#healthObject (readonly)

Returns the value of attribute health.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def health
  @health
end

#in_streamObject (readonly)

Returns the value of attribute in_stream.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def in_stream
  @in_stream
end

#indicatorObject (readonly)

Returns the value of attribute indicator.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def indicator
  @indicator
end

#injuriesObject (readonly)

Returns the value of attribute injuries.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def injuries
  @injuries
end

#injury_modeObject (readonly)

Returns the value of attribute injury_mode.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def injury_mode
  @injury_mode
end

#last_pulseObject (readonly)

Returns the value of attribute last_pulse.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def last_pulse
  @last_pulse
end

#last_spiritObject (readonly)

Returns the value of attribute last_spirit.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def last_spirit
  @last_spirit
end

#levelObject (readonly)

Returns the value of attribute level.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def level
  @level
end

#manaObject (readonly)

Returns the value of attribute mana.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def mana
  @mana
end

#max_concentrationObject (readonly)

Returns the value of attribute max_concentration.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def max_concentration
  @max_concentration
end

#max_healthObject (readonly)

Returns the value of attribute max_health.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def max_health
  @max_health
end

#max_manaObject (readonly)

Returns the value of attribute max_mana.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def max_mana
  @max_mana
end

#max_spiritObject (readonly)

Returns the value of attribute max_spirit.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def max_spirit
  @max_spirit
end

#max_staminaObject (readonly)

Returns the value of attribute max_stamina.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def max_stamina
  @max_stamina
end

#mind_textObject (readonly)

Returns the value of attribute mind_text.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def mind_text
  @mind_text
end

#mind_valueObject (readonly)

Returns the value of attribute mind_value.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def mind_value
  @mind_value
end

#nameObject (readonly)

Returns the value of attribute name.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def name
  @name
end

#next_level_textObject (readonly)

Returns the value of attribute next_level_text.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def next_level_text
  @next_level_text
end

#next_level_valueObject (readonly)

Returns the value of attribute next_level_value.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def next_level_value
  @next_level_value
end

#player_idObject (readonly)

Returns the value of attribute player_id.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def player_id
  @player_id
end

#prepared_spellObject (readonly)

Returns the value of attribute prepared_spell.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def prepared_spell
  @prepared_spell
end

#previous_nav_rmObject (readonly)

Returns the value of attribute previous_nav_rm.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def previous_nav_rm
  @previous_nav_rm
end

#promptObject (readonly)

Returns the value of attribute prompt.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def prompt
  @prompt
end

#room_countObject (readonly)

Returns the value of attribute room_count.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def room_count
  @room_count
end

#room_descriptionObject (readonly)

Returns the value of attribute room_description.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def room_description
  @room_description
end

#room_exitsObject (readonly)

Returns the value of attribute room_exits.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def room_exits
  @room_exits
end

#room_exits_stringObject (readonly)

Returns the value of attribute room_exits_string.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def room_exits_string
  @room_exits_string
end

#room_idObject (readonly)

Returns the value of attribute room_id.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def room_id
  @room_id
end

#room_nameObject (readonly)

Returns the value of attribute room_name.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def room_name
  @room_name
end

#room_player_hiddenObject (readonly)

Returns the value of attribute room_player_hidden.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def room_player_hidden
  @room_player_hidden
end

#room_titleObject (readonly)

Returns the value of attribute room_title.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def room_title
  @room_title
end

#room_window_disabledObject (readonly)

Returns the value of attribute room_window_disabled.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def room_window_disabled
  @room_window_disabled
end

#roundtime_endObject (readonly)

Returns the value of attribute roundtime_end.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def roundtime_end
  @roundtime_end
end

#send_fake_tagsObject

Returns the value of attribute send_fake_tags.



53
54
55
# File 'documented/common/xmlparser.rb', line 53

def send_fake_tags
  @send_fake_tags
end

#server_timeObject (readonly)

Returns the value of attribute server_time.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def server_time
  @server_time
end

#server_time_offsetObject (readonly)

Returns the value of attribute server_time_offset.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def server_time_offset
  @server_time_offset
end

#society_taskObject (readonly)

Returns the value of attribute society_task.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def society_task
  @society_task
end

#spiritObject (readonly)

Returns the value of attribute spirit.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def spirit
  @spirit
end

#staminaObject (readonly)

Returns the value of attribute stamina.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def stamina
  @stamina
end

#stance_textObject (readonly)

Returns the value of attribute stance_text.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def stance_text
  @stance_text
end

#stance_valueObject (readonly)

Returns the value of attribute stance_value.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def stance_value
  @stance_value
end

#stow_container_idObject (readonly)

Returns the value of attribute stow_container_id.



41
42
43
# File 'documented/common/xmlparser.rb', line 41

def stow_container_id
  @stow_container_id
end

Instance Method Details

#active_spellsHash

for backwards compatibility Retrieves the currently active spells.

Examples:

spells = parser.active_spells

Returns:

  • (Hash)

    A hash of active spells with their durations.



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'documented/common/xmlparser.rb', line 165

def active_spells
  z = {}
  XMLData.dialogs.sort.each do |a, b|
    b.each do |k, v|
      case a
      when /Active Spells|Buffs/
        z.merge!(k => v) if k.instance_of?(String)
      when /Cooldowns/
        if k.to_s =~ /Recovery/
          z.merge!(k => v) if k.instance_of?(String)
        else
          z.merge!("#{k} Cooldown" => v) if k.instance_of?(String)
        end
      when /Debuffs/

        # need to deal with that pesky 'Silenced' versus 'Silence' from XML
        if k == "Silenced"
          k = 'Silence'
        end
        z.merge!(k => v) if k.instance_of?(String)
      end
    end
  end
  z
end

#make_scar_gslString

Generates a binary string representation of scars.

Returns:

  • (String)

    A binary string representing the scar state.



219
220
221
# File 'documented/common/xmlparser.rb', line 219

def make_scar_gsl
  @scar_gsl = sprintf("0b0%02b%02b%02b%02b%02b%02b%02b%02b%02b%02b%02b%02b%02b%02b", @injuries['nsys']['scar'], @injuries['leftEye']['scar'], @injuries['rightEye']['scar'], @injuries['back']['scar'], @injuries['abdomen']['scar'], @injuries['chest']['scar'], @injuries['leftHand']['scar'], @injuries['rightHand']['scar'], @injuries['leftLeg']['scar'], @injuries['rightLeg']['scar'], @injuries['leftArm']['scar'], @injuries['rightArm']['scar'], @injuries['neck']['scar'], @injuries['head']['scar'])
end

#make_wound_gslString

Generates a binary string representation of wounds.

Returns:

  • (String)

    A binary string representing the wound state.



213
214
215
# File 'documented/common/xmlparser.rb', line 213

def make_wound_gsl
  @wound_gsl = sprintf("0b0%02b%02b%02b%02b%02b%02b%02b%02b%02b%02b%02b%02b%02b%02b", @injuries['nsys']['wound'], @injuries['leftEye']['wound'], @injuries['rightEye']['wound'], @injuries['back']['wound'], @injuries['abdomen']['wound'], @injuries['chest']['wound'], @injuries['leftHand']['wound'], @injuries['rightHand']['wound'], @injuries['leftLeg']['wound'], @injuries['rightLeg']['wound'], @injuries['leftArm']['wound'], @injuries['rightArm']['wound'], @injuries['neck']['wound'], @injuries['head']['wound'])
end

#parse_psm3_progressbar(kind, attributes) ⇒ void

This method returns an undefined value.

Parses progress bar data from the XML stream.

Examples:

parser.parse_psm3_progressbar("Buffs", {"id" => "1", "text" => "Buff Name", "time" => "10:00"})

Parameters:

  • kind (String)

    The type of progress bar.

  • attributes (Hash)

    The attributes of the progress bar.



252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'documented/common/xmlparser.rb', line 252

def parse_psm3_progressbar(kind, attributes)
  @dialogs[kind] ||= {}
  id = attributes["id"].to_i
  name = attributes["text"]
  value = attributes["time"]
  return unless name && value
  # set the expiry for a decade for infinite duration effects
  return @dialogs[kind][name] = @dialogs[kind][id] = Time.now + DECADE if value.downcase.eql?("indefinite")

  # in psm 3.0 progress bars now have second precision!
  hour, minute, second = value.split(':')
  @dialogs[kind][name] = @dialogs[kind][id] = Time.now + (hour.to_i * 3600) + (minute.to_i * 60) + second.to_i
end

#resetvoid

This method returns an undefined value.

Resets the parser’s state. Clears all active tags and resets the current stream.



194
195
196
197
198
199
# File 'documented/common/xmlparser.rb', line 194

def reset
  @active_tags = Array.new
  @active_ids = Array.new
  @current_stream = String.new
  @current_style = String.new
end

#safe_to_respond?Boolean

Checks if the parser is in a safe state to respond to input.

Returns:

  • (Boolean)

    True if safe to respond, false otherwise.



203
204
205
206
207
208
209
# File 'documented/common/xmlparser.rb', line 203

def safe_to_respond?
  if @game =~ /^DR/
    !in_stream && !@bold && (!@current_style || @current_style.empty?)
  else
    return true
  end
end

#spellfrontObject

here for backwards compatibility, but spellfront xml isn’t sent by the game anymore



987
988
989
990
991
992
993
994
995
996
# File 'documented/common/xmlparser.rb', line 987

def spellfront
  if (Time.now.to_i - @@warned_deprecated_spellfront) > 300
    @@warned_deprecated_spellfront = Time.now.to_i
    unless (script_name = Script.current.name)
      script_name = 'unknown script'
    end
    respond "--- warning: #{script_name} is using deprecated method XMLData.spellfront; this method will be removed in a future version of Lich"
  end
  @active_spells.keys
end

#tag_end(name) ⇒ void

This method returns an undefined value.

Handles the end of an XML tag.

Parameters:

  • name (String)

    The name of the tag that is ending.

Raises:

  • (StandardError)

    If an error occurs during processing.



924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
# File 'documented/common/xmlparser.rb', line 924

def tag_end(name)
  # This is called once per element by REXML in games.rb
  # https://ruby-doc.org/stdlib-2.6.1/libdoc/rexml/rdoc/REXML/StreamListener.html

  begin
    if @game =~ /^DR/
      if name == 'compass' and $nav_seen
        $nav_seen = false
        @second_compass = true
      end
      if name == 'compass' and @second_compass
        @second_compass = false
        @room_count += 1
        $room_count += 1
      end
    end

    if name == 'inv'
      if @obj_exist == @obj_location
        if @obj_after_name == 'is closed.'
          GameObj.delete_container(@stow_container_id)
        end
      elsif @obj_exist
        GameObj.new_inv(@obj_exist, @obj_noun, @obj_name, @obj_location, @obj_before_name, @obj_after_name)
      end
    elsif @send_fake_tags and (@active_ids.last == 'room exits')
      gsl_exits = String.new
      @room_exits.each { |exit| gsl_exits.concat(DIRMAP[SHORTDIR[exit]].to_s) }
      $_CLIENT_.puts "\034GSj#{sprintf('%-20s', gsl_exits)}\r\n"
      gsl_exits = nil
    elsif @room_window_disabled and (name == 'compass')
      if defined?(Lich::Claim) && Lich::Claim::Lock.owned?
        if @room_id == 0
          @room_id = Digest::MD5.hexdigest([@room_title, @room_description, @room_exits_string].to_s).to_i(16)
        end
        if @room_player_hidden
          @arrival_pcs.push(:hidden)
          @room_player_hidden = false
        end
        @check_obvious_hiding = false
        Lich::Claim.parser_handle(@room_id, @arrival_pcs)
        Lich::Claim.unlock
      end
      @room_description = @room_description.strip
      @room_exits_string.concat " #{@room_exits.join(', ')}" unless @room_exits.empty?
      gsl_exits = String.new
      @room_exits.each { |exit| gsl_exits.concat(DIRMAP[SHORTDIR[exit]].to_s) }
      $_CLIENT_.puts "\034GSj#{sprintf('%-20s', gsl_exits)}\r\n"
      gsl_exits = nil
      @room_count += 1
      $room_count += 1
    end
    @last_tag = @active_tags.pop
    @last_id = @active_ids.pop
  rescue
    $stdout.puts "--- error: XMLParser.tag_end: #{$!}"
    Lich.log "error: XMLParser.tag_end: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
    sleep 0.1
    reset
  end
end

#tag_start(name, attributes) ⇒ void

This method returns an undefined value.

Handles the start of an XML tag.

Parameters:

  • name (String)

    The name of the tag.

  • attributes (Hash)

    The attributes of the tag.

Raises:

  • (StandardError)

    If an error occurs during processing.



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
# File 'documented/common/xmlparser.rb', line 273

def tag_start(name, attributes)
  # This is called once per element by REXML in games.rb
  # https://ruby-doc.org/stdlib-2.6.1/libdoc/rexml/rdoc/REXML/StreamListener.html
  begin
    @active_tags.push(name)
    @active_ids.push(attributes['id'].to_s)

    if name == 'nav'
      Lich::Claim.lock if defined?(Lich::Claim)
      GameObj.clear_loot
      GameObj.clear_npcs
      GameObj.clear_pcs
      GameObj.clear_room_desc
      @check_obvious_hiding = true
      unless XMLData.game =~ /^DR/
        @previous_nav_rm = @room_id
        @room_id = attributes['rm'].to_i
      end
      @arrival_pcs = []
      $nav_seen = true
    end

    if name == 'compass'
      if defined?(Lich::Claim) && Lich::Claim::Lock.owned?
        if @room_id == 0
          @room_id = Digest::MD5.hexdigest([@room_title, @room_description, @room_exits_string].to_s).to_i(16)
        end
        if @room_player_hidden
          @arrival_pcs.push(:hidden)
          @room_player_hidden = false
        end
        @check_obvious_hiding = false
        Lich::Claim.parser_handle(@room_id, @arrival_pcs)
        Lich::Claim.unlock
      end
      if @current_stream == 'familiar'
        @fam_mode = String.new
      elsif @room_window_disabled
        @room_exits = Array.new
      end
    end

    if (name == 'compDef') or (name == 'component')
      if attributes['id'] == 'room objs'
        GameObj.clear_loot
        GameObj.clear_npcs
      elsif attributes['id'] == 'room players'
        GameObj.clear_pcs
      elsif attributes['id'] == 'room exits'
        @room_exits = Array.new
        @room_exits_string = String.new
      elsif attributes['id'] == 'room desc'
        @room_description = String.new
        GameObj.clear_room_desc
      end
    end

    if name =~ /^(?:a|right|left)$/
      @obj_exist = attributes['exist']
      @obj_noun = attributes['noun']
    end
    if name == 'inv'
      if attributes['id'] == 'stow'
        @obj_location = @stow_container_id
      else
        @obj_location = attributes['id']
      end
      @obj_exist = nil
      @obj_noun = nil
      @obj_name = nil
      @obj_before_name = nil
      @obj_after_name = nil
    end
    if name == 'dialogData' and attributes['clear'] == 't' and PSM_3_DIALOG_IDS.include?(attributes["id"])
      @dialogs[attributes["id"]] ||= {}
      @dialogs[attributes["id"]].clear
      # detect a clear board request for effects, and send to activespell
      ActiveSpell.request_update
    end
    if name == 'resource'
      # rubocop:disable Lint/Void
      nil
      # rubocop:enable Lint/Void
    end
    if name == 'pushStream'
      @in_stream = true
      @current_stream = attributes['id'].to_s
      GameObj.clear_inv if attributes['id'].to_s == 'inv'
    end
    if name == 'popStream'
      if attributes['id'] == 'room'
        unless @room_window_disabled
          @room_count += 1
          $room_count += 1
        end
      end
      @in_stream = false
      if attributes['id'] == 'bounty'
        @bounty_task.strip!
      end
      @current_stream = String.new
    end
    if name == 'pushBold'
      @bold = true
    end
    if name == 'popBold'
      @bold = false
    end
    if (name == 'streamWindow')
      if (attributes['id'] == 'main') and attributes['subtitle']
        unless attributes['subtitle'].empty? || attributes['subtitle'].nil?
          if XMLData.game =~ /^GS/
            if Lich.display_uid == false && attributes['subtitle'][3..-1] =~ / - \d+$/
              Lich.display_uid = true
            end
            @room_title = '[' + attributes['subtitle'][3..-1].gsub(/ - \d+$/, '') + ']'
          elsif XMLData.game =~ /^DR/
            # - [Bosque Deriel, Hermit's Shacks] (230008)
            room = attributes['subtitle'].match(/(?<roomtitle>\[.*?\])(?:\s\((?<uid>\d+)\))?/)
            @room_title = "[#{room[:roomtitle]}]"
            @room_id = room[:uid].to_i
          else
            @room_title = String.new
          end
        end
      end
    end
    if name == 'style'
      @current_style = attributes['id']
    end
    if (name == 'clearStream' && attributes['id'] == 'percWindow')
      @dr_active_spells_clear = true
    end

    if (name == 'pushStream' && attributes['id'] == 'percWindow')
      @dr_active_spell_tracking = true
      @dr_active_spells_clear = false
    end

    if name == 'prompt'
      @server_time = attributes['time'].to_i
      @server_time_offset = (Time.now.to_i - @server_time)
      $_CLIENT_.puts "\034GSq#{sprintf('%010d', @server_time)}\r\n" if @send_fake_tags

      if @dr_active_spell_tracking
        @dr_active_spell_tracking = false
        @dr_active_spells_slivers = false
        @dr_active_spells = @dr_active_spells_tmp
        @dr_active_spells_tmp = {}
      elsif @dr_active_spells_clear
        @dr_active_spells = {}
      end
    end

    if name == 'clearContainer'
      if attributes['id'] == 'stow'
        GameObj.clear_container(@stow_container_id)
      else
        GameObj.clear_container(attributes['id'])
      end
    end
    if name == 'deleteContainer'
      GameObj.delete_container(attributes['id'])
    end
    if name == 'progressBar'
      if attributes['id'] == 'pbarStance'
        @stance_text = attributes['text'].split.first
        @stance_value = attributes['value'].to_i
        $_CLIENT_.puts "\034GSg#{sprintf('%010d', @stance_value)}\r\n" if @send_fake_tags
      elsif attributes['id'] == 'mana'
        last_mana = @mana
        @mana, @max_mana = attributes['text'].scan(/-?\d+/).collect { |num| num.to_i }
        difference = @mana - last_mana
        # fixme: enhancives screw this up
        unless XMLData.name.empty?
          if (difference == noded_pulse) or (difference == unnoded_pulse) or ((@mana == @max_mana) and (last_mana + noded_pulse > @max_mana))
            @last_pulse = Time.now.to_i
            if @send_fake_tags
              $_CLIENT_.puts "\034GSZ#{sprintf('%010d', (@mana + 1))}\n"
              $_CLIENT_.puts "\034GSZ#{sprintf('%010d', @mana)}\n"
            end
          end
        end
        if @send_fake_tags
          $_CLIENT_.puts "\034GSV#{sprintf('%010d%010d%010d%010d%010d%010d%010d%010d', @max_health.to_i, @health.to_i, @max_spirit.to_i, @spirit.to_i, @max_mana.to_i, @mana.to_i, @wound_gsl, @scar_gsl)}\r\n"
        end
      elsif attributes['id'] == 'stamina'
        @stamina, @max_stamina = attributes['text'].scan(/-?\d+/).collect { |num| num.to_i }
      elsif attributes['id'] == 'mindState'
        @mind_text = attributes['text']
        @mind_value = attributes['value'].to_i
        $_CLIENT_.puts "\034GSr#{MINDMAP[@mind_text]}\r\n" if @send_fake_tags
      elsif attributes['id'] == 'health'
        @health, @max_health = attributes['text'].scan(/-?\d+/).collect { |num| num.to_i }
        $_CLIENT_.puts "\034GSV#{sprintf('%010d%010d%010d%010d%010d%010d%010d%010d', @max_health.to_i, @health.to_i, @max_spirit.to_i, @spirit.to_i, @max_mana.to_i, @mana.to_i, @wound_gsl, @scar_gsl)}\r\n" if @send_fake_tags
      elsif attributes['id'] == 'spirit'
        @last_spirit = @spirit if @last_spirit
        @spirit, @max_spirit = attributes['text'].scan(/-?\d+/).collect { |num| num.to_i }
        @last_spirit = @spirit unless @last_spirit
        $_CLIENT_.puts "\034GSV#{sprintf('%010d%010d%010d%010d%010d%010d%010d%010d', @max_health.to_i, @health.to_i, @max_spirit.to_i, @spirit.to_i, @max_mana.to_i, @mana.to_i, @wound_gsl, @scar_gsl)}\r\n" if @send_fake_tags
      elsif attributes['id'] == 'nextLvlPB'
        Gift.pulse unless @next_level_text == attributes['text']
        @next_level_value = attributes['value'].to_i
        @next_level_text = attributes['text']
      elsif attributes['id'] == 'encumlevel'
        @encumbrance_value = attributes['value'].to_i
        @encumbrance_text = attributes['text']
      elsif attributes['id'] == 'concentration'
        @concentration, @max_concentration = attributes['text'].scan(/-?\d+/).collect { |num| num.to_i }
      elsif PSM_3_DIALOG_IDS.include?(@active_ids[-2])
        # puts "kind=(%s) name=%s attributes=%s" % [@active_ids[-2], name, attributes]
        self.parse_psm3_progressbar(@active_ids[-2], attributes)
        # since we received an updated spell duration, let's signal infomon to update
        ActiveSpell.request_update
      end
    end
    if name == 'roundTime'
      @roundtime_end = attributes['value'].to_i
      $_CLIENT_.puts "\034GSQ#{sprintf('%010d', @roundtime_end)}\r\n" if @send_fake_tags
    end
    if name == 'castTime'
      @cast_roundtime_end = attributes['value'].to_i
    end
    if name == 'dropDownBox'
      if attributes['id'] == 'dDBTarget'
        @current_target_ids.clear
        attributes['content_value'].split(',').each { |t|
          if t =~ /^\#(\-?\d+)(?:,|$)/
            @current_target_ids.push($1)
          end
        }
        if attributes['content_value'] =~ /^\#(\-?\d+)(?:,|$)/
          @current_target_id = $1
        else
          @current_target_id = nil
        end
      end
    end
    if name == 'indicator'
      @indicator[attributes['id']] = attributes['visible']
      if @send_fake_tags
        if attributes['id'] == 'IconPOISONED'
          if attributes['visible'] == 'y'
            $_CLIENT_.puts "\034GSJ0000000000000000000100000000001\r\n"
          else
            $_CLIENT_.puts "\034GSJ0000000000000000000000000000000\r\n"
          end
        elsif attributes['id'] == 'IconDISEASED'
          if attributes['visible'] == 'y'
            $_CLIENT_.puts "\034GSK0000000000000000000100000000001\r\n"
          else
            $_CLIENT_.puts "\034GSK0000000000000000000000000000000\r\n"
          end
        else
          gsl_prompt = String.new; ICONMAP.keys.each { |icon| gsl_prompt += ICONMAP[icon] if @indicator[icon] == 'y' }
          $_CLIENT_.puts "\034GSP#{sprintf('%-30s', gsl_prompt)}\r\n"
        end
      end
    end
    if (name == 'image') and @active_ids.include?('injuries')
      if @injuries.keys.include?(attributes['id'])
        if attributes['name'] =~ /Injury/i
          @injuries[attributes['id']]['wound'] = attributes['name'].slice(/\d/).to_i
        elsif attributes['name'] =~ /Scar/i
          @injuries[attributes['id']]['wound'] = 0
          @injuries[attributes['id']]['scar'] = attributes['name'].slice(/\d/).to_i
        elsif attributes['name'] =~ /Nsys/i
          rank = attributes['name'].slice(/\d/).to_i
          if rank == 0
            @injuries['nsys']['wound'] = 0
            @injuries['nsys']['scar'] = 0
          else
            Thread.new {
              wait_while { dead? }
              action = proc { |server_string|
                if (@nerve_tracker_active == 'maybe')
                  if @nerve_tracker_active == 'maybe'
                    if server_string =~ /^You/
                      @nerve_tracker_active = 'yes'
                      @injuries['nsys']['wound'] = 0
                      @injuries['nsys']['scar'] = 0
                    else
                      @nerve_tracker_active = 'no'
                    end
                  end
                end
                if @nerve_tracker_active == 'yes'
                  if server_string =~ /<output class=['"]['"]\/>/
                    @nerve_tracker_active = 'no'
                    @nerve_tracker_num -= 1
                    DownstreamHook.remove('nerve_tracker') if @nerve_tracker_num < 1
                    $_CLIENT_.puts "\034GSV#{sprintf('%010d%010d%010d%010d%010d%010d%010d%010d', @max_health.to_i, @health.to_i, @max_spirit.to_i, @spirit.to_i, @max_mana.to_i, @mana.to_i, make_wound_gsl, make_scar_gsl)}\r\n" if @send_fake_tags
                    server_string
                  elsif server_string =~ /a case of uncontrollable convulsions/
                    @injuries['nsys']['wound'] = 3
                    nil
                  elsif server_string =~ /a case of sporadic convulsions/
                    @injuries['nsys']['wound'] = 2
                    nil
                  elsif server_string =~ /a strange case of muscle twitching/
                    @injuries['nsys']['wound'] = 1
                    nil
                  elsif server_string =~ /a very difficult time with muscle control/
                    @injuries['nsys']['scar'] = 3
                    nil
                  elsif server_string =~ /constant muscle spasms/
                    @injuries['nsys']['scar'] = 2
                    nil
                  elsif server_string =~ /developed slurred speech/
                    @injuries['nsys']['scar'] = 1
                    nil
                  end
                else
                  if server_string =~ /<output class=['"]mono['"]\/>/
                    @nerve_tracker_active = 'maybe'
                  end
                  server_string
                end
              }
              @nerve_tracker_num += 1
              DownstreamHook.add('nerve_tracker', action)
              Game._puts "#{$cmd_prefix}health"
            }
          end
        else
          @injuries[attributes['id']]['wound'] = 0
          @injuries[attributes['id']]['scar'] = 0
        end
      end
      $_CLIENT_.puts "\034GSV#{sprintf('%010d%010d%010d%010d%010d%010d%010d%010d', @max_health.to_i, @health.to_i, @max_spirit.to_i, @spirit.to_i, @max_mana.to_i, @mana.to_i, make_wound_gsl, make_scar_gsl)}\r\n" if @send_fake_tags
    end
    if @room_window_disabled and (name == 'dir') and @active_tags.include?('compass')
      @room_exits.push(LONGDIR[attributes['value']])
    end
    if name == 'radio'
      if attributes['id'] == 'injrRad'
        @injury_mode = 0 if attributes['value'] == '1'
      elsif attributes['id'] == 'scarRad'
        @injury_mode = 1 if attributes['value'] == '1'
      elsif attributes['id'] == 'bothRad'
        @injury_mode = 2 if attributes['value'] == '1'
      end
    end
    if name == 'label'
      if attributes['id'] == 'yourLvl'
        @level = attributes['value'].slice(/\d+/).to_i
      elsif attributes['id'] == 'encumblurb'
        @encumbrance_full_text = attributes['value']
      end
    end
    if (name == 'container') and (attributes['id'] == 'stow')
      @stow_container_id = attributes['target'].sub('#', '')
    end
    if (name == 'clearStream')
      if attributes['id'] == 'bounty'
        @bounty_task = String.new
      end
    end
    if (name == 'playerID')
      @player_id = attributes['id']
      unless $frontend =~ /^(?:wizard|avalon)$/
        if Lich.inventory_boxes(@player_id)
          DownstreamHook.remove('inventory_boxes_off')
        end
      end
    end
    if name == 'settingsInfo'
      if (game = attributes['instance'])
        if game == 'GS4'
          @game = 'GSIV'
        elsif (game == 'GSX') or (game == 'GS4X')
          @game = 'GSPlat'
        else
          @game = game # covers DR, DRT, DRF, GST, GSF
        end
      end
    end
    if (name == 'app') and (@name = attributes['char'])
      if @game.nil? or @game.empty?
        @game = 'unknown'
      end
      unless File.exist?("#{DATA_DIR}/#{@game}")
        Dir.mkdir("#{DATA_DIR}/#{@game}")
      end
      unless File.exist?("#{DATA_DIR}/#{@game}/#{@name}")
        Dir.mkdir("#{DATA_DIR}/#{@game}/#{@name}")
      end
      if $frontend =~ /^(?:wizard|avalon)$/
        Game._puts "#{$cmd_prefix}_flag Display Dialog Boxes 0"
        sleep 0.05
        Game._puts "#{$cmd_prefix}_injury 2"
        sleep 0.05
        # fixme: game name hardcoded as Gemstone IV; maybe doesn't make any difference to the client
        $_CLIENT_.puts "\034GSB0000000000#{attributes['char']}\r\n\034GSA#{Time.now.to_i}GemStone IV\034GSD\r\n"
        # Sending fake GSL tags to the Wizard FE is disabled until now, because it doesn't accept the tags and just gives errors until initialized with the above line
        @send_fake_tags = true
        # Send all the tags we missed out on
        $_CLIENT_.puts "\034GSV#{sprintf('%010d%010d%010d%010d%010d%010d%010d%010d', @max_health.to_i, @health.to_i, @max_spirit.to_i, @spirit.to_i, @max_mana.to_i, @mana.to_i, make_wound_gsl, make_scar_gsl)}\r\n"
        $_CLIENT_.puts "\034GSg#{sprintf('%010d', @stance_value)}\r\n"
        $_CLIENT_.puts "\034GSr#{MINDMAP[@mind_text]}\r\n"
        gsl_prompt = String.new
        @indicator.keys.each { |icon| gsl_prompt += ICONMAP[icon] if @indicator[icon] == 'y' }
        $_CLIENT_.puts "\034GSP#{sprintf('%-30s', gsl_prompt)}\r\n"
        gsl_prompt = nil
        gsl_exits = String.new
        @room_exits.each { |exit| gsl_exits.concat(DIRMAP[SHORTDIR[exit]].to_s) }
        $_CLIENT_.puts "\034GSj#{sprintf('%-20s', gsl_exits)}\r\n"
        gsl_exits = nil
        $_CLIENT_.puts "\034GSn#{sprintf('%-14s', @prepared_spell)}\r\n"
        $_CLIENT_.puts "\034GSm#{sprintf('%-45s', GameObj.right_hand.name)}\r\n"
        $_CLIENT_.puts "\034GSl#{sprintf('%-45s', GameObj.left_hand.name)}\r\n"
        $_CLIENT_.puts "\034GSq#{sprintf('%010d', @server_time)}\r\n"
        $_CLIENT_.puts "\034GSQ#{sprintf('%010d', @roundtime_end)}\r\n" if @roundtime_end > 0
      end
      Game._puts("#{$cmd_prefix}_flag Display Inventory Boxes 1")
    end
  rescue
    $stdout.puts "--- error: XMLParser.tag_start: #{$!}"
    Lich.log "error: XMLParser.tag_start: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
    sleep 0.1
    reset
  end
end

#text(text_string) ⇒ void

Note:

This method is called once per element with text in it.

This method returns an undefined value.

Processes text content within an XML tag.

Parameters:

  • text_string (String)

    The text content to process.



701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
# File 'documented/common/xmlparser.rb', line 701

def text(text_string)
  # This is called once per element with text in it by REXML in games.rb
  # https://ruby-doc.org/stdlib-2.6.1/libdoc/rexml/rdoc/REXML/StreamListener.html
  begin
    # fixme: /<stream id="Spells">.*?<\/stream>/m
    # $_CLIENT_.write(text_string) unless ($frontend != 'suks') or (@current_stream =~ /^(?:spellfront|inv|bounty|society)$/) or @active_tags.any? { |tag| tag =~ /^(?:compDef|inv|component|right|left|spell)$/ } or (@active_tags.include?('stream') and @active_ids.include?('Spells')) or (text_string == "\n" and (@last_tag =~ /^(?:popStream|prompt|compDef|dialogData|openDialog|switchQuickBar|component)$/))

    # DR Active Spell tracking and handling
    if @dr_active_spell_tracking
      spell = nil
      duration = nil
      case text_string
      when /(?<spell>^[^\(]+)\((?<duration>\d+|Indefinite|OM|Fading)\s*(?:%|roisae?n)?\)/i
        # Spell with known duration remaining
        # XML looks like:
        # Hydra Hex  (Indefinite)
        # Persistence of Mana  (OM)
        # Cure Disease  (Fading)
        # Osrel Meraud  (94%)
        # Landslide (4 roisaen)
        # Khri Sagacity  (1 roisan)
        spell = Regexp.last_match[:spell]
        duration = Regexp.last_match[:duration]

        if duration.match?(/Indefinite|OM/)
          duration = 1000
        elsif duration.match?(/Fading/)
          duration = 0
        else
          duration = duration.to_i
        end
      when /(?<spell>Stellar Collector)\s+\((?<percentage>\d+)%,\s*(?<duration>\d+)?\s*(?<unit>(?:roisae?n|anlaen|fading))/
        # Stellar collector special case
        # XML looks like:
        # Stellar Collector  (0%, 4 anlaen)
        # Stellar Collector  (0%, fading)
        spell = Regexp.last_match[:spell]
        duration = Regexp.last_match[:duration].to_i
        @dr_active_spells_stellar_percentage = Regexp.last_match[:percentage].to_i
        unit = Regexp.last_match[:unit]
        duration = unit == 'anlaen' ? duration * 30 : duration
      when /(?<spell>^[^\(]+)\(.+\)/i
        # Spells with inexact duration verbiage, such as with
        # Barbarians without knowledge of Power Monger mastery
        spell = Regexp.last_match[:spell]
        duration = 1000
      when /.*orbiting sliver.*/i
        # Moon Mage slivers
        @dr_active_spells_slivers = true
      end
      spell.strip!
      if spell
        @dr_active_spells_tmp[spell] = duration
      end
    end

    if @current_style == 'roomName'
      @room_name = text_string.match(/(?<roomname>\[.*?\])/)[:roomname]
    end

    if @active_tags.include?('inv')
      if @active_tags[-1] == 'a'
        @obj_name = text_string
      elsif @obj_name.nil?
        @obj_before_name = text_string.strip
      else
        @obj_after_name = text_string.strip
      end
    elsif @active_tags.last == 'prompt'
      @prompt = text_string
    elsif @active_tags.include?('right')
      GameObj.new_right_hand(@obj_exist, @obj_noun, text_string)
      $_CLIENT_.puts "\034GSm#{sprintf('%-45s', text_string)}\r\n" if @send_fake_tags
    elsif @active_tags.include?('left')
      GameObj.new_left_hand(@obj_exist, @obj_noun, text_string)
      $_CLIENT_.puts "\034GSl#{sprintf('%-45s', text_string)}\r\n" if @send_fake_tags
    elsif @active_tags.include?('spell')
      @prepared_spell = text_string
      $_CLIENT_.puts "\034GSn#{sprintf('%-14s', text_string)}\r\n" if @send_fake_tags
    elsif @active_tags.include?('compDef') or @active_tags.include?('component')
      if @active_ids.include?('room objs')
        if @active_tags.include?('a')
          if @bold
            GameObj.new_npc(@obj_exist, @obj_noun, text_string)
          else
            GameObj.new_loot(@obj_exist, @obj_noun, text_string)
          end
        elsif (text_string =~ /that (?:is|appears) ([\w\s]+)(?:,| and|\.)/) or (text_string =~ / \(([^\(]+)\)/)
          GameObj.npcs[-1].status = $1
        end
      elsif @active_ids.include?('room players')
        if @active_tags.include?('a')
          @pc = GameObj.new_pc(@obj_exist, @obj_noun, "#{@player_title}#{text_string}", @player_status)
          @player_status = nil
          @arrival_pcs.push(@pc.noun) if (defined?(Lich::Claim) && Lich::Claim::Lock.owned?)
        else
          if @game =~ /^DR/
            GameObj.clear_pcs
            text_string.sub(/^Also here\: /, '').sub(/ and ([^,]+)\./) { ", #{$1}" }.split(', ').each { |player|
              if player =~ / who is (.+)/
                status = $1
                player.sub!(/ who is .+/, '')
              elsif player =~ / \((.+)\)/
                status = $1
                player.sub!(/ \(.+\)/, '')
              else
                status = nil
              end
              noun = player.slice(/\b[A-Z][a-z]+$/)
              if player =~ /the body of /
                player.sub!('the body of ', '')
                if status
                  status.concat ' dead'
                else
                  status = 'dead'
                end
              end
              if player =~ /a stunned /
                player.sub!('a stunned ', '')
                if status
                  status.concat ' stunned'
                else
                  status = 'stunned'
                end
              end
              GameObj.new_pc(nil, noun, player, status)
            }
          else
            if (text_string =~ /^ who (?:is|appears) ([\w\s]+)(?:,| and|\.|$)/) or (text_string =~ / \(([\w\s]+)\)(?: \(([\w\s]+)\))?/)
              if @pc.status
                @pc.status.concat " #{$1}"
              else
                @pc.status = $1
              end
              @pc.status.concat " #{$2}" if $2
            end
            if text_string =~ /(?:^Also here: |, )(?:a )?([a-z\s]+)?([\w\s\-!\?',]+)?$/
              @player_status = ($1.strip.gsub('the body of', 'dead')) if $1
              @player_title = $2
            end
          end
        end
      elsif @active_ids.include?('room desc')
        if text_string == '[Room window disabled at this location.]'
          @room_window_disabled = true
        else
          @room_window_disabled = false
          @room_description.concat(text_string)
          if @active_tags.include?('a')
            GameObj.new_room_desc(@obj_exist, @obj_noun, text_string)
          end
        end
      elsif @active_ids.include?('room exits')
        @room_exits_string.concat(text_string)
        @room_exits.push(text_string) if @active_tags.include?('d')
      end
    elsif @current_stream == 'bounty'
      @bounty_task += text_string
    elsif @current_stream == 'society'
      @society_task = text_string
    elsif (@current_stream == 'inv') and @active_tags.include?('a')
      GameObj.new_inv(@obj_exist, @obj_noun, text_string, nil)
    elsif @check_obvious_hiding && text_string =~ /obvious signs of someone hiding/
      @room_player_hidden = true
    elsif @current_stream == 'familiar'
      # fixme: familiar room tracking does not (can not?) auto update, status of pcs and npcs isn't tracked at all, titles of pcs aren't tracked
      if @current_style == 'roomName'
        @familiar_room_title = text_string
        @familiar_room_description = String.new
        @familiar_room_exits = Array.new
        GameObj.clear_fam_room_desc
        GameObj.clear_fam_loot
        GameObj.clear_fam_npcs
        GameObj.clear_fam_pcs
        @fam_mode = String.new
      elsif @current_style == 'roomDesc'
        @familiar_room_description.concat(text_string)
        if @active_tags.include?('a')
          GameObj.new_fam_room_desc(@obj_exist, @obj_noun, text_string)
        end
      elsif text_string =~ /^You also see/
        @fam_mode = 'things'
      elsif text_string =~ /^Also here/
        @fam_mode = 'people'
      elsif text_string =~ /Obvious (?:paths|exits)/
        @fam_mode = 'paths'
      elsif @fam_mode == 'things'
        if @active_tags.include?('a')
          if @bold
            GameObj.new_fam_npc(@obj_exist, @obj_noun, text_string)
          else
            GameObj.new_fam_loot(@obj_exist, @obj_noun, text_string)
          end
        end
        # puts 'things: ' + text_string
      elsif @fam_mode == 'people' and @active_tags.include?('a')
        GameObj.new_fam_pc(@obj_exist, @obj_noun, text_string)
        # puts 'people: ' + text_string
      elsif (@fam_mode == 'paths') and @active_tags.include?('a')
        @familiar_room_exits.push(text_string)
      end
    elsif @room_window_disabled
      if @current_style == 'roomDesc'
        @room_description.concat(text_string)
        if @active_tags.include?('a')
          GameObj.new_room_desc(@obj_exist, @obj_noun, text_string)
        end
      elsif text_string =~ /^Obvious (?:paths|exits): (?:none)?$/
        @room_exits_string = text_string.strip
      end
    end
  rescue
    $stdout.puts "--- error: XMLParser.text: #{$!}"
    Lich.log "error: XMLParser.text: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
    sleep 0.1
    reset
  end
end