Module: Lich::Gemstone::QStrike
- Defined in:
- documented/gemstone/psms/qstrike.rb
Overview
QStrike module calculates optimal QSTRIKE roundtime reduction while avoiding negative stamina. Accounts for weapon speeds, attack costs, and Striking Asp stance discounts.
Constant Summary collapse
- SPEED_MULTIPLIERS =
Speed multipliers by weapon category Applied per-weapon to calculate Equipment Speed
{ two_handed: 1.5, polearm: 1.5, ranged: 2.5, # All others default to 1.0 }.freeze
- DEFAULT_MULTIPLIER =
All others default to 1.0
1.0- STRIKING_ASP_MULTIPLIERS =
Striking Asp stance cost multipliers by rank Rank 1 = 2/3 cost, Rank 2 = 1/2 cost, Rank 3 = 1/3 cost
{ 1 => 2.0 / 3.0, # 0.667 2 => 1.0 / 2.0, # 0.500 3 => 1.0 / 3.0, # 0.333 }.freeze
- BASE_COST =
Base cost constant from formula
10- MAX_REDUCTION =
Maximum seconds of RT reduction (reasonable upper bound)
8- MSTRIKE_COST =
MSTRIKE's own stamina cost (Multi Opponent Combat/Multistrike): nothing outside its recovery period; during it, base + per * weapon speed, where a second weapon adds (its speed - 2, at least 0).
{ open: { base: 20, per_speed: 3 }, focused: { base: 30, per_speed: 4 } }.freeze
- MSTRIKE_COOLDOWN =
The cooldown Effects names while MSTRIKE is in its recovery period
'Multi-Strike'- VALID_ACTIONS =
Valid combat actions that can use QSTRIKE
%w[ ascension ambush attack cheapshot cman cock disarm feat fire grapple hurl jab kill kick mstrike punch shield smite stunman subdue sweep tackle trip weapon wtricks ].freeze
- DEFAULT_SETTINGS =
Default settings
{ reserve: 1, adaptive: false }.freeze
- TECHNIQUE_MODULES =
Module lookup configuration: [Module, class_var, type_symbol]
[ [:CMan, :@@combat_mans, :cman], [:Weapon, :@@weapon_techniques, :weapon], [:Shield, :@@shield_techniques, :shield], ].freeze
Class Method Summary collapse
-
.affordable?(reserve: nil, attack_cost: 0, attack_name: nil, attack_rt: nil) ⇒ Boolean
Check if any QSTRIKE reduction is affordable.
-
.base_rt ⇒ Integer
Get base RT for current weapon setup Uses the primary weapon's base RT.
-
.build_attack_command(attack, target = nil) ⇒ String
Build attack command string.
-
.cache_cost(cost) ⇒ Object
Store cost in cache with current hand state.
-
.calculate(reserve: nil, attack_cost: 0, attack_name: nil, attack_rt: nil) ⇒ Hash
Calculate optimal QSTRIKE reduction that won't cause negative stamina.
-
.clear_cache ⇒ Object
Clear the cache (call if you know equipment changed).
-
.command(reserve: nil, attack_cost: 0, attack_name: nil, attack_rt: nil) ⇒ String?
Convenience method: returns just the command string.
-
.cost_for_reduction(seconds) ⇒ Integer
Calculate stamina cost for a specific reduction amount.
-
.cost_per_second_reduction ⇒ Integer
Calculate stamina cost per second of RT reduction Formula: (10 + primary_equipment_speed + (secondary_equipment_speed / 2)) * asp_multiplier.
-
.debug_calculation ⇒ void
Display detailed calculation breakdown for debugging Shows all intermediate values used in cost calculation.
-
.default(key) ⇒ Object
Get a default value.
-
.defaults ⇒ Hash
Get current defaults.
-
.defaults=(new_defaults) ⇒ Object
Set all defaults at once.
-
.defined_module?(mod_name) ⇒ Boolean
Check if a module is defined.
-
.detect_attack_type(name) ⇒ Symbol
Detect what type of attack this is.
-
.execute_attack(attack, target = nil) ⇒ Object
Execute the attack command using appropriate method.
-
.execute_qstrike(reduction) ⇒ Object
Execute the qstrike command.
-
.find_max_seconds(available_stamina, cost_per_second) ⇒ Integer
Find maximum seconds of reduction affordable.
-
.find_weapon_stats(hand) ⇒ Hash?
Find weapon stats using multiple lookup strategies Tries: noun, then extracts weapon type from full name.
-
.hand_cache_key(hand) ⇒ String
Get a cache key for a hand (handles empty hands).
-
.load_settings ⇒ void
Load settings from DB_Store (per-character).
-
.lookup_attack_cost(name) ⇒ Integer
Look up stamina cost for a CMan or Weapon technique, or for MSTRIKE ("mstrike" is an open strike, "mstrike_focused" / "focused_mstrike" a focused one).
-
.lookup_technique_cost(name, type) ⇒ Integer
Generic technique cost lookup.
-
.mstrike_cost(focused: false) ⇒ Integer
MSTRIKE's stamina cost right now: free outside its recovery period (the Multi-Strike cooldown), else MSTRIKE_COST by kind and weapon speed.
-
.mstrike_recovering? ⇒ Boolean
Is MSTRIKE in its recovery period (its cooldown active)?.
-
.mstrike_weapon_speed ⇒ Integer
The weapon speed MSTRIKE's cost is priced on: the primary weapon's base speed, plus (offhand speed - 2, at least 0) for a second weapon; a shield or an empty hand adds nothing.
-
.normalize_attack_name(attack) ⇒ String
Normalize attack name for lookup.
-
.primary_equipment_speed ⇒ Integer
Get primary hand equipment speed For ranged: LEFT hand is primary For melee: RIGHT hand is primary.
-
.ranged_weapon? ⇒ Boolean
Determine if using ranged weapon (bow/crossbow in LEFT hand).
-
.reduction_for_target_rt(target_rt) ⇒ Integer
Calculate reduction needed to achieve target absolute RT.
-
.reset_defaults ⇒ Object
Reset defaults to factory values.
-
.reset_settings_cache ⇒ void
Reset settings loaded flag (for testing).
-
.resolve_reduction(reduction, reserve, attack_cost) ⇒ Integer?
Resolve reduction value to actual seconds Handles :max, negative (reduce by N), and positive (target RT).
-
.save_settings ⇒ void
Save settings to DB_Store (per-character).
-
.secondary_equipment_speed ⇒ Integer
Get secondary hand equipment speed For ranged: RIGHT hand is secondary For melee: LEFT hand is secondary Only weapons count - shields and non-weapons = 0.
-
.set_default(key, value) ⇒ Object
Set a single default value (persists to DB_Store for per-character storage).
-
.striking_asp_active? ⇒ Boolean
Check if Striking Asp stance is active.
-
.striking_asp_multiplier ⇒ Float
Get the cost multiplier based on Striking Asp status.
-
.striking_asp_rank ⇒ Integer
Get Striking Asp rank (1, 2, or 3).
-
.use(reduction:, attack:, target: nil, reserve: nil, adaptive: nil) ⇒ Hash
Execute QSTRIKE with an attack command.
-
.valid_cache? ⇒ Boolean
Check if cached value is still valid (hands haven't changed).
-
.weapon_speed_for(hand) ⇒ Hash
Get weapon stats and equipment speed for a hand.
Class Method Details
.affordable?(reserve: nil, attack_cost: 0, attack_name: nil, attack_rt: nil) ⇒ Boolean
Check if any QSTRIKE reduction is affordable
249 250 251 252 |
# File 'documented/gemstone/psms/qstrike.rb', line 249 def self.affordable?(reserve: nil, attack_cost: 0, attack_name: nil, attack_rt: nil) result = calculate(reserve: reserve, attack_cost: attack_cost, attack_name: attack_name, attack_rt: attack_rt) result[:seconds].positive? end |
.base_rt ⇒ Integer
Get base RT for current weapon setup Uses the primary weapon's base RT
360 361 362 363 |
# File 'documented/gemstone/psms/qstrike.rb', line 360 def self.base_rt hand = ranged_weapon? ? GameObj.left_hand : GameObj.right_hand weapon_speed_for(hand)[:base_rt] end |
.build_attack_command(attack, target = nil) ⇒ String
Build attack command string
862 863 864 865 866 867 868 |
# File 'documented/gemstone/psms/qstrike.rb', line 862 def self.build_attack_command(attack, target = nil) if target && !target.empty? "#{attack} #{target}" else attack end end |
.cache_cost(cost) ⇒ Object
Store cost in cache with current hand state
629 630 631 632 633 634 635 |
# File 'documented/gemstone/psms/qstrike.rb', line 629 def self.cache_cost(cost) @cached_cost = cost @cached_right_hand = hand_cache_key(GameObj.right_hand) @cached_left_hand = hand_cache_key(GameObj.left_hand) rescue StandardError # Ignore caching errors end |
.calculate(reserve: nil, attack_cost: 0, attack_name: nil, attack_rt: nil) ⇒ Hash
Calculate optimal QSTRIKE reduction that won't cause negative stamina
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'documented/gemstone/psms/qstrike.rb', line 169 def self.calculate(reserve: nil, attack_cost: 0, attack_name: nil, attack_rt: nil) reserve ||= default(:reserve) # Look up attack cost if name provided if attack_name && attack_cost.zero? attack_cost = lookup_attack_cost(attack_name) end current_stamina = Char.stamina available = current_stamina - reserve - attack_cost if available <= 0 return { seconds: 0, stamina_cost: 0, qstrike_cmd: nil, reason: :insufficient_stamina, current_stamina: current_stamina, available_stamina: available, attack_cost: attack_cost, reserve: reserve } end cost_per_second = cost_per_second_reduction max_seconds = find_max_seconds(available, cost_per_second) # Cap reduction based on attack's RT (can't reduce below 1 second) if attack_rt && attack_rt > 1 max_useful = attack_rt - 1 max_seconds = [max_seconds, max_useful].min end if max_seconds.positive? total_cost = cost_per_second * max_seconds { seconds: max_seconds, stamina_cost: total_cost, qstrike_cmd: "qstrike -#{max_seconds}", current_stamina: current_stamina, available_stamina: available, attack_cost: attack_cost, attack_rt: attack_rt, reserve: reserve, cost_per_second: cost_per_second, striking_asp_active: striking_asp_active? } else { seconds: 0, stamina_cost: 0, qstrike_cmd: nil, reason: :too_expensive, current_stamina: current_stamina, available_stamina: available, attack_cost: attack_cost, attack_rt: attack_rt, reserve: reserve, cost_per_second: cost_per_second } end end |
.clear_cache ⇒ Object
Clear the cache (call if you know equipment changed)
638 639 640 641 642 |
# File 'documented/gemstone/psms/qstrike.rb', line 638 def self.clear_cache @cached_cost = nil @cached_right_hand = nil @cached_left_hand = nil end |
.command(reserve: nil, attack_cost: 0, attack_name: nil, attack_rt: nil) ⇒ String?
Convenience method: returns just the command string
238 239 240 |
# File 'documented/gemstone/psms/qstrike.rb', line 238 def self.command(reserve: nil, attack_cost: 0, attack_name: nil, attack_rt: nil) calculate(reserve: reserve, attack_cost: attack_cost, attack_name: attack_name, attack_rt: attack_rt)[:qstrike_cmd] end |
.cost_for_reduction(seconds) ⇒ Integer
Calculate stamina cost for a specific reduction amount
350 351 352 353 354 |
# File 'documented/gemstone/psms/qstrike.rb', line 350 def self.cost_for_reduction(seconds) return 0 if seconds.nil? || seconds <= 0 cost_per_second_reduction * seconds end |
.cost_per_second_reduction ⇒ Integer
Calculate stamina cost per second of RT reduction Formula: (10 + primary_equipment_speed + (secondary_equipment_speed / 2)) * asp_multiplier
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 |
# File 'documented/gemstone/psms/qstrike.rb', line 479 def self.cost_per_second_reduction # Check memoization cache return @cached_cost if valid_cache? primary = primary_equipment_speed secondary = secondary_equipment_speed # Base formula: 10 + primary + (secondary / 2) base_cost = BASE_COST + primary + (secondary / 2) # Apply Striking Asp discount if active final_cost = (base_cost * striking_asp_multiplier).to_i # Cache the result cache_cost(final_cost) final_cost end |
.debug_calculation ⇒ void
This method returns an undefined value.
Display detailed calculation breakdown for debugging Shows all intermediate values used in cost calculation
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 |
# File 'documented/gemstone/psms/qstrike.rb', line 502 def self.debug_calculation respond "=== QStrike Debug Calculation ===" # Right hand right = GameObj.right_hand respond "Right hand: #{right&.name || 'Empty'} (noun: #{right&.noun || 'nil'}, id: #{right&.id || 'nil'})" if right && right.name != "Empty" stats = find_weapon_stats(right) if stats respond " Weapon found: #{stats[:base_name]} (category: #{stats[:category]})" respond " base_rt: #{stats[:base_rt]}" multiplier = SPEED_MULTIPLIERS[stats[:category]] || DEFAULT_MULTIPLIER respond " multiplier: #{multiplier}" equip_speed = (stats[:base_rt].to_i * multiplier).to_i respond " equipment_speed: #{equip_speed}" else respond " WARNING: No weapon stats found!" end end # Left hand left = GameObj.left_hand respond "Left hand: #{left&.name || 'Empty'} (noun: #{left&.noun || 'nil'}, id: #{left&.id || 'nil'})" if left && left.name != "Empty" stats = find_weapon_stats(left) if stats respond " Weapon found: #{stats[:base_name]} (category: #{stats[:category]})" respond " base_rt: #{stats[:base_rt]}" multiplier = SPEED_MULTIPLIERS[stats[:category]] || DEFAULT_MULTIPLIER respond " multiplier: #{multiplier}" equip_speed = (stats[:base_rt].to_i * multiplier).to_i respond " equipment_speed: #{equip_speed}" else respond " WARNING: No weapon stats found!" end end # Primary/Secondary determination is_ranged = ranged_weapon? respond "Ranged mode: #{is_ranged}" respond "Primary hand: #{is_ranged ? 'LEFT' : 'RIGHT'}" respond "Secondary hand: #{is_ranged ? 'RIGHT' : 'LEFT'}" # Calculated values primary = primary_equipment_speed secondary = secondary_equipment_speed respond "Primary equipment_speed: #{primary}" respond "Secondary equipment_speed: #{secondary}" respond "Secondary / 2 (integer division): #{secondary / 2}" # Formula base_cost = BASE_COST + primary + (secondary / 2) respond "Formula: BASE_COST(#{BASE_COST}) + primary(#{primary}) + secondary/2(#{secondary / 2}) = #{base_cost}" # Striking Asp asp_mult = striking_asp_multiplier if (asp_mult - 1.0).abs > Float::EPSILON respond "Striking Asp multiplier: #{asp_mult}" final_cost = (base_cost * asp_mult).to_i respond "Final cost (with Asp): #{base_cost} * #{asp_mult} = #{final_cost}" else respond "Striking Asp: not active" respond "Final cost per second: #{base_cost}" end respond "=== End Debug ===" end |
.default(key) ⇒ Object
Get a default value
117 118 119 120 |
# File 'documented/gemstone/psms/qstrike.rb', line 117 def self.default(key) load_settings @settings.fetch(key.to_sym, DEFAULT_SETTINGS[key.to_sym]) end |
.defaults ⇒ Hash
Get current defaults
89 90 91 92 93 94 95 |
# File 'documented/gemstone/psms/qstrike.rb', line 89 def self.defaults load_settings { reserve: @settings[:reserve], adaptive: @settings[:adaptive] } end |
.defaults=(new_defaults) ⇒ Object
Set all defaults at once
99 100 101 102 103 |
# File 'documented/gemstone/psms/qstrike.rb', line 99 def self.defaults=(new_defaults) load_settings @settings.merge!(new_defaults) save_settings end |
.defined_module?(mod_name) ⇒ Boolean
Check if a module is defined
735 736 737 738 739 |
# File 'documented/gemstone/psms/qstrike.rb', line 735 def self.defined_module?(mod_name) Object.const_defined?(mod_name) rescue StandardError false end |
.detect_attack_type(name) ⇒ Symbol
Detect what type of attack this is
841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 |
# File 'documented/gemstone/psms/qstrike.rb', line 841 def self.detect_attack_type(name) TECHNIQUE_MODULES.each do |mod_name, class_var, type| next unless defined_module?(mod_name) begin mod = Object.const_get(mod_name) data = mod.class_variable_get(class_var) return type if data.key?(name) || data.values.any? { |v| v[:short_name] == name } rescue StandardError next end end :basic end |
.execute_attack(attack, target = nil) ⇒ Object
Execute the attack command using appropriate method
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 |
# File 'documented/gemstone/psms/qstrike.rb', line 805 def self.execute_attack(attack, target = nil) attack_str = attack.to_s normalized = normalize_attack_name(attack) # Detect and execute based on attack type attack_type = detect_attack_type(normalized) case attack_type when :cman if defined?(CMan) && CMan.respond_to?(:use) CMan.use(normalized, target) else fput build_attack_command(attack_str, target) end when :weapon if defined?(Weapon) && Weapon.respond_to?(:use) Weapon.use(normalized, target) else fput build_attack_command(attack_str, target) end when :shield if defined?(Shield) && Shield.respond_to?(:use) Shield.use(normalized, target) else fput build_attack_command(attack_str, target) end else # Basic command - just send it fput build_attack_command(attack_str, target) end end |
.execute_qstrike(reduction) ⇒ Object
Execute the qstrike command
795 796 797 798 799 |
# File 'documented/gemstone/psms/qstrike.rb', line 795 def self.execute_qstrike(reduction) return if reduction.nil? || reduction <= 0 fput "qstrike -#{reduction}" end |
.find_max_seconds(available_stamina, cost_per_second) ⇒ Integer
Find maximum seconds of reduction affordable
746 747 748 749 750 751 752 753 754 |
# File 'documented/gemstone/psms/qstrike.rb', line 746 def self.find_max_seconds(available_stamina, cost_per_second) return 0 if cost_per_second <= 0 # Simple division - how many full seconds can we afford? max = available_stamina / cost_per_second # Cap at reasonable maximum [max, MAX_REDUCTION].min end |
.find_weapon_stats(hand) ⇒ Hash?
Find weapon stats using multiple lookup strategies Tries: noun, then extracts weapon type from full name
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
# File 'documented/gemstone/psms/qstrike.rb', line 383 def self.find_weapon_stats(hand) return nil if hand.nil? # Strategy 1: Try the noun directly (works for "dagger", "broadsword", etc.) stats = Armaments::WeaponStats.find(hand.noun) return stats if stats # Strategy 2: Try the full name (works for "slim short sword" -> finds "short sword") stats = Armaments::WeaponStats.find(hand.name) return stats if stats # Strategy 3: Extract weapon type from name by removing common adjectives # e.g., "slim short sword" -> try "short sword" name = hand.name.to_s.downcase adjectives = %w[slim gleaming steel iron silver gold mithril vultite golvern ora krodera drakar rhimar gornar zorchar eonake faenor invar kelyn laje razern rolaren vaalorn veil imflass alexandrite black white red blue green small large heavy light ornate polished rusted ancient old new fine] words = name.split # Remove leading adjectives while words.length > 1 && adjectives.include?(words.first) words.shift end # Try progressively shorter suffixes: "short sword", then "sword" while words.length > 0 attempt = words.join(' ') stats = Armaments::WeaponStats.find(attempt) return stats if stats words.shift end nil end |
.hand_cache_key(hand) ⇒ String
Get a cache key for a hand (handles empty hands)
606 607 608 609 610 611 612 |
# File 'documented/gemstone/psms/qstrike.rb', line 606 def self.hand_cache_key(hand) return "empty" if hand.nil? return "empty" if hand.name.nil? || hand.name.empty? || hand.name == "Empty" return "empty" if hand.id.nil? "#{hand.id}:#{hand.noun}" end |
.load_settings ⇒ void
This method returns an undefined value.
Load settings from DB_Store (per-character)
130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'documented/gemstone/psms/qstrike.rb', line 130 def self.load_settings return if @settings_loaded if defined?(Lich::Common::DB_Store) && defined?(XMLData) && !XMLData.game.to_s.empty? && !XMLData.name.to_s.empty? scope = "#{XMLData.game}:#{XMLData.name}" stored = Lich::Common::DB_Store.read(scope, 'lich_qstrike') @settings = DEFAULT_SETTINGS.merge(stored || {}) @settings_loaded = true else # Fallback to in-memory defaults @settings ||= DEFAULT_SETTINGS.dup end end |
.lookup_attack_cost(name) ⇒ Integer
Look up stamina cost for a CMan or Weapon technique, or for MSTRIKE ("mstrike" is an open strike, "mstrike_focused" / "focused_mstrike" a focused one)
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 |
# File 'documented/gemstone/psms/qstrike.rb', line 697 def self.lookup_attack_cost(name) name = name.to_s.downcase.gsub(/[\s-]+/, '_') return mstrike_cost(focused: name.include?('focus')) if name =~ /\Amstrike(?:_|\z)|_mstrike\z/ # Handle explicit type prefixes for disambiguation TECHNIQUE_MODULES.each do |_, _, type| prefix = "#{type}_" return lookup_technique_cost(name.sub(prefix, ''), type) if name.start_with?(prefix) end # Try each module in order until we find a cost TECHNIQUE_MODULES.each do |_, _, type| cost = lookup_technique_cost(name, type) return cost if cost.positive? end 0 end |
.lookup_technique_cost(name, type) ⇒ Integer
Generic technique cost lookup
720 721 722 723 724 725 726 727 728 729 730 |
# File 'documented/gemstone/psms/qstrike.rb', line 720 def self.lookup_technique_cost(name, type) mod_name, class_var, = TECHNIQUE_MODULES.find { |_, _, t| t == type } return 0 unless mod_name && defined_module?(mod_name) mod = Object.const_get(mod_name) data = mod.class_variable_get(class_var) entry = data[name] || data.values.find { |v| v[:short_name] == name } entry&.dig(:cost, :stamina).to_i rescue StandardError 0 end |
.mstrike_cost(focused: false) ⇒ Integer
MSTRIKE's stamina cost right now: free outside its recovery period (the Multi-Strike cooldown), else MSTRIKE_COST by kind and weapon speed. Not in the technique tables, so priced here.
661 662 663 664 665 666 |
# File 'documented/gemstone/psms/qstrike.rb', line 661 def self.mstrike_cost(focused: false) return 0 unless mstrike_recovering? cost = MSTRIKE_COST.fetch(focused ? :focused : :open) cost[:base] + cost[:per_speed] * mstrike_weapon_speed end |
.mstrike_recovering? ⇒ Boolean
Is MSTRIKE in its recovery period (its cooldown active)?
671 672 673 674 675 |
# File 'documented/gemstone/psms/qstrike.rb', line 671 def self.mstrike_recovering? return false unless defined?(Effects::Cooldowns) Effects::Cooldowns.active?(MSTRIKE_COOLDOWN) end |
.mstrike_weapon_speed ⇒ Integer
The weapon speed MSTRIKE's cost is priced on: the primary weapon's base speed, plus (offhand speed - 2, at least 0) for a second weapon; a shield or an empty hand adds nothing.
682 683 684 685 686 687 688 689 |
# File 'documented/gemstone/psms/qstrike.rb', line 682 def self.mstrike_weapon_speed primary = ranged_weapon? ? GameObj.left_hand : GameObj.right_hand offhand = ranged_weapon? ? GameObj.right_hand : GameObj.left_hand speed = weapon_speed_for(primary)[:base_rt] off = weapon_speed_for(offhand)[:base_rt] speed += [off - 2, 0].max if off.positive? speed end |
.normalize_attack_name(attack) ⇒ String
Normalize attack name for lookup
788 789 790 |
# File 'documented/gemstone/psms/qstrike.rb', line 788 def self.normalize_attack_name(attack) attack.to_s.downcase.gsub(/[\s-]+/, '_').gsub(/[^a-z0-9_]/, '') end |
.primary_equipment_speed ⇒ Integer
Get primary hand equipment speed For ranged: LEFT hand is primary For melee: RIGHT hand is primary
459 460 461 462 |
# File 'documented/gemstone/psms/qstrike.rb', line 459 def self.primary_equipment_speed hand = ranged_weapon? ? GameObj.left_hand : GameObj.right_hand weapon_speed_for(hand)[:equipment_speed] end |
.ranged_weapon? ⇒ Boolean
Determine if using ranged weapon (bow/crossbow in LEFT hand)
422 423 424 425 426 427 428 |
# File 'documented/gemstone/psms/qstrike.rb', line 422 def self.ranged_weapon? left = GameObj.left_hand return false if left.nil? || left.name == "Empty" stats = find_weapon_stats(left) stats&.dig(:category) == :ranged end |
.reduction_for_target_rt(target_rt) ⇒ Integer
Calculate reduction needed to achieve target absolute RT
369 370 371 372 373 374 |
# File 'documented/gemstone/psms/qstrike.rb', line 369 def self.reduction_for_target_rt(target_rt) current_base = base_rt return 0 if target_rt >= current_base [current_base - target_rt, MAX_REDUCTION].min end |
.reset_defaults ⇒ Object
Reset defaults to factory values
123 124 125 126 |
# File 'documented/gemstone/psms/qstrike.rb', line 123 def self.reset_defaults @settings = DEFAULT_SETTINGS.dup save_settings end |
.reset_settings_cache ⇒ void
This method returns an undefined value.
Reset settings loaded flag (for testing)
155 156 157 158 |
# File 'documented/gemstone/psms/qstrike.rb', line 155 def self.reset_settings_cache @settings_loaded = false @settings = nil end |
.resolve_reduction(reduction, reserve, attack_cost) ⇒ Integer?
Resolve reduction value to actual seconds Handles :max, negative (reduce by N), and positive (target RT)
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 |
# File 'documented/gemstone/psms/qstrike.rb', line 765 def self.resolve_reduction(reduction, reserve, attack_cost) case reduction when :max, :optimal calculate(reserve: reserve, attack_cost: attack_cost)[:seconds] when Integer if reduction.negative? # Negative = reduce by that many seconds reduction.abs elsif reduction.positive? # Positive = target absolute RT reduction_for_target_rt(reduction) else 0 end else nil end end |
.save_settings ⇒ void
This method returns an undefined value.
Save settings to DB_Store (per-character)
146 147 148 149 150 151 |
# File 'documented/gemstone/psms/qstrike.rb', line 146 def self.save_settings if defined?(Lich::Common::DB_Store) && defined?(XMLData) && !XMLData.game.to_s.empty? && !XMLData.name.to_s.empty? scope = "#{XMLData.game}:#{XMLData.name}" Lich::Common::DB_Store.save(scope, 'lich_qstrike', @settings) end end |
.secondary_equipment_speed ⇒ Integer
Get secondary hand equipment speed For ranged: RIGHT hand is secondary For melee: LEFT hand is secondary Only weapons count - shields and non-weapons = 0
470 471 472 473 |
# File 'documented/gemstone/psms/qstrike.rb', line 470 def self.secondary_equipment_speed hand = ranged_weapon? ? GameObj.right_hand : GameObj.left_hand weapon_speed_for(hand)[:equipment_speed] end |
.set_default(key, value) ⇒ Object
Set a single default value (persists to DB_Store for per-character storage)
108 109 110 111 112 |
# File 'documented/gemstone/psms/qstrike.rb', line 108 def self.set_default(key, value) load_settings @settings[key.to_sym] = value save_settings end |
.striking_asp_active? ⇒ Boolean
Check if Striking Asp stance is active
574 575 576 577 578 579 580 |
# File 'documented/gemstone/psms/qstrike.rb', line 574 def self.striking_asp_active? return false unless defined?(Effects::Buffs) Effects::Buffs.active?('Striking Asp') rescue StandardError false end |
.striking_asp_multiplier ⇒ Float
Get the cost multiplier based on Striking Asp status
594 595 596 597 598 599 |
# File 'documented/gemstone/psms/qstrike.rb', line 594 def self.striking_asp_multiplier return 1.0 unless striking_asp_active? rank = striking_asp_rank STRIKING_ASP_MULTIPLIERS[rank] || 1.0 end |
.striking_asp_rank ⇒ Integer
Get Striking Asp rank (1, 2, or 3)
584 585 586 587 588 589 590 |
# File 'documented/gemstone/psms/qstrike.rb', line 584 def self.striking_asp_rank return 0 unless defined?(CMan) CMan['striking_asp'].to_i rescue StandardError 0 end |
.use(reduction:, attack:, target: nil, reserve: nil, adaptive: nil) ⇒ Hash
Execute QSTRIKE with an attack command
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'documented/gemstone/psms/qstrike.rb', line 275 def self.use(reduction:, attack:, target: nil, reserve: nil, adaptive: nil) reserve ||= default(:reserve) adaptive = default(:adaptive) if adaptive.nil? attack_name = normalize_attack_name(attack) # A targeted mstrike is a focused one, whatever the name says attack_cost = attack_name == 'mstrike' && target ? mstrike_cost(focused: true) : lookup_attack_cost(attack_name) # Determine the actual reduction to attempt actual_reduction = resolve_reduction(reduction, reserve, attack_cost) if actual_reduction.nil? || actual_reduction.zero? max_affordable = calculate(reserve: reserve, attack_cost: attack_cost)[:seconds] respond "[QStrike] Cannot afford any reduction. Stamina: #{Char.stamina}, Reserve: #{reserve}, Attack cost: #{attack_cost}" return { success: false, reason: :cannot_afford, requested_reduction: reduction, max_affordable: max_affordable } end # Check if we can afford the requested reduction qstrike_cost = cost_for_reduction(actual_reduction) available = Char.stamina - reserve - attack_cost if qstrike_cost > available if adaptive # Calculate what we can actually afford max_affordable = calculate(reserve: reserve, attack_cost: attack_cost)[:seconds] if max_affordable.positive? actual_reduction = max_affordable qstrike_cost = cost_for_reduction(actual_reduction) else respond "[QStrike] Insufficient stamina. Need: #{qstrike_cost}, Available: #{available} (after #{reserve} reserve + #{attack_cost} attack)" return { success: false, reason: :insufficient_stamina, requested_reduction: reduction, available_stamina: available, qstrike_cost: qstrike_cost } end else max_affordable = calculate(reserve: reserve, attack_cost: attack_cost)[:seconds] respond "[QStrike] Insufficient stamina for #{actual_reduction}s reduction. Need: #{qstrike_cost}, Available: #{available}. Max affordable: #{max_affordable}s" return { success: false, reason: :insufficient_stamina, requested_reduction: reduction, available_stamina: available, qstrike_cost: qstrike_cost, max_affordable: max_affordable } end end # Execute the qstrike and attack execute_qstrike(actual_reduction) execute_attack(attack, target) { success: true, reduction_used: actual_reduction, qstrike_cost: qstrike_cost, attack_cost: attack_cost, total_cost: qstrike_cost + attack_cost, stamina_after: Char.stamina - qstrike_cost - attack_cost } end |
.valid_cache? ⇒ Boolean
Check if cached value is still valid (hands haven't changed)
616 617 618 619 620 621 622 623 624 625 |
# File 'documented/gemstone/psms/qstrike.rb', line 616 def self.valid_cache? return false unless @cached_cost current_right = hand_cache_key(GameObj.right_hand) current_left = hand_cache_key(GameObj.left_hand) @cached_right_hand == current_right && @cached_left_hand == current_left rescue StandardError false end |
.weapon_speed_for(hand) ⇒ Hash
Get weapon stats and equipment speed for a hand
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 |
# File 'documented/gemstone/psms/qstrike.rb', line 434 def self.weapon_speed_for(hand) empty_result = { base_rt: 0, category: nil, equipment_speed: 0 } return empty_result if hand.nil? || hand.name == "Empty" stats = find_weapon_stats(hand) return empty_result unless stats base_rt = stats[:base_rt] base_rt = base_rt.first if base_rt.is_a?(Array) base_rt = base_rt.to_i category = stats[:category] multiplier = SPEED_MULTIPLIERS[category] || DEFAULT_MULTIPLIER # Equipment Speed = Weapon Base RT * Speed Modifier equipment_speed = (base_rt * multiplier).to_i { base_rt: base_rt, category: category, equipment_speed: equipment_speed } end |