whelan / fvtt-merchant-sheet-npc

FVTT - Merchant Sheet NPC 5E
MIT License
12 stars 13 forks source link

Custom Currencies #82

Closed cstby closed 2 years ago

cstby commented 2 years ago

Is your feature request related to a problem? Please describe.

As a DM of a world with custom currencies, I need to some merchants to only use certain currencies. For example, a merchant in a junkyard on Tatoonie may not be inclined to accept imperial credits. A leader of an orc tribe might accept metal coinage, but not paper money from the nearby kingdom.

Describe the solution you'd like

I'm proposing several pieces of functionality in priority order:

Listing Currency

For example: When making a merchant in the kingdom capital, I select his listing currency as "Royal Crowns," which I have already loaded to the 5e config using a custom currencies module. The exchange rate set in the config specifies that there are 100 Crowns to 1 Gold Piece, and that the abbreviation for Crowns is "Cr". The price of the dagger in the merchant's inventory would now be "200 Cr" instead of "2".

Accepted Currencies

For example: The GM specifies that the merchant only takes Royal Crowns. A player has 10 gold pieces but no Royal Crowns. When attempt to buy the dagger, they are told they do not have enough money. "Those old gold pieces don't spend here in the capital, friend."

Available Currency

Ideally, the GM would have some control over which currencies a player would get back when selling an item to a merchant. The implementation will depend on whether you plan for GMs to specify how much of each currency a merchant has on hand.

Currency Rates (Maybe?)

Some merchant may deal in other currencies but only at a high price. Along with each accepted currency, there would be a multiplier that represents the merchant's markup. This might be out of scope, as it can already be achieved with some manual configuration if the above features are implemented.

For example: The GM sets the merchant's currency rate to 1.5x. The merchant is willing to take 3 gold for the dagger.

Describe alternatives you've considered

Additional context

whelan commented 2 years ago

Just trying to understand some of the things mentioned here.

You have a custom module to change the rates from the default DND5e? Do you have any link to the custom currencies module, maybe they have an API that can be integrated? It would be possible for me to check for other modules that are installed. I like the ideas about currency rates, just don't have an idea right now how to implement it.

I also would love to have time to investigate how a merchant can have limited money to buy stuff from players. :)

cstby commented 2 years ago

Awesome. I'm glad you're interested in this use case. :)

I just started a refactor of the "5e Custom Currencies" module. The original module looks like it is broken right now. I've linked both my WIP refactor and the orginal module below. I'll explain the API here to save you the trouble of reading through the code.

The D&D 5e system for Foundry records currencies into the CONFIG object. The default currencies looks like this. (You can get it by typing CONFIG.DND5e.currencies into the console after starting a foundry world that uses the dnd5e system.)

DND5E.currencies = {
  pp: {
    label: "DND5E.CurrencyPP",
    abbreviation: "DND5E.CurrencyAbbrPP"
  },
  gp: {
    label: "DND5E.CurrencyGP",
    abbreviation: "DND5E.CurrencyAbbrGP",
    conversion: {into: "pp", each: 10}
  },
  ep: {
    label: "DND5E.CurrencyEP",
    abbreviation: "DND5E.CurrencyAbbrEP",
    conversion: {into: "gp", each: 2}
  },
  sp: {
    label: "DND5E.CurrencySP",
    abbreviation: "DND5E.CurrencyAbbrSP",
    conversion: {into: "ep", each: 5}
  },
  cp: {
    label: "DND5E.CurrencyCP",
    abbreviation: "DND5E.CurrencyAbbrCP",
    conversion: {into: "sp", each: 10}
  }
};

(https://gitlab.com/foundrynet/dnd5e/-/blob/master/module/config.js#L560)

The names and labels are pulled from the localization file (en.json), which cannot be patched after foundry has loaded afaik. Any maintainable custom currencies module should gather the currency specs from the user and then patch the above config object. This is what the currently broken custom currencies module tries to do. Here is an example of what the currencies would look like after they are patched:

{
    "pp": {
        "label": "Concordian Lira",
        "abbreviation": "₤"
    },
    "gp": {
        "label": "Gold Pieces",
        "abbreviation": "GP",
        "conversion": {
            "into": "pp",
            "each": 50
        }
    },
    "ep": {
        "label": "Silver Pieces",
        "abbreviation": "SP",
        "conversion": {
            "into": "gp",
            "each": 10
        }
    },
    "sp": {
        "label": "Concordian Mille",
        "abbreviation": "₥",
        "conversion": {
            "into": "ep",
            "each": 2
        }
    },
    "cp": {
        "label": "Dwendalian Crowns",
        "abbreviation": "₡",
        "conversion": {
            "into": "sp",
            "each": 5
        }
    }
}

You'll notice above that the keywords "cp", "sp" etc. remain. Character sheets and loot sheets can use those keys to access the labels, abbreviations and conversion. From your module's perspective, it actually does not need to know or care whether the currencies were patched. As long as it pulls the names, abbreviations, and conversion rates from this config object, it'll work for both traditional and custom currencies.

I hope that helps. Please do let me know if you have more questions. I'd submit a merge request, but I honestly do not know any Javascript or Typescript. Here are the links: https://github.com/cstby/FVTT-5e-custom-currency/blob/cstby/scripts/5e-custom-currency.js https://github.com/ktrieun/FVTT-5e-custom-currency

whelan commented 2 years ago

Thanks for the PR 88 I do not know if my comment helps with the implementation. It is also to minimize the duplicated code if we can, so it is easier to maintain.

whelan commented 2 years ago

It is merged into 2.4.1 So you can try it out and see if it works