Module: Lich::Gemstone::ActiveSpell

Extended by:
Common::Watchable
Defined in:
documented/gemstone/infomon/activespell.rb

Overview

Module for managing active spells in the Lich game.

This module handles spell duration updates and displays.

See Also:

Class Method Summary collapse

Methods included from Common::Watchable

watch!

Class Method Details

.block_until_update_requestedTime

Blocks until an update request is made and clears the queue.

Returns:

  • (Time)

    the time when the update was requested



196
197
198
199
200
# File 'documented/gemstone/infomon/activespell.rb', line 196

def self.block_until_update_requested
  event = queue.pop
  queue.clear
  event
end

.get_spell_info(spell_check = XMLData.active_spells) ⇒ Array<String>, Hash

Retrieves information about active spells and their durations.

Parameters:

  • spell_check (Hash) (defaults to: XMLData.active_spells)

    a hash of active spells to check

Returns:

  • (Array<String>, Hash)

    an array containing spell names and a hash of their durations



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'documented/gemstone/infomon/activespell.rb', line 33

def self.get_spell_info(spell_check = XMLData.active_spells)
  respond "spell update requested\r\n" if $infomon_debug
  spell_update_durations = spell_check
  spell_update_names = []
  makeychange = []
  spell_update_durations.each do |k, _v|
    case k
    when /(?:Mage Armor|520) - /
      makeychange << k
      spell_update_names.push('Mage Armor')
      next
    when /(?:CoS|712) - /
      makeychange << k
      spell_update_names.push('Cloak of Shadows')
      next
    when /Enh\./
      makeychange << k
      case k
      when /Enh\. Strength/
        spell_update_names.push('Surge of Strength')
      when /Enh\. (?:Dexterity|Agility)/
        spell_update_names.push('Burst of Swiftness')
      end
      next
    when /Empowered/
      makeychange << k
      spell_update_names.push('Shout')
      next
    when /Multi-Strike/
      makeychange << k
      spell_update_names.push('MStrike Cooldown')
      next
    when /Next Bounty Cooldown/
      makeychange << k
      spell_update_names.push('Next Bounty')
      next
    when /(?:Resist Nature|620) (?:- (?:Heat|Cold) \(\d\d%|- Steam \(\d\d|- Lightning|\(\d\d%\))/
      makeychange << k
      spell_update_names.push('Resist Nature')
      next
    end
    spell_update_names << k
  end
  makeychange.each do |changekey|
    next unless spell_update_durations.key?(changekey)

    case changekey
    when /(?:Mage Armor|520) - /
      spell_update_durations['Mage Armor'] = spell_update_durations.delete changekey
    when /(?:CoS|712) - /
      spell_update_durations['Cloak of Shadows'] = spell_update_durations.delete changekey
    when /Enh\. Strength/
      spell_update_durations['Surge of Strength'] = spell_update_durations.delete changekey
    when /Enh\. (?:Dexterity|Agility)/
      spell_update_durations['Burst of Swiftness'] = spell_update_durations.delete changekey
    when /Empowered/
      spell_update_durations['Shout'] = spell_update_durations.delete changekey
    when /Multi-Strike/
      spell_update_durations['MStrike Cooldown'] = spell_update_durations.delete changekey
    when /Next Bounty Cooldown/
      spell_update_durations['Next Bounty'] = spell_update_durations.delete changekey
    when /Next Group Bounty Cooldown/
      spell_update_durations['Next Group Bounty'] = spell_update_durations.delete changekey
    when /(?:Resist Nature|620) (?:- (?:Heat|Cold) \(\d\d%|- Steam \(\d\d|- Lightning|\(\d\d%\))/
      spell_update_durations['Resist Nature'] = spell_update_durations.delete changekey
    end
  end
  [spell_update_names, spell_update_durations]
end

.queueQueue

Retrieves the queue for update requests.

Returns:

  • (Queue)

    the queue of update requests



190
191
192
# File 'documented/gemstone/infomon/activespell.rb', line 190

def self.queue
  @queue ||= Queue.new
end

.request_updatevoid

This method returns an undefined value.

Requests an update for spell durations.



184
185
186
# File 'documented/gemstone/infomon/activespell.rb', line 184

def self.request_update
  queue << Time.now
end

.show_duration_changevoid

This method returns an undefined value.

Displays changes in active spell durations.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'documented/gemstone/infomon/activespell.rb', line 105

def self.show_duration_change
  active_durations = Array.new
  group_effects = [307, 310, 1605, 1609, 1618, 1608]
  [Effects::Spells.dup, Effects::Cooldowns.dup, Effects::Buffs.dup, Effects::Debuffs.dup].each do |effect_type|
    active_durations += effect_type.to_h.keys
    effect_type.to_h.each do |effect, end_time|
      next unless effect.is_a?(String)
      effect, end_time = ActiveSpell.get_spell_info({ effect=>end_time })
      effect = effect.join
      end_time = end_time[effect]
      next unless (spell = Spell.list.find { |s| s.num == effect.to_i || s.name =~ /^#{effect}$/ })
      if effect_type.to_h.find { |k, _v| k == spell.num }
        effect_key = spell.num
      else
        effect_key = spell.name
      end
      time_left = ((end_time - Time.now) / 60).to_f
      duration = ((end_time - (@current_durations[effect_key].nil? ? Time.now : @current_durations[effect_key])) / 60).to_f
      if @durations_first_pass_complete && (@current_durations[effect_key].nil? || end_time > @current_durations[effect_key]) && duration > (0.1).to_f && !(group_effects.include?(spell.num) && !spell.known?)
        respond "[ #{spell.num} #{spell.name}: +#{duration.as_time}, #{time_left.as_time} ]"
      end
      @current_durations[effect_key] = end_time
    end
  end
  (@current_durations.keys - active_durations).each do |spell|
    respond "[ #{Spell.list.find { |s| s.num == spell.to_i || s.name =~ /#{spell}/ }.num} #{Spell.list.find { |s| s.num == spell.to_i || s.name =~ /#{spell}/ }.name}: Ended ]" if @durations_first_pass_complete
    @current_durations.delete(spell)
  end
  @durations_first_pass_complete = true
end

.show_durations?Boolean

Checks if spell durations should be displayed.

Returns:

  • (Boolean)

    true if durations should be shown, false otherwise



26
27
28
# File 'documented/gemstone/infomon/activespell.rb', line 26

def self.show_durations?
  Infomon.get_bool("infomon.show_durations")
end

.update_spell_durationsvoid

This method returns an undefined value.

Updates the durations of active spells based on the latest information.



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'documented/gemstone/infomon/activespell.rb', line 138

def self.update_spell_durations
  begin
    respond "[infomon] updating spell durations..." if $infomon_debug
    spell_update_names, spell_update_durations = ActiveSpell.get_spell_info
    respond "#{spell_update_names}\r\n" if $infomon_debug
    respond "#{spell_update_durations}\r\n" if $infomon_debug

    existing_spell_names = []
    active_spells = Spell.active
    ignore_spells = ["Berserk", "Council Task", "Council Punishment", "Briar Betrayer", "Rapid Fire Penalty"]
    active_spells.each { |s| existing_spell_names << s.name }
    inactive_spells = existing_spell_names - ignore_spells - spell_update_names
    inactive_spells.reject! do |s|
      s =~ /^Aspect of the \w+ Cooldown|^[\w\s]+ Recovery/
    end
    inactive_spells.each do |s|
      badspell = Spell[s].num
      Spell[badspell].putdown if Spell[s].active?
    end

    spell_update_durations.uniq.each do |k, v|
      if (spell = Spell.list.find { |s| (s.name.downcase == k.strip.downcase) || (s.num.to_s == k.strip) })
        if (spell.circle.to_i == 10) and not active_spells.any? { |s| s.circle.to_i == 10 }
          Spellsong.renewed
        end
        spell.active = true
        spell.timeleft = if v - Time.now > 300 * 60
                           600.01
                         else
                           ((v - Time.now) / 60)
                         end
      elsif $infomon_debug
        respond "no spell matches #{k}"
      end
    end
    show_duration_change if show_durations?
  rescue StandardError => e
    if $infomon_debug
      respond 'Error in spell durations thread'
      respond e.inspect
    end
  end
end

.watch!void

This method returns an undefined value.

Starts a thread that watches for update requests and processes them.



204
205
206
207
208
209
210
211
212
213
214
# File 'documented/gemstone/infomon/activespell.rb', line 204

def self.watch!
  @thread ||= Thread.new do
    loop do
      block_until_update_requested
      update_spell_durations
    rescue StandardError => e
      respond 'Error in spell durations thread'
      respond e.inspect
    end
  end
end