Top Level Namespace
- Includes:
- Win32
Defined Under Namespace
Modules: Lich, SessionVars, Win32, Wine Classes: MatchData, NilClass, Numeric, String
Constant Summary collapse
- HAVE_GTK =
false
- DELETE_CANDIDATES =
only keep the last 20 debug files
%r[^debug(?:-\d+)+\.log$]
- LICH_VERSION =
The current version of the Lich software.
'5.12.0-beta.2'
- REQUIRED_RUBY =
The minimum required Ruby version for Lich.
'2.6'
- RECOMMENDED_RUBY =
The recommended Ruby version for optimal performance with Lich.
'3.2'
- TESTING =
Indicates whether the application is in testing mode
false
- DIRMAP =
Mapping of direction abbreviations to their corresponding codes
{ 'out' => 'K', 'ne' => 'B', 'se' => 'D', 'sw' => 'F', 'nw' => 'H', 'up' => 'I', 'down' => 'J', 'n' => 'A', 'e' => 'C', 's' => 'E', 'w' => 'G', }
- SHORTDIR =
Mapping of full direction names to their abbreviations
{ 'out' => 'out', 'northeast' => 'ne', 'southeast' => 'se', 'southwest' => 'sw', 'northwest' => 'nw', 'up' => 'up', 'down' => 'down', 'north' => 'n', 'east' => 'e', 'south' => 's', 'west' => 'w', }
- LONGDIR =
Mapping of direction abbreviations to their full names
{ 'out' => 'out', 'ne' => 'northeast', 'se' => 'southeast', 'sw' => 'southwest', 'nw' => 'northwest', 'up' => 'up', 'down' => 'down', 'n' => 'north', 'e' => 'east', 's' => 'south', 'w' => 'west', }
- MINDMAP =
Mapping of mental state descriptions to their corresponding codes
{ 'clear as a bell' => 'A', 'fresh and clear' => 'B', 'clear' => 'C', 'muddled' => 'D', 'becoming numbed' => 'E', 'numbed' => 'F', 'must rest' => 'G', 'saturated' => 'H', }
- ICONMAP =
Mapping of icon names to their corresponding codes
{ 'IconKNEELING' => 'GH', 'IconPRONE' => 'G', 'IconSITTING' => 'H', 'IconSTANDING' => 'T', 'IconSTUNNED' => 'I', 'IconHIDDEN' => 'N', 'IconINVISIBLE' => 'D', 'IconDEAD' => 'B', 'IconWEBBED' => 'C', 'IconJOINED' => 'P', 'IconBLEEDING' => 'O', }
Constants included from Win32
Win32::HKEY_LOCAL_MACHINE, Win32::IDICANCEL, Win32::IDINO, Win32::IDIOK, Win32::IDIYES, Win32::KEY_ALL_ACCESS, Win32::KEY_CREATE_SUB_KEY, Win32::KEY_ENUMERATE_SUB_KEYS, Win32::KEY_EXECUTE, Win32::KEY_NOTIFY, Win32::KEY_QUERY_VALUE, Win32::KEY_READ, Win32::KEY_SET_VALUE, Win32::KEY_WOW64_32KEY, Win32::KEY_WOW64_64KEY, Win32::KEY_WRITE, Win32::MB_ICONERROR, Win32::MB_ICONQUESTION, Win32::MB_ICONWARNING, Win32::MB_OK, Win32::MB_OKCANCEL, Win32::MB_YESNO, Win32::PROCESS_QUERY_INFORMATION, Win32::PROCESS_VM_READ, Win32::REG_BINARY, Win32::REG_DWORD, Win32::REG_DWORD_BIG_ENDIAN, Win32::REG_DWORD_LITTLE_ENDIAN, Win32::REG_EXPAND_SZ, Win32::REG_LINK, Win32::REG_MULTI_SZ, Win32::REG_NONE, Win32::REG_QWORD, Win32::REG_QWORD_LITTLE_ENDIAN, Win32::REG_SZ, Win32::SEE_MASK_NOCLOSEPROCESS, Win32::SIZEOF_CHAR, Win32::SIZEOF_LONG, Win32::STILL_ACTIVE, Win32::SW_SHOW, Win32::SW_SHOWNORMAL, Win32::TOKEN_QUERY, Win32::TokenElevation
Instance Method Summary collapse
-
#_echo(*messages) ⇒ nil
Sends messages to the current script’s response handler, using a different response method.
-
#_respond(first = "", *messages) ⇒ void
Responds to the client with the provided messages, similar to ‘respond` but with a different internal handling.
-
#abort! ⇒ void
Aborts the current script execution.
-
#activate ⇒ void
Connects the activate event for the password entry.
-
#alias_deprecated ⇒ void
(also: #reallybleeding?)
Displays a deprecation warning for the alias command.
-
#before_dying(&code) ⇒ void
Registers a block of code to be executed when the script is exiting.
-
#bin2dec(n) ⇒ Integer
Converts a binary string to a decimal number.
-
#bound? ⇒ Boolean
Checks if the player is currently bound.
-
#calmed? ⇒ Boolean
Checks if the player is currently calmed.
-
#cast(spell, target = nil, results_of_interest = nil) ⇒ Boolean
Casts a spell on a target.
-
#check_mind(string = nil) ⇒ Boolean, String
Checks the mental state of the character.
-
#checkarea(*strings) ⇒ String, Boolean
Checks if the current area matches any of the provided strings.
-
#checkbleeding ⇒ Boolean
(also: #bleeding?)
Checks if the character is bleeding.
-
#checkbound ⇒ Boolean
Checks if the player is currently bound.
-
#checkbounty ⇒ Object?
(also: #bounty?)
Checks if there is a current bounty task.
-
#checkcalmed ⇒ Boolean
Checks if the player is currently calmed.
-
#checkcastrt ⇒ Float
Checks the remaining cast roundtime.
-
#checkcutthroat ⇒ Boolean
Checks if the player is currently cutthroat.
-
#checkdead ⇒ Boolean
(also: #dead?)
Checks if the character is dead.
-
#checkdisease ⇒ Boolean
(also: #diseased?)
Checks if the character is diseased.
-
#checkencumbrance(string = nil) ⇒ String, ...
(also: #encumbrance?)
Checks the current encumbrance or compares it against a given string or value.
-
#checkfamarea(*strings) ⇒ String, Boolean
Checks the current familiar area or compares it against a given string.
-
#checkfamnpcs(*strings) ⇒ Array<String>, Boolean
Checks the current familiar NPCs or compares them against a given list of strings.
-
#checkfampaths(dir = "none") ⇒ Boolean, Array<String>
Checks the available paths for the familiar in the specified direction.
-
#checkfampcs(*strings) ⇒ Array<String>, Boolean
Checks the current familiar PCs or compares them against a given list of strings.
-
#checkfamroom(*strings) ⇒ String, Boolean
Checks the current familiar room or compares it against a given string.
-
#checkfamroomdescrip(*val) ⇒ Integer?
Checks the familiar room description for a match with the provided values.
-
#checkfried ⇒ Boolean
(also: #fried?)
Checks if the character’s mind state indicates they must rest.
-
#checkgrouped ⇒ Boolean
(also: #joined?, #checkjoined, #group?)
Checks if the character is grouped.
-
#checkhealth(num = nil) ⇒ Integer, Boolean
(also: #health, #health?)
Checks the current health value or compares it to a given number.
-
#checkhidden ⇒ Boolean
(also: #hiding?, #hidden?, #hidden, #checkhiding)
Checks if the character is hidden.
-
#checkinvisible ⇒ Boolean
(also: #invisible?)
Checks if the character is invisible.
-
#checkkneeling ⇒ Boolean
(also: #kneeling?)
Checks if the character is kneeling.
-
#checkleft(*hand) ⇒ String?
(also: #lefthand?, #lefthand)
Checks the left hand for a matching instance from the provided hand.
-
#checkloot ⇒ Array<String>
Collects the loot items from the game object.
-
#checkmana(num = nil) ⇒ Integer, Boolean
(also: #mana, #mana?)
Checks the current mana value or compares it to a given number.
-
#checkmind(string = nil) ⇒ Boolean?
(also: #mind?)
Checks the mental state of the character with a different approach.
-
#checkname(*strings) ⇒ Boolean, String
(also: #myname?)
Checks if the character’s name matches any of the provided strings.
-
#checknotstanding ⇒ Boolean
Checks if the character is not standing.
-
#checknpcs(*strings) ⇒ Array<String>, Boolean
Checks the current NPCs or compares them against a given list of strings.
-
#checkpaths(dir = "none") ⇒ Array, Boolean
Checks if a given direction is valid based on the room exits.
-
#checkpcs(*strings) ⇒ Array<String>, Boolean
Checks the current PCs or compares them against a given list of strings.
-
#checkpoison ⇒ Boolean
(also: #poisoned?)
Checks if the character is poisoned.
-
#checkprep(spell = nil) ⇒ Boolean, String
(also: #prepped?, #checkprepared)
Checks the prepared spell status.
-
#checkprone ⇒ Boolean
Checks if the character is prone.
-
#checkreallybleeding ⇒ Boolean
Checks if the character is really bleeding, considering active spells.
-
#checkright(*hand) ⇒ String?
(also: #righthand?, #righthand)
Checks the right hand for a matching instance from the provided hand.
-
#checkroom(*strings) ⇒ String, Boolean
Checks if the current room matches any of the provided strings.
-
#checkroomdescrip(*val) ⇒ Integer?
(also: #roomdescription?)
Checks the room description for a match with the provided values.
-
#checkrt ⇒ Float
Checks the remaining roundtime.
-
#checksaturated ⇒ Boolean
(also: #saturated?)
Checks if the character’s mind state is saturated.
-
#checksilenced ⇒ Boolean
Checks if the player is currently silenced.
-
#checksitting ⇒ Boolean
(also: #sitting?)
Checks if the character is sitting.
-
#checksleeping ⇒ Boolean
Checks if the player is currently sleeping.
-
#checkspell(*spells) ⇒ Boolean
(also: #active?, #checkactive)
Checks if all provided spells are currently active.
-
#checkspirit(num = nil) ⇒ Integer, Boolean
(also: #spirit, #spirit?)
Checks the current spirit value or compares it to a given number.
-
#checkstamina(num = nil) ⇒ Integer, Boolean
(also: #stamina, #stamina?)
Checks the current stamina or compares it against a given threshold.
-
#checkstance(num = nil) ⇒ String, ...
(also: #stance?, #stance)
Checks the current stance or compares it against a given threshold.
-
#checkstanding ⇒ Boolean
(also: #standing?)
Checks if the character is standing.
-
#checkstunned ⇒ Boolean
(also: #stunned?)
Checks if the character is stunned.
-
#checkwebbed ⇒ Boolean
(also: #webbed?)
Checks if the character is webbed.
-
#clear(_opt = 0) ⇒ Array
Clears the downstream buffer of the current script.
-
#clicked ⇒ void
Connects the click event for the play button.
-
#count_npcs ⇒ Integer
Counts the number of current NPCs.
-
#cutthroat? ⇒ Boolean
Checks if the player is currently cutthroat.
-
#d ⇒ String
The string ‘down’.
-
#debug(*args) {|Array| ... } ⇒ Object
Outputs debug information if debugging is enabled.
-
#dec2bin(n) ⇒ String
Converts a decimal number to a binary string.
-
#die_with_me(*vals) ⇒ nil
Registers scripts to die with the current script.
-
#do_client(client_string) ⇒ nil
Processes a client command string, executing the appropriate action based on the command.
-
#dothis(action, success_line) ⇒ String
Executes a given action and waits for a success line in the output.
-
#dothistimeout(action, timeout, success_line) ⇒ String?
Inserts a timeout mechanism for executing an action and waiting for a success line.
-
#down ⇒ String
The string ‘down’.
-
#e ⇒ String
The string ‘east’.
-
#echo(*messages) ⇒ nil
Sends messages to the current script’s response handler.
-
#echo_off ⇒ void?
Turns off echo for the current script.
-
#echo_on ⇒ void?
Turns on echo for the current script.
-
#empty_hand ⇒ void
Empties the hand that is less full based on the current state of the character’s hands.
-
#empty_hands ⇒ void
Empties both hands by calling the stash method.
-
#empty_left_hand ⇒ void
Empties the left hand by calling the stash method.
-
#empty_right_hand ⇒ void
Empties the right hand by calling the stash method.
-
#fb_to_sf(line) ⇒ String?
Converts a line from the front-end format to a server-friendly format.
-
#fetchloot(userbagchoice = UserVars.lootsack) ⇒ Boolean
Fetches loot from the game object and places it into the user’s bag.
-
#fill_hand ⇒ void
Fills the hand based on the current state of the character’s hands.
-
#fill_hands ⇒ void
Fills both hands by calling the equip method.
-
#fill_left_hand ⇒ void
Fills the left hand by calling the equip method.
-
#fill_right_hand ⇒ void
Fills the right hand by calling the equip method.
-
#fix_injury_mode ⇒ void
Fixes the injury mode in the game if it is not set to 2.
-
#force_start_script(script_name, cli_vars = [], flags = {}) ⇒ void
Forces the start of a script, ensuring it runs even if it is already running.
-
#fput(message, *waitingfor) ⇒ String, false
(also: #forceput)
Sends a message to the script and waits for a response.
-
#get ⇒ String
Retrieves a line of input from the current script.
-
#get? ⇒ Boolean
Checks if there is a line of input available from the current script.
-
#goto(label) ⇒ void
Jumps to a specified label in the current script.
-
#hide_me ⇒ void
Toggles the visibility of the current script.
-
#hide_script(*args) ⇒ void
Hides or shows the specified scripts by name.
-
#i_stand_alone ⇒ Boolean?
Toggles the downstream setting for the current script.
-
#idle?(time = 60) ⇒ Boolean
Checks if the character has been idle for a specified time.
-
#key_exists?(path) ⇒ Boolean
Checks if a registry key exists at the given path.
-
#match(label, string) ⇒ String, false
Matches a label and string against the game line queue.
-
#matchafter(*strings) ⇒ String, false
Matches a string after a specified condition.
-
#matchbefore(*strings) ⇒ String, false
Matches a string before a specified condition.
-
#matchboth(*strings) ⇒ Array<String>
Matches any of the provided strings in the input until a match is found.
-
#matchfind(*strings) ⇒ String+
Matches input against the provided strings and captures groups.
-
#matchfindexact(*strings) ⇒ String, ...
Matches input exactly against the provided strings.
-
#matchfindword(*strings) ⇒ String+
Matches input against the provided words and captures groups.
-
#matchtimeout(secs, *strings) ⇒ String, false
Waits for a match within a specified timeout period.
-
#matchwait(*strings) ⇒ String?
Waits for a line of input that matches any of the provided strings.
-
#maxconcentration ⇒ Integer
Retrieves the maximum concentration value.
-
#maxhealth ⇒ Integer
Returns the maximum health value.
-
#maxmana ⇒ Integer
(also: #max_mana)
Returns the maximum mana value.
-
#maxspirit ⇒ Integer
Returns the maximum spirit value.
-
#maxstamina ⇒ Integer
Retrieves the maximum stamina value.
-
#monsterbold_end ⇒ String
Returns the end sequence for bold text based on the frontend type.
-
#monsterbold_start ⇒ String
Returns the start sequence for bold text based on the frontend type.
-
#move(dir = 'none', giveup_seconds = 10, giveup_lines = 30) ⇒ Boolean?
Moves the character in the specified direction.
-
#muckled? ⇒ Boolean
Checks if the character is muckled based on the game type.
-
#multifput(*cmds) ⇒ void
Sends multiple commands to the script.
-
#multimove(*dirs) ⇒ void
Moves the character in the specified directions.
-
#n ⇒ String
The string ‘north’.
-
#ne ⇒ String
The string ‘northeast’.
-
#no_kill_all ⇒ void
Toggles the no_kill_all setting for the current script.
-
#no_pause_all ⇒ void
Toggles the no_pause_all setting for the current script.
-
#noded_pulse ⇒ Integer
Calculates the pulse value for a noded character based on their profession and game state.
-
#nw ⇒ String
The string ‘northwest’.
-
#o ⇒ String
The string ‘out’.
-
#out ⇒ String
The string ‘out’.
-
#outside? ⇒ Boolean
(also: #checkoutside)
Checks if the player is currently outside based on room exits.
-
#parse_list(string) ⇒ Array<String>
Parses a string into a list.
-
#pause(num = 1) ⇒ nil
Pauses execution for a specified duration.
-
#pause_script(*names) ⇒ void
(also: #pause_scripts)
Pauses the specified scripts by name.
-
#percentconcentration(num = nil) ⇒ Integer, Boolean
Calculates the percentage of concentration based on current and maximum concentration values.
-
#percentencumbrance(num = nil) ⇒ Integer, Boolean
Calculates the percentage of encumbrance based on current encumbrance value.
-
#percenthealth(num = nil) ⇒ Integer, Boolean
Checks the percentage of current health relative to maximum health.
-
#percentmana(num = nil) ⇒ Integer, Boolean
Checks the percentage of current mana relative to maximum mana.
-
#percentmind(num = nil) ⇒ Integer, Boolean
Checks the current mind value or compares it to a given number.
-
#percentspirit(num = nil) ⇒ Integer, Boolean
Calculates the percentage of spirit based on current and maximum spirit values.
-
#percentstamina(num = nil) ⇒ Integer, Boolean
Calculates the percentage of stamina based on current and maximum stamina values.
-
#percentstance(num = nil) ⇒ Integer, Boolean
Retrieves the current stance value or compares it against a given threshold.
-
#put(*messages) ⇒ void
Sends messages to the game output.
-
#quiet_exit ⇒ void
Toggles the quiet mode of the current script.
-
#reget(*lines) ⇒ Array<String>?
Retrieves lines of input based on the provided criteria.
-
#regetall(*lines) ⇒ Array<String>?
Retrieves all lines of input based on the provided criteria.
-
#report_errors(&block) ⇒ nil
Reports errors that occur during the execution of the given block.
-
#respond(first = "", *messages) ⇒ void
Responds to the client with the provided messages.
-
#reverse_direction(dir) ⇒ String, Boolean
Reverses a given direction.
-
#run ⇒ nil
Runs the walk method in a loop until it returns false.
-
#running?(*snames) ⇒ Boolean
Checks if the specified scripts are currently running.
-
#s ⇒ String
The string ‘south’.
-
#se ⇒ String
The string ‘southeast’.
-
#selectput(string, success, failure, timeout = nil) ⇒ String?
Sends a command and waits for a response, handling success and failure cases.
-
#send_scripts(*messages) ⇒ Boolean
(also: #send_script)
Sends messages to downstream scripts.
-
#send_to_script(*values) ⇒ Boolean
Sends values to a script that matches the first value.
-
#setpriority(val = nil) ⇒ Integer
(also: #priority?)
Sets the priority of the current thread.
-
#sf_to_wiz(line) ⇒ String?
Converts a line from server format to wizard format.
-
#silence_me ⇒ Boolean?
Toggles the silent mode for the current script.
-
#silenced? ⇒ Boolean
Checks if the player is currently silenced.
-
#sleeping? ⇒ Boolean
Checks if the player is currently sleeping.
-
#start_exec_script(cmd_data, options = Hash.new) ⇒ void
Starts an execution script with the given command data and options.
-
#start_script(script_name, cli_vars = [], flags = Hash.new) ⇒ void
Starts a script with the given name and optional command line variables and flags.
-
#start_scripts(*script_names) ⇒ void
Starts multiple scripts sequentially.
-
#status_tags(onoff = "none") ⇒ void
(also: #toggle_status)
Inserts status tags for the current script based on the provided on/off parameter.
-
#stop_script(*target_names) ⇒ Integer, false
(also: #stop_scripts, #kill_scripts, #kill_script)
Stops the specified scripts by name.
-
#strip_xml(line, type: 'main') ⇒ String?
Strips XML tags from a line based on the specified type.
-
#survivedisease? ⇒ Boolean
Checks if the character can survive disease.
-
#survivepoison? ⇒ Boolean
Checks if the character can survive poison.
-
#sw ⇒ String
The string ‘southwest’.
-
#take(*items) ⇒ void
Takes items and places them into the user’s bag.
-
#timetest(*contestants) ⇒ Array<Float>
Times the execution of provided code blocks.
-
#toggle_echo ⇒ void?
Toggles the echo setting for the current script.
-
#toggle_unique ⇒ nil
Toggles the unique downstream setting for the current script.
-
#toggle_upstream ⇒ void?
Toggles the upstream setting for the current script.
-
#u ⇒ String
The string ‘up’.
-
#undo_before_dying ⇒ void
Clears any previously registered exit procedures.
-
#unique_get ⇒ String?
Retrieves a unique line from the current script’s unique input.
-
#unique_get? ⇒ Boolean?
Checks if there is a unique line available from the current script’s unique input.
-
#unique_send_to_script(*values) ⇒ Boolean
Sends unique values to a script that matches the first value.
-
#unique_waitfor(*strings) ⇒ String
Waits for a unique line from the current script’s unique input.
-
#unnoded_pulse ⇒ Integer
Calculates the pulse value for an unnoded character based on their profession and game state.
-
#unpause_script(*names) ⇒ void
(also: #unpause_scripts)
Unpauses the specified scripts by name.
-
#up ⇒ String
The string ‘up’.
-
#upstream_get ⇒ Boolean?
Retrieves upstream data for the current script.
-
#upstream_get? ⇒ Boolean?
Checks if the current script is set to receive upstream data.
-
#upstream_waitfor(*strings) ⇒ String, false
Waits for a line from the upstream that matches any of the provided strings.
-
#variable ⇒ Hash?
Retrieves the variables of the current script.
-
#w ⇒ String
The string ‘west’.
-
#wait ⇒ String
Waits for a line of input and clears the script’s buffer.
-
#wait_until(announce = nil) {|Boolean| ... } ⇒ nil
Waits until a condition is met, optionally announcing the status.
-
#wait_while(announce = nil) {|Boolean| ... } ⇒ nil
Waits while a condition is true, optionally announcing the status.
-
#waitcastrt ⇒ void
Waits for cast roundtime to complete.
-
#waitcastrt? ⇒ Boolean
Waits for cast roundtime to complete and returns whether it was successful.
-
#waitfor(*strings) ⇒ String, false
Waits for a line of input that matches any of the provided strings.
-
#waitforre(regexp) ⇒ nil
Waits for a line of input that matches the provided regular expression.
-
#waitrt ⇒ void
Waits for roundtime to complete.
-
#waitrt? ⇒ Boolean
Waits for roundtime to complete and returns whether it was successful.
-
#walk(*boundaries) {|Boolean| ... } ⇒ Object
Walks through boundaries until a condition is met.
-
#watchhealth(value, theproc = nil) {|Proc| ... } ⇒ nil
Watches the health of a character and executes a block or proc when health is no longer valid.
Methods included from Win32
AdminShellExecute, CreateProcess, GetCurrentProcess, GetExitCodeProcess, GetLastError, GetModuleFileName, GetTokenInformation, GetVersionEx, MessageBox, OpenProcessToken, RegCloseKey, RegDeleteValue, RegOpenKeyEx, RegQueryValueEx, RegSetValueEx, ShellExecute, ShellExecuteEx, admin?, isXP?
Instance Method Details
#_echo(*messages) ⇒ nil
Sends messages to the current script’s response handler, using a different response method.
265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/global_defs.rb', line 265 def _echo(*) _respond if .empty? if (script = Script.current) unless script.no_echo .each { || _respond("[#{script.name}: #{.to_s.chomp}]") } end else .each { || _respond("[(unknown script): #{.to_s.chomp}]") } end nil end |
#_respond(first = "", *messages) ⇒ void
This method returns an undefined value.
Responds to the client with the provided messages, similar to ‘respond` but with a different internal handling.
2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 |
# File 'lib/global_defs.rb', line 2703 def _respond(first = "", *) str = '' begin if first.class == Array first.flatten.each { |ln| str += sprintf("%s\r\n", ln.to_s.chomp) } else str += sprintf("%s\r\n", first.to_s.chomp) end # str.gsub!(/\r?\n/, "\r\n") if $frontend == 'genie' .flatten.each { || str += sprintf("%s\r\n", .to_s.chomp) } str.split(/\r?\n/).each { |line| Script.new_script_output(line); Buffer.update(line, Buffer::SCRIPT_OUTPUT) } # fixme: strip/separate script output? str_sent = false if $_CLIENT_ until str_sent wait_while { !XMLData.safe_to_respond? } str_sent = $_CLIENT_.puts_if(str) { XMLData.safe_to_respond? } end end if $_DETACHABLE_CLIENT_ str_sent = false until str_sent wait_while { !XMLData.safe_to_respond? } begin str_sent = $_DETACHABLE_CLIENT_.puts_if(str) { XMLData.safe_to_respond? } rescue break end end end rescue puts $! puts $!.backtrace.first end end |
#abort! ⇒ void
This method returns an undefined value.
Aborts the current script execution.
74 75 76 |
# File 'lib/global_defs.rb', line 74 def abort! Script.exit! end |
#activate ⇒ void
This method returns an undefined value.
Connects the activate event for the password entry
241 242 243 |
# File 'lib/common/gui-manual-login.rb', line 241 user_id_entry.signal_connect('activate') { pass_entry.grab_focus } |
#alias_deprecated ⇒ void Also known as: reallybleeding?
This method returns an undefined value.
Displays a deprecation warning for the alias command.
3600 3601 3602 3603 |
# File 'lib/global_defs.rb', line 3600 def alias_deprecated # todo: add command reference, possibly add calling script echo "The alias command you're attempting to use is deprecated. Fix your script." end |
#before_dying(&code) ⇒ void
This method returns an undefined value.
Registers a block of code to be executed when the script is exiting.
56 57 58 |
# File 'lib/global_defs.rb', line 56 def (&code) Script.at_exit(&code) end |
#bin2dec(n) ⇒ Integer
Converts a binary string to a decimal number.
651 652 653 |
# File 'lib/global_defs.rb', line 651 def bin2dec(n) [("0" * 32 + n.to_s)[-32..-1]].pack("B32").unpack("N")[0] end |
#bound? ⇒ Boolean
Checks if the player is currently bound.
2038 2039 2040 2041 |
# File 'lib/global_defs.rb', line 2038 def bound? return Status.bound? if XMLData.game =~ /GS/ fail "Error: toplevel bound? command not enabled in #{XMLData.game}" end |
#calmed? ⇒ Boolean
Checks if the player is currently calmed.
2082 2083 2084 2085 |
# File 'lib/global_defs.rb', line 2082 def calmed? return Status.calmed? if XMLData.game =~ /GS/ fail "Error: toplevel calmed? command not enabled in #{XMLData.game}" end |
#cast(spell, target = nil, results_of_interest = nil) ⇒ Boolean
Casts a spell on a target.
2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 |
# File 'lib/global_defs.rb', line 2145 def cast(spell, target = nil, results_of_interest = nil) if spell.class == Spell spell.cast(target, results_of_interest) elsif ((spell.class == Integer) or (spell.to_s =~ /^[0-9]+$/)) and (find_spell = Spell[spell.to_i]) find_spell.cast(target, results_of_interest) elsif (spell.class == String) and (find_spell = Spell[spell]) find_spell.cast(target, results_of_interest) else echo "cast: invalid spell (#{spell})" false end end |
#check_mind(string = nil) ⇒ Boolean, String
Checks the mental state of the character.
1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 |
# File 'lib/global_defs.rb', line 1267 def check_mind(string = nil) if string.nil? return XMLData.mind_text elsif (string.class == String) and (string.to_i == 0) if string =~ /#{XMLData.mind_text}/i return true else return false end elsif string.to_i.between?(0, 100) return string.to_i <= XMLData.mind_value.to_i else echo("check_mind error! You must provide an integer ranging from 0-100, the common abbreviation of how full your head is, or provide no input to have check_mind return an abbreviation of how filled your head is."); sleep 1 return false end end |
#checkarea(*strings) ⇒ String, Boolean
Checks if the current area matches any of the provided strings.
If strings are provided, returns true if the room title matches any of the strings, otherwise false.
1674 1675 1676 1677 1678 1679 1680 1681 |
# File 'lib/global_defs.rb', line 1674 def checkarea(*strings) strings.flatten! if strings.empty? XMLData.room_title.split(',').first.sub('[', '') else XMLData.room_title.split(',').first =~ /#{strings.join('|')}/i end end |
#checkbleeding ⇒ Boolean Also known as: bleeding?
Checks if the character is bleeding.
474 475 476 |
# File 'lib/global_defs.rb', line 474 def checkbleeding XMLData.indicator['IconBLEEDING'] == 'y' end |
#checkbound ⇒ Boolean
Checks if the player is currently bound.
2027 2028 2029 2030 |
# File 'lib/global_defs.rb', line 2027 def checkbound return Status.bound? if XMLData.game =~ /GS/ fail "Error: toplevel checkbound command not enabled in #{XMLData.game}" end |
#checkbounty ⇒ Object? Also known as: bounty?
Checks if there is a current bounty task.
1991 1992 1993 1994 1995 1996 1997 |
# File 'lib/global_defs.rb', line 1991 def checkbounty if XMLData.bounty_task return XMLData.bounty_task else return nil end end |
#checkcalmed ⇒ Boolean
Checks if the player is currently calmed.
2071 2072 2073 2074 |
# File 'lib/global_defs.rb', line 2071 def checkcalmed return Status.calmed? if XMLData.game =~ /GS/ fail "Error: toplevel checkcalmed command not enabled in #{XMLData.game}" end |
#checkcastrt ⇒ Float
Checks the remaining cast roundtime.
393 394 395 |
# File 'lib/global_defs.rb', line 393 def checkcastrt [0, XMLData.cast_roundtime_end.to_f - Time.now.to_f + XMLData.server_time_offset.to_f].max end |
#checkcutthroat ⇒ Boolean
Checks if the player is currently cutthroat.
2093 2094 2095 2096 |
# File 'lib/global_defs.rb', line 2093 def checkcutthroat return Status.cutthroat? if XMLData.game =~ /GS/ fail "Error: toplevel checkcutthroat command not enabled in #{XMLData.game}" end |
#checkdead ⇒ Boolean Also known as: dead?
Checks if the character is dead.
492 493 494 |
# File 'lib/global_defs.rb', line 492 def checkdead XMLData.indicator['IconDEAD'] == 'y' end |
#checkdisease ⇒ Boolean Also known as: diseased?
Checks if the character is diseased.
438 439 440 |
# File 'lib/global_defs.rb', line 438 def checkdisease XMLData.indicator['IconDISEASED'] == 'y' end |
#checkencumbrance(string = nil) ⇒ String, ... Also known as: encumbrance?
Checks the current encumbrance or compares it against a given string or value.
If string is a valid description or value, returns true if the current encumbrance matches, otherwise false.
1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 |
# File 'lib/global_defs.rb', line 1632 def checkencumbrance(string = nil) Lich.deprecated('checkencumbrance', 'Char.encumbrance') if string.nil? XMLData.encumbrance_text elsif (string.class == Integer) or (string =~ /^[0-9]+$/ and (string = string.to_i)) string <= XMLData.encumbrance_value else # fixme if string =~ /#{XMLData.encumbrance_text}/i true else false end end end |
#checkfamarea(*strings) ⇒ String, Boolean
Checks the current familiar area or compares it against a given string.
If strings are provided, returns true if the familiar room title matches any of the strings, otherwise false.
1721 1722 1723 1724 1725 1726 |
# File 'lib/global_defs.rb', line 1721 def checkfamarea(*strings) strings.flatten! if strings.empty? then return XMLData.familiar_room_title.split(',').first.sub('[', '') end XMLData.familiar_room_title.split(',').first =~ /#{strings.join('|')}/i end |
#checkfamnpcs(*strings) ⇒ Array<String>, Boolean
Checks the current familiar NPCs or compares them against a given list of strings.
If strings are provided, returns true if any of the NPC names match, otherwise false.
1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 |
# File 'lib/global_defs.rb', line 1770 def checkfamnpcs(*strings) parsed = Array.new XMLData.familiar_npcs.each { |val| parsed.push(val.split.last) } if strings.empty? if parsed.empty? return false else return parsed end else if (mtch = strings.find { |lookfor| parsed.find { |critter| critter =~ /#{lookfor}/ } }) return mtch else return false end end end |
#checkfampaths(dir = "none") ⇒ Boolean, Array<String>
Checks the available paths for the familiar in the specified direction.
otherwise returns the list of exits. If dir is specified, returns true if the direction is included in exits, otherwise false.
1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 |
# File 'lib/global_defs.rb', line 1736 def checkfampaths(dir = "none") if dir == "none" if XMLData.familiar_room_exits.empty? return false else return XMLData.familiar_room_exits end else XMLData.familiar_room_exits.include?(dir) end end |
#checkfampcs(*strings) ⇒ Array<String>, Boolean
Checks the current familiar PCs or compares them against a given list of strings.
If strings are provided, returns true if any of the PC names match, otherwise false.
1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 |
# File 'lib/global_defs.rb', line 1796 def checkfampcs(*strings) familiar_pcs = Array.new XMLData.familiar_pcs.to_s.gsub(/Lord |Lady |Great |High |Renowned |Grand |Apprentice |Novice |Journeyman /, '').split(',').each { |line| familiar_pcs.push(line.slice(/[A-Z][a-z]+/)) } if familiar_pcs.empty? return false elsif strings.empty? return familiar_pcs else regexpstr = strings.join('|\b') peeps = familiar_pcs.find_all { |val| val =~ /\b#{regexpstr}/i } if peeps.empty? return false else return peeps end end end |
#checkfamroom(*strings) ⇒ String, Boolean
Checks the current familiar room or compares it against a given string.
If strings are provided, returns true if the familiar room title matches any of the strings, otherwise false.
1756 1757 1758 1759 1760 |
# File 'lib/global_defs.rb', line 1756 def checkfamroom(*strings) strings.flatten!; if strings.empty? then return XMLData.familiar_room_title.chomp end XMLData.familiar_room_title =~ /#{strings.join('|')}/i end |
#checkfamroomdescrip(*val) ⇒ Integer?
Checks the familiar room description for a match with the provided values.
1926 1927 1928 1929 1930 1931 1932 1933 |
# File 'lib/global_defs.rb', line 1926 def checkfamroomdescrip(*val) val.flatten! if val.empty? return XMLData.familiar_room_description else return XMLData.familiar_room_description =~ /#{val.join('|')}/i end end |
#checkfried ⇒ Boolean Also known as: fried?
Checks if the character’s mind state indicates they must rest.
1334 1335 1336 1337 1338 1339 1340 |
# File 'lib/global_defs.rb', line 1334 def checkfried if XMLData.mind_text =~ /must rest|saturated/ true else false end end |
#checkgrouped ⇒ Boolean Also known as: joined?, checkjoined, group?
Checks if the character is grouped.
483 484 485 |
# File 'lib/global_defs.rb', line 483 def checkgrouped XMLData.indicator['IconJOINED'] == 'y' end |
#checkhealth(num = nil) ⇒ Integer, Boolean Also known as: health, health?
Checks the current health value or compares it to a given number.
1406 1407 1408 1409 1410 1411 1412 1413 |
# File 'lib/global_defs.rb', line 1406 def checkhealth(num = nil) Lich.deprecated('checkhealth', 'Char.health') if num.nil? XMLData.health else XMLData.health >= num.to_i end end |
#checkhidden ⇒ Boolean Also known as: hiding?, , , checkhiding
Checks if the character is hidden.
525 526 527 |
# File 'lib/global_defs.rb', line 525 def checkhidden XMLData.indicator['IconHIDDEN'] == 'y' end |
#checkinvisible ⇒ Boolean Also known as: invisible?
Checks if the character is invisible.
534 535 536 |
# File 'lib/global_defs.rb', line 534 def checkinvisible XMLData.indicator['IconINVISIBLE'] == 'y' end |
#checkkneeling ⇒ Boolean Also known as: kneeling?
Checks if the character is kneeling.
456 457 458 |
# File 'lib/global_defs.rb', line 456 def checkkneeling XMLData.indicator['IconKNEELING'] == 'y' end |
#checkleft(*hand) ⇒ String? Also known as: lefthand?, lefthand
Checks the left hand for a matching instance from the provided hand.
1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 |
# File 'lib/global_defs.rb', line 1892 def checkleft(*hand) if GameObj.left_hand.nil? then return nil end hand.flatten! if GameObj.left_hand.name == "Empty" or GameObj.left_hand.name.empty? nil elsif hand.empty? GameObj.left_hand.noun else hand.find { |instance| GameObj.left_hand.name =~ /#{instance}/i } end end |
#checkloot ⇒ Array<String>
Collects the loot items from the game object.
594 595 596 |
# File 'lib/global_defs.rb', line 594 def checkloot GameObj.loot.collect { |item| item.noun } end |
#checkmana(num = nil) ⇒ Integer, Boolean Also known as: mana, mana?
Checks the current mana value or compares it to a given number.
1361 1362 1363 1364 1365 1366 1367 1368 |
# File 'lib/global_defs.rb', line 1361 def checkmana(num = nil) Lich.deprecated('checkmana', 'Char.mana') if num.nil? XMLData.mana else XMLData.mana >= num.to_i end end |
#checkmind(string = nil) ⇒ Boolean? Also known as: mind?
Checks the mental state of the character with a different approach.
1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 |
# File 'lib/global_defs.rb', line 1291 def checkmind(string = nil) if string.nil? return XMLData.mind_text elsif string.class == String and string.to_i == 0 if string =~ /#{XMLData.mind_text}/i return true else return false end elsif string.to_i.between?(1, 8) mind_state = ['clear as a bell', 'fresh and clear', 'clear', 'muddled', 'becoming numbed', 'numbed', 'must rest', 'saturated'] if mind_state.index(XMLData.mind_text) mind = mind_state.index(XMLData.mind_text) + 1 return string.to_i <= mind else echo "Bad string in checkmind: mind_state" nil end else echo("Checkmind error! You must provide an integer ranging from 1-8 (7 is fried, 8 is 100% fried), the common abbreviation of how full your head is, or provide no input to have checkmind return an abbreviation of how filled your head is."); sleep 1 return false end end |
#checkname(*strings) ⇒ Boolean, String Also known as: myname?
Checks if the character’s name matches any of the provided strings.
580 581 582 583 584 585 586 587 |
# File 'lib/global_defs.rb', line 580 def checkname(*strings) strings.flatten! if strings.empty? XMLData.name else XMLData.name =~ /^(?:#{strings.join('|')})/i end end |
#checknotstanding ⇒ Boolean
Checks if the character is not standing.
561 562 563 |
# File 'lib/global_defs.rb', line 561 def checknotstanding XMLData.indicator['IconSTANDING'] == 'n' end |
#checknpcs(*strings) ⇒ Array<String>, Boolean
Checks the current NPCs or compares them against a given list of strings.
If strings are provided, returns true if any of the NPC names match, otherwise false.
1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 |
# File 'lib/global_defs.rb', line 1844 def checknpcs(*strings) npcs = GameObj.npcs.collect { |npc| npc.noun } if npcs.empty? if strings.empty? then return nil else return false end end strings.flatten! if strings.empty? npcs else regexpstr = strings.join(' ') npcs.find { |npc| regexpstr =~ /\b#{npc}/i } end end |
#checkpaths(dir = "none") ⇒ Array, Boolean
Checks if a given direction is valid based on the room exits.
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 |
# File 'lib/global_defs.rb', line 1174 def checkpaths(dir = "none") if dir == "none" if XMLData.room_exits.empty? return false else return XMLData.room_exits.collect { |room_exits| SHORTDIR[room_exits] } end else XMLData.room_exits.include?(dir) || XMLData.room_exits.include?(SHORTDIR[dir]) end end |
#checkpcs(*strings) ⇒ Array<String>, Boolean
Checks the current PCs or compares them against a given list of strings.
If strings are provided, returns true if any of the PC names match, otherwise false.
1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 |
# File 'lib/global_defs.rb', line 1822 def checkpcs(*strings) pcs = GameObj.pcs.collect { |pc| pc.noun } if pcs.empty? if strings.empty? then return nil else return false end end strings.flatten! if strings.empty? pcs else regexpstr = strings.join(' ') pcs.find { |pc| regexpstr =~ /\b#{pc}/i } end end |
#checkpoison ⇒ Boolean Also known as: poisoned?
Checks if the character is poisoned.
429 430 431 |
# File 'lib/global_defs.rb', line 429 def checkpoison XMLData.indicator['IconPOISONED'] == 'y' end |
#checkprep(spell = nil) ⇒ Boolean, String Also known as: prepped?, checkprepared
Checks the prepared spell status.
1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 |
# File 'lib/global_defs.rb', line 1956 def checkprep(spell = nil) if spell.nil? XMLData.prepared_spell elsif spell.class != String echo("Checkprep error, spell # not implemented! You must use the spell name") false else XMLData.prepared_spell =~ /^#{spell}/i end end |
#checkprone ⇒ Boolean
Checks if the character is prone.
552 553 554 |
# File 'lib/global_defs.rb', line 552 def checkprone XMLData.indicator['IconPRONE'] == 'y' end |
#checkreallybleeding ⇒ Boolean
Checks if the character is really bleeding, considering active spells.
501 502 503 |
# File 'lib/global_defs.rb', line 501 def checkreallybleeding checkbleeding and !(Spell[9909].active? or Spell[9905].active?) end |
#checkright(*hand) ⇒ String? Also known as: righthand?, righthand
Checks the right hand for a matching instance from the provided hand.
1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 |
# File 'lib/global_defs.rb', line 1873 def checkright(*hand) if GameObj.right_hand.nil? then return nil end hand.flatten! if GameObj.right_hand.name == "Empty" or GameObj.right_hand.name.empty? nil elsif hand.empty? GameObj.right_hand.noun else hand.find { |instance| GameObj.right_hand.name =~ /#{instance}/i } end end |
#checkroom(*strings) ⇒ String, Boolean
Checks if the current room matches any of the provided strings.
If strings are provided, returns true if the room title matches any of the strings, otherwise false.
1691 1692 1693 1694 1695 1696 1697 1698 |
# File 'lib/global_defs.rb', line 1691 def checkroom(*strings) strings.flatten! if strings.empty? XMLData.room_title.chomp else XMLData.room_title =~ /#{strings.join('|')}/i end end |
#checkroomdescrip(*val) ⇒ Integer? Also known as: roomdescription?
Checks the room description for a match with the provided values.
1911 1912 1913 1914 1915 1916 1917 1918 |
# File 'lib/global_defs.rb', line 1911 def checkroomdescrip(*val) val.flatten! if val.empty? return XMLData.room_description else return XMLData.room_description =~ /#{val.join('|')}/i end end |
#checkrt ⇒ Float
Checks the remaining roundtime.
384 385 386 |
# File 'lib/global_defs.rb', line 384 def checkrt [0, XMLData.roundtime_end.to_f - Time.now.to_f + XMLData.server_time_offset.to_f].max end |
#checksaturated ⇒ Boolean Also known as: saturated?
Checks if the character’s mind state is saturated.
1347 1348 1349 1350 1351 1352 1353 |
# File 'lib/global_defs.rb', line 1347 def checksaturated if XMLData.mind_text =~ /saturated/ true else false end end |
#checksilenced ⇒ Boolean
Checks if the player is currently silenced.
2049 2050 2051 2052 |
# File 'lib/global_defs.rb', line 2049 def checksilenced return Status.silenced? if XMLData.game =~ /GS/ fail "Error: toplevel checksilenced command not enabled in #{XMLData.game}" end |
#checksitting ⇒ Boolean Also known as: sitting?
Checks if the character is sitting.
447 448 449 |
# File 'lib/global_defs.rb', line 447 def checksitting XMLData.indicator['IconSITTING'] == 'y' end |
#checksleeping ⇒ Boolean
Checks if the player is currently sleeping.
2005 2006 2007 2008 |
# File 'lib/global_defs.rb', line 2005 def checksleeping return Status.sleeping? if XMLData.game =~ /GS/ fail "Error: toplevel checksleeping command not enabled in #{XMLData.game}" end |
#checkspell(*spells) ⇒ Boolean Also known as: active?, checkactive
Checks if all provided spells are currently active.
1941 1942 1943 1944 1945 1946 1947 |
# File 'lib/global_defs.rb', line 1941 def checkspell(*spells) spells.flatten! return false if Spell.active.empty? spells.each { |spell| return false unless Spell[spell].active? } true end |
#checkspirit(num = nil) ⇒ Integer, Boolean Also known as: spirit, spirit?
Checks the current spirit value or compares it to a given number.
1446 1447 1448 1449 1450 1451 1452 1453 |
# File 'lib/global_defs.rb', line 1446 def checkspirit(num = nil) Lich.deprecated('checkspirit', 'Char.spirit') if num.nil? XMLData.spirit else XMLData.spirit >= num.to_i end end |
#checkstamina(num = nil) ⇒ Integer, Boolean Also known as: stamina, stamina?
Checks the current stamina or compares it against a given threshold.
If num is provided, returns true if current stamina is greater than or equal to num, otherwise false.
1492 1493 1494 1495 1496 1497 1498 1499 |
# File 'lib/global_defs.rb', line 1492 def checkstamina(num = nil) Lich.deprecated('checkstamina', 'Char.stamina') if num.nil? XMLData.stamina else XMLData.stamina >= num.to_i end end |
#checkstance(num = nil) ⇒ String, ... Also known as: stance?, stance
Checks the current stance or compares it against a given threshold.
If num is a valid stance description or value, returns true if the current stance matches, otherwise false.
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 |
# File 'lib/global_defs.rb', line 1576 def checkstance(num = nil) Lich.deprecated('checkstance', 'Char.stance') if num.nil? XMLData.stance_text elsif (num.class == String) and (num.to_i == 0) if num =~ /off/i XMLData.stance_value == 0 elsif num =~ /adv/i XMLData.stance_value.between?(01, 20) elsif num =~ /for/i XMLData.stance_value.between?(21, 40) elsif num =~ /neu/i XMLData.stance_value.between?(41, 60) elsif num =~ /gua/i XMLData.stance_value.between?(61, 80) elsif num =~ /def/i XMLData.stance_value == 100 else echo "checkstance: invalid argument (#{num}). Must be off/adv/for/neu/gua/def or 0-100" nil end elsif (num.class == Integer) or (num =~ /^[0-9]+$/ and (num = num.to_i)) XMLData.stance_value == num.to_i else echo "checkstance: invalid argument (#{num}). Must be off/adv/for/neu/gua/def or 0-100" nil end end |
#checkstanding ⇒ Boolean Also known as: standing?
Checks if the character is standing.
570 571 572 |
# File 'lib/global_defs.rb', line 570 def checkstanding XMLData.indicator['IconSTANDING'] == 'y' end |
#checkstunned ⇒ Boolean Also known as: stunned?
Checks if the character is stunned.
465 466 467 |
# File 'lib/global_defs.rb', line 465 def checkstunned XMLData.indicator['IconSTUNNED'] == 'y' end |
#checkwebbed ⇒ Boolean Also known as: webbed?
Checks if the character is webbed.
543 544 545 |
# File 'lib/global_defs.rb', line 543 def checkwebbed XMLData.indicator['IconWEBBED'] == 'y' end |
#clear(_opt = 0) ⇒ Array
Clears the downstream buffer of the current script.
2164 2165 2166 2167 2168 2169 |
# File 'lib/global_defs.rb', line 2164 def clear(_opt = 0) unless (script = Script.current) then respond('--- clear: Unable to identify calling script.'); return false; end to_return = script.downstream_buffer.dup script.downstream_buffer.clear to_return end |
#clicked ⇒ void
This method returns an undefined value.
Connects the click event for the play button
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/common/gui-manual-login.rb', line 114 .signal_connect('clicked') { .sensitive = false user_id_entry.sensitive = false pass_entry.sensitive = false iter = liststore.append iter[1] = 'working...' Gtk.queue { begin login_info = EAccess.auth( account: user_id_entry.text || argv.account, password: pass_entry.text || argv.password, legacy: true ) end if login_info.to_s =~ /error/i @msgbox.call "\nSomething went wrong... probably invalid \nuser id and / or password.\n\nserver response: #{login_info}" .sensitive = true .sensitive = false user_id_entry.sensitive = true pass_entry.sensitive = true else liststore.clear login_info.each do |row| iter = liststore.append iter[0] = row[:game_code] iter[1] = row[:game_name] iter[2] = row[:char_code] iter[3] = row[:char_name] end .sensitive = true end true } } |
#count_npcs ⇒ Integer
Counts the number of current NPCs.
1863 1864 1865 |
# File 'lib/global_defs.rb', line 1863 def count_npcs checknpcs.length end |
#cutthroat? ⇒ Boolean
Checks if the player is currently cutthroat.
2104 2105 2106 2107 |
# File 'lib/global_defs.rb', line 2104 def cutthroat? return Status.cutthroat? if XMLData.game =~ /GS/ fail "Error: toplevel cutthroat? command not enabled in #{XMLData.game}" end |
#debug(*args) {|Array| ... } ⇒ Object
Outputs debug information if debugging is enabled.
615 616 617 618 619 620 621 622 623 |
# File 'lib/global_defs.rb', line 615 def debug(*args) if $LICH_DEBUG if block_given? yield(*args) else echo(*args) end end end |
#dec2bin(n) ⇒ String
Converts a decimal number to a binary string.
641 642 643 |
# File 'lib/global_defs.rb', line 641 def dec2bin(n) "0" + [n].pack("N").unpack("B32")[0].sub(/^0+(?=\d)/, '') end |
#die_with_me(*vals) ⇒ nil
Registers scripts to die with the current script.
725 726 727 728 729 730 |
# File 'lib/global_defs.rb', line 725 def die_with_me(*vals) unless (script = Script.current) then echo 'die_with_me: cannot identify calling script.'; return nil; end script.die_with.push vals script.die_with.flatten! echo("The following script(s) will now die when I do: #{script.die_with.join(', ')}") unless script.die_with.empty? end |
#do_client(client_string) ⇒ nil
Processes a client command string, executing the appropriate action based on the command.
3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 |
# File 'lib/global_defs.rb', line 3198 def do_client(client_string) client_string.strip! # Buffer.update(client_string, Buffer::UPSTREAM) client_string = UpstreamHook.run(client_string) # Buffer.update(client_string, Buffer::UPSTREAM_MOD) return nil if client_string.nil? if client_string =~ /^(?:<c>)?#{$lich_char_regex}(.+)$/ cmd = $1 if cmd =~ /^k$|^kill$|^stop$/ if Script.running.empty? respond '--- Lich: no scripts to kill' else Script.running.last.kill end elsif cmd =~ /^p$|^pause$/ if (s = Script.running.reverse.find { |s_check| not s_check.paused? }) s.pause else respond '--- Lich: no scripts to pause' end nil elsif cmd =~ /^u$|^unpause$/ if (s = Script.running.reverse.find { |s_check| s_check.paused? }) s.unpause else respond '--- Lich: no scripts to unpause' end nil elsif cmd =~ /^ka$|^kill\s?all$|^stop\s?all$/ did_something = false Script.running.find_all { |s_check| not s_check.no_kill_all }.each { |s_check| s_check.kill; did_something = true } respond('--- Lich: no scripts to kill') unless did_something elsif cmd =~ /^pa$|^pause\s?all$/ did_something = false Script.running.find_all { |s_check| not s_check.paused? and not s_check.no_pause_all }.each { |s_check| s_check.pause; did_something = true } respond('--- Lich: no scripts to pause') unless did_something elsif cmd =~ /^ua$|^unpause\s?all$/ did_something = false Script.running.find_all { |s_check| s_check.paused? and not s_check.no_pause_all }.each { |s_check| s_check.unpause; did_something = true } respond('--- Lich: no scripts to unpause') unless did_something elsif cmd =~ /^(k|kill|stop|p|pause|u|unpause)\s(.+)/ action = $1 target = $2 script = Script.running.find { |s_running| s_running.name == target } || Script.hidden.find { |s_hidden| s_hidden.name == target } || Script.running.find { |s_running| s_running.name =~ /^#{target}/i } || Script.hidden.find { |s_hidden| s_hidden.name =~ /^#{target}/i } if script.nil? respond "--- Lich: #{target} does not appear to be running! Use '#{$clean_lich_char}list' or '#{$clean_lich_char}listall' to see what's active." elsif action =~ /^(?:k|kill|stop)$/ script.kill elsif action =~ /^(?:p|pause)$/ script.pause elsif action =~ /^(?:u|unpause)$/ script.unpause end target = nil elsif cmd =~ /^list\s?(?:all)?$|^l(?:a)?$/i if cmd =~ /a(?:ll)?/i list = Script.running + Script.hidden else list = Script.running end if list.empty? respond '--- Lich: no active scripts' else respond "--- Lich: #{list.collect { |active| active.paused? ? "#{active.name} (paused)" : active.name }.join(", ")}" end nil elsif cmd =~ /^force\s+[^\s]+/ if cmd =~ /^force\s+([^\s]+)\s+(.+)$/ Script.start($1, $2, :force => true) elsif cmd =~ /^force\s+([^\s]+)/ Script.start($1, :force => true) end elsif cmd =~ /^send |^s / if cmd.split[1] == "to" script = (Script.running + Script.hidden).find { |scr| scr.name == cmd.split[2].chomp.strip } || script = (Script.running + Script.hidden).find { |scr| scr.name =~ /^#{cmd.split[2].chomp.strip}/i } if script msg = cmd.split[3..-1].join(' ').chomp if script.want_downstream script.downstream_buffer.push(msg) else script.unique_buffer.push(msg) end respond "--- sent to '#{script.name}': #{msg}" else respond "--- Lich: '#{cmd.split[2].chomp.strip}' does not match any active script!" end nil else if Script.running.empty? and Script.hidden.empty? respond('--- Lich: no active scripts to send to.') else msg = cmd.split[1..-1].join(' ').chomp respond("--- sent: #{msg}") Script.new_downstream(msg) end end elsif cmd =~ /^(?:exec|e)(q)? (.+)$/ cmd_data = $2 ExecScript.start(cmd_data, { :quiet => $1 }) elsif cmd =~ /^(?:execname|en) ([\w\d-]+) (.+)$/ execname = $1 cmd_data = $2 ExecScript.start(cmd_data, { :name => execname }) elsif cmd =~ /^trust\s+(.*)/i script_name = $1 if RUBY_VERSION =~ /^2\.[012]\./ if File.exist?("#{SCRIPT_DIR}/#{script_name}.lic") if Script.trust(script_name) respond "--- Lich: '#{script_name}' is now a trusted script." else respond "--- Lich: '#{script_name}' is already trusted." end else respond "--- Lich: could not find script: #{script_name}" end else respond "--- Lich: this feature isn't available in this version of Ruby " end elsif cmd =~ /^(?:dis|un)trust\s+(.*)/i script_name = $1 if RUBY_VERSION =~ /^2\.[012]\./ if Script.distrust(script_name) respond "--- Lich: '#{script_name}' is no longer a trusted script." else respond "--- Lich: '#{script_name}' was not found in the trusted script list." end else respond "--- Lich: this feature isn't available in this version of Ruby " end elsif cmd =~ /^list\s?(?:un)?trust(?:ed)?$|^lt$/i if RUBY_VERSION =~ /^2\.[012]\./ list = Script.list_trusted if list.empty? respond "--- Lich: no scripts are trusted" else respond "--- Lich: trusted scripts: #{list.join(', ')}" end nil else respond "--- Lich: this feature isn't available in this version of Ruby " end elsif cmd =~ /^set\s(.+)\s(on|off)/ toggle_var = $1 set_state = $2 did_something = false begin Lich.db.execute("INSERT OR REPLACE INTO lich_settings(name,value) values(?,?);", [toggle_var.to_s.encode('UTF-8'), set_state.to_s.encode('UTF-8')]) did_something = true rescue SQLite3::BusyException sleep 0.1 retry end respond("--- Lich: toggle #{toggle_var} set #{set_state}") if did_something did_something = false nil elsif cmd =~ /^hmr\s+(?<pattern>.*)/i begin HMR.reload %r{#{Regexp.last_match[:pattern]}} rescue ArgumentError if $!.to_s == 'invalid Unicode escape' respond "--- Lich: error: invalid Unicode escape" respond "--- Lich: cmd: #{cmd}" respond "--- Lich: \\u is unicode escape, did you mean to use a / instead?" else respond "--- Lich: error: #{$!}\n\t#{$!.backtrace[0..1].join("\n\t")}" Lich.log "error: #{$!}\n\t#{$!.backtrace.join("\n\t")}" end end elsif XMLData.game =~ /^GS/ && cmd =~ /^infomon sync/i ExecScript.start("Infomon.sync", { :quiet => true }) elsif XMLData.game =~ /^GS/ && cmd =~ /^infomon (?:reset|redo)!?/i ExecScript.start("Infomon.redo!", { :quiet => true }) elsif XMLData.game =~ /^GS/ && cmd =~ /^infomon show( full)?/i case Regexp.last_match(1) when 'full' Infomon.show(true) else Infomon.show(false) end elsif XMLData.game =~ /^GS/ && cmd =~ /^infomon effects?(?: (true|false))?/i new_value = !(Infomon.get_bool("infomon.show_durations")) case Regexp.last_match(1) when 'true' new_value = true when 'false' new_value = false end respond "Changing Infomon's effect duration showing to #{new_value}" Infomon.set('infomon.show_durations', new_value) elsif XMLData.game =~ /^GS/ && cmd =~ /^sk\b(?: (add|rm|list|help)(?: ([\d\s]+))?)?/i SK.main(Regexp.last_match(1), Regexp.last_match(2)) elsif XMLData.game =~ /^DR/ && cmd =~ /^display flaguid(?: (true|false))?/i new_value = !(Lich.hide_uid_flag) case Regexp.last_match(1) when 'true' new_value = true when 'false' new_value = false end respond "Changing Lich to NOT display Room Title RealIDs while FLAG ShowRoomID ON to #{new_value}" Lich.hide_uid_flag = new_value elsif cmd =~ /^display lichid(?: (true|false))?/i new_value = !(Lich.display_lichid) case Regexp.last_match(1) when 'true' new_value = true when 'false' new_value = false end respond "Changing Lich to display Lich ID#s to #{new_value}" Lich.display_lichid = new_value elsif cmd =~ /^display uid(?: (true|false))?/i new_value = !(Lich.display_uid) case Regexp.last_match(1) when 'true' new_value = true when 'false' new_value = false end respond "Changing Lich to display RealID#s to #{new_value}" Lich.display_uid = new_value elsif cmd =~ /^display exits?(?: (true|false))?/i new_value = !(Lich.display_exits) case Regexp.last_match(1) when 'true' new_value = true when 'false' new_value = false end respond "Changing Lich to display Room Exits of non-StringProc/Obvious exits to #{new_value}" Lich.display_exits = new_value elsif cmd =~ /^display stringprocs?(?: (true|false))?/i new_value = !(Lich.display_stringprocs) case Regexp.last_match(1) when 'true' new_value = true when 'false' new_value = false end respond "Changing Lich to display Room Exits of StringProcs to #{new_value}" Lich.display_stringprocs = new_value elsif cmd =~ /^(?:lich5-update|l5u)\s+(.*)/i update_parameter = $1.dup Lich::Util::Update.request("#{update_parameter}") elsif cmd =~ /^(?:lich5-update|l5u)/i Lich::Util::Update.request("--help") elsif cmd =~ /^banks$/ && XMLData.game =~ /^GS/ Game._puts "<c>bank account" $_CLIENTBUFFER_.push "<c>bank account" elsif cmd =~ /^magic$/ && XMLData.game =~ /^GS/ Effects.display elsif cmd =~ /^help$/i respond respond "Lich v#{LICH_VERSION}" respond respond 'built-in commands:' respond " #{$clean_lich_char}<script name> start a script" respond " #{$clean_lich_char}force <script name> start a script even if it's already running" respond " #{$clean_lich_char}pause <script name> pause a script" respond " #{$clean_lich_char}p <script name> ''" respond " #{$clean_lich_char}unpause <script name> unpause a script" respond " #{$clean_lich_char}u <script name> ''" respond " #{$clean_lich_char}kill <script name> kill a script" respond " #{$clean_lich_char}k <script name> ''" respond " #{$clean_lich_char}pause pause the most recently started script that isn't aready paused" respond " #{$clean_lich_char}p ''" respond " #{$clean_lich_char}unpause unpause the most recently started script that is paused" respond " #{$clean_lich_char}u ''" respond " #{$clean_lich_char}kill kill the most recently started script" respond " #{$clean_lich_char}k ''" respond " #{$clean_lich_char}list show running scripts (except hidden ones)" respond " #{$clean_lich_char}l ''" respond " #{$clean_lich_char}pause all pause all scripts" respond " #{$clean_lich_char}pa ''" respond " #{$clean_lich_char}unpause all unpause all scripts" respond " #{$clean_lich_char}ua ''" respond " #{$clean_lich_char}kill all kill all scripts" respond " #{$clean_lich_char}ka ''" respond " #{$clean_lich_char}list all show all running scripts" respond " #{$clean_lich_char}la ''" respond respond " #{$clean_lich_char}exec <code> executes the code as if it was in a script" respond " #{$clean_lich_char}e <code> ''" respond " #{$clean_lich_char}execq <code> same as #{$clean_lich_char}exec but without the script active and exited messages" respond " #{$clean_lich_char}eq <code> ''" respond " #{$clean_lich_char}execname <name> <code> creates named exec (name#) and then executes the code as if it was in a script" respond if (RUBY_VERSION =~ /^2\.[012]\./) respond " #{$clean_lich_char}trust <script name> let the script do whatever it wants" respond " #{$clean_lich_char}distrust <script name> restrict the script from doing things that might harm your computer" respond " #{$clean_lich_char}list trusted show what scripts are trusted" respond " #{$clean_lich_char}lt ''" respond end respond " #{$clean_lich_char}send <line> send a line to all scripts as if it came from the game" respond " #{$clean_lich_char}send to <script> <line> send a line to a specific script" respond respond " #{$clean_lich_char}set <variable> [on|off] set a global toggle variable on or off" respond " #{$clean_lich_char}lich5-update --<command> Lich5 ecosystem management " respond " see #{$clean_lich_char}lich5-update --help" respond " #{$clean_lich_char}hmr <regex filepath> Hot module reload a Ruby or Lich5 file without relogging, uses Regular Expression matching" if XMLData.game =~ /^GS/ respond respond " #{$clean_lich_char}infomon sync sends all the various commands to resync character data for infomon (fixskill)" respond " #{$clean_lich_char}infomon reset resets entire character infomon db table and then syncs data (fixprof)" respond " #{$clean_lich_char}infomon effects toggle display of effect durations" respond " #{$clean_lich_char}infomon show shows all current Infomon values for character" respond " #{$clean_lich_char}sk help show information on modifying self-knowledge spells to be known" elsif XMLData.game =~ /^DR/ respond " #{$clean_lich_char}display flaguid toggle display of RealID in Room Title with FLAG ShowRoomID (required for Lich5 to be ON)" end respond " #{$clean_lich_char}display lichid toggle display of Lich Map# when displaying room information" respond " #{$clean_lich_char}display uid toggle display of RealID Map# when displaying room information" respond " #{$clean_lich_char}display exits toggle display of non-StringProc/Obvious exits known for room in mapdb" respond " #{$clean_lich_char}display stringprocs toggle display of StringProc exits known for room in mapdb if timeto is valid" respond respond 'If you liked this help message, you might also enjoy:' respond " #{$clean_lich_char}lnet help" if defined?(LNet) respond " #{$clean_lich_char}go2 help" respond " #{$clean_lich_char}repository help" respond " #{$clean_lich_char}alias help" respond " #{$clean_lich_char}vars help" respond " #{$clean_lich_char}autostart help" respond else if cmd =~ /^([^\s]+)\s+(.+)/ Script.start($1, $2) else Script.start(cmd) end end else if $offline_mode respond "--- Lich: offline mode: ignoring #{client_string}" else client_string = "#{$cmd_prefix}bbs" if ($frontend =~ /^(?:wizard|avalon)$/) and (client_string == "#{$cmd_prefix}\egbbk\n") # launch forum Game._puts client_string end $_CLIENTBUFFER_.push client_string end Script.new_upstream(client_string) end |
#dothis(action, success_line) ⇒ String
Executes a given action and waits for a success line in the output.
2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 |
# File 'lib/global_defs.rb', line 2885 def dothis(action, success_line) loop { Script.current.clear put action loop { line = get if line =~ success_line return line elsif line =~ /^(\.\.\.w|W)ait ([0-9]+) sec(onds)?\.$/ if $2.to_i > 1 sleep($2.to_i - "0.5".to_f) else sleep 0.3 end break elsif line == 'Sorry, you may only type ahead 1 command.' sleep 1 break elsif line == 'You are still stunned.' wait_while { stunned? } break elsif line == 'That is impossible to do while unconscious!' 100.times { unless (line = get?) sleep 0.1 else break if line =~ /Your thoughts slowly come back to you as you find yourself lying on the ground\. You must have been sleeping\.$|^You wake up from your slumber\.$/ end } break elsif line == "You don't seem to be able to move to do that." 100.times { unless (line = get?) sleep 0.1 else break if line == 'The restricting force that envelops you dissolves away.' end } break elsif line == "You can't do that while entangled in a web." wait_while { checkwebbed } break elsif line == 'You find that impossible under the effects of the lullabye.' 100.times { unless (line = get?) sleep 0.1 else # fixme break if line == 'You shake off the effects of the lullabye.' end } break end } } end |
#dothistimeout(action, timeout, success_line) ⇒ String?
This method will continuously check for the success line until the timeout is reached.
Inserts a timeout mechanism for executing an action and waiting for a success line.
2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 |
# File 'lib/global_defs.rb', line 2951 def dothistimeout(action, timeout, success_line) end_time = Time.now.to_f + timeout line = nil loop { Script.current.clear put action unless action.nil? loop { line = get? if line.nil? sleep 0.1 elsif line =~ success_line return line elsif line =~ /^(\.\.\.w|W)ait ([0-9]+) sec(onds)?\.$/ if $2.to_i > 1 sleep($2.to_i - "0.5".to_f) else sleep 0.3 end end_time = Time.now.to_f + timeout break elsif line == 'Sorry, you may only type ahead 1 command.' sleep 1 end_time = Time.now.to_f + timeout break elsif line == 'You are still stunned.' wait_while { stunned? } end_time = Time.now.to_f + timeout break elsif line == 'That is impossible to do while unconscious!' 100.times { unless (line = get?) sleep 0.1 else break if line =~ /Your thoughts slowly come back to you as you find yourself lying on the ground\. You must have been sleeping\.$|^You wake up from your slumber\.$/ end } break elsif line == "You don't seem to be able to move to do that." 100.times { unless (line = get?) sleep 0.1 else break if line == 'The restricting force that envelops you dissolves away.' end } break elsif line == "You can't do that while entangled in a web." wait_while { checkwebbed } break elsif line == 'You find that impossible under the effects of the lullabye.' 100.times { unless (line = get?) sleep 0.1 else # fixme break if line == 'You shake off the effects of the lullabye.' end } break end if Time.now.to_f >= end_time return nil end } } end |
#down ⇒ String
Returns The string ‘down’.
869 |
# File 'lib/global_defs.rb', line 869 def down; 'down'; end |
#echo(*messages) ⇒ nil
Sends messages to the current script’s response handler.
247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/global_defs.rb', line 247 def echo(*) respond if .empty? if (script = Script.current) unless script.no_echo .each { || respond("[#{script.name}: #{.to_s.chomp}]") } end else .each { || respond("[(unknown script): #{.to_s.chomp}]") } end nil end |
#echo_off ⇒ void?
Turns off echo for the current script.
207 208 209 210 |
# File 'lib/global_defs.rb', line 207 def echo_off unless (script = Script.current) then respond('--- echo_off: Unable to identify calling script.'); return nil; end script.no_echo = true end |
#echo_on ⇒ void?
Turns on echo for the current script.
197 198 199 200 |
# File 'lib/global_defs.rb', line 197 def echo_on unless (script = Script.current) then respond('--- echo_on: Unable to identify calling script.'); return nil; end script.no_echo = false end |
#empty_hand ⇒ void
This method returns an undefined value.
Empties the hand that is less full based on the current state of the character’s hands.
2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 |
# File 'lib/global_defs.rb', line 2803 def empty_hand right_hand = GameObj.right_hand left_hand = GameObj.left_hand unless (right_hand.id.nil? and ([Wounds.rightArm, Wounds.rightHand, Scars.rightArm, Scars.rightHand].max < 3)) or (left_hand.id.nil? and ([Wounds.leftArm, Wounds.leftHand, Scars.leftArm, Scars.leftHand].max < 3)) if right_hand.id and ([Wounds.rightArm, Wounds.rightHand, Scars.rightArm, Scars.rightHand].max < 3 or [Wounds.leftArm, Wounds.leftHand, Scars.leftArm, Scars.leftHand].max == 3) waitrt? Lich::Stash::stash_hands(right: true) else waitrt? Lich::Stash::stash_hands(left: true) end end end |
#empty_hands ⇒ void
This method returns an undefined value.
Empties both hands by calling the stash method.
2793 2794 2795 2796 |
# File 'lib/global_defs.rb', line 2793 def empty_hands waitrt? Lich::Stash::stash_hands(both: true) end |
#empty_left_hand ⇒ void
This method returns an undefined value.
Empties the left hand by calling the stash method.
2833 2834 2835 2836 |
# File 'lib/global_defs.rb', line 2833 def empty_left_hand waitrt? Lich::Stash::stash_hands(left: true) end |
#empty_right_hand ⇒ void
This method returns an undefined value.
Empties the right hand by calling the stash method.
2823 2824 2825 2826 |
# File 'lib/global_defs.rb', line 2823 def empty_right_hand waitrt? Lich::Stash::stash_hands(right: true) end |
#fb_to_sf(line) ⇒ String?
Converts a line from the front-end format to a server-friendly format.
3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 |
# File 'lib/global_defs.rb', line 3030 def fb_to_sf(line) begin return line if line == "\r\n" line = line.gsub(/<c>/, "") return nil if line.gsub("\r\n", '').length < 1 return line rescue $_CLIENT_.puts "--- Error: fb_to_sf: #{$!}" $_CLIENT_.puts "$_SERVERSTRING_: #{$_SERVERSTRING_}" Lich.log("--- Error: fb_to_sf: #{$!}\n\t#{$!.backtrace.join("\n\t")}") Lich.log("$_SERVERSTRING_: #{$_SERVERSTRING_}") Lich.log("Line: #{line}") end end |
#fetchloot(userbagchoice = UserVars.lootsack) ⇒ Boolean
Fetches loot from the game object and places it into the user’s bag.
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 |
# File 'lib/deprecated.rb', line 35 def fetchloot(userbagchoice = UserVars.lootsack) if GameObj.loot.empty? return false end if UserVars.excludeloot.empty? regexpstr = nil else regexpstr = UserVars.excludeloot.split(', ').join('|') end if checkright and checkleft stowed = GameObj.right_hand.noun fput "put my #{stowed} in my #{UserVars.lootsack}" else stowed = nil end GameObj.loot.each { |loot| unless not regexpstr.nil? and loot.name =~ /#{regexpstr}/ fput "get #{loot.noun}" fput("put my #{loot.noun} in my #{userbagchoice}") if (checkright || checkleft) end } if stowed fput "take my #{stowed} from my #{UserVars.lootsack}" end end |
#fill_hand ⇒ void
This method returns an undefined value.
Fills the hand based on the current state of the character’s hands.
2853 2854 2855 2856 |
# File 'lib/global_defs.rb', line 2853 def fill_hand waitrt? Lich::Stash::equip_hands() end |
#fill_hands ⇒ void
This method returns an undefined value.
Fills both hands by calling the equip method.
2843 2844 2845 2846 |
# File 'lib/global_defs.rb', line 2843 def fill_hands waitrt? Lich::Stash::equip_hands(both: true) end |
#fill_left_hand ⇒ void
This method returns an undefined value.
Fills the left hand by calling the equip method.
2873 2874 2875 2876 |
# File 'lib/global_defs.rb', line 2873 def fill_left_hand waitrt? Lich::Stash::equip_hands(left: true) end |
#fill_right_hand ⇒ void
This method returns an undefined value.
Fills the right hand by calling the equip method.
2863 2864 2865 2866 |
# File 'lib/global_defs.rb', line 2863 def fill_right_hand waitrt? Lich::Stash::equip_hands(right: true) end |
#fix_injury_mode ⇒ void
This method returns an undefined value.
Fixes the injury mode in the game if it is not set to 2.
327 328 329 330 331 332 |
# File 'lib/global_defs.rb', line 327 def fix_injury_mode unless XMLData.injury_mode == 2 Game._puts '_injury 2' 150.times { sleep 0.05; break if XMLData.injury_mode == 2 } end end |
#force_start_script(script_name, cli_vars = [], flags = {}) ⇒ void
This method returns an undefined value.
Forces the start of a script, ensuring it runs even if it is already running.
44 45 46 47 48 |
# File 'lib/global_defs.rb', line 44 def force_start_script(script_name, cli_vars = [], flags = {}) flags = Hash.new unless flags.class == Hash flags[:force] = true start_script(script_name, cli_vars, flags) end |
#fput(message, *waitingfor) ⇒ String, false Also known as: forceput
Sends a message to the script and waits for a response.
2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 |
# File 'lib/global_defs.rb', line 2445 def fput(, *waitingfor) unless (script = Script.current) then respond('--- waitfor: Unable to identify calling script.'); return false; end waitingfor.flatten! clear put() while (string = get) if string =~ /(?:\.\.\.wait |Wait )[0-9]+/ hold_up = string.slice(/[0-9]+/).to_i sleep(hold_up) unless hold_up.nil? clear put() next elsif string =~ /^You.+struggle.+stand/ clear fput 'stand' next elsif string =~ /stunned|can't do that while|cannot seem|^(?!You rummage).*can't seem|don't seem|Sorry, you may only type ahead/ if dead? echo "You're dead...! You can't do that!" sleep 1 script.downstream_buffer.unshift(string) return false elsif checkstunned while checkstunned sleep("0.25".to_f) end elsif checkwebbed while checkwebbed sleep("0.25".to_f) end elsif string =~ /Sorry, you may only type ahead/ sleep 1 else sleep 0.1 script.downstream_buffer.unshift(string) return false end clear put() next else if waitingfor.empty? script.downstream_buffer.unshift(string) return string else if (foundit = waitingfor.find { |val| string =~ /#{val}/i }) script.downstream_buffer.unshift(string) return foundit end sleep 1 clear put() next end end end end |
#get ⇒ String
Retrieves a line of input from the current script.
2366 2367 2368 |
# File 'lib/global_defs.rb', line 2366 def get Script.current.gets end |
#get? ⇒ Boolean
Checks if there is a line of input available from the current script.
2375 2376 2377 |
# File 'lib/global_defs.rb', line 2375 def get? Script.current.gets? end |
#goto(label) ⇒ void
This method returns an undefined value.
Jumps to a specified label in the current script.
284 285 286 287 |
# File 'lib/global_defs.rb', line 284 def goto(label) Script.current.jump_label = label.to_s raise JUMP end |
#hide_me ⇒ void
This method is intended for use prior to 2024.
This method returns an undefined value.
Toggles the visibility of the current script.
134 135 136 |
# File 'lib/global_defs.rb', line 134 def hide_me Script.current.hidden = !Script.current.hidden end |
#hide_script(*args) ⇒ void
This method returns an undefined value.
Hides or shows the specified scripts by name.
340 341 342 343 344 345 346 347 |
# File 'lib/global_defs.rb', line 340 def hide_script(*args) args.flatten! args.each { |name| if (script = Script.running.find { |scr| scr.name == name }) script.hidden = !script.hidden end } end |
#i_stand_alone ⇒ Boolean?
Toggles the downstream setting for the current script.
603 604 605 606 607 |
# File 'lib/global_defs.rb', line 603 def i_stand_alone unless (script = Script.current) then echo 'i_stand_alone: cannot identify calling script.'; return nil; end script.want_downstream = !script.want_downstream return !script.want_downstream end |
#idle?(time = 60) ⇒ Boolean
Checks if the character has been idle for a specified time.
661 662 663 |
# File 'lib/global_defs.rb', line 661 def idle?(time = 60) Time.now - $_IDLETIMESTAMP_ >= time end |
#key_exists?(path) ⇒ Boolean
Checks if a registry key exists at the given path.
62 63 64 65 66 67 |
# File 'lib/init.rb', line 62 def key_exists?(path) Registry.open(Registry::HKEY_LOCAL_MACHINE, path, ::Win32::Registry::KEY_READ) true rescue StandardError false end |
#match(label, string) ⇒ String, false
Matches a label and string against the game line queue.
2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 |
# File 'lib/global_defs.rb', line 2179 def match(label, string) strings = [label, string] strings.flatten! unless (script = Script.current) then echo("An unknown script thread tried to fetch a game line from the queue, but Lich can't process the call without knowing which script is calling! Aborting..."); Thread.current.kill; return false end if strings.empty? then echo("Error! 'match' was given no strings to look for!"); sleep 1; return false end unless strings.length == 2 while (line_in = script.gets) strings.each { |string| if line_in =~ /#{string}/ then return $~.to_s end } end else if script.respond_to?(:match_stack_add) script.match_stack_add(strings.first.to_s, strings.last) else script.match_stack_labels.push(strings[0].to_s) script.match_stack_strings.push(strings[1]) end end end |
#matchafter(*strings) ⇒ String, false
Matches a string after a specified condition.
2257 2258 2259 2260 2261 2262 2263 |
# File 'lib/global_defs.rb', line 2257 def matchafter(*strings) strings.flatten! unless (script = Script.current) then echo("An unknown script thread tried to fetch a game line from the queue, but Lich can't process the call without knowing which script is calling! Aborting..."); Thread.current.kill; return false end if strings.empty? then echo("matchafter without any strings to wait for!"); return end regexpstr = strings.join('|') loop { if (script.gets) =~ /#{regexpstr}/ then return $'.to_s end } end |
#matchbefore(*strings) ⇒ String, false
Matches a string before a specified condition.
2242 2243 2244 2245 2246 2247 2248 |
# File 'lib/global_defs.rb', line 2242 def matchbefore(*strings) strings.flatten! unless (script = Script.current) then echo("An unknown script thread tried to fetch a game line from the queue, but Lich can't process the call without knowing which script is calling! Aborting..."); Thread.current.kill; return false end if strings.empty? then echo("matchbefore without any strings to wait for!"); return false end regexpstr = strings.join('|') loop { if (script.gets) =~ /#{regexpstr}/ then return $`.to_s end } end |
#matchboth(*strings) ⇒ Array<String>
Matches any of the provided strings in the input until a match is found.
2272 2273 2274 2275 2276 2277 2278 2279 |
# File 'lib/global_defs.rb', line 2272 def matchboth(*strings) strings.flatten! unless (script = Script.current) then echo("An unknown script thread tried to fetch a game line from the queue, but Lich can't process the call without knowing which script is calling! Aborting..."); Thread.current.kill; return false end if strings.empty? then echo("matchboth without any strings to wait for!"); return end regexpstr = strings.join('|') loop { if (script.gets) =~ /#{regexpstr}/ then break end } return [$`.to_s, $'.to_s] end |
#matchfind(*strings) ⇒ String+
Matches input against the provided strings and captures groups.
2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 |
# File 'lib/global_defs.rb', line 2564 def matchfind(*strings) regex = /#{strings.flatten.join('|').gsub('?', '(.+)')}/i unless (script = Script.current) respond "Unknown script is asking to use matchfind! Cannot process request without identifying the calling script; killing this thread." Thread.current.kill end while true if (reobj = regex.match(script.gets)) ret = reobj.captures.compact if ret.length < 2 return ret.first else return ret end end end end |
#matchfindexact(*strings) ⇒ String, ...
Matches input exactly against the provided strings.
2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 |
# File 'lib/global_defs.rb', line 2531 def matchfindexact(*strings) strings.flatten! unless (script = Script.current) then echo("An unknown script thread tried to fetch a game line from the queue, but Lich can't process the call without knowing which script is calling! Aborting..."); Thread.current.kill; return false end if strings.empty? then echo("error! 'matchfind' with no strings to look for!"); sleep 1; return false end looking = Array.new strings.each { |str| looking.push(str.gsub('?', '(\b.+\b)')) } if looking.empty? then echo("matchfind without any strings to wait for!"); return false end regexpstr = looking.join('|') while (line_in = script.gets) if (gotit = line_in.slice(/#{regexpstr}/)) matches = Array.new looking.each_with_index { |str, idx| if gotit =~ /#{str}/i strings[idx].count('?').times { |n| matches.push(eval("$#{n + 1}")) } end } break end end if matches.length == 1 return matches.first else return matches.compact end end |
#matchfindword(*strings) ⇒ String+
Matches input against the provided words and captures groups.
2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 |
# File 'lib/global_defs.rb', line 2589 def matchfindword(*strings) regex = /#{strings.flatten.join('|').gsub('?', '([\w\d]+)')}/i unless (script = Script.current) respond "Unknown script is asking to use matchfindword! Cannot process request without identifying the calling script; killing this thread." Thread.current.kill end while true if (reobj = regex.match(script.gets)) ret = reobj.captures.compact if ret.length < 2 return ret.first else return ret end end end end |
#matchtimeout(secs, *strings) ⇒ String, false
Waits for a match within a specified timeout period.
2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 |
# File 'lib/global_defs.rb', line 2208 def matchtimeout(secs, *strings) unless (Script.current) then echo("An unknown script thread tried to fetch a game line from the queue, but Lich can't process the call without knowing which script is calling! Aborting..."); Thread.current.kill; return false end unless (secs.class == Float || secs.class == Integer) echo('matchtimeout error! You appear to have given it a string, not a #! Syntax: matchtimeout(30, "You stand up")') return false end strings.flatten! if strings.empty? echo("matchtimeout without any strings to wait for!") sleep 1 return false end regexpstr = strings.join('|') end_time = Time.now.to_f + secs loop { line = get? if line.nil? sleep 0.1 elsif line =~ /#{regexpstr}/i return line end if (Time.now.to_f > end_time) return false end } end |
#matchwait(*strings) ⇒ String?
Waits for a line of input that matches any of the provided strings.
2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 |
# File 'lib/global_defs.rb', line 2288 def matchwait(*strings) unless (script = Script.current) then respond('--- matchwait: Unable to identify calling script.'); return false; end strings.flatten! unless strings.empty? regexpstr = strings.collect { |str| str.kind_of?(Regexp) ? str.source : str }.join('|') regexobj = /#{regexpstr}/ while (line_in = script.gets) return line_in if line_in =~ regexobj end else strings = script.match_stack_strings labels = script.match_stack_labels regexpstr = /#{strings.join('|')}/i while (line_in = script.gets) if (mdata = regexpstr.match(line_in)) jmp = labels[strings.index(mdata.to_s) || strings.index(strings.find { |str| line_in =~ /#{str}/i })] script.match_stack_clear goto jmp end end end end |
#maxconcentration ⇒ Integer
Retrieves the maximum concentration value.
1541 1542 1543 |
# File 'lib/global_defs.rb', line 1541 def maxconcentration() XMLData.max_concentration end |
#maxhealth ⇒ Integer
Returns the maximum health value.
1420 1421 1422 1423 |
# File 'lib/global_defs.rb', line 1420 def maxhealth Lich.deprecated('maxhealth', 'Char.max_health') XMLData.max_health end |
#maxmana ⇒ Integer Also known as: max_mana
Returns the maximum mana value.
1375 1376 1377 1378 |
# File 'lib/global_defs.rb', line 1375 def maxmana Lich.deprecated('maxmana', 'Char.maxmana') XMLData.max_mana end |
#maxspirit ⇒ Integer
Returns the maximum spirit value.
1460 1461 1462 1463 |
# File 'lib/global_defs.rb', line 1460 def maxspirit Lich.deprecated('maxspirit', 'Char.max_spirit') XMLData.max_spirit end |
#maxstamina ⇒ Integer
Retrieves the maximum stamina value.
1507 1508 1509 1510 |
# File 'lib/global_defs.rb', line 1507 def maxstamina() Lich.deprecated('maxstamina', 'Char.max_stamina') XMLData.max_stamina end |
#monsterbold_end ⇒ String
Returns the end sequence for bold text based on the frontend type.
3181 3182 3183 3184 3185 3186 3187 3188 3189 |
# File 'lib/global_defs.rb', line 3181 def monsterbold_end if $frontend =~ /^(?:wizard|avalon)$/ "\034GSM\r\n" elsif $frontend =~ /^(?:stormfront|frostbite|wrayth|profanity|genie)$/ '<popBold/>' else '' end end |
#monsterbold_start ⇒ String
Returns the start sequence for bold text based on the frontend type.
3166 3167 3168 3169 3170 3171 3172 3173 3174 |
# File 'lib/global_defs.rb', line 3166 def monsterbold_start if $frontend =~ /^(?:wizard|avalon)$/ "\034GSL\r\n" elsif $frontend =~ /^(?:stormfront|frostbite|wrayth|profanity|genie)$/ '<pushBold/>' else '' end end |
#move(dir = 'none', giveup_seconds = 10, giveup_lines = 30) ⇒ Boolean?
This method handles various scenarios and responses from the game environment.
Moves the character in the specified direction.
889 890 891 892 893 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 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 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 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 |
# File 'lib/global_defs.rb', line 889 def move(dir = 'none', giveup_seconds = 10, giveup_lines = 30) # [LNet]-[Private]-Casis: "You begin to make your way up the steep headland pathway. Before traveling very far, however, you lose your footing on the loose stones. You struggle in vain to maintain your balance, then find yourself falling to the bay below!" (20:35:36) # [LNet]-[Private]-Casis: "You smack into the water with a splash and sink far below the surface." (20:35:50) # You approach the entrance and identify yourself to the guard. The guard checks over a long scroll of names and says, "I'm sorry, the Guild is open to invitees only. Please do return at a later date when we will be open to the public." if dir == 'none' echo 'move: no direction given' return false end need_full_hands = false tried_open = false tried_fix_drag = false line_count = 0 room_count = XMLData.room_count giveup_time = Time.now.to_i + giveup_seconds.to_i save_stream = Array.new put_dir = proc { if XMLData.room_count > room_count fill_hands if need_full_hands Script.current.downstream_buffer.unshift(save_stream) Script.current.downstream_buffer.flatten! return true end waitrt? wait_while { stunned? } giveup_time = Time.now.to_i + giveup_seconds.to_i line_count = 0 save_stream.push(clear) put dir } put_dir.call loop { line = get? unless line.nil? save_stream.push(line) line_count += 1 end if line.nil? sleep 0.1 elsif line =~ /^You realize that would be next to impossible while in combat.|^You can't do that while engaged!|^You are engaged to |^You need to retreat out of combat first!|^You try to move, but you're engaged|^While in combat\? You'll have better luck if you first retreat/ # DragonRealms fput 'retreat' fput 'retreat' put_dir.call elsif line =~ /^You can't enter .+ and remain hidden or invisible\.|if he can't see you!$|^You can't enter .+ when you can't be seen\.$|^You can't do that without being seen\.$|^How do you intend to get .*? attention\? After all, no one can see you right now\.$/ fput 'unhide' put_dir.call elsif (line =~ /^You (?:take a few steps toward|trudge up to|limp towards|march up to|sashay gracefully up to|skip happily towards|sneak up to|stumble toward) a rusty doorknob/) and (dir =~ /door/) which = ['first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eight', 'ninth', 'tenth', 'eleventh', 'twelfth'] # avoid stomping the room for the entire session due to a transient failure dir = dir.to_s if dir =~ /\b#{which.join('|')}\b/ dir.sub!(/\b(#{which.join('|')})\b/) { "#{which[which.index($1) + 1]}" } else dir.sub!('door', 'second door') end put_dir.call elsif line =~ /^You can't go there|^You can't (?:go|swim) in that direction\.|^Where are you trying to go\?|^What were you referring to\?|^I could not find what you were referring to\.|^How do you plan to do that here\?|^You take a few steps towards|^You cannot do that\.|^You settle yourself on|^You shouldn't annoy|^You can't go to|^That's probably not a very good idea|^Maybe you should look|^You are already(?! as far away as you can get)|^You walk over to|^You step over to|The [\w\s]+ is too far away|You may not pass\.|become impassable\.|prevents you from entering\.|Please leave promptly\.|is too far above you to attempt that\.$|^Uh, yeah\. Right\.$|^Definitely NOT a good idea\.$|^Your attempt fails|^There doesn't seem to be any way to do that at the moment\.$/ echo 'move: failed' fill_hands if need_full_hands Script.current.downstream_buffer.unshift(save_stream) Script.current.downstream_buffer.flatten! return false elsif line =~ /^[A-z\s-] is unable to follow you\.$|^An unseen force prevents you\.$|^Sorry, you aren't allowed to enter here\.|^That looks like someplace only performers should go\.|^As you climb, your grip gives way and you fall down|^The clerk stops you from entering the partition and says, "I'll need to see your ticket!"$|^The guard stops you, saying, "Only members of registered groups may enter the Meeting Hall\. If you'd like to visit, ask a group officer for a guest pass\."$|^An? .*? reaches over and grasps [A-Z][a-z]+ by the neck preventing (?:him|her) from being dragged anywhere\.$|^You'll have to wait, [A-Z][a-z]+ .* locker|^As you move toward the gate, you carelessly bump into the guard|^You attempt to enter the back of the shop, but a clerk stops you. "Your reputation precedes you!|you notice that thick beams are placed across the entry with a small sign that reads, "Abandoned\."$|appears to be closed, perhaps you should try again later\?$/ echo 'move: failed' fill_hands if need_full_hands Script.current.downstream_buffer.unshift(save_stream) Script.current.downstream_buffer.flatten! # return nil instead of false to show the direction shouldn't be removed from the map database return nil elsif line =~ /^You grab [A-Z][a-z]+ and try to drag h(?:im|er), but s?he (?:is too heavy|doesn't budge)\.$|^Tentatively, you attempt to swim through the nook\. After only a few feet, you begin to sink! Your lungs burn from lack of air, and you begin to panic! You frantically paddle back to safety!$|^Guards(?:wo)?man [A-Z][a-z]+ stops you and says, "(?:Stop\.|Halt!) You need to make sure you check in|^You step into the root, but can see no way to climb the slippery tendrils inside\. After a moment, you step back out\.$|^As you start .*? back to safe ground\.$|^You stumble a bit as you try to enter the pool but feel that your persistence will pay off\.$|^A shimmering field of magical crimson and gold energy flows through the area\.$|^You attempt to navigate your way through the fog, but (?:quickly become entangled|get turned around)|^Trying to judge the climb, you peer over the edge\.\s*A wave of dizziness hits you, and you back away from the .*\.$|^You approach the .*, but the steepness is intimidating\.$|^You make your way (?:up|down) the .*\.\s*Partway (?:up|down), you make the mistake of looking down\. Struck by vertigo, you cling to the .* for a few moments, then slowly climb back (?:up|down)\.$|^You pick your way up the .*, but reach a point where your footing is questionable.\s*Reluctantly, you climb back down.$/ sleep 1 waitrt? put_dir.call elsif line =~ /^Climbing.*(?:plunge|fall)|^Tentatively, you attempt to climb.*(?:fall|slip)|^You start up the .* but slip after a few feet and fall to the ground|^You start.*but quickly realize|^You.*drop back to the ground|^You leap .* fall unceremoniously to the ground in a heap\.$|^You search for a way to make the climb .*? but without success\.$|^You start to climb .* you fall to the ground|^You attempt to climb .* wrong approach|^You run towards .*? slowly retreat back, reassessing the situation\.|^You attempt to climb down the .*, but you can't seem to find purchase\.|^You start down the .*, but you find it hard going.\s*Rather than risking a fall, you make your way back up\./ sleep 1 waitrt? fput 'stand' unless standing? waitrt? put_dir.call elsif line =~ /^You begin to climb up the silvery thread.* you tumble to the ground/ sleep 0.5 waitrt? fput 'stand' unless standing? waitrt? if checkleft or checkright need_full_hands = true empty_hands end put_dir.call elsif line == 'You are too injured to be doing any climbing!' if (resolve = Spell[9704]) and resolve.known? wait_until { resolve.affordable? } resolve.cast put_dir.call else return nil end elsif line =~ /^You(?:'re going to| will) have to climb that\./ dir.gsub!('go', 'climb') put_dir.call elsif line =~ /^You can't climb that\./ dir.gsub!('climb', 'go') put_dir.call elsif line =~ /^You can't drag/ if tried_fix_drag fill_hands if need_full_hands Script.current.downstream_buffer.unshift(save_stream) Script.current.downstream_buffer.flatten! return false elsif (dir =~ /^(?:go|climb) .+$/) and (drag_line = reget.reverse.find { |l| l =~ /^You grab .*?(?:'s body)? and drag|^You are now automatically attempting to drag .*? when/ }) tried_fix_drag = true name = (/^You grab (.*?)('s body)? and drag/.match(drag_line).captures.first || /^You are now automatically attempting to drag (.*?) when/.match(drag_line).captures.first) target = /^(?:go|climb) (.+)$/.match(dir).captures.first fput "drag #{name}" dir = "drag #{name} #{target}" put_dir.call else tried_fix_drag = true dir.sub!(/^climb /, 'go ') put_dir.call end elsif line =~ /^Maybe if your hands were empty|^You figure freeing up both hands might help\.|^You can't .+ with your hands full\.$|^You'll need empty hands to climb that\.$|^It's a bit too difficult to swim holding|^You will need both hands free for such a difficult task\./ need_full_hands = true empty_hands put_dir.call elsif line =~ /(?:appears|seems) to be closed\.$|^You cannot quite manage to squeeze between the stone doors\.$/ if tried_open fill_hands if need_full_hands Script.current.downstream_buffer.unshift(save_stream) Script.current.downstream_buffer.flatten! return false else tried_open = true fput dir.sub(/go|climb/, 'open') put_dir.call end elsif line =~ /^(\.\.\.w|W)ait ([0-9]+) sec(onds)?\.$/ if $2.to_i > 1 sleep($2.to_i - "0.2".to_f) else sleep 0.3 end put_dir.call elsif line =~ /will have to stand up first|must be standing first|^You'll have to get up first|^But you're already sitting!|^Shouldn't you be standing first|^That would be quite a trick from that position\. Try standing up\.|^Perhaps you should stand up|^Standing up might help|^You should really stand up first|You can't do that while sitting|You must be standing to do that|You can't do that while lying down/ fput 'stand' waitrt? put_dir.call elsif line =~ /^You're still recovering from your recent/ sleep 2 put_dir.call elsif line =~ /^The ground approaches you at an alarming rate/ sleep 1 fput 'stand' unless standing? put_dir.call elsif line =~ /You go flying down several feet, landing with a/ sleep 1 fput 'stand' unless standing? put_dir.call elsif line =~ /^Sorry, you may only type ahead/ sleep 1 put_dir.call elsif line == 'You are still stunned.' wait_while { stunned? } put_dir.call elsif line =~ /you slip (?:on a patch of ice )?and flail uselessly as you land on your rear(?:\.|!)$|You wobble and stumble only for a moment before landing flat on your face!$|^You slip in the mud and fall flat on your back\!$/ waitrt? fput 'stand' unless standing? waitrt? put_dir.call elsif line =~ /^You flick your hand (?:up|down)wards and focus your aura on your disk, but your disk only wobbles briefly\.$/ put_dir.call elsif line =~ /^You dive into the fast-moving river, but the current catches you and whips you back to shore, wet and battered\.$|^Running through the swampy terrain, you notice a wet patch in the bog|^You flounder around in the water.$|^You blunder around in the water, barely able|^You struggle against the swift current to swim|^You slap at the water in a sad failure to swim|^You work against the swift current to swim/ waitrt? put_dir.call elsif line =~ /^(You notice .* at your feet, and do not wish to leave it behind|As you prepare to move away, you remember)/ fput "stow feet" sleep 1 put_dir.call elsif line == "You don't seem to be able to move to do that." 30.times { break if clear.include?('You regain control of your senses!') sleep 0.1 } put_dir.call elsif line =~ /^It's pitch dark and you can't see a thing!/ echo "You will need a light source to continue your journey" return true end if XMLData.room_count > room_count fill_hands if need_full_hands Script.current.downstream_buffer.unshift(save_stream) Script.current.downstream_buffer.flatten! return true end if Time.now.to_i >= giveup_time echo "move: no recognized response in #{giveup_seconds} seconds. giving up." fill_hands if need_full_hands Script.current.downstream_buffer.unshift(save_stream) Script.current.downstream_buffer.flatten! return nil end if line_count >= giveup_lines echo "move: no recognized response after #{line_count} lines. giving up." fill_hands if need_full_hands Script.current.downstream_buffer.unshift(save_stream) Script.current.downstream_buffer.flatten! return nil end } end |
#muckled? ⇒ Boolean
This method requires a better DR solution.
Checks if the character is muckled based on the game type.
511 512 513 514 515 516 517 518 |
# File 'lib/global_defs.rb', line 511 def muckled? # need a better DR solution if XMLData.game =~ /GS/ return Status.muckled? else return checkdead || checkstunned || checkwebbed end end |
#multifput(*cmds) ⇒ void
This method returns an undefined value.
Sends multiple commands to the script.
2433 2434 2435 |
# File 'lib/global_defs.rb', line 2433 def multifput(*cmds) cmds.flatten.compact.each { |cmd| fput(cmd) } end |
#multimove(*dirs) ⇒ void
This method returns an undefined value.
Moves the character in the specified directions.
834 835 836 |
# File 'lib/global_defs.rb', line 834 def multimove(*dirs) dirs.flatten.each { |dir| move(dir) } end |
#n ⇒ String
Returns The string ‘north’.
839 |
# File 'lib/global_defs.rb', line 839 def n; 'north'; end |
#ne ⇒ String
Returns The string ‘northeast’.
842 |
# File 'lib/global_defs.rb', line 842 def ne; 'northeast'; end |
#no_kill_all ⇒ void
This method returns an undefined value.
Toggles the no_kill_all setting for the current script.
143 144 145 146 |
# File 'lib/global_defs.rb', line 143 def no_kill_all script = Script.current script.no_kill_all = !script.no_kill_all end |
#no_pause_all ⇒ void
This method returns an undefined value.
Toggles the no_pause_all setting for the current script.
153 154 155 156 |
# File 'lib/global_defs.rb', line 153 def no_pause_all script = Script.current script.no_pause_all = !script.no_pause_all end |
#noded_pulse ⇒ Integer
Calculates the pulse value for a noded character based on their profession and game state.
2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 |
# File 'lib/global_defs.rb', line 2743 def noded_pulse unless XMLData.game =~ /DR/ if Stats.prof =~ /warrior|rogue|sorcerer/i stats = [Skills.smc.to_i, Skills.emc.to_i] elsif Stats.prof =~ /empath|bard/i stats = [Skills.smc.to_i, Skills.mmc.to_i] elsif Stats.prof =~ /wizard/i stats = [Skills.emc.to_i, 0] elsif Stats.prof =~ /paladin|cleric|ranger/i stats = [Skills.smc.to_i, 0] else stats = [0, 0] end return (XMLData.max_mana * 25 / 100) + (stats.max / 10) + (stats.min / 20) else return 0 # this method is not used by DR end end |
#nw ⇒ String
Returns The string ‘northwest’.
860 |
# File 'lib/global_defs.rb', line 860 def nw; 'northwest'; end |
#out ⇒ String
Returns The string ‘out’.
878 |
# File 'lib/global_defs.rb', line 878 def out; 'out'; end |
#outside? ⇒ Boolean Also known as: checkoutside
Checks if the player is currently outside based on room exits.
1705 1706 1707 1708 1709 1710 1711 |
# File 'lib/global_defs.rb', line 1705 def outside? if XMLData.room_exits_string =~ /Obvious paths:/ true else false end end |
#parse_list(string) ⇒ Array<String>
Parses a string into a list.
355 356 357 |
# File 'lib/global_defs.rb', line 355 def parse_list(string) string.split_as_list end |
#pause(num = 1) ⇒ nil
Pauses execution for a specified duration.
2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 |
# File 'lib/global_defs.rb', line 2125 def pause(num = 1) if num.to_s =~ /m/ sleep((num.sub(/m/, '').to_f * 60)) elsif num.to_s =~ /h/ sleep((num.sub(/h/, '').to_f * 3600)) elsif num.to_s =~ /d/ sleep((num.sub(/d/, '').to_f * 86400)) else sleep(num.to_f) end end |
#pause_script(*names) ⇒ void Also known as: pause_scripts
This method returns an undefined value.
Pauses the specified scripts by name.
295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/global_defs.rb', line 295 def pause_script(*names) names.flatten! if names.empty? Script.current.pause Script.current else names.each { |scr| fnd = Script.list.find { |nm| nm.name =~ /^#{scr}/i } fnd.pause unless (fnd.paused || fnd.nil?) } end end |
#percentconcentration(num = nil) ⇒ Integer, Boolean
Calculates the percentage of concentration based on current and maximum concentration values.
If num is provided, returns true if the percentage is greater than or equal to num, otherwise false.
1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 |
# File 'lib/global_defs.rb', line 1554 def percentconcentration(num = nil) if XMLData.max_concentration == 0 percent = 100 else percent = ((XMLData.concentration.to_f / XMLData.max_concentration.to_f) * 100).to_i end if num.nil? percent else percent >= num.to_i end end |
#percentencumbrance(num = nil) ⇒ Integer, Boolean
Calculates the percentage of encumbrance based on current encumbrance value.
If num is provided, returns true if the current encumbrance value is greater than or equal to num, otherwise false.
1657 1658 1659 1660 1661 1662 1663 1664 |
# File 'lib/global_defs.rb', line 1657 def percentencumbrance(num = nil) Lich.deprecated('percentencumbrance', 'Char.percent_encumbrance') if num.nil? XMLData.encumbrance_value else num.to_i <= XMLData.encumbrance_value end end |
#percenthealth(num = nil) ⇒ Integer, Boolean
Checks the percentage of current health relative to maximum health.
1431 1432 1433 1434 1435 1436 1437 1438 |
# File 'lib/global_defs.rb', line 1431 def percenthealth(num = nil) Lich.deprecated('percenthealth', 'Char.percent_health') if num.nil? ((XMLData.health.to_f / XMLData.max_health.to_f) * 100).to_i else ((XMLData.health.to_f / XMLData.max_health.to_f) * 100).to_i >= num.to_i end end |
#percentmana(num = nil) ⇒ Integer, Boolean
Checks the percentage of current mana relative to maximum mana.
1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 |
# File 'lib/global_defs.rb', line 1386 def percentmana(num = nil) Lich.deprecated('percentmana', 'Char.percent_mana') if XMLData.max_mana == 0 percent = 100 else percent = ((XMLData.mana.to_f / XMLData.max_mana.to_f) * 100).to_i end if num.nil? percent else percent >= num.to_i end end |
#percentmind(num = nil) ⇒ Integer, Boolean
Checks the current mind value or compares it to a given number.
1321 1322 1323 1324 1325 1326 1327 |
# File 'lib/global_defs.rb', line 1321 def percentmind(num = nil) if num.nil? XMLData.mind_value else XMLData.mind_value >= num.to_i end end |
#percentspirit(num = nil) ⇒ Integer, Boolean
Calculates the percentage of spirit based on current and maximum spirit values.
If num is provided, returns true if the percentage is greater than or equal to num, otherwise false.
1474 1475 1476 1477 1478 1479 1480 1481 |
# File 'lib/global_defs.rb', line 1474 def percentspirit(num = nil) Lich.deprecated('percentspirit', 'Char.percent_spirit') if num.nil? ((XMLData.spirit.to_f / XMLData.max_spirit.to_f) * 100).to_i else ((XMLData.spirit.to_f / XMLData.max_spirit.to_f) * 100).to_i >= num.to_i end end |
#percentstamina(num = nil) ⇒ Integer, Boolean
Calculates the percentage of stamina based on current and maximum stamina values.
If num is provided, returns true if the percentage is greater than or equal to num, otherwise false.
1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 |
# File 'lib/global_defs.rb', line 1521 def percentstamina(num = nil) Lich.deprecated('percentstamina', 'Char.percent_stamina') if XMLData.max_stamina == 0 percent = 100 else percent = ((XMLData.stamina.to_f / XMLData.max_stamina.to_f) * 100).to_i end if num.nil? percent else percent >= num.to_i end end |
#percentstance(num = nil) ⇒ Integer, Boolean
Retrieves the current stance value or compares it against a given threshold.
If num is provided, returns true if the current stance value is greater than or equal to num, otherwise false.
1614 1615 1616 1617 1618 1619 1620 1621 |
# File 'lib/global_defs.rb', line 1614 def percentstance(num = nil) Lich.deprecated('percentstance', 'Char.percent_stance') if num.nil? XMLData.stance_value else XMLData.stance_value >= num.to_i end end |
#put(*messages) ⇒ void
This method returns an undefined value.
Sends messages to the game output.
2510 2511 2512 |
# File 'lib/global_defs.rb', line 2510 def put(*) .each { || Game.puts() } end |
#quiet_exit ⇒ void
This method returns an undefined value.
Toggles the quiet mode of the current script.
2519 2520 2521 2522 |
# File 'lib/global_defs.rb', line 2519 def quiet_exit script = Script.current script.quiet = !(script.quiet) end |
#reget(*lines) ⇒ Array<String>?
Retrieves lines of input based on the provided criteria.
2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 |
# File 'lib/global_defs.rb', line 2386 def reget(*lines) unless (script = Script.current) then respond('--- reget: Unable to identify calling script.'); return false; end lines.flatten! if caller.find { |c| c =~ /regetall/ } history = ($_SERVERBUFFER_.history + $_SERVERBUFFER_).join("\n") else history = $_SERVERBUFFER_.dup.join("\n") end unless script.want_downstream_xml history.gsub!(/<pushStream id=["'](?:spellfront|inv|bounty|society)["'][^>]*\/>.*?<popStream[^>]*>/m, '') history.gsub!(/<stream id="Spells">.*?<\/stream>/m, '') history.gsub!(/<(compDef|inv|component|right|left|spell|prompt)[^>]*>.*?<\/\1>/m, '') history.gsub!(/<[^>]+>/, '') history.gsub!('>', '>') history.gsub!('<', '<') end history = history.split("\n").delete_if { |line| line.nil? or line.empty? or line =~ /^[\r\n\s\t]*$/ } if lines.first.kind_of?(Numeric) or lines.first.to_i.nonzero? history = history[-([lines.shift.to_i, history.length].min)..-1] end unless lines.empty? or lines.nil? regex = /#{lines.join('|')}/i history = history.find_all { |line| line =~ regex } end if history.empty? nil else history end end |
#regetall(*lines) ⇒ Array<String>?
Retrieves all lines of input based on the provided criteria.
2423 2424 2425 |
# File 'lib/global_defs.rb', line 2423 def regetall(*lines) reget(*lines) end |
#report_errors(&block) ⇒ nil
Reports errors that occur during the execution of the given block.
3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 |
# File 'lib/global_defs.rb', line 3557 def report_errors(&block) begin block.call rescue respond "--- Lich: error: #{$!}\n\t#{$!.backtrace[0..1].join("\n\t")}" Lich.log "error: #{$!}\n\t#{$!.backtrace.join("\n\t")}" rescue SyntaxError respond "--- Lich: error: #{$!}\n\t#{$!.backtrace[0..1].join("\n\t")}" Lich.log "error: #{$!}\n\t#{$!.backtrace.join("\n\t")}" rescue SystemExit nil rescue SecurityError respond "--- Lich: error: #{$!}\n\t#{$!.backtrace[0..1].join("\n\t")}" Lich.log "error: #{$!}\n\t#{$!.backtrace.join("\n\t")}" rescue ThreadError respond "--- Lich: error: #{$!}\n\t#{$!.backtrace[0..1].join("\n\t")}" Lich.log "error: #{$!}\n\t#{$!.backtrace.join("\n\t")}" rescue SystemStackError respond "--- Lich: error: #{$!}\n\t#{$!.backtrace[0..1].join("\n\t")}" Lich.log "error: #{$!}\n\t#{$!.backtrace.join("\n\t")}" rescue StandardError respond "--- Lich: error: #{$!}\n\t#{$!.backtrace[0..1].join("\n\t")}" Lich.log "error: #{$!}\n\t#{$!.backtrace.join("\n\t")}" # rescue ScriptError # respond "--- Lich: error: #{$!}\n\t#{$!.backtrace[0..1].join("\n\t")}" # Lich.log "error: #{$!}\n\t#{$!.backtrace.join("\n\t")}" rescue LoadError respond "--- Lich: error: #{$!}\n\t#{$!.backtrace[0..1].join("\n\t")}" Lich.log "error: #{$!}\n\t#{$!.backtrace.join("\n\t")}" rescue NoMemoryError respond "--- Lich: error: #{$!}\n\t#{$!.backtrace[0..1].join("\n\t")}" Lich.log "error: #{$!}\n\t#{$!.backtrace.join("\n\t")}" rescue respond "--- Lich: error: #{$!}\n\t#{$!.backtrace[0..1].join("\n\t")}" Lich.log "error: #{$!}\n\t#{$!.backtrace.join("\n\t")}" end end |
#respond(first = "", *messages) ⇒ void
This method returns an undefined value.
Responds to the client with the provided messages.
2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 |
# File 'lib/global_defs.rb', line 2654 def respond(first = "", *) str = '' begin if first.class == Array first.flatten.each { |ln| str += sprintf("%s\r\n", ln.to_s.chomp) } else str += sprintf("%s\r\n", first.to_s.chomp) end .flatten.each { || str += sprintf("%s\r\n", .to_s.chomp) } str.split(/\r?\n/).each { |line| Script.new_script_output(line); Buffer.update(line, Buffer::SCRIPT_OUTPUT) } # str.gsub!(/\r?\n/, "\r\n") if $frontend == 'genie' if $frontend == 'stormfront' || $frontend == 'genie' str = "<output class=\"mono\"/>\r\n#{str.gsub('&', '&').gsub('<', '<').gsub('>', '>')}<output class=\"\"/>\r\n" elsif $frontend == 'profanity' str = str.gsub('&', '&').gsub('<', '<').gsub('>', '>') end # Double-checked locking to avoid interrupting a stream and crashing the client str_sent = false if $_CLIENT_ until str_sent wait_while { !XMLData.safe_to_respond? } str_sent = $_CLIENT_.puts_if(str) { XMLData.safe_to_respond? } end end if $_DETACHABLE_CLIENT_ str_sent = false until str_sent wait_while { !XMLData.safe_to_respond? } begin str_sent = $_DETACHABLE_CLIENT_.puts_if(str) { XMLData.safe_to_respond? } rescue break end end end rescue puts $! puts $!.backtrace.first end end |
#reverse_direction(dir) ⇒ String, Boolean
Reverses a given direction.
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 |
# File 'lib/global_defs.rb', line 1192 def reverse_direction(dir) if dir == "n" then 's' elsif dir == "ne" then 'sw' elsif dir == "e" then 'w' elsif dir == "se" then 'nw' elsif dir == "s" then 'n' elsif dir == "sw" then 'ne' elsif dir == "w" then 'e' elsif dir == "nw" then 'se' elsif dir == "up" then 'down' elsif dir == "down" then 'up' elsif dir == "out" then 'out' elsif dir == 'o' then out elsif dir == 'u' then 'down' elsif dir == 'd' then up elsif dir == n then s elsif dir == ne then sw elsif dir == e then w elsif dir == se then nw elsif dir == s then n elsif dir == sw then ne elsif dir == w then e elsif dir == nw then se elsif dir == u then d elsif dir == d then u else echo("Cannot recognize direction to properly reverse it!"); false end end |
#run ⇒ nil
Runs the walk method in a loop until it returns false.
1256 1257 1258 |
# File 'lib/global_defs.rb', line 1256 def run loop { break unless walk } end |
#running?(*snames) ⇒ Boolean
Checks if the specified scripts are currently running.
112 113 114 115 |
# File 'lib/global_defs.rb', line 112 def running?(*snames) snames.each { |checking| (return false) unless (Script.running.find { |lscr| lscr.name =~ /^#{checking}$/i } || Script.running.find { |lscr| lscr.name =~ /^#{checking}/i } || Script.hidden.find { |lscr| lscr.name =~ /^#{checking}$/i } || Script.hidden.find { |lscr| lscr.name =~ /^#{checking}/i }) } true end |
#s ⇒ String
Returns The string ‘south’.
851 |
# File 'lib/global_defs.rb', line 851 def s; 'south'; end |
#se ⇒ String
Returns The string ‘southeast’.
848 |
# File 'lib/global_defs.rb', line 848 def se; 'southeast'; end |
#selectput(string, success, failure, timeout = nil) ⇒ String?
Sends a command and waits for a response, handling success and failure cases.
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 |
# File 'lib/global_defs.rb', line 675 def selectput(string, success, failure, timeout = nil) timeout = timeout.to_f if timeout and !timeout.kind_of?(Numeric) success = [success] if success.kind_of? String failure = [failure] if failure.kind_of? String if !string.kind_of?(String) or !success.kind_of?(Array) or !failure.kind_of?(Array) or timeout && !timeout.kind_of?(Numeric) raise ArgumentError, "usage is: selectput(game_command,success_array,failure_array[,timeout_in_secs])" end success.flatten! failure.flatten! regex = /#{(success + failure).join('|')}/i successre = /#{success.join('|')}/i thr = Thread.current timethr = Thread.new { timeout -= sleep("0.1".to_f) until timeout <= 0 thr.raise(StandardError) } if timeout begin loop { fput(string) response = waitforre(regex) if successre.match(response.to_s) timethr.kill if timethr.alive? break(response.string) end yield(response.string) if block_given? } rescue nil end end |
#send_scripts(*messages) ⇒ Boolean Also known as: send_script
Sends messages to downstream scripts.
2613 2614 2615 2616 2617 2618 2619 |
# File 'lib/global_defs.rb', line 2613 def send_scripts(*) .flatten! .each { || Script.new_downstream() } true end |
#send_to_script(*values) ⇒ Boolean
Sends values to a script that matches the first value.
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 |
# File 'lib/global_defs.rb', line 756 def send_to_script(*values) values.flatten! if (script = Script.list.find { |val| val.name =~ /^#{values.first}/i }) if script.want_downstream values[1..-1].each { |val| script.downstream_buffer.push(val) } else values[1..-1].each { |val| script.unique_buffer.push(val) } end echo("Sent to #{script.name} -- '#{values[1..-1].join(' ; ')}'") return true else echo("'#{values.first}' does not match any active scripts!") return false end end |
#setpriority(val = nil) ⇒ Integer Also known as: priority?
Sets the priority of the current thread.
1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 |
# File 'lib/global_defs.rb', line 1974 def setpriority(val = nil) if val.nil? then return Thread.current.priority end if val.to_i > 3 echo("You're trying to set a script's priority as being higher than the send/recv threads (this is telling Lich to run the script before it even gets data to give the script, and is useless); the limit is 3") return Thread.current.priority else Thread.current.group.list.each { |thr| thr.priority = val.to_i } return Thread.current.priority end end |
#sf_to_wiz(line) ⇒ String?
Converts a line from server format to wizard format.
3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 |
# File 'lib/global_defs.rb', line 3054 def sf_to_wiz(line) begin return line if line == "\r\n" if $sftowiz_multiline $sftowiz_multiline = $sftowiz_multiline + line line = $sftowiz_multiline end if (line.scan(/<pushStream[^>]*\/>/).length > line.scan(/<popStream[^>]*\/>/).length) $sftowiz_multiline = line return nil end if (line.scan(/<style id="\w+"[^>]*\/>/).length > line.scan(/<style id=""[^>]*\/>/).length) $sftowiz_multiline = line return nil end $sftowiz_multiline = nil if line =~ /<LaunchURL src="(.*?)" \/>/ $_CLIENT_.puts "\034GSw00005\r\nhttps://www.play.net#{$1}\r\n" end if line =~ /<preset id='speech'>(.*?)<\/preset>/m line = line.sub(/<preset id='speech'>.*?<\/preset>/m, "#{$speech_highlight_start}#{$1}#{$speech_highlight_end}") end if line =~ /<pushStream id="thoughts"[^>]*>\[([^\\]+?)\]\s*(.*?)<popStream\/>/m thought_channel = $1 msg = $2 thought_channel.gsub!(' ', '-') msg.gsub!('<pushBold/>', '') msg.gsub!('<popBold/>', '') line = line.sub(/<pushStream id="thoughts".*<popStream\/>/m, "You hear the faint thoughts of [#{thought_channel}]-ESP echo in your mind:\r\n#{msg}") end if line =~ /<pushStream id="voln"[^>]*>\[Voln \- (?:<a[^>]*>)?([A-Z][a-z]+)(?:<\/a>)?\]\s*(".*")[\r\n]*<popStream\/>/m line = line.sub(/<pushStream id="voln"[^>]*>\[Voln \- (?:<a[^>]*>)?([A-Z][a-z]+)(?:<\/a>)?\]\s*(".*")[\r\n]*<popStream\/>/m, "The Symbol of Thought begins to burn in your mind and you hear #{$1} thinking, #{$2}\r\n") end if line =~ /<stream id="thoughts"[^>]*>([^:]+): (.*?)<\/stream>/m line = line.sub(/<stream id="thoughts"[^>]*>.*?<\/stream>/m, "You hear the faint thoughts of #{$1} echo in your mind:\r\n#{$2}") end if line =~ /<pushStream id="familiar"[^>]*>(.*)<popStream\/>/m line = line.sub(/<pushStream id="familiar"[^>]*>.*<popStream\/>/m, "\034GSe\r\n#{$1}\034GSf\r\n") end if line =~ /<pushStream id="death"\/>(.*?)<popStream\/>/m line = line.sub(/<pushStream id="death"\/>.*?<popStream\/>/m, "\034GSw00003\r\n#{$1}\034GSw00004\r\n") end if line =~ /<style id="roomName" \/>(.*?)<style id=""\/>/m line = line.sub(/<style id="roomName" \/>.*?<style id=""\/>/m, "\034GSo\r\n#{$1}\034GSp\r\n") end line.gsub!(/<style id="roomDesc"\/><style id=""\/>\r?\n/, '') if line =~ /<style id="roomDesc"\/>(.*?)<style id=""\/>/m desc = $1.gsub(/<a[^>]*>/, $link_highlight_start).gsub("</a>", $link_highlight_end) line = line.sub(/<style id="roomDesc"\/>.*?<style id=""\/>/m, "\034GSH\r\n#{desc}\034GSI\r\n") end line = line.gsub("</prompt>\r\n", "</prompt>") line = line.gsub("<pushBold/>", "\034GSL\r\n") line = line.gsub("<popBold/>", "\034GSM\r\n") line = line.gsub(/<pushStream id=["'](?:spellfront|inv|bounty|society|speech|talk)["'][^>]*\/>.*?<popStream[^>]*>/m, '') line = line.gsub(/<stream id="Spells">.*?<\/stream>/m, '') line = line.gsub(/<(compDef|inv|component|right|left|spell|prompt)[^>]*>.*?<\/\1>/m, '') line = line.gsub(/<[^>]+>/, '') line = line.gsub('>', '>') line = line.gsub('<', '<') line = line.gsub('&', '&') return nil if line.gsub("\r\n", '').length < 1 return line rescue $_CLIENT_.puts "--- Error: sf_to_wiz: #{$!}" $_CLIENT_.puts "$_SERVERSTRING_: #{$_SERVERSTRING_}" Lich.log("--- Error: sf_to_wiz: #{$!}\n\t#{$!.backtrace.join("\n\t")}") Lich.log("$_SERVERSTRING_: #{$_SERVERSTRING_}") Lich.log("Line: #{line}") end end |
#silence_me ⇒ Boolean?
Toggles the silent mode for the current script.
173 174 175 176 177 178 179 180 |
# File 'lib/global_defs.rb', line 173 def silence_me unless (script = Script.current) then echo 'silence_me: cannot identify calling script.'; return nil; end if script.safe? then echo("WARNING: 'safe' script attempted to silence itself. Ignoring the request.") sleep 1 return true end script.silent = !script.silent end |
#silenced? ⇒ Boolean
Checks if the player is currently silenced.
2060 2061 2062 2063 |
# File 'lib/global_defs.rb', line 2060 def silenced? return Status.silenced? if XMLData.game =~ /GS/ fail "Error: toplevel silenced? command not enabled in #{XMLData.game}" end |
#sleeping? ⇒ Boolean
Checks if the player is currently sleeping.
2016 2017 2018 2019 |
# File 'lib/global_defs.rb', line 2016 def sleeping? return Status.sleeping? if XMLData.game =~ /GS/ fail "Error: toplevel sleeping? command not enabled in #{XMLData.game}" end |
#start_exec_script(cmd_data, options = Hash.new) ⇒ void
This method returns an undefined value.
Starts an execution script with the given command data and options.
124 125 126 |
# File 'lib/global_defs.rb', line 124 def start_exec_script(cmd_data, = Hash.new) ExecScript.start(cmd_data, ) end |
#start_script(script_name, cli_vars = [], flags = Hash.new) ⇒ void
This method returns an undefined value.
Starts a script with the given name and optional command line variables and flags.
16 17 18 19 20 21 |
# File 'lib/global_defs.rb', line 16 def start_script(script_name, cli_vars = [], flags = Hash.new) if flags == true flags = { :quiet => true } end Script.start(script_name, cli_vars.join(' '), flags) end |
#start_scripts(*script_names) ⇒ void
This method returns an undefined value.
Starts multiple scripts sequentially.
29 30 31 32 33 34 |
# File 'lib/global_defs.rb', line 29 def start_scripts(*script_names) script_names.flatten.each { |script_name| start_script(script_name) sleep 0.02 } end |
#status_tags(onoff = "none") ⇒ void Also known as: toggle_status
This method returns an undefined value.
Inserts status tags for the current script based on the provided on/off parameter.
2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 |
# File 'lib/global_defs.rb', line 2627 def (onoff = "none") script = Script.current if onoff == "on" script.want_downstream = false script.want_downstream_xml = true echo("Status tags will be sent to this script.") elsif onoff == "off" script.want_downstream = true script.want_downstream_xml = false echo("Status tags will no longer be sent to this script.") elsif script.want_downstream_xml script.want_downstream = true script.want_downstream_xml = false else script.want_downstream = false script.want_downstream_xml = true end end |
#stop_script(*target_names) ⇒ Integer, false Also known as: stop_scripts, kill_scripts, kill_script
Stops the specified scripts by name.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/global_defs.rb', line 84 def stop_script(*target_names) numkilled = 0 target_names.each { |target_name| condemned = Script.list.find { |s_sock| s_sock.name =~ /^#{target_name}/i } if condemned.nil? respond("--- Lich: '#{Script.current}' tried to stop '#{target_name}', but it isn't running!") else if condemned.name =~ /^#{Script.current.name}$/i exit end condemned.kill respond("--- Lich: '#{condemned}' has been stopped by #{Script.current}.") numkilled += 1 end } if numkilled == 0 return false else return numkilled end end |
#strip_xml(line, type: 'main') ⇒ String?
This method maintains state for multiline content based on the type.
Strips XML tags from a line based on the specified type.
3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 |
# File 'lib/global_defs.rb', line 3135 def strip_xml(line, type: 'main') return line if line == "\r\n" if $strip_xml_multiline[type] $strip_xml_multiline[type] = $strip_xml_multiline[type] + line line = $strip_xml_multiline[type] end if (line.scan(/<pushStream[^>]*\/>/).length > line.scan(/<popStream[^>]*\/>/).length) $strip_xml_multiline ||= {} $strip_xml_multiline[type] = line return nil end $strip_xml_multiline[type] = nil line = line.gsub(/<pushStream id=["'](?:spellfront|inv|bounty|society|speech|talk)["'][^>]*\/>.*?<popStream[^>]*>/m, '') line = line.gsub(/<stream id="Spells">.*?<\/stream>/m, '') line = line.gsub(/<(compDef|inv|component|right|left|spell|prompt)[^>]*>.*?<\/\1>/m, '') line = line.gsub(/<[^>]+>/, '') line = line.gsub('>', '>') line = line.gsub('<', '<') return nil if line.gsub("\n", '').gsub("\r", '').gsub(' ', '').length < 1 return line end |
#survivedisease? ⇒ Boolean
Checks if the character can survive disease.
24 25 26 27 |
# File 'lib/deprecated.rb', line 24 def survivedisease? echo 'survivepoison? called, but there is no XML for disease rate' return true end |
#survivepoison? ⇒ Boolean
Checks if the character can survive poison.
14 15 16 17 |
# File 'lib/deprecated.rb', line 14 def survivepoison? echo 'survivepoison? called, but there is no XML for poison rate' return true end |
#sw ⇒ String
Returns The string ‘southwest’.
854 |
# File 'lib/global_defs.rb', line 854 def sw; 'southwest'; end |
#take(*items) ⇒ void
This method returns an undefined value.
Takes items and places them into the user’s bag.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/deprecated.rb', line 68 def take(*items) items.flatten! if (righthand? && lefthand?) weap = checkright fput "put my #{checkright} in my #{UserVars.lootsack}" unsh = true else unsh = false end items.each { |trinket| fput "take #{trinket}" fput("put my #{trinket} in my #{UserVars.lootsack}") if (righthand? || lefthand?) } if unsh then fput("take my #{weap} from my #{UserVars.lootsack}") end end |
#timetest(*contestants) ⇒ Array<Float>
Times the execution of provided code blocks.
631 632 633 |
# File 'lib/global_defs.rb', line 631 def timetest(*contestants) contestants.collect { |code| start = Time.now; 5000.times { code.call }; Time.now - start } end |
#toggle_echo ⇒ void?
Toggles the echo setting for the current script.
187 188 189 190 |
# File 'lib/global_defs.rb', line 187 def toggle_echo unless (script = Script.current) then respond('--- toggle_echo: Unable to identify calling script.'); return nil; end script.no_echo = !script.no_echo end |
#toggle_unique ⇒ nil
Toggles the unique downstream setting for the current script.
714 715 716 717 |
# File 'lib/global_defs.rb', line 714 def toggle_unique unless (script = Script.current) then echo 'toggle_unique: cannot identify calling script.'; return nil; end script.want_downstream = !script.want_downstream end |
#toggle_upstream ⇒ void?
Toggles the upstream setting for the current script.
163 164 165 166 |
# File 'lib/global_defs.rb', line 163 def toggle_upstream unless (script = Script.current) then echo 'toggle_upstream: cannot identify calling script.'; return nil; end script.want_upstream = !script.want_upstream end |
#undo_before_dying ⇒ void
This method returns an undefined value.
Clears any previously registered exit procedures.
65 66 67 |
# File 'lib/global_defs.rb', line 65 def Script.clear_exit_procs end |
#unique_get ⇒ String?
Retrieves a unique line from the current script’s unique input.
813 814 815 816 |
# File 'lib/global_defs.rb', line 813 def unique_get unless (script = Script.current) then echo 'unique_get: cannot identify calling script.'; return nil; end script.unique_gets end |
#unique_get? ⇒ Boolean?
Checks if there is a unique line available from the current script’s unique input.
823 824 825 826 |
# File 'lib/global_defs.rb', line 823 def unique_get? unless (script = Script.current) then echo 'unique_get: cannot identify calling script.'; return nil; end script.unique_gets? end |
#unique_send_to_script(*values) ⇒ Boolean
Sends unique values to a script that matches the first value.
778 779 780 781 782 783 784 785 786 787 788 |
# File 'lib/global_defs.rb', line 778 def unique_send_to_script(*values) values.flatten! if (script = Script.list.find { |val| val.name =~ /^#{values.first}/i }) values[1..-1].each { |val| script.unique_buffer.push(val) } echo("sent to #{script}: #{values[1..-1].join(' ; ')}") return true else echo("'#{values.first}' does not match any active scripts!") return false end end |
#unique_waitfor(*strings) ⇒ String
Waits for a unique line from the current script’s unique input.
796 797 798 799 800 801 802 803 804 805 806 |
# File 'lib/global_defs.rb', line 796 def unique_waitfor(*strings) unless (script = Script.current) then echo 'unique_waitfor: cannot identify calling script.'; return nil; end strings.flatten! regexp = /#{strings.join('|')}/ while true str = script.unique_gets if str =~ regexp return str end end end |
#unnoded_pulse ⇒ Integer
Calculates the pulse value for an unnoded character based on their profession and game state.
2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 |
# File 'lib/global_defs.rb', line 2767 def unnoded_pulse unless XMLData.game =~ /DR/ if Stats.prof =~ /warrior|rogue|sorcerer/i stats = [Skills.smc.to_i, Skills.emc.to_i] elsif Stats.prof =~ /empath|bard/i stats = [Skills.smc.to_i, Skills.mmc.to_i] elsif Stats.prof =~ /wizard/i stats = [Skills.emc.to_i, 0] elsif Stats.prof =~ /paladin|cleric|ranger/i stats = [Skills.smc.to_i, 0] else stats = [0, 0] end return (XMLData.max_mana * 15 / 100) + (stats.max / 10) + (stats.min / 20) else return 0 # this method is not used by DR end end |
#unpause_script(*names) ⇒ void Also known as: unpause_scripts
This method returns an undefined value.
Unpauses the specified scripts by name.
314 315 316 317 318 319 320 |
# File 'lib/global_defs.rb', line 314 def unpause_script(*names) names.flatten! names.each { |scr| fnd = Script.list.find { |nm| nm.name =~ /^#{scr}/i } fnd.unpause if (fnd.paused and not fnd.nil?) } end |
#upstream_get ⇒ Boolean?
Retrieves upstream data for the current script.
217 218 219 220 221 222 223 224 225 |
# File 'lib/global_defs.rb', line 217 def upstream_get unless (script = Script.current) then echo 'upstream_get: cannot identify calling script.'; return nil; end unless script.want_upstream echo("This script wants to listen to the upstream, but it isn't set as receiving the upstream! This will cause a permanent hang, aborting (ask for the upstream with 'toggle_upstream' in the script)") sleep 0.3 return false end script.upstream_gets end |
#upstream_get? ⇒ Boolean?
Checks if the current script is set to receive upstream data.
232 233 234 235 236 237 238 239 |
# File 'lib/global_defs.rb', line 232 def upstream_get? unless (script = Script.current) then echo 'upstream_get: cannot identify calling script.'; return nil; end unless script.want_upstream echo("This script wants to listen to the upstream, but it isn't set as receiving the upstream! This will cause a permanent hang, aborting (ask for the upstream with 'toggle_upstream' in the script)") return false end script.upstream_gets? end |
#upstream_waitfor(*strings) ⇒ String, false
Waits for a line from the upstream that matches any of the provided strings.
738 739 740 741 742 743 744 745 746 747 748 |
# File 'lib/global_defs.rb', line 738 def upstream_waitfor(*strings) strings.flatten! script = Script.current unless script.want_upstream then echo("This script wants to listen to the upstream, but it isn't set as receiving the upstream! This will cause a permanent hang, aborting (ask for the upstream with 'toggle_upstream' in the script)"); return false end regexpstr = strings.join('|') while (line = script.upstream_gets) if line =~ /#{regexpstr}/i return line end end end |
#variable ⇒ Hash?
Retrieves the variables of the current script.
2114 2115 2116 2117 |
# File 'lib/global_defs.rb', line 2114 def variable unless (script = Script.current) then echo 'variable: cannot identify calling script.'; return nil; end script.vars end |
#wait ⇒ String
Waits for a line of input and clears the script’s buffer.
2355 2356 2357 2358 2359 |
# File 'lib/global_defs.rb', line 2355 def wait unless (script = Script.current) then respond('--- wait: unable to identify calling script.'); return false; end script.clear return script.gets end |
#wait_until(announce = nil) {|Boolean| ... } ⇒ nil
Waits until a condition is met, optionally announcing the status.
1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 |
# File 'lib/global_defs.rb', line 1137 def wait_until(announce = nil) priosave = Thread.current.priority Thread.current.priority = 0 unless announce.nil? or yield respond(announce) end until yield sleep 0.25 end Thread.current.priority = priosave end |
#wait_while(announce = nil) {|Boolean| ... } ⇒ nil
Waits while a condition is true, optionally announcing the status.
1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 |
# File 'lib/global_defs.rb', line 1156 def wait_while(announce = nil) priosave = Thread.current.priority Thread.current.priority = 0 unless announce.nil? or !yield respond(announce) end while yield sleep 0.25 end Thread.current.priority = priosave end |
#waitcastrt ⇒ void
This method returns an undefined value.
Waits for cast roundtime to complete.
374 375 376 377 |
# File 'lib/global_defs.rb', line 374 def waitcastrt wait_until { (XMLData.cast_roundtime_end.to_f - Time.now.to_f + XMLData.server_time_offset.to_f) > 0 } sleep checkcastrt end |
#waitcastrt? ⇒ Boolean
Waits for cast roundtime to complete and returns whether it was successful.
413 414 415 416 417 418 419 420 421 422 |
# File 'lib/global_defs.rb', line 413 def waitcastrt? # sleep checkcastrt current_castrt = checkcastrt if current_castrt.to_f > 0.0 sleep(current_castrt) return true else return false end end |
#waitfor(*strings) ⇒ String, false
Waits for a line of input that matches any of the provided strings.
2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 |
# File 'lib/global_defs.rb', line 2331 def waitfor(*strings) unless (script = Script.current) then respond('--- waitfor: Unable to identify calling script.'); return false; end strings.flatten! if (script.class == WizardScript) and (strings.length == 1) and (strings.first.strip == '>') return script.gets end if strings.empty? echo 'waitfor: no string to wait for' return false end regexpstr = strings.join('|') while true line_in = script.gets if (line_in =~ /#{regexpstr}/i) then return line_in end end end |
#waitforre(regexp) ⇒ nil
Waits for a line of input that matches the provided regular expression.
2318 2319 2320 2321 2322 |
# File 'lib/global_defs.rb', line 2318 def waitforre(regexp) unless (script = Script.current) then respond('--- waitforre: Unable to identify calling script.'); return false; end unless regexp.class == Regexp then echo("Script error! You have given 'waitforre' something to wait for, but it isn't a Regular Expression! Use 'waitfor' if you want to wait for a string."); sleep 1; return nil end regobj = regexp.match(script.gets) until regobj end |
#waitrt ⇒ void
This method returns an undefined value.
Waits for roundtime to complete.
364 365 366 367 |
# File 'lib/global_defs.rb', line 364 def waitrt wait_until { (XMLData.roundtime_end.to_f - Time.now.to_f + XMLData.server_time_offset.to_f) > 0 } sleep checkrt end |
#waitrt? ⇒ Boolean
Waits for roundtime to complete and returns whether it was successful.
402 403 404 405 406 |
# File 'lib/global_defs.rb', line 402 def waitrt? sleep checkrt return true if checkrt > 0.0 return false if checkrt == 0 end |
#walk(*boundaries) {|Boolean| ... } ⇒ Object
Walks through boundaries until a condition is met.
1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 |
# File 'lib/global_defs.rb', line 1229 def walk(*boundaries, &block) boundaries.flatten! unless block.nil? until (val = yield) walk(*boundaries) end return val end if $last_dir and !boundaries.empty? and checkroomdescrip =~ /#{boundaries.join('|')}/i move($last_dir) $last_dir = reverse_direction($last_dir) return checknpcs end dirs = checkpaths return checknpcs if dirs.is_a?(FalseClass) dirs.delete($last_dir) unless dirs.length < 2 this_time = rand(dirs.length) $last_dir = reverse_direction(dirs[this_time]) move(dirs[this_time]) checknpcs end |
#watchhealth(value, theproc = nil) {|Proc| ... } ⇒ nil
Watches the health of a character and executes a block or proc when health is no longer valid.
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 |
# File 'lib/global_defs.rb', line 1114 def watchhealth(value, theproc = nil, &block) value = value.to_i if block.nil? if !theproc.respond_to? :call respond "`watchhealth' was not given a block or a proc to execute!" return nil else block = theproc end end Thread.new { wait_while { health(value) } block.call } end |