Add Garlic Weapon test upgrading
This commit is contained in:
parent
0cad5ad897
commit
547c3d340d
BIN
Content/Weapons/Garlic/BP_GarlicWeapon.uasset
(Stored with Git LFS)
BIN
Content/Weapons/Garlic/BP_GarlicWeapon.uasset
(Stored with Git LFS)
Binary file not shown.
@ -23,7 +23,7 @@ void AWeapon::BeginPlay()
|
|||||||
|
|
||||||
if (expcomponent)
|
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()
|
bool AWeapon::UpgradeWeapon()
|
||||||
{
|
{
|
||||||
return UpgradeWeapon(CurrentLevel + 1);
|
if (CurrentLevel + 1 <= Upgrades.Num())
|
||||||
}
|
|
||||||
|
|
||||||
bool AWeapon::UpgradeWeapon(int newLevel)
|
|
||||||
{
|
|
||||||
if (newLevel < Upgrades.Num())
|
|
||||||
{
|
{
|
||||||
WeaponCooldown *= Upgrades[newLevel].WeaponCooldownMultiplier;
|
CurrentLevel++;
|
||||||
Damage *= Upgrades[newLevel].WeaponDamageMultiplier;
|
WeaponCooldown *= Upgrades[CurrentLevel - 1].WeaponCooldownMultiplier;
|
||||||
|
Damage *= Upgrades[CurrentLevel - 1].WeaponDamageMultiplier;
|
||||||
|
|
||||||
GetWorldTimerManager().ClearTimer(WeaponTimerHandle);
|
GetWorldTimerManager().ClearTimer(WeaponTimerHandle);
|
||||||
GetWorldTimerManager().SetTimer(WeaponTimerHandle, this, &AWeapon::FireWeaponAction, WeaponCooldown, true);
|
GetWorldTimerManager().SetTimer(WeaponTimerHandle, this, &AWeapon::FireWeaponAction, WeaponCooldown, true);
|
||||||
|
@ -57,10 +57,11 @@ public:
|
|||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties")
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties")
|
||||||
TArray<FWeaponLevelUpgrades> Upgrades = TArray<FWeaponLevelUpgrades>();
|
TArray<FWeaponLevelUpgrades> Upgrades = TArray<FWeaponLevelUpgrades>();
|
||||||
|
|
||||||
|
int CurrentLevel = 0;
|
||||||
|
|
||||||
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
|
||||||
@ -77,5 +78,4 @@ public:
|
|||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
virtual bool UpgradeWeapon();
|
virtual bool UpgradeWeapon();
|
||||||
virtual bool UpgradeWeapon(int newLevel);
|
|
||||||
};
|
};
|
||||||
|
@ -12,6 +12,7 @@ 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()
|
||||||
@ -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;
|
||||||
|
}
|
||||||
|
@ -26,12 +26,14 @@ 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();
|
||||||
|
|
||||||
@ -44,6 +46,8 @@ 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,
|
||||||
|
@ -37,18 +37,16 @@ void ULevelUpWidget::NativeConstruct()
|
|||||||
UpgradesListView->ClearListItems();
|
UpgradesListView->ClearListItems();
|
||||||
|
|
||||||
for (AWeapon* weapon : Inventory)
|
for (AWeapon* weapon : Inventory)
|
||||||
|
{
|
||||||
|
if (weapon->CurrentLevel < weapon->Upgrades.Num())
|
||||||
{
|
{
|
||||||
UUpgradeButtonDataObject* Temp = NewObject<UUpgradeButtonDataObject>(this);
|
UUpgradeButtonDataObject* Temp = NewObject<UUpgradeButtonDataObject>(this);
|
||||||
Temp->SetData(weapon);
|
Temp->SetData(weapon, this);
|
||||||
upgradeItems.Add(Temp);
|
upgradeItems.Add(Temp);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
UpgradesListView->SetListItems(upgradeItems);
|
UpgradesListView->SetListItems(upgradeItems);
|
||||||
|
|
||||||
// for (TSubclassOf<UUpgradeButtonDataObject> item : UpgradeItems)
|
|
||||||
// {
|
|
||||||
// upgradeItems.Add(NewObject<UUpgradeButtonDataObject>(this, item));
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
SetIsFocusable(true);
|
SetIsFocusable(true);
|
||||||
}
|
}
|
||||||
|
@ -5,15 +5,16 @@
|
|||||||
|
|
||||||
#include "vampires/Weapon.h"
|
#include "vampires/Weapon.h"
|
||||||
|
|
||||||
void UUpgradeButtonDataObject::SetData(AWeapon* Weapon)
|
void UUpgradeButtonDataObject::SetData(AWeapon* Weapon, UUserWidget* parent)
|
||||||
{
|
{
|
||||||
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)
|
void UUpgradeButtonDataObject::SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* parent)
|
||||||
{
|
{
|
||||||
AWeapon* temp = NewObject<AWeapon>(this, Weapon);
|
AWeapon* temp = NewObject<AWeapon>(this, Weapon);
|
||||||
if (temp)
|
if (temp)
|
||||||
@ -22,5 +23,6 @@ void UUpgradeButtonDataObject::SetData(TSubclassOf<AWeapon> Weapon)
|
|||||||
Description = temp->Description;
|
Description = temp->Description;
|
||||||
WeaponIcon = temp->Icon;
|
WeaponIcon = temp->Icon;
|
||||||
WeaponTemplate = Weapon;
|
WeaponTemplate = Weapon;
|
||||||
|
Parent = parent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,9 @@ public:
|
|||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
TObjectPtr<AWeapon> WeaponInstance;
|
TObjectPtr<AWeapon> WeaponInstance;
|
||||||
|
|
||||||
void SetData(AWeapon* Weapon);
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
void SetData(TSubclassOf<AWeapon> Weapon);
|
TObjectPtr<UUserWidget> Parent;
|
||||||
|
|
||||||
|
void SetData(AWeapon* Weapon, UUserWidget* parent);
|
||||||
|
void SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* parent);
|
||||||
};
|
};
|
||||||
|
@ -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,6 +27,24 @@ 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -43,4 +61,27 @@ 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
#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
|
||||||
{
|
{
|
||||||
@ -48,6 +50,14 @@ 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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user