Add logic for removing weapons from inventory

This commit is contained in:
Louis Hobbs 2023-01-18 22:41:10 +00:00
parent 7c44598084
commit a3456fce0f
2 changed files with 24 additions and 2 deletions

View File

@ -376,14 +376,34 @@ void APlayerCharacter::AddWeaponToInventory(TSubclassOf<class AWeapon> weapon)
void APlayerCharacter::RemoveWeaponFromInventory(int i) void APlayerCharacter::RemoveWeaponFromInventory(int i)
{ {
// TODO: Add more checking here
WeaponInventory[i]->Destroy(); WeaponInventory[i]->Destroy();
WeaponInventory.RemoveAt(i); WeaponInventory.RemoveAt(i);
if (WeaponInventory.Num() == 0)
{
CurrentInventorySlot = -1;
}
else if (int index = WeaponInventory.Find(CurrentWeapon) == INDEX_NONE)
{
SetCurrentWeapon(WeaponInventory[CurrentInventorySlot % WeaponInventory.Num()]);
}
else
{
CurrentInventorySlot = index;
}
}
void APlayerCharacter::RemoveWeaponFromInventory(AWeapon* weapon)
{
if (int index = WeaponInventory.Find(weapon) != INDEX_NONE)
{
RemoveWeaponFromInventory(index);
}
} }
void APlayerCharacter::RemoveCurrentWeaponFromInventory() void APlayerCharacter::RemoveCurrentWeaponFromInventory()
{ {
// TODO: Add more checking here RemoveWeaponFromInventory(CurrentWeapon);
} }
void APlayerCharacter::OnFire() void APlayerCharacter::OnFire()

View File

@ -137,6 +137,8 @@ public:
void RemoveWeaponFromInventory(int i); void RemoveWeaponFromInventory(int i);
void RemoveWeaponFromInventory(AWeapon* weapon);
void RemoveCurrentWeaponFromInventory(); void RemoveCurrentWeaponFromInventory();
void OnFire(); void OnFire();