Add base weapon upgrading

This commit is contained in:
baz 2025-02-03 18:53:08 +00:00
parent c9d10f86a4
commit 0cad5ad897
5 changed files with 55 additions and 68 deletions

BIN
Content/Weapons/DA_ExampleWeapon.uasset (Stored with Git LFS)

Binary file not shown.

View File

@ -32,6 +32,22 @@ void AWeapon::FireWeaponAction_Implementation()
// Do stuff // Do stuff
} }
void AWeapon::UpgradeWeapon(int newLevel) bool AWeapon::UpgradeWeapon()
{ {
return UpgradeWeapon(CurrentLevel + 1);
}
bool AWeapon::UpgradeWeapon(int newLevel)
{
if (newLevel < Upgrades.Num())
{
WeaponCooldown *= Upgrades[newLevel].WeaponCooldownMultiplier;
Damage *= Upgrades[newLevel].WeaponDamageMultiplier;
GetWorldTimerManager().ClearTimer(WeaponTimerHandle);
GetWorldTimerManager().SetTimer(WeaponTimerHandle, this, &AWeapon::FireWeaponAction, WeaponCooldown, true);
return true;
}
return false;
} }

View File

@ -6,23 +6,33 @@
#include "GameFramework/Actor.h" #include "GameFramework/Actor.h"
#include "Weapon.generated.h" #include "Weapon.generated.h"
class UPaperSprite;
class UWeaponDataAsset; class UWeaponDataAsset;
USTRUCT(BlueprintType)
struct FWeaponLevelUpgrades
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ClampMin = 0.01f, ClampMax = 1.0f))
float WeaponCooldownMultiplier = 1.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ClampMin = 0.01f))
float WeaponDamageMultiplier = 1.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ClampMin = 0.01f))
float WeaponRangeMultiplier = 1.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FText WeaponUpgradeText;
};
UCLASS() UCLASS()
class VAMPIRES_API AWeapon : public AActor class VAMPIRES_API AWeapon : public AActor
{ {
GENERATED_BODY() GENERATED_BODY()
public: public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties")
float WeaponCooldown = 1.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties")
float Damage;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties")
TObjectPtr<UWeaponDataAsset> WeaponDataAsset;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties")
FText Name; FText Name;
@ -32,9 +42,26 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties")
TObjectPtr<UTexture2D> Icon; TObjectPtr<UTexture2D> Icon;
UPROPERTY(EditDefaultsOnly, Category = "Weapon Properties")
USoundBase* WeaponActivatedSoundBase = nullptr;
UPROPERTY(EditDefaultsOnly, Category = "Weapon Properties")
TObjectPtr<UPaperSprite> WeaponSprite = nullptr;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties")
float WeaponCooldown = 1.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties")
float Damage;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties")
TArray<FWeaponLevelUpgrades> Upgrades = TArray<FWeaponLevelUpgrades>();
private: private:
FTimerHandle WeaponTimerHandle; FTimerHandle WeaponTimerHandle;
int CurrentLevel = 0;
public: public:
// Sets default values for this actor's properties // Sets default values for this actor's properties
AWeapon(); AWeapon();
@ -49,5 +76,6 @@ public:
virtual void FireWeaponAction_Implementation(); virtual void FireWeaponAction_Implementation();
UFUNCTION() UFUNCTION()
virtual void UpgradeWeapon(int newLevel); virtual bool UpgradeWeapon();
virtual bool UpgradeWeapon(int newLevel);
}; };

View File

@ -1,4 +0,0 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "WeaponDataAsset.h"

View File

@ -1,50 +0,0 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Engine/DataAsset.h"
#include "WeaponDataAsset.generated.h"
class UPaperSprite;
class AProjectile;
USTRUCT(BlueprintType)
struct FWeaponLevelUpgrades
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float WeaponCooldownMultiplier;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float WeaponDamageMultiplier;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float WeaponRangeMultiplier;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FText WeaponUpgradeText;
};
/**
*
*/
UCLASS(BlueprintType)
class VAMPIRES_API UWeaponDataAsset : public UDataAsset
{
GENERATED_BODY()
public:
UPROPERTY(EditDefaultsOnly, Category = "Weapon Properties")
TSubclassOf<AProjectile> ProjectileTemplate = nullptr;
UPROPERTY(EditDefaultsOnly, Category = "Weapon Properties")
USoundBase* WeaponActivatedSoundBase = nullptr;
UPROPERTY(EditDefaultsOnly, Category = "Weapon Properties")
TObjectPtr<UPaperSprite> WeaponSprite = nullptr;
UPROPERTY(EditDefaultsOnly, Category = "Weapon Upgrades")
TArray<FWeaponLevelUpgrades> WeaponLevelUpgrades = TArray<FWeaponLevelUpgrades>();
};