Update Game Mode for Basic Player Spawning
This commit is contained in:
		
							parent
							
								
									1169adc721
								
							
						
					
					
						commit
						3345a4d27d
					
				
							
								
								
									
										
											BIN
										
									
								
								CorruptedMemory/Content/BP_CMGameMode.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								CorruptedMemory/Content/BP_CMGameMode.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										3
									
								
								CorruptedMemory/Content/BP_StoreShelf.uasset
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								CorruptedMemory/Content/BP_StoreShelf.uasset
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
			
		||||
version https://git-lfs.github.com/spec/v1
 | 
			
		||||
oid sha256:5a1f6f15d2bcd70e7fde7988ed7890d1048dcb13dbd3aa3d53da77443b0cd6bc
 | 
			
		||||
size 30219
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								CorruptedMemory/Content/Server/BP_LobbyPlayer.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								CorruptedMemory/Content/Server/BP_LobbyPlayer.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								CorruptedMemory/Content/Server/BP_ServerMenu.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								CorruptedMemory/Content/Server/BP_ServerMenu.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								CorruptedMemory/Content/StarterContent/Props/Materials/M_TableRound.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								CorruptedMemory/Content/StarterContent/Props/Materials/M_TableRound.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								CorruptedMemory/Content/StarterContent/Props/NS_Portal.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								CorruptedMemory/Content/StarterContent/Props/NS_Portal.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								CorruptedMemory/Content/StarterContent/Props/SM_TeleporterPad.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								CorruptedMemory/Content/StarterContent/Props/SM_TeleporterPad.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								CorruptedMemory/Content/StarterContent/Props/TeleporterPad.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								CorruptedMemory/Content/StarterContent/Props/TeleporterPad.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							@ -1,3 +0,0 @@
 | 
			
		||||
version https://git-lfs.github.com/spec/v1
 | 
			
		||||
oid sha256:185f092ca45fc44e8c25644e92e32ff0b5bcd6727ba98871a52bdb67e21d00e4
 | 
			
		||||
size 925096
 | 
			
		||||
@ -386,6 +386,10 @@ void UCMGameInstance::OnRequestToGetLobbyPlayersComplete(FHttpRequestPtr Request
 | 
			
		||||
				const auto JsonIsReady = Player->AsObject()->GetBoolField("isReady");
 | 
			
		||||
				PlayersInLobby.Add(FPlayerInLobby(JsonUsername, JsonIsOwner, JsonIsReady));
 | 
			
		||||
			}
 | 
			
		||||
			PlayerIndex = PlayersInLobby.IndexOfByPredicate([this](const FPlayerInLobby& Player)
 | 
			
		||||
			{
 | 
			
		||||
				return Player.Username == AccountUsername;
 | 
			
		||||
			});
 | 
			
		||||
			OnGetPlayersInLobbyComplete.Broadcast(true);
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
 | 
			
		||||
@ -74,9 +74,11 @@ public:
 | 
			
		||||
	FOnServerClose OnServerClose;
 | 
			
		||||
 | 
			
		||||
	UPROPERTY(BlueprintReadOnly, Category = "Account")
 | 
			
		||||
	FString AccountUsername;
 | 
			
		||||
	FString AccountUsername = "Bruh";
 | 
			
		||||
	UPROPERTY(BlueprintReadOnly, Category = "Account")
 | 
			
		||||
	FString JwtToken;
 | 
			
		||||
	UPROPERTY(BlueprintReadOnly, Category = "Account")
 | 
			
		||||
	int32 PlayerIndex = 0;
 | 
			
		||||
 | 
			
		||||
	UPROPERTY(BlueprintReadOnly, Category = "Lobby")
 | 
			
		||||
	FString ServerFQDN = "cm.api.philipwhite.dev";
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										10
									
								
								CorruptedMemory/Source/CorruptedMemory/CM_GameState.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								CorruptedMemory/Source/CorruptedMemory/CM_GameState.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,10 @@
 | 
			
		||||
// Fill out your copyright notice in the Description page of Project Settings.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "CM_GameState.h"
 | 
			
		||||
 | 
			
		||||
#include "CMGameInstance.h"
 | 
			
		||||
#include "CorruptedMemoryGameMode.h"
 | 
			
		||||
#include "GameFramework/PlayerState.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										20
									
								
								CorruptedMemory/Source/CorruptedMemory/CM_GameState.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								CorruptedMemory/Source/CorruptedMemory/CM_GameState.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,20 @@
 | 
			
		||||
// Fill out your copyright notice in the Description page of Project Settings.
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "CoreMinimal.h"
 | 
			
		||||
#include "GameFramework/GameState.h"
 | 
			
		||||
#include "CM_GameState.generated.h"
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 
 | 
			
		||||
 */
 | 
			
		||||
UCLASS()
 | 
			
		||||
class CORRUPTEDMEMORY_API ACM_GameState : public AGameStateBase
 | 
			
		||||
{
 | 
			
		||||
	GENERATED_BODY()
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	UPROPERTY()
 | 
			
		||||
	APlayerState* PlayerState;
 | 
			
		||||
};
 | 
			
		||||
@ -0,0 +1,16 @@
 | 
			
		||||
// Fill out your copyright notice in the Description page of Project Settings.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "CM_PlayerController.h"
 | 
			
		||||
 | 
			
		||||
#include "CorruptedMemoryGameMode.h"
 | 
			
		||||
 | 
			
		||||
void ACM_PlayerController::BeginPlay()
 | 
			
		||||
{
 | 
			
		||||
	Super::BeginPlay();
 | 
			
		||||
	FString MapName = GetWorld()->GetMapName();
 | 
			
		||||
	MapName.RemoveFromStart(GetWorld()->StreamingLevelsPrefix);
 | 
			
		||||
	if (MapName == "ClientEntry") return;
 | 
			
		||||
	if (!GetWorld()->GetAuthGameMode()) return;
 | 
			
		||||
	Cast<ACorruptedMemoryGameMode>(GetWorld()->GetAuthGameMode())->ServerSpawnPlayer(this);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										19
									
								
								CorruptedMemory/Source/CorruptedMemory/CM_PlayerController.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								CorruptedMemory/Source/CorruptedMemory/CM_PlayerController.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,19 @@
 | 
			
		||||
// Fill out your copyright notice in the Description page of Project Settings.
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "CoreMinimal.h"
 | 
			
		||||
#include "GameFramework/PlayerController.h"
 | 
			
		||||
#include "CM_PlayerController.generated.h"
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 
 | 
			
		||||
 */
 | 
			
		||||
UCLASS()
 | 
			
		||||
class CORRUPTEDMEMORY_API ACM_PlayerController : public APlayerController
 | 
			
		||||
{
 | 
			
		||||
	GENERATED_BODY()
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
	virtual void BeginPlay() override;
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										24
									
								
								CorruptedMemory/Source/CorruptedMemory/CM_PlayerState.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								CorruptedMemory/Source/CorruptedMemory/CM_PlayerState.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,24 @@
 | 
			
		||||
// Fill out your copyright notice in the Description page of Project Settings.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "CM_PlayerState.h"
 | 
			
		||||
 | 
			
		||||
#include "CMGameInstance.h"
 | 
			
		||||
#include "CM_GameState.h"
 | 
			
		||||
#include "CorruptedMemoryCharacter.h"
 | 
			
		||||
 | 
			
		||||
void ACM_PlayerState::ClientPlayerJoin_Implementation()
 | 
			
		||||
{
 | 
			
		||||
	if (GetWorld()->GetAuthGameMode()) return;
 | 
			
		||||
	const UCMGameInstance* GameInstance = Cast<UCMGameInstance>(GetWorld()->GetGameInstance());
 | 
			
		||||
 | 
			
		||||
	if (GetPlayerName() == GameInstance->AccountUsername) return;
 | 
			
		||||
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::White, FString::Printf(TEXT("Player %s Joined %s"), *GetPlayerName(), *FString::FromInt(GameInstance->PlayerIndex)));
 | 
			
		||||
	if (!IsValid(Cast<ACorruptedMemoryCharacter>(GetWorld()->GetFirstPlayerController()->GetCharacter())))
 | 
			
		||||
	{
 | 
			
		||||
		UE_LOG(LogTemp, Warning, TEXT("Invalid Character Queueing Server Request"));
 | 
			
		||||
		bServerRequestUserInformation = true;
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	Cast<ACorruptedMemoryCharacter>(GetWorld()->GetFirstPlayerController()->GetCharacter())->ServerPlayerJoin(GameInstance->AccountUsername, GameInstance->PlayerIndex, GetUniqueId());
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										23
									
								
								CorruptedMemory/Source/CorruptedMemory/CM_PlayerState.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								CorruptedMemory/Source/CorruptedMemory/CM_PlayerState.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,23 @@
 | 
			
		||||
// Fill out your copyright notice in the Description page of Project Settings.
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "CoreMinimal.h"
 | 
			
		||||
#include "GameFramework/PlayerState.h"
 | 
			
		||||
#include "CM_PlayerState.generated.h"
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 
 | 
			
		||||
 */
 | 
			
		||||
UCLASS()
 | 
			
		||||
class CORRUPTEDMEMORY_API ACM_PlayerState : public APlayerState
 | 
			
		||||
{
 | 
			
		||||
	GENERATED_BODY()
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
	UFUNCTION(Client, Reliable)
 | 
			
		||||
	void ClientPlayerJoin();
 | 
			
		||||
 | 
			
		||||
	UPROPERTY(BlueprintReadOnly)
 | 
			
		||||
	bool bServerRequestUserInformation = false;
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										33
									
								
								CorruptedMemory/Source/CorruptedMemory/CM_Shelving.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								CorruptedMemory/Source/CorruptedMemory/CM_Shelving.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,33 @@
 | 
			
		||||
// Fill out your copyright notice in the Description page of Project Settings.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "CM_Shelving.h"
 | 
			
		||||
 | 
			
		||||
#include "Net/UnrealNetwork.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Sets default values
 | 
			
		||||
ACM_Shelving::ACM_Shelving()
 | 
			
		||||
{
 | 
			
		||||
	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
 | 
			
		||||
	PrimaryActorTick.bCanEverTick = true;
 | 
			
		||||
	bReplicates = true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Called when the game starts or when spawned
 | 
			
		||||
void ACM_Shelving::BeginPlay()
 | 
			
		||||
{
 | 
			
		||||
	Super::BeginPlay();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Called every frame
 | 
			
		||||
void ACM_Shelving::Tick(float DeltaTime)
 | 
			
		||||
{
 | 
			
		||||
	Super::Tick(DeltaTime);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ACM_Shelving::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
 | 
			
		||||
{
 | 
			
		||||
	Super::GetLifetimeReplicatedProps(OutLifetimeProps);
 | 
			
		||||
	DOREPLIFETIME(ACM_Shelving, GameplayTags);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										29
									
								
								CorruptedMemory/Source/CorruptedMemory/CM_Shelving.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								CorruptedMemory/Source/CorruptedMemory/CM_Shelving.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,29 @@
 | 
			
		||||
// Fill out your copyright notice in the Description page of Project Settings.
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "CoreMinimal.h"
 | 
			
		||||
#include "GameFramework/Actor.h"
 | 
			
		||||
#include "CM_Shelving.generated.h"
 | 
			
		||||
 | 
			
		||||
UCLASS()
 | 
			
		||||
class CORRUPTEDMEMORY_API ACM_Shelving : public AActor
 | 
			
		||||
{
 | 
			
		||||
	GENERATED_BODY()
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
	// Sets default values for this actor's properties
 | 
			
		||||
	ACM_Shelving();
 | 
			
		||||
 | 
			
		||||
	UPROPERTY(Replicated, BlueprintReadOnly, VisibleAnywhere)
 | 
			
		||||
	TArray<FString> GameplayTags;
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
	// Called when the game starts or when spawned
 | 
			
		||||
	virtual void BeginPlay() override;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
	// Called every frame
 | 
			
		||||
	virtual void Tick(float DeltaTime) override;
 | 
			
		||||
	virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
 | 
			
		||||
};
 | 
			
		||||
@ -1,6 +1,9 @@
 | 
			
		||||
// Copyright Epic Games, Inc. All Rights Reserved.
 | 
			
		||||
 | 
			
		||||
#include "CorruptedMemoryCharacter.h"
 | 
			
		||||
 | 
			
		||||
#include "CMGameInstance.h"
 | 
			
		||||
#include "CM_GameState.h"
 | 
			
		||||
#include "CorruptedMemoryProjectile.h"
 | 
			
		||||
#include "Animation/AnimInstance.h"
 | 
			
		||||
#include "Camera/CameraComponent.h"
 | 
			
		||||
@ -34,7 +37,6 @@ ACorruptedMemoryCharacter::ACorruptedMemoryCharacter()
 | 
			
		||||
	Mesh1P->CastShadow = false;
 | 
			
		||||
	//Mesh1P->SetRelativeRotation(FRotator(0.9f, -19.19f, 5.2f));
 | 
			
		||||
	Mesh1P->SetRelativeLocation(FVector(-30.f, 0.f, -150.f));
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ACorruptedMemoryCharacter::BeginPlay()
 | 
			
		||||
@ -51,6 +53,14 @@ void ACorruptedMemoryCharacter::BeginPlay()
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (GetWorld()->GetAuthGameMode()) return;
 | 
			
		||||
	if (!IsValid(GetPlayerState<ACM_PlayerState>())) return;
 | 
			
		||||
	if (GetPlayerState<ACM_PlayerState>()->bServerRequestUserInformation)
 | 
			
		||||
	{
 | 
			
		||||
		GetPlayerState<ACM_PlayerState>()->bServerRequestUserInformation = false;
 | 
			
		||||
		const UCMGameInstance* GameInstance = Cast<UCMGameInstance>(GetWorld()->GetGameInstance());
 | 
			
		||||
		ServerPlayerJoin(GameInstance->AccountUsername, GameInstance->PlayerIndex, GetPlayerState<ACM_PlayerState>()->GetUniqueId());
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//////////////////////////////////////////////////////////////////////////// Input
 | 
			
		||||
@ -73,6 +83,12 @@ void ACorruptedMemoryCharacter::SetupPlayerInputComponent(class UInputComponent*
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void ACorruptedMemoryCharacter::LogServerMessage_Implementation(const FString& Message)
 | 
			
		||||
{
 | 
			
		||||
	if (GetWorld()->GetAuthGameMode()) return;
 | 
			
		||||
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, Message);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ACorruptedMemoryCharacter::Move(const FInputActionValue& Value)
 | 
			
		||||
{
 | 
			
		||||
	// input is a Vector2D
 | 
			
		||||
@ -108,3 +124,16 @@ bool ACorruptedMemoryCharacter::GetHasRifle()
 | 
			
		||||
{
 | 
			
		||||
	return bHasRifle;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ACorruptedMemoryCharacter::ServerPlayerJoin_Implementation(const FString& PlayerName, const int32& PlayerIndex, const FUniqueNetIdRepl& UNetID)
 | 
			
		||||
{
 | 
			
		||||
	if (!GetWorld()->GetAuthGameMode()) return;
 | 
			
		||||
	if (const auto PlayerStateObjPtr = Cast<ACM_GameState>(GetWorld()->GetGameState())->PlayerArray.FindByPredicate([&](const APlayerState* Player)
 | 
			
		||||
	{
 | 
			
		||||
		return Player->GetUniqueId() == UNetID;
 | 
			
		||||
	}))
 | 
			
		||||
	{
 | 
			
		||||
		PlayerStateObjPtr->Get()->SetPlayerName(PlayerName);
 | 
			
		||||
		PlayerStateObjPtr->Get()->SetPlayerId(PlayerIndex);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -5,6 +5,7 @@
 | 
			
		||||
#include "CoreMinimal.h"
 | 
			
		||||
#include "GameFramework/Character.h"
 | 
			
		||||
#include "InputActionValue.h"
 | 
			
		||||
#include "CM_PlayerState.h"
 | 
			
		||||
#include "CorruptedMemoryCharacter.generated.h"
 | 
			
		||||
 | 
			
		||||
class UInputComponent;
 | 
			
		||||
@ -64,6 +65,12 @@ public:
 | 
			
		||||
	UFUNCTION(BlueprintCallable, Category = Weapon)
 | 
			
		||||
	bool GetHasRifle();
 | 
			
		||||
 | 
			
		||||
	UFUNCTION(Server, Reliable)
 | 
			
		||||
	void ServerPlayerJoin(const FString& PlayerName, const int32& PlayerIndex, const FUniqueNetIdRepl& UNetID);
 | 
			
		||||
 | 
			
		||||
	UFUNCTION(Client, Reliable)
 | 
			
		||||
	void LogServerMessage(const FString& Message);
 | 
			
		||||
	
 | 
			
		||||
protected:
 | 
			
		||||
	/** Called for movement input */
 | 
			
		||||
	void Move(const FInputActionValue& Value);
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,15 @@
 | 
			
		||||
// Copyright Epic Games, Inc. All Rights Reserved.
 | 
			
		||||
 | 
			
		||||
#include "CorruptedMemoryGameMode.h"
 | 
			
		||||
 | 
			
		||||
#include "CMGameInstance.h"
 | 
			
		||||
#include "CM_GameState.h"
 | 
			
		||||
#include "CM_PlayerState.h"
 | 
			
		||||
#include "CorruptedMemoryCharacter.h"
 | 
			
		||||
#include "GameFramework/GameStateBase.h"
 | 
			
		||||
#include "GameFramework/PlayerStart.h"
 | 
			
		||||
#include "GameFramework/PlayerState.h"
 | 
			
		||||
#include "Kismet/GameplayStatics.h"
 | 
			
		||||
#include "UObject/ConstructorHelpers.h"
 | 
			
		||||
 | 
			
		||||
ACorruptedMemoryGameMode::ACorruptedMemoryGameMode()
 | 
			
		||||
@ -11,4 +19,50 @@ ACorruptedMemoryGameMode::ACorruptedMemoryGameMode()
 | 
			
		||||
	static ConstructorHelpers::FClassFinder<APawn> PlayerPawnClassFinder(TEXT("/Game/FirstPerson/Blueprints/BP_FirstPersonCharacter"));
 | 
			
		||||
	DefaultPawnClass = PlayerPawnClassFinder.Class;
 | 
			
		||||
 | 
			
		||||
	static ConstructorHelpers::FClassFinder<ACharacter> PlayerCharacterClassFinder(TEXT("/Game/FirstPerson/Blueprints/BP_FirstPersonCharacter"));
 | 
			
		||||
	PlayerCharacterClass = PlayerCharacterClassFinder.Class;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ACorruptedMemoryGameMode::PostLogin(APlayerController* NewPlayer)
 | 
			
		||||
{
 | 
			
		||||
	Super::PostLogin(NewPlayer);
 | 
			
		||||
	NewPlayer->GetPlayerState<ACM_PlayerState>()->ClientPlayerJoin();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ACorruptedMemoryGameMode::BeginPlay()
 | 
			
		||||
{
 | 
			
		||||
	Super::BeginPlay();
 | 
			
		||||
 | 
			
		||||
	FString MapName = GetWorld()->GetMapName();
 | 
			
		||||
	MapName.RemoveFromStart(GetWorld()->StreamingLevelsPrefix);
 | 
			
		||||
	if (MapName == "ClientEntry") return;
 | 
			
		||||
 | 
			
		||||
	//Gets all PlayerStart Actors and sorts them by PlayerStartTag
 | 
			
		||||
	TArray<AActor*> PlayerStartActors;
 | 
			
		||||
	UGameplayStatics::GetAllActorsOfClass(GetWorld(), APlayerStart::StaticClass(), PlayerStartActors);
 | 
			
		||||
	PlayerStartActors.Sort([](const AActor& A, const AActor& B) { return FCString::Atoi(*Cast<APlayerStart>(&A)->PlayerStartTag.ToString()) < FCString::Atoi(*Cast<APlayerStart>(&B)->PlayerStartTag.ToString()); });
 | 
			
		||||
	for (const AActor* PlayerStartActor : PlayerStartActors)
 | 
			
		||||
	{
 | 
			
		||||
		SpawnPoints.Add(PlayerStartActor->GetActorTransform());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	//Gets all store shelves in level
 | 
			
		||||
	TArray<AActor*> StoreShelves;
 | 
			
		||||
	UGameplayStatics::GetAllActorsWithTag(GetWorld(), "StoreShelf", StoreShelves);
 | 
			
		||||
	for (AActor* StoreShelf : StoreShelves)
 | 
			
		||||
	{
 | 
			
		||||
		Shelves.Add(Cast<ACM_Shelving>(StoreShelf));
 | 
			
		||||
	}
 | 
			
		||||
	Shelves[0]->GameplayTags.Add("Corrupted");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ACorruptedMemoryGameMode::ServerSpawnPlayer_Implementation(APlayerController* PlayerController)
 | 
			
		||||
{
 | 
			
		||||
	if (!IsValid(PlayerController)) return;
 | 
			
		||||
	if (IsValid(PlayerController->GetPawn()))
 | 
			
		||||
	{
 | 
			
		||||
		PlayerController->GetPawn()->Destroy();
 | 
			
		||||
	}
 | 
			
		||||
	ACharacter* SpawnedPlayerCharacter = GetWorld()->SpawnActor<ACharacter>(PlayerCharacterClass, SpawnPoints[PlayerController->GetPlayerState<ACM_PlayerState>()->GetPlayerId()]);
 | 
			
		||||
	PlayerController->Possess(SpawnedPlayerCharacter);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -3,6 +3,7 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "CoreMinimal.h"
 | 
			
		||||
#include "CM_Shelving.h"
 | 
			
		||||
#include "GameFramework/GameModeBase.h"
 | 
			
		||||
#include "CorruptedMemoryGameMode.generated.h"
 | 
			
		||||
 | 
			
		||||
@ -13,7 +14,20 @@ class ACorruptedMemoryGameMode : public AGameModeBase
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
	ACorruptedMemoryGameMode();
 | 
			
		||||
	virtual void PostLogin(APlayerController* NewPlayer) override;
 | 
			
		||||
 | 
			
		||||
	UFUNCTION(Server, Reliable)
 | 
			
		||||
	void ServerSpawnPlayer(APlayerController* PlayerController);
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
	virtual void BeginPlay() override;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	UPROPERTY(BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
 | 
			
		||||
	TArray<FTransform> SpawnPoints;
 | 
			
		||||
	UPROPERTY(BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
 | 
			
		||||
	TArray<ACM_Shelving*> Shelves;
 | 
			
		||||
 | 
			
		||||
	TSubclassOf<ACharacter> PlayerCharacterClass;
 | 
			
		||||
	
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user