Class: Lich::Gemstone::Effects::Registry
- Inherits:
-
Object
- Object
- Lich::Gemstone::Effects::Registry
- Includes:
- Enumerable
- Defined in:
- documented/gemstone/effects.rb
Overview
Manages a collection of effects for the Lich project.
This class includes methods to handle the registration and retrieval of effects, including spells, buffs, and debuffs.
Instance Method Summary collapse
-
#active?(effect) ⇒ Boolean
Checks if a given effect is currently active.
-
#each {|key, value| ... } ⇒ void
Iterates over each effect in the registry.
-
#expiration(effect) ⇒ Integer
Retrieves the expiration time for a given effect.
-
#initialize(dialog) ⇒ void
constructor
Initializes a new Registry instance.
-
#time_left(effect) ⇒ Integer
Calculates the time left for a given effect.
-
#to_h ⇒ Hash
Converts the registry to a hash representation.
Constructor Details
#initialize(dialog) ⇒ void
Initializes a new Registry instance.
16 17 18 |
# File 'documented/gemstone/effects.rb', line 16 def initialize(dialog) @dialog = dialog end |
Instance Method Details
#active?(effect) ⇒ Boolean
Checks if a given effect is currently active.
47 48 49 |
# File 'documented/gemstone/effects.rb', line 47 def active?(effect) expiration(effect).to_f > Time.now.to_f end |
#each {|key, value| ... } ⇒ void
This method returns an undefined value.
Iterates over each effect in the registry.
29 30 31 |
# File 'documented/gemstone/effects.rb', line 29 def each() to_h.each { |k, v| yield(k, v) } end |
#expiration(effect) ⇒ Integer
Retrieves the expiration time for a given effect.
36 37 38 39 40 41 42 |
# File 'documented/gemstone/effects.rb', line 36 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) ⇒ Integer
Calculates the time left for a given effect.
54 55 56 57 58 59 60 |
# File 'documented/gemstone/effects.rb', line 54 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 registry to a hash representation.
22 23 24 |
# File 'documented/gemstone/effects.rb', line 22 def to_h XMLData.dialogs.fetch(@dialog, {}) end |