Module: Lich::Gemstone::CritRanks
- Defined in:
- documented/gemstone/critranks.rb
Overview
Handles critical ranks for the Gemstone game.
This module manages critical hit tables and related data.
Class Method Summary collapse
-
.clean_key(key) ⇒ String, Integer
Cleans and normalizes the provided key for consistency.
-
.create_indices ⇒ void
Creates indices for types, locations, and ranks from the critical table.
-
.fetch(type, location, rank) ⇒ Hash?
Fetches the critical rank data for the specified type, location, and rank.
-
.init ⇒ void
Initializes the critical ranks module by loading critical tables.
-
.locations ⇒ Array<String>
Returns the locations associated with critical ranks.
-
.parse(line) ⇒ Hash
Parses a line of text and matches it against the critical rank indices.
-
.ranks ⇒ Array<String>
Returns the ranks associated with critical hits.
-
.reload! ⇒ void
Reloads the critical table data.
-
.table ⇒ Hash
Returns the critical table data.
-
.tables ⇒ Array<String>
Returns an array of table names derived from types.
-
.types ⇒ Array<String>
Returns the types of critical ranks available.
-
.validate(key, valid) ⇒ String
Validates the provided key against a list of valid options.
Class Method Details
.clean_key(key) ⇒ String, Integer
Cleans and normalizes the provided key for consistency.
72 73 74 75 76 77 |
# File 'documented/gemstone/critranks.rb', line 72 def self.clean_key(key) return key.to_i if key.is_a?(Integer) || key =~ (/^\d+$/) return key.downcase if key.is_a?(Symbol) key.strip.downcase.gsub(/[ -]/, '_') end |
.create_indices ⇒ void
This method returns an undefined value.
Creates indices for types, locations, and ranks from the critical table.
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'documented/gemstone/critranks.rb', line 93 def self.create_indices @index_rx ||= {} @critical_table.each do |type, typedata| @types.append(type) typedata.each do |loc, locdata| @locations.append(loc) unless @locations.include?(loc) locdata.each do |rank, record| @ranks.append(rank) unless @ranks.include?(rank) @index_rx[record[:regex]] = record end end end end |
.fetch(type, location, rank) ⇒ Hash?
Fetches the critical rank data for the specified type, location, and rank.
122 123 124 125 126 127 128 129 130 |
# File 'documented/gemstone/critranks.rb', line 122 def self.fetch(type, location, rank) table.dig( validate(type, types), validate(location, locations), validate(rank, ranks) ) rescue StandardError => e Lich::Messaging.msg('error', "Error! #{e}") end |
.init ⇒ void
This method returns an undefined value.
Initializes the critical ranks module by loading critical tables.
20 21 22 23 24 25 26 |
# File 'documented/gemstone/critranks.rb', line 20 def self.init return unless @critical_table.empty? Dir.glob("#{File.join(LIB_DIR, "gemstone", "critranks", "*critical_table.rb")}").each do |file| require file end create_indices end |
.locations ⇒ Array<String>
Returns the locations associated with critical ranks.
59 60 61 |
# File 'documented/gemstone/critranks.rb', line 59 def self.locations @locations end |
.parse(line) ⇒ Hash
Parses a line of text and matches it against the critical rank indices.
110 111 112 113 114 |
# File 'documented/gemstone/critranks.rb', line 110 def self.parse(line) @index_rx.filter do |rx, _data| rx =~ line.strip # need to strip spaces to support anchored regex in tables end end |
.ranks ⇒ Array<String>
Returns the ranks associated with critical hits.
65 66 67 |
# File 'documented/gemstone/critranks.rb', line 65 def self.ranks @ranks end |
.reload! ⇒ void
This method returns an undefined value.
Reloads the critical table data.
36 37 38 39 |
# File 'documented/gemstone/critranks.rb', line 36 def self.reload! @critical_table = {} init end |
.table ⇒ Hash
Returns the critical table data.
30 31 32 |
# File 'documented/gemstone/critranks.rb', line 30 def self.table @critical_table end |
.tables ⇒ Array<String>
Returns an array of table names derived from types.
43 44 45 46 47 48 49 |
# File 'documented/gemstone/critranks.rb', line 43 def self.tables @tables = [] @types.each do |type| @tables.push(type.to_s.gsub(':', '')) end @tables end |
.types ⇒ Array<String>
Returns the types of critical ranks available.
53 54 55 |
# File 'documented/gemstone/critranks.rb', line 53 def self.types @types end |
.validate(key, valid) ⇒ String
Validates the provided key against a list of valid options.
84 85 86 87 88 89 |
# File 'documented/gemstone/critranks.rb', line 84 def self.validate(key, valid) clean = clean_key(key) raise "Invalid key '#{key}', expecting one of #{valid.join(',')}" unless valid.include?(clean) clean end |