Fix weapon switching

This commit is contained in:
baz 2024-05-02 22:39:34 +01:00
parent e50d8701fd
commit 126a9e116a
2 changed files with 21 additions and 12 deletions

View File

@ -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<class AWeapon> weapon)

View File

@ -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<AWeaponThrowable> WeaponThrowableTemplate = CurrentWeapon->GetWeaponThrowableTemplate();
AWeaponThrowable* Throwable = GetWorld()->SpawnActor<AWeaponThrowable>(
WeaponThrowableTemplate, SpawnLocation, FRotator::ZeroRotator);
if (WeaponThrowableTemplate)
{
AWeaponThrowable* Throwable = GetWorld()->SpawnActor<AWeaponThrowable>(
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<AThrowable>(ThrowableInventory.Pop(), SpawnLocation, FRotator::ZeroRotator);
GetWorld()->SpawnActor<AThrowable>(ThrowableInventory[GetCurrentInventorySlot()], SpawnLocation, FRotator::ZeroRotator);
}
AThrowable* APlayerCharacter::ThrowThrowable()