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

#initializeBase

Returns a new instance of Base.



185
186
187
188
189
190
# File 'documented/games.rb', line 185

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

Instance Method Details

#atmosphericsBoolean

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 an atmospheric stream is currently active.

Returns:

  • (Boolean)

    true if an atmospherics pushStream is open



241
242
243
# File 'documented/games.rb', line 241

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 state.

Parameters:

  • value (Boolean)

    whether an atmospherics stream is active

Returns:

  • (Boolean)

    the assigned value



250
251
252
# File 'documented/games.rb', line 250

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]



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'documented/games.rb', line 256

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)


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

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

#combat_countInteger

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 nesting depth of the combat stream.

Returns:

  • (Integer)

    the number of active combat streams



233
234
235
# File 'documented/games.rb', line 233

def combat_count
  @combat_count
end

#get_documentation_urlObject

Raises:

  • (NotImplementedError)


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

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

#handle_atmospherics(server_string) ⇒ Object

Raises:

  • (NotImplementedError)


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

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

#handle_combat_tags(server_string) ⇒ Object

Raises:

  • (NotImplementedError)


196
197
198
# File 'documented/games.rb', line 196

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

#increment_combat_count(server_string) ⇒ Object (protected)



281
282
283
284
285
# File 'documented/games.rb', line 281

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)


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

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)


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

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.

Injects room information lines (exits, StringProcs, room numbers) into the display.

This method is overridden by game-specific implementations to format and place room annotations according to game and frontend conventions.

Parameters:

  • alt_string (String)

    the server string being rewritten

Returns:

  • (String)

    the rewritten server string

Raises:

  • (NotImplementedError)

    when called on the base class



225
226
227
# File 'documented/games.rb', line 225

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