Initial Commit

This commit is contained in:
Norman Lansing
2026-01-28 19:08:51 -05:00
commit ecb33115bf
54042 changed files with 9695586 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Game/MatchGameState.h"
#include "Player/MatchPlayerState.h"
AMatchGameState::AMatchGameState()
{
Leaders = TArray<TObjectPtr<AMatchPlayerState>>();
bHasFirstBloodBeenHad = false;
}
AMatchPlayerState* AMatchGameState::GetLeader() const
{
if (Leaders.Num() == 1)
{
return Leaders[0];
}
return nullptr;
}
void AMatchGameState::UpdateLeader()
{
TArray<APlayerState*> SortedPlayers = PlayerArray;
SortedPlayers.Sort([](const APlayerState& A, const APlayerState& B)
{
const AMatchPlayerState* PlayerA = Cast<AMatchPlayerState>(&A);
const AMatchPlayerState* PlayerB = Cast<AMatchPlayerState>(&B);
return PlayerA->GetScoredElims() > PlayerB->GetScoredElims();
});
Leaders.Empty();
if (SortedPlayers.Num() > 0)
{
int32 HighestScore = 0;
for (APlayerState* PlayerState : SortedPlayers)
{
AMatchPlayerState* Player = Cast<AMatchPlayerState>(PlayerState);
if (IsValid(Player))
{
int32 PlayerScore = Player->GetScoredElims();
// On the first iteration, set the highest score
if (Leaders.Num() == 0)
{
HighestScore = PlayerScore;
Leaders.Add(Player);
}
else if (PlayerScore == HighestScore)
{
Leaders.Add(Player); // Add to leaders if scores are tied
}
else
{
break; // As it's sorted, no need to check further
}
}
}
}
bHasFirstBloodBeenHad = true;
}
bool AMatchGameState::IsTiedForTheLead(AMatchPlayerState* PlayerState)
{
if (Leaders.Contains(PlayerState)) return true;
return false;
}
void AMatchGameState::BeginPlay()
{
Super::BeginPlay();
}

View File

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

View File

@@ -0,0 +1,57 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Game/ShooterGameModeBase.h"
#include "GameFramework/Character.h"
#include "GameFramework/PlayerStart.h"
#include "Kismet/GameplayStatics.h"
AShooterGameModeBase::AShooterGameModeBase()
{
RespawnTime = 2.f;
}
void AShooterGameModeBase::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AShooterGameModeBase::StartPlayerElimination(float ElimTime, ACharacter* ElimmedCharacter,
APlayerController* VictimController, APlayerController* AttackerController)
{
FTimerDelegate ElimTimerDelegate;
FTimerHandle TimerHandle;
Timers.Add(VictimController, TimerHandle);
ElimTimerDelegate.BindLambda([this, ElimmedCharacter, VictimController, AttackerController]()
{
PlayerEliminated(ElimmedCharacter, VictimController, AttackerController);
GetWorldTimerManager().ClearTimer(Timers[VictimController]);
Timers.Remove(VictimController);
});
GetWorldTimerManager().SetTimer(TimerHandle, ElimTimerDelegate, ElimTime + RespawnTime, false);
}
void AShooterGameModeBase::PlayerEliminated(ACharacter* ElimmedCharacter, APlayerController* VictimController,
APlayerController* AttackerController)
{
RequestRespawn(ElimmedCharacter, VictimController);
}
void AShooterGameModeBase::RequestRespawn(ACharacter* ElimmedCharacter, AController* ElimmedController)
{
if (ElimmedCharacter)
{
ElimmedCharacter->Reset();
ElimmedCharacter->Destroy();
}
if (ElimmedController)
{
TArray<AActor*> PlayerStarts;
UGameplayStatics::GetAllActorsOfClass(this, APlayerStart::StaticClass(), PlayerStarts);
int32 Selection = FMath::RandRange(0, PlayerStarts.Num() - 1);
RestartPlayerAtPlayerStart(ElimmedController, PlayerStarts[Selection]);
}
}