Module: Lich::Gemstone::Combat::Definitions::Damage

Defined in:
documented/gemstone/combat/defs/damage.rb

Overview

Damage pattern definitions and parsing for GemStone IV combat.

Provides regular expressions to match and extract damage values from various attack types including basic weapon damage, spell effects, and environmental effects like cyclones. The .parse method efficiently extracts damage amounts and optional target information from combat lines.

Constant Summary collapse

BASIC_DAMAGE =

Core damage patterns - most common

[
  /\.\.\. and hit for (?<damage>\d+) points? of damage!/,
  /\.\.\. (?<damage>\d+) points? of damage!/,
  /\.\.\. hits for (?<damage>\d+) points? of damage!/
].freeze
SPELL_DAMAGE =

Spell damage patterns

[
  /Consumed by the hallowed flames, (?<target>.+?) is ravaged for (?<damage>\d+) points? of damage!/,
  /Wisps of black smoke swirl around (?<target>.+?) and it bursts into flame causing (?<damage>\d+) points? of damage!/
].freeze
ENVIRONMENTAL_DAMAGE =

Environmental/cyclone damage patterns

[
  /The whirlwind quickly swirls around (?<target>.+?), causing (?<damage>\d+) points? of damage!/,
  /The flickering flames quickly swirl around (?<target>.+?), causing (?<damage>\d+) points? of damage!/,
  /The shifting stones quickly orbit (?<target>.+?), causing (?<damage>\d+) points? of damage!/
].freeze
ALL_DAMAGE =

All damage patterns combined

(BASIC_DAMAGE + SPELL_DAMAGE + ENVIRONMENTAL_DAMAGE).freeze
DAMAGE_DETECTOR =

Compiled regex for fast detection

Regexp.union(ALL_DAMAGE).freeze

Class Method Summary collapse

Class Method Details

.parse(line) ⇒ Object

Parse damage from line



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'documented/gemstone/combat/defs/damage.rb', line 52

def self.parse(line)
  # Fast rejection: every damage pattern contains "point(s) of damage".
  # The substring check skips the regex scan on the ~95% of lines that
  # can't match; the union detector then rejects near-misses cheaply.
  return nil unless line.include?('point')
  return nil unless DAMAGE_DETECTOR.match?(line)

  ALL_DAMAGE.each do |pattern|
    if (match = pattern.match(line))
      result = { damage: match[:damage].to_i }
      result[:target] = match[:target] if match.names.include?('target') && match[:target]
      return result
    end
  end
  nil
end