Class: Lich::Gemstone::StowList

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

Overview

Represents a list of items that can be stowed.

This class manages the stow list entries and their states.

Constant Summary collapse

ORIGINAL_STOW_LIST =
[: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

This method returns an undefined value.

Checks the current stow list status and updates the checked state.

Parameters:

  • silent (Boolean) (defaults to: false)

    if true, suppresses output messages.

  • quiet (Boolean) (defaults to: false)

    if true, uses a quiet output pattern.



82
83
84
85
86
87
88
89
90
91
# File 'documented/gemstone/stowlist.rb', line 82

def check(silent: false, quiet: false)
  if quiet
    start_pattern = /<output class="mono"\/>|^You are a ghost!/
  else
    start_pattern = /You have the following containers set as stow targets:|^You are a ghost!/
  end
  waitrt?
  results = Lich::Util.issue_command("stow list", start_pattern, silent: silent, quiet: quiet)
  @checked = results.any? { |line| line.match?(/You have the following containers set as stow targets/) }
end

.checked=(value) ⇒ Object



44
45
46
# File 'documented/gemstone/stowlist.rb', line 44

def checked=(value)
  @checked = value
end

.checked?Boolean

Returns:

  • (Boolean)


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

def checked?
  @checked
end

.reset(all: false) ⇒ void

This method returns an undefined value.

Resets the stow list entries to nil.

Parameters:

  • all (Boolean) (defaults to: false)

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



69
70
71
72
73
74
75
# File 'documented/gemstone/stowlist.rb', line 69

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_listObject



36
37
38
# File 'documented/gemstone/stowlist.rb', line 36

def stow_list
  @stow_list
end

.valid?(all: false) ⇒ Boolean

Checks if the stow list entries are valid.

Parameters:

  • all (Boolean) (defaults to: false)

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

Returns:

  • (Boolean)

    true if all checked entries are valid, false otherwise.



52
53
54
55
56
57
58
59
60
61
62
63
# File 'documented/gemstone/stowlist.rb', line 52

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