Closed Adalbar3333 closed 1 year ago
So this was supposed to already be a thing, but I guess I biffed the code and it never runs the part where it converts that decimal part into the smaller coins.
Oops
Fixed
Hello!!!
I'm still having problems using the baglib
's decimal function to alter lower coin types. I tried using the function of coins exactly, however it does not set the coins when I use baglib.save_bags
. Additionally, when I have the modify coins, it does not use the float as expected.
Here is the code I am using.
!test <drac2>
using(bagLib = '4119d62e-6a98-4153-bea9-0a99bb36da2c')
alter = ["+11.53","gp"]
ch = character()
bagsLoaded = bagLib.load_bags()
old_coins = bagLib.get_coins(bagsLoaded)[1].copy()
autoCoins = bagLib.settings.get('autoCoins',get("autocoins","0")=="1")
compact = bagLib.settings.get('compactCoins',get("compactcoins","0")=="1")
openMode = bagLib.settings.get('openMode','all').lower()
delta, coin_error = bagLib.parsecoins(alter)
focus = None
error = coin_error
cmd = ctx.prefix + ctx.alias
title = f"{name} looks inside"
positive = False
if delta:
focus, error = bagLib.modify_coins(bagsLoaded, autoCoins=autoCoins, delta = delta)
if not error:
delta = list(delta.items())
delta.sort(key=lambda x: x[1], reverse=True)
if delta[0][1]>0:
title = f"{name} adds"
positive = True
else:
title = f"{name} removes"
if not error:
for idx, cointup in enumerate(delta):
coin, quantity = cointup
title += f"{'' if idx == 0 else ',' if (positive and quantity>0) or (not positive and quantity<0) else ', and removes'} {bagLib.round_nicely(abs(quantity))} {coin}"
if positive and quantity<0:
positive = False
bag_name = "Coin Purse" if bagLib.use_coin_purse(bagsLoaded) else bagLib.coinPouchName
if delta:
title += f" to their {bag_name}" if positive else f" from their {bag_name}"
else:
title += f" their {bag_name}"
if not focus:
bagLib.get_coins(bagsLoaded)
if bagsLoaded:
success = bagLib.save_bags(bagsLoaded, error)
else:
success = -1 if error else 1
return ch.get_cvar('bags')
</drac2>
Greetings! Do you know what would be a really cool addition to the bagLib import you got??? The ability to use Decimals and have the bot place them into the correct spots. For example, when using bagLib:
bagLib.modify_coins(bags,'gp',-10.5)
removes 10 gold, and an electrum from your coins.Im not certain how to code this in, otherwise I would make a pull request for it. If I do end up finding something out for it, I will make the pull request.
It would make multi-coin type handling much easier.