Equipment Slot Helpers
pavlicekdominik opened this issue · 0 comments
Function: DoesSlotExist
Purpose: To check if an equipment slot with the given name exists.
Inputs:
- SlotName:
FName
: The name of the slot to check for existence.
Returns: bool
: True if the slot exists, False otherwise.
Description: Checks the equipment system to see if a slot with the specified name is available.
Pseudocode:
Function DoesSlotExist(SlotName: FName) -> bool:
For each equipmentSlot in EquipmentSlots:
If equipmentSlot.SlotName == SlotName:
Return true
Return false
End Function
Function: GetEquipmentSlot
Purpose: To retrieve a single equipment slot based on the specified criteria.
Inputs:
- Criteria:
FEquipmentSlotSearchCriteria
: The criteria to search for.
Returns: FEquipmentItemSlot
: An equipment slot that matches the criteria.
Description: Searches the equipment system for the first slot matching the criteria.
Pseudocode:
Function GetEquipmentSlot(Criteria: FEquipmentSlotSearchCriteria) -> FEquipmentItemSlot:
If Criteria.IsValid():
For each equipmentSlot in EquipmentSlots:
If Criteria.SearchByName and equipmentSlot.SlotName == Criteria.SlotName:
Return equipmentSlot
If Criteria.SearchByItem and equipmentSlot.ItemSlot.ItemInstance == Criteria.ItemInstance:
Return equipmentSlot
If Criteria.SearchByGuid and equipmentSlot.SlotGuid == Criteria.SlotGuid:
Return equipmentSlot
If Criteria.SearchByTag and equipmentSlot.AcceptedTags.HasTag(Criteria.Tag):
Return equipmentSlot
If Criteria.ItemCategory and equipmentSlot.AcceptedCategories.Contains(Criteria.ItemCategory):
Return equipmentSlot
Else:
Return nullptr
End If
Return nullptr
Function: GetEquipmentSlots
Purpose: To retrieve equipment slots based on the specified criteria, or just all.
Inputs:
- Criteria:
FEquipmentSlotSearchCriteria
: The criteria to search for.
Returns: TArray<FEquipmentItemSlot>
: A list of equipment slots that match the criteria.
Description: Searches the equipment system for slots matching the criteria. If no criteria are provided, it returns all slots.
Pseudocode:
Function GetEquipmentSlots(Criteria: FEquipmentSlotSearchCriteria) -> TArray<FEquipmentItemSlot>:
ResultSlots = TArray<FEquipmentItemSlot>()
If Criteria.IsValid():
For each equipmentSlot in EquipmentSlots:
If Criteria.SearchByName and equipmentSlot.SlotName == Criteria.SlotName:
ResultSlots.Add(equipmentSlot)
Continue
If Criteria.SearchByItem and equipmentSlot.ItemSlot.ItemInstance == Criteria.ItemInstance:
ResultSlots.Add(equipmentSlot)
Continue
If Criteria.SearchByGuid and equipmentSlot.SlotGuid == Criteria.SlotGuid:
ResultSlots.Add(equipmentSlot)
Continue
If Criteria.SearchByTag and equipmentSlot.AcceptedTags.HasTag(Criteria.Tag):
ResultSlots.Add(equipmentSlot)
Continue
If Criteria.ItemCategory and equipmentSlot.AcceptedCategories.Contains(Criteria.ItemCategory):
ResultSlots.Add(equipmentSlot)
Continue
Else:
Return EquipmentSlots
End If
Return ResultSlots
End Function
Function: IsSlotValid
Purpose: To validate the integrity of an FEquipmentItemSlot
.
Inputs:
FEquipmentItemSlot
Slot: The equipment slot intended for validation.
Returns: bool
: True if the slot is valid, False otherwise.
Description: Ensures that the provided slot has:
- A valid slot name.
- A unique slot GUID.
- A valid item slot if an item is equipped.
- Consistent accepted tags and categories.
Pseudocode:
Function IsSlotValid(Slot: FEquipmentItemSlot) -> bool:
// Check for a valid slot name.
If Slot.SlotName is empty:
Return false
// Check for a valid slot GUID.
If Slot.SlotGuid is invalid:
Return false
Return true
End Function
Function: CanItemBeEquipped
Purpose: To check if an item can be equipped in a given equipment slot.
Inputs:
UInstancedItem*
Item: The item intended to be equipped.FEquipmentItemSlot
Slot: The equipment slot to which the item is intended to be equipped.
Returns: bool
: True if the item can be equipped in the slot, False otherwise.
Description: This function verifies if the item's tags and category match the accepted tags and categories of the equipment slot.
Pseudocode:
Function CanItemBeEquipped(Item: UInstancedItem*, Slot: FEquipmentItemSlot) -> bool:
// Check for item tags compatibility.
If not Slot.Tags.HasAny(Item.ItemTags):
Return false
// Check for item category compatibility.
If not Slot.AcceptedCategories.Contains(Item.ItemCategory):
Return false
Return true
End Function
Function: IsSlotOccupied
Purpose: To determine if an equipment slot is currently occupied by an item.
Inputs:
FEquipmentItemSlot
Slot: The equipment slot to check.
Returns: bool
: True if the slot is occupied, False otherwise.
Description: A straightforward function to verify if an item occupies the slot.
Pseudocode:
Function IsSlotOccupied(Slot: FEquipmentItemSlot) -> bool:
If Slot.ItemSlot.ItemInstance is not nullptr:
Return true
Else:
Return false
End Function