Module: Lich::DragonRealms
- Includes:
- Lich
- Defined in:
- documented/games.rb,
documented/dragonrealms/creature.rb,
documented/dragonrealms/drinfomon.rb,
documented/dragonrealms/commons/common.rb,
documented/dragonrealms/commons/slackbot.rb,
documented/dragonrealms/drinfomon/drdefs.rb,
documented/dragonrealms/drinfomon/drroom.rb,
documented/dragonrealms/drinfomon/events.rb,
documented/dragonrealms/drinfomon/drskill.rb,
documented/dragonrealms/drinfomon/drstats.rb,
documented/dragonrealms/drinfomon/startup.rb,
documented/dragonrealms/drinfomon/drparser.rb,
documented/dragonrealms/drinfomon/drspells.rb,
documented/dragonrealms/drinfomon/drbanking.rb,
documented/dragonrealms/commons/common-items.rb,
documented/dragonrealms/commons/common-money.rb,
documented/dragonrealms/commons/equipmanager.rb,
documented/dragonrealms/custom_substitutions.rb,
documented/dragonrealms/commons/common-arcana.rb,
documented/dragonrealms/commons/common-travel.rb,
documented/dragonrealms/drinfomon/drvariables.rb,
documented/dragonrealms/commons/common-healing.rb,
documented/dragonrealms/commons/common-theurgy.rb,
documented/dragonrealms/drinfomon/drexpmonitor.rb,
documented/dragonrealms/commons/common-crafting.rb,
documented/dragonrealms/commons/common-moonmage.rb,
documented/dragonrealms/commons/common-summoning.rb,
documented/dragonrealms/commons/common-money-data.rb,
documented/dragonrealms/commons/common-validation.rb,
documented/dragonrealms/dependency/settings_config.rb,
documented/dragonrealms/commons/common-healing-data.rb
Overview
Module containing configuration settings for DragonRealms.
This module holds the configuration constants used by the SettingsTransformer.
Defined Under Namespace
Modules: Creature, CustomSubstitutions, DRBanking, DRC, DRCA, DRCC, DRCH, DRCI, DRCM, DRCMM, DRCS, DRCT, DRCTH, DRDefsPattern, DRExpMonitor, DRInfomon, DRParser, DRSpells, DRStats, SettingsConfig Classes: CharacterValidator, CreatureInstance, DRRoom, DRSkill, EquipmentManager, Flags, Game, GameInstance, SlackBot
Constant Summary collapse
- DR_LEARNING_RATES =
Learning rates for skills in DragonRealms, ordered from slowest to fastest.
[ 'clear', 'dabbling', 'perusing', 'learning', 'thoughtful', 'thinking', 'considering', 'pondering', 'ruminating', 'concentrating', 'attentive', 'deliberative', 'interested', 'examining', 'understanding', 'absorbing', 'intrigued', 'scrutinizing', 'analyzing', 'studious', 'focused', 'very focused', 'engaged', 'very engaged', 'cogitating', 'fascinated', 'captivated', 'engrossed', 'riveted', 'very riveted', 'rapt', 'very rapt', 'enthralled', 'nearly locked', 'mind lock' ].freeze
- DR_LONGEST_LEARNING_RATE_LENGTH =
Length of the longest learning rate name, used for padding in exp display
DR_LEARNING_RATES.max_by(&:length).length
- DR_BALANCE_VALUES =
Balance quality descriptors used in combat positioning.
[ 'completely', 'hopelessly', 'extremely', 'very badly', 'badly', 'somewhat off', 'off', 'slightly off', 'solidly', 'nimbly', 'adeptly', 'incredibly' ].freeze
- DR_POSITION_VALUES =
Combat positioning relative to your opponent, captured from the balance status line (e.g. "[You're solidly balanced and in good position.]"). Stored as a signed magnitude: positive means you hold the advantage, negative means your opponent does, and 0 is an even contest. The scale is symmetric, and the two "overwhelming opponent" phrasings map to the same value.
{ 'opponent overwhelming you' => -9, 'opponent dominating' => -8, 'opponent in excellent position' => -7, 'opponent in superior position' => -6, 'opponent in very strong position' => -5, 'opponent in strong position' => -4, 'opponent in good position' => -3, 'opponent in better position' => -2, 'opponent has slight advantage' => -1, 'no advantage' => 0, 'have slight advantage' => 1, 'in better position' => 2, 'in good position' => 3, 'in strong position' => 4, 'in very strong position' => 5, 'in superior position' => 6, 'in excellent position' => 7, 'in dominating position' => 8, 'overwhelming opponent' => 9, 'overwhelming your opponent' => 9 }.freeze
- DR_SKILLS_DATA =
Skill tree structure and guild-specific skill aliases for DragonRealms.
Contains two sections:
skillsets: Maps skill category names ('Armor', 'Lore', 'Weapon', 'Magic', 'Survival') to arrays of individual skills within that category.guild_skill_aliases: Maps guild names to hashes of skill name substitutions. For example, Clerics use 'Holy Magic' where the base skill is 'Primary Magic'.
{ skillsets: { 'Armor' => [ 'Shield Usage', 'Light Armor', 'Chain Armor', 'Brigandine', 'Plate Armor', 'Defending', 'Conviction' ].freeze, 'Lore' => [ 'Alchemy', 'Appraisal', 'Enchanting', 'Engineering', 'Forging', 'Outfitting', 'Performance', 'Scholarship', 'Tactics', 'Empathy', 'Bardic Lore', 'Trading', 'Mechanical Lore' ].freeze, 'Weapon' => [ 'Parry Ability', 'Small Edged', 'Large Edged', 'Twohanded Edged', 'Small Blunt', 'Large Blunt', 'Twohanded Blunt', 'Slings', 'Bow', 'Crossbow', 'Staves', 'Polearms', 'Light Thrown', 'Heavy Thrown', 'Brawling', 'Offhand Weapon', 'Melee Mastery', 'Missile Mastery', 'Expertise' ].freeze, 'Magic' => [ 'Primary Magic', 'Arcana', 'Attunement', 'Augmentation', 'Debilitation', 'Targeted Magic', 'Utility', 'Warding', 'Sorcery', 'Astrology', 'Summoning', 'Theurgy', 'Inner Magic', 'Inner Fire', 'Lunar Magic', 'Elemental Magic', 'Holy Magic', 'Life Magic', 'Arcane Magic' ].freeze, 'Survival' => [ 'Evasion', 'Athletics', 'Perception', 'Stealth', 'Locksmithing', 'Thievery', 'First Aid', 'Outdoorsmanship', 'Skinning', 'Instinct', 'Backstab', 'Thanatology' ].freeze }.freeze, guild_skill_aliases: { 'Cleric' => { 'Primary Magic' => 'Holy Magic' }.freeze, 'Necromancer' => { 'Primary Magic' => 'Arcane Magic' }.freeze, 'Warrior Mage' => { 'Primary Magic' => 'Elemental Magic' }.freeze, 'Thief' => { 'Primary Magic' => 'Inner Magic' }.freeze, 'Barbarian' => { 'Primary Magic' => 'Inner Fire' }.freeze, 'Ranger' => { 'Primary Magic' => 'Life Magic' }.freeze, 'Bard' => { 'Primary Magic' => 'Elemental Magic' }.freeze, 'Paladin' => { 'Primary Magic' => 'Holy Magic' }.freeze, 'Empath' => { 'Primary Magic' => 'Life Magic' }.freeze, 'Trader' => { 'Primary Magic' => 'Lunar Magic' }.freeze, 'Moon Mage' => { 'Primary Magic' => 'Lunar Magic' }.freeze }.freeze }.freeze
- KRONAR_BANKS =
Towns with banks that accept Kronar currency.
['Crossings', 'Dirge', 'Ilaya Taipa', 'Leth Deriel'].freeze
- LIRUM_BANKS =
Towns with banks that accept Lirum currency.
["Aesry Surlaenis'a", "Hara'jaal", "Mer'Kresh", "Muspar'i", 'Ratha', 'Riverhaven', "Rossman's Landing", 'Therenborough', 'Throne City'].freeze
- DOKORA_BANKS =
Towns with banks that accept Dokora currency.
['Ain Ghazal', 'Boar Clan', "Chyolvea Tayeu'a", 'Hibarnhvidar', 'Fang Cove', "Raven's Point", 'Shard'].freeze
- BANK_TITLES =
In-game room titles for bank deposit and teller windows by location.
Keys are town names; values are arrays of room titles where banking transactions can occur. Rooms are specified in the Lich room reference format [[location, descriptor]].
{ "Aesry Surlaenis'a" => ['[[Tona Kertigen, Deposit Window]]'].freeze, 'Ain Ghazal' => ['[[Ain Ghazal, Private Depository]]'].freeze, 'Boar Clan' => ['[[Ranger Guild, Bank]]'].freeze, "Chyolvea Tayeu'a" => ["[[Chyolvea Tayeu'a, Teller]]"].freeze, 'Crossings' => ['[[Provincial Bank, Teller]]'].freeze, 'Dirge' => ["[[Dirge, Traveller's Bank]]"].freeze, 'Fang Cove' => ['[[First Council Banking, Vault]]'].freeze, "Hara'jaal" => ["[[Baron's Forset, Teller]]"].freeze, 'Hibarnhvidar' => ['[[Second Provincial Bank of Hibarnhvidar, Teller]]', '[[Hibarnhvidar, Teller Windows]]', '[[First Arachnid Bank, Lobby]]'].freeze, 'Ilaya Taipa' => ['[[Ilaya Taipa, Trader Outpost Bank]]'].freeze, 'Leth Deriel' => ['[[Imperial Depository, Domestic Branch]]'].freeze, "Mer'Kresh" => ["[[Harti Clemois Bank, Teller's Window]]"].freeze, "Muspar'i" => ["[[Old Lata'arna Keep, Teller Windows]]"].freeze, 'Ratha' => ['[[Lower Bank of Ratha, Cashier]]', '[[Sshoi-sson Palace, Grand Provincial Bank, Bursarium]]'].freeze, "Raven's Point" => ["[[Bank of Raven's Point, Depository]]"].freeze, 'Riverhaven' => ['[[Bank of Riverhaven, Teller]]'].freeze, "Rossman's Landing" => ["[[Traders' Guild Outpost, Depository]]"].freeze, 'Shard' => ["[[First Bank of Ilithi, Teller's Windows]]"].freeze, 'Therenborough' => ['[[Bank of Therenborough, Teller]]'].freeze, 'Throne City' => ['[[Faldesu Exchequer, Teller]]'].freeze }.freeze
- VAULT_TITLES =
In-game room titles for vault carousel chambers by location.
Keys are town names; values are arrays of room titles where vault storage can be accessed. Not all towns with banks have vaults.
{ 'Crossings' => ['[[Crossing, Carousel Chamber]]'].freeze, 'Fang Cove' => ['[[Fang Cove, Carousel Chamber]]'].freeze, 'Leth Deriel' => ['[[Leth Deriel, Carousel Chamber]]'].freeze, "Mer'Kresh" => ["[[Mer'Kresh, Carousel Square]]"].freeze, "Muspar'i" => ["[[Muspar'i, Carousel Square]]"].freeze, 'Ratha' => ['[[Ratha, Carousel Square]]'].freeze, 'Riverhaven' => ['[[Riverhaven, Carousel Chamber]]'].freeze, 'Shard' => ['[[Shard, Carousel Chamber]]'].freeze, 'Therenborough' => ['[[Therenborough, Carousel Chamber]]'].freeze }.freeze
- UNKNOWN_DURATION =
Some spells may last for an unknown duration, such as cyclic spells that last as long as the caster can harness mana for it. Or, barbarian abilities when the character doesn't have Power Monger mastery to see true durations but only vague guestimates. In those situations, we set use this value.
1000- HOMETOWN_REGEX_MAP =
Regular expressions that match player-input abbreviations and variations for each town.
Keys are canonical town names; values are case-insensitive regexes that accept common abbreviations and alternate spellings. Used to normalize user input.
{ 'Arthe Dale' => /^(arthe( dale)?)$/i, 'Crossing' => /^(cross(ing)?)$/i, 'Darkling Wood' => /^(darkling( wood)?)$/i, 'Dirge' => /^(dirge)$/i, "Fayrin's Rest" => /^(fayrin'?s?( rest)?)$/i, 'Leth Deriel' => /^(leth( deriel)?)$/i, 'Shard' => /^(shard)$/i, 'Steelclaw Clan' => /^(steel( )?claw( clan)?|SCC)$/i, 'Stone Clan' => /^(stone( clan)?)$/i, 'Tiger Clan' => /^(tiger( clan)?)$/i, 'Wolf Clan' => /^(wolf( clan)?)$/i, 'Riverhaven' => /^(river|haven|riverhaven)$/i, "Rossman's Landing" => /^(rossman'?s?( landing)?)$/i, 'Therenborough' => /^(theren(borough)?)$/i, 'Langenfirth' => /^(lang(enfirth)?)$/i, 'Fornsted' => /^(fornsted)$/i, 'Hvaral' => /^(hvaral)$/i, 'Ratha' => /^(ratha)$/i, 'Aesry' => /^(aesry)$/i, "Mer'Kresh" => /^(mer'?kresh)$/i, 'Throne City' => /^(throne( city)?)$/i, 'Hibarnhvidar' => /^(hib(arnhvidar)?)$/i, "Raven's Point" => /^(raven'?s?( point)?)$/i, 'Boar Clan' => /^(boar( clan)?)$/i, 'Fang Cove' => /^(fang( cove)?)$/i, "Muspar'i" => /^(muspar'?i)$/i, 'Ain Ghazal' => /^(ain( )?ghazal)$/i }.freeze
- HOMETOWN_LIST =
List of canonical town names, like 'Therenborough' and 'Langenfirth'.
HOMETOWN_REGEX_MAP.keys.freeze
- HOMETOWN_REGEX =
Union of regular expressions that match town names, like /^(theren(borough)?)$/i
Regexp.union(HOMETOWN_REGEX_MAP.values)
- ORDINALS =
English ordinal words from first to twentieth.
%w[first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth thirteenth fourteenth fifteenth sixteenth seventeenth eighteenth nineteenth twentieth].freeze
- CURRENCIES =
Currency types recognized in DragonRealms.
%w[Kronars Lirums Dokoras].freeze
- ENC_MAP =
Character encumbrance levels and their numeric indices.
Keys are encumbrance descriptors from game output (e.g., "You are carrying a light burden"); values are numeric severity levels from 0 (no burden) to 11 (extreme burden).
{ 'None' => 0, 'Light Burden' => 1, 'Somewhat Burdened' => 2, 'Burdened' => 3, 'Heavy Burden' => 4, 'Very Heavy Burden' => 5, 'Overburdened' => 6, 'Very Overburdened' => 7, 'Extremely Overburdened' => 8, 'Tottering Under Burden' => 9, 'Are you even able to move?' => 10, "It's amazing you aren't squashed!" => 11 }.freeze
- NUM_MAP =
English number words mapped to their integer equivalents.
Covers zero through twenty and tens (thirty, forty, etc. up to ninety).
{ 'zero' => 0, 'one' => 1, 'two' => 2, 'three' => 3, 'four' => 4, 'five' => 5, 'six' => 6, 'seven' => 7, 'eight' => 8, 'nine' => 9, 'ten' => 10, 'eleven' => 11, 'twelve' => 12, 'thirteen' => 13, 'fourteen' => 14, 'fifteen' => 15, 'sixteen' => 16, 'seventeen' => 17, 'eighteen' => 18, 'nineteen' => 19, 'twenty' => 20, 'thirty' => 30, 'forty' => 40, 'fifty' => 50, 'sixty' => 60, 'seventy' => 70, 'eighty' => 80, 'ninety' => 90 }.freeze
- BOX_WOODS =
Box wood/material adjectives recognized in rummaged box lists. Players extend this via the
custom_box_woodssetting; see DRC.box_list_to_adj_and_noun. %w[brass copper deobar driftwood iron ironwood mahogany oaken pine steel wooden].freeze
- BOX_CONTAINERS =
Box container nouns recognized in rummaged box lists. Players extend this via the
custom_box_containerssetting. %w[box caddy casket chest coffer crate skippet strongbox trunk].freeze
- BOX_REGEX =
Recognizes "
" box descriptions. Built from BOX_WOODS and BOX_CONTAINERS so both remain a single source of truth; kept as a global ($box_regex) for third-party scripts. /((?:#{BOX_WOODS.join('|')}) (?:#{BOX_CONTAINERS.join('|')}))/.freeze
- MANA_MAP =
Mana level descriptors grouped by skill training stage.
Each key represents a training phase; values are arrays of adjectives that describe the character's mana reserves at that stage. Used to assess spell readiness and casting potential.
{ 'weak' => %w[dim glowing bright].freeze, 'developing' => %w[faint muted glowing luminous bright].freeze, 'improving' => %w[faint hazy flickering shimmering glowing lambent shining fulgent glaring].freeze, 'good' => %w[faint dim hazy dull muted dusky pale flickering shimmering pulsating glowing lambent shining luminous radiant fulgent brilliant flaring glaring blazing blinding].freeze }.freeze
- PRIMARY_SIGILS_PATTERN =
Pattern matching primary sigil types in spell or ability names.
Matches word boundaries around sigil names: abolition, congruence, induction, permutation, or rarefaction.
/\b(?:abolition|congruence|induction|permutation|rarefaction) sigil\b/.freeze
- SECONDARY_SIGILS_PATTERN =
Pattern matching secondary sigil types in spell or ability names.
Matches word boundaries around sigil names: antipode, ascension, clarification, decay, evolution, integration, metamorphosis, nurture, paradox, or unity.
/\b(?:antipode|ascension|clarification|decay|evolution|integration|metamorphosis|nurture|paradox|unity) sigil\b/.freeze
- VOL_MAP =
Object volume descriptors mapped to approximate container sizes.
Keys are size adjectives; values are numeric volume estimates used to estimate container capacity and item bulk.
{ 'colossal' => 200, 'gigantic' => 100, 'immense' => 50, 'enormous' => 20, 'massive' => 10, 'huge' => 5, 'large' => 4, 'medium' => 3, 'small' => 2, 'tiny' => 1 }.freeze
Constants included from Lich
DEFAULT_SQLITE_BUSY_TIMEOUT_MS, MAX_DEBUG_LOGS_DEFAULT, MAX_DEBUG_LOGS_MINIMUM, ROOMID_LOCATIONS
Instance Method Summary collapse
-
#add_ordinals_to_duplicates(npc_list) ⇒ Array<String>
Adds ordinal prefixes to duplicate NPCs (e.g., "second goblin").
-
#check_exp_mods ⇒ Array<String>?
Issues the 'exp mods' command and parses skill modifiers.
-
#clean_and_split(room_objs) ⇒ Array<String>
Cleans room objects string and splits into array.
-
#clean_npc_string(npc_string) ⇒ Array<String>
Cleans and normalizes NPC strings to creature names.
-
#convert2copper(amt, denomination) ⇒ Integer
Converts an amount and denomination to copper.
-
#convert2plats(copper) ⇒ String
Converts copper to a readable currency string with denominations.
-
#extract_final_name(text) ⇒ String?
Extracts just the creature name (letters, hyphens, apostrophes).
-
#extract_last_creature(text) ⇒ String
Extracts the last creature from an "X and Y" string.
-
#extract_npcs(room_objs, select_dead: false) ⇒ Array<String>
Extract NPCs from room objects.
-
#extract_pcs(room_players, filter_pattern: nil, status_pattern: DRDefsPattern::PLAYER_STATUS) ⇒ Array<String>
Extract player names from room player string.
-
#find_all_npcs(room_objs) ⇒ Array<String>
Finds all NPC strings (both living and dead) in room objects.
-
#find_dead_npcs(room_objs) ⇒ Array<String>
Finds dead NPCs in the room.
-
#find_npcs(room_objs) ⇒ Array<String>
Finds living NPCs in the room.
-
#find_objects(room_objs) ⇒ Array<String>
Finds non-NPC objects in the room (items, furniture, etc.).
-
#find_pcs(room_players) ⇒ Array<String>
Finds all player names in the room.
-
#find_pcs_prone(room_players) ⇒ Array<String>
Finds players who are lying down in the room.
-
#find_pcs_sitting(room_players) ⇒ Array<String>
Finds players who are sitting in the room.
-
#normalize_creature_names(text) ⇒ String
Normalizes creature names that have variant descriptions, collapsing any string that contains a canonical name to just that name (e.g. "a sinewy leopard that is prowling" -> "sinewy leopard").
-
#normalize_trailing_and(text) ⇒ String
Normalizes "X and Y" to "X, Y" for consistent splitting.
-
#remove_html_tags(text) ⇒ String
Removes pushBold/popBold XML tags from text.
Methods included from Lich
break_game_host_port, class_eval, class_variable_get, cleanup_debug_logs, configure_sqlite_connection, core_updated_with_lich_version, core_updated_with_lich_version=, db, db_maint_due?, db_maint_last_at, db_maint_lock_path, db_maint_set!, db_mutex, db_vacuum_if_due!, debug_messaging, debug_messaging=, deprecated, display_exits, display_exits=, display_expgains, display_expgains=, display_lichid, display_lichid=, display_room_links, display_room_links=, display_room_mono, display_room_mono=, display_roomid_location, display_roomid_location=, display_stringprocs, display_stringprocs=, display_uid, display_uid=, find_hosts_file, fix_game_host_port, get_simu_launcher, hide_uid_flag, hide_uid_flag=, hosts_file, init_db, inventory_boxes, link_to_sal, link_to_sge, log, max_debug_logs, max_debug_logs=, method_missing, modify_hosts, module_eval, msgbox, mutex_lock, mutex_unlock, open_sequel_sqlite, open_sqlite_db, restore_hosts, seek, set_inventory_boxes, show_deprecated_log, sqlite_busy_timeout_ms, track_autosort_state, track_autosort_state=, track_dark_mode, track_dark_mode=, track_layout_state, track_layout_state=, track_persistent_launcher_mode, track_persistent_launcher_mode=, unlink_from_sal, unlink_from_sge, win32_launch_method, win32_launch_method=
Instance Method Details
#add_ordinals_to_duplicates(npc_list) ⇒ Array<String>
Adds ordinal prefixes to duplicate NPCs (e.g., "second goblin").
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'documented/dragonrealms/drinfomon/drdefs.rb', line 252 def add_ordinals_to_duplicates(npc_list) flat_npcs = [] npc_list.uniq.each do |npc| # Count how many times this NPC appears count = npc_list.count(npc) # Create entries with ordinals for duplicates count.times do |index| if index.zero? flat_npcs << npc else # Use ordinal from $ORDINALS if available, otherwise generate one ordinal = $ORDINALS[index] || "#{index + 1}th" flat_npcs << "#{ordinal} #{npc}" end end end flat_npcs end |
#check_exp_mods ⇒ Array<String>?
Issues the 'exp mods' command and parses skill modifiers.
88 89 90 |
# File 'documented/dragonrealms/drinfomon/drdefs.rb', line 88 def check_exp_mods Lich::Util.issue_command("exp mods", /The following skills are currently under the influence of a modifier/, /^<output class=""/, quiet: true, include_end: false, usexml: false) end |
#clean_and_split(room_objs) ⇒ Array<String>
Cleans room objects string and splits into array. Removes "You also see" prefix and mount descriptions.
111 112 113 114 115 116 |
# File 'documented/dragonrealms/drinfomon/drdefs.rb', line 111 def clean_and_split(room_objs) room_objs.sub(DRDefsPattern::YOU_ALSO_SEE, '') .sub(DRDefsPattern::MOUNT_DESCRIPTION, '') .strip .split(DRDefsPattern::COMMA_OR_AND) end |
#clean_npc_string(npc_string) ⇒ Array<String>
Cleans and normalizes NPC strings to creature names. Handles XML tag removal, name normalization, and ordinal numbering.
182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'documented/dragonrealms/drinfomon/drdefs.rb', line 182 def clean_npc_string(npc_string) # Normalize NPC names normalized_npcs = npc_string .map { |obj| normalize_creature_names(obj) } .map { |obj| (obj) } .map { |obj| extract_last_creature(obj) } .map { |obj| extract_final_name(obj) } .compact .sort # Count occurrences and add ordinals add_ordinals_to_duplicates(normalized_npcs) end |
#convert2copper(amt, denomination) ⇒ Integer
Converts an amount and denomination to copper.
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'documented/dragonrealms/drinfomon/drdefs.rb', line 72 def convert2copper(amt, denomination) if denomination =~ /platinum/ (amt.to_i * 10_000) elsif denomination =~ /gold/ (amt.to_i * 1000) elsif denomination =~ /silver/ (amt.to_i * 100) elsif denomination =~ /bronze/ (amt.to_i * 10) else amt end end |
#convert2plats(copper) ⇒ String
Converts copper to a readable currency string with denominations.
95 96 97 98 99 100 101 102 103 104 105 |
# File 'documented/dragonrealms/drinfomon/drdefs.rb', line 95 def convert2plats(copper) denominations = [[10_000, 'platinum'], [1000, 'gold'], [100, 'silver'], [10, 'bronze'], [1, 'copper']] denominations.inject([copper, []]) do |result, denomination| remaining = result.first display = result.last if remaining / denomination.first > 0 display << "#{remaining / denomination.first} #{denomination.last}" end [remaining % denomination.first, display] end.last.join(', ') end |
#extract_final_name(text) ⇒ String?
Extracts just the creature name (letters, hyphens, apostrophes).
244 245 246 247 |
# File 'documented/dragonrealms/drinfomon/drdefs.rb', line 244 def extract_final_name(text) # Extract just the creature name (letters, hyphens, apostrophes) text.strip.scan(DRDefsPattern::CREATURE_NAME).first end |
#extract_last_creature(text) ⇒ String
Extracts the last creature from an "X and Y" string. Removes modifiers like "glowing with a holy aura".
236 237 238 239 |
# File 'documented/dragonrealms/drinfomon/drdefs.rb', line 236 def extract_last_creature(text) # Get the last creature name after "and", removing modifiers like "glowing with" text.split(/\sand\s/).last.sub(DRDefsPattern::GLOWING_WITH, '') end |
#extract_npcs(room_objs, select_dead: false) ⇒ Array<String>
Extract NPCs from room objects
278 279 280 281 282 283 284 285 286 |
# File 'documented/dragonrealms/drinfomon/drdefs.rb', line 278 def extract_npcs(room_objs, select_dead: false) all_npcs = find_all_npcs(room_objs) filtered = if select_dead all_npcs.select { |obj| DRDefsPattern::DEAD_NPC.match?(obj) } else all_npcs.reject { |obj| DRDefsPattern::DEAD_NPC.match?(obj) } end clean_npc_string(filtered) end |
#extract_pcs(room_players, filter_pattern: nil, status_pattern: DRDefsPattern::PLAYER_STATUS) ⇒ Array<String>
Extract player names from room player string
135 136 137 138 139 140 141 142 143 144 145 |
# File 'documented/dragonrealms/drinfomon/drdefs.rb', line 135 def extract_pcs(room_players, filter_pattern: nil, status_pattern: DRDefsPattern::PLAYER_STATUS) return [] if room_players.nil? || room_players.empty? players = normalize_trailing_and(room_players).split(', ') players = players.select { |obj| filter_pattern.match?(obj) } if filter_pattern players .map { |obj| obj.sub(status_pattern, '').sub(DRDefsPattern::PARENTHETICAL, '') } .map { |obj| obj.strip.scan(DRDefsPattern::PLAYER_NAME).first } .compact end |
#find_all_npcs(room_objs) ⇒ Array<String>
Finds all NPC strings (both living and dead) in room objects.
171 172 173 174 175 176 |
# File 'documented/dragonrealms/drinfomon/drdefs.rb', line 171 def find_all_npcs(room_objs) room_objs.sub(DRDefsPattern::YOU_ALSO_SEE, '') .sub(DRDefsPattern::MOUNT_DESCRIPTION, '') .strip .scan(DRDefsPattern::NPC_SCAN) end |
#find_dead_npcs(room_objs) ⇒ Array<String>
Finds dead NPCs in the room.
298 299 300 |
# File 'documented/dragonrealms/drinfomon/drdefs.rb', line 298 def find_dead_npcs(room_objs) extract_npcs(room_objs, select_dead: true) end |
#find_npcs(room_objs) ⇒ Array<String>
Finds living NPCs in the room.
291 292 293 |
# File 'documented/dragonrealms/drinfomon/drdefs.rb', line 291 def find_npcs(room_objs) extract_npcs(room_objs, select_dead: false) end |
#find_objects(room_objs) ⇒ Array<String>
Finds non-NPC objects in the room (items, furniture, etc.).
305 306 307 308 309 310 311 |
# File 'documented/dragonrealms/drinfomon/drdefs.rb', line 305 def find_objects(room_objs) # Use sub instead of sub! to avoid mutating frozen strings processed_objs = room_objs.sub(DRDefsPattern::GELAPOD, DRDefsPattern::GELAPOD_REPLACEMENT) clean_and_split(processed_objs) .reject { |obj| DRDefsPattern::PUSH_BOLD.match?(obj) } .map { |obj| obj.sub(DRDefsPattern::TRAILING_PERIOD, '').strip.sub(DRDefsPattern::LEADING_ARTICLE, '').strip } end |
#find_pcs(room_players) ⇒ Array<String>
Finds all player names in the room.
150 151 152 |
# File 'documented/dragonrealms/drinfomon/drdefs.rb', line 150 def find_pcs(room_players) extract_pcs(room_players) end |
#find_pcs_prone(room_players) ⇒ Array<String>
Finds players who are lying down in the room.
157 158 159 |
# File 'documented/dragonrealms/drinfomon/drdefs.rb', line 157 def find_pcs_prone(room_players) extract_pcs(room_players, filter_pattern: DRDefsPattern::LYING_DOWN, status_pattern: DRDefsPattern::WHO_STATUS) end |
#find_pcs_sitting(room_players) ⇒ Array<String>
Finds players who are sitting in the room.
164 165 166 |
# File 'documented/dragonrealms/drinfomon/drdefs.rb', line 164 def find_pcs_sitting(room_players) extract_pcs(room_players, filter_pattern: DRDefsPattern::SITTING, status_pattern: DRDefsPattern::WHO_STATUS) end |
#normalize_creature_names(text) ⇒ String
Normalizes creature names that have variant descriptions, collapsing any string that contains a canonical name to just that name (e.g. "a sinewy leopard that is prowling" -> "sinewy leopard").
The canonical list is Lich::DragonRealms::DRDefsPattern::CREATURE_NORMALIZATIONS merged with
the player's custom_creature_normalizations setting, so a player can
teach Lich about their own problematic creature/pet descriptions without a
Lich release. The merged list is memoized; see
CustomSubstitutions.
This runs on the hot NPC-parsing path (#find_npcs fires on every room update), so it uses a plain substring check rather than compiling a regex per name per call.
215 216 217 218 219 220 221 |
# File 'documented/dragonrealms/drinfomon/drdefs.rb', line 215 def normalize_creature_names(text) names = CustomSubstitutions.resolve(:custom_creature_normalizations, DRDefsPattern::CREATURE_NORMALIZATIONS, type: :names) # Longest match against the ORIGINAL text, not a fold over the accumulator: # folding would let a later name that is a substring of an earlier match's # replacement (e.g. 'war yak' after 'grumpy war yak') re-collapse it. names.select { |name| text.include?(name) }.max_by(&:length) || text end |
#normalize_trailing_and(text) ⇒ String
Normalizes "X and Y" to "X, Y" for consistent splitting. Used to handle the lack of Oxford comma in game output.
122 123 124 125 126 127 128 |
# File 'documented/dragonrealms/drinfomon/drdefs.rb', line 122 def normalize_trailing_and(text) if (match = text.match(DRDefsPattern::TRAILING_AND)) text.sub(DRDefsPattern::TRAILING_AND, ", #{match[:last]}") else text end end |
#remove_html_tags(text) ⇒ String
Removes pushBold/popBold XML tags from text.
226 227 228 229 230 |
# File 'documented/dragonrealms/drinfomon/drdefs.rb', line 226 def (text) text .sub('<pushBold/>', '') .sub(%r{<popBold/>.*}, '') end |