From ba7457dca9f4356c13c0d36147ba2c90b08321b2 Mon Sep 17 00:00:00 2001 From: Louis Hobbs Date: Wed, 18 Jan 2023 00:09:18 +0000 Subject: [PATCH] Add Ammo counts to Weapon --- Source/Nakatomi/Weapon.cpp | 42 ++++++++++++++++++++++++++++++++++++++ Source/Nakatomi/Weapon.h | 19 +++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/Source/Nakatomi/Weapon.cpp b/Source/Nakatomi/Weapon.cpp index 7b0f4d2..6fe24e7 100644 --- a/Source/Nakatomi/Weapon.cpp +++ b/Source/Nakatomi/Weapon.cpp @@ -13,6 +13,8 @@ AWeapon::AWeapon() void AWeapon::BeginPlay() { Super::BeginPlay(); + + SetAmmoCountToDefault(); } @@ -65,3 +67,43 @@ void AWeapon::SetFireSound(USoundBase* USoundBase) { FireSound = USoundBase; } + +int AWeapon::GetAmmoCount() +{ + return AmmoCount; +} + +void AWeapon::SetAmmoCount(int ammoCount) +{ + AmmoCount = ammoCount; + + if (AmmoCount > WeaponProperties.MaxAmmo) + { + AmmoCount = WeaponProperties.MaxAmmo; + } +} + +void AWeapon::SetAmmoCountToDefault() +{ + AmmoCount = WeaponProperties.DefaultAmmo; +} + +void AWeapon::IncrementAmmoCount(int ammoCount) +{ + AmmoCount += ammoCount; + + if (AmmoCount > WeaponProperties.MaxAmmo) + { + AmmoCount = WeaponProperties.MaxAmmo; + } +} + +void AWeapon::DecrementAmmoCount(int ammoCount) +{ + AmmoCount -= ammoCount; + + if (AmmoCount < 0) + { + AmmoCount = 0; + } +} diff --git a/Source/Nakatomi/Weapon.h b/Source/Nakatomi/Weapon.h index b711127..0bc923c 100644 --- a/Source/Nakatomi/Weapon.h +++ b/Source/Nakatomi/Weapon.h @@ -31,6 +31,12 @@ struct FWeaponProperties UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties") float WeaponChangeTime = 2.0f; + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties") + int MaxAmmo = 1; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties") + int DefaultAmmo = 1; + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties") int ProjectilesPerShot = 1; @@ -66,6 +72,9 @@ protected: UPROPERTY(EditDefaultsOnly) USoundBase* FireSound; + UPROPERTY(VisibleAnywhere) + int AmmoCount; + public: // Sets default values for this actor's properties AWeapon(); @@ -94,4 +103,14 @@ public: USoundBase* GetFireSound(); void SetFireSound(USoundBase* USoundBase); + + int GetAmmoCount(); + + void SetAmmoCount(int ammoCount); + + void SetAmmoCountToDefault(); + + void IncrementAmmoCount(int ammoCount); + + void DecrementAmmoCount(int ammoCount); };