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 <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
- .extract_creature_target(line) ⇒ Object
- .extract_target_from_line(line) ⇒ Object
- .extract_target_from_match(match) ⇒ Object
-
.parse_attack(line) ⇒ Hash?
Parses an 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 extracts the status information.
-
.parse_ucs(line) ⇒ Hash?
Parses a UCS line and extracts the UCS information.
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.
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.
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.
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 |