Add Garlic Weapon test upgrading

This commit is contained in:
baz 2025-02-03 20:12:58 +00:00
parent 0cad5ad897
commit 547c3d340d
10 changed files with 99 additions and 33 deletions

Binary file not shown.

View File

@ -23,7 +23,7 @@ void AWeapon::BeginPlay()
if (expcomponent)
{
expcomponent->OnEXPLevelUp.AddUniqueDynamic(this, &AWeapon::UpgradeWeapon);
//expcomponent->OnEXPLevelUp.AddUniqueDynamic(this, &AWeapon::UpgradeWeapon);
}
}
@ -34,15 +34,11 @@ void AWeapon::FireWeaponAction_Implementation()
bool AWeapon::UpgradeWeapon()
{
return UpgradeWeapon(CurrentLevel + 1);
}
bool AWeapon::UpgradeWeapon(int newLevel)
{
if (newLevel < Upgrades.Num())
if (CurrentLevel + 1 <= Upgrades.Num())
{
WeaponCooldown *= Upgrades[newLevel].WeaponCooldownMultiplier;
Damage *= Upgrades[newLevel].WeaponDamageMultiplier;
CurrentLevel++;
WeaponCooldown *= Upgrades[CurrentLevel - 1].WeaponCooldownMultiplier;
Damage *= Upgrades[CurrentLevel - 1].WeaponDamageMultiplier;
GetWorldTimerManager().ClearTimer(WeaponTimerHandle);
GetWorldTimerManager().SetTimer(WeaponTimerHandle, this, &AWeapon::FireWeaponAction, WeaponCooldown, true);
@ -50,4 +46,4 @@ bool AWeapon::UpgradeWeapon(int newLevel)
}
return false;
}
}

View File

@ -56,11 +56,12 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties")
TArray<FWeaponLevelUpgrades> Upgrades = TArray<FWeaponLevelUpgrades>();
int CurrentLevel = 0;
private:
FTimerHandle WeaponTimerHandle;
int CurrentLevel = 0;
public:
// Sets default values for this actor's properties
@ -77,5 +78,4 @@ public:
UFUNCTION()
virtual bool UpgradeWeapon();
virtual bool UpgradeWeapon(int newLevel);
};

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

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