Module: Lich::Gemstone::Combat::Tracker

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

Overview

Combat tracking system

Main interface for the combat tracking system. Integrates with Lich’s Combat Tracker - Main interface for combat event processing Integrates with Lich’s game processing to track damage, wounds, and status effects

Examples:

Using the Tracker module

Lich::Gemstone::Combat::Tracker.enable!

Constant Summary collapse

DEFAULT_SETTINGS =

Default settings for combat tracking Default settings for combat tracking

{
  enabled: false,           # Disabled by default, user must enable
  track_damage: true,
  track_wounds: true,
  track_statuses: true,
  track_ucs: true,          # Track UCS (position, tierup, smite)
  max_threads: 2,           # Keep threading for performance
  debug: false,
  buffer_size: 200,         # Increase for large combat chunks
  fallback_max_hp: 350,     # Default max HP when template unavailable
  cleanup_interval: 100,    # Cleanup creature registry every N chunks
  cleanup_max_age: 600      # Remove creatures older than N seconds (10 minutes)
}.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.bufferObject (readonly)

Returns the value of attribute buffer.



48
49
50
# File 'documented/gemstone/combat/tracker.rb', line 48

def buffer
  @buffer
end

.settingsObject (readonly)

Returns the value of attribute settings.



48
49
50
# File 'documented/gemstone/combat/tracker.rb', line 48

def settings
  @settings
end

Class Method Details

.combat_relevant?(line) ⇒ Boolean

Checks if a line of text is relevant to combat

Examples:

if Lich::Gemstone::Combat::Tracker.combat_relevant?(line)
  puts "This line is combat relevant"
end

Parameters:

  • line (String)

    The line of text to check

Returns:

  • (Boolean)

    true if the line is combat relevant, false otherwise



175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'documented/gemstone/combat/tracker.rb', line 175

def combat_relevant?(line)
  line.include?('swing') ||
    line.include?('thrust') ||
    line.include?('cast') ||
    line.include?('gesture') ||
    line.include?('points of damage') ||
    line.include?('**') || # Flares
    line.include?('<pushBold/>') || # Creatures
    line.include?('AS:') || # Attack rolls
    line.include?('positioning against') || # UCS position
    line.include?('vulnerable to a followup') || # UCS tierup
    line.include?('crimson mist') || # UCS smite
    line.match?(/\b(?:hit|miss|parr|block|dodge)\b/i)
end

.configure(new_settings = {}) ⇒ void

This method returns an undefined value.

Configures the combat tracker with new settings

Examples:

Lich::Gemstone::Combat::Tracker.configure(enabled: true)

Parameters:

  • new_settings (Hash) (defaults to: {})

    A hash of settings to update



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'documented/gemstone/combat/tracker.rb', line 195

def configure(new_settings = {})
  initialize! unless @initialized
  @settings.merge!(new_settings)

  # Save to Lich settings system for persistence
  save_settings

  # Reinitialize processor if thread count changed
  if new_settings.key?(:max_threads)
    shutdown_processor
    initialize_processor
  end

  respond "[Combat] Settings updated: #{@settings}" if debug?
end

.debug?Boolean

Checks if debug mode is enabled

Examples:

if Lich::Gemstone::Combat::Tracker.debug?
  puts "Debugging is enabled"
end

Returns:

  • (Boolean)

    true if debug mode is enabled, false otherwise



101
102
103
# File 'documented/gemstone/combat/tracker.rb', line 101

def debug?
  @settings[:debug] || $combat_debug
end

.disable!void

This method returns an undefined value.

Disables combat tracking

Examples:

Lich::Gemstone::Combat::Tracker.disable!


82
83
84
85
86
87
88
89
90
91
92
93
# File 'documented/gemstone/combat/tracker.rb', line 82

def disable!
  return unless @enabled

  initialize! unless @initialized
  @enabled = false
  @settings[:enabled] = false
  save_settings # Persist disabled state
  remove_downstream_hook
  shutdown_processor

  respond "[Combat] Combat tracking disabled" if debug?
end

.disable_debug!void

This method returns an undefined value.

Disables debug mode for combat tracking

Examples:

Lich::Gemstone::Combat::Tracker.disable_debug!


118
119
120
121
# File 'documented/gemstone/combat/tracker.rb', line 118

def disable_debug!
  configure(debug: false)
  respond "[Combat] Debug mode disabled"
end

.enable!void

This method returns an undefined value.

Enables combat tracking

Examples:

Lich::Gemstone::Combat::Tracker.enable!


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

def enable!
  return if @enabled

  initialize! unless @initialized
  @enabled = true
  @settings[:enabled] = true # Force enabled in settings
  save_settings # Persist enabled state
  initialize_processor
  add_downstream_hook

  respond "[Combat] Combat tracking enabled" if debug?
end

.enable_debug!void

This method returns an undefined value.

Enables debug mode for combat tracking

Examples:

Lich::Gemstone::Combat::Tracker.enable_debug!


109
110
111
112
# File 'documented/gemstone/combat/tracker.rb', line 109

def enable_debug!
  configure(debug: true, enabled: true)
  respond "[Combat] Debug mode enabled"
end

.enabled?Boolean

Checks if combat tracking is enabled

Examples:

if Lich::Gemstone::Combat::Tracker.enabled?
  puts "Tracking is enabled"
end

Returns:

  • (Boolean)

    true if combat tracking is enabled, false otherwise



56
57
58
59
# File 'documented/gemstone/combat/tracker.rb', line 56

def enabled?
  initialize! unless @initialized
  @enabled && @settings[:enabled]
end

.fallback_hpInteger

Retrieves the fallback maximum HP value

Examples:

hp = Lich::Gemstone::Combat::Tracker.fallback_hp

Returns:

  • (Integer)

    The fallback maximum HP value



137
138
139
140
# File 'documented/gemstone/combat/tracker.rb', line 137

def fallback_hp
  initialize! unless @initialized
  @settings[:fallback_max_hp]
end

.process(chunk) ⇒ void

This method returns an undefined value.

Processes a chunk of combat data

Examples:

Lich::Gemstone::Combat::Tracker.process(chunk)

Parameters:

  • chunk (Array<String>)

    The chunk of combat data to process



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'documented/gemstone/combat/tracker.rb', line 147

def process(chunk)
  return unless enabled?
  return if chunk.empty?

  # Quick filter - only process if combat-related content present
  return unless chunk.any? { |line| combat_relevant?(line) }

  if @settings[:max_threads] > 1
    @async_processor.process_async(chunk)
  else
    Processor.process(chunk)
  end

  # Periodic cleanup of old creature instances
  @chunks_processed += 1
  if @chunks_processed >= @settings[:cleanup_interval]
    cleanup_creatures
    @chunks_processed = 0
  end
end

.set_fallback_hp(hp_value) ⇒ void

This method returns an undefined value.

Sets the fallback maximum HP value

Examples:

Lich::Gemstone::Combat::Tracker.set_fallback_hp(400)

Parameters:

  • hp_value (Integer)

    The fallback maximum HP value



128
129
130
131
# File 'documented/gemstone/combat/tracker.rb', line 128

def set_fallback_hp(hp_value)
  configure(fallback_max_hp: hp_value.to_i)
  respond "[Combat] Fallback max HP set to #{hp_value}"
end

.statsHash

Retrieves the current stats of the combat tracker

Examples:

stats = Lich::Gemstone::Combat::Tracker.stats

Returns:

  • (Hash)

    A hash containing the current stats



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'documented/gemstone/combat/tracker.rb', line 215

def stats
  return { enabled: false } unless enabled?

  base_stats = {
    enabled: true,
    buffer_size: @buffer.size,
    settings: @settings
  }

  if @async_processor
    base_stats.merge(@async_processor.stats)
  else
    base_stats.merge(active: 0, total: 0)
  end
end