Module: Lich::DragonRealms::DRCA
- Defined in:
- documented/dragonrealms/commons/common-arcana.rb
Overview
DragonRealms Common Arcana - shared spell casting, buffing, and mana management utilities for all guilds.
This module provides the core casting workflow (prepare, charge, invoke, cast), cyclic spell management, Khri and Barbarian buff activation, mana perception and discernment, and cambrinth charge distribution. Most methods serve scripts that cast spells from waggle configs and other spell-driven logic.
Constant Summary collapse
- CYCLIC_RELEASE_SUCCESS_PATTERNS =
Game messages matching successful release of a cyclic spell.
[ # Ranger spells /^The world seems to accelerate around you as the spirit of the cheetah escapes you/, # Cheetah Swiftness /^You feel distinctly frail and vulnerable as the spirit of the bear leaves you/, # Bear Strength /^The forces of nature that you roused are no longer with you/, # Awaken Forest # Empath spells /^Aesandry Darlaeth loses cohesion, returning your reaction time to normal/, # Aesandry Darlaeth /^You sense your hold on your Guardian Spirit weaken, then evaporate entirely/, # Guardian Spirit /^The signs of empathic atrocity escape to the deepest pits of your personality, your touch no longer deadly/, # Icutu Zaharenela /^The tingling across your body diminishes as you feel the motes of energy fade away/, # Regenerate # Bard spells /^You sing, purposely warbling some of the held notes for effec/, # Abandoned Heart (ABAN) /^The final tones of your enchante end with an abrupt flourish that leaves stark silence in its wake/, # Aether Wolves (AEWO) /^With a rising crescendo in your voice, you reprise the strong lines of the chorus of Albreda's Balm before bringing it to an abrupt conclusion/, # Albreda's Balm (ALB) /^The final, quiet notes of Blessing of the Fae stir the air gently, and die away/, # Blessing of the Fae (BOTF) /^The warm air swirling around you stills and begins to cool/, # Caress of the Sun (CARE) /^A few fleeting, soporific notes tarry in the air before your lullaby slowly dies down like the night receding at Anduwen/, # Damaris' Lullaby (DALU) /^You no longer feel the clarity of vision you had, as shadows creep across the area/, # Eye of Kertigen (EYE) /^You let your voice fade even as the pace of Faenella's Grace slows, winding down to a quiet conclusion/, # Faenella's Grace (FAE) /^The aethereal static subsides, returning your spellcasting abilities to normal/, # Glythtide's Joy (GJ) /^As your rendition of Hodierna's Lilt winds down to a close, you let each note linger on the air a moment, drawing out the final moment with a reluctance to let the soothing melody fade/, # Hodierna's Lilt (HODI) /^You build the final notes of Phoenix's Pyre with an upward scale that rises into a steep crescendo, and end with an abrupt silence/, # Phoenix's Pyre (PYRE) /^The dome of light extinguishes as the final notes of music die away/, # Sanctuary # Warrior Mage spells /^The dark mantle of aether surrounding you fades away/, # Aether Cloak (AC) /^You release your connection to the Elemental Plane of Electricity, allowing the static electricity to dissipate/, # Electrostatic Eddy (EE) /^Your link to the Fire Rain matrix has been severed/, # Fire Rain (FR) /^The chilling vapor surrounding you dissipates slowly/, # Rimefang (spell) (RIM) /^The frost-covered blade circling around you shatters into a fine icy mist/, # Rimefang (spell) (RIM) /^The jagged stone spears surrounding you at .* range tremble slightly, then crumble into a grey dust that is quickly reclaimed by the earth/, # Ring of Spears (ROS) # Cleric spells /^The deadening murk around you subsides/, # Hydra Hex (HYH) /^The dark patch of grime around you subsides/, # Hydra Hex (HYH) /^You sense the dark presence depart/, # Soul Attrition (SA) # Resurrection (REZZ) does not have messaging that makes it usable here. /^The heightened sense of spiritual awareness leaves you/, # Revelation (REV) /^The swirling fog dissipates from around you/, # Ghost Shroud (GHS) # Paladin spells /^The .* radiance of your soul subsides, retreating into your body/, # Holy Warrior (HOW) /^Truffenyi's Rally ends, leaving behind a momentary sensation of something stuck in your throat/, # Truffenyi's Rally (TR) # Moon Mage spells /^The web of shadows twitches one last time and then goes inert/, # Shadow Web (SHW) /^You release your mental hold on the lunar energy that sustains your moongate/, # Moongate (MG) /^The refractive field surrounding you fades away/, # Steps of Vuan (SOV) /^A .* sphere suddenly flares with a cold light and vaporizes/, # Starlight Sphere (SLS) # Trader spells /^Your calligraphy of light assailing/, # Arbiter's Stylus (ARS) /^The .* moonsmoke blows away from your face/, # Mask of the Moons (MOM) # Necromancer spells /^The Rite of Contrition matrix loses cohesion, leaving your aura naked/, # Rite of Contrition (ROC) /^The Rite of Forbearance matrix loses cohesion, leaving you to wallow in temptation/, # Rite of Forbearance (ROF) /^The Rite of Grace matrix loses cohesion, leaving your body exposed/, # Rite of Grace (ROG) /^The greenish hues about you vanish as the Universal Solvent matrix loses its cohesion/, # Universal Solvent (USOL) /^You sense your Call from Within spell weaken and disperse/ # Call from Within (CFW) ].freeze
- INFUSE_OM_SUCCESS_PATTERNS =
Strings matching successful infusion of mana into Osrel Meraud (OM), a Moon Mage spell.
[ 'having reached its full capacity', 'A sense of fullness', 'Something in the area is interfering with your attempt to harness' ].freeze
- INFUSE_OM_FAILURE_PATTERNS =
Strings matching failed infusion of mana into Osrel Meraud (OM).
[ 'as if it hungers for more', 'Your infusion fails completely', "You don't have enough harnessed mana to infuse that much", 'You have no harnessed' ].freeze
- INFUSE_OM_MAX_RETRIES =
20- PREPARE_MAX_RETRIES =
3- CAST_MAX_RETRIES =
3- PREP_CONFIRM_WAIT_SECONDS =
How long, and how often, prep_confirmed? polls the prepared-spell indicator after prepare? returned '' (see prep_confirmed?).
3- PREP_CONFIRM_POLL_SECONDS =
0.1- BARB_BUFF_MAX_RETRIES =
3- STOW_FOCUS_MAX_RETRIES =
3- WIELD_FOCUS_SUCCESS_PATTERNS =
Game messages matching successful wielding (drawing, grabbing, or obtaining) of a spell focus.
[ /^You draw out/, /^You grab/, /^You slip/, /^You deftly remove/ ].freeze
- WIELD_FOCUS_FAILURE_PATTERNS =
Game messages matching failure to wield a spell focus.
[ /^What were you/, /^Wield what/, /^You need a free hand/ ].freeze
- SHEATHE_FOCUS_SUCCESS_PATTERNS =
Game messages matching successful sheathing, securing, or stowing of a spell focus.
[ /^You sheathe/, /^Sheathing/, /^You secure/, /^You slip/, /^You hang/, /^You strap/, /^You easily strap/ ].freeze
- SHEATHE_FOCUS_FAILURE_PATTERNS =
Game messages matching failure to sheathe a spell focus.
[ /^Sheathe your .* where/, /^There's no room/ ].freeze
- STARLIGHT_MESSAGES =
Trader aura levels in order from faintest to brightest, used to infer aura level from perceive aura output.
[ 'The smallest hint of starlight flickers within your aura', 'A bare flicker of starlight plays within your aura', 'A faint amount of starlight illuminates your aura', 'Your aura pulses slowly with starlight', 'A steady pulse of starlight runs through your aura', 'Starlight dances vividly across the confines of your aura', 'Strong pulses of starlight flare within your aura', 'Your aura seethes with brilliant starlight', 'Your aura is blinding', 'The power contained in your aura' ].freeze
- CHARGE_LEVELS =
Warrior Mage elemental charge levels (0-11) in order, matched from pathway sense output. Each pattern matches one charge level; use the pattern's index to get the level (0 = no charge, 11 = maximum).
[ /^You sense nothing out of the ordinary. Only magic could detect the useless trace of .* still in your system.$/, /^A small charge lingers within your body, just above the threshold of perception.$/, /^A small charge lingers within your body.$/, /^A charge dances through your body.$/, /^A charge dances just below the threshold of discomfort.$/, /^A charge circulates through your body, causing a low hum to vibrate through your bones.$/, /^Elemental essence floats freely within your body, leaving little untouched.$/, /^Elemental essence has infused every inch of your body. While you could contain more, you'd do so at the risk of your health.$/, /^Extraplanar power crackles within your body, leaving you feeling mildly feverish.$/, /^Extraplanar power crackles within your body, leaving you feeling acutely ill.$/, /^Your body sings and crackles with a barely contained charge, destroying what little cenesthesia you had left.$/, /^You have reached the limits of your body's capacity to store a charge. The laws of the Elemental Plane of .* scream demands upon your physiology, threatening your life.$/ ].freeze
- PERC_MANA_START_PATTERN =
Regexp matching the start of Moon Mage PERC MANA output.
/streams of .* mana/- PERC_MANA_END_PATTERN =
Regexp matching the end of Moon Mage PERC MANA output.
/Roundtime/- PERC_MANA_BOOK_PATTERN =
One line of a Moon Mage's PERC MANA reply, one per Lunar spellbook, e.g. "You reach out with your senses and see glaring (19/21) streams of cold, white Lunar mana available for the Illusion book."
%r{\A\s*You reach out with your .+? and (?:see|hear) (?<adj>\w+) (?:\((?<level>\d+)/(?<max>\d+)\) )?streams of .* mana available for the (?<book>.+?) book}- SYMBIOSIS_PATTERN =
Regexp matching successful perception of active symbiotic research, with named capture :type for the symbiosis type.
/combine the weaves of the (?<type>\w+) symbiosis/- DISCERN_SORCERY_PATTERN =
Regexp matching discern output for sorcery spells, with named capture :min for the minimum mana streams required.
/requires at minimum (?<min>\d+) mana streams/- DISCERN_FULL_PATTERN =
Regexp matching full discern output for non-sorcery spells, with named captures :min (base mana) and :more (reinforcement mana).
/minimum (?<min>\d+) mana streams and you think you can reinforce it with (?<more>\d+) more/i- DISCERN_RETRY_SECONDS =
Seconds check_discern waits before discerning a spell again after a discern drew no recognised reply, at most check_discern_timer_in_hours.
300- USELESS_RUNESTONE_PATTERNS =
Game messages matching retrieval of a useless (expended) runestone.
[ /^You get a useless/ ].freeze
- GET_RUNESTONE_SUCCESS_PATTERNS =
Game messages matching successful retrieval of a runestone.
[ /^You get/, /^You pick up/ ].freeze
- GET_RUNESTONE_FAILURE_PATTERNS =
Game messages matching failure to retrieve a runestone.
[ /^What were you referring to/, /^I could not find/ ].freeze
- ZERO_WIDTH_PROBE =
Probe text for #zero_width_pattern?: a short sentence, a pangram in both cases, every digit and every ASCII punctuation mark, then a double space and a sentence ending the probe with a period. Word-boundary assertions and lookarounds for any single printable character, a double space, a line-final period, or a word in the probe find a position to match at. Must stay ASCII-only: a non-ASCII probe raises Encoding::CompatibilityError (not a RegexpError) against a binary pattern that carries high bytes.
%q(You a. 1! The quick brown fox jumps over the lazy dog, THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG 0123456789 !"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ You a.)
Class Method Summary collapse
-
.activate_barb_buff?(name, meditation_pause_timer = 20, sit_to_meditate = false, retries: BARB_BUFF_MAX_RETRIES) ⇒ Boolean
Activates a single Barbarian active ability, retrying on positioning failures.
-
.activate_khri?(settings_kneel, ability) ⇒ Boolean
Needs to handle (based on current usage): - Hasten - Delay Hasten - Hasten Focus - Delay Hasten Focus - Khri Hasten - Khri Delay Hasten - Khri Delay Hasten Focus.
-
.allocate_cambrinth_charges(mana, cambrinth_items, num_charges) ⇒ Object
Works out how to charge an amount of mana into the cambrinth items.
-
.backfired? ⇒ Boolean
Returns whether the most recent cast via #cast? backfired.
-
.calculate_mana(min, more, discern_data, cyclic_or_ritual, settings) ⇒ void
private
Calculates prep mana and cambrinth charge distribution from discern min + reinforcement.
-
.calculate_mana_by_item(total, remaining, discern_data, cyclic_or_ritual, settings) ⇒ Object
Opt in with cambrinth_distribute_charges.
-
.calculate_mana_by_ratio(total, remaining, discern_data, cyclic_or_ritual, settings) ⇒ Object
Default.
-
.cambrinth_caps(settings) ⇒ Object
Signature of the configured cambrinth items.
-
.cambrinth_charge_counts(allocations, num_charges) ⇒ Object
Gives one charge to every item that holds mana, then spends what is left of the charge budget on the largest charge, while that makes it smaller.
-
.cambrinth_item_cap(item) ⇒ Object
The mana capacity of one cambrinth item.
-
.cast?(cast_command = 'cast', symbiosis = false, before = [], after = [], custom_cast_message = nil, retries: CAST_MAX_RETRIES) ⇒ Boolean
Casts the prepared spell, inferring success from the absence of a failure flag (see the Flags below), and handling the WM barrage fallback and the cyclic-too-recent / full-preparation retry cases.
-
.cast_spell(data, settings, force_cambrinth = false, cast_lifecycle_lambda = nil) ⇒ Boolean?
Executes the full spell casting workflow: prepare, charge, cast, with optional ritual or runestone handling.
-
.cast_spell?(data, settings, force_cambrinth = false, cast_lifecycle_lambda = nil) ⇒ Boolean
Wrapper around #cast_spell that returns true/false instead of the spell result.
-
.cast_spells(spells, settings, force_cambrinth = false, cast_lifecycle_lambda = nil) ⇒ void
Casts multiple spells in sequence, managing mana and concentration thresholds.
-
.charge?(cambrinth, mana) ⇒ Boolean
Charges a cambrinth item with a mana amount, handling skill and positioning errors.
-
.charge_and_invoke(cambrinth, dedicated_camb_use, charges, invoke_exact_amount = nil) ⇒ void
Charges a cambrinth item with mana and invokes it, stopping if any charge fails.
-
.charge_avtalia(cambrinth, charge_amount) ⇒ void
private
Charges cambrinth for an avatar script (avtalia), updating its mana tracker with decay estimation.
-
.charge_cambrinth_items(data, settings) ⇒ void
private
Charges one or more cambrinth items for the prepared spell.
-
.charge_cambrinth_items_by_item(data, settings) ⇒ Object
Opt in with cambrinth_distribute_charges.
-
.charge_cambrinth_items_repeated(data, settings) ⇒ Object
Default.
-
.check_discern(data, settings, spell_is_sorcery = false, more_override = nil) ⇒ Hash
Discerns a spell's mana requirements and caches the result for future casts.
-
.check_elemental_charge ⇒ Object
Determine the numerical range of a Warrior Mage's elemental charge.
-
.check_to_harness(should_harness) ⇒ Boolean
Determines whether to harness mana (sorcery) or charge cambrinth.
-
.choose_avtalia(charge_needed, mana_percentage) ⇒ Array(String, Hash)?
private
Selects the best avatar cambrinth item to charge from (avtalia script only).
-
.crafting_cast_spell(data, settings) ⇒ Boolean
Casts a spell without the full prep workflow, for use during crafting rituals.
-
.crafting_magic_routine(settings) ⇒ void
Supports automated spell casting during crafting to train Warding, Utility, Augmentation, and optionally Sorcery.
-
.crafting_prepare_spell(data, settings) ⇒ String, false
Prepares a spell without casting, for use during crafting rituals (e.g., alchemy, forging).
-
.custom_message_pattern(message) ⇒ Regexp?
Compiles a single player-supplied message into a case-insensitive Regexp for use as a bput pattern, matching how bput treats the built-in string patterns; leading/trailing whitespace is trimmed so an accidental space in yaml does not silently break matching.
-
.day_night_ok?(data) ⇒ Boolean
Whether a spell's day/night restriction allows casting it now: a 'night' spell only at night, a 'day' spell only by day, anything else always.
-
.discern_retry_pending?(discern_data, settings) ⇒ Boolean
private
Whether a discern that drew no recognised reply was sent too recently to try again: within DISCERN_RETRY_SECONDS, or within check_discern_timer_in_hours when that is shorter.
-
.distribute_cambrinth_charges(charge_values, cambrinth_items) ⇒ Object
Packs a flat list of charge values into the cambrinth items.
-
.do_buffs(settings, set_name) ⇒ void
Casts all buffs in a named waggle set, handling guild-specific buff activation.
-
.find_cambrinth(cambrinth, stored_cambrinth, cambrinth_cap) ⇒ Boolean
Ensures cambrinth is in hand or ready for charging, based on config and skill.
-
.find_charge_invoke_stow(cambrinth, stored_cambrinth, cambrinth_cap, dedicated_camb_use, charges, invoke_exact_amount = nil) ⇒ void
Orchestrates the full cambrinth workflow: find, charge, invoke, and stow.
-
.find_focus(focus, worn, tied, sheathed) ⇒ void
Retrieves a spell focus from storage based on how it is equipped.
-
.get_runestone?(runestone, settings) ⇒ Boolean
private
Retrieves a runestone from storage into hands, or verifies it is already held.
-
.harness?(mana) ⇒ Boolean
Attempts to harness mana for sorcery spellcasting.
-
.harness_mana(amounts) ⇒ void
Iterates through an array of mana amounts, harnessing each via #harness? until one fails.
-
.infuse_om(harness, amount) ⇒ void
Repeatedly attempts to infuse mana into Osrel Meraud (OM), a Moon Mage cyclic spell that stores mana.
-
.invoke(cambrinth, dedicated_camb_use, invoke_amount) ⇒ void
Invokes a cambrinth item to release charged mana into the prepared spell.
-
.invoke_avtalia(cambrinth, dedicated_camb_use, invoke_amount) ⇒ void
private
Invokes cambrinth for an avatar script (avtalia), updating its mana tracker.
-
.invoke_messages(spell_custom_invoke_message = nil) ⇒ Array<String, Regexp>
The bput patterns for invoking: the built-in invoke messages plus the player's custom_invoke_message additions -- the per-character one (their ritual focus, from settings) and, for a runestone spell, the per-spell one from the spell's data.
-
.kneel_for_khri?(kneel, ability) ⇒ Boolean
private
Determines whether to kneel before activating a specific Khri ability.
-
.need_buffs?(buff_list) ⇒ Boolean
Determines whether any buffs are missing or need recasting.
-
.normalize_cambrinth_items(settings) ⇒ void
private
Converts legacy single-cambrinth settings into the multi-item format.
-
.parse_mana_message(mana_msg) ⇒ Integer
private
Parses the adjective from a PERC message and returns the mana level (1-21).
-
.parse_regalia ⇒ Array<String>?
Parses the player's worn combat regalia (rough-cut, faceted, or resplendent crystals).
-
.perc_aura ⇒ Hash?
Perceives the player's aura (Traders only) and returns its level, cap status, and growth status.
-
.perc_mana ⇒ Hash{String => Integer}, ...
Perceives the local mana level.
-
.perc_symbiotic_research ⇒ Object
check which symbiotic research is active.
-
.prep_confirmed?(prep_result, abbrev, command: 'prepare', runestone_name: nil) ⇒ Boolean
Whether a #prepare? result means a spell is now being prepared, so a caller can go on to charge cambrinth, harness mana, invoke a focus or cast.
-
.prepare?(abbrev, mana, symbiosis = false, command = 'prepare', tattoo_tm = false, runestone_name = nil, runestone_tm = false, custom_prep_message = nil, custom_invoke_message: nil, custom_spell_prep: nil, retries: PREPARE_MAX_RETRIES) ⇒ String, false
Prepares a spell -- via a normal prep, or by invoking a runestone when
runestone_nameis given -- retrying the transient "desire slips away" case and bailing on hard failures. -
.prepare_to_cast_runestone?(spell, settings) ⇒ Boolean
private
Pre-flight check for runestone casting: verifies the runestone is in storage or obtains it.
-
.release_cyclics(cyclic_no_release = []) ⇒ void
Releases all active cyclic spells except those in the exclusion list.
-
.release_magical_research ⇒ Object
release symbiotic research.
-
.ritual(data, settings) ⇒ Boolean?
Executes the full ritual spell casting workflow: prepare, find/invoke focus, cast, and cleanup.
-
.segue?(abbrev, mana) ⇒ Boolean
Attempts a bard Segue from a currently prepared cyclic spell.
-
.shatter_regalia?(worn_regalia = nil) ⇒ Boolean
Shatters worn crystal regalia for Traders, returning them to motes of silvery light.
-
.skilled_to_charge_while_worn?(cambrinth_cap) ⇒ Boolean
Determines whether current Arcana skill is high enough to charge a worn cambrinth without dropping it.
-
.spell_prepared? ⇒ Boolean
Returns true if you're prepared to cast your spell.
-
.spell_preparing ⇒ Object
Returns name of the spell being prepared, or nil if not preparing one.
-
.spell_preparing? ⇒ Boolean
Returns true if preparing a spell, false otherwise.
-
.split_cambrinth_charges(total_mana, num_charges) ⇒ Object
Splits an amount of mana into num_charges charge values, largest first.
-
.spread_flat_cambrinth_charges(charge_values, cambrinth_items) ⇒ Object
Turns one flat list of charge values, as written in a spell config, into one list for each cambrinth item.
-
.stale_cambrinth_caps?(discern_data, settings) ⇒ Boolean
True when cached discern data was calculated against a different set of cambrinth items.
-
.start_barb_abilities(abilities, settings) ⇒ void
Activates a list of Barbarian active abilities (buffs) in sequence.
-
.start_khris(khris, settings) ⇒ void
Activates a list of Thief Khri abilities in sequence.
-
.stow_cambrinth(cambrinth, stored_cambrinth, _cambrinth_cap) ⇒ Boolean
Returns cambrinth to storage or wear, based on config.
-
.stow_focus(focus, worn, tied, sheathed, retries: STOW_FOCUS_MAX_RETRIES) ⇒ Boolean, void
Returns a spell focus to storage based on how it should be equipped.
-
.update_avtalia ⇒ void
private
Queries the current mana in the player's avatar cambrinth item (avtalia script only).
-
.usable_cambrinth_indexes(cambrinth_items, num_charges) ⇒ Object
Every item that holds mana needs at least one charge, so the charge budget limits how many items can be used.
-
.with_custom_messages(base_messages, *custom_messages) ⇒ Array<String, Regexp>
Appends the player's validated custom message patterns to a built-in message list.
-
.zero_width_pattern?(pattern) ⇒ Boolean
Whether
patterncan succeed without consuming any text -- e.g.
Class Method Details
.activate_barb_buff?(name, meditation_pause_timer = 20, sit_to_meditate = false, retries: BARB_BUFF_MAX_RETRIES) ⇒ Boolean
Reads get_data('spells').barb_abilities for ability metadata (start_command, activated_message, type).
Activates a single Barbarian active ability, retrying on positioning failures. Returns immediately (true) if the ability is already active per DRSpells. For meditation-type abilities and sit_to_meditate=true, sits before attempting activation. Handles failures: retreats and retries on unengaged/sitting/standing requirements; on water, logs bold message and returns false. Pauses for meditation_pause_timer seconds after successful meditation activation to let it take effect.
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 373 def (name, meditation_pause_timer = 20, sit_to_meditate = false, retries: BARB_BUFF_MAX_RETRIES) # Note, you must know Power meditation or Powermonger mastery # for your active abilities to be detected by DRSpells. return true if DRSpells.active_spells[name] if retries <= 0 Lich::Messaging.msg("bold", "DRCA: activate_barb_buff? exhausted #{BARB_BUFF_MAX_RETRIES} retries for '#{name}' - giving up") return false end activated = false ability_data = get_data('spells').[name] if ability_data['type'].eql?('meditation') && sit_to_meditate DRC.retreat DRC.bput('sit', 'You sit', 'You are already', 'You rise', 'While swimming?') end case DRC.bput(ability_data['start_command'], ability_data['activated_message'], 'You have not been trained', 'But you are already', 'Your inner fire lacks', 'find yourself lacking the inner fire', 'You should stand', 'You must be sitting', 'You must be unengaged', 'While swimming?') when 'You must be unengaged' DRC.retreat activated = (name, meditation_pause_timer, sit_to_meditate, retries: retries - 1) when 'You must be sitting' DRC.retreat case DRC.bput('sit', 'You sit', 'You are already', 'You rise', 'While swimming?') when 'While swimming?' Lich::Messaging.msg("bold", "DRCA: cannot sit to activate '#{name}' - water is too deep") activated = false else activated = (name, meditation_pause_timer, sit_to_meditate, retries: retries - 1) end when 'You should stand' DRC.fix_standing activated = (name, meditation_pause_timer, sit_to_meditate, retries: retries - 1) when /#{ability_data['activated_message']}/ # Pause at least for the preferred amount of time # to let the meditation take effect else it may fail. if ability_data['type'].eql?('meditation') && meditation_pause_timer pause meditation_pause_timer end # Wait for any remaining RT before proceeding waitrt? activated = true else activated = false end DRC.fix_standing activated end |
.activate_khri?(settings_kneel, ability) ⇒ Boolean
Needs to handle (based on current usage):
- Hasten
- Delay Hasten
- Hasten Focus
- Delay Hasten Focus
- Khri Hasten
- Khri Delay Hasten
- Khri Delay Hasten Focus
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 309 def activate_khri?(settings_kneel, ability) abilities = ability.split.map(&:capitalize) # Standardize for with/without 'Khri' on the front abilities = abilities.drop(1) if abilities.first.casecmp('khri') == 0 # Handling for 'Delay' should_delay = abilities.first.casecmp('delay') == 0 abilities = abilities.drop(1) if should_delay # Check each khri in the list against Active Spells, Drop any that are active needed_abilities = abilities.select { |ability_to_check| DRSpells.active_spells["Khri #{ability_to_check}"].nil? } return true if needed_abilities.empty? kneel = needed_abilities.any? { |ability_to_check| kneel_for_khri?(settings_kneel, ability_to_check) } DRC.retreat if kneel DRC.bput('kneel', 'You kneel', 'You are already', 'You rise', "While swimming? Don't be silly") if kneel && !kneeling? result = DRC.bput("Khri #{should_delay ? 'Delay ' : ''}#{needed_abilities.join(' ')}", get_data('spells').khri_preps) waitrt? DRC.fix_standing return ['Your mind and body are willing', 'Your body is willing', 'You have not recovered'].none?(result) end |
.allocate_cambrinth_charges(mana, cambrinth_items, num_charges) ⇒ Object
Works out how to charge an amount of mana into the cambrinth items.
Each item takes as much as its cap allows, in the order the config lists them, so a small worn item fills before a large stored one. Each item then splits its own share into charges. Returns the per-item nested array and the mana that fits in no item.
1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1625 def allocate_cambrinth_charges(mana, cambrinth_items, num_charges) return [[], mana] if mana <= 0 || num_charges <= 0 return [[], mana] if cambrinth_items.nil? || cambrinth_items.empty? allocations = Array.new(cambrinth_items.length, 0) unallocated = mana usable_cambrinth_indexes(cambrinth_items, num_charges).each do |index| allocations[index] = [unallocated, cambrinth_item_cap(cambrinth_items[index])].min unallocated -= allocations[index] end counts = cambrinth_charge_counts(allocations, num_charges) distribution = allocations.each_with_index.map do |allocation, index| split_cambrinth_charges(allocation, counts[index]) end # Drop trailing empty entries so unused items are skipped entirely. [distribution.reverse.drop_while(&:empty?).reverse, unallocated] end |
.backfired? ⇒ Boolean
Set by #cast? via the 'spell-backfired' flag; persists across calls.
Returns whether the most recent cast via #cast? backfired.
789 790 791 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 789 def backfired? @backfired_status || false end |
.calculate_mana(min, more, discern_data, cyclic_or_ritual, settings) ⇒ void
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.
This method returns an undefined value.
Calculates prep mana and cambrinth charge distribution from discern min + reinforcement.
Applies prep_scaling_factor, calculates base prep as ceil(total/5) but at least min. Remaining mana is distributed to cambrinth via #calculate_mana_by_ratio (default) or #calculate_mana_by_item (if cambrinth_distribute_charges is true). For cyclics or rituals, all remaining goes to prep mana (no cambrinth).
1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1535 def calculate_mana(min, more, discern_data, cyclic_or_ritual, settings) total = min + more total = (total * settings.prep_scaling_factor).floor discern_data['mana'] = [(total / 5.0).ceil, min].max remaining = total - discern_data['mana'] normalize_cambrinth_items(settings) # Ignore cambrinth if charges to use is nil or 0 settings.cambrinth_num_charges ||= 0 if settings.cambrinth_distribute_charges calculate_mana_by_item(total, remaining, discern_data, cyclic_or_ritual, settings) else calculate_mana_by_ratio(total, remaining, discern_data, cyclic_or_ritual, settings) end end |
.calculate_mana_by_item(total, remaining, discern_data, cyclic_or_ritual, settings) ⇒ Object
Opt in with cambrinth_distribute_charges. Splits the mana into whole charges, then fills each item up to its cap before it uses the next, the same way cast.lic does. No item goes over its cap and no mana is dropped.
1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1590 def calculate_mana_by_item(total, remaining, discern_data, cyclic_or_ritual, settings) cambrinth_items = settings.cambrinth_num_charges == 0 ? [] : settings.cambrinth_items discern_data['cambrinth_caps'] = cambrinth_caps(settings) total_cambrinth_cap = cambrinth_items.map { |item| item['cap'].to_i }.sum if remaining > total_cambrinth_cap discern_data['mana'] = discern_data['mana'] + (remaining - total_cambrinth_cap) remaining = total - discern_data['mana'] end if cyclic_or_ritual || cambrinth_items.empty? discern_data['cambrinth'] = nil discern_data['mana'] = discern_data['mana'] + remaining elsif remaining > 0 num_charges = remaining >= settings.cambrinth_num_charges ? settings.cambrinth_num_charges : 1 distribution, leftover = allocate_cambrinth_charges(remaining, cambrinth_items, num_charges) # Mana that fits in no cambrinth item goes into the base prep instead. discern_data['mana'] = discern_data['mana'] + leftover discern_data['cambrinth'] = distribution.empty? ? nil : distribution else discern_data['cambrinth'] = nil end end |
.calculate_mana_by_ratio(total, remaining, discern_data, cyclic_or_ritual, settings) ⇒ Object
Default. Splits the mana by the cap ratio of each cambrinth item, then gives every charge of an item the same size. It can charge an item past its cap, and integer division can drop mana. Kept as the default because a change to the charge amounts affects every profile.
1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1554 def calculate_mana_by_ratio(total, remaining, discern_data, cyclic_or_ritual, settings) settings.cambrinth_items = [] if settings.cambrinth_num_charges == 0 total_cambrinth_cap = settings.cambrinth_items.map { |x| x['cap'] }.inject(&:+) || 0 charges_count_floor = remaining >= settings.cambrinth_num_charges ? settings.cambrinth_num_charges : 1 settings.cambrinth_items.each do |item| item['charges'] = ((item['cap'].to_f / total_cambrinth_cap) * charges_count_floor).ceil end total_cambrinth_charges = settings.cambrinth_items.map { |x| x['charges'] }.inject(&:+) || 0 if remaining > total_cambrinth_cap discern_data['mana'] = discern_data['mana'] + (remaining - total_cambrinth_cap) remaining = total - discern_data['mana'] end if cyclic_or_ritual || total_cambrinth_charges == 0 discern_data['cambrinth'] = nil discern_data['mana'] = discern_data['mana'] + remaining elsif remaining > 0 total_cambrinth_mana = [remaining, total_cambrinth_cap].min settings.cambrinth_items.each_with_index do |item, index| discern_data['cambrinth'] ||= [] charge_amount = (total_cambrinth_mana / total_cambrinth_charges) * item['charges'] discern_data['cambrinth'][index] = [] charge_amount.times do |i| # Lich patches NilClass#+ so that nil + 1 is 1. Spell it out here so # that this does not depend on the patch. slot = i % item['charges'] discern_data['cambrinth'][index][slot] = (discern_data['cambrinth'][index][slot] || 0) + 1 end end else discern_data['cambrinth'] = nil end end |
.cambrinth_caps(settings) ⇒ Object
Signature of the configured cambrinth items. A change to it invalidates any cached discern data, because the cached charges are split per item.
1719 1720 1721 1722 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1719 def cambrinth_caps(settings) normalize_cambrinth_items(settings) settings.cambrinth_items.map { |item| item['cap'].to_i } end |
.cambrinth_charge_counts(allocations, num_charges) ⇒ Object
Gives one charge to every item that holds mana, then spends what is left of the charge budget on the largest charge, while that makes it smaller. This keeps each charge inside what the character can channel at once.
1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1657 def cambrinth_charge_counts(allocations, num_charges) counts = allocations.map { |allocation| allocation > 0 ? 1 : 0 } funded = allocations.each_index.select { |index| allocations[index] > 0 } spare = num_charges - funded.length while spare > 0 index = funded.max_by { |i| [allocations[i].to_f / counts[i], allocations[i]] } break if counts[index] >= allocations[index] largest = funded.map { |i| allocations[i].to_f / counts[i] }.max split = funded.map { |i| allocations[i].to_f / (i == index ? counts[i] + 1 : counts[i]) }.max break if split >= largest counts[index] += 1 spare -= 1 end counts end |
.cambrinth_item_cap(item) ⇒ Object
The mana capacity of one cambrinth item. An unset or non-positive cap means the config never declared a limit, so do not enforce one.
1614 1615 1616 1617 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1614 def cambrinth_item_cap(item) cap = item['cap'].to_i cap <= 0 ? Float::INFINITY : cap end |
.cast?(cast_command = 'cast', symbiosis = false, before = [], after = [], custom_cast_message = nil, retries: CAST_MAX_RETRIES) ⇒ Boolean
A timeout counts as success. When nothing cast? accepts (the
cast_messages plus the custom cast message) arrives before bput gives
up (a server stall, or a successful cast whose message is not
listed), bput returns '', which no when arm handles: the
barrage and cyclic/full-prep retry flags still apply, and the result
rests on the spell-fail flag. That flag is read only after the cast
bput, the roundtime wait and the after actions, so
the result is true unless a failure line arrived before then (in
which case mana, and any symbiosis, is released and the result is
false); a failure line that arrives later is missed. This is
deliberate. Mapping a timeout to false would make retry loops such as
until cast_spell?(...) prepare and cast again after a cast that went
off but was not recognised (a stall, or a message that is not listed;
the reason custom_cast_message exists). A missed late failure line is
not always harmless: if it arrives while a later cast? is running,
that call takes it as its own failure, returns false and releases
mana (and any symbiosis) even if its own cast went off.
#cast_spell, #cast_spell? and #crafting_cast_spell pass this
result through (#cast_spell returns nil, and so #cast_spell?
returns false, for a ritual spell, after a successful segue, and
when the prep failed or #prep_confirmed? rejected it, in which
case cast? is not called).
Casts the prepared spell, inferring success from the absence of a failure flag (see the Flags below), and handling the WM barrage fallback and the cyclic-too-recent / full-preparation retry cases.
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 837 def cast?(cast_command = 'cast', symbiosis = false, before = [], after = [], = nil, retries: CAST_MAX_RETRIES) before.each { |action| DRC.bput(action['message'], action['matches']) } Flags.add('unknown-command', "Please rephrase that command") Flags.add('barrage-fail', "That was an invalid attack choice.", "Wouldn't it be better if you used a melee weapon?", "You'll need to be using a weapon to BARRAGE your target", "You must have a fully developed target matrix to make a barrage attack", "You are unable to muster the energy to do that", "You do not know how to manipulate that pathway.", "You cannot BARRAGE with that spell.") Flags.add('spell-fail', 'Currently lacking the skill to complete the pattern', "You don't have a spell prepared!", /^Your spell .*backfires/, 'Something is interfering with the spell', 'There is nothing else to face', 'You strain, but are too mentally fatigued', 'The spell pattern resists the influx of unfocused mana', 'Your target pattern dissipates because') Flags.add('cyclic-too-recent', 'The mental strain of initiating a cyclic spell so recently prevents you from formulating the spell pattern') Flags.add('spell-full-prep', /^This pattern may only be cast with full preparation/) Flags.add('spell-backfired', /^Your spell .*backfires/) = (get_data('spells')., ) case DRC.bput(cast_command || 'cast', ) when /^Your target pattern dissipates/, /^You can't cast that at yourself/, /^You need to specify a body part to consume/, /^There is nothing else to face/ DRC.bput('release spell', 'You let your concentration lapse', "You aren't preparing a spell") DRC.bput('release mana', 'You release all', "You aren't harnessing any mana") when /You gesture/ pause 0.25 end waitrt? # Warrior Mage failed to use (or doesn't know) barrage ability. Do regular cast instead. if cast_command =~ /\b(barrage)\b/i && (Flags['unknown-command'] || Flags['barrage-fail']) return cast?('cast', symbiosis, [], after, , retries: retries - 1) if retries > 0 Lich::Messaging.msg("bold", "DRCA: cast? barrage fallback exhausted retries - giving up") return false end if Flags['cyclic-too-recent'] || Flags['spell-full-prep'] if retries <= 0 Lich::Messaging.msg("bold", "DRCA: cast? exhausted #{CAST_MAX_RETRIES} retries waiting for cyclic/full-prep - giving up") return false end pause 1 Flags.delete('spell-full-prep') return cast?(cast_command, symbiosis, [], after, , retries: retries - 1) end after.each { |action| DRC.bput(action['message'], action['matches']) } if symbiosis && Flags['spell-fail'] DRC.bput('release mana', 'You release all', "You aren't harnessing any mana") DRC.bput('release symbiosis', 'You release', 'But you haven\'t prepared') elsif Flags['spell-fail'] DRC.bput('release mana', 'You release all', "You aren't harnessing any mana") end @backfired_status = Flags['spell-backfired'] !Flags['spell-fail'] end |
.cast_spell(data, settings, force_cambrinth = false, cast_lifecycle_lambda = nil) ⇒ Boolean?
Executes the full spell casting workflow: prepare, charge, cast, with optional ritual or runestone handling.
For Location spells, auto-casts Clear Vision first if not active. If data is true, delegates to #ritual. For runestone spells, verifies runestone is ready via #prepare_to_cast_runestone?. Releases active cyclics (except those to keep), releases any existing prep/mana, then:
- Prepares via #prepare?, confirming with #prep_confirmed?
- Charges cambrinth or harneses mana
- Waits for prep_time or cast readiness
- Casts via #cast?
1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1351 def cast_spell(data, settings, force_cambrinth = false, cast_lifecycle_lambda = nil) return unless data return unless settings data = DRCMM.update_astral_data(data, settings) return unless data # DRCMM.update_astral_data returns nil on failure if (data['abbrev'] =~ /locat/i) && !DRSpells.active_spells['Clear Vision'] cast_spell({ 'abbrev' => 'cv', 'mana' => 1, 'prep_time' => 5 }, settings) end if data['ritual'] ritual(data, settings) return end if data['runestone_name'] return unless prepare_to_cast_runestone?(data, settings) end cast_lifecycle_lambda&.call('pre-prep', data, settings) command = 'prep' command = data['prep'] if data['prep'] command = data['prep_type'] if data['prep_type'] if command == 'segue' return if segue?(data['abbrev'], data['mana']) command = 'prep' end release_cyclics if data['cyclic'] DRC.bput('release spell', 'You let your concentration lapse', "You aren't preparing a spell") unless checkprep == 'None' DRC.bput('release mana', 'You release all', "You aren't harnessing any mana") prepared = prepare?(data['abbrev'], data['mana'], data['symbiosis'], command, data['tattoo_tm'], data['runestone_name'], data['runestone_tm'], data['custom_prep_message'], custom_invoke_message: data['custom_invoke_message'], custom_spell_prep: settings['custom_spell_prep']) return unless prepared DRCI.put_away_item?(data['runestone_name'], settings.runestone_storage) if DRCI.in_hands?(data['runestone_name']) return unless prep_confirmed?(prepared, data['abbrev'], command: command, runestone_name: data['runestone_name']) prepare_time = Time.now normalize_cambrinth_items(settings) if check_to_harness(settings.use_harness_when_arcana_locked) && !force_cambrinth harness_mana(data['cambrinth'].flatten) else charge_cambrinth_items(data, settings) end cast_lifecycle_lambda&.call('post-prep', data, settings) if data['prep_time'] pause until Time.now - prepare_time >= data['prep_time'] else waitcastrt? end cast_lifecycle_lambda&.call('pre-cast', data, settings) spell_cast = cast?(data['cast'], data['symbiosis'], data['before'], data['after'], data['custom_cast_message']) cast_lifecycle_lambda&.call('post-cast', data, settings) spell_cast end |
.cast_spell?(data, settings, force_cambrinth = false, cast_lifecycle_lambda = nil) ⇒ Boolean
Wrapper around #cast_spell that returns true/false instead of the spell result.
1331 1332 1333 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1331 def cast_spell?(data, settings, force_cambrinth = false, cast_lifecycle_lambda = nil) !!cast_spell(data, settings, force_cambrinth, cast_lifecycle_lambda) end |
.cast_spells(spells, settings, force_cambrinth = false, cast_lifecycle_lambda = nil) ⇒ void
This method returns an undefined value.
Casts multiple spells in sequence, managing mana and concentration thresholds.
Infuses OM if the player is a Moon Mage and configured for it. Iterates through spells, skipping those already active (unless recast is needed). Waits for mana and concentration to exceed configured thresholds before each cast.
1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1311 def cast_spells(spells, settings, force_cambrinth = false, cast_lifecycle_lambda = nil) infuse_om(!settings.osrel_no_harness, settings.osrel_amount) spells.each do |name, data| next if DRSpells.active_spells[name] && (data['recast'].nil? || DRSpells.active_spells[name].to_i > data['recast']) while DRStats.mana < settings.waggle_spells_mana_threshold || DRStats.concentration < settings.waggle_spells_concentration_threshold Lich::Messaging.msg("plain", "DRCA: waiting on mana over #{settings.waggle_spells_mana_threshold} or concentration over #{settings.waggle_spells_concentration_threshold}...") pause 15 end cast_spell(data, settings, force_cambrinth, cast_lifecycle_lambda) end end |
.charge?(cambrinth, mana) ⇒ Boolean
Charges a cambrinth item with a mana amount, handling skill and positioning errors.
If 'in no condition' response (encumbrance, etc.), harneses the mana instead. If 'too clumsy' response (arcana skill too low while worn) or 'need to hold it', retrieves the cambrinth into hands and retries; falls back to stow if it cannot be held. If 'absorbs all of the energy', charge succeeded.
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1112 def charge?(cambrinth, mana) charged = false result = DRC.bput("charge my #{cambrinth} #{mana}", get_data('spells')., 'I could not find') pause waitrt? case result when /You are in no condition to do that/ charged = harness?(mana) when /You'll have to hold it/ # You're not wearing nor holding your cambrinth item, go find it again. # Likely it's configured in your yaml that you wear it but it's stowed for some reason. # Try to find the cambrinth and get it to your hands. Lich::Messaging.msg("bold", "DRCA: where did your cambrinth go?") retry_find_cambrinth = true when /you find it too clumsy/ Lich::Messaging.msg("bold", "DRCA: your arcana skill is too low to charge your cambrinth while worn") retry_find_cambrinth = true else charged = result =~ /absorbs? all of the energy/ end if retry_find_cambrinth # If the cambrinth is in your hands and you can't charge it, nothing else to do. unless DRCI.in_hands?(cambrinth) # Otherwise, try to find the cambrinth and get it to your hands. find_cambrinth(cambrinth, false, 999) # If you were able to get the cambrinth into a hand then retry charging it. # You might not have been able to if your hands were full. if DRCI.in_hands?(cambrinth) charged = charge?(cambrinth, mana) stow_cambrinth(cambrinth, false, 999) end end end charged end |
.charge_and_invoke(cambrinth, dedicated_camb_use, charges, invoke_exact_amount = nil) ⇒ void
This method returns an undefined value.
Charges a cambrinth item with mana and invokes it, stopping if any charge fails.
Iterates through charges array calling #charge? for each; breaks on first failure. Then invokes the cambrinth with the total of all charges if invoke_exact_amount is true, or without an amount if false/nil.
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1054 def charge_and_invoke(cambrinth, dedicated_camb_use, charges, invoke_exact_amount = nil) return unless charges&.any? charges.each do |mana| break unless charge?(cambrinth, mana) end invoke_amount = invoke_exact_amount ? charges.inject(0, :+) : nil invoke(cambrinth, dedicated_camb_use, invoke_amount) end |
.charge_avtalia(cambrinth, charge_amount) ⇒ void
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.
This method returns an undefined value.
Charges cambrinth for an avatar script (avtalia), updating its mana tracker with decay estimation. Returns immediately if cambrinth is nil or avtalia script is not running.
If charge fails, resets mana to cap. If charge succeeds, estimates 10% decay every 5 minutes and adjusts the assumed reserve accordingly.
1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1919 def charge_avtalia(cambrinth, charge_amount) return unless cambrinth return unless Script.running?('avtalia') if !charge?(cambrinth, charge_amount) UserVars.avtalia[cambrinth]['mana'] = UserVars.avtalia[cambrinth]['cap'] else # Experiments show very roughly 10% falloff regardless of cap every 10 minutes # Assume 10% every 5 minutes. No falloff in starlight, but that's not tracked ATM. time_diff = Time.now - UserVars.avtalia[cambrinth]['time_seen'] time_mod = (time_diff / 300.0).floor time_adjust = 1 - [time_mod * 0.10, 1.0].min assumed_reserve = (UserVars.avtalia[cambrinth]['mana'] * time_adjust).floor + charge_amount UserVars.avtalia[cambrinth]['mana'] = [assumed_reserve, UserVars.avtalia[cambrinth]['cap']].min end UserVars.avtalia[cambrinth]['time_seen'] = Time.now end |
.charge_cambrinth_items(data, settings) ⇒ void
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.
This method returns an undefined value.
Charges one or more cambrinth items for the prepared spell.
Delegates to #charge_cambrinth_items_repeated (default) or #charge_cambrinth_items_by_item (if cambrinth_distribute_charges is true).
2003 2004 2005 2006 2007 2008 2009 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 2003 def charge_cambrinth_items(data, settings) if settings.cambrinth_distribute_charges charge_cambrinth_items_by_item(data, settings) else charge_cambrinth_items_repeated(data, settings) end end |
.charge_cambrinth_items_by_item(data, settings) ⇒ Object
Opt in with cambrinth_distribute_charges. A flat list is spread over the items instead of charged into every one of them.
2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 2026 def charge_cambrinth_items_by_item(data, settings) charges = data['cambrinth'] return unless charges.is_a?(Array) && !charges.empty? unless charges.first.is_a?(Array) return unless charges.first.is_a?(Integer) charges = spread_flat_cambrinth_charges(charges, settings.cambrinth_items) end settings.cambrinth_items.each_with_index do |item, index| item_charges = charges[index] next if item_charges.nil? || item_charges.empty? find_charge_invoke_stow(item['name'], item['stored'], item['cap'], settings.dedicated_camb_use, item_charges, settings.cambrinth_invoke_exact_amount) end end |
.charge_cambrinth_items_repeated(data, settings) ⇒ Object
Default. A nested cambrinth list gives one entry to each item. A flat list goes to every item in full, so several items each charge the whole list.
2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 2013 def charge_cambrinth_items_repeated(data, settings) settings.cambrinth_items.each_with_index do |item, index| case data['cambrinth'].first when Array find_charge_invoke_stow(item['name'], item['stored'], item['cap'], settings.dedicated_camb_use, data['cambrinth'][index], settings.cambrinth_invoke_exact_amount) when Integer find_charge_invoke_stow(item['name'], item['stored'], item['cap'], settings.dedicated_camb_use, data['cambrinth'], settings.cambrinth_invoke_exact_amount) end end end |
.check_discern(data, settings, spell_is_sorcery = false, more_override = nil) ⇒ Hash
Retreats before discerning; blocks discern retry if one failed too recently.
Discerns a spell's mana requirements and caches the result for future casts.
For sorcery spells (or if spell_is_sorcery=true), discerns only the minimum mana streams, bypassing reinforcement and cambrinth calculations.
For non-sorcery spells, discerns full pattern (minimum + reinforcement) if cache is stale or if a retry window has passed (DISCERN_RETRY_SECONDS or check_discern_timer_in_hours, whichever is shorter). If held or rooted, casts at minimum. On no recognised reply, marks failed_at and will retry later. Caches the result in UserVars.discerns, including cambrinth_caps signature for the distribute_charges path.
Calls #calculate_mana to split the total into prep mana and cambrinth charges. On any failure or minimum, returns minimum = 1 for mana and nil for cambrinth.
1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1451 def check_discern(data, settings, spell_is_sorcery = false, more_override = nil) UserVars.discerns = {} unless UserVars.discerns discern_data = UserVars.discerns[data['abbrev']] || {} held = false if data['symbiosis'] || spell_is_sorcery if discern_data.empty? || discern_data['min'].nil? || more_override DRC.retreat discern_result = DRC.bput("discern #{data['abbrev']}", 'requires at minimum \d+ mana streams') match = discern_result.match(DISCERN_SORCERY_PATTERN) if match discern_data['mana'] = match[:min].to_i discern_data['cambrinth'] = nil discern_data['min'] = match[:min].to_i discern_data['more'] = (more_override || 0) end end calculate_mana(discern_data['min'], discern_data['more'], discern_data, false, settings) elsif (discern_data.empty? || discern_data['time_stamp'].nil? || Time.now - discern_data['time_stamp'] > settings.check_discern_timer_in_hours * 60 * 60 || !discern_data['more'].nil? || stale_cambrinth_caps?(discern_data, settings)) && !discern_retry_pending?(discern_data, settings) DRC.retreat case discern = DRC.bput("discern #{data['abbrev']}", 'The spell requires at minimum \d+ mana streams and you think you can reinforce it with \d+ more', 'You don\'t think you are able to cast this spell', 'You have no idea how to cast that spell', 'You don\'t seem to be able to move to do that') when /you don't think you are able/i, 'You have no idea how to cast that spell' discern_data.delete('failed_at') discern_data['time_stamp'] = Time.now discern_data['mana'] = 1 discern_data['cambrinth'] = nil when 'You don\'t seem to be able to move to do that' # Held or rooted: the reply says nothing about the spell, so this # cast is at the minimum. The stored entry is left alone: it keeps # any earlier real answer, and its time stamp, so the next cast # discerns again. held = true else # Only a real answer is cached. A discern with no recognised reply # is tried again after DISCERN_RETRY_SECONDS, so each cast in # between doesn't pay for another retreat and bput timeout. match = discern.match(DISCERN_FULL_PATTERN) if match discern_data.delete('failed_at') discern_data['time_stamp'] = Time.now calculate_mana(match[:min].to_i, match[:more].to_i, discern_data, data['cyclic'] || data['ritual'], settings) else discern_data['failed_at'] = Time.now end end end waitrt? UserVars.discerns[data['abbrev']] = discern_data # With no stored answer (a discern that drew no recognised reply, and # its retry window), cast at the minimum as when held, not with nil. minimum = held || discern_data['mana'].nil? data['mana'] = minimum ? 1 : discern_data['mana'] data['cambrinth'] = minimum ? nil : discern_data['cambrinth'] data end |
.check_elemental_charge ⇒ Object
Determine the numerical range of a Warrior Mage's elemental charge. This can be used to know if the mage is ready to perform certain abilities, like barrage. Returns a number between 0 (no charge) and 11 (max charge). https://elanthipedia.play.net/Summoning_skill#Charge_levels
1957 1958 1959 1960 1961 1962 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1957 def check_elemental_charge return 0 unless DRStats.warrior_mage? result = DRC.bput("pathway sense", *CHARGE_LEVELS) CHARGE_LEVELS.find_index { |pattern| pattern =~ result } end |
.check_to_harness(should_harness) ⇒ Boolean
Determines whether to harness mana (sorcery) or charge cambrinth. Returns false if should_harness is false, or if Attunement XP >= Arcana XP (Arcana is locked).
1738 1739 1740 1741 1742 1743 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1738 def check_to_harness(should_harness) return false unless should_harness return false if DRSkill.getxp('Attunement') > DRSkill.getxp('Arcana') true end |
.choose_avtalia(charge_needed, mana_percentage) ⇒ Array(String, Hash)?
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.
Selects the best avatar cambrinth item to charge from (avtalia script only). Filters to items seen recently (< 600s), above mana_percentage of cap, and with mana > charge_needed/10. Returns the item with the highest mana.
1945 1946 1947 1948 1949 1950 1951 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1945 def choose_avtalia(charge_needed, mana_percentage) UserVars.avtalia.select { |_camb, data| data['time_seen'] && data['cap'] && data['mana'] } .select { |_camb, data| Time.now - data['time_seen'] < 600.0 } .select { |_camb, data| (data['mana'].to_f / data['cap'].to_f) * 100 >= mana_percentage } .select { |_camb, data| data['mana'] > charge_needed / 10 } .max_by { |_camb, data| data['mana'] } end |
.crafting_cast_spell(data, settings) ⇒ Boolean
Casts a spell without the full prep workflow, for use during crafting rituals. Normalizes cambrinth config, charges or harneses mana, and casts.
Returns nil if data or settings is nil. Does not prepare a spell; assumes one is already prepared or will be prepared separately.
1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1754 def crafting_cast_spell(data, settings) return unless data return unless settings normalize_cambrinth_items(settings) if check_to_harness(settings.use_harness_when_arcana_locked) harness_mana(data['cambrinth'].flatten) else charge_cambrinth_items(data, settings) end cast?(data['cast'], data['symbiosis'], data['before'], data['after'], data['custom_cast_message']) end |
.crafting_magic_routine(settings) ⇒ void
This method returns an undefined value.
Supports automated spell casting during crafting to train Warding, Utility, Augmentation, and optionally Sorcery.
Skips if no training spells configured, mana is below threshold, or cast roundtime is active. If a spell is prepared and cast is ready, casts it. Otherwise, selects the first Warding/Utility/Augmentation skill below 31 XP (or Sorcery if enabled), prioritizing by lowest XP, and prepares its training spell.
1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1804 def crafting_magic_routine(settings) training_spells = settings.crafting_training_spells return if training_spells.empty? return if DRStats.mana <= settings.waggle_spells_mana_threshold if checkcastrt > 0 return elsif !XMLData.prepared_spell.eql?('None') && checkcastrt == 0 spell = XMLData.prepared_spell data = training_spells.find { |_skill, info| info['name'] == spell }.last crafting_cast_spell(data, settings) end return if checkcastrt > 0 needs_training = %w[Warding Utility Augmentation] needs_training.append("Sorcery") if (settings.crafting_training_spells_enable_sorcery && !Script.running?('forge')) || (settings.crafting_training_spells_enable_sorcery && settings.crafting_training_spells_enable_sorcery_forging) needs_training = needs_training.select { |skill| training_spells[skill] } .select { |skill| DRSkill.getxp(skill) < 31 } .sort_by { |skill| [DRSkill.getxp(skill), DRSkill.getrank(skill)] } .first return unless needs_training crafting_prepare_spell(training_spells[needs_training], settings) end |
.crafting_prepare_spell(data, settings) ⇒ String, false
Prepares a spell without casting, for use during crafting rituals (e.g., alchemy, forging). Normalizes cambrinth config, releases active cyclics and existing prep/mana, then prepares.
For lunar spells, skips if no moons are available (via DRCMM.set_moon_data). Returns nil if data or settings is nil, or if DRCMM.set_moon_data returns nil.
1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1777 def crafting_prepare_spell(data, settings) return unless data return unless settings # Skip preparing lunar spell if no moons available return unless DRCMM.set_moon_data(data) release_cyclics if data['cyclic'] DRC.bput('release spell', 'You let your concentration lapse', "You aren't preparing a spell") unless checkprep == 'None' DRC.bput('release mana', 'You release all', "You aren't harnessing any mana") command = 'prep' command = data['prep'] if data['prep'] command = data['prep_type'] if data['prep_type'] prepare?(data['abbrev'], data['mana'], data['symbiosis'], command, data['tattoo_tm'], data['runestone_name'], data['runestone_tm'], data['custom_prep_message'], custom_invoke_message: data['custom_invoke_message'], custom_spell_prep: settings['custom_spell_prep']) end |
.custom_message_pattern(message) ⇒ Regexp?
Compiles a single player-supplied message into a case-insensitive Regexp for use as a bput pattern, matching how bput treats the built-in string patterns; leading/trailing whitespace is trimmed so an accidental space in yaml does not silently break matching. Returns nil -- so the entry is dropped rather than applied -- when the message is not a String, is blank/whitespace-only (an empty pattern compiles to //, matching every line), is not a valid regular expression (which would otherwise raise inside bput), or can match without consuming any text (see #zero_width_pattern?; like //, such a pattern matches every line). Shared guard for every custom_*_message key.
490 491 492 493 494 495 496 497 498 499 500 501 502 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 490 def () return nil unless .is_a?(String) stripped = .strip return nil if stripped.empty? pattern = Regexp.new(stripped, Regexp::IGNORECASE) return nil if zero_width_pattern?(pattern) pattern rescue RegexpError nil end |
.day_night_ok?(data) ⇒ Boolean
Whether a spell's day/night restriction allows casting it now: a 'night' spell only at night, a 'day' spell only by day, anything else always. Reads UserVars.sun, which moonwatch keeps current; with no sun data, day and night spells are both skipped. Scripts that decide whether to cast or wait on a waggle spell should use this so they agree with #do_buffs.
1842 1843 1844 1845 1846 1847 1848 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1842 def day_night_ok?(data) sun = UserVars.sun || {} return false if data['night'] && !sun['night'] return false if data['day'] && !sun['day'] true end |
.discern_retry_pending?(discern_data, settings) ⇒ 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.
Whether a discern that drew no recognised reply was sent too recently to try again: within DISCERN_RETRY_SECONDS, or within check_discern_timer_in_hours when that is shorter.
1514 1515 1516 1517 1518 1519 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1514 def discern_retry_pending?(discern_data, settings) failed_at = discern_data['failed_at'] return false unless failed_at Time.now - failed_at < [DISCERN_RETRY_SECONDS, settings.check_discern_timer_in_hours * 60 * 60].min end |
.distribute_cambrinth_charges(charge_values, cambrinth_items) ⇒ Object
Packs a flat list of charge values into the cambrinth items. Each item is filled up to its cap before the next item is used. Returns the per-item nested array and the mana that fits in no item.
1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1695 def distribute_cambrinth_charges(charge_values, cambrinth_items) pending = Array(charge_values).flatten.map(&:to_i).reject { |value| value <= 0 } return [[], pending.sum] if cambrinth_items.nil? || cambrinth_items.empty? distribution = Array.new(cambrinth_items.length) { [] } charged = Array.new(cambrinth_items.length, 0) leftover = 0 pending.each do |charge_value| index = cambrinth_items.each_index.find do |i| charged[i] + charge_value <= cambrinth_item_cap(cambrinth_items[i]) end if index distribution[index] << charge_value charged[index] += charge_value else leftover += charge_value end end # Drop trailing empty entries so unused items are skipped entirely. [distribution.reverse.drop_while(&:empty?).reverse, leftover] end |
.do_buffs(settings, set_name) ⇒ void
This method returns an undefined value.
Casts all buffs in a named waggle set, handling guild-specific buff activation.
For Barbarians, activates abilities via #start_barb_abilities. For Thieves, activates Khris via #start_khris. For other guilds, filters by day/night restrictions, auto-discerns spells with use_auto_mana=true, and casts via #cast_spells.
1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1860 def do_buffs(settings, set_name) return unless settings.waggle_sets[set_name] spells = settings.waggle_sets[set_name] if DRStats. (spells, settings) elsif DRStats.thief? start_khris(spells, settings) else # Non-mutating select: select! returns nil when it removes nothing, # which skipped the day filter, and it deleted out-of-season spells # from the caller's settings.waggle_sets. spells = spells.select { |_name, data| day_night_ok?(data) } spells.values .select { |spell| spell['use_auto_mana'] } .each { |spell| check_discern(spell, settings) } cast_spells(spells, settings, settings.waggle_force_cambrinth) end end |
.find_cambrinth(cambrinth, stored_cambrinth, cambrinth_cap) ⇒ Boolean
Ensures cambrinth is in hand or ready for charging, based on config and skill.
If stored_cambrinth is true, gets it into hands or removes it from wear. If stored_cambrinth is false but arcana skill is too low to charge while worn (< 2*cap + 100), verifies it is in hands or removes it or gets it. If stored_cambrinth is false and skill is sufficient, assumes it is worn or held and takes no action.
981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 981 def find_cambrinth(cambrinth, stored_cambrinth, cambrinth_cap) if stored_cambrinth # Your config says you keep your cambrinth stowed. # If item not in your hands, maybe you're wearing it by accident? DRCI.get_item_if_not_held?(cambrinth) || DRCI.remove_item?(cambrinth) elsif !skilled_to_charge_while_worn?(cambrinth_cap) # Your config says you wear your cambrinth. # But you're not skilled to charge it while worn. # If item not in your hands, maybe you're wearing it or stowed it by accident? DRCI.in_hands?(cambrinth) || DRCI.remove_item?(cambrinth) || DRCI.get_item?(cambrinth) else # Your config says you wear your cambrinth # and you're skilled to charge it while worn. # Let's hope you're wearing or holding it :) # To verify that would require more commands # and more time, and be more spammy. # For now, no validation or recovery for this scenario. true end end |
.find_charge_invoke_stow(cambrinth, stored_cambrinth, cambrinth_cap, dedicated_camb_use, charges, invoke_exact_amount = nil) ⇒ void
This method returns an undefined value.
Orchestrates the full cambrinth workflow: find, charge, invoke, and stow.
Returns immediately if charges is nil or empty. Calls #find_cambrinth, #charge_and_invoke (with invoke_exact_amount), then #stow_cambrinth.
902 903 904 905 906 907 908 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 902 def find_charge_invoke_stow(cambrinth, stored_cambrinth, cambrinth_cap, dedicated_camb_use, charges, invoke_exact_amount = nil) return unless charges find_cambrinth(cambrinth, stored_cambrinth, cambrinth_cap) charge_and_invoke(cambrinth, dedicated_camb_use, charges, invoke_exact_amount) stow_cambrinth(cambrinth, stored_cambrinth, cambrinth_cap) end |
.find_focus(focus, worn, tied, sheathed) ⇒ void
This method returns an undefined value.
Retrieves a spell focus from storage based on how it is equipped.
Returns immediately if focus is nil. If worn, removes it. If tied, unties it. If sheathed, wields it. Otherwise gets it.
920 921 922 923 924 925 926 927 928 929 930 931 932 933 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 920 def find_focus(focus, worn, tied, sheathed) return unless focus if worn DRCI.remove_item?(focus) elsif tied DRCI.untie_item?(focus, tied) elsif sheathed result = DRC.bput("wield my #{focus}", WIELD_FOCUS_SUCCESS_PATTERNS, WIELD_FOCUS_FAILURE_PATTERNS) WIELD_FOCUS_FAILURE_PATTERNS.none? { |pattern| pattern =~ result } else DRCI.get_item?(focus) end end |
.get_runestone?(runestone, settings) ⇒ 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.
Retrieves a runestone from storage into hands, or verifies it is already held.
Returns true immediately if the runestone is in hands. Attempts to get the runestone from the configured storage location. If a useless (expended) runestone is obtained, disposes it, logs a bold message, and returns false. If retrieval fails, logs a bold message and returns false.
767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 767 def get_runestone?(runestone, settings) return true if DRCI.in_hands?(runestone) result = DRC.bput( "get my #{runestone} from my #{settings.runestone_storage}", USELESS_RUNESTONE_PATTERNS, GET_RUNESTONE_SUCCESS_PATTERNS, GET_RUNESTONE_FAILURE_PATTERNS ) if USELESS_RUNESTONE_PATTERNS.any? { |pat| pat.match?(result) } DRCI.dispose_trash(runestone) Lich::Messaging.msg("bold", "DRCA: got a useless #{runestone} - disposing and giving up") return false elsif GET_RUNESTONE_FAILURE_PATTERNS.any? { |pat| pat.match?(result) } Lich::Messaging.msg("bold", "DRCA: could not find #{runestone} in #{settings.runestone_storage}") return false end true end |
.harness?(mana) ⇒ Boolean
Attempts to harness mana for sorcery spellcasting.
270 271 272 273 274 275 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 270 def harness?(mana) result = DRC.bput("harness #{mana}", 'You tap into', 'Strain though you may') pause 0.5 waitrt? return result =~ /You tap into/ end |
.harness_mana(amounts) ⇒ void
This method returns an undefined value.
Iterates through an array of mana amounts, harnessing each via #harness? until one fails.
282 283 284 285 286 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 282 def harness_mana(amounts) amounts.each do |mana| break unless harness?(mana) end end |
.infuse_om(harness, amount) ⇒ void
This is the first step of a Moongate/Osrel Meraud casting workflow for Moon Mages.
This method returns an undefined value.
Repeatedly attempts to infuse mana into Osrel Meraud (OM), a Moon Mage cyclic spell that stores mana. Returns if OM is not active or has >90 seconds remaining, or if amount is nil. On each attempt, waits until mana > 40, optionally harneses the amount, then sends infuse om command. Retries up to INFUSE_OM_MAX_RETRIES (20) times on failure, pausing 0.5s between attempts.
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 244 def infuse_om(harness, amount) return unless DRSpells.active_spells['Osrel Meraud'] && DRSpells.active_spells['Osrel Meraud'] < 90 return unless amount retries = 0 loop do if retries >= INFUSE_OM_MAX_RETRIES Lich::Messaging.msg("bold", "DRCA: infuse_om exhausted #{INFUSE_OM_MAX_RETRIES} retries - giving up") break end retries += 1 pause 5 while DRStats.mana <= 40 harness_mana([amount]) if harness break if INFUSE_OM_SUCCESS_PATTERNS.include?(DRC.bput("infuse om #{amount}", INFUSE_OM_SUCCESS_PATTERNS, INFUSE_OM_FAILURE_PATTERNS)) pause 0.5 waitrt? end end |
.invoke(cambrinth, dedicated_camb_use, invoke_amount) ⇒ void
Handles the case where arcana is too low to invoke a worn cambrinth by getting it into hands.
This method returns an undefined value.
Invokes a cambrinth item to release charged mana into the prepared spell.
Returns immediately if cambrinth is nil. Sends invoke command with optional dedicated_camb_use flag and invoke_amount. If the invoke fails with 'too clumsy' (arcana skill too low while worn), attempts to retrieve the cambrinth into hands and retry; if successful, re-stows it.
1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1078 def invoke(cambrinth, dedicated_camb_use, invoke_amount) return unless cambrinth result = DRC.bput("invoke my #{cambrinth} #{invoke_amount} #{dedicated_camb_use}".strip, , 'Invoke what?') pause waitrt? case result when /you find it too clumsy/ Lich::Messaging.msg("bold", "DRCA: your arcana skill is too low to invoke your cambrinth while worn") # If the cambrinth is in your hands and you can't invoke it, nothing else to do. unless DRCI.in_hands?(cambrinth) # Otherwise, try to find the cambrinth and get it to your hands. find_cambrinth(cambrinth, false, 999) # If you were able to get the cambrinth into a hand then retry invoking it. # You might not have been able to if your hands were full. if DRCI.in_hands?(cambrinth) invoke(cambrinth, dedicated_camb_use, invoke_amount) stow_cambrinth(cambrinth, false, 999) end end end end |
.invoke_avtalia(cambrinth, dedicated_camb_use, invoke_amount) ⇒ void
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.
This method returns an undefined value.
Invokes cambrinth for an avatar script (avtalia), updating its mana tracker. Returns immediately if cambrinth is nil or avtalia script is not running.
1901 1902 1903 1904 1905 1906 1907 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1901 def invoke_avtalia(cambrinth, dedicated_camb_use, invoke_amount) return unless cambrinth return unless Script.running?('avtalia') invoke(cambrinth, dedicated_camb_use, invoke_amount) UserVars.avtalia[cambrinth]['mana'] -= [DRStats.mana, invoke_amount].min end |
.invoke_messages(spell_custom_invoke_message = nil) ⇒ Array<String, Regexp>
The bput patterns for invoking: the built-in invoke messages plus the player's custom_invoke_message additions -- the per-character one (their ritual focus, from settings) and, for a runestone spell, the per-spell one from the spell's data.
545 546 547 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 545 def ( = nil) (get_data('spells')., get_settings., ) end |
.kneel_for_khri?(kneel, ability) ⇒ 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.
Determines whether to kneel before activating a specific Khri ability.
If kneel is an array, returns true only if the ability (case-insensitive, 'khri ' prefix removed) is in the array. Otherwise returns kneel as-is (true/false).
343 344 345 346 347 348 349 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 343 def kneel_for_khri?(kneel, ability) if kneel.is_a? Array kneel.map(&:downcase).include? ability.downcase.sub('khri ', '') else kneel end end |
.need_buffs?(buff_list) ⇒ Boolean
Does not check recast for spells where recast < 0 (ignite, etf, etc.) unless they are cyclic.
Determines whether any buffs are missing or need recasting.
Returns false if buff_list is nil or empty (no buffs to check). For Commoners, returns true (cannot check active spells). For Barbarians, checks if any buff in the list is not in active spells. For Thieves, parses buff_list as Khri names (stripping 'Khri', 'Delay' prefixes) and checks each against active spells with 'Khri' prefix. For other guilds, checks if any spell is missing or has remaining duration <= recast time (allowing for spell refresh before expiry).
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 432 def need_buffs?(buff_list) # no need to iterate if list of buffs is already empty return false if buff_list.nil? || buff_list.size == 0 # commoner's don't really have a way to check buffs so assume always yes return true if DRStats.guild == "Commoner" # no need to iterate if no buffs active and buff_list is not empty return true if DRSpells.active_spells.empty? case DRStats.guild when 'Barbarian' # barbarian buffs are an array of strings so we can just iterate over it and check if any are not in the active spells hash buff_list.each { |buff| return true if !DRSpells.active_spells.key?("#{buff}") } when 'Thief' # thieves need special handling to convert buff_list to an array of JUST khri names due to the different options supported buff_list.map { |buff| buff.sub(/khri /i, '') } .map { |buff| buff.sub(/delay /i, '') } .join(' ') .split(' ') .each { |khri| return true if !DRSpells.active_spells.key?("Khri #{khri}") } else # for MUs check list of required buffs against list of active spells and their durations/recast buff_list.each do |spell, data| # ignore spells which don't recast (ignite, etf, etc.) but not cyclics next if data['recast'] < 0 && !data['cyclic'] # if any buff is not in the active spells, or whose duration is less than recast, need to buff return true if !DRSpells.active_spells.key?(spell) || DRSpells.active_spells[spell] <= (data['recast'] ? data['recast'] : 1) end end # all buffs were in active spells with longer durations than recast, no need to buff return false end |
.normalize_cambrinth_items(settings) ⇒ void
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.
This method returns an undefined value.
Converts legacy single-cambrinth settings into the multi-item format.
If settings.cambrinth_items is empty or missing the 'name' key, replaces it with a single-item array from settings.cambrinth, cambrinth_cap, and stored_cambrinth.
1984 1985 1986 1987 1988 1989 1990 1991 1992 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1984 def normalize_cambrinth_items(settings) return if settings.cambrinth_items[0]['name'] settings.cambrinth_items = [{ 'name' => settings.cambrinth, 'cap' => settings.cambrinth_cap, 'stored' => settings.stored_cambrinth }] end |
.parse_mana_message(mana_msg) ⇒ Integer
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.
Parses the adjective from a PERC message and returns the mana level (1-21).
Matches 'weak', 'developing', 'improving' or 'good' in the message to select the mana level scale, then extracts the last word (adjective) and finds its index + 1 in that scale.
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1205 def (mana_msg) manalevels = if mana_msg.include? 'weak' $MANA_MAP['weak'] elsif mana_msg.include? 'developing' $MANA_MAP['developing'] elsif mana_msg.include? 'improving' $MANA_MAP['improving'] else $MANA_MAP['good'] end adj = mana_msg.split(' ')[-1] manalevels.index(adj).to_i + 1 end |
.parse_regalia ⇒ Array<String>?
Parses the player's worn combat regalia (rough-cut, faceted, or resplendent crystals). Returns nil for non-Traders.
1170 1171 1172 1173 1174 1175 1176 1177 1178 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1170 def parse_regalia return unless DRStats.trader? snapshot = Lich::Util.issue_command("inv combat", /All of your worn combat|You aren't wearing anything like that/, /Use INVENTORY HELP for more options/, usexml: false, include_end: false) .map(&:strip) regalia_items = snapshot - ["All of your worn combat equipment:", "You aren't wearing anything like that."] regalia_items.select { |item| item.include?('rough-cut crystal') || item.include?('faceted crystal') || item.include?('resplendent crystal') } .map { |item| DRC.get_noun(item) } end |
.perc_aura ⇒ Hash?
Perceives the player's aura (Traders only) and returns its level, cap status, and growth status.
Returns nil if not a Trader. Sends 'perceive aura' and captures starlight messages to determine aura level (0-9 per STARLIGHT_MESSAGES).
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1282 def perc_aura return unless DRStats.trader? Flags.add('aura-level', Regexp.union(STARLIGHT_MESSAGES)) Flags.add('aura-capped?', 'Your aura contains as much starlight as you can safely handle') Flags.add('aura-growing?', 'Local conditions permit optimal growth of your aura', 'Local conditions are hindering the growth of your aura') aura = {} DRC.bput('perceive aura', 'Roundtime') aura['level'] = Flags['aura-level'] ? STARLIGHT_MESSAGES.index(Flags['aura-level'][0]) : 0 aura['capped'] = Flags['aura-capped?'] ? true : false aura['growing'] = Flags['aura-growing?'] ? true : false Flags.delete('aura-level') Flags.delete('aura-capped?') Flags.delete('aura-growing?') aura end |
.perc_mana ⇒ Hash{String => Integer}, ...
Perceives the local mana level.
A Moon Mage sends PERC MANA and gets one line per Lunar spellbook; the result is a Hash of book name (downcased, spaces as underscores, e.g. 'fabrication', 'illusion', 'noematics') to its level on the 21-step mana scale (1 = faint, 21 = blinding). Only the books named in the reply are keys. The level is the reply's (N/21) figure, or the adjective's place on the scale when the figure is missing or out of some other maximum; a book line with neither is skipped with a bold message. A cut-off reply prints a bold message and returns the books that arrived. Returns nil when no book line was captured.
Other magic users send PERC and get a single Integer level.
1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1236 def perc_mana return nil if DRStats. || DRStats.thief? || DRStats.trader? || DRStats.commoner? if DRStats.moon_mage? lines, complete = DRC.capture_reply( 'perc mana', PERC_MANA_START_PATTERN, PERC_MANA_END_PATTERN, usexml: false, timeout: 5 ) if lines.empty? Lich::Messaging.msg("bold", "DRCA: Failed to capture PERC MANA output (timeout).") return nil end Lich::Messaging.msg("bold", "DRCA: PERC MANA output was cut off (timeout); the result may be incomplete.") unless complete books = lines.each_with_object({}) do |line, levels| match = PERC_MANA_BOOK_PATTERN.match(line) next unless match level = if match[:level] && match[:max].to_i == $MANA_MAP['good'].length match[:level].to_i elsif (idx = $MANA_MAP['good'].index(match[:adj])) idx + 1 end unless level Lich::Messaging.msg("bold", "DRCA: PERC MANA reported an unknown mana level '#{match[:adj]}' for the #{match[:book]} book; skipping it.") next end levels[match[:book].downcase.tr(' ', '_')] = level end books.empty? ? nil : books else mana_msg = DRC.bput('perc', '^You reach out with your .* and (see|hear) \w+') (mana_msg) end end |
.perc_symbiotic_research ⇒ Object
check which symbiotic research is active
1965 1966 1967 1968 1969 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1965 def perc_symbiotic_research result = DRC.bput('perceive', SYMBIOSIS_PATTERN, /Roundtime/) match = result.match(SYMBIOSIS_PATTERN) match ? match[:type] : nil end |
.prep_confirmed?(prep_result, abbrev, command: 'prepare', runestone_name: nil) ⇒ Boolean
Whether a #prepare? result means a spell is now being prepared, so a
caller can go on to charge cambrinth, harness mana, invoke a focus or
cast. A matched prep message counts and false does not. For ''
(bput matched nothing; see #prepare?) the answer comes from the
game's prepared-spell indicator (#spell_preparing?), which the game
sends with its prep reply (on the same line or just before it),
listed or not: it counts if a spell shows as being prepared within
PREP_CONFIRM_WAIT_SECONDS, which also covers a prep reply that lands
just after bput returned early (see #prepare?). Otherwise a bold
message says so, release spell is sent and the result is false.
The game handles commands in order, so during a server stall that
release lands behind the prep still waiting there and cancels it,
rather than leaving it prepared for the next caller (whose own
release is skipped while the indicator still shows no spell) to
charge and cast as its own.
The indicator rule covers preps made with a prep command. An invoke
(a runestone, or a tattoo whose prep command is invoke) is not
checked: there is no record of whether the game sets the indicator
for those, and rejecting a real invoke would leave its spell
prepared and uncast. For them '' counts, as it did before.
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 675 def prep_confirmed?(prep_result, abbrev, command: 'prepare', runestone_name: nil) return false unless prep_result return true unless prep_result == '' return true if runestone_name || command.to_s.strip.match?(/\Ainvoke\b/i) polls = (PREP_CONFIRM_WAIT_SECONDS / PREP_CONFIRM_POLL_SECONDS).round polls.times do return true if spell_preparing? pause PREP_CONFIRM_POLL_SECONDS end return true if spell_preparing? Lich::Messaging.msg("bold", "DRCA: no prep reply was recognised for '#{abbrev}' and no spell is being prepared - not casting") DRC.bput('release spell', 'You let your concentration lapse', "You aren't preparing a spell") false end |
.prepare?(abbrev, mana, symbiosis = false, command = 'prepare', tattoo_tm = false, runestone_name = nil, runestone_tm = false, custom_prep_message = nil, custom_invoke_message: nil, custom_spell_prep: nil, retries: PREPARE_MAX_RETRIES) ⇒ String, false
A timeout is not a failure. When nothing prepare? accepts (the
prep_messages plus the custom prep messages, or #invoke_messages
for a runestone) arrives before bput gives up, bput returns ''
and prepare? returns it unchanged, after still sending the
tattoo/runestone target. A timeout is ambiguous: the prep may
have succeeded with a message that is not in the list (the reason
custom_prep_message exists) or with a reply delayed by a server
stall, and returning false there would abort a real prep. It can
also mean nothing was prepared at all. Callers that would otherwise
charge cambrinth, harness mana or cast on the strength of this
result should pass it to #prep_confirmed?, which accepts ''
after a prep command only when the game shows a spell being
prepared (and after an invoke as is). #cast_spell and
#ritual do; #crafting_prepare_spell returns the result as is.
Prepares a spell -- via a normal prep, or by invoking a runestone when
runestone_name is given -- retrying the transient "desire slips away"
case and bailing on hard failures.
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 597 def prepare?(abbrev, mana, symbiosis = false, command = 'prepare', tattoo_tm = false, runestone_name = nil, runestone_tm = false, = nil, custom_invoke_message: nil, custom_spell_prep: nil, retries: PREPARE_MAX_RETRIES) return false unless abbrev = (get_data('spells')., , custom_spell_prep) DRC.bput('prepare symbiosis', 'You recall the exact details of the', 'But you\'ve already prepared', 'Please don\'t do that here') if symbiosis if runestone_name.nil? match = DRC.bput("#{command} #{abbrev} #{mana}", ) else match = DRC.bput("#{command} my #{runestone_name}", ()) end case match when 'Your desire to prepare this offensive spell suddenly slips away' if retries <= 0 Lich::Messaging.msg("bold", "DRCA: prepare? exhausted #{PREPARE_MAX_RETRIES} retries for '#{abbrev}' - giving up") return false end pause 1 return prepare?(abbrev, mana, symbiosis, command, tattoo_tm, runestone_name, runestone_tm, , custom_invoke_message: , custom_spell_prep: custom_spell_prep, retries: retries - 1) when 'Something in the area interferes with your spell preparations', 'You shouldn\'t disrupt the area right now', 'You have no idea how to cast that spell', 'You have yet to receive any training in the magical arts', 'Please don\'t do that here', 'You cannot use the tattoo while maintaining the effort to stay hidden' DRC.bput('release symbiosis', 'You release the', 'But you haven\'t') if symbiosis return false when 'Well, that was fun' DRCI.dispose_trash(runestone_name) return false when 'You\'ll have to hold it' return false end DRC.bput("target", ) if tattoo_tm || runestone_tm match end |
.prepare_to_cast_runestone?(spell, settings) ⇒ 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.
Pre-flight check for runestone casting: verifies the runestone is in storage or obtains it.
Returns false if the runestone is in storage but #get_runestone? fails to retrieve it. Logs a bold message and returns false if the runestone is not in the configured storage location.
746 747 748 749 750 751 752 753 754 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 746 def prepare_to_cast_runestone?(spell, settings) if DRCI.inside?("#{spell['runestone_name']}", settings.runestone_storage) return false unless get_runestone?(spell['runestone_name'], settings) else Lich::Messaging.msg("bold", "DRCA: out of #{spell['runestone_name']}!") return false end true end |
.release_cyclics(cyclic_no_release = []) ⇒ void
This method returns an undefined value.
Releases all active cyclic spells except those in the exclusion list.
Retrieves cyclic spells from spell data, filters for those in active_spells, excludes any in cyclic_no_release, and sends 'release abbrev' for each.
1156 1157 1158 1159 1160 1161 1162 1163 1164 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1156 def release_cyclics(cyclic_no_release = []) get_data('spells') .spell_data .select { |_name, properties| properties['cyclic'] } .select { |name, _properties| DRSpells.active_spells.keys.include?(name) } .reject { |name| cyclic_no_release.include?(name) } .map { |_name, properties| properties['abbrev'] } .each { |abbrev| DRC.bput("release #{abbrev}", CYCLIC_RELEASE_SUCCESS_PATTERNS, 'Release what?') } end |
.release_magical_research ⇒ Object
release symbiotic research
1972 1973 1974 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1972 def release_magical_research 2.times { DRC.bput("release symbiosis", "Are you sure", "You intentionally wipe", "But you haven't") } end |
.ritual(data, settings) ⇒ Boolean?
Rituals are for spells requiring manual focus handling (rune, augment, etc.).
Executes the full ritual spell casting workflow: prepare, find/invoke focus, cast, and cleanup.
Steps: retreat, release invisibility, prepare spell (retrying on transients), find focus (worn/tied/sheathed), invoke focus, stow focus, wait for prep_time or cast readiness, then cast. Respects skip_retreat flag and uses tattoo_tm or runestone_tm to re-target after prep.
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 703 def ritual(data, settings) DRC.retreat(settings.ignored_npcs) unless data['skip_retreat'] DRC.release_invisibility DRC.set_stance('shield') unless data['skip_retreat'] command = 'prepare' command = data['prep'] if data['prep'] command = data['prep_type'] if data['prep_type'] # As in cast_spell: drop a spell left prepared by an earlier caller, so # the focus invoke and the cast below act on this ritual's prep. DRC.bput('release spell', 'You let your concentration lapse', "You aren't preparing a spell") unless checkprep == 'None' prepared = prepare?(data['abbrev'], data['mana'], data['symbiosis'], command, data['tattoo_tm'], data['runestone_name'], data['runestone_tm'], data['custom_prep_message'], custom_invoke_message: data['custom_invoke_message'], custom_spell_prep: settings['custom_spell_prep']) return unless prep_confirmed?(prepared, data['abbrev'], command: command, runestone_name: data['runestone_name']) prepare_time = Time.now find_focus(data['focus'], data['worn_focus'], data['tied_focus'], data['sheathed_focus']) invoke(data['focus'], nil, nil) stow_focus(data['focus'], data['worn_focus'], data['tied_focus'], data['sheathed_focus']) DRC.retreat(settings.ignored_npcs) unless data['skip_retreat'] if data['prep_time'] pause until Time.now - prepare_time >= data['prep_time'] else waitcastrt? end return unless cast?(data['cast'], data['symbiosis'], data['before'], data['after'], data['custom_cast_message']) DRC.retreat(settings.ignored_npcs) unless data['skip_retreat'] end |
.segue?(abbrev, mana) ⇒ Boolean
Attempts a bard Segue from a currently prepared cyclic spell. Returns false if segue is not possible (not performing cyclic, too soon, lacking flair). Returns true otherwise.
1424 1425 1426 1427 1428 1429 1430 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1424 def segue?(abbrev, mana) case DRC.bput("segue #{abbrev} #{mana}", get_data('spells').) when 'You must be performing a cyclic spell to segue from', 'It is too soon to segue', 'You are lacking the bardic flair' return false end true end |
.shatter_regalia?(worn_regalia = nil) ⇒ Boolean
Shatters worn crystal regalia for Traders, returning them to motes of silvery light. Returns false for non-Traders or if no regalia is worn.
1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1185 def shatter_regalia?(worn_regalia = nil) return false unless DRStats.trader? worn_regalia ||= parse_regalia return false if worn_regalia.empty? worn_regalia.each do |item| DRC.bput("remove my #{item}", 'into motes of silvery', 'Remove what?', "You .*#{item}") end true end |
.skilled_to_charge_while_worn?(cambrinth_cap) ⇒ Boolean
Determines whether current Arcana skill is high enough to charge a worn cambrinth without dropping it.
Required skill: (cambrinth_cap * 2) + 100.
1038 1039 1040 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1038 def skilled_to_charge_while_worn?(cambrinth_cap) DRSkill.getrank('Arcana').to_i >= ((cambrinth_cap.to_i * 2) + 100) end |
.spell_prepared? ⇒ Boolean
Returns true if you're prepared to cast your spell. Infers this if you're preparing a spell and there's no more prep time to wait.
637 638 639 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 637 def spell_prepared? spell_preparing? && checkcastrt <= 0 end |
.spell_preparing ⇒ Object
Returns name of the spell being prepared, or nil if not preparing one.
642 643 644 645 646 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 642 def spell_preparing name = XMLData.prepared_spell name = nil if name.empty? || name.eql?('None') name end |
.spell_preparing? ⇒ Boolean
Returns true if preparing a spell, false otherwise.
631 632 633 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 631 def spell_preparing? !spell_preparing.nil? end |
.split_cambrinth_charges(total_mana, num_charges) ⇒ Object
Splits an amount of mana into num_charges charge values, largest first. For example, 53 mana over 4 charges becomes [14, 13, 13, 13].
1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1677 def split_cambrinth_charges(total_mana, num_charges) return [] if total_mana <= 0 || num_charges <= 0 charge_values = [] rest = total_mana charges_left = num_charges while rest > 0 && charges_left > 0 next_charge = (rest * 1.0 / charges_left).ceil charge_values << next_charge rest -= next_charge charges_left -= 1 end charge_values end |
.spread_flat_cambrinth_charges(charge_values, cambrinth_items) ⇒ Object
Turns one flat list of charge values, as written in a spell config, into one list for each cambrinth item.
A single item takes the list unchanged. In this path cambrinth_cap feeds the arcana check in skilled_to_charge_while_worn?, not a charge limit, and many configs charge well past it on purpose.
Several items need the list spread over them, because the whole list into every item charges the same mana again for each item.
2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 2053 def spread_flat_cambrinth_charges(charge_values, cambrinth_items) return [charge_values] if cambrinth_items.nil? || cambrinth_items.length <= 1 distribution, leftover = distribute_cambrinth_charges(charge_values, cambrinth_items) return distribution if leftover <= 0 # Never drop mana. What fits nowhere goes to the item with the largest cap. largest = cambrinth_items.each_with_index.max_by { |item, _index| item['cap'].to_i }.last distribution[largest] = (distribution[largest] || []) + [leftover] Lich::Messaging.msg("bold", "DRCA: #{leftover} mana does not fit your cambrinth_items caps and went into your #{cambrinth_items[largest]['name']}. Check those caps.") distribution end |
.stale_cambrinth_caps?(discern_data, settings) ⇒ Boolean
True when cached discern data was calculated against a different set of cambrinth items. Only the cambrinth_distribute_charges path records the signature, so the default path never invalidates on it.
1727 1728 1729 1730 1731 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1727 def stale_cambrinth_caps?(discern_data, settings) return false unless settings.cambrinth_distribute_charges discern_data['cambrinth_caps'] != cambrinth_caps(settings) end |
.start_barb_abilities(abilities, settings) ⇒ void
This method returns an undefined value.
Activates a list of Barbarian active abilities (buffs) in sequence.
357 358 359 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 357 def (abilities, settings) abilities.each { |name| (name, settings.meditation_pause_timer, settings.sit_to_meditate) } end |
.start_khris(khris, settings) ⇒ void
This method returns an undefined value.
Activates a list of Thief Khri abilities in sequence.
294 295 296 297 298 299 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 294 def start_khris(khris, settings) khris .each do |khri_set| activate_khri?(settings.kneel_khri, khri_set) end end |
.stow_cambrinth(cambrinth, stored_cambrinth, _cambrinth_cap) ⇒ Boolean
Returns cambrinth to storage or wear, based on config.
If stored_cambrinth is true, ensures it is in hands (or removes from wear), then stows it. If stored_cambrinth is false and cambrinth is in hands, tries to wear it, falling back to stow if that fails. If stored_cambrinth is false and cambrinth is not in hands, assumes it is worn and takes no action.
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1012 def stow_cambrinth(cambrinth, stored_cambrinth, _cambrinth_cap) if stored_cambrinth # Your config says you keep your cambrinth stowed. # If item not in your hands and not stowed, maybe you're wearing it by accident? DRCI.get_item_if_not_held?(cambrinth) || DRCI.remove_item?(cambrinth) DRCI.stow_item?(cambrinth) elsif DRCI.in_hands?(cambrinth) # Your config says you wear your cambrinth. # For some reason it's currently in your hands. # If can't wear item for some reason then stow it. DRCI.wear_item?(cambrinth) || DRCI.stow_item?(cambrinth) else # Your config says you wear your cambrinth # and you're not currently holding it so # we'll assume you're wearing it. # No further action needed. true end end |
.stow_focus(focus, worn, tied, sheathed, retries: STOW_FOCUS_MAX_RETRIES) ⇒ Boolean, void
Returns a spell focus to storage based on how it should be equipped.
Returns immediately if focus is nil. If worn, wears it. If tied, ties it (retrying on failure with retreat). If sheathed, sheathes it. Otherwise stows it.
946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 946 def stow_focus(focus, worn, tied, sheathed, retries: STOW_FOCUS_MAX_RETRIES) return unless focus if worn DRCI.wear_item?(focus) elsif tied result = DRCI.tie_item?(focus, tied) unless result if retries <= 0 Lich::Messaging.msg("bold", "DRCA: stow_focus exhausted #{STOW_FOCUS_MAX_RETRIES} retries tying #{focus} - giving up") return false end DRC.retreat return stow_focus(focus, worn, tied, sheathed, retries: retries - 1) end result elsif sheathed result = DRC.bput("sheathe my #{focus}", SHEATHE_FOCUS_SUCCESS_PATTERNS, SHEATHE_FOCUS_FAILURE_PATTERNS) SHEATHE_FOCUS_FAILURE_PATTERNS.none? { |pattern| pattern =~ result } else DRCI.stow_item?(focus) end end |
.update_avtalia ⇒ void
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.
This method returns an undefined value.
Queries the current mana in the player's avatar cambrinth item (avtalia script only). Sends 'focus cambrinth' and extracts the mana amount from the response.
1888 1889 1890 1891 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1888 def update_avtalia DRC.bput("focus cambrinth", /^The .+ pulses? .+ (\d+)/, 'dim, almost magically null', '^You let your magical senses wander') waitrt? end |
.usable_cambrinth_indexes(cambrinth_items, num_charges) ⇒ Object
Every item that holds mana needs at least one charge, so the charge budget limits how many items can be used. When there are more items than charges, keep the items with the largest caps.
1647 1648 1649 1650 1651 1652 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 1647 def usable_cambrinth_indexes(cambrinth_items, num_charges) indexes = (0...cambrinth_items.length).to_a return indexes if indexes.length <= num_charges indexes.max_by(num_charges) { |index| cambrinth_item_cap(cambrinth_items[index]) }.sort end |
.with_custom_messages(base_messages, *custom_messages) ⇒ Array<String, Regexp>
Appends the player's validated custom message patterns to a built-in message list. Each custom message is compiled by #custom_message_pattern and silently dropped if blank or invalid. (Duplicate detection is left to config validation, e.g. validate.lic; a duplicate here is merely redundant.)
534 535 536 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 534 def (, *) + .filter_map { || () } end |
.zero_width_pattern?(pattern) ⇒ Boolean
Whether pattern can succeed without consuming any text -- e.g. '.*',
'You|', '(foo)?', '^', '\b' or '(?=.)'. bput returns on the first line a
pattern matches, so such a pattern accepts whatever line arrives first
(returning it, or '') as though it were the expected message. Detected by
an empty-string match, or a zero-length match at any position of
ZERO_WIDTH_PROBE. A lookaround that needs a word or other multi-character
context the probe lacks (e.g. '(?=Your)' or '(?=You feel a surge)') is
not detected; it still makes an empty match, but only on lines that
contain that text. The probe is matched like any game line, so a pattern
with catastrophic backtracking hangs here just as it would inside bput.
517 518 519 520 521 522 523 524 |
# File 'documented/dragonrealms/commons/common-arcana.rb', line 517 def zero_width_pattern?(pattern) return true if pattern.match?('') (0..ZERO_WIDTH_PROBE.length).any? do |position| match = pattern.match(ZERO_WIDTH_PROBE, position) match && match[0].empty? end end |