Module: Lich::Gemstone::Effects

Defined in:
documented/gemstone/effects.rb

Overview

Namespace for tracking active spell effects, buffs, debuffs, and cooldowns from the game server's XML feed. Provides registries for querying effect state and expiration times.

Defined Under Namespace

Classes: Registry

Constant Summary collapse

Spells =
Registry.new("Active Spells")
Buffs =
Registry.new("Buffs")
Debuffs =
Registry.new("Debuffs")
Cooldowns =
Registry.new("Cooldowns")

Class Method Summary collapse

Class Method Details

.display ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Displays a formatted table of all active effects (spells, cooldowns, buffs, debuffs) and any known spells not yet cast. Sends output to the terminal.



104
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
135
136
137
138
139
140
141
142
143
144
145
# File 'documented/gemstone/effects.rb', line 104

def self.display
  effect_out = Terminal::Table.new :headings => ["ID", "Type", "Name", "Duration"]
  titles = ["Spells", "Cooldowns", "Buffs", "Debuffs"]
  existing_spell_nums = []
  active_spells = Spell.active
  active_spells.each { |s| existing_spell_nums << s.num }
  circle = nil
  [Effects::Spells, Effects::Cooldowns, Effects::Buffs, Effects::Debuffs].each { |effect|
    title = titles.shift
    id_effects = effect.to_h.select { |k, _v| k.is_a?(Integer) }
    text_effects = effect.to_h.reject { |k, _v| k.is_a?(Integer) }
    if id_effects.length != text_effects.length
      # has spell names disabled
      text_effects = id_effects
    end
    if id_effects.length == 0
      effect_out.add_row ["", title, "No #{title.downcase} found!", ""]
    else
      id_effects.each { |sn, end_time|
        stext = text_effects.shift[0]
        duration = ((end_time - Time.now) / 60.to_f)
        if duration < 0
          next
        elsif duration > 86400
          duration = "Indefinite"
        else
          duration = duration.as_time
        end
        if Spell[sn].circlename && circle != Spell[sn].circlename && title == 'Spells'
          circle = Spell[sn].circlename
        end
        effect_out.add_row [sn, title, stext, duration]
        existing_spell_nums.delete_if { |s| Spell[s].name =~ /#{Regexp.escape(stext)}/ || stext =~ /#{Regexp.escape(Spell[s].name)}/ || s == sn }
      }
    end
    effect_out.add_separator unless title == 'Debuffs' && existing_spell_nums.empty?
  }
  existing_spell_nums.each { |sn|
    effect_out.add_row [sn, "Other", Spell[sn].name, (Spell[sn].timeleft.as_time)]
  }
  Lich::Messaging.mono(effect_out.to_s)
end