Class: Lich::Gemstone::Effects::Registry

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(dialog) ⇒ Registry

Initializes a new Registry instance.

Parameters:

  • dialog (String)

    the name of the dialog to fetch effects from.



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.

Parameters:

  • effect (String)

    the effect to check.

Returns:

  • (Boolean)

    true if the effect is active, false otherwise.



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.

Yields:

  • (k, v)

    yields each key-value pair of effects.



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.

Parameters:

  • effect (String, Regexp)

    the effect to check for expiration.

Returns:

  • (Integer)

    the expiration time in seconds, or 0 if not found.



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.

Parameters:

  • effect (String)

    the effect to check.

Returns:

  • (Float)

    the time left in minutes, or the expiration time if it is 0.



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_hHash

Converts the effects in the registry to a hash.

Returns:

  • (Hash)

    a hash representation of the effects.



18
19
20
# File 'lib/gemstone/effects.rb', line 18

def to_h
  XMLData.dialogs.fetch(@dialog, {})
end