Class: Lich::Gemstone::Society

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

Overview

The Society class provides accessors for a character's society membership, rank, and task data.

All methods rely on Infomon or XMLData, and a future rewrite might shift responsibility to character-specific data models or direct game scraping.

Class Method Summary collapse

Class Method Details

.command(entry, prefix, target = nil) ⇒ String

The command a society ability's use sends, without sending it.

An entry with a :usage string sends that verb ("signal", "smite"); any other sends <prefix> <short_name> ("sign of striking"). A GameObj or Integer target is appended as #id, a String as given.

Parameters:

  • entry (Hash) —

    The resolved ability metadata (from the reader's [])

  • prefix (String) —

    "sign of", "sigil of" or "symbol of"

  • target (String, Integer, GameObj, nil) (defaults to: nil) —

    Optional target

Returns:

  • (String) —

    e.g. "symbol of holiness", "sigil of contact #12345"



150
151
152
153
154
155
# File 'documented/gemstone/society.rb', line 150

def self.command(entry, prefix, target = nil)
  base = entry[:usage] || "#{prefix} #{entry[:short_name]}"
  target = "##{target.id}" if target.respond_to?(:id) && !target.is_a?(String)
  target = "##{target}" if target.is_a?(Integer)
  "#{base} #{target}".strip
end

.define_name_methods(target_class, data) ⇒ Object

Defines singleton accessors for both short and long names on a given target class.

Method names are normalized using Util.normalize_name, which ensures compatibility with Ruby method naming (e.g., downcased, underscores instead of spaces, etc.).

Example:

"Symbol of Recognition" => `symbol_of_recognition`
"Kai's Strike"          => `kais_strike`

Parameters:

  • target_class (Class) —

    The class to define singleton methods on (typically self)

  • data (Hash<String, Hash>) —

    The metadata hash (e.g., @@voln_symbols)



170
171
172
173
174
175
176
177
178
# File 'documented/gemstone/society.rb', line 170

def self.define_name_methods(target_class, data)
  data.values.each do |entry|
    short_method = Lich::Util.normalize_name(entry[:short_name])
    long_method  = Lich::Util.normalize_name(entry[:long_name])

    target_class.define_singleton_method(short_method) { target_class[entry[:short_name]] }
    target_class.define_singleton_method(long_method)  { target_class[entry[:short_name]] }
  end
end

.favor ⇒ Integer

Deprecated.

Use OrderOfVoln.favor instead. Deprecated 6/2025

Returns The amount of Voln favor.

Returns:

  • (Integer) —

    The amount of Voln favor



95
96
97
98
99
# File 'documented/gemstone/society.rb', line 95

def self.favor
  Lich.deprecated("Society.favor", "Society::OrderOfVoln.favor", caller[0], fe_log: false)
  # Infomon.get('resources.voln_favor')
  Societies::OrderOfVoln.favor
end

.lookup(name, lookups) ⇒ Hash?

Looks up an ability definition from a society hash using a normalized short or long name.

Parameters:

  • name (String) —

    The user-facing name (short or long) of the ability

  • entries (Hash<String, Hash>) —

    The base hash keyed by short_name

  • lookups (Array<Hash>) —

    An array of hashes containing at least :short_name and :long_name

Returns:

  • (Hash, nil) —

    The matching entry from the base hash, or nil if not found



109
110
111
112
113
114
115
116
117
118
# File 'documented/gemstone/society.rb', line 109

def self.lookup(name, lookups)
  normalized = Lich::Util.normalize_name(name)

  lookups.find do |entry|
    [entry[:short_name], entry[:long_name]]
      .compact
      .map { |n| Lich::Util.normalize_name(n) }
      .include?(normalized)
  end
end

.member ⇒ String

Deprecated.

Use #member_of instead. Deprecated 6/2025

Returns The current society membership.

Returns:

  • (String) —

    The current society membership



77
78
79
80
# File 'documented/gemstone/society.rb', line 77

def self.member
  Lich.deprecated("Society.member", "Society.membership", caller[0], fe_log: false)
  self.membership
end

.membership ⇒ String?

Retrieves the character's society membership status.

Returns:

  • (String, nil) —

    The name of the society:

    • "Order of Voln"
    • "Council of Light"
    • "Guardians of Sunfist"
    • or nil/"None" if not a member


21
22
23
# File 'documented/gemstone/society.rb', line 21

def self.membership
  Infomon.get("society.status")
end

.rank ⇒ Integer

Retrieves the character's current rank within their society.

Returns:

  • (Integer) —

    The rank number, or 0 if not a member



41
42
43
# File 'documented/gemstone/society.rb', line 41

def self.rank
  Infomon.get("society.rank")
end

.resolve(value, context = nil) ⇒ Object

Resolves a value that may be a static literal or a lambda/proc.

If the value responds to :call (i.e., is a Proc or lambda), it is called and the result is returned. Otherwise, the value is returned as-is.

This allows society metadata fields such as :duration or :summary to be defined as either static values or dynamically evaluated lambdas.

Parameters:

  • value (Object, Proc) —

    The value to resolve

Returns:

  • (Object) —

    The resolved value, or the original value if not callable



132
133
134
135
136
# File 'documented/gemstone/society.rb', line 132

def self.resolve(value, context = nil)
  return value.call if value.respond_to?(:call) && value.arity == 0
  return value.call(context) if value.respond_to?(:call) && value.arity == 1
  value
end

.serialize ⇒ Array<(String, Integer)>

Bundles the current society status and rank into a simple structure.

Returns:

  • (Array<(String, Integer)>) —

    An array in the format [status, rank]



65
66
67
# File 'documented/gemstone/society.rb', line 65

def self.serialize
  [self.membership, self.rank]
end

.status ⇒ String?

Retrieves the character's society membership status.

Returns:

  • (String, nil) —

    The name of the society:

    • "Order of Voln"
    • "Council of Light"
    • "Guardians of Sunfist"
    • or nil/"None" if not a member


33
34
35
# File 'documented/gemstone/society.rb', line 33

def self.status
  self.membership
end

.step ⇒ Integer

Deprecated.

Use #rank instead. Deprecated 6/2025

Returns The current society rank.

Returns:

  • (Integer) —

    The current society rank



86
87
88
89
# File 'documented/gemstone/society.rb', line 86

def self.step
  Lich.deprecated("Society.step", "Society.rank", caller[0], fe_log: false)
  self.rank
end

.task ⇒ String

Retrieves the current task assigned by the society, if any.

The current society task, or "You are not currently in a society." if not a member, or "It is your eternal duty to release undead creatures from their suffering in the name of the Great Spirit Voln." if a Voln Master.

Returns:

  • (String) —

    The current society task message. Examples:

    • A task description
    • "You are not currently in a society."
    • "It is your eternal duty to release undead creatures..." (Voln masters)


57
58
59
# File 'documented/gemstone/society.rb', line 57

def self.task
  XMLData.society_task
end