RealtimeStyleTransferRuntime/Source/LyraGame/Teams/LyraTeamCheats.cpp

67 lines
1.8 KiB
C++
Raw Normal View History

2022-05-23 18:41:30 +00:00
// Copyright Epic Games, Inc. All Rights Reserved.
#include "LyraTeamCheats.h"
2022-09-13 07:18:28 +00:00
#include "Containers/Array.h"
2022-05-23 18:41:30 +00:00
#include "Engine/World.h"
#include "GameFramework/PlayerController.h"
2022-09-13 07:18:28 +00:00
#include "HAL/IConsoleManager.h"
#include "Logging/LogCategory.h"
#include "Logging/LogMacros.h"
#include "Teams/LyraTeamSubsystem.h"
#include "Trace/Detail/Channel.h"
2022-05-23 18:41:30 +00:00
//////////////////////////////////////////////////////////////////////
// ULyraTeamCheats
void ULyraTeamCheats::CycleTeam()
{
if (ULyraTeamSubsystem* TeamSubsystem = UWorld::GetSubsystem<ULyraTeamSubsystem>(GetWorld()))
{
APlayerController* PC = GetPlayerController();
const int32 OldTeamId = TeamSubsystem->FindTeamFromObject(PC);
const TArray<int32> TeamIds = TeamSubsystem->GetTeamIDs();
if (TeamIds.Num())
{
const int32 IndexOfOldTeam = TeamIds.Find(OldTeamId);
const int32 IndexToUse = (IndexOfOldTeam + 1) % TeamIds.Num();
const int32 NewTeamId = TeamIds[IndexToUse];
TeamSubsystem->ChangeTeamForActor(PC, NewTeamId);
}
const int32 ActualNewTeamId = TeamSubsystem->FindTeamFromObject(PC);
UE_LOG(LogConsoleResponse, Log, TEXT("Changed to team %d (from team %d)"), ActualNewTeamId, OldTeamId);
}
}
void ULyraTeamCheats::SetTeam(int32 TeamID)
{
if (ULyraTeamSubsystem* TeamSubsystem = UWorld::GetSubsystem<ULyraTeamSubsystem>(GetWorld()))
{
if (TeamSubsystem->DoesTeamExist(TeamID))
{
APlayerController* PC = GetPlayerController();
TeamSubsystem->ChangeTeamForActor(PC, TeamID);
}
}
}
void ULyraTeamCheats::ListTeams()
{
if (ULyraTeamSubsystem* TeamSubsystem = UWorld::GetSubsystem<ULyraTeamSubsystem>(GetWorld()))
{
const TArray<int32> TeamIDs = TeamSubsystem->GetTeamIDs();
for (const int32 TeamID : TeamIDs)
{
UE_LOG(LogConsoleResponse, Log, TEXT("Team ID %d"), TeamID);
}
}
}