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=, #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



902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
# File 'documented/games.rb', line 902

def clean_serverstring(server_string)
  # 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



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

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

#handle_atmospherics(server_string) ⇒ Object



945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
# File 'documented/games.rb', line 945

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



928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
# File 'documented/games.rb', line 928

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



971
972
973
974
975
976
977
978
979
# File 'documented/games.rb', line 971

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



966
967
968
969
# File 'documented/games.rb', line 966

def process_game_specific_data(server_string)
  infomon_serverstring = server_string.dup
  DRParser.parse(infomon_serverstring)
end

#process_room_display(alt_string) ⇒ Object



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
1023
1024
1025
# File 'documented/games.rb', line 981

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 ['wrayth', 'stormfront'].include?($frontend)
      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