Class: Lich::Common::XMLParser
- Inherits:
-
Object
- Object
- Lich::Common::XMLParser
- Includes:
- REXML::StreamListener
- Defined in:
- lib/common/xmlparser.rb
Overview
A class responsible for parsing XML data related to game state and player attributes.
Constant Summary collapse
- DECADE =
def parse(line)
@buffer.concat(line) loop { if (str = @buffer.slice!(/^[^<]+/)) text(str.gsub(/&(lt|gt|quot|apos|amp)/) { @unescape[$1] }) elsif (str = @buffer.slice!(/^<\/[^<]+>/)) element = /^<\/([^\s>\/]+)/.match(str).captures.first tag_end(element) elsif (str = @buffer.slice!(/^<[^<]+>/)) element = /^<([^\s>\/]+)/.match(str).captures.first attributes = Hash.new str.scan(/([A-z][A-z0-9_\-]*)=(["'])(.*?)\2/).each { |attr| attributes[attr[0]] = attr[2] } tag_start(element, attributes) tag_end(element) if str =~ /\/>$/ else break end }
end
10 * 31_536_000
- PSM_3_DIALOG_IDS =
["Buffs", "Active Spells", "Debuffs", "Cooldowns"]
- @@warned_deprecated_spellfront =
0
Instance Attribute Summary collapse
- #arrival_pcs ⇒ Integer, ... readonly
- #bounty_task ⇒ Integer, ... readonly
- #cast_roundtime_end ⇒ Integer, ... readonly
- #concentration ⇒ Integer, ... readonly
- #current_target_id ⇒ Integer, ... readonly
- #current_target_ids ⇒ Integer, ... readonly
- #dialogs ⇒ Integer, ... readonly
- #dr_active_spells ⇒ Integer, ... readonly
- #dr_active_spells_slivers ⇒ Integer, ... readonly
- #dr_active_spells_stellar_percentage ⇒ Integer, ... readonly
- #encumbrance_full_text ⇒ Integer, ... readonly
- #encumbrance_text ⇒ Integer, ... readonly
- #encumbrance_value ⇒ Integer, ... readonly
- #familiar_room_description ⇒ Integer, ... readonly
- #familiar_room_exits ⇒ Integer, ... readonly
- #familiar_room_title ⇒ Integer, ... readonly
- #game ⇒ Integer, ... readonly
- #health ⇒ Integer, ... readonly
- #in_stream ⇒ Integer, ... readonly
- #indicator ⇒ Integer, ... readonly
- #injuries ⇒ Integer, ... readonly
- #injury_mode ⇒ Integer, ... readonly
- #last_pulse ⇒ Integer, ... readonly
- #last_spirit ⇒ Integer, ... readonly
- #level ⇒ Integer, ... readonly
- #mana ⇒ Integer, ... readonly
- #max_concentration ⇒ Integer, ... readonly
- #max_health ⇒ Integer, ... readonly
- #max_mana ⇒ Integer, ... readonly
- #max_spirit ⇒ Integer, ... readonly
- #max_stamina ⇒ Integer, ... readonly
- #mind_text ⇒ Integer, ... readonly
- #mind_value ⇒ Integer, ... readonly
- #name ⇒ Integer, ... readonly
- #next_level_text ⇒ Integer, ... readonly
- #next_level_value ⇒ Integer, ... readonly
- #player_id ⇒ Integer, ... readonly
- #prepared_spell ⇒ Integer, ... readonly
- #previous_nav_rm ⇒ Integer, ... readonly
- #prompt ⇒ Integer, ... readonly
- #room_count ⇒ Integer, ... readonly
- #room_description ⇒ Integer, ... readonly
- #room_exits ⇒ Integer, ... readonly
- #room_exits_string ⇒ Integer, ... readonly
- #room_id ⇒ Integer, ... readonly
- #room_name ⇒ Integer, ... readonly
- #room_player_hidden ⇒ Integer, ... readonly
- #room_title ⇒ Integer, ... readonly
- #room_window_disabled ⇒ Integer, ... readonly
- #roundtime_end ⇒ Integer, ... readonly
-
#send_fake_tags ⇒ Boolean
Whether to send fake tags.
- #server_time ⇒ Integer, ... readonly
- #server_time_offset ⇒ Integer, ... readonly
- #society_task ⇒ Integer, ... readonly
- #spirit ⇒ Integer, ... readonly
- #stamina ⇒ Integer, ... readonly
- #stance_text ⇒ Integer, ... readonly
- #stance_value ⇒ Integer, ... readonly
- #stow_container_id ⇒ Integer, ... readonly
Instance Method Summary collapse
-
#active_spells ⇒ Hash
Retrieves the active spells and their statuses.
-
#initialize ⇒ XMLParser
constructor
Initializes a new instance of XMLParser.
-
#make_scar_gsl ⇒ String
Generates a binary string representation of the player’s scars.
-
#make_wound_gsl ⇒ String
Generates a binary string representation of the player’s wounds.
-
#parse_psm3_progressbar(kind, attributes) ⇒ void
Parses the progress bar data from the PSM3 format.
-
#reset ⇒ void
Resets the parser’s state by clearing active tags and IDs.
-
#safe_to_respond? ⇒ Boolean
Checks if it is safe to respond based on the current game state.
-
#spellfront ⇒ Array
Retrieves the currently active spells.
-
#tag_end(name) ⇒ void
Handles the end of a tag in the XML parsing process.
-
#tag_start(name, attributes) ⇒ void
Handles the start of an XML tag.
-
#text(text_string) ⇒ void
Processes the given text string and updates the game state accordingly.
Constructor Details
#initialize ⇒ XMLParser
This constructor sets up various attributes to their default values.
Initializes a new instance of XMLParser.
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 159 160 161 162 163 164 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 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/common/xmlparser.rb', line 115 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_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_pcs ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def arrival_pcs @arrival_pcs end |
#bounty_task ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def bounty_task @bounty_task end |
#cast_roundtime_end ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def cast_roundtime_end @cast_roundtime_end end |
#concentration ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def concentration @concentration end |
#current_target_id ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def current_target_id @current_target_id end |
#current_target_ids ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def current_target_ids @current_target_ids end |
#dialogs ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def dialogs @dialogs end |
#dr_active_spells ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def dr_active_spells @dr_active_spells end |
#dr_active_spells_slivers ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def dr_active_spells_slivers @dr_active_spells_slivers end |
#dr_active_spells_stellar_percentage ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def dr_active_spells_stellar_percentage @dr_active_spells_stellar_percentage end |
#encumbrance_full_text ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def encumbrance_full_text @encumbrance_full_text end |
#encumbrance_text ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def encumbrance_text @encumbrance_text end |
#encumbrance_value ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def encumbrance_value @encumbrance_value end |
#familiar_room_description ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def familiar_room_description @familiar_room_description end |
#familiar_room_exits ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def familiar_room_exits @familiar_room_exits end |
#familiar_room_title ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def familiar_room_title @familiar_room_title end |
#game ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def game @game end |
#health ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def health @health end |
#in_stream ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def in_stream @in_stream end |
#indicator ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def indicator @indicator end |
#injuries ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def injuries @injuries end |
#injury_mode ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def injury_mode @injury_mode end |
#last_pulse ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def last_pulse @last_pulse end |
#last_spirit ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def last_spirit @last_spirit end |
#level ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def level @level end |
#mana ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def mana @mana end |
#max_concentration ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def max_concentration @max_concentration end |
#max_health ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def max_health @max_health end |
#max_mana ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def max_mana @max_mana end |
#max_spirit ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def max_spirit @max_spirit end |
#max_stamina ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def max_stamina @max_stamina end |
#mind_text ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def mind_text @mind_text end |
#mind_value ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def mind_value @mind_value end |
#name ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def name @name end |
#next_level_text ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def next_level_text @next_level_text end |
#next_level_value ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def next_level_value @next_level_value end |
#player_id ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def player_id @player_id end |
#prepared_spell ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def prepared_spell @prepared_spell end |
#previous_nav_rm ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def previous_nav_rm @previous_nav_rm end |
#prompt ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def prompt @prompt end |
#room_count ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def room_count @room_count end |
#room_description ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def room_description @room_description end |
#room_exits ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def room_exits @room_exits end |
#room_exits_string ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def room_exits_string @room_exits_string end |
#room_id ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def room_id @room_id end |
#room_name ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def room_name @room_name end |
#room_player_hidden ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def room_player_hidden @room_player_hidden end |
#room_title ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def room_title @room_title end |
#room_window_disabled ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def room_window_disabled @room_window_disabled end |
#roundtime_end ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def roundtime_end @roundtime_end end |
#send_fake_tags ⇒ Boolean
Returns whether to send fake tags.
107 108 109 |
# File 'lib/common/xmlparser.rb', line 107 def @send_fake_tags end |
#server_time ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def server_time @server_time end |
#server_time_offset ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def server_time_offset @server_time_offset end |
#society_task ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def society_task @society_task end |
#spirit ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def spirit @spirit end |
#stamina ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def stamina @stamina end |
#stance_text ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def stance_text @stance_text end |
#stance_value ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def stance_value @stance_value end |
#stow_container_id ⇒ Integer, ... (readonly)
94 95 96 |
# File 'lib/common/xmlparser.rb', line 94 def stow_container_id @stow_container_id end |
Instance Method Details
#active_spells ⇒ Hash
Retrieves the active spells and their statuses.
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 |
# File 'lib/common/xmlparser.rb', line 216 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_gsl ⇒ String
Generates a binary string representation of the player’s scars.
276 277 278 |
# File 'lib/common/xmlparser.rb', line 276 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_gsl ⇒ String
Generates a binary string representation of the player’s wounds.
268 269 270 |
# File 'lib/common/xmlparser.rb', line 268 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 the progress bar data from the PSM3 format.
308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/common/xmlparser.rb', line 308 def (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 |
#reset ⇒ void
This method returns an undefined value.
Resets the parser’s state by clearing active tags and IDs.
246 247 248 249 250 251 |
# File 'lib/common/xmlparser.rb', line 246 def reset @active_tags = Array.new @active_ids = Array.new @current_stream = String.new @current_style = String.new end |
#safe_to_respond? ⇒ Boolean
This method checks the game prefix to determine the response safety.
Checks if it is safe to respond based on the current game state.
256 257 258 259 260 261 262 |
# File 'lib/common/xmlparser.rb', line 256 def safe_to_respond? if @game =~ /^DR/ !in_stream && !@bold && (!@current_style || @current_style.empty?) else return true end end |
#spellfront ⇒ Array
This method will be removed in a future version of Lich.
Retrieves the currently active spells.
This method is here for backwards compatibility, but spellfront XML isn’t sent by the game anymore. It warns the user if the method is called after a certain time interval.
1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 |
# File 'lib/common/xmlparser.rb', line 1073 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 modifies global variables and game state.
This method returns an undefined value.
Handles the end of a tag in the XML parsing process.
This method is called once per element by REXML in games.rb. It processes various tags and updates game state accordingly.
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 |
# File 'lib/common/xmlparser.rb', line 994 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 == 'popStream') @dr_active_spell_tracking = false if @dr_active_spell_tracking 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 modifies several instance variables and may have side effects on the game state, including clearing game objects and updating player status.
This method returns an undefined value.
Handles the start of an XML tag.
This method is called once per element by REXML in games.rb. It processes various XML tags and updates the game state accordingly.
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 696 697 698 699 700 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 |
# File 'lib/common/xmlparser.rb', line 338 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 == 'clearStream' && attributes['id'] == 'percWindow') @dr_active_spells = {} @dr_active_spells_slivers = false end if (name == 'pushStream' && attributes['id'] == 'percWindow') @dr_active_spell_tracking = true 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 == '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 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.(@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
This method handles various game states and updates internal variables based on the content of the text string. It also manages active spells, room descriptions, and player statuses.
This method returns an undefined value.
Processes the given text string and updates the game state accordingly.
This method is called once per element with text in it by REXML in games.rb.
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 919 920 921 922 923 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 |
# File 'lib/common/xmlparser.rb', line 765 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>[^<>]+?)\s+\((?:\D*)(?<duration>\d+)\s*(?:%|roisae?n)\)/i # Spell with known duration remaining spell = Regexp.last_match[:spell] duration = Regexp.last_match[:duration].to_i when /(?<spell>[^<>]+?)\s+\(fading\)/i # Spell fading away spell = Regexp.last_match[:spell] duration = 0 when /(?<spell>[^<>]+?)\s+\((?<duration>indefinite|om)\)/i # Cyclic spell or Osrel Meraud cyclic spell spell = Regexp.last_match[:spell] duration = 1000 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>[^<>]+?)\s+\(.+\)/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 when /^(.*)$/ # No idea what we received, just a general catch all spell = Regexp.last_match(1) duration = 1000 end spell.strip! if spell @dr_active_spells[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 |