diff --git a/Source/Nakatomi/PlayerCharacter.cpp b/Source/Nakatomi/PlayerCharacter.cpp index 73dea4a..d805c70 100644 --- a/Source/Nakatomi/PlayerCharacter.cpp +++ b/Source/Nakatomi/PlayerCharacter.cpp @@ -376,14 +376,34 @@ void APlayerCharacter::AddWeaponToInventory(TSubclassOf weapon) void APlayerCharacter::RemoveWeaponFromInventory(int i) { - // TODO: Add more checking here WeaponInventory[i]->Destroy(); 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() { - // TODO: Add more checking here + RemoveWeaponFromInventory(CurrentWeapon); } void APlayerCharacter::OnFire() diff --git a/Source/Nakatomi/PlayerCharacter.h b/Source/Nakatomi/PlayerCharacter.h index 1ccd018..16fec01 100644 --- a/Source/Nakatomi/PlayerCharacter.h +++ b/Source/Nakatomi/PlayerCharacter.h @@ -137,6 +137,8 @@ public: void RemoveWeaponFromInventory(int i); + void RemoveWeaponFromInventory(AWeapon* weapon); + void RemoveCurrentWeaponFromInventory(); void OnFire();