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.

Examples:

Check if a combat maneuver can be used with current stamina

PSMS.assess("bullrush", "CMan", true)

Generate a technique command

PSMS.command("cman", "bullrush", GameObj.targets.first)

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 Regexp using Regexp.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.

Examples:

if PSMS::FAILURES_REGEXES.match?(response)
  respond "Action failed: #{response}"
end

Returns:

  • (Regexp) —

    A union of common failure message patterns.

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

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.

Examples:

Check if a combat maneuver can be used with current stamina

assess("feint", "CMan", true)

Get the Infomon rank of a shield technique

assess("bulwark", "Shield")

Check if a feat can be used with current stamina, considering forced RT applications

assess("shield bash", "Feat", true, forcert_count: 2)

Parameters:

  • name (String) —

    The name of the PSM skill to assess.

  • type (String) —

    The category of the PSM skill (e.g., "Armor", "CMan", "Feat", "Shield", "Warcry", "Weapon").

  • costcheck (Boolean) (defaults to: false) —

    If true, check whether the character has enough stamina to use the skill.

  • forcert_count (Integer) (defaults to: 0) —

    Optional. Number of forced RT applications, affecting stamina cost calculation (default: 0).

Returns:

  • (Boolean, Object) —

    Returns a boolean if costcheck is true (indicating stamina sufficiency),

Raises:

  • (StandardError) —

    If the skill name is invalid or not found in the given category.



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).

Examples:

Check if a combat maneuver is available

PSMS.available?("bull_rush")
# => true (if not in cooldown or overexerted)

Parameters:

  • name (String) —

    The name of the PSM skill to check.

  • ignore_cooldown (Boolean) (defaults to: false) —

    Skip the cooldown check (default: false)

Returns:

  • (Boolean) —

    True if the skill is available (not in cooldown or overexerted), false otherwise.



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.

Examples:

Check if the character can perform 2 forcert rounds

PSMS.can_forcert?(2)
# => true  (if MOC ranks are 35 or higher)

Parameters:

  • times (Integer) —

    The number of forcert rounds to check eligibility for.

Returns:

  • (Boolean) —

    True if the character can perform at least the given number of forcert rounds, false otherwise.



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.

Examples:

PSMS.command("cman", "bullrush", GameObj.targets.first)  # => "cman bullrush #12345"

Parameters:

  • verb (String, nil) —

    "cman", "shield", ... or nil for a bare command (FEAT GUARD)

  • usage (String) —

    the technique's usage word

  • target (String, Integer, GameObj) (defaults to: "") —

    a GameObj or id is sent as #id; a String as given

  • forcert_count (Integer) (defaults to: 0) —

    more than 0 appends FORCERT

Returns:



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.

Parameters:

  • cost (Hash) —

    e.g. { stamina: 20 }, keyed by XMLData resource

  • forcert_count (Integer) (defaults to: 0) —

    FORCERTs used, including this one

Returns:

  • (Boolean)


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).

Parameters:

  • usage_cmd (String) —

    the command, e.g. from command

  • results_regex (Regexp) —

    the lines that answer it, e.g. from results_regex

  • timeout (Numeric) (defaults to: 5) —

    seconds to wait for an answer

Returns:

  • (String, nil) —

    the answering line, or nil on timeout



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.

Parameters:

  • registry (Effects::Registry) —

    Effects::Buffs, Effects::Cooldowns, ...

  • effect (String, Symbol, Integer, Regexp) —

    the effect name, id or pattern

Returns:

  • (Boolean)


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.

Examples:

PSMS.find_name("feint", "CMan")
# => { long_name: "combat_feint", short_name: "feint", cost: 10 }

Parameters:

  • name (String) —

    The name of the PSM to find (normalized beforehand).

  • type (String) —

    The category of the PSM (e.g., "Armor", "CMan", "Feat", "Shield", "Warcry", "Weapon").

Returns:

  • (Hash, nil) —

    A hash representing the PSM's attributes if found, or nil if not found.



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.

Parameters:

  • name (String) —

    the normalized technique name

  • type (String) —

    the category ("CMan", "Shield", ...)

Raises:

  • (ArgumentError) —

    always



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

Examples:

PSMS.max_forcert_count
# => 3  (for a character with 100 MOC ranks)

Returns:

  • (Integer) —

    The maximum number of forcert rounds the character can perform.



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.

Parameters:

  • focused (Boolean) (defaults to: false) —

    a focused (single target) strike, else open

Returns:

  • (Boolean)


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.

Examples:

PSMS.name_normal("Some Name")
# => "some_name"

Parameters:

  • name (String) —

    The name to normalize.

Returns:

  • (String) —

    The normalized 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.

Parameters:

  • name (String) —

    the technique name as the caller gave it

  • patterns (Array<Regexp, nil>) —

    the technique's result regex and friends; nils are skipped

  • results_of_interest (Regexp, nil) (defaults to: nil) —

    extra lines the caller wants to see

Returns:

  • (Regexp)


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.

Parameters:

  • target (String, Integer, GameObj, nil)

Returns:

  • (Boolean)


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