Closed Adalbar3333 closed 1 year ago
Utilizing the !coins
alias on the workshop does not handle coins as desired.
If you have the lesser coins (silver and copper in the above example), it will remove the coin. Though, I did expect that if it had the gold above it, it will remove 1 gold, and add it to the silver, or copper as needed.
Here is the code I have in an alias of mine to handle coins, though it may need cleanup and organization to be added to your alias. I just want to help improve it to allow more people to handle their custom coins easier, rather than needing to use the coinpurse
built in now.
This def I have also handles if it needs to use the coinpurse option if the user does not have a "Coin Pouch" bag.
def handle_coins(costs, ctype=coinTypes[0]):
bagsLoaded = load_yaml(get('bags', '[]'))
maybepouch = [i for i in bagsLoaded if i[0] == 'Coin Pouch'] or coinRates != DEFAULT_coinRates and [["Coin Pouch", {"cp": 0, "sp": 0, "ep": 0, "gp": 0, "pp": 0}]]
if maybepouch:
pouch = maybepouch[0]
if pouch not in bagsLoaded:
bagsLoaded.append(pouch)
pouch = [i for i in bagsLoaded if i[0] == 'Coin Pouch'][0]
coins = pouch[1]
coins.update({ctype:coins[ctype]+costs})
for coin in coinTypes[:-1]: # for each coin type except for the last one
larger = coinTypes[coinTypes.index(coin)+1] # get the coin type that is one larger (cp -> sp, etc)
rate = int(coinRates[coin]/coinRates[larger]) # find the rate between the current coin and the larger coin. (cp/sp = 100/10=10)
p = coins[coin]//rate # find the new value by dividing the current amount of coins by the rate
if coins[coin] < 0: # if our coin subtraction brought this coin type below 0 coins:
coins.update( # Update our coin pouch
{
larger:coins[larger]+p, # Subtract the new value to the larger coin type (since p is negative)
coin:coins[coin]-p*rate # Add the new value multiplied by the rate to the smaller coin type
}
)
# If they dont have the coin, it errors.
error = any([coins[x]<0 for x in coins])
if not error:
character().set_cvar("bags",dump_json(bagsLoaded))
else:
purse = character().coinpurse
delta = parse_coins(f"{costs}{ctype}")
if not (error:=-delta.total > purse.total):
purse.modify_coins(delta.pp, delta.gp, delta.ep, delta.sp, delta.cp)
coins = {coin:purse[coin] for coin in coinTypes}
return error, coins
This should be fixed with aa89c92
Hello!!! Sorry for being annoying about it...
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 usebaglib.save_bags
. Additionally, when I have the modify_coins, it does not use the float as expected.Here is the code I am using.
You can totally just ping me on the Avrae server or PM me via discord rather than replying here and just close it after confirming the fix.
Originally posted by @Adalbar3333 in https://github.com/LazyDope/avrae-stuff/issues/13#issuecomment-1647048536