Skip to content

Commit

Permalink
Merge pull request #1760 from Deysh/eloot-updates
Browse files Browse the repository at this point in the history
[eloot] v2.1.4 rework coin bag logic to reduce excessive inspect calls
  • Loading branch information
mrhoribu authored Jan 27, 2025
2 parents 321a1c4 + b4aeeb2 commit e6c6586
Showing 1 changed file with 48 additions and 40 deletions.
88 changes: 48 additions & 40 deletions scripts/eloot.lic
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
wiki: https://gswiki.play.net/Lich:Script_Eloot
game: Gemstone
tags: loot
version: 2.1.3
version: 2.1.4
Improvements:
Major_change.feature_addition.bugfix
v2.1.4 (2025-01-25
- rework coin bag logic to reduce excessive inspect calls
v2.1.3 (2025-01-24)
- bugfix in incrimental tipping
v2.1.2 (2025-01-23)
Expand Down Expand Up @@ -712,6 +714,12 @@ module ELoot
end
}
end

# is it a hand or a bag?
lines = ELoot.get_command("inspect ##{ELoot.data.coin_hand.id}", /You carefully inspect/, silent: true, quiet: true)
if lines.any? { |l| l =~ /can store a approximately (\d+) silver coins/ }
ELoot.data.coin_bag = ELoot.data.coin_hand
end
end
ELoot.msg(type: "debug", text: " ELoot.data.settings[:coin_hand_name]: #{ELoot.data.settings[:coin_hand_name].inspect} ELoot.data.coin_hand: #{ELoot.data.coin_hand.inspect}")

Expand Down Expand Up @@ -1068,45 +1076,37 @@ module ELoot
end

def self.use_coin_hand
return unless ELoot.silver_check.positive?
return if ELoot.data.coin_hand.nil?
available_silver = ELoot.silver_check
return unless available_silver.positive?

unless ELoot.data.coin_container.nil?
Inventory.free_hand
Inventory.open_single_container(ELoot.data.coin_container)
Inventory.drag(ELoot.data.coin_hand)
end

lines = ELoot.get_command("inspect ##{ELoot.data.coin_hand.id}", /You carefully inspect/, silent: true, quiet: true)

if lines.any? { |l| l =~ /can store a approximately (\d+) silver coins/ }
capacity = Regexp.last_match(1).to_i
# How many are there?
coins = 0
coin_lines = ELoot.get_command("look in ##{ELoot.data.coin_hand.id}", /inside the|There is nothing|that is closed/i, silent: true, quiet: true)
if ELoot.data.coin_bag.nil?
dothistimeout("close ##{ELoot.data.coin_hand.id}", 1, /You feel your pockets lighten/)
elsif !ELoot.data.coin_bag.nil? && !ELoot.data.coin_bag_full
Inventory.free_hand

if coin_lines.any? { |lines| lines =~ /That is closed/i }
Inventory.open_single_container(ELoot.data.coin_hand)
coin_lines = ELoot.get_command("look in ##{ELoot.data.coin_hand.id}", /inside the|There is nothing|that is closed/i, silent: true, quiet: true)
end
begin
lines = ELoot.get_command("put #{available_silver} silver in ##{ELoot.data.coin_bag.id}", /You place|There is only room|That might work better if you opened/)

if coin_lines.any? { |c| c =~ /you see approximately (\d+) silver coins/ }
coins = Regexp.last_match(1).to_i
end
bag_capacity = capacity - coins
available_coins = ELoot.silver_check
coin_storage = available_coins > bag_capacity ? bag_capacity : available_coins
if lines.any? { |l| l =~ /That might work better if you opened/i }
ELoot.get_command("open ##{ELoot.data.coin_bag.id}", ELoot.data.silent_open)
raise
end

unless coin_storage.zero?
Inventory.free_hand
ELoot.get_res("put #{coin_storage} silver in ##{ELoot.data.coin_hand.id}", /You place/)
Inventory.return_hands
if lines.find { |line| line.match(/There is only room for (?<silver>[\d,]+) more coins inside/) }
capacity = Regexp.last_match[:silver].gsub(',', '').to_i
ELoot.get_res("put #{capacity} silver in ##{ELoot.data.coin_bag.id}", /You place/)
ELoot.data.coin_bag_full = true
end
rescue
retry
end

ELoot.data.coin_bag = true
else
dothistimeout("close ##{ELoot.data.coin_hand.id}", 1, /You feel your pockets lighten/)
ELoot.data.coin_bag = false
end

unless ELoot.data.coin_container.nil?
Expand Down Expand Up @@ -1477,19 +1477,26 @@ module ELoot
Inventory.drag(ELoot.data.coin_hand)
end

lines = ELoot.get_command("inspect ##{ELoot.data.coin_hand.id}", /You carefully inspect/, silent: true, quiet: true)
if lines.any? { |l| l =~ /can store a approximately (\d+) silver coins/ } # these are the coin bags
ELoot.data.coin_bag = true
coin_lines = ELoot.get_command("look in ##{ELoot.data.coin_hand.id}", /inside the|There is nothing/i, silent: true, quiet: true)
if coin_lines.any? { |c| c =~ /you see approximately (\d+) silver coins/ }
coins = Regexp.last_match(1).to_i
ELoot.get_res("get #{coins} silver from ##{ELoot.data.coin_hand.id}", /You reach into/)
ELoot.wait_rt
end
else
ELoot.data.coin_bag = false
if ELoot.data.coin_bag.nil?
fput "open ##{ELoot.data.coin_hand.id}"
ELoot.wait_rt
else
begin
lines = ELoot.get_command("look in ##{ELoot.data.coin_bag.id}", /Inside the|There is nothing|That is closed/i, silent: true, quiet: true)

if lines.any? { |l| l =~ /That is closed/i }
ELoot.get_command("open ##{ELoot.data.coin_bag.id}", ELoot.data.silent_open)
raise
end

if lines.any? { |l| l =~ /Inside the .* you see approximately [,\d]+ silver coins\.|Get a job/i }
ELoot.get_res("get coins", /You reach into your/)
ELoot.data.coin_bag_full = false
ELoot.wait_rt
end
rescue
retry
end
end

# Return it to the container if needed
Expand Down Expand Up @@ -1716,7 +1723,7 @@ module ELoot
:charm, :gauntlet, :coin_bag, :reagent_horde_inv, :account_type, :gem_regex, :locker, :container_settings, :everything_list, :everything,
:only_list, :only, :inventory, :gem_inventory, :alchemy_inventory, :horde_type, :cache, :locker_city, :use_hording, :stash,
:items_to_horde, :horde_deposit, :inv_save, :deposit_regex, :withdraw_regex, :disk_nouns_regex, :sigil_determination_on_fail, :start_room, :last_called,
:urchin_msg, :gemshop_first, :reject_loot_names, :reject_loot_nouns, :version, :debug_logger, :details_check
:urchin_msg, :gemshop_first, :reject_loot_names, :reject_loot_nouns, :version, :debug_logger, :details_check, :coin_bag_full

def initialize(settings)
@settings = settings
Expand All @@ -1739,6 +1746,7 @@ module ELoot
@charm = nil
@gauntlet = nil
@coin_bag = nil
@coin_bag_full = false

@disk = nil
@disk_full = false
Expand Down

0 comments on commit e6c6586

Please sign in to comment.