-
-
Notifications
You must be signed in to change notification settings - Fork 8
Inventory Component
Imagine you're playing a video game where your character can pick up, use, and store various items like potions, weapons, and armor. The Inventory Component in our game works like a backpack, allowing the character to manage all these items.
When your character picks up an item (let's say, a potion), the following things happen:
-
Check Authority: First, the game checks if it has the "authority" to add the item. Think of this like asking, "Am I allowed to put this in my backpack?"
-
Add or Update:
- If the item is already in the backpack (like another potion of the same type), the game just updates the existing item's quantity.
- If it's a new item, the game creates a space for it in the backpack.
-
Notify the Game: After adding or updating the item, the game makes a note of this change. This is like telling your character, "Hey, your backpack has new items!"
When your character uses or drops an item:
-
Check Authority: Just like when adding an item, the game first checks if it's allowed to remove the item.
-
Remove the Item: The game then takes the item out of the backpack.
-
Notify the Game: The game updates its records, noting that the item is no longer in the backpack.
Sometimes, your character might use part of an item (like drinking half a potion):
-
Check Authority: The game checks if it can change the item's quantity.
-
Reduce Quantity:
- If there's some of the item left (like half a potion), the game updates the item's quantity in the backpack.
- If the item is completely used up (like finishing the potion), the game removes it from the backpack.
-
Notify the Game: The game updates its records, either changing the item's quantity or noting that it's been removed.
In online games, there are two key concepts:
- Server: This is like the game's main brain. It makes sure that everything in the game is running correctly.
- Client: This is your personal view of the game. It's what you see and interact with on your screen.
When you pick up, use, or drop an item, your game (the client) asks the server, "Can I do this?" The server then responds, either allowing or denying the action. This ensures that all players in the game have a fair and synchronized experience.
The Inventory Component is a crucial part of the game that manages all the items your character carries. It ensures that the items are added, updated, or removed correctly and that these changes are recognized both by your game and by others playing online.
graph TD
A[Start] -->|Function Call| B[AddItemToInventory_Implementation]
B -->|Validate Request| C[Check Authority]
C -->|No Authority| D[AddItemToInventory_Server]
C -->|Has Authority| E[Execute Add Item Logic]
E -->|Search for Existing Item| F[Existing Item Check]
F -->|Exists| G[Update Existing Item]
F -->|Doesn't Exist| H[Create New Item]
G --> I[OnItemUpdated Broadcast]
H --> J[OnItemAdded Broadcast]
I -->|Client-side Event| I2[PostItemUpdated_Client]
J -->|Client-side Event| J2[PostItemAdded_Client]
A -->|Function Call| K[RemoveItemFromInventory_Implementation]
K -->|Validate Request| L[Check Authority]
L -->|No Authority| M[RemoveItemFromInventory_Server]
L -->|Has Authority| N[Execute Remove Item Logic]
N --> O[OnItemRemoved Broadcast]
O -->|Client-side Event| O2[PostItemRemoved_Client]
A -->|Function Call| P[ReduceItemInInventory_Implementation]
P -->|Validate Request| Q[Check Authority]
Q -->|No Authority| R[ReduceItemInInventory_Server]
Q -->|Has Authority| S[Execute Reduce Item Logic]
S -->|Check Remaining Quantity| T[Quantity > 0 or <= 0]
T -->|> 0| U[OnItemUpdated Broadcast]
T -->|<= 0| V[Trigger Remove Item Logic]
U -->|Client-side Event| U2[PostItemUpdated_Client]
V -->|Triggers| K
D -.->|Network Communication| E
M -.->|Network Communication| N
R -.->|Network Communication| S
A -->|Function Call| W[RequestNetworkRefresh]
W -->|Check Authority| X[Authority Check]
X -->|No Authority| Y[RequestNetworkRefresh_Server]
X -->|Has Authority| Z[Refresh Inventory Key]
Y -.->|Network Communication| Z
graph TD
A[Start] -->|Function Call| B[CalculateAddAmount]
B -->|Determine Max Stack Size| C[DetermineMaxStackSize]
A2[Start] -->|Function Call| D[FindEmptySlot]
D -->|Search Empty Slot| E[Return Slot Index or INDEX_NONE]
A3[Start] -->|Function Call| F[MakeNewSlot]
F -->|Create New Slot| G[UpdateStacksInSlot]
G -->|Update Stacks| B
A4[Start] -->|Function Call| H[UpdateStacksInSlot]
H -->|Update Existing Stacks| I[ReduceQuantityInStacks]
I --> J[Remove Empty Stacks]
H -->|Create New Stacks if Needed| K[UpdateStack]
K -->|Update Stack Quantity| I
A5[Start] -->|Function Call| L[ReduceQuantityInStacks]
L --> M[Sort Stacks by Quantity]
L --> N[Reduce Quantity in Each Stack]
N -->|Remove Empty Stacks| J
A6[Start] -->|Function Call| O[UpdateStack]
O -->|Find Existing Stack| P[Update Existing Stack Quantity]
P -->|Adjust Remaining Quantity| Q[Create New Stack]
Q -->|Update Stack| I
A7[Start] -->|Function Call| R[IsItemValid]
R --> S[Check Item Validity]
R -->|Return Validity Status| T[End]
- Home
-
- Components
-
- Objects
-
- Settings
-
-
- Inventory & Equipment Settings
-
-
-
-
- Theme Config
-
-
-
-
-
-
- Content Theme Config
-
-
-
-
-
- Inventory & Equipment Settings (Editor)
-
- Event's System