Module: Lich::Gemstone::PSMS Private
- Defined in:
- documented/gemstone/psms.rb,
documented/gemstone/psms/technique.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Unified interface for Player System Manager (PSM) skills in GemStone IV.
Provides centralized utilities for Combat Maneuvers, Shield Specializations, Feats, Warcries, Weapon Techniques, Armor Specializations, and Ascension abilities. Handles skill lookup, stamina cost validation, cooldown checks, and command generation.
PSM categories are defined in separate submodules, each loadable as a file under psms/: CMan, Shield, Feat, Weapon, Armor, Warcry, Ascension, and QStrike.
Defined Under Namespace
Modules: Technique
Constant Summary collapse
- FAILURES_REGEXES =
A compiled regular expression used to match common failure messages across all PSM (Player System Manager) actions.
This constant combines several game-generated failure messages into a single
RegexpusingRegexp.union, allowing centralized pattern matching for detecting failed actions.Useful for interpreting command results and handling expected failure states in scripting logic. Note that in most cases, the match on a failure message here is not considered an error, but rather that the command succeeded, but the action itself failed for some reason.
Regexp.union( /^And give yourself away! Never!$/, /^You are unable to do that right now\.$/, /^You don't seem to be able to move to do that\.$/, /^Provoking a GameMaster is not such a good idea\.$/, /^You do not currently have a target\.$/, /^Your mind clouds with confusion and you glance around uncertainly\.$/, /^But your hands are full\!$/, /^You are still stunned\.$/, /^You lack the momentum to attempt another skill\.$/, /^You can't reach .+!$/, / attempting to .+ would be a rather awkward proposition\.$/, )
- ROUNDTIME_REGEX =
The roundtime line most techniques answer with.
/^Roundtime: [0-9]+ sec\.$/- RECOVERED_REGEX =
The lines that end "You don't seem to be able to move to do that."
/^(?:You regain control of your senses!|The restricting force that envelops you dissolves away\.)$/
Class Method Summary collapse
-
.assess(name, type, costcheck = false, forcert_count: 0) ⇒ Boolean, Object
Assess the validity or cost of a given PSM (Player System Manager) skill.
-
.available?(name, ignore_cooldown = false) ⇒ Boolean
Determines if a given PSM skill is available for use (not in cooldown, and not overexerted).
-
.can_forcert?(times) ⇒ Boolean
Determines whether the character is eligible to perform the given number of forced roundtime (forcert) rounds.
-
.command(verb, usage, target = "", forcert_count: 0) ⇒ String
The command a technique is sent with, as each category's
usesends it: the verb, the technique's usage word, an optional target, and FORCERT. -
.cost_affordable?(cost, forcert_count: 0) ⇒ Boolean
Whether current stamina (or other resource) covers a cost, with the FORCERT surcharge of 25% plus 10% per FORCERT when any are used.
-
.dispatch(usage_cmd, results_regex, timeout: 5) ⇒ String?
Sends a technique command and waits for its answer.
-
.effect_active?(registry, effect) ⇒ Boolean
Whether an unexpired effect is listed in an Effects registry.
-
.find_name(name, type) ⇒ Hash?
Finds a Player System Manager (PSM) skill by name within the specified category.
-
.invalid_technique!(name, type) ⇒ Object
Logs and raises for a technique name that is not in its category, which stops (kills) the offending script.
-
.max_forcert_count ⇒ Integer
Determines the maximum number of forced roundtime (forcert) activations allowed based on the character's Multi-Opponent Combat (MOC) training.
-
.mstrike_available?(focused: false) ⇒ Boolean
Whether MSTRIKE can be used right now: enough Multi Opponent Combat training (5 ranks open, 30 focused), not overexerted, and enough stamina for its cost while it is in recovery.
-
.name_normal(name) ⇒ String
Normalizes a name for internal lookup consistency.
-
.results_regex(name, *patterns, results_of_interest: nil) ⇒ Regexp
Every line that answers a technique command: the shared failures, the "X what?" and cooldown refusals for this technique, its own result messaging, and any extra patterns.
-
.single_target?(target) ⇒ Boolean
Whether a technique target names a single creature or character, as opposed to none (the character, or the room) or ALL.
Class Method Details
.assess(name, type, costcheck = false, forcert_count: 0) ⇒ Boolean, Object
Assess the validity or cost of a given PSM (Player System Manager) skill.
This method checks if a named PSM skill exists in a given category (type), and either:
- Verifies if the character has enough stamina to use it (when `costcheck` is true),
- Or retrieves the rank of the skill from Infomon (when `costcheck` is false).
If the skill cannot be found, it logs an error and raises an exception to halt execution.
or the Infomon rank of the skill otherwise.
120 121 122 123 124 125 126 127 128 129 130 |
# File 'documented/gemstone/psms.rb', line 120 def self.assess(name, type, costcheck = false, forcert_count: 0) return false unless forcert_count <= max_forcert_count name = self.name_normal(name) seek_psm = self.find_name(name, type) || invalid_technique!(name, type) if costcheck category = Object.const_get("Lich::Gemstone::#{type}") cost_affordable?(category.respond_to?(:cost) ? category.cost(name) : seek_psm[:cost], forcert_count: forcert_count) else Infomon.get("#{type.downcase}.#{seek_psm[:short_name]}") end end |
.available?(name, ignore_cooldown = false) ⇒ Boolean
Determines if a given PSM skill is available for use (not in cooldown, and not overexerted).
167 168 169 170 171 |
# File 'documented/gemstone/psms.rb', line 167 def self.available?(name, ignore_cooldown = false) return false if effect_active?(Effects::Debuffs, 'Overexerted') return false if !ignore_cooldown && effect_active?(Effects::Cooldowns, name) return true end |
.can_forcert?(times) ⇒ Boolean
Determines whether the character is eligible to perform the given number of forced roundtime (forcert) rounds.
This method checks if the character's Multi-Opponent Combat (MOC) training allows at least the specified number of forcert rounds, based on the result of max_forcert_count.
230 231 232 |
# File 'documented/gemstone/psms.rb', line 230 def self.can_forcert?(times) max_forcert_count >= times end |
.command(verb, usage, target = "", forcert_count: 0) ⇒ String
The command a technique is sent with, as each category's use sends
it: the verb, the technique's usage word, an optional target, and
FORCERT. Exposed so a script that sends and confirms on its own
terms (an engine with its own roundtime and timeout discipline)
still gets the exact command use would send.
307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'documented/gemstone/psms.rb', line 307 def self.command(verb, usage, target = "", forcert_count: 0) cmd = verb.nil? || verb.to_s.empty? ? usage.to_s : "#{verb} #{usage}" if target.is_a?(GameObj) cmd += " ##{target.id}" elsif target.is_a?(Integer) cmd += " ##{target}" elsif target.to_s != "" cmd += " #{target}" end cmd += " forcert" if forcert_count > 0 cmd end |
.cost_affordable?(cost, forcert_count: 0) ⇒ Boolean
Whether current stamina (or other resource) covers a cost, with the FORCERT surcharge of 25% plus 10% per FORCERT when any are used.
149 150 151 152 153 154 155 156 |
# File 'documented/gemstone/psms.rb', line 149 def self.cost_affordable?(cost, forcert_count: 0) return false unless forcert_count <= max_forcert_count cost.all? do |cost_type, cost_amount| cost_amount = (cost_amount + (cost_amount * ((25 + (10.0 * forcert_count)) / 100))).truncate if forcert_count > 0 cost_amount < XMLData.public_send(cost_type) end end |
.dispatch(usage_cmd, results_regex, timeout: 5) ⇒ String?
Sends a technique command and waits for its answer. dothistimeout itself waits out and re-sends after "...wait N seconds." (roundtime the client had not seen yet), so results_regex leaves that line out. After "You don't seem to be able to move to do that." the command is sent once more, and only if the character regains control within 10s (either RECOVERED_REGEX line).
354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'documented/gemstone/psms.rb', line 354 def self.dispatch(usage_cmd, results_regex, timeout: 5) usage_result = dothistimeout(usage_cmd, timeout, results_regex) return usage_result unless usage_result == "You don't seem to be able to move to do that." recovered = false 100.times do break if (recovered = clear.any? { |line| line =~ RECOVERED_REGEX }) sleep 0.1 end recovered ? dothistimeout(usage_cmd, timeout, results_regex) : usage_result end |
.effect_active?(registry, effect) ⇒ Boolean
Whether an unexpired effect is listed in an Effects registry. A String matches regardless of case, colons and apostrophes, a space and an underscore alike ("seanettes_shout" matches "Seanette's Shout"); a Regexp matches any entry; an Integer matches an effect id. The game's parser lists each effect under both its name and its Integer id, so keys are compared as text.
182 183 184 185 186 187 188 189 190 191 192 |
# File 'documented/gemstone/psms.rb', line 182 def self.effect_active?(registry, effect) now = Time.now.to_f wanted = effect.is_a?(Regexp) ? effect : name_normal(effect.to_s) # Iterate a snapshot: to_h is the parser's live Hash, which the game # thread clears and refills; adding a key mid-iteration raises in the parser. registry.to_h.dup.any? do |key, expiry| next false unless expiry.to_f > now wanted.is_a?(Regexp) ? wanted.match?(key.to_s) : name_normal(key.to_s) == wanted end end |
.find_name(name, type) ⇒ Hash?
Finds a Player System Manager (PSM) skill by name within the specified category.
This method searches for a PSM skill (such as a combat maneuver, armor skill, feat, etc.)
by matching the normalized long_name or short_name within the specified type's lookup table.
88 89 90 91 92 |
# File 'documented/gemstone/psms.rb', line 88 def self.find_name(name, type) name = self.name_normal(name) Object.const_get("Lich::Gemstone::#{type}").method("#{type.downcase}_lookups").call .find { |h| h[:long_name].eql?(name) || h[:short_name].eql?(name) } end |
.invalid_technique!(name, type) ⇒ Object
Logs and raises for a technique name that is not in its category, which stops (kills) the offending script.
138 139 140 141 |
# File 'documented/gemstone/psms.rb', line 138 def self.invalid_technique!(name, type) Lich.log("error: PSMS request: invalid #{type} skill #{name}\n\t") raise ArgumentError, "Aborting script - The referenced #{type} skill #{name} is invalid.\r\nCheck your PSM category (Armor, CMan, Feat, Shield, Warcry, Weapon) and your spelling of #{name}.", (caller.find { |call| call =~ /^#{Script.current.name}/ }) end |
.max_forcert_count ⇒ Integer
Determines the maximum number of forced roundtime (forcert) activations allowed based on the character's Multi-Opponent Combat (MOC) training.
The number of forcert rounds scales with ranks in MOC as follows:
- 0-9 ranks: 0 forcert rounds
- 10-34 ranks: 1 forcert round
- 35-74 ranks: 2 forcert rounds
- 75-124 ranks: 3 forcert rounds
- 125+ ranks: 4 forcert rounds
249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'documented/gemstone/psms.rb', line 249 def self.max_forcert_count case Skills.multi_opponent_combat when 0..9 0 when 10..34 1 when 35..74 2 when 75..124 3 else # 125+ 4 end end |
.mstrike_available?(focused: false) ⇒ Boolean
Whether MSTRIKE can be used right now: enough Multi Opponent Combat training (5 ranks open, 30 focused), not overexerted, and enough stamina for its cost while it is in recovery.
211 212 213 214 215 216 217 |
# File 'documented/gemstone/psms.rb', line 211 def self.mstrike_available?(focused: false) return false if Skills.multi_opponent_combat < (focused ? 30 : 5) return false if effect_active?(Effects::Debuffs, 'Overexerted') cost = QStrike.mstrike_cost(focused: focused) cost.zero? || cost_affordable?({ stamina: cost }) end |
.name_normal(name) ⇒ String
Normalizes a name for internal lookup consistency.
Converts the input string to a standardized format (e.g., downcased, underscored)
using Lich::Util.normalize_name.
72 73 74 |
# File 'documented/gemstone/psms.rb', line 72 def self.name_normal(name) Lich::Util.normalize_name(name) end |
.results_regex(name, *patterns, results_of_interest: nil) ⇒ Regexp
Every line that answers a technique command: the shared failures, the
"X what?" and cooldown refusals for this technique, its own result
messaging, and any extra patterns. This is the regex each category's
use waits on, so a caller confirming the command itself matches the
same lines use would.
330 331 332 333 334 335 |
# File 'documented/gemstone/psms.rb', line 330 def self.results_regex(name, *patterns, results_of_interest: nil) parts = [FAILURES_REGEXES, /^#{name} what\?$/i, /^#{name} is still in cooldown\./i] parts.concat(patterns.compact) parts << results_of_interest if results_of_interest.is_a?(Regexp) Regexp.union(*parts) end |
.single_target?(target) ⇒ Boolean
Whether a technique target names a single creature or character, as opposed to none (the character, or the room) or ALL.
199 200 201 202 203 |
# File 'documented/gemstone/psms.rb', line 199 def self.single_target?(target) return true if target.is_a?(GameObj) || target.is_a?(Integer) !target.to_s.strip.empty? && !target.to_s.strip.casecmp?('all') end |