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

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

Constant Summary collapse

BASIC_DAMAGE =

Core damage patterns - most common Core damage patterns - most common.

Examples:

BASIC_DAMAGE.match("... and hit for 50 points of damage!") # => #<MatchData>

See Also:

[
  /\.\.\. 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 Spell damage patterns.

Examples:

SPELL_DAMAGE.match("Consumed by the hallowed flames, target is ravaged for 30 points of damage!") # => #<MatchData>

See Also:

[
  /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 Environmental/cyclone damage patterns.

Examples:

ENVIRONMENTAL_DAMAGE.match("The whirlwind quickly swirls around target, causing 20 points of damage!") # => #<MatchData>

See Also:

[
  /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 All damage patterns combined.

(BASIC_DAMAGE + SPELL_DAMAGE + ENVIRONMENTAL_DAMAGE).freeze
DAMAGE_DETECTOR =

Compiled regex for fast detection Compiled regex for fast detection of damage patterns.

See Also:

Regexp.union(ALL_DAMAGE).freeze

Class Method Summary collapse

Class Method Details

.parse(line) ⇒ Hash?

Note:

This method uses the combined damage patterns from ALL_DAMAGE.

Parses a line of text to extract damage information.

Examples:

parse("... and hit for 50 points of damage!") # => { damage: 50 }

Parameters:

  • line (String)

    the line of text to parse

Returns:

  • (Hash, nil)

    a hash containing damage and optionally target, or nil if no match



67
68
69
70
71
72
73
74
75
76
# File 'documented/gemstone/combat/defs/damage.rb', line 67

def self.parse(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