Class: Lich::Gemstone::Overwatch

Inherits:
Object
  • Object
show all
Defined in:
documented/gemstone/overwatch.rb

Overview

Manages hidden creature detection and tracking in Gemstone IV. Automatically tracks when creatures hide and reveals them when they emerge. Integrates with GameObj and XMLData to maintain accurate target lists.

Examples:

Check if current room has hidden creatures

Overwatch.hiders? #=> true or false

Get room ID where hiders were detected

room_id = Overwatch.room_with_hiders #=> 12345 or nil

Enable debug output

Overwatch.debug = true

Defined Under Namespace

Modules: Observer

Class Method Summary collapse

Class Method Details

.clearnil

Clears the hidden targets tracking.

Returns:

  • (nil)


27
28
29
# File 'documented/gemstone/overwatch.rb', line 27

def self.clear
  @@hidden_targets = nil
end

.debug=(value) ⇒ Boolean

Enables or disables debug output.

Parameters:

  • value (Boolean)

    true to enable debug output

Returns:

  • (Boolean)

    the debug value



66
67
68
# File 'documented/gemstone/overwatch.rb', line 66

def self.debug=(value)
  @@debug = value
end

.debug?Boolean

Checks if debug mode is enabled.

Returns:

  • (Boolean)

    true if debug is enabled



73
74
75
# File 'documented/gemstone/overwatch.rb', line 73

def self.debug?
  @@debug
end

.hiders?Boolean

Checks if the current room has hidden targets.

Returns:

  • (Boolean)

    true if current room matches tracked hider room



41
42
43
44
# File 'documented/gemstone/overwatch.rb', line 41

def self.hiders?
  return false if @@hidden_targets.nil?
  @@hidden_targets.eql?(XMLData.room_id)
end

.push_revealed_targets(target_id, target_noun, target_name, silent_strike: false) ⇒ void

This method returns an undefined value.

Adds a revealed target to GameObj and XMLData if not already present. Handles silent strike detection by checking recent game output.

Parameters:

  • target_id (String)

    the target's game object ID

  • target_noun (String)

    the target's noun

  • target_name (String)

    the target's full name

  • silent_strike (Boolean) (defaults to: false)

    whether to check for silent strike rehide



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'documented/gemstone/overwatch.rb', line 85

def self.push_revealed_targets(target_id, target_noun, target_name, silent_strike: false)
  @@hidden_targets = nil

  if silent_strike
    respond "Checking for silent strike against #{target_id} #{target_name}." if @@debug
    result = reget(10, /fades into the surroundings\./, /slips into the shadows\./, /botch an attempt at concealing\./, /The figure quickly disappears from view\./, core: true)
    respond result if @@debug

    unless result.empty?
      case result[0]
      when /With a (?:barely audible hiss|sibilant exhalation), <pushBold\/>\w+ <a exist="(\d+)" noun=" ?\w+">[^<]+<\/a><popBold\/> (?:fades into the surroundings|slips into the shadows)\./
        if target_id == Regexp.last_match[1]
          respond "Silent Strike Detected. Target #{target_id} #{target_name} is hidden." if @@debug
          return
        end
      when /The figure quickly disappears from view\./
        respond "Silent Strike Detected. Target is hidden." if @@debug
        return
      when /You notice <pushBold\/>\w+ <a exist="(\d+)" noun=" ?\w+">[^<]+<\/a><popBold\/> botch an attempt at concealing <pushBold\/><a exist="\d+" noun=" ?\w+">\w+<\/a><popBold\/>\./
        if target_id == Regexp.last_match[1]
          respond "Silent Strike Botched. Target #{target_id} #{target_name}." if @@debug
        end
      end
    end
  end

  respond "push_revealed_targets(#{target_id}, #{target_noun}, #{target_name}, silent_strike: #{silent_strike})" if @@debug

  # Add to GameObj.npcs if not already present
  unless GameObj.npcs.any? { |npc| npc.id == target_id }
    GameObj.new_npc(target_id, target_noun, target_name.gsub(/  /, " "))
    respond "#{target_id} added to GameObj.npcs." if @@debug
  end

  # Add to XMLData.current_target_ids if not already present
  unless XMLData.current_target_ids.include?(target_id)
    XMLData.current_target_ids.unshift(target_id)
    respond "#{target_id} added to XMLData.current_target_ids." if @@debug
  end
end

.room_with_hidersInteger?

Gets the room ID where hidden targets were last detected.

Returns:

  • (Integer, nil)

    room ID or nil if no hidden targets tracked



34
35
36
# File 'documented/gemstone/overwatch.rb', line 34

def self.room_with_hiders
  @@hidden_targets
end

.room_with_hiders_resetnil

Clears hidden targets tracking. Alias for clear method.

Returns:

  • (nil)


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

def self.room_with_hiders_reset
  clear
end

.track_hidden_targets(room_id) ⇒ Integer

Sets the room where hidden targets were detected.

Parameters:

  • room_id (Integer)

    the room ID to track

Returns:

  • (Integer)

    the room_id



50
51
52
# File 'documented/gemstone/overwatch.rb', line 50

def self.track_hidden_targets(room_id)
  @@hidden_targets = room_id
end