I've made an item and inventory system that works as expected in a multiplayer setting.
The issue I'm facing is implementing using / doing actions / modifying items; more specifically, serializing specific parameters.
The system is pretty standard;
- ItemData defines the static parts of an item (sprite, name, Id, stats, etc)
- ItemInstance is a struct that is serialized over the network and describes a single item / stack
- Stats are just byte values with a unique identifier for dynamic information like ammo, condition, etc
The goal is 'translating' the data into an actual physical object so that I can implement actions like:
- Firing a weapon
- Consuming an item
- Food spoiling
I initially thought about creating an abstract class that describes an action, and adding a list of actions to the ItemData that receive the ItemInstance and player object
But I quickly ran into two issues:
-
Since the actions are pure data, where do I call my Rpc to execute the action on the server?
-
Since the actions are executed on the server, it would need to receive dynamic data from the player :
For example, if I fired a gun, the server wants to spawn the bullet where the player was when clicked the fire button (as opposed to where the player was when the Rpc was received)
This means that the arguments I want to send to the Rpcs are dynamic (consuming food doesn't require the player's position when the action was executed, but firing a gun does)