Class: Lich::DragonRealms::GameInstance

Inherits:
GameBase::GameInstance::Base show all
Defined in:
documented/games.rb

Overview

DragonRealms-specific game instance

Constant Summary

Constants included from GameBase::RoomFormatter

GameBase::RoomFormatter::OBVIOUS_EXIT_PATTERN

Instance Method Summary collapse

Methods inherited from GameBase::GameInstance::Base

#atmospherics, #atmospherics=, #buffer_room_objs, #combat_count, #increment_combat_count, #initialize

Constructor Details

This class inherits a constructor from Lich::GameBase::GameInstance::Base

Instance Method Details

#clean_serverstring(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.

Cleans a DragonRealms server string: buffers split room components, fixes encoding and malformed XML tags, handles combat/atmospherics.

Buffers the "...wait N seconds." part of split room object/player components, removes superfluous combat wrapping, fixes encoding and duplicate tags, and processes combat/atmospheric stream markers.

Parameters:

  • server_string (String) —

    the raw server string

Returns:

  • (String, nil) —

    the cleaned server string, or nil if buffering (should skip)



1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
# File 'documented/games.rb', line 1764

def clean_serverstring(server_string)
  # Buffer split room objs components (server sends "...wait N seconds." separately)
  should_skip, server_string = buffer_room_objs(server_string)
  return nil if should_skip

  # Clear out superfluous tags
  server_string = server_string.gsub("<pushStream id=\"combat\" /><popStream id=\"combat\" />", "")
  server_string = server_string.gsub("<popStream id=\"combat\" /><pushStream id=\"combat\" />", "")

  # Fix encoding issues
  server_string = GameBase::XMLCleaner.fix_invalid_characters(server_string)

  # Fix combat wrapping components
  server_string = server_string.gsub("<pushStream id=\"combat\" /><component id=", "<component id=")

  # Fix XML tags
  server_string = GameBase::XMLCleaner.fix_xml_tags(server_string)

  # Fix duplicate pushStrings
  while server_string.include?("<pushStream id=\"combat\" /><pushStream id=\"combat\" />")
    server_string = server_string.gsub("<pushStream id=\"combat\" /><pushStream id=\"combat\" />", "<pushStream id=\"combat\" />")
  end

  # Handle combat and atmospherics
  server_string = handle_combat_tags(server_string)
  server_string = handle_atmospherics(server_string)

  server_string
end

#get_documentation_url ⇒ 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.

Returns the DragonRealms-specific documentation URL.

Returns:

  • (String) —

    the Lich 5 GitHub wiki URL



1848
1849
1850
# File 'documented/games.rb', line 1848

def get_documentation_url
  "https://github.com/elanthia-online/lich-5/wiki/Documentation-for-Installing-and-Upgrading-Lich"
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.

Manages DragonRealms atmospheric stream state (familiar and spell effects).

Closes pending atmospheric streams and strips misplaced stream tags that break prompt processing (familiar narration and pet pig effects).

Parameters:

  • server_string (String) —

    the server string with atmospheric tags

Returns:

  • (String) —

    the modified string



1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
# File 'documented/games.rb', line 1827

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]+">&gt;<\/prompt>/ # Cry For Help spell is broken...
    server_string.sub!('<pushStream id="familiar" />', '')
  elsif server_string =~ /<pushStream id="atmospherics" \/><prompt time="[0-9]+">&gt;<\/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) ⇒ 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.

Manages DragonRealms combat stream nesting: closes pending streams and removes duplicates.

When exiting combat, wraps end tags (prompt, clearStream, etc.) with closing combat stream markers. Removes orphaned opening tags when not in combat.

Parameters:

  • server_string (String) —

    the server string with combat tags

Returns:

  • (String) —

    the modified string



1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
# File 'documented/games.rb', line 1802

def handle_combat_tags(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

#modify_room_display(alt_string) ⇒ String

Rewrites the room-name line (the "<style id="roomName" />[Title]" chunk) on its way to the client. Two independent concerns:

1. When the player wants the room id/UID in the title (";display roomid title|both"),
 inject Lich's configured id/UID before the closing bracket. The game-supplied
 RealID (present only under the ShowRoomID flag) is preserved GemStone-style so
 ";display lichid" alone reads "[Town Square - 1234] (230008)" - matching how
 Lich::Gemstone::GameInstance#modify_room_display already behaves. It is stripped
 only when Lich is rendering its own UID instead ({#suppress_game_realid?}), so a
 ";display uid" title reads "[Town Square - 1234 - (u230008)]" with no duplicate.
2. Otherwise preserve the historical behavior of hiding the game's inline RealID when
 the player asked to (";display uid" or ";display flaguid").

Edits only this outbound client string; XMLData (and therefore scripts) are untouched, because process_xml_data has already parsed the inbound stream before this runs.

Parameters:

  • alt_string (String) —

    the outbound room-name server string, modified in place

Returns:

  • (String) —

    the rewritten string

See Also:



1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
# File 'documented/games.rb', line 1883

def modify_room_display(alt_string)
  if room_id_in_title?
    alt_string.sub!(/] \((?:\d+|\*\*)\)/) { "]" } if suppress_game_realid?
    room_number = room_number_display
    alt_string.sub!(']') { " - #{room_number}]" } unless room_number.empty?
  elsif suppress_game_realid?
    alt_string.sub!(/] \((?:\d+|\*\*)\)/) { "]" }
  end

  alt_string
end

#process_game_specific_data(server_string, _stripped_server = nil) ⇒ void

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.

This method returns an undefined value.

Parses DragonRealms-specific data via DRParser (vitals, experience, room info).

Runs DRParser to update character state and optionally inject inline exp display. The parser may modify server_string in place.

Parameters:

  • server_string (String) —

    the raw server XML string, possibly modified in place



1860
1861
1862
1863
1864
# File 'documented/games.rb', line 1860

def process_game_specific_data(server_string, _stripped_server = nil)
  # Parse directly to allow inline modifications (e.g., inline exp display)
  # The parser modifies server_string in place via line.replace()
  DRParser.parse(server_string)
end

#process_room_display(alt_string) ⇒ String

Prepends the shared exit / StringProc lines, then renders the optional DragonRealms room id/UID. The "Room Number:" line below the room appears for the "line" and "both" placements (honoring the mono toggle). The room-window subtitle (room-window front-ends only) reflects Lich's id/UID for every placement, since the window title bar is itself a title surface. It also re-appends the game-supplied RealID (#synthesized_realid_suffix) whenever the game displayed it (ShowRoomID ON) - independent of ";display roomid", which governs only where Lich's own id is placed, not whether the game's RealID is shown. So a ShowRoomID-on room shows the RealID in the window title under every placement, matching the game's own behavior and the RealID the game already leaves on the room-name line for the "line"/nil placements. The RealID is synthesized from the authoritative nav UID (XMLData.room_id) rather than copied from the inbound string, because the subtitle is rebuilt from the (UID-free) XMLData.room_title; for a complete arrival nav and the room-name literal agree, so the two surfaces read identically. The inline room-name injection for the "title"/"both" placements is handled separately in #modify_room_display.

Parameters:

  • alt_string (String) —

    the server string being rewritten

Returns:

  • (String) —

    the rewritten server string



1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
# File 'documented/games.rb', line 1911

def process_room_display(alt_string)
  alt_string = prepend_room_lines(alt_string, room_stringproc_entries, room_exit_entries)

  room_number = room_number_display
  unless room_number.empty?
    if room_id_in_line?
      alt_string = "#{room_styled("Room Number: #{room_number}")}\r\n#{alt_string}"
    end
    if Frontend.supports_room_window?
      subtitle = " - [#{XMLData.room_title[2..-3]} - #{room_number}]#{synthesized_realid_suffix}"
      alt_string = "<streamWindow id='main' title='Story' subtitle=\"#{subtitle}\" location='center' target='drop'/>\r\n#{alt_string}"
      alt_string = "<streamWindow id='room' title='Room' subtitle=\"#{subtitle}\" location='center' target='drop' ifClosed='' resident='true'/>#{alt_string}"
    end
  end

  alt_string
end