Skip to content

Commit

Permalink
Merge branch 'rpherbig:master' into ct_honor_stop_hunting_if_bleeding
Browse files Browse the repository at this point in the history
  • Loading branch information
MahtraDR authored Jul 17, 2024
2 parents 6e9af3c + fd717cd commit 9344036
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 40 deletions.
6 changes: 3 additions & 3 deletions alchemy.lic
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Alchemy
waitrt?
end
quantity_needed -= 6 # Forage forages 6 units.
fput("put my #{ingredient['name']} in my #{@alchemy_herb_storage}")
DRCI.put_away_item?(ingredient['name'], @alchemy_herb_storage)
# Track the count down to make sure it stops when enough foraged.
echo("quantity_needed = #{quantity_needed}") if @debug
end
Expand All @@ -107,9 +107,9 @@ class Alchemy
f_stack = DRC.bput("count my first #{ingredient['output']}", 'You count out \d+ pieces').scan(/\d+/).first.to_i
s_stack = DRC.bput("count my second #{ingredient['output']}", 'I could not find', 'You count out \d+ pieces').scan(/\d+/).first.to_i
if f_stack == 75
DRC.bput("stow my first #{ingredient['output']}", "You put")
DRCI.put_away_item?("first #{ingredient['output']}", @herb_container)
elsif s_stack == 75
DRC.bput("stow my second #{ingredient['output']}", "You put", "Stow what?")
DRCI.put_away_item?("second #{ingredient['output']}", @herb_container)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion attunement.lic
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class Attunement
end
return true
end
case DRC.bput(get_perceive_command, "You fail to sense", "You're not ready to do that again, yet", "You reach out", "You sense:", "Roundtime")
case DRC.bput(get_perceive_command, "You fail to sense", "You're not ready to do that again, yet", "You reach out", "You sense:", "Roundtime", "Something in the area is interfering")
when "You reach out", "You sense:"
true
else
Expand Down
2 changes: 1 addition & 1 deletion bescort.lic
Original file line number Diff line number Diff line change
Expand Up @@ -2029,7 +2029,7 @@ class Bescort
end
@settings.hometown = town
succeeded = false
DRCM.minimize_coins(amount).each { |each_amount| succeeded = DRCM.get_money_from_bank(each_amount, settings) }
DRCM.minimize_coins(amount).each { |each_amount| succeeded = DRCM.get_money_from_bank(each_amount, @settings) }
echo "Put some fare money in the #{town} bank!" unless succeeded
manual_go2(room)
succeeded
Expand Down
138 changes: 111 additions & 27 deletions inventory-manager.lic
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,29 @@ 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." }
],
[
{ name: 'search', regex: /search/i, description: 'Start a search across all characters for specified item.' },
{ name: 'item', regex: /\w+/i, optional: false, description: 'Item to find.' }
{ name: 'item', regex: /\w+/i, optional: false, description: 'Item to find.' },
{ name: 'nest', regex: /nest|-n/i, optional: true, description: 'Print the nesting container data', default: false }
],
[
{ name: 'list', regex: /list/i, description: "Print out a list of names in the database." },
{ name: 'name', regex: /\w+/i, optional: true, description: "List full inventory for specified character. (Can spam!)" }
{ name: 'name', regex: /\w+/i, optional: true, description: "List full inventory for specified character. (Can spam!)" },
{ name: 'nest', regex: /nest|-n/i, optional: true, description: 'Print the nesting container data', default: false }
],
[
{ name: 'remove', regex: /remove/i, description: "Remove character's inventory." },
Expand All @@ -45,12 +49,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 +67,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,16 +77,18 @@ 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
get_inv_count(args.desc)
elsif args.remove
remove_character_data(args.name)
elsif args.search
search_for_item(args.item)
search_for_item(args.item, args.nest)
elsif args.list
list_character_inv(args.name)
list_character_inv(args.name, args.nest)
else
DRC.message('Type ;inventory-manager help for a usage guide')
end
Expand Down Expand Up @@ -124,7 +131,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 +156,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:/, timeout: 3) unless waitrt?
end
capture.each do |line|
item = line.lstrip

Expand All @@ -162,7 +172,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/, timeout: 3) unless waitrt?
end
capture.each do |line|
item = line.lstrip

Expand All @@ -184,8 +197,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, timeout: 3) unless waitrt?
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 @@ -201,32 +216,50 @@ class InventoryManager
end

container = ""
sub_container = ""
lines.each do |line|
line.sub!(/\(\d+\)/, '') if command == 'vault standard'
item = line.lstrip

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] = ''
item.concat(" (in container - #{container})")
if line =~ /\s{8,}-(?:a|an|some|the|several|clusters|one) /
item.concat(" (nested container - #{sub_container})")
elsif line =~ /\s{5}-(?:a|an|some|the|several|clusters|one) /
item.concat(" (in container - #{container})")
sub_container = item.to_s
else
container = item.to_s
end
elsif inventory_type == 'character'
# We don't want the inventory_type here as it's extra noise, so we do a .to_s so container doesn't get updated by changing item later
container = (item.include?("eddy") ? "eddy" : item).to_s
item.concat(' (worn)')
elsif inventory_type == 'shadow_servant'
# items in a container are prefixed by 6 spaces
if line =~ /\s{6}(?:a|an|some) /
elsif command == "read my storage book" || command == "read my vault book" || inventory_type == "shadow_servant"
# Vault book, storage book and shadow servant via PG all have same output formatting
if line =~ /\s{8,}(?:a|an|some|the|several|clusters|one) /
item.concat(" (nested container - #{sub_container})")
elsif line =~ /\s{6}(?:a|an|some|the|several|clusters|one) /
item.concat(" (in container - #{container})")
sub_container = item.to_s
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) /
if line =~ /\s{16,}(?:a|an|some|the|several|clusters|one) /
item.concat(" (nested container - #{sub_container})")
elsif line =~ /\s{11}(?:a|an|some|the|several|clusters|one) /
item.concat(" (in container - #{container})")
sub_container = item.to_s
else
container = item.to_s
end
Expand Down Expand Up @@ -262,6 +295,17 @@ 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 +318,28 @@ 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 +350,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 +397,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.$/, timeout: 3) unless waitrt?
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 +441,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:/, timeout: 3) unless waitrt?
end
capture.each do |line|
line = line.lstrip

Expand All @@ -392,7 +457,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:/, timeout: 3) unless waitrt?
end
capture.each do |line|
line = line.lstrip

Expand All @@ -405,7 +473,7 @@ class InventoryManager
save_item_data('trader_shop')
end

def list_character_inv(name)
def list_character_inv(name, nested)
if name.nil?
DRC.message("There is inventory data for:")
@item_data.each do |k, v|
Expand All @@ -423,20 +491,28 @@ class InventoryManager
name_sym = name.capitalize.to_sym
if @item_data.has_key?(name_sym)
DRC.message("Inventory for #{name.capitalize}")
@item_data[name_sym].each { |item| DRC.message(" - #{item}") }
@item_data[name_sym].each { |item|
if !nested
item = strip_nesting(item)
end
DRC.message(" - #{item}")
}
else
DRC.message("No data found for the character #{name.capitalize}!")
end
end

def search_for_item(item)
def search_for_item(item, nested)
total_found = 0
@item_data.each do |k, v|
next if k == @version_string

total_found = 0
DRC.message("Checking #{k}:")
v.each { |data|
if !nested
data = strip_nesting(data)
end
if data.downcase.include?(item)
total_found += 1
DRC.message("Match #{total_found}): #{data}")
Expand All @@ -446,6 +522,14 @@ class InventoryManager
end
end

def strip_nesting(item)
if (match = /^(?<tap>[a-z "':!-]*(?<closed>\(closed\))?)\s\((?<nest1>(?<nest2>nested container[a-z "':!-]*)\s\()?(?<main>in container[a-z "':!-]*)\)?\)\s(?<origin>\(.*\))$/i.match(item))
return "#{match["tap"]} #{match["origin"]}"
else
return item
end
end

def remove_character_data(name_to_remove)
return if name_to_remove == "version"

Expand Down
Loading

0 comments on commit 9344036

Please sign in to comment.