Module: Lich::Gemstone::SK

Defined in:
lib/gemstone/sk.rb

Class Method Summary collapse

Class Method Details

.add(*numbers) ⇒ void

This method returns an undefined value.

Adds one or more spell numbers to the list of known SK spells.

Examples:

Lich::Gemstone::SK.add("1", "2")

Parameters:

  • numbers (Array<String>)

    the spell numbers to add.



85
86
87
88
# File 'lib/gemstone/sk.rb', line 85

def self.add(*numbers)
  self.sk_known = (@sk_known + numbers).uniq
  self.list
end

.helpvoid

This method returns an undefined value.

Provides help information for SK spell commands.

Examples:

Lich::Gemstone::SK.help


69
70
71
72
73
74
75
76
77
# File 'lib/gemstone/sk.rb', line 69

def self.help
  respond "   Script to add SK spells to be known and used with Spell API calls."
  respond ""
  respond "   ;sk add <SPELL_NUMBER>  - Add spell number to saved list"
  respond "   ;sk rm <SPELL_NUMBER>   - Remove spell number from saved list"
  respond "   ;sk list                - Show all currently saved SK spell numbers"
  respond "   ;sk help                - Show this menu"
  respond ""
end

.known?(spell) ⇒ Boolean

Checks if a specific spell is known.

Examples:

is_known = Lich::Gemstone::SK.known?(some_spell)

Parameters:

  • spell (Object)

    the spell object to check.

Returns:

  • (Boolean)

    true if the spell is known, false otherwise.

Raises:

  • (NoMethodError)

    if spell does not respond to ‘num`.



49
50
51
52
# File 'lib/gemstone/sk.rb', line 49

def self.known?(spell)
  self.sk_known if @sk_known.nil?
  @sk_known.include?(spell.num.to_s)
end

.listvoid

This method returns an undefined value.

Lists the current known SK spells.

Examples:

Lich::Gemstone::SK.list


59
60
61
62
# File 'lib/gemstone/sk.rb', line 59

def self.list
  respond "Current SK Spells: #{@sk_known.inspect}"
  respond ""
end

.main(action = help, spells = nil) ⇒ void

This method returns an undefined value.

Main entry point for SK spell commands.

Examples:

Lich::Gemstone::SK.main(:add, "1 2")

Parameters:

  • action (Symbol) (defaults to: help)

    the action to perform (add, rm, list, help).

  • spells (String, nil) (defaults to: nil)

    the spell numbers to process (if applicable).



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/gemstone/sk.rb', line 108

def self.main(action = help, spells = nil)
  self.sk_known if @sk_known.nil?
  action = action.to_sym
  spells = spells.split(" ").uniq
  case action
  when :add
    self.add(*spells) unless spells.empty?
    self.help if spells.empty?
  when :rm
    self.remove(*spells) unless spells.empty?
    self.help if spells.empty?
  when :list
    self.list
  else
    self.help
  end
end

.remove(*numbers) ⇒ void

This method returns an undefined value.

Removes one or more spell numbers from the list of known SK spells.

Examples:

Lich::Gemstone::SK.remove("1")

Parameters:

  • numbers (Array<String>)

    the spell numbers to remove.



96
97
98
99
# File 'lib/gemstone/sk.rb', line 96

def self.remove(*numbers)
  self.sk_known = (@sk_known - numbers).uniq
  self.list
end

.sk_knownArray<String>

Note:

If the known spells are not set, it attempts to read from the database.

Retrieves the list of known SK spells.

Examples:

known_spells = Lich::Gemstone::SK.sk_known

Returns:

  • (Array<String>)

    the list of known SK spell numbers as strings.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gemstone/sk.rb', line 12

def self.sk_known
  if @sk_known.nil?
    val = DB_Store.read("#{XMLData.game}:#{XMLData.name}", "sk_known")
    if val.nil? || (val.class == Hash && val.empty?)
      old_settings = DB_Store.read("#{XMLData.game}:#{XMLData.name}", "vars")["sk/known"]
      if old_settings.class == Array
        val = old_settings
      else
        val = []
      end
      self.sk_known = val
    end
    @sk_known = val unless val.nil?
  end
  return @sk_known
end

.sk_known=(val) ⇒ Array<String>

Note:

This method saves the new list to the database.

Sets the list of known SK spells.

Examples:

Lich::Gemstone::SK.sk_known = ["1", "2", "3"]

Parameters:

  • val (Array<String>)

    the new list of known SK spell numbers.

Returns:

  • (Array<String>)

    the updated list of known SK spell numbers.



36
37
38
39
40
# File 'lib/gemstone/sk.rb', line 36

def self.sk_known=(val)
  return @sk_known if @sk_known == val
  DB_Store.save("#{XMLData.game}:#{XMLData.name}", "sk_known", val)
  @sk_known = val
end