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); };