Module: Lich::Gemstone::PSMS

Defined in:
lib/gemstone/psms.rb

Constant Summary collapse

FAILURES_REGEXES =

Common failure messages potentially used across all PSMs.

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\.$/
)

Class Method Summary collapse

Class Method Details

.assess(name, type, costcheck = false) ⇒ Boolean, Object

Assesses the validity and cost of a specified name and type.

Examples:

valid = Lich::Gemstone::PSMS.assess("Some Name", "Armor", true)

Parameters:

  • name (String)

    the name to assess

  • type (String)

    the type of the name (e.g., Armor, CMan, etc.)

  • costcheck (Boolean) (defaults to: false)

    whether to check the cost (default: false)

Returns:

  • (Boolean, Object)

    true if cost is valid, otherwise returns Infomon data

Raises:

  • (StandardError)

    if the referenced skill is invalid



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/gemstone/psms.rb', line 50

def self.assess(name, type, costcheck = false)
  name = self.name_normal(name)
  seek_psm = self.find_name(name, type)
  # this logs then raises an exception to stop (kill) the offending script
  if seek_psm.nil?
    Lich.log("error: PSMS request: #{$!}\n\t")
    raise StandardError.new "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}."
  end
  # otherwise process request
  case costcheck
  when true
    seek_psm[:cost] < XMLData.stamina
  else
    Infomon.get("#{type.downcase}.#{seek_psm[:short_name]}")
  end
end

.find_name(name, type) ⇒ Hash?

Finds a name of a specified type in the PSMS.

Examples:

found_name = Lich::Gemstone::PSMS.find_name("Some Name", "Armor")

Parameters:

  • name (String)

    the name to find

  • type (String)

    the type of the name (e.g., Armor, CMan, etc.)

Returns:

  • (Hash, nil)

    the found name hash or nil if not found



34
35
36
37
# File 'lib/gemstone/psms.rb', line 34

def self.find_name(name, type)
  Object.const_get("Lich::Gemstone::#{type}").method("#{type.downcase}_lookups").call
        .find { |h| h[:long_name].eql?(name) || h[:short_name].eql?(name) }
end

.name_normal(name) ⇒ String

Normalizes the given name using the Lich::Util module.

Examples:

normalized_name = Lich::Gemstone::PSMS.name_normal("Some Name")

Parameters:

  • name (String)

    the name to normalize

Returns:

  • (String)

    the normalized name



22
23
24
# File 'lib/gemstone/psms.rb', line 22

def self.name_normal(name)
  Lich::Util.normalize_name(name)
end