Class: Lich::Gemstone::Effects::Registry
- Inherits:
-
Object
- Object
- Lich::Gemstone::Effects::Registry
- Includes:
- Enumerable
- Defined in:
- lib/gemstone/effects.rb
Overview
A class that manages the registry of effects, including spells, buffs, debuffs, and cooldowns.
Instance Method Summary collapse
-
#active?(effect) ⇒ Boolean
Checks if a given effect is currently active.
-
#each {|k, v| ... } ⇒ Object
Iterates over each effect in the registry.
-
#expiration(effect) ⇒ Integer
Retrieves the expiration time of a given effect.
-
#initialize(dialog) ⇒ Registry
constructor
Initializes a new Registry instance.
-
#time_left(effect) ⇒ Float
Calculates the time left for a given effect.
-
#to_h ⇒ Hash
Converts the effects in the registry to a hash.
Constructor Details
#initialize(dialog) ⇒ Registry
Initializes a new Registry instance.
11 12 13 |
# File 'lib/gemstone/effects.rb', line 11 def initialize(dialog) @dialog = dialog end |
Instance Method Details
#active?(effect) ⇒ Boolean
Checks if a given effect is currently active.
45 46 47 |
# File 'lib/gemstone/effects.rb', line 45 def active?(effect) expiration(effect).to_f > Time.now.to_f end |
#each {|k, v| ... } ⇒ Object
Iterates over each effect in the registry.
25 26 27 |
# File 'lib/gemstone/effects.rb', line 25 def each() to_h.each { |k, v| yield(k, v) } end |
#expiration(effect) ⇒ Integer
Retrieves the expiration time of a given effect.
33 34 35 36 37 38 39 |
# File 'lib/gemstone/effects.rb', line 33 def expiration(effect) if effect.is_a?(Regexp) to_h.find { |k, _v| k.to_s =~ effect }[1] || 0 else to_h.fetch(effect, 0) end end |
#time_left(effect) ⇒ Float
Calculates the time left for a given effect.
53 54 55 56 57 58 59 |
# File 'lib/gemstone/effects.rb', line 53 def time_left(effect) if expiration(effect) != 0 ((expiration(effect) - Time.now) / 60.to_f) else expiration(effect) end end |
#to_h ⇒ Hash
Converts the effects in the registry to a hash.
18 19 20 |
# File 'lib/gemstone/effects.rb', line 18 def to_h XMLData.dialogs.fetch(@dialog, {}) end |