Class: Lich::GameBase::GameInstance::Base

Inherits:
Object
  • Object
show all
Includes:
RoomFormatter
Defined in:
documented/games.rb

Overview

Base instance class that defines the interface

Constant Summary

Constants included from RoomFormatter

RoomFormatter::OBVIOUS_EXIT_PATTERN

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Base

Returns a new instance of Base.



192
193
194
195
196
197
# File 'documented/games.rb', line 192

def initialize
  @atmospherics = false
  @combat_count = 0
  @end_combat_tags = ["<prompt", "<clearStream", "<component", "<pushStream id=\"percWindow"]
  @pending_room_objs = nil
end

Instance Method Details

#atmospherics ⇒ Boolean

Returns the current atmospheric stream flag state.

Returns:

  • (Boolean) —

    true if an atmospheric stream is open and awaiting closure



245
246
247
# File 'documented/games.rb', line 245

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 atmospheric stream flag state.

Parameters:

  • value (Boolean) —

    true to mark an atmospheric stream as open, false to close it

Returns:

  • (Boolean) —

    the new state



254
255
256
# File 'documented/games.rb', line 254

def atmospherics=(value)
  @atmospherics = value
end

#buffer_room_objs(server_string) ⇒ Object

Buffer split or when server sends "...wait N seconds." on separate line Returns [should_skip, server_string]



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'documented/games.rb', line 260

def buffer_room_objs(server_string)
  if @pending_room_objs
    if server_string.include?("</component>")
      combined = @pending_room_objs + server_string.sub(/\r\n$/, '')
      Lich.log "Combined split room component: #{combined.inspect}"
      @pending_room_objs = nil
      return [false, combined]
    else
      @pending_room_objs = @pending_room_objs + server_string.sub(/\r\n$/, '')
      return [true, nil]
    end
  end

  if server_string =~ /^(?:<\/?(?:pushStream|popStream)[^>]*>\s*)*<component id='room (?:objs|players)'>.*\.\.\.wait \d+ seconds?\.\r\n$/ && !server_string.include?("</component>")
    Lich.log "Open-ended room component tag, buffering: #{server_string.inspect}"
    # Strip the "...wait N seconds.\r\n" part, keep the opening tag and any content before it
    @pending_room_objs = server_string.sub(/\.\.\.wait \d+ seconds?\.\r\n$/, '')
    return [true, nil]
  end

  [false, server_string]
end

#clean_serverstring(server_string) ⇒ Object

Raises:

  • (NotImplementedError)


199
200
201
# File 'documented/games.rb', line 199

def clean_serverstring(server_string)
  raise NotImplementedError, "#{self.class} must implement #clean_serverstring"
end

#combat_count ⇒ Integer

Returns the current depth of combat stream nesting.

Returns:

  • (Integer) —

    the number of active combat streams (0 when not in combat)



238
239
240
# File 'documented/games.rb', line 238

def combat_count
  @combat_count
end

#get_documentation_url ⇒ Object

Raises:

  • (NotImplementedError)


211
212
213
# File 'documented/games.rb', line 211

def get_documentation_url
  raise NotImplementedError, "#{self.class} must implement #get_documentation_url"
end

#handle_atmospherics(server_string) ⇒ Object

Raises:

  • (NotImplementedError)


207
208
209
# File 'documented/games.rb', line 207

def handle_atmospherics(server_string)
  raise NotImplementedError, "#{self.class} must implement #handle_atmospherics"
end

#handle_combat_tags(server_string) ⇒ Object

Raises:

  • (NotImplementedError)


203
204
205
# File 'documented/games.rb', line 203

def handle_combat_tags(server_string)
  raise NotImplementedError, "#{self.class} must implement #handle_combat_tags"
end

#increment_combat_count(server_string) ⇒ Object (protected)



285
286
287
288
289
# File 'documented/games.rb', line 285

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

Raises:

  • (NotImplementedError)


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

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

Raises:

  • (NotImplementedError)


215
216
217
# File 'documented/games.rb', line 215

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.

Prepends room exit and StringProc navigation lines to the server output.

Subclasses must override to provide game-specific room display processing.

Parameters:

  • alt_string (String) —

    the outbound server string being rewritten

Returns:

  • (String) —

    the modified server string with room lines prepended

Raises:

  • (NotImplementedError) —

    in the base class



231
232
233
# File 'documented/games.rb', line 231

def process_room_display(alt_string)
  raise NotImplementedError, "#{self.class} must implement #process_room_display"
end