-
Notifications
You must be signed in to change notification settings - Fork 81
Add player shops #234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add player shops #234
Conversation
|
This PR only is for player shops. I have not implemented hired merchants. |
|
Why are player shops being stored in the database? These only need to persist whilst a player is online. Only hired merchants need to persist. The player struct could be modified to have a I can't remember how quantites are managed in player shops but if the client supports selling more than 1 of an item then at the point of sale the |
I went with DB escrow because once an item is listed I’m actually removing it from the character’s inventory, and keeping that removed inventory purely in memory means a crash can lose items. I originally tried the simpler “visual remove / add back later” approach and ran into consistency problems: the client inventory UI and the server’s idea of slots/stacks would drift, and getting items to reliably reappear without desyncs or edge-case glitches was messy. Escrow keeps things authoritative and predictable by making the item live in exactly one place at a time (inventory or escrow) and gives a clean restore path on login. It also sets things up for hired merchants later since they need persistence and can reuse the same escrow/restore mechanism instead of introducing a separate system. |
This should only be the case if a save isn't performed at the point of sale. When an item is bought a save should occur for both parties, to guarantee no desync's. If the seller disconnects and relogs then they will just load in the inventory from db which will be pre-shop creation minus any sales. When a player makes a shop and places an item into the shop list what happens in the client UI? Does the item disappear from it's item slot like a trade window? Are you able to attach a screenshot? You should be able to treat this similar to a trade room with only 1 side having items. |
I get the just save on sale argument, but that doesn’t address what was actually going wrong for me. The hard part wasn’t persisting the buyer/seller at the moment of purchase, it was trying to model a shop as “the item is still in the owner’s inventory, but also listed somewhere else” and then relying on UI tricks or a trade-like one-sided flow to keep everything consistent. Once you do that you’re forced into either faking inventory state (and dealing with slot/stack desyncs when things merge/split, partial quantities, etc.) or implementing a real lock/reserve system so the listed item can’t be moved/dropped/traded/consumed while it’s listed. That lock approach sounds simple but it spreads everywhere: every inventory-changing path has to check and enforce it, and if you miss one you’ve created a dupe/desync. The DB escrow approach keeps it contained and deterministic: listing is a real server-side state change (item is no longer in inventory while listed), so you don’t need global locking rules, restore is straightforward, and it’s also the same primitive hired merchants will need anyways. So this isn’t persisting player shops, it’s persisting removed inventory safely and reusing the same path for merchant persistence later. |
This pull request implements the core functionality for player shops, allowing players to create, manage, and interact with personal shops in the game. It introduces a new
shopRoomtype, handles shop-related operations (such as adding, buying, and removing items), and updates the packet protocol to support shop features. Additionally, it generalizes the display logic for rooms and introduces a new interface for game box display.The most important changes are:
Player Shop System Implementation:
shopRoomtype with logic for creating shops, managing players, adding/removing items, handling purchases, and shop closure. This includes theshopItemstruct and methods such asaddPlayer,removePlayer,addItem,buyItem, andcloseShop.Room and Display Logic Generalization:
boxDisplayerinterface to generalize how rooms display themselves on the game map, and updated the room pool logic to use this interface instead of the previousgameRoomertype. [1] [2] [3] [4]displayBytesmethod forshopRoomto support the new interface and ensure proper shop display on the map.Protocol and Constants Updates:
packetRoomShowWindowand related packet functions to handle player shop-specific data and ensure compatibility with the new shop system. [1] [2]These changes collectively enable the creation and management of player shops, allowing for item trading between players in a controlled room environment.