Skip to content

Equipment Component

Dominik Morse edited this page Nov 27, 2023 · 2 revisions

Equipment Component Explanation

Overview

In our game, characters can wear or use various equipment like armor, weapons, and gadgets. The Equipment Component acts like the character's personal gear manager, handling the equipping and unequipping of these items.

How It Works

Equipping an Item

When your character decides to equip an item, such as a sword or a helmet, here's what happens:

  1. Check Authority: The game first verifies if it's allowed to perform the equip action, similar to asking, "Can I wear this?"

  2. Equip the Item:

    • If the selected slot is empty, the item is placed there.
    • If the slot is already occupied, the current item is unequipped, and the new item takes its place.
  3. Notify the Game: The game then records this change, effectively telling your character, "You have a new item equipped!"

Unequipping an Item

When your character decides to remove an item:

  1. Check Authority: Like equipping, the game checks if it can remove the item from the equipment slot.

  2. Remove the Item: The item is taken off and either placed back into the inventory or discarded.

  3. Notify the Game: The game updates its records to reflect that the item is no longer equipped.

Server and Client Communication

  • Server: Acts as the central system, ensuring the game's rules are followed.
  • Client: Your view of the game, where you interact with the game world.

When equipping or unequipping items, your game (client) requests these actions from the server. The server confirms these actions, ensuring consistency across all players' experiences.

Conclusion

The Equipment Component is vital for managing a character's gear, ensuring the actions of equipping and unequipping are smoothly executed and recognized across the game network.

Flow

Equipment Component Functions

graph TD
    A[Start] -->|Function Call| B[EquipItem_Implementation]
    B -->|Validate Request| C[Check Authority]
    C -->|No Authority| D[EquipItem_Server]
    C -->|Has Authority| E[Execute Equip Logic]
    E -->|Find Target Slot| F[Slot Found]
    F -->|Slot Empty| G[Equip in Empty Slot]
    F -->|Slot Occupied| H[UnEquip Current Item]
    G --> I[OnSlotEquipped Broadcast]
    H --> I
    I -->|Client-side Event| I2[PostItemEquipped_Client]
    D -.->|Network Communication| E

    A -->|Function Call| J[UnEquipItem_Implementation]
    J -->|Validate Request| K[Check Authority]
    K -->|No Authority| L[UnEquipItem_Server]
    K -->|Has Authority| M[Execute UnEquip Logic]
    M -->|Find Target Slot| N[Slot Found]
    N -->|Perform UnEquip| O[OnSlotUnEquipped Broadcast]
    O -->|Client-side Event| O2[PostItemUnEquipped_Client]
    L -.->|Network Communication| M
Loading

Helper Functions

graph TD
    A[Start] -->|Function Call| B[FindSlotForItem]
    B -->|Search Slot for Item| C[Return Slot ID or INVALID_SLOT]

    A2[Start] -->|Function Call| D[FindSlotByID]
    D -->|Search Slot by ID| E[Return Slot Index or INDEX_NONE]

    A3[Start] -->|Function Call| F[CanEquipItem]
    F -->|Check Equip Feasibility| G[Return True or False]

    A4[Start] -->|Function Call| H[CanUnEquipItem]
    H -->|Check UnEquip Feasibility| I[Return True or False]

    A5[Start] -->|Function Call| J[GetAllSlots]
    J -->|Retrieve All Slots| K[Return Slot Array]

    A6[Start] -->|Function Call| L[IsItemEquipped]
    L -->|Check If Item Is Equipped| M[Return True or False]
Loading

Clone this wiki locally