Update Player Character for Base Scanning Function
This commit is contained in:
parent
24c09c1ff1
commit
2515ce4e9c
@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:c3384b0ef9ac9102b4073bc0793ca6fe17e0874a220fe4bb55a21c0d2604c028
|
||||
oid sha256:682634b96166cdd01fa16451402719e5e849c8cf7e5f4e8e3511d57a5decbb13
|
||||
size 42197
|
||||
|
@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:176aa0e3af0cb53206b368ca8493438efd106cf7275ee80c5808c70421dc255f
|
||||
oid sha256:52a5259efe0a304bf08cdbf35cf509dab18fa2dae3ac9da963b6d36d4686bda2
|
||||
size 901607
|
||||
|
3
CorruptedMemory/Content/UI/BP_GameUI.uasset
Normal file
3
CorruptedMemory/Content/UI/BP_GameUI.uasset
Normal file
@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:44c850bde4cbd5839a09e56aa98661c6ed81aae05e343a32f9462d57483e0d2e
|
||||
size 167096
|
@ -5,6 +5,12 @@
|
||||
|
||||
#include "CorruptedMemoryGameMode.h"
|
||||
|
||||
void ACM_PlayerController::ServerAddGameplayTagToShelf_Implementation(AActor* Shelving, const FString& GameplayTag)
|
||||
{
|
||||
if (!GetWorld()->GetAuthGameMode()) return;
|
||||
Cast<ACorruptedMemoryGameMode>(GetWorld()->GetAuthGameMode())->AddGameplayTagToShelf(Shelving, GameplayTag);
|
||||
}
|
||||
|
||||
void ACM_PlayerController::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
@ -14,6 +14,10 @@ class CORRUPTEDMEMORY_API ACM_PlayerController : public APlayerController
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UFUNCTION(Server, Reliable)
|
||||
void ServerAddGameplayTagToShelf(AActor* Shelving, const FString& GameplayTag);
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
};
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
#include "CMGameInstance.h"
|
||||
#include "CM_GameState.h"
|
||||
#include "CM_PlayerController.h"
|
||||
#include "CM_Shelving.h"
|
||||
#include "CorruptedMemoryProjectile.h"
|
||||
#include "Animation/AnimInstance.h"
|
||||
#include "Camera/CameraComponent.h"
|
||||
@ -30,13 +32,14 @@ ACorruptedMemoryCharacter::ACorruptedMemoryCharacter()
|
||||
FirstPersonCameraComponent->bUsePawnControlRotation = true;
|
||||
|
||||
// Create a mesh component that will be used when being viewed from a '1st person' view (when controlling this pawn)
|
||||
Mesh1P = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("CharacterMesh1P"));
|
||||
Mesh1P->SetOnlyOwnerSee(true);
|
||||
Mesh1P->SetupAttachment(FirstPersonCameraComponent);
|
||||
Mesh1P->bCastDynamicShadow = false;
|
||||
Mesh1P->CastShadow = false;
|
||||
//Mesh1P->SetRelativeRotation(FRotator(0.9f, -19.19f, 5.2f));
|
||||
Mesh1P->SetRelativeLocation(FVector(-30.f, 0.f, -150.f));
|
||||
// Mesh1P = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("CharacterMesh1P"));
|
||||
// Mesh1P->SetOnlyOwnerSee(true);
|
||||
// Mesh1P->SetupAttachment(FirstPersonCameraComponent);
|
||||
// Mesh1P->bCastDynamicShadow = false;
|
||||
// Mesh1P->CastShadow = false;
|
||||
// //Mesh1P->SetRelativeRotation(FRotator(0.9f, -19.19f, 5.2f));
|
||||
// Mesh1P->SetRelativeLocation(FVector(-30.f, 0.f, -150.f));
|
||||
bReplicates = true;
|
||||
}
|
||||
|
||||
void ACorruptedMemoryCharacter::BeginPlay()
|
||||
@ -79,6 +82,10 @@ void ACorruptedMemoryCharacter::SetupPlayerInputComponent(class UInputComponent*
|
||||
|
||||
//Looking
|
||||
EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &ACorruptedMemoryCharacter::Look);
|
||||
|
||||
//Scanning
|
||||
EnhancedInputComponent->BindAction(ScanAction, ETriggerEvent::Started, this, &ACorruptedMemoryCharacter::ScanStart);
|
||||
EnhancedInputComponent->BindAction(ScanAction, ETriggerEvent::Canceled, this, &ACorruptedMemoryCharacter::ScanCancel);
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,6 +96,24 @@ void ACorruptedMemoryCharacter::LogServerMessage_Implementation(const FString& M
|
||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, Message);
|
||||
}
|
||||
|
||||
void ACorruptedMemoryCharacter::Client_EnableUserInput_Implementation()
|
||||
{
|
||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("EnableUserInput_Implementation"));
|
||||
EnableInput(GetWorld()->GetFirstPlayerController());
|
||||
GetWorld()->GetFirstPlayerController()->SetInputMode(FInputModeGameOnly());
|
||||
}
|
||||
|
||||
void ACorruptedMemoryCharacter::Client_DisableUserInput_Implementation()
|
||||
{
|
||||
DisableInput(GetWorld()->GetFirstPlayerController());
|
||||
GetWorld()->GetFirstPlayerController()->SetInputMode(FInputModeUIOnly());
|
||||
}
|
||||
|
||||
void ACorruptedMemoryCharacter::Client_GameStart_Implementation()
|
||||
{
|
||||
OnGameStart.Broadcast();
|
||||
}
|
||||
|
||||
void ACorruptedMemoryCharacter::Move(const FInputActionValue& Value)
|
||||
{
|
||||
// input is a Vector2D
|
||||
@ -115,6 +140,33 @@ void ACorruptedMemoryCharacter::Look(const FInputActionValue& Value)
|
||||
}
|
||||
}
|
||||
|
||||
void ACorruptedMemoryCharacter::ScanStart(const FInputActionValue& Value)
|
||||
{
|
||||
//Line trace to see if there is a shelf in front of the player
|
||||
FHitResult HitResult;
|
||||
FVector StartLocation = FirstPersonCameraComponent->GetComponentLocation();
|
||||
FVector EndLocation = StartLocation + (FirstPersonCameraComponent->GetForwardVector() * 1000.f);
|
||||
FCollisionQueryParams TraceParams;
|
||||
TraceParams.AddIgnoredActor(this);
|
||||
TraceParams.AddIgnoredActor(GetOwner());
|
||||
TraceParams.bTraceComplex = true;
|
||||
TraceParams.bReturnPhysicalMaterial = false;
|
||||
GetWorld()->LineTraceSingleByChannel(HitResult, StartLocation, EndLocation, ECC_Visibility, TraceParams);
|
||||
|
||||
if (!IsValid(HitResult.GetActor())) return;
|
||||
if (HitResult.GetActor()->Tags.Contains("StoreShelf"))
|
||||
{
|
||||
FString AccountName = Cast<UCMGameInstance>(GetWorld()->GetGameInstance())->AccountUsername;
|
||||
if (Cast<ACM_Shelving>(HitResult.GetActor())->GameplayTags.Contains(AccountName)) return;
|
||||
Cast<ACM_PlayerController>(GetWorld()->GetFirstPlayerController())->ServerAddGameplayTagToShelf(HitResult.GetActor(), AccountName);
|
||||
ServerSuccessfulScan(AccountName);
|
||||
}
|
||||
}
|
||||
|
||||
void ACorruptedMemoryCharacter::ScanCancel(const FInputActionValue& Value)
|
||||
{
|
||||
}
|
||||
|
||||
void ACorruptedMemoryCharacter::SetHasRifle(bool bNewHasRifle)
|
||||
{
|
||||
bHasRifle = bNewHasRifle;
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "GameFramework/Character.h"
|
||||
#include "InputActionValue.h"
|
||||
#include "CM_PlayerState.h"
|
||||
#include "CorruptedMemoryGameMode.h"
|
||||
#include "CorruptedMemoryCharacter.generated.h"
|
||||
|
||||
class UInputComponent;
|
||||
@ -20,9 +21,17 @@ class ACorruptedMemoryCharacter : public ACharacter
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
/** Pawn mesh: 1st person view (arms; seen only by self) */
|
||||
UPROPERTY(VisibleDefaultsOnly, Category=Mesh)
|
||||
USkeletalMeshComponent* Mesh1P;
|
||||
// /** Pawn mesh: 1st person view (arms; seen only by self) */
|
||||
// UPROPERTY(VisibleDefaultsOnly, Category=Mesh)
|
||||
// USkeletalMeshComponent* Mesh1P;
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnGameStart);
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnGameEnd);
|
||||
|
||||
UPROPERTY(BlueprintAssignable, Category = "Game")
|
||||
FOnGameStart OnGameStart;
|
||||
UPROPERTY(BlueprintAssignable, Category = "Game")
|
||||
FOnGameEnd OnGameEnd;
|
||||
|
||||
/** First person camera */
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
|
||||
@ -40,6 +49,8 @@ class ACorruptedMemoryCharacter : public ACharacter
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true"))
|
||||
class UInputAction* MoveAction;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true"))
|
||||
UInputAction* ScanAction;
|
||||
|
||||
public:
|
||||
ACorruptedMemoryCharacter();
|
||||
@ -48,7 +59,6 @@ protected:
|
||||
virtual void BeginPlay();
|
||||
|
||||
public:
|
||||
|
||||
/** Look Input Action */
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
|
||||
class UInputAction* LookAction;
|
||||
@ -67,10 +77,21 @@ public:
|
||||
|
||||
UFUNCTION(Server, Reliable)
|
||||
void ServerPlayerJoin(const FString& PlayerName, const int32& PlayerIndex, const FUniqueNetIdRepl& UNetID);
|
||||
UFUNCTION(Server, Reliable)
|
||||
void ServerSuccessfulScan(const FString& Username);
|
||||
|
||||
|
||||
UFUNCTION(Client, Reliable)
|
||||
void LogServerMessage(const FString& Message);
|
||||
|
||||
UFUNCTION(Client, Reliable)
|
||||
void Client_EnableUserInput();
|
||||
UFUNCTION(Client, Reliable)
|
||||
void Client_DisableUserInput();
|
||||
|
||||
UFUNCTION(Client, Reliable)
|
||||
void Client_GameStart();
|
||||
|
||||
protected:
|
||||
/** Called for movement input */
|
||||
void Move(const FInputActionValue& Value);
|
||||
@ -78,6 +99,9 @@ protected:
|
||||
/** Called for looking input */
|
||||
void Look(const FInputActionValue& Value);
|
||||
|
||||
void ScanStart(const FInputActionValue& Value);
|
||||
void ScanCancel(const FInputActionValue& Value);
|
||||
|
||||
protected:
|
||||
// APawn interface
|
||||
virtual void SetupPlayerInputComponent(UInputComponent* InputComponent) override;
|
||||
@ -85,10 +109,15 @@ protected:
|
||||
|
||||
public:
|
||||
/** Returns Mesh1P subobject **/
|
||||
USkeletalMeshComponent* GetMesh1P() const { return Mesh1P; }
|
||||
// USkeletalMeshComponent* GetMesh1P() const { return Mesh1P; }
|
||||
/** Returns FirstPersonCameraComponent subobject **/
|
||||
UCameraComponent* GetFirstPersonCameraComponent() const { return FirstPersonCameraComponent; }
|
||||
|
||||
|
||||
};
|
||||
|
||||
inline void ACorruptedMemoryCharacter::ServerSuccessfulScan_Implementation(const FString& Username)
|
||||
{
|
||||
if (const ACorruptedMemoryGameMode* GameMode = Cast<ACorruptedMemoryGameMode>(GetWorld()->GetAuthGameMode()))
|
||||
{
|
||||
GameMode->SuccessfulScan(Username);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "CMGameInstance.h"
|
||||
#include "CM_GameState.h"
|
||||
#include "CM_PlayerController.h"
|
||||
#include "CM_PlayerState.h"
|
||||
#include "CorruptedMemoryCharacter.h"
|
||||
#include "GameFramework/GameStateBase.h"
|
||||
@ -27,6 +28,36 @@ void ACorruptedMemoryGameMode::PostLogin(APlayerController* NewPlayer)
|
||||
{
|
||||
Super::PostLogin(NewPlayer);
|
||||
NewPlayer->GetPlayerState<ACM_PlayerState>()->ClientPlayerJoin();
|
||||
FString MaxPlayers;
|
||||
FParse::Value(FCommandLine::Get(), TEXT("maxPlayers="), MaxPlayers);
|
||||
if (GetWorld()->GetGameState()->PlayerArray.Num() == FCString::Atoi(*MaxPlayers))
|
||||
{
|
||||
auto World = GetWorld();
|
||||
FTimerHandle TimerHandle;
|
||||
GetWorld()->GetTimerManager().SetTimer(TimerHandle, [World]()
|
||||
{
|
||||
for (const auto PlayerState : World->GetGameState()->PlayerArray)
|
||||
{
|
||||
Cast<ACorruptedMemoryCharacter>(PlayerState->GetPlayerController()->GetCharacter())->Client_GameStart();
|
||||
Cast<ACorruptedMemoryCharacter>(PlayerState->GetPlayerController()->GetCharacter())->Client_EnableUserInput();
|
||||
PlayerState->GetPlayerController()->EnableInput(PlayerState->GetPlayerController());
|
||||
PlayerState->GetPlayerController()->SetInputMode(FInputModeGameOnly());
|
||||
}
|
||||
}, 5.f, false);
|
||||
}
|
||||
}
|
||||
|
||||
void ACorruptedMemoryGameMode::SuccessfulScan(const FString& Username) const
|
||||
{
|
||||
ACM_GameState* CurrentGameState = GetWorld()->GetGameState<ACM_GameState>();
|
||||
const auto PlayerState = CurrentGameState->PlayerArray.FindByPredicate([Username](const APlayerState* PlayerState) { return PlayerState->GetPlayerName() == Username; });
|
||||
PlayerState->Get()->SetScore(PlayerState->Get()->GetScore() + SuccessfulScanScore);
|
||||
}
|
||||
|
||||
void ACorruptedMemoryGameMode::AddGameplayTagToShelf(AActor* Shelving, const FString& GameplayTag)
|
||||
{
|
||||
ACM_Shelving** FoundShelf = Shelves.FindByPredicate([Shelving](const ACM_Shelving* Shelf) { return Shelf == Shelving; });
|
||||
(*FoundShelf)->GameplayTags.Add(GameplayTag);
|
||||
}
|
||||
|
||||
void ACorruptedMemoryGameMode::BeginPlay()
|
||||
@ -65,4 +96,6 @@ void ACorruptedMemoryGameMode::ServerSpawnPlayer_Implementation(APlayerControlle
|
||||
}
|
||||
ACharacter* SpawnedPlayerCharacter = GetWorld()->SpawnActor<ACharacter>(PlayerCharacterClass, SpawnPoints[PlayerController->GetPlayerState<ACM_PlayerState>()->GetPlayerId()]);
|
||||
PlayerController->Possess(SpawnedPlayerCharacter);
|
||||
PlayerController->EnableInput(PlayerController);
|
||||
PlayerController->SetInputMode(FInputModeGameOnly());
|
||||
}
|
||||
|
@ -14,11 +14,19 @@ class ACorruptedMemoryGameMode : public AGameModeBase
|
||||
|
||||
public:
|
||||
ACorruptedMemoryGameMode();
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Game")
|
||||
int SuccessfulScanScore = 10;
|
||||
|
||||
virtual void PostLogin(APlayerController* NewPlayer) override;
|
||||
|
||||
UFUNCTION(Server, Reliable)
|
||||
void ServerSpawnPlayer(APlayerController* PlayerController);
|
||||
|
||||
void SuccessfulScan(const FString& Username) const;
|
||||
|
||||
void AddGameplayTagToShelf(AActor* Shelving, const FString& GameplayTag);
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
@ -29,5 +37,4 @@ private:
|
||||
TArray<ACM_Shelving*> Shelves;
|
||||
|
||||
TSubclassOf<ACharacter> PlayerCharacterClass;
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user