Added reload functionality for all current and future weapons

This commit is contained in:
MH261677 2023-10-08 15:06:31 +01:00
parent 3c75d16e4b
commit 0e401a6f62
7 changed files with 51 additions and 9 deletions

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ff90caf01f6ea20dccd612ea5629215ce5c5a4a63e4da2ec242cabf9000bd6c6
size 42353
oid sha256:a408fa1c344f5612f1ed59bfeefbd99f2fc986c49f66bf42e849db73e65fdc2e
size 42307

Binary file not shown.

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6a0af94b654f58c85c8b4453fa211608ecc7bc67b9c82e2e3768814e906babcd
size 16334
oid sha256:ff3f732c27d0c0064f659482af85f116bc5eb967b29d3ca42bdc2324c3662cd8
size 16910

View File

@ -91,6 +91,9 @@ void AEndlessVendettaCharacter::SetupPlayerInputComponent(class UInputComponent*
EnhancedInputComponent->BindAction(TapShootAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::FireCaller);
EnhancedInputComponent->BindAction(GunAimInAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::GunRightClick);
EnhancedInputComponent->BindAction(GunAimInAction, ETriggerEvent::Completed, this, &AEndlessVendettaCharacter::StopGunRightClick);
//Weapon Reloading
EnhancedInputComponent->BindAction(GunReloadAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::GunReload);
}
}
@ -256,6 +259,18 @@ void AEndlessVendettaCharacter::StopGunRightClick()
}
}
void AEndlessVendettaCharacter::GunReload()
{
if (IsValid(PrimaryWeapon))
{
PrimaryWeapon->WeaponReload();
}
if (IsValid(SecondaryWeapon))
{
SecondaryWeapon->WeaponReload();
}
}
void AEndlessVendettaCharacter::Move(const FInputActionValue& Value)
{

View File

@ -61,6 +61,9 @@ class AEndlessVendettaCharacter : public ACharacter
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true"))
class UInputAction* GunAimInAction;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true"))
class UInputAction* GunReloadAction;
public:
AEndlessVendettaCharacter();
@ -109,6 +112,9 @@ public:
UFUNCTION(BlueprintCallable, Category = "Weapons")
void StopGunRightClick();
UFUNCTION(BlueprintCallable, Category = "Weapons")
void GunReload();
UArrowComponent* ScopedLocationArrow;
UPROPERTY(EditAnywhere, Category = "Dont Touch")

View File

@ -44,6 +44,10 @@ void ABaseWeaponClass::BeginPlay()
originalMaxAngleLeft = recoilMaxAngleLeft;
originalMaxAngleRight = recoilMaxAngleRight;
originalMinMultiplier = recoilMinMultiplier;
currentAmmoCount = MagazineSize;
UE_LOG(LogTemp, Display, TEXT("crnnt ammo: %d"), MagazineSize);
}
// Called every frame
@ -134,7 +138,7 @@ void ABaseWeaponClass::CancelFire()
void ABaseWeaponClass::Fire()
{
if(MagazineSize > 0)
if(currentAmmoCount > 0)
{
//do damage fallof based off distance
FHitResult outHit;
@ -153,8 +157,8 @@ void ABaseWeaponClass::Fire()
//Debug line to see where the trace hit
DrawDebugLine(this->GetWorld(), traceStart, traceEnd, FColor::Red, false, 5.0f, 0U, 2.5f);
playerControllerRef->PlayerCameraManager->StartCameraShake(CameraShakeClass, 1);
MagazineSize -= 1;
UE_LOG(LogTemp, Display, TEXT("Ammo Count: %d"), MagazineSize);
currentAmmoCount -= 1;
UE_LOG(LogTemp, Display, TEXT("Ammo Count: %d"), currentAmmoCount);
GenerateRecoilVector();
ClickDetectionTimer();
if (outHit.bBlockingHit)
@ -162,9 +166,9 @@ void ABaseWeaponClass::Fire()
UE_LOG(LogTemp, Display, TEXT("hit item: %s"), *outHit.GetActor()->GetName());
}
}
else if(MagazineSize <= 0)
else if(currentAmmoCount <= 0)
{
UE_LOG(LogTemp, Display, TEXT("No ammo, Ammo count: %d"), MagazineSize);
UE_LOG(LogTemp, Display, TEXT("No ammo, Ammo count: %d"), currentAmmoCount);
}
}
@ -188,4 +192,13 @@ void ABaseWeaponClass::WeaponScopedFire()
}
}
void ABaseWeaponClass::WeaponReload()
{
if(MagazineSize > currentAmmoCount)
{
UE_LOG(LogTemp, Display, TEXT("Weapon Reloading: mag size: %d"), MagazineSize);
currentAmmoCount = MagazineSize;
}
}

View File

@ -110,6 +110,9 @@ public:
UFUNCTION(BlueprintCallable, Category = "Weapons")
void WeaponScopedFire();
UFUNCTION(BlueprintCallable, Category = "Weapons")
void WeaponReload();
private:
UArrowComponent* GunStartArrow;
@ -121,5 +124,7 @@ private:
float originalMaxAngleLeft;
float originalMaxAngleRight;
float originalMinMultiplier;
int currentAmmoCount;
};