Class: Lich::Gemstone::SpellRanks

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

Overview

Represents the spell ranks for various classes in the Lich project.

This class manages loading and saving spell rank data.

See Also:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ void

Initializes a new SpellRanks object with the given name.

Parameters:

  • name (String) —

    the name of the spell rank



97
98
99
100
101
102
# File 'documented/gemstone/spellranks.rb', line 97

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

#arcanesymbols ⇒ Object

Returns the value of attribute arcanesymbols.



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

def arcanesymbols
  @arcanesymbols
end

#bard ⇒ Object

Returns the value of attribute bard.



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

def bard
  @bard
end

#cleric ⇒ Object

Returns the value of attribute cleric.



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

def cleric
  @cleric
end

#empath ⇒ Object

Returns the value of attribute empath.



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

def empath
  @empath
end

#magicitemuse ⇒ Object

Returns the value of attribute magicitemuse.



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

def magicitemuse
  @magicitemuse
end

#majorelemental ⇒ Object

Returns the value of attribute majorelemental.



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

def majorelemental
  @majorelemental
end

#majorspiritual ⇒ Object

Returns the value of attribute majorspiritual.



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

def majorspiritual
  @majorspiritual
end

#minorelemental ⇒ Object

Returns the value of attribute minorelemental.



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

def minorelemental
  @minorelemental
end

#minormental ⇒ Object

Returns the value of attribute minormental.



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

def minormental
  @minormental
end

#minorspiritual ⇒ Object

Returns the value of attribute minorspiritual.



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

def minorspiritual
  @minorspiritual
end

#monk ⇒ Object

Returns the value of attribute monk.



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

def monk
  @monk
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



13
14
15
# File 'documented/gemstone/spellranks.rb', line 13

def name
  @name
end

#paladin ⇒ Object

Returns the value of attribute paladin.



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

def paladin
  @paladin
end

#ranger ⇒ Object

Returns the value of attribute ranger.



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

def ranger
  @ranger
end

#sorcerer ⇒ Object

Returns the value of attribute sorcerer.



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

def sorcerer
  @sorcerer
end

#wizard ⇒ Object

Returns the value of attribute wizard.



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

def wizard
  @wizard
end

Class Method Details

.[](name) ⇒ Object?

Finds a spell rank by name.

Parameters:

  • name (String) —

    the name of the spell rank to find

Returns:

  • (Object, nil) —

    the spell rank object or nil if not found



74
75
76
77
# File 'documented/gemstone/spellranks.rb', line 74

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

.list ⇒ Array<Object>

Retrieves the list of all spell ranks.

Returns:

  • (Array<Object>) —

    an array of all spell rank objects



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

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

.load ⇒ void

This method returns an undefined value.

Loads the spell ranks from a data file.

Raises:

  • (StandardError) —

    if there is an error loading the data



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'documented/gemstone/spellranks.rb', line 19

def self.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



89
90
91
92
# File 'documented/gemstone/spellranks.rb', line 89

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

.save ⇒ void

This method returns an undefined value.

Saves the current spell ranks to a data file.

Raises:

  • (StandardError) —

    if there is an error saving the data



45
46
47
48
49
50
51
52
53
54
# File 'documented/gemstone/spellranks.rb', line 45

def self.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

.timestamp ⇒ Integer

Retrieves the current timestamp for the spell ranks.

Returns:

  • (Integer) —

    the timestamp of the last load



58
59
60
61
# File 'documented/gemstone/spellranks.rb', line 58

def self.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



66
67
68
69
# File 'documented/gemstone/spellranks.rb', line 66

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