diff --git a/Source/Nakatomi/NakatomiCharacter.cpp b/Source/Nakatomi/NakatomiCharacter.cpp index dace3d2..6a43ab0 100644 --- a/Source/Nakatomi/NakatomiCharacter.cpp +++ b/Source/Nakatomi/NakatomiCharacter.cpp @@ -124,17 +124,22 @@ void ANakatomiCharacter::RemoveWeaponFromInventory(int i) WeaponInventory[i]->Destroy(); WeaponInventory.RemoveAt(i); - if (WeaponInventory.Num() == 0) + + if (WeaponInventory.Num() == 1) + { + SelectInventorySlot(0); + } + else if (WeaponInventory.Num() == 0) { CurrentInventorySlot = -1; } - else if (int index = WeaponInventory.Find(CurrentWeapon) == INDEX_NONE) + else if (CurrentInventorySlot == 0) { - SetCurrentWeapon(WeaponInventory[CurrentInventorySlot % WeaponInventory.Num()]); + SelectInventorySlot(0); } else { - CurrentInventorySlot = index; + SelectInventorySlot(i-1); } } @@ -142,13 +147,13 @@ void ANakatomiCharacter::RemoveWeaponFromInventory(AWeapon* weapon) { if (int index = WeaponInventory.Find(weapon) != INDEX_NONE) { - RemoveWeaponFromInventory(index - 1); + RemoveWeaponFromInventory(index); } } void ANakatomiCharacter::RemoveCurrentWeaponFromInventory() { - RemoveWeaponFromInventory(CurrentWeapon); + RemoveWeaponFromInventory(CurrentInventorySlot); } void ANakatomiCharacter::AddWeaponToInventory(TSubclassOf weapon) diff --git a/Source/Nakatomi/PlayerCharacter.cpp b/Source/Nakatomi/PlayerCharacter.cpp index c71a169..c737931 100644 --- a/Source/Nakatomi/PlayerCharacter.cpp +++ b/Source/Nakatomi/PlayerCharacter.cpp @@ -250,7 +250,8 @@ void APlayerCharacter::EndJumpCallback(const FInputActionInstance& Instance) void APlayerCharacter::BeginFireCallback(const FInputActionInstance& Instance) { - if (CurrentWeapon == nullptr || CurrentWeapon->GetCurrentWeaponStatus()->GetValue() != Idle || (IsSprinting && GetVelocity().Length() > 500.0f)) + if (CurrentWeapon == nullptr || CurrentWeapon->GetCurrentWeaponStatus()->GetValue() != Idle || + (IsSprinting && GetVelocity().Length() > 500.0f)) { return; } @@ -768,10 +769,13 @@ void APlayerCharacter::ThrowWeapon() TSubclassOf WeaponThrowableTemplate = CurrentWeapon->GetWeaponThrowableTemplate(); - AWeaponThrowable* Throwable = GetWorld()->SpawnActor( - WeaponThrowableTemplate, SpawnLocation, FRotator::ZeroRotator); + if (WeaponThrowableTemplate) + { + AWeaponThrowable* Throwable = GetWorld()->SpawnActor( + WeaponThrowableTemplate, SpawnLocation, FRotator::ZeroRotator); - Throwable->SetWeaponSkeletalMesh(GetCurrentWeapon()->GetSkeletalMesh()); + Throwable->SetWeaponSkeletalMesh(GetCurrentWeapon()->GetSkeletalMesh()); + } } void APlayerCharacter::ThrowExplosiveCallback() @@ -793,8 +797,8 @@ void APlayerCharacter::ThrowExplosive() SpawnLocation += Location; SpawnLocation += (25.0f * GetActorForwardVector()); SpawnLocation.Z += BoxExtent.Z; - - GetWorld()->SpawnActor(ThrowableInventory.Pop(), SpawnLocation, FRotator::ZeroRotator); + + GetWorld()->SpawnActor(ThrowableInventory[GetCurrentInventorySlot()], SpawnLocation, FRotator::ZeroRotator); } AThrowable* APlayerCharacter::ThrowThrowable()