Module: Lich::DragonRealms::DRStats

Defined in:
documented/dragonrealms/drinfomon/drstats.rb

Overview

Access and manage character stats and attributes in DragonRealms.

This module provides thread-safe read/write access to character statistics gathered from the game's XML data feed, including abilities (strength, agility, etc.), dynamic states (health, mana, balance), and character metadata (guild, gender, age). Stats are cached in module-level variables and persist across script reloads when serialized and restored.

Examples:

Check character guild

if DRStats.paladin?
  DRStats.circle  # => 40
end

Query trained stats

DRStats.agility  # => 18

Check native mana type

DRStats.native_mana  # => "holy" for Paladin

Constant Summary collapse

GUILD_MANA_TYPES =

Guilds and their native mana types, frozen for immutability.

{
  'Necromancer'  => 'arcane',
  'Barbarian'    => nil,
  'Thief'        => nil,
  'Moon Mage'    => 'lunar',
  'Trader'       => 'lunar',
  'Warrior Mage' => 'elemental',
  'Bard'         => 'elemental',
  'Cleric'       => 'holy',
  'Paladin'      => 'holy',
  'Empath'       => 'life',
  'Ranger'       => 'life'
}.freeze
@@race =
nil
@@guild =
nil
@@gender =
nil
@@encumbrance =
nil

Class Method Summary collapse

Class Method Details

.ageInteger

Returns the character's age in years.

Returns:

  • (Integer)

    the age, or 0 if not yet loaded



92
93
94
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 92

def self.age
  @@age
end

.age=(val) ⇒ Integer

Sets the character's age.

Parameters:

  • val (Integer)

    the age in years

Returns:

  • (Integer)


100
101
102
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 100

def self.age=(val)
  @@age = val
end

.agilityInteger

Returns the character's trained Agility ability.

Returns:

  • (Integer)

    the trained rank, or 0 if not yet loaded



167
168
169
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 167

def self.agility
  @@agility
end

.agility=(val) ⇒ Integer

Sets the character's trained Agility ability.

Parameters:

  • val (Integer)

    the trained rank

Returns:

  • (Integer)


175
176
177
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 175

def self.agility=(val)
  @@agility = val
end

.balanceInteger

Returns the character's current balance, a measure of how soon the character can perform an action.

Returns:

  • (Integer)

    the balance value, defaults to 8



287
288
289
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 287

def self.balance
  @@balance
end

.balance=(val) ⇒ Integer

Sets the character's current balance.

Parameters:

  • val (Integer)

    the balance value

Returns:

  • (Integer)


295
296
297
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 295

def self.balance=(val)
  @@balance = val
end

.barbarian?Boolean

Returns whether the character is a Barbarian.

Returns:

  • (Boolean)


421
422
423
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 421

def self.barbarian?
  @@guild == 'Barbarian'
end

.bard?Boolean

Returns whether the character is a Bard.

Returns:

  • (Boolean)


428
429
430
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 428

def self.bard?
  @@guild == 'Bard'
end

.charismaInteger

Returns the character's trained Charisma ability.

Returns:

  • (Integer)

    the trained rank, or 0 if not yet loaded



227
228
229
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 227

def self.charisma
  @@charisma
end

.charisma=(val) ⇒ Integer

Sets the character's trained Charisma ability.

Parameters:

  • val (Integer)

    the trained rank

Returns:

  • (Integer)


235
236
237
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 235

def self.charisma=(val)
  @@charisma = val
end

.circleInteger

Returns the character's guild circle (experience tier).

Returns:

  • (Integer)

    the circle, or 0 if not yet loaded



107
108
109
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 107

def self.circle
  @@circle
end

.circle=(val) ⇒ Integer

Sets the character's guild circle.

Parameters:

  • val (Integer)

    the circle

Returns:

  • (Integer)


115
116
117
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 115

def self.circle=(val)
  @@circle = val
end

.cleric?Boolean

Returns whether the character is a Cleric.

Returns:

  • (Boolean)


435
436
437
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 435

def self.cleric?
  @@guild == 'Cleric'
end

.commoner?Boolean

Returns whether the character is a Commoner.

Returns:

  • (Boolean)


442
443
444
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 442

def self.commoner?
  @@guild == 'Commoner'
end

.concentrationInteger

Returns the character's current concentration from the XML data feed.

Returns:

  • (Integer)

    the current concentration



370
371
372
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 370

def self.concentration
  XMLData.concentration
end

.disciplineInteger

Returns the character's trained Discipline ability.

Returns:

  • (Integer)

    the trained rank, or 0 if not yet loaded



212
213
214
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 212

def self.discipline
  @@discipline
end

.discipline=(val) ⇒ Integer

Sets the character's trained Discipline ability.

Parameters:

  • val (Integer)

    the trained rank

Returns:

  • (Integer)


220
221
222
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 220

def self.discipline=(val)
  @@discipline = val
end

.empath?Boolean

Returns whether the character is an Empath.

Returns:

  • (Boolean)


449
450
451
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 449

def self.empath?
  @@guild == 'Empath'
end

.encumbranceString?

Returns the character's encumbrance level.

Returns:

  • (String, nil)

    the encumbrance state, or nil if not yet loaded



320
321
322
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 320

def self.encumbrance
  @@encumbrance
end

.encumbrance=(val) ⇒ String?

Sets the character's encumbrance level.

Parameters:

  • val (String, nil)

    the encumbrance state

Returns:



328
329
330
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 328

def self.encumbrance=(val)
  @@encumbrance = val
end

.fatigueInteger

Returns the character's current fatigue (stamina pool) from the XML data feed.

Returns:

  • (Integer)

    the current fatigue



356
357
358
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 356

def self.fatigue
  XMLData.stamina
end

.favorsInteger

Returns the character's favor count.

Returns:

  • (Integer)

    the favor count, or 0 if not yet loaded



242
243
244
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 242

def self.favors
  @@favors
end

.favors=(val) ⇒ Integer

Sets the character's favor count.

Parameters:

  • val (Integer)

    the favor count

Returns:

  • (Integer)


250
251
252
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 250

def self.favors=(val)
  @@favors = val
end

.genderString?

Returns the character's gender.

Returns:

  • (String, nil)

    the gender, or nil if not yet loaded



77
78
79
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 77

def self.gender
  @@gender
end

.gender=(val) ⇒ String?

Sets the character's gender.

Parameters:

  • val (String, nil)

    the gender

Returns:



85
86
87
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 85

def self.gender=(val)
  @@gender = val
end

.guildString?

Returns the character's guild.

Returns:

  • (String, nil)

    the guild name (e.g. "Paladin", "Moon Mage"), or nil if not yet loaded



62
63
64
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 62

def self.guild
  @@guild
end

.guild=(val) ⇒ String?

Sets the character's guild.

Parameters:

  • val (String, nil)

    the guild name

Returns:



70
71
72
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 70

def self.guild=(val)
  @@guild = val
end

.healthInteger

Returns the character's current health from the XML data feed.

Returns:

  • (Integer)

    the current health



342
343
344
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 342

def self.health
  XMLData.health
end

.intelligenceInteger

Returns the character's trained Intelligence ability.

Returns:

  • (Integer)

    the trained rank, or 0 if not yet loaded



182
183
184
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 182

def self.intelligence
  @@intelligence
end

.intelligence=(val) ⇒ Integer

Sets the character's trained Intelligence ability.

Parameters:

  • val (Integer)

    the trained rank

Returns:

  • (Integer)


190
191
192
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 190

def self.intelligence=(val)
  @@intelligence = val
end

.load_serialized=(array) ⇒ Object

BUG FIX: Original code used array which only provides 8 elements but tried to assign to 13 variables (circle + 12 stats), causing data loss. The correct slice is array for the remaining 13 variables.



411
412
413
414
415
416
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 411

def self.load_serialized=(array)
  return if array.nil? || array.empty?

  @@race, @@guild, @@gender, @@age = array[0..3]
  @@circle, @@strength, @@stamina, @@reflex, @@agility, @@intelligence, @@wisdom, @@discipline, @@charisma, @@favors, @@tdps, @@luck, @@encumbrance = array[4..16]
end

.luckInteger

Returns the character's luck rating.

Returns:

  • (Integer)

    the luck rating, or 0 if not yet loaded



272
273
274
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 272

def self.luck
  @@luck
end

.luck=(val) ⇒ Integer

Sets the character's luck rating.

Parameters:

  • val (Integer)

    the luck rating

Returns:

  • (Integer)


280
281
282
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 280

def self.luck=(val)
  @@luck = val
end

.manaInteger

Returns the character's current mana from the XML data feed.

Returns:

  • (Integer)

    the current mana



349
350
351
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 349

def self.mana
  XMLData.mana
end

.moon_mage?Boolean

Returns whether the character is a Moon Mage.

Returns:

  • (Boolean)


456
457
458
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 456

def self.moon_mage?
  @@guild == 'Moon Mage'
end

.nameString

Returns the character's name from the XML data feed.

Returns:

  • (String)

    the character name



335
336
337
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 335

def self.name
  XMLData.name
end

.native_manaString?

Returns the mana type native to the character's guild.

Examples:

DRStats.native_mana  # => "holy" for Paladin
DRStats.native_mana  # => nil for Barbarian

Returns:

  • (String, nil)

    the mana type ("arcane", "lunar", "elemental", "holy", "life"), or nil for guilds without native mana (Barbarian, Thief, Commoner)



395
396
397
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 395

def self.native_mana
  GUILD_MANA_TYPES[@@guild]
end

.necromancer?Boolean

Returns whether the character is a Necromancer.

Returns:

  • (Boolean)


463
464
465
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 463

def self.necromancer?
  @@guild == 'Necromancer'
end

.paladin?Boolean

Returns whether the character is a Paladin.

Returns:

  • (Boolean)


470
471
472
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 470

def self.paladin?
  @@guild == 'Paladin'
end

.positionObject

Combat positioning relative to your opponent. Signed magnitude where positive means you hold the advantage, negative means your opponent does, and 0 is an even contest. See DR_POSITION_VALUES.



302
303
304
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 302

def self.position
  @@position
end

.position=(val) ⇒ Integer

Sets the character's combat positioning relative to the opponent.

Positive values indicate an advantage, negative values indicate a disadvantage, and 0 is an even contest.

Parameters:

  • val (Integer)

    the signed position value

Returns:

  • (Integer)


313
314
315
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 313

def self.position=(val)
  @@position = val
end

.raceString?

Returns the character's race.

Returns:

  • (String, nil)

    the race name, or nil if not yet loaded



47
48
49
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 47

def self.race
  @@race
end

.race=(val) ⇒ String?

Sets the character's race.

Parameters:

  • val (String, nil)

    the race name

Returns:



55
56
57
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 55

def self.race=(val)
  @@race = val
end

.ranger?Boolean

Returns whether the character is a Ranger.

Returns:

  • (Boolean)


477
478
479
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 477

def self.ranger?
  @@guild == 'Ranger'
end

.reflexInteger

Returns the character's trained Reflex ability.

Returns:

  • (Integer)

    the trained rank, or 0 if not yet loaded



152
153
154
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 152

def self.reflex
  @@reflex
end

.reflex=(val) ⇒ Integer

Sets the character's trained Reflex ability.

Parameters:

  • val (Integer)

    the trained rank

Returns:

  • (Integer)


160
161
162
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 160

def self.reflex=(val)
  @@reflex = val
end

.serializeObject

Serialization order (17 elements, indices 0-16): 0: race, 1: guild, 2: gender, 3: age, 4: circle, 5: strength, 6: stamina, 7: reflex, 8: agility, 9: intelligence, 10: wisdom, 11: discipline, 12: charisma, 13: favors, 14: tdps, 15: luck, 16: encumbrance



404
405
406
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 404

def self.serialize
  [@@race, @@guild, @@gender, @@age, @@circle, @@strength, @@stamina, @@reflex, @@agility, @@intelligence, @@wisdom, @@discipline, @@charisma, @@favors, @@tdps, @@luck, @@encumbrance]
end

.spiritInteger

Returns the character's current spirit from the XML data feed.

Returns:

  • (Integer)

    the current spirit



363
364
365
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 363

def self.spirit
  XMLData.spirit
end

.staminaInteger

Returns the character's trained Stamina ability.

Returns:

  • (Integer)

    the trained rank, or 0 if not yet loaded



137
138
139
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 137

def self.stamina
  @@stamina
end

.stamina=(val) ⇒ Integer

Sets the character's trained Stamina ability.

Parameters:

  • val (Integer)

    the trained rank

Returns:

  • (Integer)


145
146
147
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 145

def self.stamina=(val)
  @@stamina = val
end

.strengthInteger

Returns the character's trained Strength ability.

Returns:

  • (Integer)

    the trained rank, or 0 if not yet loaded



122
123
124
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 122

def self.strength
  @@strength
end

.strength=(val) ⇒ Integer

Sets the character's trained Strength ability.

Parameters:

  • val (Integer)

    the trained rank

Returns:

  • (Integer)


130
131
132
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 130

def self.strength=(val)
  @@strength = val
end

.tdpsInteger

Returns the character's total drained points (from experience loss).

Returns:

  • (Integer)

    the drained points, or 0 if not yet loaded



257
258
259
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 257

def self.tdps
  @@tdps
end

.tdps=(val) ⇒ Integer

Sets the character's total drained points.

Parameters:

  • val (Integer)

    the drained points

Returns:

  • (Integer)


265
266
267
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 265

def self.tdps=(val)
  @@tdps = val
end

.thief?Boolean

Returns whether the character is a Thief.

Returns:

  • (Boolean)


484
485
486
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 484

def self.thief?
  @@guild == 'Thief'
end

.trader?Boolean

Returns whether the character is a Trader.

Returns:

  • (Boolean)


491
492
493
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 491

def self.trader?
  @@guild == 'Trader'
end

.warrior_mage?Boolean

Returns whether the character is a Warrior Mage.

Returns:

  • (Boolean)


498
499
500
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 498

def self.warrior_mage?
  @@guild == 'Warrior Mage'
end

.wisdomInteger

Returns the character's trained Wisdom ability.

Returns:

  • (Integer)

    the trained rank, or 0 if not yet loaded



197
198
199
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 197

def self.wisdom
  @@wisdom
end

.wisdom=(val) ⇒ Integer

Sets the character's trained Wisdom ability.

Parameters:

  • val (Integer)

    the trained rank

Returns:

  • (Integer)


205
206
207
# File 'documented/dragonrealms/drinfomon/drstats.rb', line 205

def self.wisdom=(val)
  @@wisdom = val
end