Implement Shop Logic

Shops are used to allow players to buy and sell items. A new feature is the concept of stock, where a shop can contain a specific number of items, and can refresh the amount of these items based on a set timer.

The use case for a shop goes like this:

  1. A client is within a region (convex hull) that is marked to be a Shop, and has a Shop Id attached to it.

  2. The client sends a request to the game server to see the inventory of a shop given the Shop Id. The game server performs a check to make sure the player is within the shop's region, replies with a list of items. The descriptions for each item are already known to the user, so this is a list of Item Ids and the Quantity.

  3. The client sends a request to the game server to buy an item given an item Id and the quantity. The game server performs a check to make sure that the player is within the shop's region, that the shop has enough of the item stocked, and that the player has enough money on their character. The shop's quantity is updated, the player's money and inventory are updated on the server, and the response is sent back to the client.

These steps model two sets of Request/Response flows - namely the Get Shop Inventory and Purchase Item flows. A third Sell Item flow is not present here, but follows the same approach.

As mentioned, shops now have identifiers, as there can be more than one shop in a map. Furthermore, the extents of each shopping zone is marked by a convex boundary that lies on the map floor; when a player steps into this region, they can buy and sell equipment.

The UI is to reflect when a player is inside of a shopping zone - probably bring up an explicit button that shows something like "Shop Available (F12)" in a prominent location.