Skip to content

Commit

Permalink
Updates to get_scrolls method
Browse files Browse the repository at this point in the history
This was previously buggy and failing to order scrolls much of the time. I redid some of the logic and moved to ROUND instead of CEIL which will reduce over-buying of scrolls.
  • Loading branch information
Nyctus committed Nov 3, 2023
1 parent f0bbb68 commit 9d844a8
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions sigilharvest.lic
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class SigilHarvest
@action_difficulty = { "trivial" => 1, "straightforward" => 2, "challenging" => 3, "difficult" => 4, "formidable" => 5 }

@args = parse_args(arg_definitions)
@debug = @args.debug

# sigil harvesting uses the same sorts of buffs that other gathering skills use i.e. outdoorsmanship and perception
DRCA.do_buffs(@settings, 'outdoors')
Expand Down Expand Up @@ -338,6 +337,7 @@ class SigilHarvest

# check our stock of scrolls since we just used some
get_scrolls
exit unless @args.roomcap #if roomcap was not specified, exit script once sigil-scrolls are harvested
end # scribe_sigils

# returns the current seasonw which determines what room list to pull from base-sigils
Expand All @@ -352,11 +352,9 @@ class SigilHarvest
@stock_scrolls ? target_scrolls = @stock_scrolls : target_scrolls = 25

# Count scrolls and store number in a variable, set variable to 0 if scrolls are not found
if /^There (?:are|is) (.*) scrolls? left for use with crafting\.$/ =~ DRC.bput("count my blank scrolls", 'I could not find', /^There (?:is|are) .* scrolls? left for use with crafting\.$/)
num_scrolls = DRC.text2num($1)
else
num_scrolls = 0
end
num_scrolls = DRCI.count_item_parts('blank scroll')
DRC.message("Scrolls Remaining: #{num_scrolls.to_s}") if @args.debug
DRC.message("Target Scrolls: #{target_scrolls.to_s}") if @args.debug

# if we have enough scrolls exit the function
return if num_scrolls >= target_scrolls
Expand All @@ -374,19 +372,27 @@ class SigilHarvest
scroll_price = 90 # dokora
end

DRC.message("Buying more scrolls from #{Room[scroll_room].title.to_s}") if @args.debug

# ensure hands are clear
DRCI.stow_hands

# blank scrolls come in a stack of 25, divide the difference by 25 and ceil to determine the number of times we need to order to meet or exceed stock target
num_to_order = ((target_scrolls - num_scrolls) / 25).ceil()
# blank scrolls come in a stack of 25, divide the difference by 25 and round to determine the number of times we need to order. (Changed to ROUND instead of CEIL. No longer tries to always meet or exceed value but instead gets close to target quantity.)
num_to_order = target_scrolls - num_scrolls
num_to_order = num_to_order / 25
num_to_order = num_to_order.round

# calculate the amount of money needed
coppers_needed = num_to_order * scroll_price

# go to bank if insufficient funds on hand
DRC.message("Getting #{coppers_needed.to_s} coppers to buy scrolls.") if @args.debug

#get money if needed
DRCM.ensure_copper_on_hand(coppers_needed, @settings)

# order repeatedly and combine
DRC.message("Ordering scrolls #{num_to_order} times.") if @args.debug
(1..num_to_order).each do
DRCT.order_item(scroll_room, 8)
DRC.bput('combine', /^You combine|^You must/)
Expand Down

0 comments on commit 9d844a8

Please sign in to comment.