Full Item Sync (#13): purchases, Lost & Found, job payment and a shared inventory - #164
Open
OxoGhost01 wants to merge 6 commits into
Open
Full Item Sync (#13): purchases, Lost & Found, job payment and a shared inventory#164OxoGhost01 wants to merge 6 commits into
OxoGhost01 wants to merge 6 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Full Item Sync (#13): purchases, Lost & Found, job payment and a shared inventory
Closes #102, #103, #104.
Summary
This implements the remaining sub-issues of #13 on top of the existing
NetworkedItem/NetworkedItemManagergroundwork.The starting point turned out to be that item synchronisation was never actually running: snapshots were produced and sent, but the calls that hand received snapshots to the item manager were commented out on both the client and the server, so every item update was discarded on arrival. Enabling that is the first commit, and it surfaced a number of latent issues that the rest of the work builds on.
What is included
Shop purchases (#103)
Shop registers previously bypassed the register synchronisation entirely, so a client buying something spawned a local-only item and paid from a local wallet. Purchases now run through the same server-routed flow the service registers already used:
Lost & Found (#104)
Summoning items (the shed button, fast travel) previously collected everything in the world, including other players' belongings. Items now record who last carried them, and a summon only collects the summoning player's own items.
Job payment
Completing a job prints physical banknotes at the validator. Because a client's job validation is executed on the host, those notes only ever existed on the host's machine. They are now spawned as ordinary networked world items so that they replicate, and because the wallet is shared and server-authoritative, banking money is routed through the server rather than credited locally, where it would simply be overwritten by the host's value.
One case is still open: a client who validates a job does not reliably see the notes unless the host is nearby. See Known limitations.
Shared inventory (#102)
See the design note below. Players carry the same set of items; the server owns the list and each player holds their own physical copy.
Design decision: one shared inventory
Multiplayer is co-operative today, so all players carry the same items. If anyone picks something up, everyone gets it; if anyone drops or uses it up, it leaves everyone's inventory.
What is deliberately not shared is presentation. Each player has their own physical copy of each item, so slot placement and which item is in hand are per-player and independent. Two players can hold their own copy of the same item at the same time.
This was chosen because a single shared pool matches how co-op is actually played: it avoids one player having to hand tools over for the other to work, and it avoids the awkward question of who "owns" a jointly earned item.
Per-player inventories are still the right model for a future competitive or role-separated mode, so that path has been kept rather than deleted: the per-player inventory serialisation is still written to the save, and the code that hands a player their own inventory is retained (commented, in
NetworkedSaveGameManager.Server_GetPlayerInventory) so it can be switched back on when such a mode exists.Notes for review
IdPool.ReleaseIdpreviously accepted the unassigned id back and handed it out again, producing objects that could never be referenced over the network. This affected everyIdMonoBehaviourtype, not only items.Known limitations
Testing
Tested in two-player sessions (host + client) across repeated runs: