Skip to content

Looting Component

Dominik Morse edited this page Nov 19, 2023 · 5 revisions

Pickup and Loot

Overview

Imagine you're in a video game world where you can explore, defeat enemies, and discover treasures. In this world, you often come across items that you can pick up and add to your inventory – this could be anything from a sword left behind by a vanquished foe to a mysterious amulet found in a treasure chest or just an enemy corpse. The Pickup and Loot system is what makes this possible, acting like a magical pouch that helps manage all these discoveries.

How It Works

Finding and Looting Items

When you, as a character in the game, come across something that can be looted:

  • Identify Loot Source: The game first identifies where the loot is coming from. This could be a chest, a fallen enemy, or even a hidden stash.
  • Loot the Items:
    • You can choose to take specific items, inspecting each to see if it's useful or valuable.
    • Alternatively, you can grab everything available, quickly looting all the items.

Managing Loot

  • Source and Target Inventories: The game uses two concepts here – the Source (where the loot is coming from) and the Target (usually your inventory).
    • Setting the Source and Target: The game defines where you are looting from and where the looted items will go.
  • Looting Process:
    • Check Authority: Just like a guardian asking, "Are you allowed to take this?", the game checks if you're allowed to loot the items.
    • Transfer Items: The game then moves the items from the source to your inventory.
    • Update Inventories: Both the source of the loot and your inventory are updated to reflect the new changes.

Server and Client Roles in Online Play

In an online game, keeping everyone's game experience synchronized is crucial.

  • Server: This is the central system that ensures fairness and consistency in the game. It's like a referee in a sports match.
  • Client: This is your personal game experience, what you see and interact with.
  • Communication: When you loot items, your game (the client) communicates with the server to make sure the action is valid and fair. This ensures that what you're doing aligns with the experiences of other players in the same game world.

Conclusion

The Pickup and Loot system is an essential part of the game's interactive experience. It lets players explore and gather items from the game world, enriching their adventure and providing a sense of achievement and progress. Whether you're a brave warrior collecting spoils from a battle or a curious explorer uncovering ancient relics, this system makes each discovery exciting and rewarding.

Flow

graph TD

    Start[Start] -->|Player interacts with loot source| SetSourceInventory[Set Source Inventory]

    SetSourceInventory --> CheckAuthority[Check Authority]
    CheckAuthority -->|Authority? Yes| SetSourceInventory_Server[SetSourceInventory]
    CheckAuthority -->|Authority? No| SetSourceInventory[SetSourceInventory Server]

    CanLootItem -->|Can loot? Yes| LootLogic[Loot Item Logic]
    CanLootItem -->|Can loot? No| Forbidden2[Forbidden Action]

    LootLogic --> UpdateInventories[Update Inventories]
    UpdateInventories -->|Single Item| LootItem[Loot Item]
    UpdateInventories -->|Multiple Items| LootAllItems[Loot All Items]

    LootItem --> NotifyServer[Notify Server of Loot]
    LootAllItems --> NotifyServer
    NotifyServer --> ServerRequest 

    ServerRequest --> ServerValidation[Server-side Validation]
    ServerValidation -->|Valid| ServerLootLogic[Server Loot Item Logic]
    ServerValidation -->|Invalid| Forbidden

    ServerLootLogic --> ServerUpdateInventories[Server Update Inventories]
    ServerUpdateInventories --> ServerNotify[Server Notify Client]
Loading