Module: Lich::Gemstone::PSMS::Technique Private

Included in:
Armor, CMan, Feat, Shield, Warcry, Weapon
Defined in:
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.

Behaviour shared by every technique category (CMan, Shield, Weapon, Feat, Armor, Warcry). A category module keeps its own table of techniques, then extends this module and registers the table:

module CMan
@@combat_mans = { "bull_rush" => { short_name: "bullrush", ... }, ... }
extend PSMS::Technique
techniques @@combat_mans, type: "CMan", verb: "cman"
end

A category that behaves differently overrides the method on itself (+def Weapon.use+) and calls super for the shared behaviour.

Table entry keys:

- +:short_name+ [String] the name Infomon tracks the rank under
- +:type+ [Symbol] :setup, :attack, :area_of_effect, :assault, :buff, :passive, ...
- +:cost+ [Hash] e.g. { stamina: 10 }
- +:cooldown_cost+ [Hash, optional] the cost while the technique's own cooldown is active
- +:target_cost+ [Hash, optional] the cost when used on a single target
- +:regex+ [Regexp] the line(s) that answer the technique's command
- +:usage+ [String, nil, optional] the command word; nil for techniques that
cannot be used; +:short_name+ when absent
- +:buff+ [String, Regexp, optional] the Effects::Buffs entry the technique grants;
a Regexp also matches that stat buff when something else granted it
- +:ignorable_cooldown+ [Boolean, optional] whether +ignore_cooldown: true+ applies

Instance Method Summary collapse

Instance Method Details

#[](name) ⇒ Integer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The rank known of a technique.

Parameters:

  • name (String, Symbol) —

    the technique name

Returns:

  • (Integer) —

    0 when unknown



67
68
69
# File 'documented/gemstone/psms/technique.rb', line 67

def [](name)
  Infomon.get("#{@type.downcase}.#{technique(name)[:short_name]}").to_i
end

#affordable?(name, target: "", forcert_count: 0) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns whether the character can pay for the technique.

Parameters:

  • name (String, Symbol) —

    the technique name

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

    the target it will be used on

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

    FORCERTs used, including this one

Returns:

  • (Boolean) —

    whether the character can pay for the technique



97
98
99
100
101
# File 'documented/gemstone/psms/technique.rb', line 97

def affordable?(name, target: "", forcert_count: 0)
  return true if waived?(technique(name), :cost)

  PSMS.cost_affordable?(cost(name, target: target), forcert_count: forcert_count)
end

#available?(name, target: "", ignore_cooldown: false, min_rank: 1, forcert_count: 0) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Whether a technique can be used right now: known, affordable, off cooldown (unless ignored), and the character is not overexerted.

Parameters:

  • name (String, Symbol) —

    the technique name

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

    the target it will be used on

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

    skip the cooldown check, for techniques that allow it

  • min_rank (Integer) (defaults to: 1) —

    the rank required (default: 1)

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

    FORCERTs used, including this one

Returns:

  • (Boolean)


112
113
114
115
116
117
118
119
# File 'documented/gemstone/psms/technique.rb', line 112

def available?(name, target: "", ignore_cooldown: false, min_rank: 1, forcert_count: 0)
  long_name, psm = find(name)
  return false unless known?(name, min_rank: min_rank)
  return false unless affordable?(name, target: target, forcert_count: forcert_count)

  ignore = cooldown_ignored?(psm, ignore_cooldown)
  [long_name, name.to_s].uniq.all? { |n| PSMS.available?(n, ignore) }
end

#buff_active?(name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A pattern :buff matches the stat buff whatever granted it: surge is active under bearhug's "Enh. Strength (+20)", burst under barrage's "Enh. Dexterity (+10)", coup de grace under shout's "Empowered (+20)", and the other way round (bearhug under a matching surge buff).

Parameters:

  • name (String, Symbol) —

    the technique name

Returns:

  • (Boolean) —

    whether the buff the technique grants (or the same stat buff) is active



128
129
130
131
# File 'documented/gemstone/psms/technique.rb', line 128

def buff_active?(name)
  buff = technique(name)[:buff]
  !buff.nil? && PSMS.effect_active?(Effects::Buffs, buff)
end

#command(name, target = "", forcert_count: 0) ⇒ String?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The command #use sends, without sending it.

Parameters:

  • name (String, Symbol) —

    the technique name

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

    the target (optional)

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

    more than 0 appends FORCERT

Returns:

  • (String, nil) —

    e.g. "cman bullrush #12345", nil when the technique cannot be used



163
164
165
166
167
168
169
# File 'documented/gemstone/psms/technique.rb', line 163

def command(name, target = "", forcert_count: 0)
  psm = technique(name)
  usage = psm.key?(:usage) ? psm[:usage] : psm[:short_name]
  return nil if usage.nil?

  PSMS.command(verb_for(usage), usage, target, forcert_count: forcert_count)
end

#cost(name, target: "") ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

What a technique costs right now: its :cooldown_cost while its own cooldown is active, its :target_cost when aimed at a single target, else its :cost.

Parameters:

  • name (String, Symbol) —

    the technique name

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

    the target it will be used on

Returns:

  • (Hash) —

    e.g. { stamina: 30 }



85
86
87
88
89
90
91
# File 'documented/gemstone/psms/technique.rb', line 85

def cost(name, target: "")
  long_name, psm = find(name)
  return psm[:cooldown_cost] if psm[:cooldown_cost] && PSMS.effect_active?(Effects::Cooldowns, long_name)
  return psm[:target_cost] if psm[:target_cost] && PSMS.single_target?(target)

  psm[:cost]
end

#free_under(buff, type: nil, affects: %i[cost cooldown]) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Declares a buff under which the category's techniques (or only those of one type) cost nothing and/or skip their cooldown check. Cost and cooldown are separate, since a buff can waive one without the other.

Examples:

free_under "Glorious Momentum", type: :area_of_effect
free_under "Ardor of the Scourge", type: :assault, affects: :cooldown

Parameters:

  • buff (String, Regexp) —

    the Effects::Buffs entry

  • type (Symbol, nil) (defaults to: nil) —

    limit to techniques of this :type; nil for all

  • affects (Symbol, Array<Symbol>) (defaults to: %i[cost cooldown]) —

    :cost, :cooldown, or both



200
201
202
# File 'documented/gemstone/psms/technique.rb', line 200

def free_under(buff, type: nil, affects: %i[cost cooldown])
  (@free_conditions ||= []) << { buff: buff, type: type, affects: Array(affects) }
end

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • name (String, Symbol) —

    the technique name

  • min_rank (Integer) (defaults to: 1) —

    the rank to test against (default: 1, so known at all)

Returns:

  • (Boolean)


74
75
76
# File 'documented/gemstone/psms/technique.rb', line 74

def known?(name, min_rank: 1)
  self[name] >= [min_rank, 1].max
end

#lookups ⇒ Array<Hash>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns each technique's :long_name, :short_name and base :cost.

Returns:

  • (Array<Hash>) —

    each technique's :long_name, :short_name and base :cost



50
51
52
# File 'documented/gemstone/psms/technique.rb', line 50

def lookups
  @table.map { |long_name, psm| { long_name: long_name, short_name: psm[:short_name], cost: psm[:cost] } }
end

#regexp(name) ⇒ Regexp

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The line(s) that answer the technique's command. A match means the technique was attempted, not that it succeeded.

Parameters:

  • name (String, Symbol) —

    the technique name

Returns:

  • (Regexp)


185
186
187
# File 'documented/gemstone/psms/technique.rb', line 185

def regexp(name)
  technique(name)[:regex]
end

#results_regex(name, results_of_interest: nil) ⇒ Regexp

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Every line that answers the technique's command: the regex #use waits on.

Parameters:

  • name (String, Symbol) —

    the technique name

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

    extra lines to match

Returns:

  • (Regexp)


176
177
178
# File 'documented/gemstone/psms/technique.rb', line 176

def results_regex(name, results_of_interest: nil)
  PSMS.results_regex(name, regexp(name), PSMS::ROUNDTIME_REGEX, results_of_interest: results_of_interest)
end

#technique(name) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A technique's table entry.

Parameters:

  • name (String, Symbol) —

    long or short name, in any case, with spaces or underscores

Returns:

Raises:

  • (ArgumentError) —

    if the name is not a technique in this category



59
60
61
# File 'documented/gemstone/psms/technique.rb', line 59

def technique(name)
  find(name).last
end

#techniques(table, type:, verb:) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Registers the category's technique table, and defines a rank getter for every technique by short and long name (+CMan.bullrush+, CMan.bull_rush) and the category's <type>_lookups.

Parameters:

  • table (Hash{String => Hash}) —

    technique entries by long name

  • type (String) —

    the category name PSMS knows it by ("CMan")

  • verb (String) —

    the command verb ("cman")



38
39
40
41
42
43
44
45
46
47
# File 'documented/gemstone/psms/technique.rb', line 38

def techniques(table, type:, verb:)
  @table = table
  @type = type
  @verb = verb
  define_singleton_method("#{type.downcase}_lookups") { lookups }
  table.each do |long_name, psm|
    define_singleton_method(psm[:short_name]) { self[psm[:short_name]] }
    define_singleton_method(long_name) { self[psm[:short_name]] }
  end
end

#use(name, target = "", ignore_cooldown: false, results_of_interest: nil, forcert_count: 0) ⇒ String?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Uses a technique if it is available, waiting out roundtime first unless using FORCERT.

Parameters:

  • name (String, Symbol) —

    the technique name

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

    the target; the character when omitted

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

    skip the cooldown check, for techniques that allow it

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

    extra lines to return on

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

    FORCERTs used, including this one

Returns:

  • (String, nil) —

    the answering line; nil when not used or on timeout



142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'documented/gemstone/psms/technique.rb', line 142

def use(name, target = "", ignore_cooldown: false, results_of_interest: nil, forcert_count: 0)
  return unless available?(name, target: target, ignore_cooldown: ignore_cooldown, forcert_count: forcert_count)

  usage_cmd = command(name, target, forcert_count: forcert_count)
  return if usage_cmd.nil?

  # with forcert we don't want to wait for rt, but we need to otherwise
  unless forcert_count > 0
    waitrt?
    waitcastrt?
  end

  PSMS.dispatch(usage_cmd, results_regex(name, results_of_interest: results_of_interest))
end

#verb_for(_usage) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The command verb for a usage word. Overridden by categories with bare commands.



206
207
208
# File 'documented/gemstone/psms/technique.rb', line 206

def verb_for(_usage)
  @verb
end