Class: Lich::Gemstone::SpellRanks

Inherits:
Object
  • Object
show all
Defined in:
documented/gemstone/spellranks.rb

Overview

Represents the spell ranks in the Lich5 project. This class handles loading, saving, and managing spell rank data.

Examples:

Loading spell ranks

SpellRanks.load

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ void

Initializes a new SpellRanks object with a name.

Parameters:

  • name (String)

    The name of the spell rank.



109
110
111
112
113
114
# File 'documented/gemstone/spellranks.rb', line 109

def initialize(name)
  SpellRanks.load unless @@loaded
  @name = name
  @minorspiritual, @majorspiritual, @cleric, @minorelemental, @majorelemental, @ranger, @sorcerer, @wizard, @bard, @empath, @paladin, @minormental, @arcanesymbols, @magicitemuse = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  @@list.push(self)
end

Instance Attribute Details

#arcanesymbolsObject

Accessors for various spell rank attributes.



20
21
22
# File 'documented/gemstone/spellranks.rb', line 20

def arcanesymbols
  @arcanesymbols
end

#bardObject

Accessors for various spell rank attributes.



20
21
22
# File 'documented/gemstone/spellranks.rb', line 20

def bard
  @bard
end

#clericObject

Accessors for various spell rank attributes.



20
21
22
# File 'documented/gemstone/spellranks.rb', line 20

def cleric
  @cleric
end

#empathObject

Accessors for various spell rank attributes.



20
21
22
# File 'documented/gemstone/spellranks.rb', line 20

def empath
  @empath
end

#magicitemuseObject

Accessors for various spell rank attributes.



20
21
22
# File 'documented/gemstone/spellranks.rb', line 20

def magicitemuse
  @magicitemuse
end

#majorelementalObject

Accessors for various spell rank attributes.



20
21
22
# File 'documented/gemstone/spellranks.rb', line 20

def majorelemental
  @majorelemental
end

#majorspiritualObject

Accessors for various spell rank attributes.



20
21
22
# File 'documented/gemstone/spellranks.rb', line 20

def majorspiritual
  @majorspiritual
end

#minorelementalObject

Accessors for various spell rank attributes.



20
21
22
# File 'documented/gemstone/spellranks.rb', line 20

def minorelemental
  @minorelemental
end

#minormentalObject

Accessors for various spell rank attributes.



20
21
22
# File 'documented/gemstone/spellranks.rb', line 20

def minormental
  @minormental
end

#minorspiritualObject

Accessors for various spell rank attributes.



20
21
22
# File 'documented/gemstone/spellranks.rb', line 20

def minorspiritual
  @minorspiritual
end

#monkObject

Accessors for various spell rank attributes.



20
21
22
# File 'documented/gemstone/spellranks.rb', line 20

def monk
  @monk
end

#nameObject (readonly)

The name of the spell rank.



18
19
20
# File 'documented/gemstone/spellranks.rb', line 18

def name
  @name
end

#paladinObject

Accessors for various spell rank attributes.



20
21
22
# File 'documented/gemstone/spellranks.rb', line 20

def paladin
  @paladin
end

#rangerObject

Accessors for various spell rank attributes.



20
21
22
# File 'documented/gemstone/spellranks.rb', line 20

def ranger
  @ranger
end

#sorcererObject

Accessors for various spell rank attributes.



20
21
22
# File 'documented/gemstone/spellranks.rb', line 20

def sorcerer
  @sorcerer
end

#wizardObject

Accessors for various spell rank attributes.



20
21
22
# File 'documented/gemstone/spellranks.rb', line 20

def wizard
  @wizard
end

Class Method Details

.[](name) ⇒ SpellRanks?

Finds a spell rank by name.

Examples:

Finding a spell rank

rank = SpellRanks["Fireball"]

Parameters:

  • name (String)

    The name of the spell rank to find.

Returns:

  • (SpellRanks, nil)

    the found spell rank or nil if not found.



86
87
88
89
# File 'documented/gemstone/spellranks.rb', line 86

def SpellRanks.[](name)
  SpellRanks.load unless @@loaded
  @@list.find { |n| n.name == name }
end

.listArray<SpellRanks>

Retrieves the list of all spell ranks.

Returns:

  • (Array<SpellRanks>)

    an array of all spell ranks.



93
94
95
96
# File 'documented/gemstone/spellranks.rb', line 93

def SpellRanks.list
  SpellRanks.load unless @@loaded
  @@list
end

.loadvoid

This method returns an undefined value.

Loads the spell ranks from a data file.

Examples:

Loading spell ranks

SpellRanks.load

Raises:

  • (StandardError)

    if there is an error loading the data.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'documented/gemstone/spellranks.rb', line 27

def SpellRanks.load
  if File.exist?(File.join(DATA_DIR, "#{XMLData.game}", "spell-ranks.dat"))
    begin
      File.open(File.join(DATA_DIR, "#{XMLData.game}", "spell-ranks.dat"), 'rb') { |f|
        @@timestamp, @@list = Marshal.load(f.read)
      }
      # minor mental circle added 2012-07-18; old data files will have @minormental as nil
      @@list.each { |rank_info| rank_info.minormental ||= 0 }
      # monk circle added 2013-01-15; old data files will have @minormental as nil
      @@list.each { |rank_info| rank_info.monk ||= 0 }
      @@loaded = true
    rescue
      respond "--- Lich: error: SpellRanks.load: #{$!}"
      Lich.log "error: SpellRanks.load: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
      @@list      = Array.new
      @@timestamp = 0
      @@loaded = true
    end
  else
    @@loaded = true
  end
end

.method_missing(arg = nil) ⇒ void

This method returns an undefined value.

Handles calls to undefined methods for the SpellRanks class.

Parameters:

  • arg (Symbol) (defaults to: nil)

    The name of the method that was called.



101
102
103
104
# File 'documented/gemstone/spellranks.rb', line 101

def SpellRanks.method_missing(arg = nil)
  echo "error: unknown method #{arg} for class SpellRanks"
  respond caller[0..1]
end

.savevoid

This method returns an undefined value.

Saves the current spell ranks to a data file.

Examples:

Saving spell ranks

SpellRanks.save

Raises:

  • (StandardError)

    if there is an error saving the data.



55
56
57
58
59
60
61
62
63
64
# File 'documented/gemstone/spellranks.rb', line 55

def SpellRanks.save
  begin
    File.open(File.join(DATA_DIR, "#{XMLData.game}", "spell-ranks.dat"), 'wb') { |f|
      f.write(Marshal.dump([@@timestamp, @@list]))
    }
  rescue
    respond "--- Lich: error: SpellRanks.save: #{$!}"
    Lich.log "error: SpellRanks.save: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
  end
end

.timestampInteger

Retrieves the current timestamp for the spell ranks.

Returns:

  • (Integer)

    the current timestamp.



68
69
70
71
# File 'documented/gemstone/spellranks.rb', line 68

def SpellRanks.timestamp
  SpellRanks.load unless @@loaded
  @@timestamp
end

.timestamp=(val) ⇒ void

This method returns an undefined value.

Sets the timestamp for the spell ranks.

Parameters:

  • val (Integer)

    The new timestamp value.



76
77
78
79
# File 'documented/gemstone/spellranks.rb', line 76

def SpellRanks.timestamp=(val)
  SpellRanks.load unless @@loaded
  @@timestamp = val
end