Class: Lich::Gemstone::ReadyList

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

Overview

Note:

Entries are stored as GameObj instances; ReadyList.valid? confirms all stored items remain in inventory, containers, or hands.

Tracks equipped items and storage locations from the "ready list" command in GemStone IV.

Maintains two parallel lists: a ready list of currently equipped items (shields, weapons, wands, etc.) and a store list of items staged for retrieval from storage. Use ReadyList.check to sync state from the game server, then read individual entries via accessor methods like weapon or store_weapon.

Constant Summary collapse

ORIGINAL_READY_LIST =

Standard game-provided ready list entry types.

Represents the default equipment slots GemStone IV tracks: shields, primary/secondary weapons, ranged weapons, ammo bundles, sheaths, and wands.

[:shield, :weapon, :secondary_weapon, :ranged_weapon, :ammo_bundle, :ammo2_bundle, :sheath, :secondary_sheath, :wand]
ORIGINAL_STORE_LIST =

Standard game-provided store list entry types.

Subset of ORIGINAL_READY_LIST used for tracking items awaiting retrieval from storage. Excludes ammo2_bundle, sheath, and secondary_sheath.

[:shield, :weapon, :secondary_weapon, :ranged_weapon, :ammo_bundle, :wand]

Class Method Summary collapse

Class Method Details

.check(silent: false, quiet: false) ⇒ void

This method returns an undefined value.

Syncs ready list state from the game server by parsing "ready list" command output.

Waits for roundtime, issues the "ready list" command, and reads equipment assignments from the server response. Parses the response to extract item IDs and slot types, populating ready_list and store_list. Sets checked? to true only if the response contains "Your current settings are:", indicating a valid ready list from the server.

Examples:

Lich::Gemstone::ReadyList.check

Parameters:

  • silent (Boolean) (defaults to: false) —

    if true, suppress command echoing to the script window (default: false)

  • quiet (Boolean) (defaults to: false) —

    if true, use compact XML output format instead of human-readable (default: false); affects the start_pattern used to parse server response

See Also:



168
169
170
171
172
173
174
175
176
177
# File 'documented/gemstone/readylist.rb', line 168

def check(silent: false, quiet: false)
  if quiet
    start_pattern = /<output class="mono"\/>|^You are a ghost!/
  else
    start_pattern = /Your current settings are:|^You are a ghost!/
  end
  waitrt?
  results = Lich::Util.issue_command("ready list", start_pattern, silent: silent, quiet: quiet)
  @checked = results.any? { |line| line.match?(/Your current settings are:/) }
end

.checked=(value) ⇒ 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.

Sets the checked state flag.

Parameters:

  • value (Boolean) —

    whether the ready list is considered in sync with the server

Returns:

  • (Boolean) —

    the assigned value



100
101
102
# File 'documented/gemstone/readylist.rb', line 100

def checked=(value)
  @checked = value
end

.checked? ⇒ Boolean

Returns true if check has successfully synced state from the game server.

Returns:

  • (Boolean) —

    true if the ready list has been checked; false initially or after reset

See Also:



91
92
93
# File 'documented/gemstone/readylist.rb', line 91

def checked?
  @checked
end

.ready_list ⇒ Hash{Symbol => GameObj, nil}

Returns the internal hash mapping equipment slot names to GameObj instances.

Examples:

Lich::Gemstone::ReadyList.ready_list
#=> {:shield=>nil, :weapon=>#<GameObj id=12345>, ...}

Returns:

  • (Hash{Symbol => GameObj, nil}) —

    keys are :shield, :weapon, :secondary_weapon, :ranged_weapon, :ammo_bundle, :ammo2_bundle, :sheath, :secondary_sheath, :wand; values are GameObj or nil if unset



72
73
74
# File 'documented/gemstone/readylist.rb', line 72

def ready_list
  @ready_list
end

.reset(all: false) ⇒ void

This method returns an undefined value.

Clears all stored entries and sets checked state to false.

Sets checked= to false, then nilifies entries in ready_list and store_list.

Examples:

Lich::Gemstone::ReadyList.reset

Parameters:

  • all (Boolean) (defaults to: false) —

    if true, reset all entries; if false (default), reset only entries in ORIGINAL_READY_LIST and ORIGINAL_STORE_LIST

See Also:



142
143
144
145
146
147
148
149
150
151
152
# File 'documented/gemstone/readylist.rb', line 142

def reset(all: false)
  @checked = false
  @ready_list.each do |key, _value|
    next unless all || ORIGINAL_READY_LIST.include?(key)
    @ready_list[key] = nil
  end
  @store_list.each do |key, _value|
    next unless all || ORIGINAL_STORE_LIST.include?(key)
    @store_list[key] = nil
  end
end

.store_list ⇒ Hash{Symbol => GameObj, nil}

Returns the internal hash mapping storage slot names to GameObj instances.

Examples:

Lich::Gemstone::ReadyList.store_list
#=> {:shield=>nil, :weapon=>#<GameObj id=67890>, ...}

Returns:

  • (Hash{Symbol => GameObj, nil}) —

    keys are :shield, :weapon, :secondary_weapon, :ranged_weapon, :ammo_bundle, :wand; values are GameObj or nil if unset



83
84
85
# File 'documented/gemstone/readylist.rb', line 83

def store_list
  @store_list
end

.valid?(all: false) ⇒ Boolean

Verifies that all stored equipment items still exist in inventory, containers, or hands.

Confirms checked? is true, then iterates the ready list verifying each non-wand entry either has a nil value or the GameObj (by id) still appears in GameObj.inv, GameObj.containers, GameObj.right_hand, or GameObj.left_hand. Wand entries are excluded from validation. Sets checked= to false if any item is missing.

Examples:

Lich::Gemstone::ReadyList.check
Lich::Gemstone::ReadyList.valid? #=> true

Parameters:

  • all (Boolean) (defaults to: false) —

    if true, validate all ready_list entries; if false (default), validate only entries in ORIGINAL_READY_LIST

Returns:

  • (Boolean) —

    true if checked and all relevant items are valid; false if not checked or an item is missing

See Also:



119
120
121
122
123
124
125
126
127
128
129
130
# File 'documented/gemstone/readylist.rb', line 119

def valid?(all: false)
  # check if existing ready items are valid or not
  return false unless checked?
  @ready_list.each do |key, value|
    next unless all || ORIGINAL_READY_LIST.include?(key)
    unless key.eql?(:wand) || value.nil? || GameObj.inv.map(&:id).include?(value.id) || GameObj.containers.values.flatten.map(&:id).include?(value.id) || GameObj.right_hand.id.eql?(value.id) || GameObj.left_hand.id.eql?(value.id)
      @checked = false
      return false
    end
  end
  return true
end