Class: Lich::Gemstone::StowList

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

Overview

Represents a list of items to stow in the Lich game. This class manages the stow list and provides methods to check, reset, and validate the stow targets.

Examples:

Lich::Gemstone::StowList.checked = true
Lich::Gemstone::StowList.check

Constant Summary collapse

ORIGINAL_STOW_LIST =

The original list of stowable item types.

[:box, :gem, :herb, :skin, :wand, :scroll, :potion, :trinket, :reagent, :lockpick, :treasure, :forageable, :collectible, :default]

Class Method Summary collapse

Class Method Details

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

Note:

This method will set the checked status to true after execution.

This method returns an undefined value.

Checks the stow list and updates the checked status.

Examples:

Lich::Gemstone::StowList.check(silent: true)

Parameters:

  • silent (Boolean) (defaults to: false)

    If true, suppresses output.

  • quiet (Boolean) (defaults to: false)

    If true, uses a quiet output pattern.



92
93
94
95
96
97
98
99
100
101
# File 'documented/gemstone/stowlist.rb', line 92

def check(silent: false, quiet: false)
  if quiet
    start_pattern = /<output class="mono"\/>/
  else
    start_pattern = /You have the following containers set as stow targets:/
  end
  waitrt?
  Lich::Util.issue_command("stow list", start_pattern, silent: silent, quiet: quiet)
  @checked = true
end

.checked=(value) ⇒ Boolean

Sets the checked status of the stow list.

Parameters:

  • value (Boolean)

    The new checked status.

Returns:

  • (Boolean)

    The updated checked status.



54
55
56
# File 'documented/gemstone/stowlist.rb', line 54

def checked=(value)
  @checked = value
end

.checked?Boolean

Checks if the stow list has been validated.

Returns:

  • (Boolean)

    True if the stow list has been checked, false otherwise.



47
48
49
# File 'documented/gemstone/stowlist.rb', line 47

def checked?
  @checked
end

.reset(all: false) ⇒ Object

Resets the stow list entries to nil.

Parameters:

  • all (Boolean) (defaults to: false)

    If true, resets all entries; otherwise, only resets original stow list.



77
78
79
80
81
82
83
# File 'documented/gemstone/stowlist.rb', line 77

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

.stow_listHash

Returns the current stow list.

Returns:

  • (Hash)

    The stow list with item types as keys and their values.



41
42
43
# File 'documented/gemstone/stowlist.rb', line 41

def stow_list
  @stow_list
end

.valid?(all: false) ⇒ Boolean

Note:

This method requires that the stow list has been checked.

Validates the stow list entries.

Parameters:

  • all (Boolean) (defaults to: false)

    If true, checks all entries; otherwise, only checks original stow list.

Returns:

  • (Boolean)

    True if all checked entries are valid, false otherwise.



62
63
64
65
66
67
68
69
70
71
72
73
# File 'documented/gemstone/stowlist.rb', line 62

def valid?(all: false)
  # check if existing containers are valid or not
  return false unless checked?
  @stow_list.each do |key, value|
    next unless all || ORIGINAL_STOW_LIST.include?(key)
    unless value.nil? || GameObj.inv.map(&:id).include?(value.id)
      @checked = false
      return false
    end
  end
  return true
end