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

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

Constructor Details

#initialize(dialog) ⇒ void

Initializes a new Registry instance.

Parameters:

  • dialog (String)

    the name of the dialog associated with this registry



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.

Parameters:

  • effect (String, Regexp)

    the effect to check

Returns:

  • (Boolean)

    true if the effect is active, false otherwise



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.

Yields:

  • (key, value)

    each key-value pair in the effects hash



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.

Parameters:

  • effect (String, Regexp)

    the effect to check for expiration

Returns:

  • (Integer)

    the expiration time in seconds since epoch, or 0 if not found



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.

Parameters:

  • effect (String, Regexp)

    the effect to check

Returns:

  • (Integer)

    the time left in minutes, or the expiration time if not active



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_hHash

Converts the registry to a hash representation.

Returns:

  • (Hash)

    a hash containing the effects associated with the dialog



22
23
24
# File 'documented/gemstone/effects.rb', line 22

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