Module: Lich::Gemstone::Combat::Parser
- Defined in:
- documented/gemstone/combat/parser.rb
Constant Summary collapse
- TARGET_LINK_PATTERN =
Target link pattern - extract creatures/players from XML Target link pattern - extract creatures/players from XML.
/<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 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 tag (e.g., "a creature" or just "creature").
/<pushBold\/>([^<]*<a exist="[^"]+"[^>]+>[^<]+<\/a>)<popBold\/>/i.freeze
Class Method Summary collapse
-
.extract_creature_target(line) ⇒ Hash?
Extracts a creature target from a line containing bolded links.
-
.extract_target_from_line(line) ⇒ Hash?
Extracts target information from a line, only accepting bolded creatures.
-
.extract_target_from_match(match) ⇒ Hash?
Extracts target information from a regex match object.
-
.parse_attack(line) ⇒ Hash?
Parses a combat attack line and extracts relevant information.
-
.parse_damage(line) ⇒ Integer?
Parses a damage line and extracts the damage value.
-
.parse_status(line) ⇒ Hash?
Parses a status line and returns the status information.
-
.parse_ucs(line) ⇒ Hash?
Parses a UCS line and returns the UCS information.
Class Method Details
.extract_creature_target(line) ⇒ Hash?
Extracts a creature target from a line containing bolded links.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'documented/gemstone/combat/parser.rb', line 117 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) ⇒ Hash?
Extracts target information from a line, only accepting bolded creatures.
171 172 173 174 175 |
# File 'documented/gemstone/combat/parser.rb', line 171 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) ⇒ Hash?
Extracts target information from a regex match object.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'documented/gemstone/combat/parser.rb', line 144 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 a combat attack line and extracts relevant information.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'documented/gemstone/combat/parser.rb', line 53 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.
76 77 78 79 |
# File 'documented/gemstone/combat/parser.rb', line 76 def parse_damage(line) result = Definitions::Damage.parse(line) result ? result[:damage] : nil end |
.parse_status(line) ⇒ Hash?
Only returns a result if tracking statuses is enabled.
Parses a status line and returns the status information.
89 90 91 92 93 94 |
# File 'documented/gemstone/combat/parser.rb', line 89 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?
Only returns a result if tracking UCS is enabled.
Parses a UCS line and returns the UCS information.
104 105 106 107 108 |
# File 'documented/gemstone/combat/parser.rb', line 104 def parse_ucs(line) return nil unless Tracker.settings[:track_ucs] Definitions::UCS.parse(line) end |