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 tracking system

Main interface for the combat tracking system. Integrates with Lich's game processing to track various combat-related events.

Constant Summary collapse

DEFAULT_SETTINGS =

Default settings for combat tracking Default settings for combat tracking

Examples:

Default settings

DEFAULT_SETTINGS[:enabled] # => false
DEFAULT_SETTINGS[:track_damage] # => true
{
  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.



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

def buffer
  @buffer
end

.settingsObject (readonly)

Returns the value of attribute settings.



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

def settings
  @settings
end

Class Method Details

.combat_relevant?(line) ⇒ Boolean

Determines if a line of text is relevant to combat.

Parameters:

  • line (String)

    the line of text to check

Returns:

  • (Boolean)

    true if the line is combat relevant, false otherwise



169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'documented/gemstone/combat/tracker.rb', line 169

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.

Parameters:

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

    the new settings to apply



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'documented/gemstone/combat/tracker.rb', line 188

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.

Returns:

  • (Boolean)

    true if debug mode is enabled, false otherwise



103
104
105
# File 'documented/gemstone/combat/tracker.rb', line 103

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

.disable!void

This method returns an undefined value.

Disables combat tracking.



87
88
89
90
91
92
93
94
95
96
97
98
# File 'documented/gemstone/combat/tracker.rb', line 87

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.



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.



71
72
73
74
75
76
77
78
79
80
81
82
# File 'documented/gemstone/combat/tracker.rb', line 71

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.



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

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

.enabled?Boolean

Checks if combat tracking is enabled.

Returns:

  • (Boolean)

    true if combat tracking is enabled, false otherwise



63
64
65
66
# File 'documented/gemstone/combat/tracker.rb', line 63

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

.fallback_hpInteger

Retrieves the fallback maximum HP value.

Returns:

  • (Integer)

    the fallback maximum HP value



135
136
137
138
# File 'documented/gemstone/combat/tracker.rb', line 135

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.

Parameters:

  • chunk (Array<String>)

    the chunk of combat data to process



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

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.

Parameters:

  • hp_value (Integer)

    the fallback maximum HP value



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

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 statistics of the combat tracker.

Returns:

  • (Hash)

    a hash containing the current stats



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'documented/gemstone/combat/tracker.rb', line 207

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