refactored party members into uobjects

feature/upgrades
Jers 10 months ago
parent d0807c3775
commit c5d77baa69

BIN
Content/Blueprints/BP_GameState.uasset (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/Levels/MainMenu.umap (Stored with Git LFS)

Binary file not shown.

@ -3,12 +3,64 @@
#include "PartyMember.h" #include "PartyMember.h"
FPartyMember::FPartyMember() int32 UPartyMember::GetAllocated()
{ {
UnitInfo = nullptr; return Allocated;
} }
FPartyMember::FPartyMember(UUnitInfo* InUnitInfo) void UPartyMember::AddToParty()
{ {
UnitInfo = InUnitInfo; if(Allocated == Available++)
{
Allocated++;
}
} }
int32 UPartyMember::GetAvailable()
{
return Available;
}
int32 UPartyMember::SetAllocation(int32 Amount)
{
if(Amount > Available)
{
Allocated = Available;
} else if (Amount < 0)
{
Allocated = 0;
} else
{
Allocated = Amount;
}
return Allocated;
}
int32 UPartyMember::AllocateMember()
{
if(Allocated == Available)
{
return Allocated;
} else
{
return ++Allocated;
}
}
int32 UPartyMember::DeallocateMember()
{
if(Allocated == 0)
{
return Allocated;
} else
{
return --Allocated;
}
}

@ -3,31 +3,10 @@
#include "PartySubsystem.h" #include "PartySubsystem.h"
#include "Unit.h"
#include "UpgradeSubsystem.h"
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
void UPartySubsystem::AddToParty(UUnitInfo* UnitInfo)
{
for (FPartyMember &Unit : Members)
{
if(Unit.UnitInfo == UnitInfo)
{
const bool UpdateAllocated = GetMemberAvailable(Unit) == GetMemberAllocated(Unit);
SetMemberAvailable(Unit, GetMemberAvailable(Unit) + 1);
if (UpdateAllocated)
{
AllocateMember(Unit);
}
return;
}
}
}
TArray<FPartyMember> UPartySubsystem::GetMembers()
{
return Members;
}
int32 UPartySubsystem::SpawnParty(const float InVerticalSpacing, const float InHorizontalOffset, const float InHorizontalSpacing, const int InNumRows) int32 UPartySubsystem::SpawnParty(const float InVerticalSpacing, const float InHorizontalOffset, const float InHorizontalSpacing, const int InNumRows)
{ {
this->VerticalSpacing = InVerticalSpacing; this->VerticalSpacing = InVerticalSpacing;
@ -42,12 +21,11 @@ int32 UPartySubsystem::SpawnParty(const float InVerticalSpacing, const float InH
UGameplayStatics::GetAllActorsWithTag(GetWorld(), "PlayerSpawn", SpawnPoints); UGameplayStatics::GetAllActorsWithTag(GetWorld(), "PlayerSpawn", SpawnPoints);
SpawnPoint = SpawnPoints[0]; SpawnPoint = SpawnPoints[0];
for (FPartyMember &Unit : GetMembers()) for (UPartyMember* Unit : PartyMembers)
{ {
const int32 Allocated = GetMemberAllocated(Unit); for(auto i = 0; i < Unit->GetAllocated(); i++)
for(auto i = 0; i < Allocated; i++)
{ {
SpawnQueue.Add(GetMemberUnitInfo(Unit)->GetCharacterClass()); SpawnQueue.Add(Unit->UnitInfo->GetCharacterClass());
} }
} }
@ -86,6 +64,11 @@ void UPartySubsystem::SpawnUnits()
if(NewActor != nullptr) if(NewActor != nullptr)
{ {
NewActor->Tags.Add(TEXT("player")); NewActor->Tags.Add(TEXT("player"));
TObjectPtr<AUnit> NewUnit = Cast<AUnit>(NewActor);
if(NewUnit != nullptr)
{
GetWorld()->GetFirstLocalPlayerFromController()->GetSubsystem<UUpgradeSubsystem>()->ApplyUnitUpgrades(NewUnit);
}
} }
FHitResult Hit; FHitResult Hit;
@ -105,104 +88,43 @@ void UPartySubsystem::SpawnUnits()
CurrentColumn++; CurrentColumn++;
} }
TArray<UUnitInfo*> UPartySubsystem::GetUnitsByTier(const int32 Tier) const
{
TArray<UUnitInfo*> TierMembers;
for(FPartyMember Member : Members)
{
if(GetMemberUnitInfo(Member)->GetTier() == Tier)
{
TierMembers.Add(GetMemberUnitInfo(Member));
}
}
return TierMembers;
}
void UPartySubsystem::SetCredits(const int32 Amount) void UPartySubsystem::SetCredits(const int32 Amount)
{ {
Credits = Amount; Credits = Amount;
} }
bool UPartySubsystem::AllocateMember(FPartyMember& Member) int32 UPartySubsystem::GetTotalAvailablePartyMembers()
{
Member.Allocated++;
if(Member.Allocated > Member.Available)
{
Member.Allocated = Member.Available;
return false;
}
return true;
}
bool UPartySubsystem::DeallocateMember(FPartyMember &Member)
{ {
Member.Allocated--; int32 Total = 0;
for(auto const Member : PartyMembers)
if (Member.Allocated < 0)
{ {
Member.Allocated = 0; Total += Member->GetAvailable();
return false;
} }
return true; return Total;
}
void UPartySubsystem::SetMemberMax(FPartyMember& Member)
{
Member.Allocated = Member.Available;
}
void UPartySubsystem::ClearMember(FPartyMember& Member)
{
Member.Allocated = 0;
}
int32 UPartySubsystem::GetMemberAllocated(FPartyMember& Member) const
{
return Member.Allocated;
}
int32 UPartySubsystem::GetMemberAvailable(FPartyMember& Member) const
{
return Member.Available;
}
void UPartySubsystem::SetMemberAvailable(FPartyMember& Member, int32 const Amount)
{
Member.Available = Amount;
}
void UPartySubsystem::SetMemberUnitInfo(FPartyMember& Member, UUnitInfo* InUnitInfo)
{
Member.UnitInfo = InUnitInfo;
}
UUnitInfo* UPartySubsystem::GetMemberUnitInfo(FPartyMember& Member) const
{
return Member.UnitInfo;
} }
int32 UPartySubsystem::GetTotalAvailablePartyMembers() int32 UPartySubsystem::GetTotalAllocatedPartyMembers()
{ {
int32 Total = 0; int32 Total = 0;
for(auto const Member : Members) for(auto const Member : PartyMembers)
{ {
Total += Member.Available; Total += Member->GetAllocated();
} }
return Total; return Total;
} }
int32 UPartySubsystem::GetTotalAllocatedPartyMembers() TArray<UPartyMember*> UPartySubsystem::GetMembersInTier(const int32 Tier)
{ {
int32 Total = 0; TArray<UPartyMember*> TierMembers;
for(auto const Member : Members) for(auto Member : PartyMembers)
{ {
Total += Member.Allocated; if (Member->UnitInfo->GetTier() == Tier)
{
TierMembers.Add(Member);
}
} }
return Total; return TierMembers;
} }

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

@ -0,0 +1,34 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Unit.h"
// Sets default values
AUnit::AUnit()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void AUnit::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AUnit::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void AUnit::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
}

@ -0,0 +1,9 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "UnitUpgrade.h"
void UUnitUpgrade::ApplyToUnit(AUnit* Unit)
{
}

@ -0,0 +1,9 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Upgrade.h"
TArray<FString> UUpgrade::GetApplicableTags()
{
return ApplicableTags;
}

@ -0,0 +1,30 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "UpgradeSubsystem.h"
#include "UnitUpgrade.h"
void UUpgradeSubsystem::ApplyUnitUpgrades(AUnit* Unit)
{
for (const auto Upgrade : SelectedUpgrades)
{
UUnitUpgrade* UnitUpgrade = Cast<UUnitUpgrade>(Upgrade.UpgradeData);
if(UnitUpgrade != nullptr)
{
for (const FString Tag : Upgrade.UpgradeData->GetApplicableTags())
{
if(Unit->UnitTags.Contains(Tag))
{
UnitUpgrade->ApplyToUnit(Unit);
}
}
}
}
}
void UUpgradeSubsystem::ApplyGlobalUpgrades()
{
}

@ -9,17 +9,34 @@
/** /**
* *
*/ */
USTRUCT(Blueprintable, BlueprintType) UCLASS(Blueprintable, BlueprintType)
struct SPACEBATTLER_API FPartyMember class SPACEBATTLER_API UPartyMember : public UObject
{ {
GENERATED_BODY() GENERATED_BODY()
FPartyMember(); public:
explicit FPartyMember(UUnitInfo* InUnitInfo); UPROPERTY(BlueprintReadWrite, meta=(ExposeOnSpawn=true))
UUnitInfo* UnitInfo;
UFUNCTION(BlueprintCallable)
void AddToParty();
UFUNCTION(BlueprintCallable)
int32 GetAvailable();
UFUNCTION(BlueprintCallable)
int32 GetAllocated();
UPROPERTY(BlueprintReadWrite) UFUNCTION(BlueprintCallable)
UUnitInfo* UnitInfo = nullptr; int32 AllocateMember();
UFUNCTION(BlueprintCallable)
int32 DeallocateMember();
UFUNCTION(BlueprintCallable)
int32 SetAllocation(int32 Amount);
protected:
UPROPERTY(BlueprintReadOnly) UPROPERTY(BlueprintReadOnly)
int32 Available = 0; int32 Available = 0;

@ -4,7 +4,6 @@
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "PartyMember.h" #include "PartyMember.h"
#include "UnitInfo.h"
#include "Subsystems/LocalPlayerSubsystem.h" #include "Subsystems/LocalPlayerSubsystem.h"
#include "PartySubsystem.generated.h" #include "PartySubsystem.generated.h"
@ -18,60 +17,27 @@ class SPACEBATTLER_API UPartySubsystem : public UGameInstanceSubsystem
public: public:
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
int32 SpawnParty(const float InVerticalSpacing, const float InHorizontalOffset, const float InHorizontalSpacing, const int InNumRows); int32 SpawnParty(const float InVerticalSpacing, const float InHorizontalOffset, const float InHorizontalSpacing, const int InNumRows);
UFUNCTION(BlueprintCallable)
void AddToParty(UUnitInfo* UnitInfo);
UFUNCTION(BlueprintCallable)
TArray<FPartyMember> GetMembers();
UFUNCTION(BlueprintCallable)
TArray<UUnitInfo*> GetUnitsByTier(const int32 Tier) const;
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void SetCredits(int32 Amount); void SetCredits(int32 Amount);
UFUNCTION(BlueprintCallable)
void SetMemberUnitInfo(UPARAM(ref) FPartyMember& Member, UUnitInfo* UnitInfo);
UFUNCTION(BlueprintCallable)
bool AllocateMember(UPARAM(ref) FPartyMember& Member);
UFUNCTION(BlueprintCallable)
bool DeallocateMember(UPARAM(ref) FPartyMember &Member);
UFUNCTION(BlueprintCallable)
void SetMemberMax(UPARAM(ref) FPartyMember& Member);
UFUNCTION(BlueprintCallable)
void ClearMember(UPARAM(ref) FPartyMember& Member);
UFUNCTION(BlueprintCallable)
void SetMemberAvailable(UPARAM(ref) FPartyMember& Member,int32 const Amount);
UFUNCTION(BlueprintCallable)
int32 GetMemberAvailable(UPARAM(ref) FPartyMember& Member) const;
UFUNCTION(BlueprintCallable)
int32 GetMemberAllocated(UPARAM(ref) FPartyMember& Member) const;
UFUNCTION(BlueprintCallable)
UUnitInfo* GetMemberUnitInfo(UPARAM(ref) FPartyMember& Member) const;
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
int32 GetTotalAvailablePartyMembers(); int32 GetTotalAvailablePartyMembers();
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
int32 GetTotalAllocatedPartyMembers(); int32 GetTotalAllocatedPartyMembers();
UFUNCTION(BlueprintCallable)
TArray<UPartyMember*> GetMembersInTier(const int32 Tier);
protected: protected:
void SpawnUnits(); void SpawnUnits();
UPROPERTY(BlueprintReadWrite, EditAnywhere)
TArray<TObjectPtr<UPartyMember>> PartyMembers;
UPROPERTY() UPROPERTY()
TArray<TSubclassOf<AActor>> SpawnQueue; TArray<TSubclassOf<AActor>> SpawnQueue;
UPROPERTY(BlueprintReadWrite, EditAnywhere)
TArray<FPartyMember> Members;
UPROPERTY(BlueprintReadWrite, EditAnywhere) UPROPERTY(BlueprintReadWrite, EditAnywhere)
UPrimaryDataAsset* SelectedGeneral; UPrimaryDataAsset* SelectedGeneral;

@ -0,0 +1,22 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Upgrade.h"
#include "SelectedUpgrade.generated.h"
/**
*
*/
USTRUCT(BlueprintType)
struct FSelectedUpgrade
{
GENERATED_BODY()
UPROPERTY(BlueprintReadWrite)
UUpgrade* UpgradeData;
UPROPERTY(BlueprintReadWrite)
int32 TimesSelected;
};

@ -0,0 +1,63 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Unit.generated.h"
UCLASS()
class SPACEBATTLER_API AUnit : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
AUnit();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
/** Please add a variable description */
UPROPERTY(BlueprintReadWrite, Category="Unit Info Copy")
double MaxHP;
/** Please add a variable description */
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="State")
double HP;
/** Please add a variable description */
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="Unit Info Copy")
double Attack;
/** Please add a variable description */
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="Unit Info Copy")
double Range;
/** Please add a variable description */
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="Unit Info Copy")
double RangedProjectileSpeed;
/** Please add a variable description */
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="Unit Info Copy")
double RangedProjectileDelay;
/** Please add a variable description */
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="Unit Info Copy")
int32 RangedProjectileAmount;
/** Please add a variable description */
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="Unit Info Copy")
double Cooldown;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="Unit Info Copy")
TArray<FString> UnitTags;
};

@ -74,4 +74,7 @@ protected:
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="Ranged Info") UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="Ranged Info")
UAnimMontage* RangedProjectileMontage; UAnimMontage* RangedProjectileMontage;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="Information")
TArray<FText> UnitTags;
}; };

@ -0,0 +1,20 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Unit.h"
#include "Upgrade.h"
#include "UnitUpgrade.generated.h"
/**
*
*/
UCLASS()
class SPACEBATTLER_API UUnitUpgrade : public UUpgrade
{
GENERATED_BODY()
public:
void ApplyToUnit(AUnit* Unit);
};

@ -0,0 +1,32 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Engine/DataAsset.h"
#include "Upgrade.generated.h"
/**
*
*/
UCLASS()
class SPACEBATTLER_API UUpgrade : public UPrimaryDataAsset
{
GENERATED_BODY()
public:
TArray<FString> GetApplicableTags();
protected:
UPROPERTY(BlueprintReadWrite)
FText Name;
UPROPERTY(BlueprintReadWrite, meta=(MultiLine=true))
FText Description;
UPROPERTY(BlueprintReadWrite)
bool Repeatable;
UPROPERTY(BlueprintReadWrite, EditAnywhere)
TArray<FString> ApplicableTags;
};

@ -0,0 +1,32 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "SelectedUpgrade.h"
#include "Unit.h"
#include "Subsystems/LocalPlayerSubsystem.h"
#include "UpgradeSubsystem.generated.h"
/**
*
*/
UCLASS()
class SPACEBATTLER_API UUpgradeSubsystem : public ULocalPlayerSubsystem
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable)
void ApplyUnitUpgrades(AUnit* Unit);
UFUNCTION(BlueprintCallable)
void ApplyGlobalUpgrades();
protected:
UPROPERTY(BlueprintReadWrite)
int32 BattleTier;
UPROPERTY(BlueprintReadWrite)
TArray<FSelectedUpgrade> SelectedUpgrades;
};
Loading…
Cancel
Save