Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[script][inventory-manager]add vault book,storage book,pocket. adjust vault surface handling for container nesting data #6859

Merged
merged 15 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 77 additions & 15 deletions inventory-manager.lic
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ class InventoryManager
],
[
{ name: 'save', regex: /save/i, description: "Save new or update current character's items to the database." },
{ name: 'vault_book', regex: /vault_book/i, optional: true, description: "DEPRECATED. Will call vault_standard." },
{ name: 'vault_book', regex: /vault_book/i, optional: true, description: "Uses vault book to get a list of items from your vault." },
{ name: 'vault_regular', regex: /vault_regular/i, optional: true, description: "Rummages your vault to save items NOTE: must be standing by your open vault." },
{ name: 'storage_box', regex: /storage_box/i, optional: true, description: "Rummages caravan storage box for items." },
{ name: 'storage_book', regex: /storage_book/i, optional: true, description: "Uses storage book to get a list of items from your caravan storage box." },
{ name: 'family_vault', regex: /family_vault/i, optional: true, description: "Rummages your family vault to save items NOTE: must be standing by your open vault." },
{ name: 'register', regex: /register/i, optional: true, description: "Reads contents of deed register." },
{ name: 'eddy', regex: /eddy/i, optional: true, description: "Save the contents of an eddy (HE 436 Gift)." },
{ name: 'scrolls', regex: /scrolls/i, optional: true, description: "Save spell scrolls tracked with sort-scrolls or stack-scrolls." },
{ name: 'home', regex: /home/i, optional: true, description: "Save home inventory." },
{ name: 'servant', regex: /servant/i, optional: true, description: "Save shadow servant inventory." },
{ name: 'shop', regex: /shop/i, optional: true, description: "Save your Trader shop inventory." },
{ name: 'pocket', regex: /pocket/i, optional: true, description: "Rummages your secret pocket container for list of items. NOTE: Must be wearing the container." },
{ name: 'vault_standard', regex: /vault_standard/i, optional: true, description: "Uses VAULT STANDARD to get a list of items." }
],
[
Expand All @@ -45,12 +47,11 @@ class InventoryManager
args = parse_args(arg_definitions)
@settings = get_settings
@inventory_ignores = @settings.inventory_manager_ignores

@vault_surfaces = @settings.inventory_manager_vault_surfaces
setup

if args.vault_book
DRC.message('Vault Book support has been removed in favor of VAULT STANDARD.')
add_vault_standard
add_vault_book
elsif args.vault_standard
add_vault_standard
elsif args.vault_regular
Expand All @@ -64,6 +65,8 @@ class InventoryManager
add_eddy_inv
elsif args.storage_box
add_storage_box_inv
elsif args.storage_book
add_storage_book
elsif args.scrolls
add_scrolls
elsif args.home
Expand All @@ -72,6 +75,8 @@ class InventoryManager
add_shadow_servant
elsif args.shop
add_trader_shop
elsif args.pocket
add_pocket_inv
elsif args.save
add_current_inv
elsif args.count
Expand Down Expand Up @@ -124,7 +129,7 @@ class InventoryManager
end

def valid_data_row(item)
if item.include?('(vault)') || item.include?('(register)') || item.include?('(eddy)') || item.include?('(caravan_box)') || item.include?('(Family)')
if item.include?('(vault)') || item.include?('(register)') || item.include?('(eddy)') || item.include?('(caravan_box)') || item.include?('(Family)') || item.include?('(pocket)')
true
else
false
Expand All @@ -149,7 +154,10 @@ class InventoryManager
count, closed = 0, 0
if desc.nil?
# Counting all items in inventory
capture = Lich::Util.issue_command('inv list', /^You have:/)
capture = []
until capture != []
capture = Lich::Util.issue_command('inv list', /^You have:/)
end
capture.each do |line|
item = line.lstrip

Expand All @@ -162,7 +170,10 @@ class InventoryManager
DRC.message("You have #{count} items, #{closed} of which are (closed) containers.")
else
# Counting items matching the description, i.e., inv count pouch
capture = Lich::Util.issue_command("inv search #{desc}", /rummage about your person/)
capture = []
until capture != []
capture = Lich::Util.issue_command("inv search #{desc}", /rummage about your person/)
end
capture.each do |line|
item = line.lstrip

Expand All @@ -184,8 +195,10 @@ class InventoryManager

get_item_data(inventory_type)

capture = Lich::Util.issue_command(command, end_pattern)

capture = []
until capture != []
capture = Lich::Util.issue_command(command, end_pattern)
end
lines = capture
# when rummaging, this block splits the items, including the last two that are split by and instead of a comma
if command.start_with?("rummage")
Expand All @@ -208,6 +221,10 @@ class InventoryManager
next if item.empty?
next if item.start_with?(*@inventory_ignores)

if item.start_with?(*@vault_surfaces)
container = item.to_s
next
end
# if the item starts with a -, it's in a container
if item[0].eql? '-'
item[0] = ''
Expand All @@ -223,6 +240,20 @@ class InventoryManager
else
container = item.to_s
end
elsif /vault book/.match(command)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 257 uses command == 'vault standard', the two new ones use /vault book/.match(command). I don't know this for sure, but .match does a regular expression comparison, which I suspect is more labor intensive than just doing a string compare. It's probably fairly insignificant, but I would think we're better off with consistency, in any event.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One other thought, you should probably combine the vault book and storage book, since the code itself is the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My initial thought was just being against"read my vault book" and "read my storage book" as the matches and typically just use regex. Can change to whatever.

I was following the example of vault and family vault being unique methods when I made the updates.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, not the methods, I just mean these two elsif statements. But just my two cents!

      elsif /vault book/.match(command)
        # items in vault book output are prefixed by 6 spaces
        if line =~ /\s{6}(?:a|an|some) /
          item.concat(" (in container - #{container})")
        else
          container = item.to_s
        end
      elsif /storage book/.match(command)
        # items in a storage book are prefixed by 6 spaces
        if line =~ /\s{6}(?:a|an|some) /
          item.concat(" (in container - #{container})")
        else
          container = item.to_s
        end

# items in vault book output are prefixed by 6 spaces
if line =~ /\s{6}(?:a|an|some) /
item.concat(" (in container - #{container})")
else
container = item.to_s
end
elsif /storage book/.match(command)
# items in a storage book are prefixed by 6 spaces
if line =~ /\s{6}(?:a|an|some) /
item.concat(" (in container - #{container})")
else
container = item.to_s
end
elsif command == 'vault standard'
# items in a container are prefixed by 11 spaces once the item count is removed
if line =~ /\s{11}(?:a|an|some) /
Expand Down Expand Up @@ -262,6 +293,15 @@ class InventoryManager
check_inventory("vault standard", /^Vault Inventory:/, 'vault')
end

def add_vault_book
unless DRCI.get_item_if_not_held?("vault book")
DRC.message("Unable to find your vault book, exiting!")
exit
end
check_inventory("read my vault book", /^Vault Inventory/, 'vault')
DRCI.stow_item?("book")
end

def add_current_inv
check_inventory("inv list", /^You have:/, 'character')
end
Expand All @@ -274,17 +314,26 @@ class InventoryManager

DRC.bput("turn my register to contents", 'You flip your deed register', 'already at the table of contents')

check_inventory("read my register", /^Stored Deeds:/, 'register')
check_inventory("read my register", /^Stored Deeds:|You haven't stored any deeds in this register/, 'register')

DRCI.stow_item?("register")
end

def add_eddy_inv
checkInventory("inv eddy", /^Inside a/, 'eddy')
check_inventory("inv eddy", /^Inside a/, 'eddy')
end

def add_storage_box_inv
check_inventory("rummage storage boc", /^You rummage through a storage box/, 'caravan_box', 41)
check_inventory("rummage storage box", /^You rummage through a storage box/, 'caravan_box', 41)
end

def add_storage_book
unless DRCI.get_item_if_not_held?("storage book")
DRC.message("Unable to find your storage book, exiting!")
exit
end
check_inventory("read my storage book", /^\W+in the known realms since 402/, 'caravan_box')
DRCI.stow_item?("book")
end

def add_family_vault
Expand All @@ -295,6 +344,10 @@ class InventoryManager
check_inventory("rummage vault", /^You rummage through a secure vault/, 'vault', 42)
end

def add_pocket_inv
check_inventory("rummage my pocket", /^You rummage through a pocket/, 'pocket', 36)
end

def add_scrolls
stacker_container = (@settings.scroll_sorter['stacker_container'] || @settings.stacker_container)
unless stacker_container
Expand Down Expand Up @@ -338,7 +391,10 @@ class InventoryManager

def check_scroll_stacker(stacker)
spells = []
capture = Lich::Util.issue_command("flip my #{stacker.split.last}", /^You flip through the #{stacker.split.last}, checking each section before closing it.$/)
capture = []
until capture != []
capture = Lich::Util.issue_command("flip my #{stacker.split.last}", /^You flip through the #{stacker.split.last}, checking each section before closing it.$/)
end
capture.each do |line|
if line =~ /The (.+) section has (\d+)/
spell = "#{Regexp.last_match(1)} (#{Regexp.last_match(2)})"
Expand Down Expand Up @@ -379,7 +435,10 @@ class InventoryManager
get_item_data('trader_shop')

surfaces = Hash.new
capture = Lich::Util.issue_command("shop customer", /^The following items contain goods for sale:/)
capture = []
until capture != []
capture = Lich::Util.issue_command("shop customer", /^The following items contain goods for sale:/)
end
capture.each do |line|
line = line.lstrip

Expand All @@ -392,7 +451,10 @@ class InventoryManager
end

surfaces.each do |surface|
capture = Lich::Util.issue_command(surface[1], /, you see:/)
capture = []
until capture != []
capture = Lich::Util.issue_command(surface[1], /, you see:/)
end
capture.each do |line|
line = line.lstrip

Expand Down
19 changes: 12 additions & 7 deletions profiles/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2190,13 +2190,6 @@ inventory_manager_ignores:
- 'Vault Inventory'
- 'Done'
- 'The last note'
- 'a brass hook'
- 'a steel wire rack'
- 'a small shelf'
- 'a top drawer'
- 'a middle drawer'
- 'a bottom drawer'
- 'a large shelf'
- 'Inside a'
- 'Page'
- 'Stored Deeds'
Expand All @@ -2205,6 +2198,18 @@ inventory_manager_ignores:
- 'The home contains'
- 'Within the belly'
- 'Your Servant is holding'
- 'in the known realms'
- 'A notation at'
- '...You have nothing currently stored'

inventory_manager_vault_surfaces:
- 'a brass hook'
- 'a steel wire rack'
- 'a small shelf'
- 'a top drawer'
- 'a middle drawer'
- 'a bottom drawer'
- 'a large shelf'

stabbity:

Expand Down
Loading