Module: Lich::Gemstone::Combat::Parser

Defined in:
documented/gemstone/combat/parser.rb

Constant Summary collapse

/<a exist="(?<id>[^"]+)" noun="(?<noun>[^"]+)">(?<name>[^<]+)<\/a>/i.freeze
BOLD_WRAPPER_PATTERN =

Bold tag pattern - creatures are wrapped in bold tags Non-greedy match to avoid spanning multiple creatures Allow zero or more characters before <a> tag (e.g., “a creature” or just “creature”) Bold tag pattern - creatures are wrapped in bold tags Non-greedy match to avoid spanning multiple creatures Allow zero or more characters before <a> tag (e.g., “a creature” or just “creature”)

/<pushBold\/>([^<]*<a exist="[^"]+"[^>]+>[^<]+<\/a>)<popBold\/>/i.freeze

Class Method Summary collapse

Class Method Details

.extract_creature_target(line) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'documented/gemstone/combat/parser.rb', line 92

def extract_creature_target(line)
  # Check if line contains a bolded link
  bold_match = BOLD_WRAPPER_PATTERN.match(line)
  return nil unless bold_match

  # Extract the link from within the bold tags
  link_text = bold_match[1]
  link_match = TARGET_LINK_PATTERN.match(link_text)
  return nil unless link_match

  id = link_match[:id].to_i
  return nil if id <= 0 # Skip invalid IDs

  {
    id: id,
    noun: link_match[:noun],
    name: link_match[:name]
  }
end

.extract_target_from_line(line) ⇒ Object



132
133
134
135
136
# File 'documented/gemstone/combat/parser.rb', line 132

def extract_target_from_line(line)
  # ONLY accept bolded creatures as targets
  # Non-bolded links are equipment, objects, or other non-combatants
  extract_creature_target(line)
end

.extract_target_from_match(match) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'documented/gemstone/combat/parser.rb', line 112

def extract_target_from_match(match)
  return nil unless match.names.include?('target')
  target_text = match[:target]
  return nil if target_text.nil? || target_text.strip.empty?

  # Look for creature in target text
  if (target_match = TARGET_LINK_PATTERN.match(target_text))
    id = target_match[:id].to_i
    return nil if id < 0

    return {
      id: id,
      noun: target_match[:noun],
      name: target_match[:name]
    }
  end

  nil
end

.parse_attack(line) ⇒ Hash?

Parses an attack line and extracts relevant information.

Examples:

attack_info = Lich::Gemstone::Combat::Parser.parse_attack("You attack the creature.")

Parameters:

  • line (String)

    The line containing the attack information.

Returns:

  • (Hash, nil)

    A hash containing attack details or nil if no attack is detected.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'documented/gemstone/combat/parser.rb', line 40

def parse_attack(line)
  return nil unless attack_detector.match?(line)

  attack_lookup.each do |pattern, name|
    if (match = pattern.match(line))
      target_info = extract_target_from_match(match) || extract_target_from_line(line)
      return {
        name: name,
        target: target_info || {},
        damaging: true
      }
    end
  end
  nil
end

.parse_damage(line) ⇒ Integer?

Parses a damage line and extracts the damage value.

Examples:

damage = Lich::Gemstone::Combat::Parser.parse_damage("You deal 10 damage.")

Parameters:

  • line (String)

    The line containing the damage information.

Returns:

  • (Integer, nil)

    The damage value or nil if not found.



62
63
64
65
# File 'documented/gemstone/combat/parser.rb', line 62

def parse_damage(line)
  result = Definitions::Damage.parse(line)
  result ? result[:damage] : nil
end

.parse_status(line) ⇒ Hash?

Parses a status line and extracts the status information.

Examples:

status_info = Lich::Gemstone::Combat::Parser.parse_status("You are now stunned.")

Parameters:

  • line (String)

    The line containing the status information.

Returns:

  • (Hash, nil)

    A hash containing status details or nil if not found.



73
74
75
76
77
78
# File 'documented/gemstone/combat/parser.rb', line 73

def parse_status(line)
  return nil unless Tracker.settings[:track_statuses]

  # Return the full result including action field
  Definitions::Statuses.parse(line)
end

.parse_ucs(line) ⇒ Hash?

Parses a UCS line and extracts the UCS information.

Examples:

ucs_info = Lich::Gemstone::Combat::Parser.parse_ucs("You are now under a curse.")

Parameters:

  • line (String)

    The line containing the UCS information.

Returns:

  • (Hash, nil)

    A hash containing UCS details or nil if not found.



86
87
88
89
90
# File 'documented/gemstone/combat/parser.rb', line 86

def parse_ucs(line)
  return nil unless Tracker.settings[:track_ucs]

  Definitions::UCS.parse(line)
end