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.
absg/Source/SpaceBattler/Private/PartySubsystem.cpp

70 lines
1.4 KiB

// Fill out your copyright notice in the Description page of Project Settings.
#include "PartySubsystem.h"
void UPartySubsystem::AddToParty(UUnitInfo* UnitInfo)
{
for (TPair<UUnitInfo*, int32> &Unit : Members)
{
if(Unit.Key->GetClass() == UnitInfo->GetClass())
{
Unit.Value++;
return;
}
}
}
TMap<UUnitInfo*, int32> UPartySubsystem::GetMembers()
{
return Members;
}
int32 UPartySubsystem::SpawnParty(float InVerticalSpacing, float InHorizontalOffset, int InNumRows)
{
this->VerticalSpacing = InVerticalSpacing;
this->HorizontalOffset = InHorizontalOffset;
this->NumRows = InNumRows;
GetMembers().KeySort([](const UUnitInfo& A, const UUnitInfo& B)
{
return A.GetTier() < B.GetTier();
});
for (TPair<UUnitInfo*, int32> &Unit : GetMembers())
{
for(auto i = 0; i < Unit.Value; i++)
{
SpawnQueue.Add(Unit.Key->GetCharacterClass());
}
}
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;
}
FVector Location = FVector(VerticalSpacing * i - VerticalSpacing, -HorizontalOffset, 0);
GetWorld()->SpawnActor(SpawnQueue[i + LastSpawnIndex], &Location);
}
LastSpawnIndex += NumRows;
}