Shopkeepers

Shopkeepers

2M Downloads

Support for an arbitrary amount of currencies

blablubbabc opened this issue · 10 comments

commented

Currently the selling and buying shopkeepers only support 2 currencies: High and low.
Idea: Allow admins to setup additional currencies (with even larger values) in the config.

The plugin would then have to dynamically convert between these currencies when a player sets up prices inside the shopkeeper editor, which could work like this:
Currently:

  • Selling (normal) shopkeeper: The player specifies low and high currency price separately via clicking actions in the editor window.
  • Buying shopkeeper: The player can only specify the price using the low currency.

Instead:
Let the player edit the price via the same clicking actions as now, but limit it to a single clickable slot. Use a second non-clickable slot to display the setup amount in the next larger currency (or more general: a second currency).
If the clicked slot's item amount reaches a certain value (the max stack size, or the value or the min-cost of the next larger currency), increase the amount of the item in the slot representing the next larger currency and decrease the amount of the clicked item accordingly. If the amount of the high currency reaches a certain limit, switch the used currencies to use the next larger ones.

Alternatively: Maybe have both slots clickable, and allow switching the currency item by some click type that isn't used yet (ctrl-left/right click possible?).

Also, the chest contents could get dynamically 'compressed' to always use the largest currencies possible to represent the currently stored value, making best use of the available chest space.

TODO: figure out in detail how this could work.

commented

Hello there;
I am struggling here.

We use Gringotts via Vault as our in-game bank. It allows item-based currencies.
So, we have several.
Emeralds named "Alaesian Jots" are worth 1.
Diamonds named "Imperial Astyr" are worth 5.
Iron Nuggets named "Ervyn La'hr" are worth 2.
And Gold Nuggets named "Saghrel Ba'hn Piece" are worth 3.

I can set a Shopkeeper to use any 1 of the above currencies. But, being a medieval server, it gets complex.
The "Alaesian Jot" is our dollar. The "Imperial Astyr" is our $20 bill.
The Empire of Alaesia contains the Kingdom of Ervos, in which "Eryvn La'hr" are more popular.

So, in some regions (Ervos), players/people use Jots, Astyr, and La'hr.

It is sort of okay, for "pay outs." If a player sells an Ervyn Shopkeeper a product, it makes sense that it is in La'hr, for example.

Yet, when players are BUYING stuff, they should be able to spend their Jots & Astyr anywhere, as the Empire contains the rest of the Realm.

So, how can we go about introducing this?
It wouldn't be too difficult, I imagine. Can the plugin be hooked into Vault?

commented

I know you've marked this for "the indefinite future," but, if you're able to get this worked out, my server will be situated. This is the only Trader option that is a viable alternative to Citizens 2.
I would LOVE gringotts compatibility, through Vault.

commented

Interesting. I haven't considered this scenario yet of letting players offer any of the available currency items and then dynamically update the available offers of the shopkeeper.
You would probably also have to handle handing out any remaining change then (player offers gold nugget worth of 3, but the item only costs 2).

And another issue might be that the player gets confused, since the trade would update from 'requires-cost-2-item' to 'requires-cost-3-item', since he doesn't know at first whether he will get any excess change back when accepting the trade for these new conditions.
Maybe this could be somehow solved by still displaying the original trade, but regardless of that insert the result item into the result slot and still allow the trade. The problem would be, that minecraft constantly (or at least when the input items change) tries to update the result slot to the item it expects there. So one would have to manually keep this consistent according to the own trading rules.
And one would have to replace the logic responsible for determining the recipe used for the trade.

I don't know how difficulty this would be to implement or how well it would actually work. However, any differences between the server's behavior and the client's expectations are usually prone to issues.. (the smallest but most certain of these issues would be that items temporarily pop up).
Shopkeepers therefore tries to keep its behavior mostly in-line with the vanilla behavior (exceptions being preventing trades or unsupported types of clicks).

Anyways, this ticket was more about how to dynamically determine the currency items to use for a trade, depending on some (simple) player interactions in the editor window. The trade, and the currency items it uses, would in the end however (when presented to a trading player) still be fixed.
Somehow being able to also dynamically accept any of the setup currency items would however fit well into this (assuming this is indeed possible without larger issues).

I will have to do some testing if/when I find some time for this. But this certainly sounds interesting.

Right now, what you can do with the admin shopkeepers, is to set up multiple trades for the same item, each accepting different currencies.
This however wouldn't handle returning of excess change, and it wouldn't be as nice and user-friendly as dynamically accepting the various currency items: The player would have to skip through a bunch of trades he isn't interested in, until he finds the one matching the currency he has on hand.
Something else that might help here: Maybe it would be possible to automatically select a matching trade depending on the items the player has already inserted, or depending on the items he has in his inventory. Or maybe automatically skip, or even remove all trades for which the player doesn't have the correct currency items in his inventory.
This might even be possible to do with a separate plugin, hooking into Shopkeepers and updating the trading recipes right after the player has opened the merchant inventory view of a shopkeeper.
An external plugin might even be able to automatically/dynamically create the trades corresponding to the different currency items.

Regarding hooking into Vault: I am not sure how that would help in this scenario.
Vault doesn't support different currencies in its API (this seems to be a Gringotts-specific feature), so this would still have to be specified and handled inside Shopkeepers anyways. And Shopkeepers would be mostly incompatible with most economy plugins, since most economy plugins are not item based (which makes using the item-based trading interface mostly useless then -> there are better shop plugins specific for these).

commented
commented

The math of summing up the value of the different currency items and calculating the change is not the problem (Shopkeepers is doing that already when converting between high and low currency, and when removing/adding currency from/to chests).

The problem is: Shopkeepers is using minecraft's trading interface, which only supports a fixed list of trades, and each trade only supports 2 input and 1 output item.

I should also be able to give it 10 Jots, 3 La'hr, and one Astyr.

I don't see how this would work with minecraft's trading interface (which only allows 2 inputs).

Assuming we limit the input to 2 items at most:
The largest problem would be to let the trading dynamically adjust to the offered items, while still using minecraft's trading interface, which is backed by minecraft's trading logic under-the-hood. (I tried to outline some of the difficulties about that above).

This might not be an issue for other shop plugins, which don't have the 'limitations' of using minecraft's trading interface, and which can therefore use Vault and support any type of economy plugin. But since Shopkeepers uses minecraft's trading interface, I have those 'limitations'.

Edit:
Something else which might principally be possible:
When the player drops some currency item into one of the input slots, a plugin could automatically convert it to the lowest, or the required currency.

Example:
Player has 4 Astyrs (=20 Jots) in his inventory.
He opens a trading window which offers some item for 18 Jots.
Player picks up the 4 Astyrs onto his cursor.
Player clicks the input slot of the trading interface.
The cursor gets cleared, the 4 Astrys gets converted to 20 Jots, which get added to the input slot.
The player takes the item from the result slot: 18 Jots are removed from the input slot.
The player picksup the remaining 2 Jots and returns them into his inventory.

Maybe this is even what you meant above.

This would basically allow the player the convert the currency he is carrying right inside the trading inventory.

commented

Something which is possible now already, with the existing Shopkeeper features: You could of course explicitly setup trades which convert between the different accepted currencies to the shopkeeper's local currency. So for your 4 overall currencies (assuming all are accepted everywhere), you would need to add 3 additional trades per shopkeeper.
Or possibly even better/more realistically: You could have one/multiple separate shopkeeper(s) in each region, which offer these exchange services. So if players happen to not have the correct currency at hand required at the region they are trying to trade in, they would first have to go to this exchange shopkeeper. To make it even more realistically, you could even let them apply different exchange rates there (making the exchanging cost the player something, if you would want that).

What is this "second slot" for adding currency? The "high" and the "low" number?

If you are referring to the initial post of this ticket, it refers to the current editor window of (selling) player shopkeepers. See here: https://raw.githubusercontent.com/wiki/Shopkeepers/Shopkeepers-Wiki/images/setup/setup-player-shop-sell-text.png
This is where players currently configure the costs of traded items using the 2 available currencies.

commented

Well articulated.

That could work as well, having "in-trader" live conversions.
Honestly, whatever you wish to do, obviously, I support. I by no means claim to be a coder, though, I believe I'm beginning to understand the basic "rules" it follows. That said, I recognize that I am now not in your role; rather, I write to you from an artistic standpoint. My server is the source of inspiration for an original mythological universe, within which I (as a creative writer) have been drawing out stories, with aspirations of literature.

So for me, I am trying to bring my world to life, to make it "realistic," and immersive.
Or at least a passionately attempted Minecraft manifestation of it.

"Realistically," it makes sense as is. Individuals only trading with one currency. It is less likely that any given shopkeeper in our universe would have the means by which to do live currency exchanges.

However, that would be a great feature to add, regardless (perhaps optionally).

Either way, I appreciate your support greatly.

I have to admit I am a bit confused about one thing, though.
What is this "second slot" for adding currency?
The "high" and the "low" number?
I've yet to fully grasp it.

commented
commented

I think my server is much simpler, we only have a place to buy and sell all kind of items, and we also have this villager who exchanges the different values.

Pretty basic, 1 coal is 1 dBs, 9 coals or 1 block of coal is 1 emerald, which is 10 dBs, and so on till you get to a diamond, with a value of 10.000 dBs

This is all really simple and Shopkeepers saved me a lot of time since we used a complex system with commands that broke everytime.

Now, the thing is that i am struggling to find a plugin or something that allows me to make a bank that allows me to deposit Emeralds, Ingots and Diamonds, maybe blocks too. I have been searching a lot of economy plugins but i can't seem to find any that helps me out with this.

commented

@Ozymandi4Z Gringotts might support that with their 'vaults'. I think to remember that they also support multiple currencies.