Module: Lich::Gemstone::PSMS::Technique Private
- 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
-
#[](name) ⇒ Integer
private
The rank known of a technique.
-
#affordable?(name, target: "", forcert_count: 0) ⇒ Boolean
private
Whether the character can pay for the technique.
-
#available?(name, target: "", ignore_cooldown: false, min_rank: 1, forcert_count: 0) ⇒ Boolean
private
Whether a technique can be used right now: known, affordable, off cooldown (unless ignored), and the character is not overexerted.
-
#buff_active?(name) ⇒ Boolean
private
A pattern
:buffmatches the stat buff whatever granted it: surge is active under bearhug's "Enh. -
#command(name, target = "", forcert_count: 0) ⇒ String?
private
The command #use sends, without sending it.
-
#cost(name, target: "") ⇒ Hash
private
What a technique costs right now: its
:cooldown_costwhile its own cooldown is active, its:target_costwhen aimed at a single target, else its:cost. -
#free_under(buff, type: nil, affects: %i[cost cooldown]) ⇒ void
private
Declares a buff under which the category's techniques (or only those of one type) cost nothing and/or skip their cooldown check.
- #known?(name, min_rank: 1) ⇒ Boolean private
-
#lookups ⇒ Array<Hash>
private
Each technique's :long_name, :short_name and base :cost.
-
#regexp(name) ⇒ Regexp
private
The line(s) that answer the technique's command.
-
#results_regex(name, results_of_interest: nil) ⇒ Regexp
private
Every line that answers the technique's command: the regex #use waits on.
-
#technique(name) ⇒ Hash
private
A technique's table entry.
-
#techniques(table, type:, verb:) ⇒ void
private
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. -
#use(name, target = "", ignore_cooldown: false, results_of_interest: nil, forcert_count: 0) ⇒ String?
private
Uses a technique if it is available, waiting out roundtime first unless using FORCERT.
-
#verb_for(_usage) ⇒ Object
private
The command verb for a usage word.
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.
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.
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.
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).
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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 |