Add Ammo counts to Weapon

This commit is contained in:
Louis Hobbs 2023-01-18 00:09:18 +00:00
parent 495e08ec74
commit ba7457dca9
2 changed files with 61 additions and 0 deletions

View File

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

View File

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