Class: Lich::Gemstone::SpellRanks
- Inherits:
-
Object
- Object
- Lich::Gemstone::SpellRanks
- 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
-
#arcanesymbols ⇒ Object
Returns the value of attribute arcanesymbols.
-
#bard ⇒ Object
Returns the value of attribute bard.
-
#cleric ⇒ Object
Returns the value of attribute cleric.
-
#empath ⇒ Object
Returns the value of attribute empath.
-
#magicitemuse ⇒ Object
Returns the value of attribute magicitemuse.
-
#majorelemental ⇒ Object
Returns the value of attribute majorelemental.
-
#majorspiritual ⇒ Object
Returns the value of attribute majorspiritual.
-
#minorelemental ⇒ Object
Returns the value of attribute minorelemental.
-
#minormental ⇒ Object
Returns the value of attribute minormental.
-
#minorspiritual ⇒ Object
Returns the value of attribute minorspiritual.
-
#monk ⇒ Object
Returns the value of attribute monk.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#paladin ⇒ Object
Returns the value of attribute paladin.
-
#ranger ⇒ Object
Returns the value of attribute ranger.
-
#sorcerer ⇒ Object
Returns the value of attribute sorcerer.
-
#wizard ⇒ Object
Returns the value of attribute wizard.
Class Method Summary collapse
-
.[](name) ⇒ SpellRanks?
Finds a spell rank by its name.
-
.list ⇒ Array<SpellRanks>
Retrieves the list of all spell ranks.
-
.load ⇒ void
Loads the spell ranks from a data file.
-
.method_missing(arg = nil) ⇒ void
Handles calls to undefined methods for the SpellRanks class.
-
.save ⇒ void
Saves the current spell ranks to a data file.
-
.timestamp ⇒ Integer
Retrieves the timestamp of the last load operation.
-
.timestamp=(val) ⇒ void
Sets the timestamp for the last load operation.
Instance Method Summary collapse
-
#initialize(name) ⇒ void
constructor
Initializes a new instance of the SpellRanks class.
Constructor Details
#initialize(name) ⇒ void
This method will load the spell ranks if they have not been loaded yet.
Initializes a new instance of the SpellRanks class.
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
#arcanesymbols ⇒ Object
Returns the value of attribute arcanesymbols.
15 16 17 |
# File 'lib/gemstone/spellranks.rb', line 15 def arcanesymbols @arcanesymbols end |
#bard ⇒ Object
Returns the value of attribute bard.
15 16 17 |
# File 'lib/gemstone/spellranks.rb', line 15 def @bard end |
#cleric ⇒ Object
Returns the value of attribute cleric.
15 16 17 |
# File 'lib/gemstone/spellranks.rb', line 15 def cleric @cleric end |
#empath ⇒ Object
Returns the value of attribute empath.
15 16 17 |
# File 'lib/gemstone/spellranks.rb', line 15 def empath @empath end |
#magicitemuse ⇒ Object
Returns the value of attribute magicitemuse.
15 16 17 |
# File 'lib/gemstone/spellranks.rb', line 15 def magicitemuse @magicitemuse end |
#majorelemental ⇒ Object
Returns the value of attribute majorelemental.
15 16 17 |
# File 'lib/gemstone/spellranks.rb', line 15 def majorelemental @majorelemental end |
#majorspiritual ⇒ Object
Returns the value of attribute majorspiritual.
15 16 17 |
# File 'lib/gemstone/spellranks.rb', line 15 def majorspiritual @majorspiritual end |
#minorelemental ⇒ Object
Returns the value of attribute minorelemental.
15 16 17 |
# File 'lib/gemstone/spellranks.rb', line 15 def minorelemental @minorelemental end |
#minormental ⇒ Object
Returns the value of attribute minormental.
15 16 17 |
# File 'lib/gemstone/spellranks.rb', line 15 def minormental @minormental end |
#minorspiritual ⇒ Object
Returns the value of attribute minorspiritual.
15 16 17 |
# File 'lib/gemstone/spellranks.rb', line 15 def minorspiritual @minorspiritual end |
#monk ⇒ Object
Returns the value of attribute monk.
15 16 17 |
# File 'lib/gemstone/spellranks.rb', line 15 def monk @monk end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/gemstone/spellranks.rb', line 14 def name @name end |
#paladin ⇒ Object
Returns the value of attribute paladin.
15 16 17 |
# File 'lib/gemstone/spellranks.rb', line 15 def paladin @paladin end |
#ranger ⇒ Object
Returns the value of attribute ranger.
15 16 17 |
# File 'lib/gemstone/spellranks.rb', line 15 def ranger @ranger end |
#sorcerer ⇒ Object
Returns the value of attribute sorcerer.
15 16 17 |
# File 'lib/gemstone/spellranks.rb', line 15 def sorcerer @sorcerer end |
#wizard ⇒ Object
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?
This method will load the spell ranks if they have not been loaded yet.
Finds a spell rank by its name.
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 |
.list ⇒ Array<SpellRanks>
This method will load the spell ranks if they have not been loaded yet.
Retrieves 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 |
.load ⇒ void
This method returns an undefined value.
Loads the spell ranks from a data 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.
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 |
.save ⇒ void
This method returns an undefined value.
Saves the current spell ranks to a data 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 |
.timestamp ⇒ Integer
This method will load the spell ranks if they have not been loaded yet.
Retrieves the timestamp of the last load operation.
69 70 71 72 |
# File 'lib/gemstone/spellranks.rb', line 69 def SpellRanks. SpellRanks.load unless @@loaded @@timestamp end |
.timestamp=(val) ⇒ void
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.
81 82 83 84 |
# File 'lib/gemstone/spellranks.rb', line 81 def SpellRanks.(val) SpellRanks.load unless @@loaded @@timestamp = val end |