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 version https://git-lfs.github.com/spec/v1
oid sha256:d593d68d5b9a9fc58b1b7ecc44936b84e361aaa1762ab04c5924e36bfd45bee9 oid sha256:7cfd791337f79a964dbfef919494665648f1ce39168d4f28cd122e2018c4b694
size 61494 size 61741

Binary file not shown.

View File

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

View File

@ -91,6 +91,7 @@ protected:
public: public:
int Money = 2000; int Money = 2000;
bool bIsReloading = false;
/** Look Input Action */ /** Look Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) 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); UE_LOG(LogTemp, Display, TEXT("crnnt ammo: %d"), MagazineSize);
} }
// Called every frame // Called every frame
void ABaseWeaponClass::Tick(float DeltaTime) void ABaseWeaponClass::Tick(float DeltaTime)
{ {
@ -63,7 +64,6 @@ void ABaseWeaponClass::Tick(float DeltaTime)
{ {
ApplyRecoil(DeltaTime); ApplyRecoil(DeltaTime);
} }
UE_LOG(LogTemp, Display, TEXT("currnt pitch: %f"), currentPitch);
if (currentPitch < 0 && bStopShooting) if (currentPitch < 0 && bStopShooting)
{ {
float increment = currentPitch * DeltaTime * 8; 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() void ABaseWeaponClass::WeaponReload()
{ {
if(MagazineSize > currentAmmoCount) if(MagazineSize >= currentAmmoCount)
{ {
UE_LOG(LogTemp, Display, TEXT("Weapon Reloading: mag size: %d"), MagazineSize); UE_LOG(LogTemp, Display, TEXT("Weapon Reloading: mag size: %d"), MagazineSize);
currentAmmoCount = MagazineSize; currentAmmoCount = MagazineSize;
endlessVendettaChar->bIsReloading = false;
} }
} }

View File

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