// Fill out your copyright notice in the Description page of Project Settings. #include "PartySubsystem.h" void UPartySubsystem::AddToParty(UUnitInfo* UnitInfo) { for (TPair &Unit : Members) { if(Unit.Key->GetClass() == UnitInfo->GetClass()) { Unit.Value++; return; } } } TMap 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 &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; }