Class: Lich::GameBase::GameInstance::Base
- Inherits:
-
Object
- Object
- Lich::GameBase::GameInstance::Base
- Includes:
- RoomFormatter
- Defined in:
- documented/games.rb
Overview
Base instance class that defines the interface
Direct Known Subclasses
Constant Summary collapse
- SPLIT_REFUSAL =
A roundtime refusal, cut into a line when something precedes it.
/\.\.\.wait \d+ seconds?\.\r\n\z/.freeze
Constants included from RoomFormatter
RoomFormatter::OBVIOUS_EXIT_PATTERN
Instance Method Summary collapse
-
#adapt_for_frontend(alt_string, _capabilities = nil) ⇒ String
Rewrites a client-bound line for front ends that predate parts of this game's stream.
-
#atmospherics ⇒ Boolean
private
Returns whether atmospherics stream is currently open and waiting for closure.
-
#atmospherics=(value) ⇒ Boolean
private
Sets the atmospherics stream state.
-
#buffer_split_line(server_string) ⇒ String
Rejoins a line the server cut with a roundtime refusal.
- #clean_serverstring(server_string) ⇒ Object
-
#combat_count ⇒ Integer
private
Returns the current count of open combat streams.
- #get_documentation_url ⇒ Object
-
#handle_atmospherics(server_string) ⇒ String
private
Tracks and suppresses the atmospherics stream tag pair.
-
#handle_combat_tags(server_string) ⇒ Object
Shared by both games; override in a subclass only if a game's stream handling diverges.
- #hold_split_line(server_string) ⇒ Object protected
- #increment_combat_count(server_string) ⇒ Object protected
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #modify_room_display(alt_string) ⇒ Object
- #process_game_specific_data(server_string, stripped_server = nil) ⇒ Object
-
#process_room_display(alt_string) ⇒ String
private
Renders room exits, StringProc destinations, and optional room-number lines.
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
201 202 203 204 205 206 207 208 |
# File 'documented/games.rb', line 201 def initialize @atmospherics = false @combat_count = 0 @end_combat_tags = ["<prompt", "<clearStream", "<component", "<pushStream id=\"percWindow"] # The part of a line before a refusal cut, held for one line until # the rest arrives (#buffer_split_line); nil when nothing is held. @split_held = nil end |
Instance Method Details
#adapt_for_frontend(alt_string, _capabilities = nil) ⇒ String
Rewrites a client-bound line for front ends that predate parts of
this game's stream. Runs on the client path only, once per distinct
client capability set, after the downstream hooks and the
298 299 300 |
# File 'documented/games.rb', line 298 def adapt_for_frontend(alt_string, _capabilities = nil) alt_string end |
#atmospherics ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns whether atmospherics stream is currently open and waiting for closure.
317 318 319 |
# File 'documented/games.rb', line 317 def atmospherics @atmospherics end |
#atmospherics=(value) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sets the atmospherics stream state.
326 327 328 |
# File 'documented/games.rb', line 326 def atmospherics=(value) @atmospherics = value end |
#buffer_split_line(server_string) ⇒ String
Rejoins a line the server cut with a roundtime refusal. The server puts "...wait N seconds.\r\n" into the line it was sending, after whatever it had sent of it, and then sends the rest of the line: its remaining text, or only its line end, as an empty line. A standalone refusal starts its line and is never followed by an empty line.
The refusal is returned at once as a line of its own, where
WAIT_RESPONSE_PATTERN finds it, and the part before it is held and
joined to the next line, which is released whatever it holds. The
game keeps each element, a
344 345 346 347 348 349 350 351 |
# File 'documented/games.rb', line 344 def buffer_split_line(server_string) return hold_split_line(server_string) unless @split_held line = @split_held + server_string @split_held = nil Lich.log "Rejoined a line cut by a roundtime refusal: #{line.inspect}" hold_split_line(line) end |
#clean_serverstring(server_string) ⇒ Object
210 211 212 |
# File 'documented/games.rb', line 210 def clean_serverstring(server_string) raise NotImplementedError, "#{self.class} must implement #clean_serverstring" end |
#combat_count ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the current count of open combat streams.
Incremented when
309 310 311 |
# File 'documented/games.rb', line 309 def combat_count @combat_count end |
#get_documentation_url ⇒ Object
262 263 264 |
# File 'documented/games.rb', line 262 def get_documentation_url raise NotImplementedError, "#{self.class} must implement #get_documentation_url" end |
#handle_atmospherics(server_string) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Tracks and suppresses the atmospherics stream tag pair.
The atmospherics stream (e.g., empath appraisals, echoes from spells/abilities)
wraps its content in
Modifies server_string in place.
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'documented/games.rb', line 245 def handle_atmospherics(server_string) if @atmospherics @atmospherics = false server_string.prepend('<popStream id="atmospherics" />') unless server_string =~ /<popStream id="atmospherics" \/>/ end if server_string =~ /<pushStream id="familiar" \/><prompt time="[0-9]+">><\/prompt>/ # Cry For Help spell is broken... server_string.sub!('<pushStream id="familiar" />', '') elsif server_string =~ /<pushStream id="atmospherics" \/><prompt time="[0-9]+">><\/prompt>/ # pet pigs in DragonRealms are broken... server_string.sub!('<pushStream id="atmospherics" />', '') elsif (server_string =~ /<pushStream id="atmospherics" \/>/) @atmospherics = true end server_string end |
#handle_combat_tags(server_string) ⇒ Object
Shared by both games; override in a subclass only if a game's stream handling diverges.
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'documented/games.rb', line 215 def (server_string) if @combat_count > 0 @end_combat_tags.each do |tag| if server_string.include?(tag) server_string = server_string.gsub(tag, "<popStream id=\"combat\" />" + tag) unless server_string.include?("<popStream id=\"combat\" />") @combat_count -= 1 end if server_string.include?("<pushStream id=\"combat\" />") server_string = server_string.gsub("<pushStream id=\"combat\" />", "") end end end increment_combat_count(server_string) server_string end |
#hold_split_line(server_string) ⇒ Object (protected)
355 356 357 358 359 360 361 |
# File 'documented/games.rb', line 355 def hold_split_line(server_string) match = SPLIT_REFUSAL.match(server_string) return server_string if match.nil? || match.pre_match.empty? @split_held = match.pre_match match[0] end |
#increment_combat_count(server_string) ⇒ Object (protected)
363 364 365 366 367 |
# File 'documented/games.rb', line 363 def increment_combat_count(server_string) @combat_count += server_string.scan("<pushStream id=\"combat\" />").length @combat_count -= server_string.scan("<popStream id=\"combat\" />").length @combat_count = 0 if @combat_count < 0 end |
#modify_room_display(alt_string) ⇒ Object
270 271 272 |
# File 'documented/games.rb', line 270 def modify_room_display(alt_string) raise NotImplementedError, "#{self.class} must implement #modify_room_display" end |
#process_game_specific_data(server_string, stripped_server = nil) ⇒ Object
266 267 268 |
# File 'documented/games.rb', line 266 def process_game_specific_data(server_string, stripped_server = nil) raise NotImplementedError, "#{self.class} must implement #process_game_specific_data" end |
#process_room_display(alt_string) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Renders room exits, StringProc destinations, and optional room-number lines.
Subclasses override to prepend "Room Exits:" and "StringProcs:" lines, and for DragonRealms, a "Room Number:" line and room-window subtitle. Called when a prompt appears after a room block, honoring the room-display toggles (display_exits, display_stringprocs, display_lichid, display_uid).
284 285 286 |
# File 'documented/games.rb', line 284 def process_room_display(alt_string) raise NotImplementedError, "#{self.class} must implement #process_room_display" end |