You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
156 lines
3.3 KiB
156 lines
3.3 KiB
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "PartySubsystem.h"
|
|
|
|
void UPartySubsystem::AddToParty(UUnitInfo* UnitInfo)
|
|
{
|
|
for (FPartyMember &Unit : Members)
|
|
{
|
|
if(GetMemberUnitInfo(Unit)->GetClass() == UnitInfo->GetClass())
|
|
{
|
|
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)
|
|
{
|
|
this->VerticalSpacing = InVerticalSpacing;
|
|
this->HorizontalOffset = InHorizontalOffset;
|
|
this->NumRows = InNumRows;
|
|
this->HorizontalSpacing = InHorizontalSpacing;
|
|
|
|
for (FPartyMember &Unit : GetMembers())
|
|
{
|
|
for(auto i = 0; i < GetMemberAllocated(Unit); i++)
|
|
{
|
|
SpawnQueue.Add(GetMemberUnitInfo(Unit)->GetCharacterClass());
|
|
}
|
|
}
|
|
|
|
const auto NumUnits= SpawnQueue.Num();
|
|
|
|
SpawnUnits();
|
|
GetWorld()->GetTimerManager().SetTimer(
|
|
SpawnTimerHandle,
|
|
this,
|
|
&UPartySubsystem::SpawnUnits,
|
|
0.5f,
|
|
true);
|
|
|
|
return NumUnits;
|
|
}
|
|
|
|
void UPartySubsystem::SpawnUnits()
|
|
{
|
|
for(auto i = 0; i < NumRows; i++)
|
|
{
|
|
if(i + LastSpawnIndex >= SpawnQueue.Num())
|
|
{
|
|
GetWorld()->GetTimerManager().ClearTimer(SpawnTimerHandle);
|
|
return;
|
|
}
|
|
|
|
FActorSpawnParameters SpawnActorParameters = {};
|
|
SpawnActorParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
|
|
|
|
FVector Location = FVector( VerticalSpacing * i - VerticalSpacing, -HorizontalOffset * CurrentColumn, 0);
|
|
GetWorld()->SpawnActor(SpawnQueue[i + LastSpawnIndex], &Location, nullptr, SpawnActorParameters);
|
|
}
|
|
|
|
LastSpawnIndex += NumRows;
|
|
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)
|
|
{
|
|
Credits = Amount;
|
|
}
|
|
|
|
bool UPartySubsystem::AllocateMember(FPartyMember& Member)
|
|
{
|
|
Member.Allocated++;
|
|
if(Member.Allocated > Member.Available)
|
|
{
|
|
Member.Allocated = Member.Available;
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool UPartySubsystem::DeallocateMember(FPartyMember& Member)
|
|
{
|
|
Member.Allocated--;
|
|
|
|
if (Member.Allocated < 0)
|
|
{
|
|
Member.Allocated = 0;
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
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;
|
|
} |