Compare commits

...

3 Commits

Author SHA1 Message Date
baz
390b50547b Clean up base weapon class 2025-02-03 20:15:22 +00:00
baz
547c3d340d Add Garlic Weapon test upgrading 2025-02-03 20:12:58 +00:00
baz
0cad5ad897 Add base weapon upgrading 2025-02-03 18:53:08 +00:00
13 changed files with 144 additions and 98 deletions

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

Binary file not shown.

Binary file not shown.

View File

@ -17,21 +17,26 @@ void AWeapon::BeginPlay()
{
Super::BeginPlay();
TArray<AWeapon*> example;
GetWorldTimerManager().SetTimer(WeaponTimerHandle, this, &AWeapon::FireWeaponAction, WeaponCooldown, true);
UEXPComponent* expcomponent = GetOwner()->GetComponentByClass<UEXPComponent>();
if (expcomponent)
{
expcomponent->OnEXPLevelUp.AddUniqueDynamic(this, &AWeapon::UpgradeWeapon);
}
}
void AWeapon::FireWeaponAction_Implementation()
{
// Do stuff
// This should be overridden in child weapon classes
}
void AWeapon::UpgradeWeapon(int newLevel)
bool AWeapon::UpgradeWeapon()
{
}
if (CurrentLevel + 1 <= Upgrades.Num())
{
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;
}

View File

@ -6,23 +6,33 @@
#include "GameFramework/Actor.h"
#include "Weapon.generated.h"
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
{
GENERATED_BODY()
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")
FText Name;
@ -32,9 +42,27 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties")
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>();
int CurrentLevel = 0;
private:
FTimerHandle WeaponTimerHandle;
public:
// Sets default values for this actor's properties
AWeapon();
@ -49,5 +77,5 @@ public:
virtual void FireWeaponAction_Implementation();
UFUNCTION()
virtual void UpgradeWeapon(int newLevel);
virtual bool UpgradeWeapon();
};

View File

@ -12,6 +12,7 @@ AGarlicWeapon::AGarlicWeapon()
SphereComponent->SetupAttachment(RootComponent);
SphereComponent->SetSphereRadius(150.0f);
Damage = 51.0f;
Range = SphereComponent->GetScaledSphereRadius();
}
void AGarlicWeapon::BeginPlay()
@ -87,3 +88,14 @@ void AGarlicWeapon::GarlicFireWeaponAction(FOverlappedEnemy EnemyCharacter)
}
}
}
bool AGarlicWeapon::UpgradeWeapon()
{
if (Super::UpgradeWeapon())
{
Range *= Upgrades[CurrentLevel - 1].WeaponRangeMultiplier;
SphereComponent->SetSphereRadius(Range);
return true;
}
return false;
}

View File

@ -26,12 +26,14 @@ UCLASS()
class VAMPIRES_API AGarlicWeapon : public AWeapon
{
GENERATED_BODY()
public:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
USphereComponent* SphereComponent;
TArray<FOverlappedEnemy> OverlappedEnemies;
private:
float Range;
public:
AGarlicWeapon();
@ -43,7 +45,9 @@ public:
UFUNCTION()
void GarlicFireWeaponAction(FOverlappedEnemy EnemyCharacter);
virtual bool UpgradeWeapon() override;
protected:
UFUNCTION()
void OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,

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

View File

@ -38,17 +38,15 @@ void ULevelUpWidget::NativeConstruct()
for (AWeapon* weapon : Inventory)
{
UUpgradeButtonDataObject* Temp = NewObject<UUpgradeButtonDataObject>(this);
Temp->SetData(weapon);
upgradeItems.Add(Temp);
if (weapon->CurrentLevel < weapon->Upgrades.Num())
{
UUpgradeButtonDataObject* Temp = NewObject<UUpgradeButtonDataObject>(this);
Temp->SetData(weapon, this);
upgradeItems.Add(Temp);
}
}
UpgradesListView->SetListItems(upgradeItems);
// for (TSubclassOf<UUpgradeButtonDataObject> item : UpgradeItems)
// {
// upgradeItems.Add(NewObject<UUpgradeButtonDataObject>(this, item));
// }
}
SetIsFocusable(true);
}

View File

@ -5,15 +5,16 @@
#include "vampires/Weapon.h"
void UUpgradeButtonDataObject::SetData(AWeapon* Weapon)
void UUpgradeButtonDataObject::SetData(AWeapon* Weapon, UUserWidget* parent)
{
WeaponName = Weapon->Name;
Description = Weapon->Description;
WeaponIcon = Weapon->Icon;
WeaponInstance = Weapon;
Parent = parent;
}
void UUpgradeButtonDataObject::SetData(TSubclassOf<AWeapon> Weapon)
void UUpgradeButtonDataObject::SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* parent)
{
AWeapon* temp = NewObject<AWeapon>(this, Weapon);
if (temp)
@ -22,5 +23,6 @@ void UUpgradeButtonDataObject::SetData(TSubclassOf<AWeapon> Weapon)
Description = temp->Description;
WeaponIcon = temp->Icon;
WeaponTemplate = Weapon;
Parent = parent;
}
}

View File

@ -31,6 +31,9 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TObjectPtr<AWeapon> WeaponInstance;
void SetData(AWeapon* Weapon);
void SetData(TSubclassOf<AWeapon> Weapon);
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TObjectPtr<UUserWidget> Parent;
void SetData(AWeapon* Weapon, UUserWidget* parent);
void SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* parent);
};

View File

@ -4,18 +4,18 @@
#include "UpgradeButtonWidget.h"
#include "UpgradeButtonDataObject.h"
#include "Blueprint/WidgetBlueprintLibrary.h"
#include "Components/Button.h"
#include "Components/Image.h"
#include "Components/TextBlock.h"
#include "Kismet/GameplayStatics.h"
#include "Kismet/KismetSystemLibrary.h"
#include "vampires/Weapon.h"
#include "UObject/UObjectBase.h"
void UUpgradeButtonWidget::NativeConstruct()
{
Super::NativeConstruct();
if (Body)
{
Body->OnClicked.AddUniqueDynamic(this, &UUpgradeButtonWidget::OnClicked);
}
}
void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
@ -27,6 +27,24 @@ void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
WeaponNameTextBlock->SetText(Item->WeaponName);
DescriptionTextBlock->SetText(Item->Description);
WeaponIcon->SetBrushFromTexture(Item->WeaponIcon);
Parent = Item->Parent;
if (Item->WeaponInstance != nullptr)
{
UpgradeType = EUpgradeType::Upgrade;
WeaponInstance = Item->WeaponInstance;
}
else if (Item->WeaponTemplate != nullptr)
{
UpgradeType = EUpgradeType::NewWeapon;
WeaponTemplate = Item->WeaponTemplate;
}
if (Body)
{
Body->OnClicked.AddUniqueDynamic(this, &UUpgradeButtonWidget::OnClicked);
}
}
@ -43,4 +61,27 @@ void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
void UUpgradeButtonWidget::OnClicked()
{
switch (UpgradeType) {
case Upgrade:
WeaponInstance->UpgradeWeapon();
break;
case NewWeapon:
// TODO: Spawn weapon
break;
default: ;
}
if (Parent)
{
Parent->RemoveFromParent();
if (APlayerController* playerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
{
UWidgetBlueprintLibrary::SetInputMode_GameOnly(playerController);
playerController->bShowMouseCursor = false;
playerController->SetPause(false);
}
Parent->SetIsFocusable(false);
}
}

View File

@ -7,6 +7,8 @@
#include "Blueprint/UserWidget.h"
#include "UpgradeButtonWidget.generated.h"
class AWeapon;
UENUM(BlueprintType)
enum EUpgradeType
{
@ -48,6 +50,14 @@ public:
UPROPERTY(EditDefaultsOnly)
TEnumAsByte<EUpgradeType> UpgradeType;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TSubclassOf<AWeapon> WeaponTemplate;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TObjectPtr<AWeapon> WeaponInstance;
TObjectPtr<UUserWidget> Parent;
private:
UPROPERTY(meta=(BindWidget))
UImage* UpgradeTypeIcon;