Module: Lich::DragonRealms::DRC
- Defined in:
- documented/dragonrealms/commons/common.rb
Overview
DRC module containing methods for interacting with the game.
Defined Under Namespace
Classes: Item
Class Method Summary collapse
-
.assess_teach ⇒ Hash
Assesses the current teaching situation.
-
.atmo(text, make_bold = true) ⇒ void
Sends a message to the atmospherics window.
-
.beep ⇒ void
windows only I believe.
-
.bold(text) ⇒ String
Helper function to wrap text in the necessary markup to make it render as bold in a frontend client.
-
.box_list_to_adj_and_noun(list) ⇒ Array
Take a game formated list of boxes “a reinforced wooden strongbox and a plain ironwood crate” And return an array [“wooden strongbox”, “ironwood crate”] Converts a formatted list of boxes into an array of adjectives and nouns.
-
.bput(message, *matches) ⇒ String
Like ‘fput` but better because will wait for RT before performing command and do smart retries.
-
.can_see_sky? ⇒ Boolean
Checks if the player can see the sky based on their location.
-
.check_encumbrance(refresh = true) ⇒ String
Checks the player’s encumbrance status.
-
.clean_instrument(settings, worn = true) ⇒ Boolean
Cleans the instrument to ensure optimal performance.
-
.collect(item, practice = true) ⇒ void
Attempts to collect an item from the environment.
-
.do_tune(instrument, tuning = "") ⇒ Boolean
Performs the tuning action on the specified instrument.
-
.fix_dr_bullshit(string) ⇒ String
Cleans up a string by removing unnecessary parts.
-
.fix_standing ⇒ void
Fixes the player’s standing state if they are not standing.
-
.forage?(item, tries = 5) ⇒ Boolean
Attempts to forage for an item in the environment.
- .get_gems(container) ⇒ Object
- .get_materials(container) ⇒ Object
-
.get_noun(long_name) ⇒ String
Extracts the noun from a long name, removing any flavor text.
- .get_skins(container) ⇒ Object
-
.get_town_name(text) ⇒ String?
Looks up the canonical name of the town based on the given text.
-
.hide?(hide_type = 'hide') ⇒ Boolean
Attempts to hide the player if they are not already hiding.
-
.kick_pile?(item = 'pile') ⇒ Boolean
Kicks a pile to see if any items can be found.
-
.left_hand ⇒ String?
Returns the name of the item in the left hand.
-
.left_hand_noun ⇒ String?
Returns the noun of the item in the left hand.
-
.list_to_array(list) ⇒ Array
Take a game formatted list “an arrow, silver coins and a deobar strongbox” And return an array [“an arrow”, “silver coins”, “a deobar strongbox”] is this ever useful compared to the list_to_nouns? Converts a game formatted list into an array of items.
-
.list_to_nouns(list) ⇒ Array
Take a game formatted list “an arrow, silver coins and a deobar strongbox” And return an array of nouns [“arrow”, “coins”, “strongbox”] Converts a game formatted list into an array of nouns.
-
.listen?(teacher, observe_flag = false) ⇒ Boolean
Checks if the player can listen to a teacher.
-
.log_window(text, window_name, make_bold = true, create_window = false, pre_clear_window = false) ⇒ void
Sends a message to the specified window.
-
.message(text, make_bold = true) ⇒ void
Sends a message to the game window.
-
.pause_all ⇒ Boolean
Pauses all running scripts except the current one.
-
.play_song?(settings, song_list, worn = true, skip_clean = false, climbing = false, skip_tuning = false) ⇒ Boolean
Plays a song using the specified settings and song list.
-
.release_invisibility ⇒ void
Releases any invisibility spells affecting the player.
-
.remove_flavor_text(item) ⇒ String
Removes flavor text from an item description.
-
.retreat(ignored_npcs = []) ⇒ void
Attempts to retreat from combat.
-
.right_hand ⇒ String?
Returns the name of the item in the right hand.
-
.right_hand_noun ⇒ String?
Returns the noun of the item in the right hand.
-
.rummage(parameter, container) ⇒ Array
Rummages through a container for a specified parameter.
-
.safe_pause_list ⇒ Array
Safely pauses all scripts that can be paused.
-
.safe_unpause_list(scripts_to_unpause) ⇒ void
Safely unpauses a list of specified scripts.
-
.scroll_list_to_adj_and_noun(list) ⇒ Array
Converts a formatted list of scrolls into an array of adjectives and nouns.
-
.set_stance(skill) ⇒ void
Sets the player’s stance based on their skill level.
-
.smart_pause_all ⇒ Array
Smartly pauses all scripts that can be paused.
-
.stop_playing ⇒ void
Stops the currently playing song.
-
.text2num(text_num) ⇒ Integer?
Converts a text representation of a number into an integer.
-
.tune_instrument(settings) ⇒ Boolean
Tunes the instrument to ensure it is in proper condition.
-
.unpause_all ⇒ Boolean
Unpauses all previously paused scripts.
-
.unpause_all_list(scripts_to_unpause) ⇒ void
Unpauses a list of specified scripts.
-
.wait_for_script_to_complete(name, args = [], flags = {}) ⇒ Object
Waits for a script to complete before proceeding.
Class Method Details
.assess_teach ⇒ Hash
Assesses the current teaching situation.
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 |
# File 'documented/dragonrealms/commons/common.rb', line 559 def assess_teach case bput('assess teach', 'is teaching a class', 'No one seems to be teaching', 'You are teaching a class') when 'No one seems to be teaching', 'You are teaching a class' waitrt? return {} end results = reget(20, 'is teaching a class') waitrt? results.each_with_object({}) do |line, hash| line.match(/(.*) is teaching a class on (.*) which is still open to new students/) do |match| teacher = match[1] skill = match[2] # Some classes match the first format, some have additional text in the 'skill' string that needs to be filtered skill.match(/.* \(compared to what you already know\) (.*)/) { |m| skill = m[1] } hash[teacher] = skill end end end |
.atmo(text, make_bold = true) ⇒ void
This method returns an undefined value.
Sends a message to the atmospherics window. By default the message is bold. DEPRECATED in favor of log_window Sends a message to the atmospherics window.
1105 1106 1107 |
# File 'documented/dragonrealms/commons/common.rb', line 1105 def atmo(text, make_bold = true) log_window(text, "atmospherics", make_bold) end |
.beep ⇒ void
This method returns an undefined value.
windows only I believe. Emits a beep sound in the game.
509 510 511 |
# File 'documented/dragonrealms/commons/common.rb', line 509 def beep echo("\a") end |
.bold(text) ⇒ String
Helper function to wrap text in the necessary markup to make it render as bold in a frontend client. This method has little use to other scripts and is designed for ‘atmo` and `message` methods in common.lic. Wraps text in markup to render it as bold in the frontend client.
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 |
# File 'documented/dragonrealms/commons/common.rb', line 1145 def bold(text) string = '' $fake_stormfront ? string.concat("\034GSL\r\n ") : string.concat("<pushBold\/>") string.concat(text) $fake_stormfront ? string.concat("\034GSM\r\n ") : string.concat("<popBold\/>") string end |
.box_list_to_adj_and_noun(list) ⇒ Array
Take a game formated list of boxes “a reinforced wooden strongbox and a plain ironwood crate” And return an array [“wooden strongbox”, “ironwood crate”] Converts a formatted list of boxes into an array of adjectives and nouns.
306 307 308 309 310 311 312 |
# File 'documented/dragonrealms/commons/common.rb', line 306 def box_list_to_adj_and_noun(list) list.strip .split($box_regex) .reject(&:empty?) .select { |item| item =~ $box_regex } .map { |box| box.gsub('ironwood', 'iron') } # make all ironwood into iron because "the parser" end |
.bput(message, *matches) ⇒ String
Like ‘fput` but better because will wait for RT before performing command and do smart retries. Will wait for matching text up to 15 seconds then timeout. Also recovers from some limited failures wherein we want to simply fix the issue and retry the bput, like when we’re prone and need to be standing. Complex handling should be done within the calling script. Like ‘fput` but better because will wait for RT before performing command and do smart retries. Will wait for matching text up to 15 seconds then timeout. Also recovers from some limited failures wherein we want to simply fix the issue and retry the bput.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'documented/dragonrealms/commons/common.rb', line 31 def bput(, *matches) = (matches.shift if matches.first.is_a?(Hash)) || {} ['timeout'] ||= 15 ['ignore_rt'] ||= false timeout = ['timeout'] ignore_rt = ['ignore_rt'] suppress = ['suppress_no_match'] if ['debug'] echo "bput.message=#{}" echo "bput.options=#{}" echo "bput.matches=#{matches}" end waitrt? unless ignore_rt log = [] matches.flatten! matches.map! { |item| item.is_a?(Regexp) ? item : /#{item}/i } clear put timer = Time.now while (response = get?) || (Time.now - timer < timeout) if response.nil? pause 0.1 next end log += [response] case response when /^For some strange reason you are unable to do that\. The world somehow seems frozen in place/ # Zadraes — 13:32 It's a "You're in an area actively being updated" message pause 1 put timer = Time.now next when /(?:\.\.\.wait |Wait |\.\.\. wait )([0-9]+)/ unless ignore_rt pause(Regexp.last_match(1).to_i - 0.5) waitrt? put timer = Time.now end next when /Sorry, you may only type ahead/ pause 1 put timer = Time.now next when /^You can't do that while you are asleep./ put 'wake' put timer = Time.now next when /^You are a bit too busy performing to do that/, /^You should stop playing before you do that/ put 'stop play' put timer = Time.now next when /would give away your hiding place/ release_invisibility put 'unhide' put timer = Time.now next when /^You don't seem to be able to move to do that/ next unless matches.include?(response) when /^You are still stunned/ pause 0.5 while stunned? pause 0.5 put timer = Time.now next when /^You can't do that while entangled in a web/ pause 0.5 while webbed? pause 0.5 put timer = Time.now next when /^You must be standing/, /^You should stand up first/, /^You'll need to stand up first/, /^You can't do that while (sitting|kneeling|lying)/, /^You should be sitting up/, /^You really should be standing to play/, /^After failing to draw a breath for what feels like forever/ fix_standing waitrt? put timer = Time.now next end matches.each do |match| if (result = response.match(match)) return result.to_a.first end end end unless suppress echo "*** No match was found after #{timeout} seconds, dumping info" echo "messages seen length: #{log.length}" log.reverse.each { |logged_response| echo "message: #{logged_response}" } echo "checked against #{matches}" echo "for command #{}" end '' end |
.can_see_sky? ⇒ Boolean
Checks if the player can see the sky based on their location.
161 162 163 164 165 166 167 168 169 170 |
# File 'documented/dragonrealms/commons/common.rb', line 161 def can_see_sky? # If you are indoors and not able to see the sky. inside_no_sky = "That's a bit hard to do while inside." # If you are indoors but able to see the sky (e.g. a window or skylight). inside_yes_sky = "You glance outside" # If you are outdoors. outside = "You glance up at the sky" # Can we see the sky? bput("weather", inside_no_sky, inside_yes_sky, outside) != inside_no_sky end |
.check_encumbrance(refresh = true) ⇒ String
Checks the player’s encumbrance status.
671 672 673 674 675 676 677 678 679 680 681 |
# File 'documented/dragonrealms/commons/common.rb', line 671 def check_encumbrance(refresh = true) encumbrance = DRStats.encumbrance if refresh encumbrance_pattern = /(?:Encumbrance)\s:\s(?<encumbrance>.*)/ case bput('encumbrance', encumbrance_pattern) when encumbrance_pattern encumbrance = Regexp.last_match[:encumbrance] end end $ENC_MAP[encumbrance] end |
.clean_instrument(settings, worn = true) ⇒ Boolean
Cleans the instrument to ensure optimal performance.
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 |
# File 'documented/dragonrealms/commons/common.rb', line 845 def clean_instrument(settings, worn = true) cloth = settings.cleaning_cloth instrument = worn ? settings.worn_instrument : settings.instrument unless DRCI.get_item?(cloth) DRC.('You have no chamois cloth -- this could cause problems with playing an instrument!') DRC.beep return false end DRC. if worn unless DRCI.remove_item?(instrument) DRC.("Could not remove #{instrument} putting away cloth, and not trying to clean.") DRCI.stow_item?(cloth) DRC.beep return false end else unless DRCI.get_item?(instrument) DRC.("Could not get #{instrument} putting away cloth, and not trying to clean.") DRCI.stow_item?(cloth) DRC.beep return false end end loop do case DRC.bput("wipe my #{instrument} with my #{cloth}", 'Roundtime', 'not in need of drying', 'You should be sitting up') when 'not in need of drying' break when 'You should be sitting up' DRC.fix_standing next end pause 1 waitrt? until /you wring a dry/i =~ DRC.bput("wring my #{cloth}", 'You wring a dry', 'You wring out') pause 1 waitrt? end end until /not in need of cleaning/i =~ DRC.bput("clean my #{instrument} with my #{cloth}", 'Roundtime', 'not in need of cleaning') pause 1 waitrt? end DRCI.wear_item?(instrument) if worn DRCI.stow_item?(cloth) true end |
.collect(item, practice = true) ⇒ void
This method returns an undefined value.
Attempts to collect an item from the environment.
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'documented/dragonrealms/commons/common.rb', line 202 def collect(item, practice = true) = [ 'As you rummage around', 'believe you would probably have better luck trying to find a dragon', 'if you had a bit more luck', 'The room is too cluttered', 'one hand free to properly collect', 'You are sure you knew', 'You begin to forage around,', 'You begin scanning the area before you', 'You begin exploring the area, searching for', 'You find something dead and lifeless', 'You cannot collect anything', 'you fail to find anything', 'You forage around but are unable to find anything', 'You manage to collect a pile', 'You survey the area and realize that any collecting efforts would be futile', 'You wander around and poke your fingers', 'You forage around for a while and manage to stir up a small mound of fire ants!' ] practicing = "practice" if practice case bput("collect #{item} #{practicing}", ) when 'The room is too cluttered' return unless kick_pile? collect(item) end waitrt? end |
.do_tune(instrument, tuning = "") ⇒ Boolean
Performs the tuning action on the specified instrument.
945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 |
# File 'documented/dragonrealms/commons/common.rb', line 945 def do_tune(instrument, tuning = "") unless instrument && DRCI.in_hands?(instrument) DRC.("No instrument found in hands. Not trying to tune.") DRC.beep return false end case DRC.bput("tune my #{instrument} #{tuning}", /^You should be sitting up/, /After a moment, you .* flat/, /After a moment, you .* sharp/, /After a moment, you .* tune/) when /After a moment, you .* tune/ DRC.("Instrument tuned.") return true when /After a moment, you .* flat/ DRC.do_tune(instrument, "sharp") when /After a moment, you .* sharp/ DRC.do_tune(instrument, "flat") when /^You should be sitting up/ DRC.fix_standing DRC.do_tune(instrument) end end |
.fix_dr_bullshit(string) ⇒ String
Cleans up a string by removing unnecessary parts.
608 609 610 611 612 613 614 615 |
# File 'documented/dragonrealms/commons/common.rb', line 608 def fix_dr_bullshit(string) return string if string.split.length <= 2 string.sub!(' and chain', '') if string =~ /ball and chain/ string =~ /(\S+) .* (\S+)/ "#{Regexp.last_match(1)} #{Regexp.last_match(2)}" end |
.fix_standing ⇒ void
This method returns an undefined value.
Fixes the player’s standing state if they are not standing.
517 518 519 520 521 522 523 |
# File 'documented/dragonrealms/commons/common.rb', line 517 def fix_standing loop do break if standing? bput('stand', 'You stand', 'You are so unbalanced', 'As you stand', 'You are already', 'weight of all your possessions', 'You are overburdened and cannot', 'You\'re unconscious', 'You swim back up into a vertical position', "You don't seem to be able to move to do that", 'prevents you from standing', 'You\'re plummeting to your death', 'There\'s no room to do much of anything here') end end |
.forage?(item, tries = 5) ⇒ Boolean
Attempts to forage for an item in the environment.
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'documented/dragonrealms/commons/common.rb', line 178 def forage?(item, tries = 5) snapshot = "#{right_hand}#{left_hand}" while snapshot == "#{right_hand}#{left_hand}" tries > 0 ? tries -= 1 : (return false) case bput("forage #{item}", 'Roundtime', 'The room is too cluttered to find anything here', 'You really need to have at least one hand free to forage properly', 'You survey the area and realize that any foraging efforts would be futile') when 'The room is too cluttered to find anything here' return false unless kick_pile? when 'You survey the area and realize that any foraging efforts would be futile' return false when 'You really need to have at least one hand free to forage properly' echo 'WARNING: hands not emptied properly. Stowing...' fput('stow right') end waitrt? end true end |
.get_gems(container) ⇒ Object
279 280 281 |
# File 'documented/dragonrealms/commons/common.rb', line 279 def get_gems(container) rummage('G', container) end |
.get_materials(container) ⇒ Object
283 284 285 |
# File 'documented/dragonrealms/commons/common.rb', line 283 def get_materials(container) rummage('M', container) end |
.get_noun(long_name) ⇒ String
Extracts the noun from a long name, removing any flavor text.
365 366 367 |
# File 'documented/dragonrealms/commons/common.rb', line 365 def get_noun(long_name) remove_flavor_text(long_name).strip.scan(/[a-z\-']+$/i).first end |
.get_skins(container) ⇒ Object
275 276 277 |
# File 'documented/dragonrealms/commons/common.rb', line 275 def get_skins(container) rummage('S', container) end |
.get_town_name(text) ⇒ String?
Looks up the canonical name of the town based on the given text. Utility to help identify the canonical town name based on arbitrary text. For example, “Theren” for “Therenborough” and “Haven” for “Riverhaven”. It also handles missing apostrophes and the occasional space between names like “merkresh” or “Mer’Kresh” or “ainghazal” or “Ain Ghazal”. Returns nil if unable to find a match. Looks up the canonical name of the town based on the given text.
494 495 496 497 498 499 500 501 502 |
# File 'documented/dragonrealms/commons/common.rb', line 494 def get_town_name(text) towns = $HOMETOWN_REGEX_MAP.select { |_town, regex| regex =~ text }.keys if towns.length > 1 DRC.("Found multiple towns that match '#{text}': #{towns}") DRC.("Using first town that matched: #{towns.first}") DRC.("To avoid ambiguity, please use the town's full name: https://elanthipedia.play.net/Category:Cities") end towns.first end |
.hide?(hide_type = 'hide') ⇒ Boolean
Attempts to hide the player if they are not already hiding.
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 |
# File 'documented/dragonrealms/commons/common.rb', line 584 def hide?(hide_type = 'hide') unless hiding? case bput(hide_type, 'Roundtime', 'too busy performing', 'can\'t see any place to hide yourself', 'Stalk what', 'You\'re already stalking', 'Stalking is an inherently stealthy', 'You haven\'t had enough time', 'You search but find no place to hide') when 'too busy performing' bput('stop play', 'You stop playing', 'In the name of') return hide?(hide_type) when "You're already stalking" put 'stop stalk' return hide?(hide_type) when 'You haven\'t had enough time' pause 1 return hide?(hide_type) end pause waitrt? end hiding? end |
.kick_pile?(item = 'pile') ⇒ Boolean
Kicks a pile to see if any items can be found.
241 242 243 244 245 |
# File 'documented/dragonrealms/commons/common.rb', line 241 def kick_pile?(item = 'pile') fix_standing return unless DRRoom.room_objs.any? { |room_obj| room_obj.match?(/pile/) } bput("kick #{item}", 'I could not find', 'take a step back and run up to', 'Now what did the .* ever do to you', 'You lean back and kick your feet,') == 'take a step back and run up to' end |
.left_hand ⇒ String?
Returns the name of the item in the left hand.
621 622 623 |
# File 'documented/dragonrealms/commons/common.rb', line 621 def left_hand GameObj.left_hand.name == 'Empty' ? nil : fix_dr_bullshit(GameObj.left_hand.name) end |
.left_hand_noun ⇒ String?
Returns the noun of the item in the left hand.
637 638 639 |
# File 'documented/dragonrealms/commons/common.rb', line 637 def left_hand_noun GameObj.left_hand == 'Empty' ? nil : GameObj.left_hand.noun end |
.list_to_array(list) ⇒ Array
Take a game formatted list “an arrow, silver coins and a deobar strongbox” And return an array [“an arrow”, “silver coins”, “a deobar strongbox”] is this ever useful compared to the list_to_nouns? Converts a game formatted list into an array of items.
295 296 297 |
# File 'documented/dragonrealms/commons/common.rb', line 295 def list_to_array(list) list.strip.split(/(?:,|(?:, |\s)?and\s?)(?:\s?<pushBold\/>\s?)?(?=\s\ba\b|\s\ban\b|\s\bsome\b|\s\bthe\b)/i).reject(&:empty?) end |
.list_to_nouns(list) ⇒ Array
Take a game formatted list “an arrow, silver coins and a deobar strongbox” And return an array of nouns [“arrow”, “coins”, “strongbox”] Converts a game formatted list into an array of nouns.
353 354 355 356 357 358 |
# File 'documented/dragonrealms/commons/common.rb', line 353 def list_to_nouns(list) list_to_array(list) .map { |long_name| get_noun(long_name) } .compact .reject { |noun| noun == '' } end |
.listen?(teacher, observe_flag = false) ⇒ Boolean
Checks if the player can listen to a teacher.
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 |
# File 'documented/dragonrealms/commons/common.rb', line 531 def listen?(teacher, observe_flag = false) return false if teacher.nil? return false if teacher.empty? bad_classes = %w[Thievery Sorcery] bad_classes += ['Life Magic', 'Holy Magic', 'Lunar Magic', 'Elemental Magic', 'Arcane Magic', 'Targeted Magic', 'Arcana', 'Attunement'] if DRStats. || DRStats.thief? bad_classes += ['Utility'] if DRStats. observe = observe_flag ? 'observe' : '' case bput("listen to #{teacher} #{observe}", 'begin to listen to \w+ teach the .* skill', 'already listening', 'could not find who', 'You have no idea', 'isn\'t teaching a class', 'don\'t have the appropriate training', 'Your teacher appears to have left', 'isn\'t teaching you anymore', 'experience differs too much from your own', 'but you don\'t see any harm in listening', 'invitation if you wish to join this class', 'You cannot concentrate to listen to .* while in combat') when /begin to listen to \w+ teach the (.*) skill/ return true if bad_classes.grep(/#{Regexp.last_match(1)}/i).empty? bput('stop listening', 'You stop listening') when 'already listening' return true when 'but you don\'t see any harm in listening' bput('stop listening', 'You stop listening') end false end |
.log_window(text, window_name, make_bold = true, create_window = false, pre_clear_window = false) ⇒ void
This method returns an undefined value.
Sends a message to the specified window. Replaces the deprecated atmo method. By default the message is bold. Creates window upon request. Pre-clears window upon request. Sends a message to the specified window.
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 |
# File 'documented/dragonrealms/commons/common.rb', line 1120 def log_window(text, window_name, make_bold = true, create_window = false, pre_clear_window = false) if create_window _respond("<streamWindow id=\"#{window_name}\" title=\"#{window_name}\" location=\"center\" save=\"true\" />") _respond("<exposeStream id=\"#{window_name}\"/>") end if pre_clear_window _respond("<clearStream id=\"#{window_name}\"/>\r\n") end _respond( "<pushStream id=\"#{window_name}\"/>" + (make_bold ? bold(text) : text), "<popStream id=\"#{window_name}\" /><prompt time=\"#{XMLData.server_time.to_i}\">></prompt>" ) end |
.message(text, make_bold = true) ⇒ void
This method returns an undefined value.
Sends a message to the game window. By default the message is bold. Sends a message to the game window.
1165 1166 1167 1168 1169 1170 1171 1172 1173 |
# File 'documented/dragonrealms/commons/common.rb', line 1165 def (text, make_bold = true) string = '' if text.index('\n') text.split('\n').each { |line| string.concat("#{line}") } else string.concat(text) end _respond(make_bold ? bold(string) : string) end |
.pause_all ⇒ Boolean
Pauses all running scripts except the current one.
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 |
# File 'documented/dragonrealms/commons/common.rb', line 974 def pause_all return false unless $pause_all_lock.try_lock @pause_all_no_unpause = [] Script.running.find_all(&:paused?).each do |script| @pause_all_no_unpause << script end Script.running.find_all do |script| !script.paused? && !script.no_pause_all && script != Script.current end .each(&:pause) pause 1 true end |
.play_song?(settings, song_list, worn = true, skip_clean = false, climbing = false, skip_tuning = false) ⇒ Boolean
Plays a song using the specified settings and song list.
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 |
# File 'documented/dragonrealms/commons/common.rb', line 755 def play_song?(settings, song_list, worn = true, skip_clean = false, climbing = false, skip_tuning = false) instrument = worn ? settings.worn_instrument : settings.instrument if UserVars.instrument.nil? ("No previous instrument setting detected. Cleaning stored song data.") UserVars.song = nil UserVars.climbing_song = nil UserVars.instrument = instrument elsif UserVars.instrument != instrument ("New instrument #{instrument} detected; old instrument: #{UserVars.instrument}. Resetting stored song data.") UserVars.song = nil UserVars.climbing_song = nil UserVars.instrument = instrument end UserVars.song = song_list.first.first unless UserVars.song UserVars.climbing_song = song_list.first.first unless UserVars.climbing_song song_to_play = climbing ? UserVars.climbing_song : UserVars.song play_command = "play #{song_to_play}" if instrument play_command = play_command + " on my #{instrument}" end fput('release ecry') if DRSpells.active_spells["Eillie's Cry"].to_i > 0 result = bput(play_command, 'too damaged to play', 'dirtiness may affect your performance', 'slightest hint of difficulty', 'fumble slightly', /Your .+ is submerged in the water/, 'You begin a', 'You struggle to begin', 'You\'re already playing a song', 'You effortlessly begin', 'You begin some', 'You cannot play', 'Play on what instrument', 'Are you sure that\'s the right instrument', 'now isn\'t the best time to be playing', 'Perhaps you should find somewhere drier before trying to play', 'You should stop practicing', /^You really need to drain/, /Your .* tuning is off, and may hinder your performance/) case result when 'Play on what instrument', 'Are you sure that\'s the right instrument' snapshot = "#{right_hand}#{left_hand}" fput("get #{instrument}") return false if snapshot == "#{right_hand}#{left_hand}" fput("wear #{instrument}") if worn play_song?(settings, song_list, worn, skip_clean, climbing, skip_tuning) when 'now isn\'t the best time to be playing', 'Perhaps you should find somewhere drier before trying to play', 'You should stop practicing' false when 'You\'re already playing a song' fput('stop play') play_song?(settings, song_list, worn, skip_clean, climbing, skip_tuning) when 'You cannot play' wait_for_script_to_complete('safe-room') when /Your .* tuning is off, and may hinder your performance/ DRC.("Instrument out of tune. Attempting to tune it.") return true if DRSkill.getrank('Performance') < 20 return true if skip_tuning return true unless DRC.tune_instrument(settings) play_song?(settings, song_list, worn, skip_clean, climbing, skip_tuning) when 'dirtiness may affect your performance', /^You really need to drain/ return true if DRSkill.getrank('Performance') < 20 return true if skip_clean return true unless clean_instrument(settings, worn) play_song?(settings, song_list, worn, skip_clean, climbing, skip_tuning) when 'slightest hint of difficulty', 'fumble slightly' true when 'You begin a', 'You effortlessly begin', 'You begin some' return true if song_to_play == song_list.to_a.last.last # Ignore difficulty messages if we have an offset return true if climbing && UserVars.climbing_song_offset UserVars.climbing_song = song_list[UserVars.climbing_song] || song_list.first.first if climbing UserVars.song = song_list[UserVars.song] || song_list.first.first unless climbing play_song?(settings, song_list, worn, skip_clean, climbing, skip_tuning) when 'You struggle to begin' return true if song_to_play == song_list.first.first # Ignore difficulty messages if we have an offset return true if climbing && UserVars.climbing_song_offset UserVars.climbing_song = song_list.first.first if climbing UserVars.song = song_list.first.first unless climbing play_song?(settings, song_list, worn, skip_clean, climbing, skip_tuning) else false end end |
.release_invisibility ⇒ void
This method returns an undefined value.
Releases any invisibility spells affecting the player.
653 654 655 656 657 658 659 660 661 662 663 664 |
# File 'documented/dragonrealms/commons/common.rb', line 653 def release_invisibility get_data('spells') .spell_data .select { |_name, properties| properties['invisibility'] } .select { |name, _properties| DRSpells.active_spells.keys.include?(name) } .map { |_name, properties| properties['abbrev'] } .each { |abbrev| fput("release #{abbrev}") } # handle khri silence as it's not part of base-spells data, and method of ending it differs from spells bput('khri stop silence', 'You attempt to relax') if DRSpells.active_spells.keys.include?('Khri Silence') bput('khri stop vanish', /^You would need to start Vanish/, /^Your control over the limited subversion of reality falters/, /^You are not trained in the Vanish meditation/) if (DRStats.guild == "Thief" && invisible?) end |
.remove_flavor_text(item) ⇒ String
Removes flavor text from an item description.
374 375 376 377 378 |
# File 'documented/dragonrealms/commons/common.rb', line 374 def remove_flavor_text(item) # link is to online regex expression tester # https://regex101.com/r/4lGY6u/13 item.sub(/\s?\b(?:(?:colorfully and )?(?:artfully|artistically|attractively|beautifully|bl?ack-|cleverly|clumsily|crudely|deeply|delicately|edged|elaborately|faintly|flamboyantly|front-|fully|gracefully|heavily|held|intricately|lavishly|masterfully|plentifully|prominantly|roughly|securely|sewn|shabbily|shadow-|simply|somberly|skillfully|sloppily|starkly|stitched|tied and|tightly|well-)\s?)?(?:accented|accentuated|acid-etched|adorned|affixed|appliqued|assembled|attached|augmented|awash|backed|back-laced|balanced|banded|batiked|beaded|bearded|bearing|bedazzled|bedecked|bejeweled|beset|bestrewn|blazoned|bordered|bound|braided|branded|brocaded|bristling|brushed|buckled|burned|buttoned|caked|camouflaged|capped|carved|caught|centered|chased|chiseled|cinched|circled|clasped|cloaked|closed|coated|cobbled together|coiled|colored|composed|concealed|connected|constructed|countoured|covered|crafted|crested|crisscrossed|crowded|crowned|cuffed|cut|dangling|dappled|decked|decorated|deformed|depicting|designed|detailed|discolored|displaying|divided|done|dotted|draped|drawn|dressed|drizzled|dusted|edged|elaborately|embedded|embell?ished|emblazed|emblazoned|embossed|embroidered(?: all over| painstakingly)?|enameled(?: across)?|encircled|encrusted|engraved|engulfed|enhanced|entwined|equipped|etched|fashioned(?: so)?|fastened|feathered|featuring|festooned|fettered|filed|filled|firestained|fit|fitted|fixed|flecked|fletched|forged|formed|framed|fringed|frosted|full|gathered|gleaming|glimmering|glittering|goldworked|growing|gypsy-set|hafted|hand-tooled|hanging|heavily(?:-beaded| covered)?|held fast|hemmed|hewn|hideously|highlighted|hilted|honed|hung|impressed|incised|ingeniously repurposed|inscribed|inlaid|inset|interlaced|interspersed|interwoven|jeweled|joined|laced(?: up)?|lacquered|laden|layered|limned|lined|linked|looped|knotted|made|marbled|marked|marred|meshed|mosaicked|mottled|mounted|oiled|oozing|outlined|ornamented|overlai(?:d|n)|padded|painted|paired|patched|pattern-welded|patterned|pinned|plumed|polished|printed|reinforced|reminiscent|rendered|revealing|riddled|ridged|rimed|ringed|riveted|sashed|scarred|scattered|scorched|sculpted|sealed|seamed|secured|securely|set|sewn|shaped|shimmering|shod|shot|shrouded|side-laced|slashed|slung|smeared|smudged|spangled|speckled|spiraled|splatter-dyed|splattered|spotted|sprinkled|stacked|surmounted|surrounded|suspended|stained|stamped|starred|stenciled|stippled|stitched(?: together)?|strapped|streaked|strengthened|strewn|striated|striped|strung|studded|swathed|swirled|tailored|tangled|tapered|tethered|textured|threaded|tied|tightly|tinged|tinted|tipped|tooled|topped|traced|trimmed|twined|veined|vivified|washed|webbed|weighted|whorled|worked|worn|woven|wrapped|wreathed|wrought)?\b ["]?\b(?:a hand-tooled|across|along|an|around|atop|bearing|belted|bright streaks|dangling|designed|detailing|down (?:each leg|one side)|dyed (?:a|and|deep|of|in|night|rust|shimmering|the|to|with)|engravings|entitled|errant pieces|featuring|flaunting|frescoed|from|Gnomish Pride|(?:encased |quartered )?in(?: the)?|into|labeled|leading|like|lining|matching|(?<!stick|slice|chunk|flask|hunk|series|set|pair|piece) of|on|out|overlayed gleaming silver|resembling|shades of color|sporting|surrounding|that|the|through|tinged somber black|titled|to|upon|WAR MONGER|with|within|\b(?:at|bearing|(?:accented |held |secured )?by|carrying|clutching|colored|cradling|dangling|depicting|(?:prominently )?displaying|embossed|etched|featuring|for(?:ming)?|holding|(?<!slice |chunk |flask |hunk |series |set |pair |piece )of|over|patterned|striped|suspending|textured|that)\b \b(?:a (?:band|beaded|brass|cascade|cluster|coral|crown|dead|.+ (?:ingot|boulder|stone|rock|nugget)|fierce|fanged|fringe|glowing|golden|grinning|howling|large|lotus|mosaic|pair|poorly|rainbow|roaring|row|silver(?:y|weave)?|small|snarling|spray|tailored|thick|tiny|trio|turquoise|yellowed)|(?:squared )?agonite (?:links|decorated)|alternating|an|(?:purple |blue )?and|ash|beaded fringe|blackened (?:steel(?: accents| bearing| with|$)|ironwood)|blue (?:gold|steel)|burnished golden|cascading layers|carved ivory|chain-lined|chitinous|(?:deep red|dull black|pale blue) cloth|cloudberry blossoms|colorful tightly|cotton candy|crimson steel|crisscrossed|curious design|curved|crystaline charm|dark (?:blue|green|grey|metals|windsteel) (?:and|exuding|glaes|hues|khor'vela|muracite|pennon|with)|dark supple|deepest|deeply blending|delicate|dusky (?:dreamweave|green-grey)|ebonwood$|emblazoned|enamel?led (?:steel|bronze)|etched|fine(?:-grained| black| crushed)|finely wrought|flame-kissed|forest|fused-together|fuzzy grey|gauze atop|gilded steel|glass eyeballs|glistening green|golden oak|grey fur|hammered|haralun|has|heavy (?:grey|pearl|silver)|horn|Ilithi cedar|inky black|interlocking silver|interwoven|iridescent|jagged interlocking plates|(?:soft dark|supple|thick|woven) (?:bolts|leather)|lightweight|long swaths|lustrous|kertig ravens|made|metal cogs|mirror-finished|mottled|multiple woods|naphtha|oak|oblong sanguine|one|onyx buttons|opposing images|overlapping|pale cerulean|pallid links|pastel-hued|pins|pitted (?:black iron|steel)|plush velvet|polished (?:bronze|hemlock|steel)|raccoon tails|ram's horns|rat pelts|raw|red and blue|rich (?:purple|golden)|riveted bindings|roughened|rowan|sanguine thornweave|scattered star|scorch marks|sculpted|shadows|shark cartilage|shifting (?:celadon|shades)|shipboard|(?:braided |cobalt |deep black |desert-tan |dusky red Taisidon |ebony |exquisite spider|fine leaf-green |flowing night|glimmering ebony |heavy |marigold |pale gold marquisette and virid |rich copper |spiral-braided |steel|unadorned black Musparan )?silk(?:cress)?|(?:coiled |shimmering )?silver(?:steel| and |y)?|sirese blue spun glitter|six crossed|slender|small bones|smoothly interlocking|snow leopard|soft brushed|somber black|sprawled|sun-bleached|steel links|stones|strips of|sunny yellow|teardrop plates|telothian|the|tiny (?:golden|indurium|scales|skull)|tightly braided|tomiek|torn|twists|two|undyed|vibrant multicolored|viscous|waves of|weighted|well-cured|white ironwood|windstorm gossamer|wintry faeweave|woven diamondwood))\b.*/, '') end |
.retreat(ignored_npcs = []) ⇒ void
This method returns an undefined value.
Attempts to retreat from combat.
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 |
# File 'documented/dragonrealms/commons/common.rb', line 688 def retreat(ignored_npcs = []) return if (DRRoom.npcs - ignored_npcs).empty? = [ /You are already as far away as you can get/, /You retreat from combat/, /You sneak back out of combat/, /Retreat to where/, /There's no place to retreat to/ ] = [ /retreat/, /sneak/, /grip on you/, /grip remains solid/, /You try to back/, /You must stand first/, /You stop advancing/, /You are already/ ] loop do case DRC.bput("retreat", *, *) when * return true else DRC.fix_standing end end end |
.right_hand ⇒ String?
Returns the name of the item in the right hand.
629 630 631 |
# File 'documented/dragonrealms/commons/common.rb', line 629 def right_hand GameObj.right_hand.name == 'Empty' ? nil : fix_dr_bullshit(GameObj.right_hand.name) end |
.right_hand_noun ⇒ String?
Returns the noun of the item in the right hand.
645 646 647 |
# File 'documented/dragonrealms/commons/common.rb', line 645 def right_hand_noun GameObj.right_hand == 'Empty' ? nil : GameObj.right_hand.noun end |
.rummage(parameter, container) ⇒ Array
Rummages through a container for a specified parameter.
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'documented/dragonrealms/commons/common.rb', line 253 def rummage(parameter, container) result = DRC.bput("rummage /#{parameter} my #{container}", 'but there is nothing in there like that\.', 'looking for .* and see .*', 'While it\'s closed', 'I don\'t know what you are referring to', 'You feel about', 'That would accomplish nothing') case result when 'You feel about' release_invisibility return rummage(parameter, container) when 'but there is nothing in there like that.', 'While it\'s closed', 'I don\'t know what you are referring to', 'That would accomplish nothing' return [] end text = result.match(/looking for .* and see (.*)\.$/).to_a[1] case parameter when 'B' box_list_to_adj_and_noun(text) when 'SC' scroll_list_to_adj_and_noun(text) else list_to_nouns(text) end end |
.safe_pause_list ⇒ Array
Safely pauses all scripts that can be paused.
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 |
# File 'documented/dragonrealms/commons/common.rb', line 1041 def safe_pause_list return false unless $safe_pause_lock.try_lock paused_script_list = [] Script.running.find_all { |s| !s.paused? && !s.no_pause_all && s.name != Script.self.name }.each do |s| s.pause paused_script_list << s.name end echo("Pausing #{paused_script_list} to run #{Script.self.name}") return paused_script_list end |
.safe_unpause_list(scripts_to_unpause) ⇒ void
This method returns an undefined value.
Safely unpauses a list of specified scripts.
1058 1059 1060 1061 1062 1063 1064 |
# File 'documented/dragonrealms/commons/common.rb', line 1058 def safe_unpause_list(scripts_to_unpause) return false unless $safe_pause_lock.owned? echo("Unpausing #{scripts_to_unpause}, #{Script.self.name} has finished.") Script.running.find_all { |s| s.paused? && !s.no_pause_all && scripts_to_unpause.include?(s.name) }.each(&:unpause) $safe_pause_lock.unlock end |
.scroll_list_to_adj_and_noun(list) ⇒ Array
Converts a formatted list of scrolls into an array of adjectives and nouns.
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'documented/dragonrealms/commons/common.rb', line 319 def scroll_list_to_adj_and_noun(list) list_to_array(list).map { |entry| entry .sub(/(an|some|a(?: piece of)?)\s/, '') .sub(/\slabeled with.*/, '') .sub(/icy blue vellum scroll/, 'icy scroll') .sub(/green vellum scroll/, 'green scroll') .sub(/fetid antelope vellum/, 'antelope vellum') .sub(/papyrus roll/, 'papyrus.roll') .sub(/pallid red scroll/, 'pallid scroll') .sub(/\s(bark|leaf|ostracon|papyrus|parchment|roll|scroll|tablet|vellum|manuscript)\s.*/, ' \1') .sub(/crumpled paper/, 'crumpled') .sub(/pale ricepaper/, 'pale') .sub(/stormy grey/, 'stormy') .sub(/mossy green/, 'mossy') .sub(/dark purple/, 'dark') .sub(/vibrant red/, 'vibrant') .sub(/bright green/, 'bright') .sub(/icy blue/, 'blue') .sub(/pearl-white silk/, 'silk') .sub(/ghostly white/, 'white') .sub(/crinkled violet/, 'crinkled') .sub(/drawing paper/, 'drawing') .strip } end |
.set_stance(skill) ⇒ void
This method returns an undefined value.
Sets the player’s stance based on their skill level.
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 |
# File 'documented/dragonrealms/commons/common.rb', line 1071 def set_stance(skill) div = if DRStats.guild == 'Paladin' 50 elsif %w[Barbarian Ranger Trader Commoner].include?(DRStats.guild) 60 else 70 end points = 80 + DRSkill.getrank('Defending') / div secondary = points > 100 ? 100 : points tertiary = points > 100 ? points - 100 : 0 stance = case skill.downcase when 'parry' "100 #{secondary} #{tertiary}" when 'shield' "100 #{tertiary} #{secondary}" else "100 #{secondary} #{tertiary}" end DRC.bput("stance set #{stance}", /Setting your/) end |
.smart_pause_all ⇒ Array
Smartly pauses all scripts that can be paused.
1017 1018 1019 1020 1021 1022 1023 1024 1025 |
# File 'documented/dragonrealms/commons/common.rb', line 1017 def smart_pause_all paused_script_list = [] Script.running.find_all { |s| !s.paused? && !s.no_pause_all && s.name != Script.self.name }.each do |s| s.pause paused_script_list << s.name end echo("Pausing #{paused_script_list} to run #{Script.self.name}") return paused_script_list end |
.stop_playing ⇒ void
This method returns an undefined value.
Stops the currently playing song.
835 836 837 |
# File 'documented/dragonrealms/commons/common.rb', line 835 def bput('stop play', 'You stop playing your song', 'In the name of', "But you're not performing") end |
.text2num(text_num) ⇒ Integer?
Converts a text representation of a number into an integer.
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 |
# File 'documented/dragonrealms/commons/common.rb', line 725 def text2num(text_num) text_num = text_num.tr('-', ' ') split_words = text_num.split(' ') g = 0 split_words.each do |word| x = $NUM_MAP.fetch(word, nil) if word.eql?('hundred') && (g != 0) g *= 100 elsif x.nil? echo 'Unknown number' return nil else g += x end end g end |
.tune_instrument(settings) ⇒ Boolean
Tunes the instrument to ensure it is in proper condition.
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 |
# File 'documented/dragonrealms/commons/common.rb', line 904 def tune_instrument(settings) instrument = settings.worn_instrument || settings.instrument unless instrument DRC.("Neither worn_instrument, nor instrument set. Doing nothing.") return false end DRC. unless (DRC.left_hand.nil? && DRC.right_hand.nil?) || DRCI.in_hands?(instrument) DRC.("Need two free hands. Not tuning now.") return false end if settings.worn_instrument unless DRCI.remove_item?(instrument) || DRCI.in_hands?(instrument) DRC.("Could not remove #{instrument}. Not trying to tune.") DRC.beep return false end else unless DRCI.get_item?(instrument) || DRCI.in_hands?(instrument) DRC.("Could not get #{instrument}. Not trying to tune.") DRC.beep return false end end DRC.do_tune(instrument) waitrt? pause 1 DRCI.wear_item?(instrument) if settings.worn_instrument true end |
.unpause_all ⇒ Boolean
Unpauses all previously paused scripts.
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 |
# File 'documented/dragonrealms/commons/common.rb', line 998 def unpause_all return false unless $pause_all_lock.owned? Script.running.find_all do |script| script.paused? && !@pause_all_no_unpause.include?(script) end .each(&:unpause) @pause_all_no_unpause = [] $pause_all_lock.unlock true end |
.unpause_all_list(scripts_to_unpause) ⇒ void
This method returns an undefined value.
Unpauses a list of specified scripts.
1032 1033 1034 1035 |
# File 'documented/dragonrealms/commons/common.rb', line 1032 def unpause_all_list(scripts_to_unpause) echo("Unpausing #{scripts_to_unpause}, #{Script.self.name} has finished.") Script.running.find_all { |s| s.paused? && !s.no_pause_all && scripts_to_unpause.include?(s.name) }.each(&:unpause) end |
.wait_for_script_to_complete(name, args = [], flags = {}) ⇒ Object
Waits for a script to complete before proceeding.
145 146 147 148 149 150 151 152 153 |
# File 'documented/dragonrealms/commons/common.rb', line 145 def wait_for_script_to_complete(name, args = [], flags = {}) verify_script(name) script_handle = start_script(name, args.map { |arg| arg.to_s =~ /\s/ ? "\"#{arg}\"" : arg }, flags) if script_handle pause 2 pause 0.5 while Script.running.include?(script_handle) end script_handle end |