Make UpgradeWeapon overrideable for child classes
This commit is contained in:
parent
55ec2cbfda
commit
9f7d2bf4c7
@ -20,23 +20,24 @@ void AWeapon::BeginPlay()
|
||||
GetWorldTimerManager().SetTimer(WeaponTimerHandle, this, &AWeapon::FireWeaponAction, WeaponCooldown, true);
|
||||
}
|
||||
|
||||
void AWeapon::ResetWeaponTimer()
|
||||
{
|
||||
GetWorldTimerManager().ClearTimer(WeaponTimerHandle);
|
||||
GetWorldTimerManager().SetTimer(WeaponTimerHandle, this, &AWeapon::FireWeaponAction, WeaponCooldown, true);
|
||||
}
|
||||
|
||||
void AWeapon::FireWeaponAction_Implementation()
|
||||
{
|
||||
// This should be overridden in child weapon classes
|
||||
}
|
||||
|
||||
bool AWeapon::UpgradeWeapon()
|
||||
bool AWeapon::UpgradeWeapon_Implementation()
|
||||
{
|
||||
if (CurrentLevel + 1 <= Upgrades.Num())
|
||||
if (CurrentLevel < MaxLevel)
|
||||
{
|
||||
CurrentLevel++;
|
||||
WeaponCooldown *= Upgrades[CurrentLevel - 1].WeaponCooldownMultiplier;
|
||||
Damage *= Upgrades[CurrentLevel - 1].WeaponDamageMultiplier;
|
||||
|
||||
GetWorldTimerManager().ClearTimer(WeaponTimerHandle);
|
||||
GetWorldTimerManager().SetTimer(WeaponTimerHandle, this, &AWeapon::FireWeaponAction, WeaponCooldown, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -9,24 +9,6 @@
|
||||
class UPaperSprite;
|
||||
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()
|
||||
class VAMPIRES_API AWeapon : public AActor
|
||||
{
|
||||
@ -55,10 +37,13 @@ public:
|
||||
float Damage;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties")
|
||||
TArray<FWeaponLevelUpgrades> Upgrades = TArray<FWeaponLevelUpgrades>();
|
||||
TArray<FText> UpgradeDescriptions;
|
||||
|
||||
int CurrentLevel = 0;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)
|
||||
int MaxLevel = 0;
|
||||
|
||||
private:
|
||||
FTimerHandle WeaponTimerHandle;
|
||||
|
||||
@ -71,11 +56,14 @@ protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
void ResetWeaponTimer();
|
||||
|
||||
public:
|
||||
UFUNCTION(BlueprintNativeEvent)
|
||||
void FireWeaponAction();
|
||||
virtual void FireWeaponAction_Implementation();
|
||||
|
||||
UFUNCTION()
|
||||
virtual bool UpgradeWeapon();
|
||||
UFUNCTION(BlueprintNativeEvent)
|
||||
bool UpgradeWeapon();
|
||||
virtual bool UpgradeWeapon_Implementation();
|
||||
};
|
||||
|
@ -43,7 +43,7 @@ void ULevelUpWidget::NativeConstruct()
|
||||
TArray<UUpgradeButtonDataObject*> upgradeItems;
|
||||
for (AWeapon* weapon : Inventory)
|
||||
{
|
||||
if (weapon->CurrentLevel < weapon->Upgrades.Num())
|
||||
if (weapon->CurrentLevel < weapon->UpgradeDescriptions.Num())
|
||||
{
|
||||
UUpgradeButtonDataObject* Temp = NewObject<UUpgradeButtonDataObject>(this);
|
||||
Temp->SetData(weapon, this);
|
||||
|
@ -8,7 +8,7 @@
|
||||
void UUpgradeButtonDataObject::SetData(AWeapon* Weapon, UUserWidget* parent)
|
||||
{
|
||||
WeaponName = Weapon->Name;
|
||||
Description = Weapon->Description;
|
||||
Description = Weapon->UpgradeDescriptions[Weapon->CurrentLevel];
|
||||
WeaponIcon = Weapon->Icon;
|
||||
WeaponInstance = Weapon;
|
||||
Parent = parent;
|
||||
|
Loading…
x
Reference in New Issue
Block a user