Module: Lich::Gemstone::Armaments::ShieldStats

Defined in:
documented/gemstone/armaments/shield_stats.rb

Constant Summary collapse

@@shield_stats =

Static array of shield stats indexed by shield identifiers. Each shield entry contains metadata such as category, alternative names, size and evade modifiers, and base weight. Static array of shield stats indexed by shield identifiers. Each shield entry contains metadata such as category, alternative names, size and evade modifiers, and base weight.

{
  :small_shield  => {
    :category       => :small_shield,
    :base_name      => "small shield",
    :all_names      => ["buckler", "kidney shield", "small shield", "targe"],
    :size_modifier  => -0.15,
    :evade_modifier => -0.22,
    :base_weight    => 6,
  },
  :medium_shield => {
    :category       => :medium_shield,
    :base_name      => "medium shield",
    :all_names      => ["battle shield", "heater", "heater shield", "knight's shield", "krytze", "lantern shield", "medium shield", "parma", "target shield"],
    :size_modifier  => 0.0,
    :evade_modifier => -0.30,
    :base_weight    => 8,
  },
  :large_shield  => {
    :category       => :large_shield,
    :base_name      => "large shield",
    :all_names      => ["aegis", "kite shield", "large shield", "pageant shield", "round shield", "scutum"],
    :size_modifier  => 0.15,
    :evade_modifier => -0.38,
    :base_weight    => 9,
  },
  :tower_shield  => {
    :category       => :tower_shield,
    :base_name      => "tower shield",
    :all_names      => ["greatshield", "mantlet", "pavis", "tower shield", "wall shield"],
    :size_modifier  => 0.30,
    :evade_modifier => -0.50,
    :base_weight    => 12,
  },
}

Class Method Summary collapse

Class Method Details

.aliases_for(name) ⇒ Array<String>

Retrieves all alternative names for a given shield.

Parameters:

  • name (String)

    the name of the shield

Returns:

  • (Array<String>)

    an array of alternative names



152
153
154
155
156
# File 'documented/gemstone/armaments/shield_stats.rb', line 152

def self.aliases_for(name)
  name = name.downcase.strip
  shield = self.find(name)
  shield ? shield[:all_names] : []
end

.categoriesArray<Symbol>

Returns a list of all shield categories.

Returns:

  • (Array<Symbol>)

    an array of shield categories



92
93
94
# File 'documented/gemstone/armaments/shield_stats.rb', line 92

def self.categories
  @@shield_stats.keys
end

.category_for(name) ⇒ Symbol?

Retrieves the category for a given shield name.

Parameters:

  • name (String)

    the name of the shield

Returns:

  • (Symbol, nil)

    the category of the shield if found, otherwise nil



100
101
102
103
104
105
# File 'documented/gemstone/armaments/shield_stats.rb', line 100

def self.category_for(name)
  name = name.downcase.strip

  shield = self.find(name)
  shield ? shield[:category] : nil
end

.compare(name1, name2) ⇒ Hash?

Compares two shields by their names and returns their attributes.

Parameters:

  • name1 (String)

    the name of the first shield

  • name2 (String)

    the name of the second shield

Returns:

  • (Hash, nil)

    a hash containing the comparison data if both shields are found, otherwise nil



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'documented/gemstone/armaments/shield_stats.rb', line 163

def self.compare(name1, name2)
  name1 = name1.downcase.strip
  name2 = name2.downcase.strip

  s1 = find(name1)
  s2 = find(name2)
  return nil unless s1 && s2

  {
    name1: s1[:base_name],
    name2: s2[:base_name],
    size_modifier: [s1[:size_modifier], s2[:size_modifier]],
    evade_modifier: [s1[:evade_modifier], s2[:evade_modifier]],
    base_weight: [s1[:base_weight], s2[:base_weight]],
    category: [s1[:category], s2[:category]],
    aliases: [s1[:all_names], s2[:all_names]]
  }
end

.find(name) ⇒ Hash?

Finds a shield by its name.

Parameters:

  • name (String)

    the name of the shield to find

Returns:

  • (Hash, nil)

    the shield information if found, otherwise nil



68
69
70
71
72
73
74
75
76
# File 'documented/gemstone/armaments/shield_stats.rb', line 68

def self.find(name)
  name = name.downcase.strip

  @@shield_stats.each_value do |shield|
    return shield if shield[:all_names]&.map(&:downcase)&.include?(name)
  end

  nil
end

.find_by_category(category) ⇒ Hash?

Finds shield information by category.

Parameters:

  • category (Symbol)

    the category of the shield to find

Returns:

  • (Hash, nil)

    the shield information if found, otherwise nil



52
53
54
55
# File 'documented/gemstone/armaments/shield_stats.rb', line 52

def self.find_by_category(category)
  _, shield_info = @@shield_stats.find { |_, stats| stats[:category] == category }
  shield_info
end

.list_shields_by_evade_modifier(min:, max:) ⇒ Array<Hash>

Lists shields within a specified evade modifier range.

Parameters:

  • min (Float)

    the minimum evade modifier

  • max (Float)

    the maximum evade modifier

Returns:

  • (Array<Hash>)

    an array of shields that match the criteria



83
84
85
86
87
# File 'documented/gemstone/armaments/shield_stats.rb', line 83

def self.list_shields_by_evade_modifier(min:, max:)
  @@shield_stats.map(&:last).select do |shield|
    shield[:evade_modifier].between?(min, max)
  end
end

.namesArray<String>

Returns a unique list of all shield names.

Returns:

  • (Array<String>)

    an array of unique shield names



60
61
62
# File 'documented/gemstone/armaments/shield_stats.rb', line 60

def self.names
  @@shield_stats.map { |_, s| s[:all_names] }.flatten.uniq
end

.pretty(name) ⇒ String

Returns a formatted string representation of the shield's details.

Parameters:

  • name (String)

    the name of the shield

Returns:

  • (String)

    a formatted string with shield details



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'documented/gemstone/armaments/shield_stats.rb', line 111

def self.pretty(name)
  shield = self.find(name)
  return "\n(no data)\n" unless shield.is_a?(Hash)

  lines = []
  lines << ""

  fields = {
    "Shield"      => shield[:base_name],
    "Category"    => shield[:category].to_s.gsub('_', ' ').capitalize,
    "Size Mod"    => format('%.2f', shield[:size_modifier]),
    "Evade Mod"   => format('%.2f', shield[:evade_modifier]),
    "Base Weight" => "#{shield[:base_weight]} lbs"
  }

  max_label = fields.keys.map(&:length).max

  fields.each do |label, value|
    lines << "%-#{max_label}s: %s" % [label, value]
  end

  if shield[:all_names]&.any?
    lines << "%-#{max_label}s: %s" % ["Alternate", shield[:all_names].join(", ")]
  end

  lines << ""
  lines.join("\n")
end

.pretty_long(name) ⇒ String

Returns a detailed formatted string representation of the shield's details.

Parameters:

  • name (String)

    the name of the shield

Returns:

  • (String)

    a formatted string with shield details



144
145
146
# File 'documented/gemstone/armaments/shield_stats.rb', line 144

def self.pretty_long(name)
  pretty(name)
end

.search(filters = {}) ⇒ Array<Hash>

Searches for shields based on various filters.

Parameters:

  • filters (Hash) (defaults to: {})

    a hash of filters to apply

Returns:

  • (Array<Hash>)

    an array of shields that match the filters



186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'documented/gemstone/armaments/shield_stats.rb', line 186

def self.search(filters = {})
  @@shield_stats.values.select do |shield|
    next if filters[:name] && !shield[:all_names].include?(filters[:name].downcase.strip)
    next if filters[:category] && shield[:category] != filters[:category]
    next if filters[:min_evade_modifier] && shield[:evade_modifier] < filters[:min_evade_modifier]
    next if filters[:max_evade_modifier] && shield[:evade_modifier] > filters[:max_evade_modifier]
    next if filters[:min_size_modifier] && shield[:size_modifier] < filters[:min_size_modifier]
    next if filters[:max_size_modifier] && shield[:size_modifier] > filters[:max_size_modifier]
    next if filters[:max_weight] && shield[:base_weight] > filters[:max_weight]

    true
  end
end

.valid_name?(name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Checks if a given name is a valid shield name.

Parameters:

  • name (String)

    the name to validate

Returns:

  • (Boolean)

    true if the name is valid, otherwise false



205
206
207
208
# File 'documented/gemstone/armaments/shield_stats.rb', line 205

def self.valid_name?(name)
  name = name.downcase.strip
  self.names.include?(name)
end