Fix local player joining system

This commit is contained in:
Kevin Poretti 2023-01-10 21:55:48 -05:00
parent 707804bf54
commit bde7b3bfd7
22 changed files with 97 additions and 23 deletions

View File

@ -7,3 +7,5 @@ bReplaceBlueprintWithClass= true
bDontLoadBlueprintOutsideEditor= true
bBlueprintIsNotBlueprintType= true
[/Script/AdvancedPreviewScene.SharedProfiles]

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
GravityStomp/Content/Maps/Debug/Test.umap (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -10,12 +10,16 @@
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
#include "GSCharacterMovementComponent.h"
#include "GameFramework/PlayerState.h"
#include "Kismet/KismetMathLibrary.h"
#include "Player/GSPlayerState.h"
//////////////////////////////////////////////////////////////////////////
// AGravityStompCharacter
class AGSPlayerState;
AGSCharacter::AGSCharacter(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer.SetDefaultSubobjectClass<UGSCharacterMovementComponent>(ACharacter::CharacterMovementComponentName))
{
@ -46,6 +50,16 @@ AGSCharacter::AGSCharacter(const FObjectInitializer& ObjectInitializer)
void AGSCharacter::ChangeTeamColor(bool bIsPlayerFriendly)
{
int32 TeamNum = GetPlayerState<AGSPlayerState>()->GetTeamNum();
// invalid team num
if(TeamNum < 0 || TeamNum >= PlayerMaterials.Num())
{
return;
}
GetMesh()->SetMaterial(0, PlayerMaterials[TeamNum].TorsoMaterial);
GetMesh()->SetMaterial(1, PlayerMaterials[TeamNum].HeadLegsMaterial);
}
@ -132,3 +146,8 @@ void AGSCharacter::PawnClientRestart()
}
}
}
void AGSCharacter::PossessedBy(AController* NewController)
{
Super::PossessedBy(NewController);
}

View File

@ -7,6 +7,17 @@
#include "InputActionValue.h"
#include "GSCharacter.generated.h"
USTRUCT(BlueprintType)
struct FPlayerMaterial
{
GENERATED_BODY()
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)
UMaterialInstance* TorsoMaterial;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)
UMaterialInstance* HeadLegsMaterial;
};
UCLASS(config=Game)
class AGSCharacter : public ACharacter
@ -24,6 +35,9 @@ class AGSCharacter : public ACharacter
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
class UInputAction* ChangeGravityAction;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Player Materials", meta = (AllowPrivateAccess = "true"))
TArray<FPlayerMaterial> PlayerMaterials;
public:
AGSCharacter(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());
@ -40,6 +54,8 @@ protected:
public:
virtual void PawnClientRestart() override;
virtual void PossessedBy(AController* NewController) override;
protected:
// APawn interface
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;

View File

@ -113,6 +113,7 @@ bool AGSGameModeBase::CanDamagePlayer(AGSPlayerController* Damager, AGSPlayerCon
void AGSGameModeBase::PickTeam(AGSPlayerState* PlayerState)
{
/*
// place player on the team with the fewest players, or on the first team if all teams have the same number of players
TArray<int32> NumTeamPlayers;
AGSGameState* GS = GetGameState<AGSGameState>();
@ -141,8 +142,9 @@ void AGSGameModeBase::PickTeam(AGSPlayerState* PlayerState)
LowestTeamIdx = TeamIdx;
}
}
*/
PlayerState->SetTeamNum(LowestTeamIdx);
PlayerState->SetTeamNum(PlayerState->GetPlayerController()->GetLocalPlayer()->GetControllerId());
}

View File

@ -2,10 +2,11 @@
#include "Player/GSPlayerController.h"
// GS includes
#include "GSPlayerState.h"
void AGSPlayerController::Client_GameStarted_Implementation()
{
FInputModeGameOnly GameOnly;
SetInputMode(GameOnly);
SetIgnoreMoveInput(false);
// enable all actions on pawn
@ -64,6 +65,8 @@ void AGSPlayerController::UnFreeze()
void AGSPlayerController::AcknowledgePossession(APawn* P)
{
GetPlayerState<AGSPlayerState>()->UpdateTeamColor();
OnAcknowledgePossession();
Super::AcknowledgePossession(P);

View File

@ -26,6 +26,13 @@ void AGSPlayerState::SetTeamNum(int32 InTeamNum)
void AGSPlayerState::UpdateTeamColor()
{
AGSCharacter* Char = GetPawn<AGSCharacter>();
if(Char)
{
Char->ChangeTeamColor(false);
}
/*
AGSPlayerState* LocalPS = GetWorld()->GetFirstPlayerController()->GetPlayerState<AGSPlayerState>();
// if this player state belongs to us then we need to update all other characters
// rendering of team will essentially flip (all enemies are now rendered as friendly and vice versa)
@ -49,9 +56,10 @@ void AGSPlayerState::UpdateTeamColor()
AGSCharacter* Char = GetPawn<AGSCharacter>();
if(Char && LocalPS)
{
Char->ChangeTeamColor(IsPlayerFriendly(LocalPS));
}
}
*/
}

View File

@ -24,6 +24,11 @@ public:
void SetTeamNum(int32 InTeamNum);
/**
* Changes how this player is rendered depending on their team number
*/
void UpdateTeamColor();
UFUNCTION(BlueprintPure)
FORCEINLINE int32 GetNumKills() const { return NumKills; }
@ -65,9 +70,4 @@ protected:
UFUNCTION()
void OnRep_TeamNum();
/**
* Changes how this player is rendered to a client
*/
void UpdateTeamColor();
};