Module: Lich::Gemstone::Armor

Defined in:
lib/gemstone/psms/armor.rb

Constant Summary collapse

@@armor_techniques =
{
  "armor_blessing"      => {
    :regex => /As \w+ prays? over \w+(?:'s)? [\w\s]+, you sense that (?:the Arkati's|a) blessing will be granted against magical attacks\./i,
    :usage => "blessing",
  },
  "armor_reinforcement" => {
    :regex => /\w+ adjusts? \w+(?:'s)? [\w\s]+, reinforcing weak spots\./i,
    :usage => "reinforcement",
  },
  "armor_spike_mastery" => {
    :regex => /Armor Spike Mastery is passive and always active once learned\./i,
    :usage => "spikemastery",
  },
  "armor_support"       => {
    :regex => /\w+ adjusts? \w+(?:'s)? [\w\s]+, improving its ability to support the weight of \w+ gear\./i,
    :usage => "support",
  },
  "armored_casting"     => {
    :regex => /\w+ adjusts? \w+(?:'s)? [\w\s]+, making it easier for \w+ to recover from failed spell casting\./i,
    :usage => "casting",
  },
  "armored_evasion"     => {
    :regex => /\w+ adjusts? \w+(?:'s)? [\w\s]+, improving its comfort and maneuverability\./i,
    :usage => "evasion",
  },
  "armored_fluidity"    => {
    :regex => /\w+ adjusts? \w+(?:'s)? [\w\s]+, making it easier for \w+ to cast spells\./i,
    :usage => "fluidity",
  },
  "armored_stealth"     => {
    :regex => /\w+ adjusts? \w+(?:'s)? [\w\s]+ to cushion \w+ movements\./i,
    :usage => "stealth",
  },
  "crush_protection"    => {
    :regex => Regexp.union(/You adjust \w+(?:'s)? [\w\s]+ with your (?:cloth|leather|scale|chain|plate|accessory) armor fittings, rearranging and reinforcing the armor to better protect against (?:punctur|crush|slash)ing damage\./i,
                           /You must specify an armor slot\./,
                           /You don't seem to have the necessary armor fittings in hand\./),
    :usage => "crush",
  },
  "puncture_protection" => {
    :regex => Regexp.union(/You adjust \w+(?:'s)? [\w\s]+ with your (?:cloth|leather|scale|chain|plate|accessory) armor fittings, rearranging and reinforcing the armor to better protect against (?:punctur|crush|slash)ing damage\./i,
                           /You must specify an armor slot\./,
                           /You don't seem to have the necessary armor fittings in hand\./),
    :usage => "puncture",
  },
  "slash_protection"    => {
    :regex => Regexp.union(/You adjust \w+(?:'s)? [\w\s]+ with your (?:cloth|leather|scale|chain|plate|accessory) armor fittings, rearranging and reinforcing the armor to better protect against (?:punctur|crush|slash)ing damage\./i,
                           /You must specify an armor slot\./,
                           /You don't seem to have the necessary armor fittings in hand\./),
    :usage => "slash",
  },
}

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Hash

Retrieves the armor technique based on the name.

Examples:

Armor["armor_blessing"]
# => { regex: /As \w+ prays? over \w+(?:'s)? [\w\s]+, .../, usage: "blessing" }

Parameters:

  • name (String)

    The name of the armor technique.

Returns:

  • (Hash)

    The armor technique details including regex and usage.

Raises:

  • (KeyError)

    If the armor technique does not exist.



94
95
96
# File 'lib/gemstone/psms/armor.rb', line 94

def Armor.[](name)
  return PSMS.assess(name, 'Armor')
end

.affordable?(name) ⇒ Boolean

Checks if the specified armor technique is affordable.

Examples:

Armor.affordable?("armor_blessing")
# => true or false

Parameters:

  • name (String)

    The name of the armor technique.

Returns:

  • (Boolean)

    True if the armor technique is affordable, false otherwise.



120
121
122
# File 'lib/gemstone/psms/armor.rb', line 120

def Armor.affordable?(name)
  return PSMS.assess(name, 'Armor', true)
end

.armor_lookupsArray<Hash>

Retrieves a list of armor lookups with their long names, short names, and costs.

Examples:

Armor.armor_lookups
# => [{ long_name: 'armor_blessing', short_name: 'blessing', cost: 0 }, ...]

Returns:

  • (Array<Hash>)

    An array of hashes containing armor attributes. Each hash includes :long_name, :short_name, and :cost.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gemstone/psms/armor.rb', line 17

def self.armor_lookups
  [{ long_name: 'armor_blessing',	        short_name: 'blessing',	        cost:	 0 },
   { long_name: 'armor_reinforcement',	  short_name: 'reinforcement',	  cost:	 0 },
   { long_name: 'armor_spike_mastery',	  short_name: 'spikemastery',	    cost:	 0 },
   { long_name: 'armor_support',	        short_name: 'support',	        cost:	 0 },
   { long_name: 'armored_casting',	      short_name: 'casting',	        cost:	 0 },
   { long_name: 'armored_evasion',	      short_name: 'evasion',	        cost:	 0 },
   { long_name: 'armored_fluidity',	      short_name: 'fluidity',	        cost:	 0 },
   { long_name: 'armored_stealth',	      short_name: 'stealth',	        cost:	 0 },
   { long_name: 'crush_protection',	      short_name: 'crush',	          cost:	 0 },
   { long_name: 'puncture_protection',	  short_name: 'puncture',	        cost:	 0 },
   { long_name: 'slash_protection',	      short_name: 'slash',	          cost:	 0 }]
  # rubocop:enable Layout/ExtraSpacing
end

.available?(name, min_rank: 1) ⇒ Boolean

Checks if the specified armor technique is available for use.

Examples:

Armor.available?("armor_blessing", min_rank: 1)
# => true or false

Parameters:

  • name (String)

    The name of the armor technique.

  • min_rank (Integer) (defaults to: 1)

    The minimum rank to check against (default is 1).

Returns:

  • (Boolean)

    True if the armor technique is known, affordable, and not on cooldown or debuffed, false otherwise.



133
134
135
# File 'lib/gemstone/psms/armor.rb', line 133

def Armor.available?(name, min_rank: 1)
  Armor.known?(name, min_rank: min_rank) and Armor.affordable?(name) and !Lich::Util.normalize_lookup('Cooldowns', name) and !Lich::Util.normalize_lookup('Debuffs', 'Overexerted')
end

.known?(name, min_rank: 1) ⇒ Boolean

Checks if the specified armor technique is known at or above the minimum rank.

Examples:

Armor.known?("armor_blessing", min_rank: 2)
# => true or false

Parameters:

  • name (String)

    The name of the armor technique.

  • min_rank (Integer) (defaults to: 1)

    The minimum rank to check against (default is 1).

Returns:

  • (Boolean)

    True if the armor technique is known at the specified rank or higher, false otherwise.



107
108
109
110
# File 'lib/gemstone/psms/armor.rb', line 107

def Armor.known?(name, min_rank: 1)
  min_rank = 1 unless min_rank >= 1 # in case a 0 or below is passed
  Armor[name] >= min_rank
end

.regexp(name) ⇒ Regexp

Retrieves the regex pattern for the specified armor technique.

Examples:

Armor.regexp("armor_blessing")
# => /As \w+ prays? over \w+(?:'s)? [\w\s]+, .../

Parameters:

  • name (String)

    The name of the armor technique.

Returns:

  • (Regexp)

    The regex pattern associated with the armor technique.

Raises:

  • (KeyError)

    If the armor technique does not exist.



196
197
198
# File 'lib/gemstone/psms/armor.rb', line 196

def Armor.regexp(name)
  @@armor_techniques.fetch(PSMS.name_normal(name))[:regex]
end

.use(name, target = "", results_of_interest: nil) ⇒ String?

Uses the specified armor technique on a target.

Examples:

Armor.use("armor_blessing", "target_name")
# => "You bless the target with armor."

Parameters:

  • name (String)

    The name of the armor technique.

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

    The target to use the technique on (optional).

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

    Additional regex to match results (optional).

Returns:

  • (String, nil)

    The result of the usage or nil if not available.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/gemstone/psms/armor.rb', line 147

def Armor.use(name, target = "", results_of_interest: nil)
  return unless Armor.available?(name)
  name_normalized = PSMS.name_normal(name)
  technique = @@armor_techniques.fetch(name_normalized)
  usage = technique[:usage]
  return if usage.nil?

  in_cooldown_regex = /^#{name} is still in cooldown\./i

  results_regex = Regexp.union(
    PSMS::FAILURES_REGEXES,
    /^#{name} what\?$/i,
    in_cooldown_regex,
    technique[:regex],
    /^Roundtime: [0-9]+ sec\.$/,
    /^\w+ [a-z]+ not wearing any armor that you can work with\.$/
  )

  if results_of_interest.is_a?(Regexp)
    results_regex = Regexp.union(results_regex, results_of_interest)
  end

  usage_cmd = "armor #{usage}"
  if target.is_a?(GameObj)
    usage_cmd += " ##{target.id}"
  elsif target.is_a?(Integer)
    usage_cmd += " ##{target}"
  elsif target != ""
    usage_cmd += " #{target}"
  end
  waitrt?
  waitcastrt?
  usage_result = dothistimeout usage_cmd, 5, results_regex
  if usage_result == "You don't seem to be able to move to do that."
    100.times { break if clear.any? { |line| line =~ /^You regain control of your senses!$/ }; sleep 0.1 }
    usage_result = dothistimeout usage_cmd, 5, results_regex
  end
  usage_result
end