Module: Lich::DragonRealms::DRCMM

Defined in:
documented/dragonrealms/commons/common-moonmage.rb

Overview

Module for common moonmage script utilities in DragonRealms. Provides methods for celestial observations, divination tools, moon weapon handling, and moonwatch data management.

Constant Summary collapse

MOON_WEAPON_REGEX =

Moon weapon detection regex. Matches summoned moon weapons in hand. Colors: black (Katamba), red-hot (Yavash), blue-white (Xibar).

/^(?:black|red-hot|blue-white) moon(?:blade|staff)$/i.freeze
MOON_WEAPON_NAMES =

Canonical moon weapon base names for glance/hold operations.

['moonblade', 'moonstaff'].freeze
MOON_WEAR_MESSAGES =

Expected game messages when wearing a summoned moon weapon.

["You're already", "You can't wear", "Wear what", "telekinetic"].freeze
MOON_DROP_MESSAGES =

Expected game messages when dropping a summoned moon weapon.

["As you open your hand", "What were you referring to"].freeze
MOON_COLOR_TO_NAME =

Maps moon weapon color adjective to moon name.

{
  'black'      => 'katamba',
  'red-hot'    => 'yavash',
  'blue-white' => 'xibar'
}.freeze
MOON_GLANCE_REGEX =

Regex for extracting moon color from glance output.

/You glance at a .* (?<color>black|red-hot|blue-white) moon(?:blade|staff)/i.freeze
MOON_FOCUS_DURATION_REGEX =

Regex for extracting the spelled-out remaining duration from FOCUSing a moon weapon, e.g. "You judge that the moonblade will last for roughly twenty-nine roisaen." The count is captured as words (a compound like "twenty-nine" or a single word like "five"). The unit is "roisaen" (plural) or "roisan" (singular, i.e. one); one roisaen == 60 seconds.

/will last for roughly (?<count>[a-z][a-z-]*) roisae?n/i.freeze
MOON_FOCUS_EXPIRING_REGEX =

Near expiry (under one roisaen remaining) FOCUS drops the "roughly " form entirely and reports "will last for less than one roisan" -- no spelled count. moon_weapon_duration treats this as 0 roisaen (expiring now).

/will last for less than one roisae?n/i.freeze
DIV_TOOL_VERBS =

Maps divination tool keywords to their use verb.

{
  'charts' => 'review',
  'bones'  => 'roll',
  'mirror' => 'gaze',
  'bowl'   => 'gaze',
  'prism'  => 'raise'
}.freeze
MOON_VISIBILITY_TIMER_THRESHOLD =

Minimum minutes remaining before a celestial body sets to be considered "visible."

4
MOON_NAMES =

The moons moonwatch publishes in UserVars.moons, each with a 'timer'.

%w[katamba yavash xibar].freeze
MOONWATCH_READY_TIMEOUT =

Seconds check_moonwatch waits, after starting moonwatch or when moonwatch is already running, for it to publish real moon data (and, separately, for another caller's start of moonwatch to finish).

10
MOONWATCH_LOCK_WAIT_MARGIN =

Extra seconds a caller queued behind another caller's start of moonwatch waits for that start to finish, beyond its own timeout. The holder's wait for the data begins only once start_script returns, so without this margin a caller that queued while the holder was still in start_script would time out just before the holder's own wait does.

1
MOONWATCH_POLL_INTERVAL =

Seconds between polls while check_moonwatch waits for moonwatch.

0.1
MOONWATCH_RESTART_COOLDOWN =

Seconds check_moonwatch waits before starting moonwatch again after its own start of moonwatch failed (moonwatch could not be found, did not start, or stopped before publishing). Without this, a moonwatch that crashes at startup would be restarted by every moon check.

60
MOONWATCH_START_LOCK =

Serializes check_moonwatch's not-running -> reset -> start sequence so two callers never both start moonwatch, and a late caller never wipes data a freshly started moonwatch has already published.

Mutex.new
MOONWATCH_STATE_LOCK =

Makes the stuck-start latch's set and clear atomic with taking and releasing MOONWATCH_START_LOCK (see note_moonwatch_start_stuck).

Mutex.new
CENTER_TELESCOPE_MESSAGES =

Expected game responses when centering a telescope on a target.

[
  'Center what',
  'You put your eye',
  'open it to make any use of it',
  'The pain is too much',
  "That's a bit tough to do when you can't see the sky",
  "You would probably need a periscope to do that",
  'Your search for',
  'Your vision is too fuzzy',
  "You'll need to open it to make any use of it",
  'You must have both hands free'
].freeze
OBSERVE_MESSAGES =

Expected game responses when observing celestial bodies. Used by observe method to match bput responses. Patterns validated via in-game testing with test_observe_comprehensive.lic Note: Roundtime is intentionally NOT included - every observation that produces a Roundtime also produces a more specific pattern that matches first.

[
  'Your search for',                           # Covers: fruitless, foiled by daylight/darkness
  'You see nothing regarding the future',      # No vision available
  'Clouds obscure',                            # Weather blocking
  'The following heavenly bodies are visible:', # Observe heavens listing
  "That's a bit hard to do while inside",      # Indoor blocking
  'too close to the sun',                      # Planet visibility (solar conjunction)
  'too faint for you to pick out',             # Requires telescope
  'You learn nothing of the future',           # Circle too low for body
  'below the horizon',                         # Body not visible
  'You have not pondered',                     # Observation cooldown
  'You are unable to make use',                # Cooldown followup
  'While the sighting',                        # Partial success
  'You learned something useful'               # Full success
].freeze

Class Method Summary collapse

Class Method Details

.align(skill) ⇒ String

Aligns internal focus on a moonmage skill.

Examples:

DRCMM.align('lunar')

Parameters:

  • skill (String) —

    the skill name to align on, e.g. "lunar", "stellar"

Returns:

  • (String) —

    the game output from the align command



300
301
302
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 300

def align(skill)
  DRC.bput("align #{skill}", 'You focus internally')
end

.any_celestial_object? ⇒ Boolean

returns true if at least one moon (katamba, yavash, xibar) or the sun are above the horizon and won't set for at least another ~4 minutes. False when moonwatch's data is unavailable (see check_moonwatch), the same answer as "nothing up". A caller that must not act on unknown data (for example a spell gated on nothing being up) should check that check_moonwatch returns true first.

Returns:

  • (Boolean)


739
740
741
742
743
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 739

def any_celestial_object?
  return false unless check_moonwatch

  (UserVars.sun['day'] && UserVars.sun['timer'] >= MOON_VISIBILITY_TIMER_THRESHOLD) || moons_visible?
end

.await_moonwatch_data(seen_running, timeout) ⇒ Boolean

Polls until moonwatch is running with real moon data, moonwatch stops after having been seen running, or the deadline passes.

Parameters:

  • seen_running (Boolean) —

    whether moonwatch is known to have started; until it has, only the deadline ends the wait

  • timeout (Numeric) —

    seconds to wait

Returns:

  • (Boolean) —

    true when moon data is ready



1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 1085

def await_moonwatch_data(seen_running, timeout)
  deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + timeout
  loop do
    running = Script.running?('moonwatch')
    return true if running && moon_data_ready?

    if running
      seen_running = true
    elsif seen_running
      Lich::Messaging.msg("bold", "DRCMM: moonwatch stopped before its moon data was ready. Moon data is unavailable.")
      return false
    end

    if Process.clock_gettime(Process::CLOCK_MONOTONIC) >= deadline
      if seen_running
        Lich::Messaging.msg("bold", "DRCMM: moonwatch did not publish moon data within #{timeout} seconds. Moon data is unavailable.")
      else
        Lich::Messaging.msg("bold", "DRCMM: moonwatch did not start within #{timeout} seconds. Moon data is unavailable.")
      end
      return false
    end

    pause MOONWATCH_POLL_INTERVAL
  end
end

.await_running_moonwatch(timeout) ⇒ Boolean

Waits for an already-running moonwatch (started outside check_moonwatch, for example by autostart) to publish real moon data. Returns false at once while a previous wait is latched as stalled (see note_moonwatch_stall), unless the data has become ready since.

Parameters:

  • timeout (Numeric) —

    seconds to wait

Returns:

  • (Boolean) —

    true when moon data is ready



943
944
945
946
947
948
949
950
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 943

def await_running_moonwatch(timeout)
  return false if @moonwatch_data_stalled && !(Script.running?('moonwatch') && moon_data_ready?)

  return moonwatch_data_ready! if await_moonwatch_data(true, timeout)

  note_moonwatch_stall if full_moonwatch_wait?(timeout)
  false
end

.bright_celestial_object? ⇒ Boolean

returns true if at least one bright moon (yavash, xibar) or the sun are above the horizon and won't set for at least another ~4 minutes. False when moonwatch's data is unavailable (see check_moonwatch), the same answer as "nothing up". A caller that must not act on unknown data (for example a spell gated on nothing being up) should check that check_moonwatch returns true first.

Returns:

  • (Boolean)


727
728
729
730
731
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 727

def bright_celestial_object?
  return false unless check_moonwatch

  (UserVars.sun['day'] && UserVars.sun['timer'] >= MOON_VISIBILITY_TIMER_THRESHOLD) || moon_visible?('xibar') || moon_visible?('yavash')
end

.center_telescope(target) ⇒ void

This method returns an undefined value.

Centers a telescope on a celestial target (planet or constellation).

Sends the center command and handles conditional responses: if the telescope is closed, attempts to open it; if the planet is not visible, logs a message.

Examples:

DRCMM.center_telescope('lornon')

Parameters:

  • target (String) —

    the planet or constellation name to center on



284
285
286
287
288
289
290
291
292
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 284

def center_telescope(target)
  case DRC.bput("center telescope on #{target}", *CENTER_TELESCOPE_MESSAGES)
  when 'The pain is too much', "That's a bit tough to do when you can't see the sky"
    Lich::Messaging.msg("bold", "DRCMM: Planet #{target} not visible. Are you indoors perhaps?")
  when "You'll need to open it to make any use of it"
    fput("open my telescope")
    fput("center telescope on #{target}")
  end
end

.check_moonwatch(timeout: MOONWATCH_READY_TIMEOUT) ⇒ Boolean

Makes sure moonwatch is running, starting it if needed, and waits a bounded time for it to publish real moon data (see moon_data_ready?).

When moonwatch is running and the data is ready, this returns at once. When moonwatch is running but the data is not ready yet (it was started elsewhere, for example by autostart, and is still starting up), this waits for the data. If any wait for the data (this one or the one after starting moonwatch) times out while moonwatch keeps running, later calls return false at once instead of waiting again, until the data becomes ready or moonwatch is seen stopped. That includes calls already queued behind another caller's start or wait. When another caller's start is in progress, it waits for that start to finish (returning as soon as the data is ready), allowing MOONWATCH_LOCK_WAIT_MARGIN beyond the timeout. If that wait times out (the other caller's script is paused, or its start is stuck), later calls do not wait on that start again until it finishes: they return false at once while moonwatch is not running, and wait only for the data of a running moonwatch. Otherwise it clears the saved UserVars.moons and UserVars.sun (they may be stale), starts moonwatch and waits until moon_data_ready? is true. The wait ends early, with a message, when moonwatch cannot be found or stops before publishing, and ends at the deadline when it never starts or never publishes. The saved data is never restored on failure, so moon and sun checks see nothing up rather than stale timers. After such a failure, while moonwatch is not running, calls return false without starting it again until MOONWATCH_RESTART_COOLDOWN seconds have passed; a moonwatch started some other way in the meantime is still used.

A nil from start_script is not treated as a failure unless moonwatch cannot be found (see moonwatch_findable?): Lich also returns nil while another start of moonwatch is still in progress, so in that case this waits (up to the deadline) for that start to finish.

The timeout bounds each wait separately. A caller queued behind another caller's start waits up to timeout + MOONWATCH_LOCK_WAIT_MARGIN for the lock. If, once it has the lock, it finds a moonwatch that was started elsewhere in the meantime and has not published yet, it then waits up to timeout for that data too. So one call can take up to 2 * timeout + MOONWATCH_LOCK_WAIT_MARGIN (21 s by default) in that sequence; every other call takes at most timeout + the margin.

Only waits of at least MOONWATCH_READY_TIMEOUT set the stall latch or the stuck-start latch. A caller passing a shorter timeout gets false when its own wait runs out, but does not make other callers skip theirs.

Parameters:

  • timeout (Numeric) (defaults to: MOONWATCH_READY_TIMEOUT) —

    seconds to wait for another caller's start to finish (plus MOONWATCH_LOCK_WAIT_MARGIN), and again for moonwatch to publish (after starting it, or when it is already running). Must be a positive, finite number.

Returns:

  • (Boolean) —

    true when moonwatch is running and has published real moon data; false when moon data is unavailable

Raises:

  • (ArgumentError) —

    when timeout is not a positive, finite number



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
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 856

def check_moonwatch(timeout: MOONWATCH_READY_TIMEOUT)
  validate_moonwatch_timeout!(timeout)

  if Script.running?('moonwatch')
    return moonwatch_data_ready! if moon_data_ready?
    return await_running_moonwatch(timeout) unless MOONWATCH_START_LOCK.locked?
  else
    @moonwatch_data_stalled = false
  end

  lock_deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + timeout + MOONWATCH_LOCK_WAIT_MARGIN
  start_generation = @moonwatch_start_generation
  until MOONWATCH_START_LOCK.try_lock
    # The other start may publish while the lock is still held (its
    # holder can be paused or slow to return), so keep checking. When
    # the holder's wait has just timed out on a running moonwatch (the
    # stall latch is set), stop waiting too. When an earlier wait on
    # this start timed out (the holder is stuck), wait only on a running
    # moonwatch itself, not on the holder.
    if Script.running?('moonwatch')
      return true if moon_data_ready?
      return false if @moonwatch_data_stalled
      return await_running_moonwatch(timeout) if @moonwatch_start_stuck
    elsif @moonwatch_start_stuck
      return false
    end
    if Process.clock_gettime(Process::CLOCK_MONOTONIC) >= lock_deadline
      Lich::Messaging.msg("bold", "DRCMM: Timed out waiting for another start of moonwatch to finish. Moon data is unavailable.")
      note_moonwatch_start_stuck(start_generation) if full_moonwatch_wait?(timeout)
      return false
    end
    pause MOONWATCH_POLL_INTERVAL
  end

  begin
    # A stuck start, if any, has released the lock.
    moonwatch_start_lock_taken
    # Another caller started moonwatch (or another wait on it ran) while
    # this one waited for the lock: wait for its data, honouring the latch.
    return await_running_moonwatch(timeout) if Script.running?('moonwatch')
    if moonwatch_restart_blocked?
      # A start failed moments ago. moonwatch is not running, so any
      # saved data is stale; clear it as a start would, so moon and sun
      # checks see nothing up rather than old timers. Look again first:
      # a moonwatch started another way since the check above has just
      # written its skeleton, which must not be wiped. Writing only when
      # there is something to clear keeps this off the usual path (the
      # failed start already cleared the data). A moonwatch started in
      # the moment between that last look and the write can still lose
      # its skeleton; only moonwatch itself could close that window.
      return await_running_moonwatch(timeout) if Script.running?('moonwatch')

      UserVars.moons = {} unless UserVars.moons == {}
      UserVars.sun = {} unless UserVars.sun == {}
      return false
    end

    Lich::Messaging.msg("bold", "DRCMM: moonwatch is not running. Starting it now.")
    @moonwatch_data_stalled = false
    UserVars.moons = {}
    UserVars.sun = {}
    started = start_script('moonwatch') ? true : false
    if !started && !Script.running?('moonwatch') && !moonwatch_findable?
      Lich::Messaging.msg("bold", "DRCMM: moonwatch could not be found. Moon data is unavailable.")
      note_moonwatch_start_failure(timeout)
      return false
    end
    if await_moonwatch_data(started, timeout)
      # Only suggest autostart once this start has actually worked.
      Lich::Messaging.msg("plain", "DRCMM: Run `#{$clean_lich_char}e autostart('moonwatch')` to avoid this in the future.") if started
      return moonwatch_data_ready!
    end

    note_moonwatch_start_failure(timeout)
    false
  ensure
    release_moonwatch_start_lock if MOONWATCH_START_LOCK.owned?
  end
end

.drop_moon_weapon? ⇒ Boolean

Drops the moon weapon in your hands, if any. Returns true if dropped something, false otherwise.

Returns:

  • (Boolean)


491
492
493
494
495
496
497
498
499
500
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 491

def drop_moon_weapon?
  dropped_it = false
  if is_moon_weapon?(DRC.left_hand)
    dropped_it = dropped_it || DRC.bput("drop #{DRC.left_hand}", *MOON_DROP_MESSAGES) == "As you open your hand"
  end
  if is_moon_weapon?(DRC.right_hand)
    dropped_it = dropped_it || DRC.bput("drop #{DRC.right_hand}", *MOON_DROP_MESSAGES) == "As you open your hand"
  end
  dropped_it
end

.find_visible_planets(planets, settings = nil) ⇒ Object

Returns the names in planets that did not turn up fruitless through the telescope (any other reply, such as daylight or indoors, still counts as visible), or nil when there is no telescope to look through (no settings, or it can't be fetched).



629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 629

def find_visible_planets(planets, settings = nil)
  # Without settings there is no telescope name or storage, so don't send
  # a bare "get" for a nil item.
  unless settings
    Lich::Messaging.msg("bold", "DRCMM: No settings given, so no telescope to find visible planets.")
    return
  end

  unless get_telescope?(settings.telescope_name, settings.telescope_storage)
    Lich::Messaging.msg("bold", "DRCMM: Could not get telescope to find visible planets.")
    return
  end

  Flags.add('planet-not-visible', 'turns up fruitless')
  observed_planets = []

  begin
    planets.each do |planet|
      center_telescope(planet)
      observed_planets << planet unless Flags['planet-not-visible']
      Flags.reset('planet-not-visible')
    end
  ensure
    Flags.delete('planet-not-visible')
  end

  Lich::Messaging.msg("bold", "DRCMM: Could not store telescope after finding visible planets.") unless store_telescope?(settings.telescope_name, settings.telescope_storage)
  observed_planets
end

.full_moonwatch_wait?(timeout) ⇒ Boolean

Whether a wait of timeout seconds was long enough to latch its failure for other callers (see note_moonwatch_stall, note_moonwatch_start_stuck). A caller that chose a shorter wait only answers for itself.

Parameters:

  • timeout (Numeric) —

    seconds the wait allowed

Returns:

  • (Boolean)


970
971
972
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 970

def full_moonwatch_wait?(timeout)
  timeout >= MOONWATCH_READY_TIMEOUT
end

.get_bones(storage) ⇒ Object

Deprecated.

Use get_bones? instead



349
350
351
352
353
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 349

def get_bones(storage)
  return if get_bones?(storage)

  Lich::Messaging.msg('bold', 'DRCMM: Failed to get bones.')
end

.get_bones?(storage) ⇒ Boolean

Retrieves divination bones from storage (tied or in a container).

Returns true if retrieval succeeds or no storage location is configured. Returns false only if retrieval fails when a storage location exists.

Examples:

storage = { 'container' => 'sack' }
DRCMM.get_bones?(storage)

Parameters:

  • storage (Hash) —

    storage configuration with optional keys 'tied' (location to untie from), 'container' (container to get from)

Returns:

  • (Boolean) —

    true if retrieval succeeded or storage not configured, false if retrieval failed



316
317
318
319
320
321
322
323
324
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 316

def get_bones?(storage)
  if storage['tied']
    DRCI.untie_item?("bones", storage['tied'])
  elsif storage['container']
    DRCI.get_item?("bones", storage['container'])
  else
    DRCI.get_item?("bones")
  end
end

.get_div_tool(tool) ⇒ Object

Deprecated.

Use get_div_tool? instead



432
433
434
435
436
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 432

def get_div_tool(tool)
  return if get_div_tool?(tool)

  Lich::Messaging.msg('bold', "DRCMM: Failed to get divination tool '#{tool['name']}'.")
end

.get_div_tool?(tool) ⇒ Boolean

Retrieves a divination tool from storage (tied, worn, or in a container).

Returns true if retrieval succeeds or no storage location is configured. Returns false only if retrieval fails when a storage location exists.

Examples:

tool = { 'name' => 'bones', 'container' => 'sack' }
DRCMM.get_div_tool?(tool)

Parameters:

  • tool (Hash) —

    tool configuration with 'name' (item name) and optional keys 'tied' (location to untie from), 'worn' (whether worn), 'container' (container to get from)

Returns:

  • (Boolean) —

    true if retrieval succeeded or storage not configured, false if retrieval failed



398
399
400
401
402
403
404
405
406
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 398

def get_div_tool?(tool)
  if tool['tied']
    DRCI.untie_item?(tool['name'], tool['container'])
  elsif tool['worn']
    DRCI.remove_item?(tool['name'])
  else
    DRCI.get_item?(tool['name'], tool['container'])
  end
end

.get_telescope(storage) ⇒ Object

Deprecated.

Use get_telescope? instead



242
243
244
245
246
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 242

def get_telescope(storage)
  return if get_telescope?('telescope', storage)

  Lich::Messaging.msg('bold', 'DRCMM: Failed to get telescope.')
end

.get_telescope?(telescope_name = 'telescope', storage) ⇒ Boolean

Retrieves a telescope from storage (tied, in a container, or on the ground).

Returns true if the telescope is already in hand, if retrieval succeeds, or if no storage location is configured. Returns false only if retrieval fails when a storage location exists.

Examples:

storage = { 'container' => 'pack' }
DRCMM.get_telescope?('spyglass', storage)

Parameters:

  • telescope_name (String) (defaults to: 'telescope') —

    the name of the telescope item, defaults to "telescope"

  • storage (Hash) —

    storage configuration with optional keys 'tied' (location to untie from), 'container' (container to get from)

Returns:

  • (Boolean) —

    true if the telescope is in hand or retrieval succeeded, false if retrieval failed



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 199

def get_telescope?(telescope_name = 'telescope', storage)
  return true if DRCI.in_hands?(telescope_name)

  if storage['tied']
    DRCI.untie_item?(telescope_name, storage['tied'])
  elsif storage['container']
    unless DRCI.get_item?(telescope_name, storage['container'])
      Lich::Messaging.msg("plain", "DRCMM: Telescope not found in container. Trying to get it from anywhere we can.")
      return DRCI.get_item?(telescope_name)
    end
    true
  else
    DRCI.get_item?(telescope_name)
  end
end

.hold_moon_weapon? ⇒ Boolean

Try to hold a moon weapon. If you end up not holding a moon weapon then returns false.

Returns:

  • (Boolean)


509
510
511
512
513
514
515
516
517
518
519
520
521
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 509

def hold_moon_weapon?
  return true if holding_moon_weapon?
  return false if [DRC.left_hand, DRC.right_hand].compact.length >= 2

  MOON_WEAPON_NAMES.each do |weapon|
    glance = DRC.bput("glance my #{weapon}", "You glance at a .* #{weapon}", "I could not find")
    case glance
    when /You glance/
      return DRC.bput("hold my #{weapon}", "You grab", "You aren't wearing", "Hold hands with whom?", "You need a free hand") == "You grab"
    end
  end
  false
end

.holding_moon_weapon? ⇒ Boolean

Is a moon weapon in your hands?

Returns:

  • (Boolean)


503
504
505
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 503

def holding_moon_weapon?
  is_moon_weapon?(DRC.left_hand) || is_moon_weapon?(DRC.right_hand)
end

.is_moon_weapon?(item) ⇒ Boolean

Does the item appear to be a moon weapon?

Returns:

  • (Boolean)


524
525
526
527
528
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 524

def is_moon_weapon?(item)
  return false unless item

  MOON_WEAPON_REGEX.match?(item)
end

.moon_data_ready? ⇒ Boolean

Whether UserVars.moons holds real moon data: every moon has a numeric 'timer' and 'visible' is a list. moonwatch first writes an empty skeleton (=> {, ..., 'visible' => []}) and fills in the timers afterwards, so the skeleton does not count as ready.

moonwatch sets 'running' to false when it exits. UserVars persist between sessions, so data marked that way is left over from a moonwatch that has stopped and does not count as ready either. Data without a 'running' key (older moonwatch versions) is judged by the timers alone.

moonwatch publishes the moons first and the sun right after, and the celestial checks read both. So while moonwatch has marked UserVars.sun as running but not yet written its 'timer' (the last key those checks read, written after 'day'), the data is not ready. Sun data without a 'running' key (older moonwatch versions) is not checked.

moonwatch's 'running' => false marker is saved only when Lich shuts down in an orderly way. After a crash the saved data can still say 'running' => true, and while a newly started moonwatch has not yet written its skeleton (normally a few milliseconds) that saved data counts as ready.

Returns:

  • (Boolean)


792
793
794
795
796
797
798
799
800
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 792

def moon_data_ready?
  moons = UserVars.moons
  return false unless moons.is_a?(Hash) && moons['visible'].is_a?(Array)
  return false if moons['running'] == false
  return false unless MOON_NAMES.all? { |moon| moons[moon].is_a?(Hash) && moons[moon]['timer'].is_a?(Numeric) }

  sun = UserVars.sun
  !(sun.is_a?(Hash) && sun['running'] == true && !sun['timer'].is_a?(Numeric))
end

.moon_used_to_summon_weapon ⇒ String?

Determines which moon (katamba, yavash, or xibar) was used to summon the currently held moon weapon.

Examines a held moonblade or moonstaff by its color adjective and returns the corresponding moon name. Returns nil if no moon weapon is held or the moon cannot be determined. Results are non-deterministic if multiple moon weapons are summoned simultaneously on different moons.

Examples:

DRCMM.moon_used_to_summon_weapon #=> 'xibar'

Returns:

  • (String, nil) —

    the moon name ('katamba', 'yavash', or 'xibar'), or nil if no moon weapon is held



542
543
544
545
546
547
548
549
550
551
552
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 542

def moon_used_to_summon_weapon
  # Note, if you have more than one weapon summoned at a time
  # then the results of this method are non-deterministic.
  # For example, if you have 2+ moonblades/staffs cast on different moons.
  MOON_WEAPON_NAMES.each do |weapon|
    glance = DRC.bput("glance my #{weapon}", MOON_GLANCE_REGEX, "I could not find")
    match = glance&.match(MOON_GLANCE_REGEX)
    return MOON_COLOR_TO_NAME[match[:color]] if match
  end
  nil
end

.moon_visible?(moon_name) ⇒ Boolean

Returns true if the moon is above the horizon and won't set for at least another ~4 minutes.

Returns:

  • (Boolean)


752
753
754
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 752

def moon_visible?(moon_name)
  visible_moons.include?(moon_name)
end

.moon_weapon_duration ⇒ Object

Focuses the summoned moon weapon (moonblade/moonstaff) you are holding or wearing and returns how many roisaen it will last: a positive Integer for the "roughly roisaen" form, 0 for the near-expiry "less than one roisan" form, or nil if you have no moon weapon or the phrase could not be parsed. One roisaen == 60 seconds; moonblade duration ranges 12-41 minutes. https://elanthipedia.play.net/Moonblade

NOTE: FOCUS incurs roundtime, so callers should not poll this every tick.



562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 562

def moon_weapon_duration
  MOON_WEAPON_NAMES.each do |weapon|
    result = DRC.bput("focus my #{weapon}", MOON_FOCUS_DURATION_REGEX, MOON_FOCUS_EXPIRING_REGEX, "I could not find", "Focus on what")

    # Near expiry FOCUS reports "less than one roisan" with no count; treat
    # as 0 roisaen (expiring now) so callers can refresh immediately.
    if result&.match?(MOON_FOCUS_EXPIRING_REGEX)
      waitrt?
      return 0
    end

    match = result&.match(MOON_FOCUS_DURATION_REGEX)
    next unless match

    waitrt?
    return parse_roisaen(match[:count])
  end
  nil
end

.moons_visible? ⇒ Boolean

Returns true if at least one moon (e.g. katamba, yavash, xibar) is above the horizon and won't set for at least another ~4 minutes.

Returns:

  • (Boolean)


747
748
749
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 747

def moons_visible?
  !visible_moons.empty?
end

.moonwatch_data_ready! ⇒ true

Called when moonwatch is running with real moon data: clears the stall latch and the restart cooldown.

Returns:

  • (true)


1017
1018
1019
1020
1021
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 1017

def moonwatch_data_ready!
  @moonwatch_data_stalled = false
  @moonwatch_restart_blocked_until = nil
  true
end

.moonwatch_findable? ⇒ Boolean

Whether Lich can find a moonwatch script file. Script.exists? does not look in custom//, which Script.start does, so when it says no this asks Script.version, which resolves names the same way Script.start does and returns nil when no file matches.

Returns:

  • (Boolean)


1070
1071
1072
1073
1074
1075
1076
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 1070

def moonwatch_findable?
  return true if Script.exists?('moonwatch')

  !Script.version('moonwatch').nil?
rescue ArgumentError
  true # the file was found, but its version header is malformed
end

.moonwatch_restart_blocked? ⇒ Boolean

Whether a recent failed start (see note_moonwatch_start_failure) still blocks check_moonwatch from starting moonwatch.

Reads the deadline once: another thread's moonwatch_data_ready! may clear it at any moment.

Returns:

  • (Boolean)


1048
1049
1050
1051
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 1048

def moonwatch_restart_blocked?
  blocked_until = @moonwatch_restart_blocked_until
  !blocked_until.nil? && Process.clock_gettime(Process::CLOCK_MONOTONIC) < blocked_until
end

.moonwatch_start_lock_taken ⇒ Object

Called by check_moonwatch right after it takes MOONWATCH_START_LOCK: starts a new generation and clears the stuck-start latch.



997
998
999
1000
1001
1002
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 997

def moonwatch_start_lock_taken
  MOONWATCH_STATE_LOCK.synchronize do
    @moonwatch_start_generation += 1
    @moonwatch_start_stuck = false
  end
end

.note_moonwatch_stall ⇒ Object

Called after a wait for moon data has failed. When moonwatch is still running, it is running without publishing, so later calls return false at once rather than stalling every caller for the full timeout; that latch clears when the data becomes ready or moonwatch is seen stopped.



1057
1058
1059
1060
1061
1062
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 1057

def note_moonwatch_stall
  return unless Script.running?('moonwatch')

  @moonwatch_data_stalled = true
  Lich::Messaging.msg("plain", "DRCMM: Not waiting for moonwatch's moon data again until it publishes the data or stops.")
end

.note_moonwatch_start_failure(timeout) ⇒ Object

Called after check_moonwatch's own start of moonwatch failed. When moonwatch is running (it never published), latches the stall (see note_moonwatch_stall) if the wait was a full one (see full_moonwatch_wait?). Otherwise blocks further starts for MOONWATCH_RESTART_COOLDOWN seconds, so a moonwatch that cannot start is not restarted, with its messages, by every moon check.

Parameters:

  • timeout (Numeric) —

    seconds the failed wait allowed



1031
1032
1033
1034
1035
1036
1037
1038
1039
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 1031

def note_moonwatch_start_failure(timeout)
  if Script.running?('moonwatch')
    note_moonwatch_stall if full_moonwatch_wait?(timeout)
    return
  end

  @moonwatch_restart_blocked_until = Process.clock_gettime(Process::CLOCK_MONOTONIC) + MOONWATCH_RESTART_COOLDOWN
  Lich::Messaging.msg("plain", "DRCMM: Not starting moonwatch again for #{MOONWATCH_RESTART_COOLDOWN} seconds. Moon checks report no moon until then, unless moonwatch is started another way.")
end

.note_moonwatch_start_stuck(start_generation) ⇒ Object

Called when a wait for another caller's start of moonwatch timed out: until that start releases the lock, callers queued on it return false at once while moonwatch is not running (see check_moonwatch).

Latches only while the start that was waited on still holds the lock. If it released the lock after the deadline check (and another caller may already have taken it for a fresh start), nothing is latched.

Parameters:

  • start_generation (Integer) —

    @moonwatch_start_generation when the wait began



984
985
986
987
988
989
990
991
992
993
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 984

def note_moonwatch_start_stuck(start_generation)
  latched = MOONWATCH_STATE_LOCK.synchronize do
    next false unless start_generation == @moonwatch_start_generation && MOONWATCH_START_LOCK.locked?

    @moonwatch_start_stuck = true
  end
  return unless latched

  Lich::Messaging.msg("plain", "DRCMM: Not waiting for that start of moonwatch again until it finishes. Moon checks report no moon until then, unless moonwatch is running.")
end

.observe(thing) ⇒ String

Observes a celestial body or the heavens using the observe command.

Examples:

DRCMM.observe('yavash')
DRCMM.observe('heavens')

Parameters:

  • thing (String) —

    the body or location to observe, e.g. "yavash", "xibar", "katamba", or "heavens" for a general observation

Returns:

  • (String) —

    the game output from the observe command



156
157
158
159
160
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 156

def observe(thing)
  output = "observe #{thing} in heavens"
  output = 'observe heavens' if thing.eql?('heavens')
  DRC.bput(output.to_s, *OBSERVE_MESSAGES)
end

.parse_roisaen(text) ⇒ Object

Converts a spelled-out roisaen count (as reported by FOCUS, e.g. "five", "twenty", "twenty-nine", "forty-one") into an Integer, or nil if any word is not a recognized number. Compounds may be hyphen- or space-separated and are summed ("forty-one" -> 41). Case-insensitive.

Uses the global $NUM_MAP published by drinfomon/drvariables.rb (the same number word map DRC.text2num uses) rather than the Lich::DragonRealms constant, to avoid any namespace-resolution surface.



590
591
592
593
594
595
596
597
598
599
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 590

def parse_roisaen(text)
  return nil if text.nil?
  return nil if $NUM_MAP.nil?

  words = text.downcase.tr('-', ' ').split
  return nil if words.empty?
  return nil unless words.all? { |word| $NUM_MAP.key?(word) }

  words.sum { |word| $NUM_MAP[word] }
end

.peer_telescope ⇒ void

This method returns an undefined value.

Peers through a telescope to examine constellations or learn about the future.

Issues the peer command and waits for roundtime. Patterns matched are specific to telescope use, including learning completion and vision quality messages.

Examples:

DRCMM.peer_telescope


263
264
265
266
267
268
269
270
271
272
273
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 263

def peer_telescope
  telescope_regex_patterns = Regexp.union(
    /The pain is too much/,
    /You see nothing regarding the future/,
    /You believe you've learned all that you can about/,
    Regexp.union(get_data('constellations').observe_finished_messages),
    /open it/,
    /Your vision is too fuzzy/,
  )
  Lich::Util.issue_command("peer my telescope", telescope_regex_patterns, /Roundtime: /, usexml: false)
end

.predict(thing) ⇒ String

Predicts the state of celestial bodies or all predictions using the predict command.

Examples:

DRCMM.predict('yavash')
DRCMM.predict('all')

Parameters:

  • thing (String) —

    the body to predict or "all" for all predictions

Returns:

  • (String) —

    the game output from the predict command



169
170
171
172
173
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 169

def predict(thing)
  output = "predict #{thing}"
  output = 'predict state all' if thing.eql?('all')
  DRC.bput(output.to_s, 'You predict that', 'You are far too', 'you lack the skill to grasp them fully', /(R|r)oundtime/i, 'You focus inwardly')
end

.release_moonwatch_start_lock ⇒ Object

Clears the stuck-start latch and releases MOONWATCH_START_LOCK as one step, so a waiter cannot latch this start after the clear.



1006
1007
1008
1009
1010
1011
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 1006

def release_moonwatch_start_lock
  MOONWATCH_STATE_LOCK.synchronize do
    @moonwatch_start_stuck = false
    MOONWATCH_START_LOCK.unlock
  end
end

.roll_bones(storage) ⇒ void

This method returns an undefined value.

Retrieves bones, rolls them for divination, and stores them away.

Retrieves from storage, executes "roll my bones", waits for roundtime, and stores the bones back. Logs a message and returns early if retrieval fails. Logs a separate message if storing fails after rolling.

Examples:

storage = { 'container' => 'sack' }
DRCMM.roll_bones(storage)

Parameters:

  • storage (Hash) —

    storage configuration with 'tied' or 'container' keys



373
374
375
376
377
378
379
380
381
382
383
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 373

def roll_bones(storage)
  unless get_bones?(storage)
    Lich::Messaging.msg('bold', 'DRCMM: Failed to get bones, aborting roll_bones.')
    return
  end

  DRC.bput('roll my bones', 'roundtime')
  waitrt?

  Lich::Messaging.msg('bold', 'DRCMM: Failed to store bones after rolling.') unless store_bones?(storage)
end

.set_moon_data(data) ⇒ Hash?

Sets the cast target for a moon-based astral spell to a visible moon or ambient.

Finds the first visible moon (katamba, yavash, or xibar) and sets the 'cast' key. If no moon is visible and the spell is "cage of light", allows casting on ambient. Returns nil (with a message) if no moon or ambient casting is possible.

Examples:

data = { 'moon' => true, 'name' => 'Moonburst' }
DRCMM.set_moon_data(data) #=> { 'moon' => true, 'name' => 'Moonburst', 'cast' => 'cast xibar' }

Parameters:

  • data (Hash) —

    astral spell data with 'moon' key and 'name' for logging

Returns:

  • (Hash, nil) —

    the updated data hash with 'cast' key set (e.g. 'cast yavash' or 'cast ambient'), or nil if no valid target is available



706
707
708
709
710
711
712
713
714
715
716
717
718
719
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 706

def set_moon_data(data)
  return data unless data['moon']

  moon = visible_moons.first
  if moon
    data['cast'] = "cast #{moon}"
  elsif data['name'].downcase == 'cage of light'
    data['cast'] = "cast ambient"
  else
    Lich::Messaging.msg("bold", "DRCMM: No moon available to cast #{data['name']}.")
    data = nil
  end
  data
end

.set_planet_data(data, settings = nil) ⇒ Hash?

Sets the cast target for a planet-based astral spell to a visible planet.

Checks which planets in the constellation data are currently visible through a telescope (requires settings with telescope configuration). Finds the first planet that matches both the spell's stat requirements and visibility. Sets the 'cast' key and returns the data; returns nil (with a message) if no visible planet matches or no telescope is available.

Examples:

data = { 'stats' => ['strength'], 'abbrev' => 'SF' }
DRCMM.set_planet_data(data, settings)

Parameters:

  • data (Hash) —

    astral spell data with 'stats' key listing spell requirements

  • settings (OpenStruct, nil) (defaults to: nil) —

    optional settings with telescope_name and telescope_storage for planet visibility checks

Returns:

  • (Hash, nil) —

    the updated data hash with 'cast' key set, or nil if no visible planet is available



675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 675

def set_planet_data(data, settings = nil)
  return data unless data['stats']

  planets = get_data('constellations')[:constellations].select { |planet| planet['stats'] }
  planet_names = planets.map { |planet| planet['name'] }
  # find_visible_planets returns nil when there is no telescope to look through.
  visible_planets = find_visible_planets(planet_names, settings) || []
  data['stats'].each do |stat|
    cast_on = planets.map { |planet| planet['name'] if planet['stats'].include?(stat) && visible_planets.include?(planet['name']) }.compact.first
    next unless cast_on

    data['cast'] = "cast #{cast_on}"
    return data
  end
  Lich::Messaging.msg("bold", "DRCMM: Could not set planet data. Cannot cast #{data['abbrev']}.")
  # Messaging.msg returns a truthy Array; callers test the result with `if data`.
  nil
end

.store_bones(storage) ⇒ Object

Deprecated.

Use store_bones? instead



356
357
358
359
360
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 356

def store_bones(storage)
  return if store_bones?(storage)

  Lich::Messaging.msg('bold', 'DRCMM: Failed to store bones.')
end

.store_bones?(storage) ⇒ Boolean

Stores divination bones away to tied location or container.

Returns true if storage succeeds or bones are not in hand. Returns false only if storage fails when bones are in hand.

Examples:

storage = { 'container' => 'sack' }
DRCMM.store_bones?(storage)

Parameters:

  • storage (Hash) —

    storage configuration with optional keys 'tied' (location to tie to), 'container' (container to put in)

Returns:

  • (Boolean) —

    true if storage succeeded or bones not in hand, false if storage failed



338
339
340
341
342
343
344
345
346
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 338

def store_bones?(storage)
  if storage['tied']
    DRCI.tie_item?("bones", storage['tied'])
  elsif storage['container']
    DRCI.put_away_item?("bones", storage['container'])
  else
    DRCI.put_away_item?("bones")
  end
end

.store_div_tool(tool) ⇒ Object

Deprecated.

Use store_div_tool? instead



439
440
441
442
443
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 439

def store_div_tool(tool)
  return if store_div_tool?(tool)

  Lich::Messaging.msg('bold', "DRCMM: Failed to store divination tool '#{tool['name']}'.")
end

.store_div_tool?(tool) ⇒ Boolean

Stores a divination tool away to tied location, wears it, or puts it in a container.

Returns true if storage succeeds or the tool is not in hand. Returns false only if storage fails when the tool is in hand.

Examples:

tool = { 'name' => 'bones', 'container' => 'sack' }
DRCMM.store_div_tool?(tool)

Parameters:

  • tool (Hash) —

    tool configuration with 'name' (item name) and optional keys 'tied' (location to tie to), 'worn' (whether to wear it), 'container' (container to put in)

Returns:

  • (Boolean) —

    true if storage succeeded or tool not in hand, false if storage failed



421
422
423
424
425
426
427
428
429
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 421

def store_div_tool?(tool)
  if tool['tied']
    DRCI.tie_item?(tool['name'], tool['container'])
  elsif tool['worn']
    DRCI.wear_item?(tool['name'])
  else
    DRCI.put_away_item?(tool['name'], tool['container'])
  end
end

.store_telescope(storage) ⇒ Object

Deprecated.

Use store_telescope? instead



249
250
251
252
253
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 249

def store_telescope(storage)
  return if store_telescope?('telescope', storage)

  Lich::Messaging.msg('bold', 'DRCMM: Failed to store telescope.')
end

.store_telescope?(telescope_name = "telescope", storage) ⇒ Boolean

Stores a telescope away to tied location, container, or ground.

Returns true if the telescope is not in hand or if storage succeeds. Returns false only if storage fails when the telescope is in hand.

Examples:

storage = { 'container' => 'pack' }
DRCMM.store_telescope?('spyglass', storage)

Parameters:

  • telescope_name (String) (defaults to: "telescope") —

    the name of the telescope item, defaults to "telescope"

  • storage (Hash) —

    storage configuration with optional keys 'tied' (location to tie to), 'container' (container to put in)

Returns:

  • (Boolean) —

    true if the telescope was not in hand or storage succeeded, false if storage failed



229
230
231
232
233
234
235
236
237
238
239
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 229

def store_telescope?(telescope_name = "telescope", storage)
  return true unless DRCI.in_hands?(telescope_name)

  if storage['tied']
    DRCI.tie_item?(telescope_name, storage['tied'])
  elsif storage['container']
    DRCI.put_away_item?(telescope_name, storage['container'])
  else
    DRCI.put_away_item?(telescope_name)
  end
end

.study_sky ⇒ String

Studies the sky to sense portents and lingering celestial impressions.

Examples:

DRCMM.study_sky

Returns:

  • (String) —

    the game output from the study sky command



180
181
182
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 180

def study_sky
  DRC.bput('study sky', 'You feel a lingering sense', 'You feel it is too soon', 'Roundtime', 'You are unable to sense additional information', 'detect any portents')
end

.update_astral_data(data, settings = nil) ⇒ Hash?

Updates astral spell data with cast targeting information for moons or planets.

Routes to #set_moon_data or #set_planet_data based on the data type. Modifies the data hash by setting a 'cast' key with the target ('moon_name', 'planet_name', or 'ambient'). Returns nil if no valid target is available (logged with a message).

Examples:

data = { 'moon' => true, 'name' => 'Moonburst' }
DRCMM.update_astral_data(data) #=> { 'moon' => true, 'name' => 'Moonburst', 'cast' => 'cast yavash' }

Parameters:

  • data (Hash) —

    astral spell data with 'moon' or 'stats' key; typically includes 'name' and 'abbrev' for logging

  • settings (OpenStruct, nil) (defaults to: nil) —

    optional settings with telescope configuration for planet visibility checks

Returns:

  • (Hash, nil) —

    the updated data hash with 'cast' key set, or nil if targeting failed



616
617
618
619
620
621
622
623
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 616

def update_astral_data(data, settings = nil)
  if data['moon']
    data = set_moon_data(data)
  elsif data['stats']
    data = set_planet_data(data, settings)
  end
  data
end

.use_div_tool(tool_storage) ⇒ void

This method returns an undefined value.

Retrieves a divination tool, uses it (with appropriate verb for the tool type), and stores it away.

For each tool keyword in DIV_TOOL_VERBS that matches the tool name, executes the corresponding verb (e.g., "review my charts", "roll my bones") and waits for roundtime. Logs messages on retrieval or storage failure.

Examples:

tool = { 'name' => 'bones', 'container' => 'sack' }
DRCMM.use_div_tool(tool)

Parameters:

  • tool_storage (Hash) —

    tool configuration with 'name' and optional storage keys 'tied', 'worn', 'container'



458
459
460
461
462
463
464
465
466
467
468
469
470
471
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 458

def use_div_tool(tool_storage)
  unless get_div_tool?(tool_storage)
    Lich::Messaging.msg('bold', "DRCMM: Failed to get divination tool '#{tool_storage['name']}', aborting use_div_tool.")
    return
  end

  DIV_TOOL_VERBS
    .select { |tool, _| tool_storage['name'].include?(tool) }
    .each   { |tool, verb| DRC.bput("#{verb} my #{tool}", 'roundtime'); waitrt? }

  unless store_div_tool?(tool_storage)
    Lich::Messaging.msg('bold', "DRCMM: Failed to store divination tool '#{tool_storage['name']}'.")
  end
end

.validate_moonwatch_timeout!(timeout) ⇒ Object

Raises unless timeout is a positive, finite number of seconds. A zero, negative or infinite timeout would make the waits end at once or never; nil would fail deep inside a wait.

Parameters:

  • timeout (Object) —

    the value passed as check_moonwatch's timeout:

Raises:

  • (ArgumentError)


958
959
960
961
962
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 958

def validate_moonwatch_timeout!(timeout)
  return if timeout.is_a?(Numeric) && timeout.real? && timeout.finite? && timeout.positive?

  raise ArgumentError, "DRCMM.check_moonwatch: timeout must be a positive, finite number of seconds, got #{timeout.inspect}"
end

.visible_moons ⇒ Object

Returns list of moon names (e.g. katamba, yavash, xibar) that are above the horizon and won't set for at least another ~4 minutes. Empty when moonwatch's data is unavailable (see check_moonwatch), even if UserVars.moons still holds saved timers.



760
761
762
763
764
765
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 760

def visible_moons
  return [] unless check_moonwatch

  UserVars.moons.select { |moon_name, moon_data| UserVars.moons['visible'].include?(moon_name) && moon_data['timer'] >= MOON_VISIBILITY_TIMER_THRESHOLD }
          .map { |moon_name, _moon_data| moon_name }
end

.wear_moon_weapon? ⇒ Boolean

There are many variants of a summoned moon weapon (blade, staff, sword, etc) This function checks if you're holding one then tries to wear it. Returns true if what is in your hands is a summoned moon weapon that becomes worn. Returns false if you're not holding a moon weapon, or you are but can't wear it. https://elanthipedia.play.net/Shape_Moonblade

Returns:

  • (Boolean)


478
479
480
481
482
483
484
485
486
487
# File 'documented/dragonrealms/commons/common-moonmage.rb', line 478

def wear_moon_weapon?
  wore_it = false
  if is_moon_weapon?(DRC.left_hand)
    wore_it = wore_it || DRC.bput("wear #{DRC.left_hand}", *MOON_WEAR_MESSAGES) == "telekinetic"
  end
  if is_moon_weapon?(DRC.right_hand)
    wore_it = wore_it || DRC.bput("wear #{DRC.right_hand}", *MOON_WEAR_MESSAGES) == "telekinetic"
  end
  wore_it
end