Class: Lich::Gemstone::SpellRanks

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

Overview

Represents the ranks of spells available in the game.

This class handles loading and saving spell rank data, as well as providing access to individual spell ranks and their properties.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ void

Note:

This method will load the spell ranks if they have not been loaded yet.

Initializes a new instance of the SpellRanks class.

Examples:

spell_rank = SpellRanks.new("Fireball")

Parameters:

  • name (String)

    the name of the spell rank.



127
128
129
130
131
132
# File 'lib/gemstone/spellranks.rb', line 127

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

Returns the value of attribute arcanesymbols.



15
16
17
# File 'lib/gemstone/spellranks.rb', line 15

def arcanesymbols
  @arcanesymbols
end

#bardObject

Returns the value of attribute bard.



15
16
17
# File 'lib/gemstone/spellranks.rb', line 15

def bard
  @bard
end

#clericObject

Returns the value of attribute cleric.



15
16
17
# File 'lib/gemstone/spellranks.rb', line 15

def cleric
  @cleric
end

#empathObject

Returns the value of attribute empath.



15
16
17
# File 'lib/gemstone/spellranks.rb', line 15

def empath
  @empath
end

#magicitemuseObject

Returns the value of attribute magicitemuse.



15
16
17
# File 'lib/gemstone/spellranks.rb', line 15

def magicitemuse
  @magicitemuse
end

#majorelementalObject

Returns the value of attribute majorelemental.



15
16
17
# File 'lib/gemstone/spellranks.rb', line 15

def majorelemental
  @majorelemental
end

#majorspiritualObject

Returns the value of attribute majorspiritual.



15
16
17
# File 'lib/gemstone/spellranks.rb', line 15

def majorspiritual
  @majorspiritual
end

#minorelementalObject

Returns the value of attribute minorelemental.



15
16
17
# File 'lib/gemstone/spellranks.rb', line 15

def minorelemental
  @minorelemental
end

#minormentalObject

Returns the value of attribute minormental.



15
16
17
# File 'lib/gemstone/spellranks.rb', line 15

def minormental
  @minormental
end

#minorspiritualObject

Returns the value of attribute minorspiritual.



15
16
17
# File 'lib/gemstone/spellranks.rb', line 15

def minorspiritual
  @minorspiritual
end

#monkObject

Returns the value of attribute monk.



15
16
17
# File 'lib/gemstone/spellranks.rb', line 15

def monk
  @monk
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/gemstone/spellranks.rb', line 14

def name
  @name
end

#paladinObject

Returns the value of attribute paladin.



15
16
17
# File 'lib/gemstone/spellranks.rb', line 15

def paladin
  @paladin
end

#rangerObject

Returns the value of attribute ranger.



15
16
17
# File 'lib/gemstone/spellranks.rb', line 15

def ranger
  @ranger
end

#sorcererObject

Returns the value of attribute sorcerer.



15
16
17
# File 'lib/gemstone/spellranks.rb', line 15

def sorcerer
  @sorcerer
end

#wizardObject

Returns the value of attribute wizard.



15
16
17
# File 'lib/gemstone/spellranks.rb', line 15

def wizard
  @wizard
end

Class Method Details

.[](name) ⇒ SpellRanks?

Note:

This method will load the spell ranks if they have not been loaded yet.

Finds a spell rank by its name.

Examples:

rank = SpellRanks["Fireball"]

Parameters:

  • name (String)

    the name of the spell rank to find.

Returns:

  • (SpellRanks, nil)

    the spell rank object if found, otherwise nil.



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

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

.listArray<SpellRanks>

Note:

This method will load the spell ranks if they have not been loaded yet.

Retrieves the list of all spell ranks.

Examples:

ranks = SpellRanks.list

Returns:

  • (Array<SpellRanks>)

    the list of all spell ranks.



104
105
106
107
# File 'lib/gemstone/spellranks.rb', line 104

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:

SpellRanks.load

Raises:

  • (StandardError)

    if there is an error reading the file.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gemstone/spellranks.rb', line 23

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.

Examples:

SpellRanks.some_undefined_method

Parameters:

  • arg (Symbol, String) (defaults to: nil)

    the name of the method that was called.



115
116
117
118
# File 'lib/gemstone/spellranks.rb', line 115

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:

SpellRanks.save

Raises:

  • (StandardError)

    if there is an error writing to the file.



52
53
54
55
56
57
58
59
60
61
# File 'lib/gemstone/spellranks.rb', line 52

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

Note:

This method will load the spell ranks if they have not been loaded yet.

Retrieves the timestamp of the last load operation.

Examples:

timestamp = SpellRanks.timestamp

Returns:

  • (Integer)

    the timestamp of the last load operation.



69
70
71
72
# File 'lib/gemstone/spellranks.rb', line 69

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

.timestamp=(val) ⇒ void

Note:

This method will load the spell ranks if they have not been loaded yet.

This method returns an undefined value.

Sets the timestamp for the last load operation.

Examples:

SpellRanks.timestamp = Time.now.to_i

Parameters:

  • val (Integer)

    the new timestamp value.



81
82
83
84
# File 'lib/gemstone/spellranks.rb', line 81

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