Added Reload Wait Timer To All Weapons

This commit is contained in:
MARCEL HARA 2023-10-16 15:54:53 +01:00
parent 055356ec01
commit a3021a2722
6 changed files with 27 additions and 11 deletions

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d593d68d5b9a9fc58b1b7ecc44936b84e361aaa1762ab04c5924e36bfd45bee9
size 61494
oid sha256:7cfd791337f79a964dbfef919494665648f1ce39168d4f28cd122e2018c4b694
size 61741

Binary file not shown.

View File

@ -256,11 +256,11 @@ void AEndlessVendettaCharacter::EquipSecondary()
//Calls the fire function in the baseWeaponClass
void AEndlessVendettaCharacter::FireCaller()
{
if (IsValid(PrimaryWeapon))
if (IsValid(PrimaryWeapon) && !bIsReloading)
{
PrimaryWeapon->Fire();
}
if (IsValid(SecondaryWeapon))
if (IsValid(SecondaryWeapon) && !bIsReloading)
{
SecondaryWeapon->Fire();
}
@ -330,11 +330,13 @@ void AEndlessVendettaCharacter::GunReload()
{
if (IsValid(PrimaryWeapon))
{
PrimaryWeapon->WeaponReload();
PrimaryWeapon->ReloadTimer();
bIsReloading = true;
}
if (IsValid(SecondaryWeapon))
{
SecondaryWeapon->WeaponReload();
SecondaryWeapon->ReloadTimer();
bIsReloading = true;
}
}

View File

@ -91,6 +91,7 @@ protected:
public:
int Money = 2000;
bool bIsReloading = false;
/** Look Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))

View File

@ -54,6 +54,7 @@ void ABaseWeaponClass::BeginPlay()
UE_LOG(LogTemp, Display, TEXT("crnnt ammo: %d"), MagazineSize);
}
// Called every frame
void ABaseWeaponClass::Tick(float DeltaTime)
{
@ -63,7 +64,6 @@ void ABaseWeaponClass::Tick(float DeltaTime)
{
ApplyRecoil(DeltaTime);
}
UE_LOG(LogTemp, Display, TEXT("currnt pitch: %f"), currentPitch);
if (currentPitch < 0 && bStopShooting)
{
float increment = currentPitch * DeltaTime * 8;
@ -213,12 +213,19 @@ void ABaseWeaponClass::WeaponScopedFire()
}
}
void ABaseWeaponClass::ReloadTimer()
{
GetWorldTimerManager().SetTimer(reloadTimerHandle, this, &ABaseWeaponClass::WeaponReload, TimeToReload, false);
GLog->Log("ReloadTimer Activated");
}
void ABaseWeaponClass::WeaponReload()
{
if(MagazineSize > currentAmmoCount)
if(MagazineSize >= currentAmmoCount)
{
UE_LOG(LogTemp, Display, TEXT("Weapon Reloading: mag size: %d"), MagazineSize);
currentAmmoCount = MagazineSize;
endlessVendettaChar->bIsReloading = false;
}
}

View File

@ -41,10 +41,12 @@ protected:
float recoilResultPitch = 0;
float recoilResultYaw = 0;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
void ReloadTimer();
UPROPERTY(EditAnywhere)
FName WeaponName;
@ -57,6 +59,9 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int MagazineSize;
UPROPERTY(EditAnywhere)
float TimeToReload = 3.f;
//how many bullets until the recoil stops going up
UPROPERTY(EditAnywhere)
int howMnyShotsTillRclStop;
@ -95,6 +100,7 @@ public:
APlayerController* playerControllerRef;
FTimerHandle timerHandle;
FTimerHandle reloadTimerHandle;
bool bFirstBulletShot = false;