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, removes superfluous tags, fixes encoding, and handles combat/atmospheric streams.

Parameters:

  • server_string (String)

    the server string to clean

Returns:

  • (String, nil)

    the cleaned server string, or nil if buffering a split component



1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
# File 'documented/games.rb', line 1726

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_urlString

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 Lich installation documentation URL.

Returns:

  • (String)

    the GitHub wiki URL for Lich installation



1806
1807
1808
# File 'documented/games.rb', line 1806

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.

Handles DragonRealms atmospheric stream state: prepends popStream when atmospherics flag is set, and manages broken familiar/pet-pig tags.

Parameters:

  • server_string (String)

    the server string, modified in place

Returns:

  • (String)

    the processed server string



1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
# File 'documented/games.rb', line 1785

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.

Handles DragonRealms combat stream nesting: closes pushStream/combat with popStream when certain end tags are encountered.

Parameters:

  • server_string (String)

    the server string, modified in place

Returns:

  • (String)

    the processed server string



1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
# File 'documented/games.rb', line 1762

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:



1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
# File 'documented/games.rb', line 1840

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 XML and line data for DRParser (dynamic data display).

Passes raw server_string to DRParser for inline modifications.

Parameters:

  • server_string (String)

    the raw XML server string, modified in place by the parser



1817
1818
1819
1820
1821
# File 'documented/games.rb', line 1817

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



1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
# File 'documented/games.rb', line 1868

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