Making Merchant (Trading) System in Godot

trading mechanics in godot

Earlier in this article, I explained how to build an inventory system. Inventory consisted of a bunch of slots carrying an item each. And it was visualized to player so player can interact with it using GUI inputs.

Merchant system extends the inventory. The purpose is to allow 2 items to be exchanged (or traded). For example, 500 wood can be brought is we pay 100 gold. It means there is 5:1 ratio of exchange. If player inserts 1 gold, he must get 5 wood in return.

Such a trading system can easily be made by arranging inventory slots in 2 columns, with the first column showing items and the other column showing the amount of gold required for that item. When player puts gold in the gold-slot, it can pick the item generated on the other slot. This system can be generalized to an “exchange” system so any 2 things can be exchanged this way.

Table of Contents

Breakdown

  1. Make a scene; call it “Merchant System”. And add an inventory to it (do not use inheritance, use composition here).
  2. Write a MerchantSystem.gd script, and enforce underlying inventory to be arranged in 2 columns (so a pair forms for every item exchange). And other necessary things such as enforcing inventory to have item_hints for every slot.
  3. In the same script, attach the inventory signals so inventory input events are also captured by the merchant system.
    • Merchant system creates new items in slots if the other slot in pair gets an item in it.
    • It recalculates (or removes) the amount in other slot in the pair if the slot item is picked.

Code

Stub. This section will be completed later.

Thank you for reading <3

Leave a Reply

Your email address will not be published. Required fields are marked *