Compare commits

..

No commits in common. "390b50547b580788bd3c88632b87616ccaded12a" and "c9d10f86a416d398e16e1e231a9b9c5eea6653d5" have entirely different histories.

13 changed files with 98 additions and 144 deletions

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

Binary file not shown.

Binary file not shown.

View File

@ -17,26 +17,21 @@ void AWeapon::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
TArray<AWeapon*> example;
GetWorldTimerManager().SetTimer(WeaponTimerHandle, this, &AWeapon::FireWeaponAction, WeaponCooldown, true); 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() void AWeapon::FireWeaponAction_Implementation()
{ {
// This should be overridden in child weapon classes // Do stuff
} }
bool AWeapon::UpgradeWeapon() void AWeapon::UpgradeWeapon(int newLevel)
{ {
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,33 +6,23 @@
#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;
@ -42,27 +32,9 @@ 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>();
int CurrentLevel = 0;
private: private:
FTimerHandle WeaponTimerHandle; FTimerHandle WeaponTimerHandle;
public: public:
// Sets default values for this actor's properties // Sets default values for this actor's properties
AWeapon(); AWeapon();
@ -77,5 +49,5 @@ public:
virtual void FireWeaponAction_Implementation(); virtual void FireWeaponAction_Implementation();
UFUNCTION() UFUNCTION()
virtual bool UpgradeWeapon(); virtual void UpgradeWeapon(int newLevel);
}; };

View File

@ -12,7 +12,6 @@ AGarlicWeapon::AGarlicWeapon()
SphereComponent->SetupAttachment(RootComponent); SphereComponent->SetupAttachment(RootComponent);
SphereComponent->SetSphereRadius(150.0f); SphereComponent->SetSphereRadius(150.0f);
Damage = 51.0f; Damage = 51.0f;
Range = SphereComponent->GetScaledSphereRadius();
} }
void AGarlicWeapon::BeginPlay() void AGarlicWeapon::BeginPlay()
@ -88,14 +87,3 @@ 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,14 +26,12 @@ UCLASS()
class VAMPIRES_API AGarlicWeapon : public AWeapon class VAMPIRES_API AGarlicWeapon : public AWeapon
{ {
GENERATED_BODY() GENERATED_BODY()
public:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true")) UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
USphereComponent* SphereComponent; USphereComponent* SphereComponent;
TArray<FOverlappedEnemy> OverlappedEnemies; TArray<FOverlappedEnemy> OverlappedEnemies;
private:
float Range;
public: public:
AGarlicWeapon(); AGarlicWeapon();
@ -45,9 +43,7 @@ public:
UFUNCTION() UFUNCTION()
void GarlicFireWeaponAction(FOverlappedEnemy EnemyCharacter); void GarlicFireWeaponAction(FOverlappedEnemy EnemyCharacter);
virtual bool UpgradeWeapon() override;
protected: protected:
UFUNCTION() UFUNCTION()
void OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, void OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,

View File

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

View File

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

View File

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

View File

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

View File

@ -4,18 +4,18 @@
#include "UpgradeButtonWidget.h" #include "UpgradeButtonWidget.h"
#include "UpgradeButtonDataObject.h" #include "UpgradeButtonDataObject.h"
#include "Blueprint/WidgetBlueprintLibrary.h"
#include "Components/Button.h" #include "Components/Button.h"
#include "Components/Image.h" #include "Components/Image.h"
#include "Components/TextBlock.h" #include "Components/TextBlock.h"
#include "Kismet/GameplayStatics.h"
#include "Kismet/KismetSystemLibrary.h"
#include "vampires/Weapon.h"
#include "UObject/UObjectBase.h"
void UUpgradeButtonWidget::NativeConstruct() void UUpgradeButtonWidget::NativeConstruct()
{ {
Super::NativeConstruct(); Super::NativeConstruct();
if (Body)
{
Body->OnClicked.AddUniqueDynamic(this, &UUpgradeButtonWidget::OnClicked);
}
} }
void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject) void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
@ -27,24 +27,6 @@ void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
WeaponNameTextBlock->SetText(Item->WeaponName); WeaponNameTextBlock->SetText(Item->WeaponName);
DescriptionTextBlock->SetText(Item->Description); DescriptionTextBlock->SetText(Item->Description);
WeaponIcon->SetBrushFromTexture(Item->WeaponIcon); 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);
}
} }
@ -61,27 +43,4 @@ void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
void UUpgradeButtonWidget::OnClicked() 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,8 +7,6 @@
#include "Blueprint/UserWidget.h" #include "Blueprint/UserWidget.h"
#include "UpgradeButtonWidget.generated.h" #include "UpgradeButtonWidget.generated.h"
class AWeapon;
UENUM(BlueprintType) UENUM(BlueprintType)
enum EUpgradeType enum EUpgradeType
{ {
@ -50,14 +48,6 @@ public:
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly)
TEnumAsByte<EUpgradeType> UpgradeType; TEnumAsByte<EUpgradeType> UpgradeType;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TSubclassOf<AWeapon> WeaponTemplate;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TObjectPtr<AWeapon> WeaponInstance;
TObjectPtr<UUserWidget> Parent;
private: private:
UPROPERTY(meta=(BindWidget)) UPROPERTY(meta=(BindWidget))
UImage* UpgradeTypeIcon; UImage* UpgradeTypeIcon;