Class: Lich::DragonRealms::GameInstance

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

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) ⇒ Object



894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
# File 'documented/games.rb', line 894

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_urlObject



958
959
960
# File 'documented/games.rb', line 958

def get_documentation_url
  "https://github.com/elanthia-online/lich-5/wiki/Documentation-for-Installing-and-Upgrading-Lich"
end

#handle_atmospherics(server_string) ⇒ Object



941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
# File 'documented/games.rb', line 941

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) ⇒ Object



924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
# File 'documented/games.rb', line 924

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) ⇒ Object



968
969
970
971
972
973
974
975
976
# File 'documented/games.rb', line 968

def modify_room_display(alt_string)
  if Lich.display_uid == true
    alt_string.sub!(/] \((?:\d+|\*\*)\)/) { "]" }
  elsif Lich.hide_uid_flag == true
    alt_string.sub!(/] \((?:\d+|\*\*)\)/) { "]" }
  end

  alt_string
end

#process_game_specific_data(server_string) ⇒ Object



962
963
964
965
966
# File 'documented/games.rb', line 962

def process_game_specific_data(server_string)
  # 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) ⇒ Object



978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
# File 'documented/games.rb', line 978

def process_room_display(alt_string)
  if Lich.display_stringprocs == true
    room_exits = []
    Map.current.wayto.each do |key, value|
      # Don't include cardinals / up/down/out (usually just climb/go)
      if value.is_a?(StringProc)
        if Map.current.timeto[key].is_a?(Numeric) || (Map.current.timeto[key].is_a?(StringProc) && Map.current.timeto[key].call.is_a?(Numeric))
          room_exits << "<d cmd=';go2 #{key}'>#{Map[key].title.first.gsub(/\[|\]/, '')}#{Lich.display_lichid ? ('(' + Map[key].id.to_s + ')') : ''}</d>"
        end
      end
    end
    alt_string = "StringProcs: #{room_exits.join(', ')}\r\n#{alt_string}" unless room_exits.empty?
  end

  if Lich.display_exits == true
    room_exits = []
    Map.current.wayto.each do |_key, value|
      # Don't include cardinals / up/down/out (usually just climb/go)
      next if value.to_s =~ /^(?:o|d|u|n|ne|e|se|s|sw|w|nw|out|down|up|north|northeast|east|southeast|south|southwest|west|northwest)$/
      unless value.is_a?(StringProc)
        room_exits << "<d cmd='#{value.dump[1..-2]}'>#{value.dump[1..-2]}</d>"
      end
    end

    unless room_exits.empty?
      alt_string = "Room Exits: #{room_exits.join(', ')}\r\n#{alt_string}"
    end
  end

  # DR-specific room number display
  room_number = ""
  room_number += "#{Map.current.id}" if Lich.display_lichid
  room_number += " - " if Lich.display_lichid && Lich.display_uid
  room_number += "(#{XMLData.room_id == 0 ? "**" : "u#{XMLData.room_id}"})" if Lich.display_uid

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

  alt_string
end