void ASCharacter::OnEquipSecondaryWeapon() { if (Inventory.Num() >= 2) { /* Find first weapon that uses secondary slot. */ for (int32 i = 0; i < Inventory.Num(); i++) { ASWeapon* Weapon = Inventory[i]; if (Weapon->GetStorageSlot() == EInventorySlot::Secondary) { EquipWeapon(Weapon); } } } }
bool ASCharacter::WeaponSlotAvailable(EInventorySlot CheckSlot) { /* Iterate all weapons to see if requested slot is occupied */ for (int32 i = 0; i < Inventory.Num(); i++) { ASWeapon* Weapon = Inventory[i]; if (Weapon) { if (Weapon->GetStorageSlot() == CheckSlot) return false; } } return true; /* Special find function as alternative to looping the array and performing if statements the [=] prefix means "capture by value", other options include [] "capture nothing" and [&] "capture by reference" */ //return nullptr == Inventory.FindByPredicate([=](ASWeapon* W){ return W->GetStorageSlot() == CheckSlot; }); }
void ASCharacter::OnEquipSecondaryWeapon() { if (CarriedObjectComp->GetIsCarryingActor()) { CarriedObjectComp->Rotate(-1.0f, 0.0f); return; } if (Inventory.Num() >= 2) { /* Find first weapon that uses secondary slot. */ for (int32 i = 0; i < Inventory.Num(); i++) { ASWeapon* Weapon = Inventory[i]; if (Weapon->GetStorageSlot() == EInventorySlot::Secondary) { EquipWeapon(Weapon); } } } }