Mountea-Framework/MounteaInventoryEquipment

EquipItem

pavlicekdominik opened this issue · 0 comments

Function: EquipItem

Purpose: To equip an item into a designated equipment slot. If the slot is already occupied, it follows a set policy (e.g., replacing the item).

Inputs:

  • ItemToEquip: UInstancedItem*: The instance of the item that needs to be equipped.
  • TargetSlotName: FName: The name of the equipment slot where the item should be placed.

Returns:

  • bool: True if the item is successfully equipped, False otherwise.

Description:

Equips an item into a designated slot. If the slot is occupied, the function's behavior depends on the game's equip-replace policy. If the policy is set to "Disallow," the function will return false. If it's set to "Replace," the current item in the slot will be unequipped, and the new item will be equipped.

Pseudocode:

Function EquipItem(ItemToEquip: UInstancedItem*, TargetSlotName: FName) -> bool:

    // Validate the input item
    If ItemToEquip is nullptr:
        Return false

    // Check if the target slot exists in the equipment system
    If not DoesSlotExist(TargetSlotName):
        Return false

    // Retrieve the target equipment slot based on its name
    TargetSlot = GetEquipmentSlot(SearchCriteria with SlotName = TargetSlotName)

    // Ensure that the item is compatible with the intended slot
    If not IsItemCompatibleWithSlot(ItemToEquip, TargetSlot):
        Return false

    // Check if the equipment slot already contains an item
    If TargetSlot.ItemSlot.ItemInstance is not nullptr:

        // Determine the game's policy on equipping items into occupied slots
        replacePolicy = GetGameEquipReplacePolicy()

        // If the policy disallows equipping over occupied slots, return false
        If replacePolicy == "Disallow":
            Return false
        // If the policy allows replacing the item, unequip the current item from the slot
        Else If replacePolicy == "Replace":
            UnequipItem(TargetSlotName)

    // Equip the new item into the slot
    TargetSlot.ItemSlot.ItemInstance = ItemToEquip

    // Mark the item as 'Equipped'
    ItemToEquip.AddItemFlag("Equipped")

    // Return true to indicate the successful equipping of the item
    Broadcast Event: "ItemEquipped" with parameters (ItemToEquip, TargetSlotName)
    Return true

End Function