diff --git a/CorruptedMemory/Content/BP_StoreShelf.uasset b/CorruptedMemory/Content/BP_StoreShelf.uasset index 10f2adc..6d1f85d 100644 --- a/CorruptedMemory/Content/BP_StoreShelf.uasset +++ b/CorruptedMemory/Content/BP_StoreShelf.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5a1f6f15d2bcd70e7fde7988ed7890d1048dcb13dbd3aa3d53da77443b0cd6bc -size 30219 +oid sha256:47dc808db14facea8876051f2e5016aa9c95429125f3019438f3376d09b35f93 +size 96910 diff --git a/CorruptedMemory/Content/FirstPerson/Input/Actions/IA_Scan.uasset b/CorruptedMemory/Content/FirstPerson/Input/Actions/IA_Scan.uasset index ca05107..3c9427f 100644 --- a/CorruptedMemory/Content/FirstPerson/Input/Actions/IA_Scan.uasset +++ b/CorruptedMemory/Content/FirstPerson/Input/Actions/IA_Scan.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:236fdc7d14693ecf2fb25624688a0b2908bb09270711f8b6fc2b7b8c6757e535 +oid sha256:dc88db6854323011d6107ea886e3ee86370db0d90c6b33b8fad5e5f0991c26a1 size 1314 diff --git a/CorruptedMemory/Content/Levels/ClientEntry.umap b/CorruptedMemory/Content/Levels/ClientEntry.umap index b539e2d..ebd6c5b 100644 --- a/CorruptedMemory/Content/Levels/ClientEntry.umap +++ b/CorruptedMemory/Content/Levels/ClientEntry.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:682634b96166cdd01fa16451402719e5e849c8cf7e5f4e8e3511d57a5decbb13 +oid sha256:08a4c6ca66b77dd6b728ee8b25d74f217d04f5fe1e94ce1c803b9695c9aa609a size 42197 diff --git a/CorruptedMemory/Content/Levels/Main.umap b/CorruptedMemory/Content/Levels/Main.umap index 9ea80a1..6574d5f 100644 --- a/CorruptedMemory/Content/Levels/Main.umap +++ b/CorruptedMemory/Content/Levels/Main.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:52a5259efe0a304bf08cdbf35cf509dab18fa2dae3ac9da963b6d36d4686bda2 +oid sha256:0c445854b6a33eda4b2c8c64d91edf4b2252d5111172e30ebe5f487d55833b84 size 901607 diff --git a/CorruptedMemory/Content/UI/BP_GameUI.uasset b/CorruptedMemory/Content/UI/BP_GameUI.uasset index 1ece487..a4ea88a 100644 --- a/CorruptedMemory/Content/UI/BP_GameUI.uasset +++ b/CorruptedMemory/Content/UI/BP_GameUI.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:44c850bde4cbd5839a09e56aa98661c6ed81aae05e343a32f9462d57483e0d2e -size 167096 +oid sha256:02e1749ca55828e1feac698dfe6f0ab7d10023eb4b4eed13b5ea3319252b5992 +size 241078 diff --git a/CorruptedMemory/Content/UI/M_Outline.uasset b/CorruptedMemory/Content/UI/M_Outline.uasset new file mode 100644 index 0000000..edf87b4 --- /dev/null +++ b/CorruptedMemory/Content/UI/M_Outline.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1fa801bf93520e4d0024f16826cb304fcbc2cc05f94402d3d77cd0e719e0bea2 +size 9235 diff --git a/CorruptedMemory/Content/UI/M_OutlineBase.uasset b/CorruptedMemory/Content/UI/M_OutlineBase.uasset new file mode 100644 index 0000000..3719be8 --- /dev/null +++ b/CorruptedMemory/Content/UI/M_OutlineBase.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2bc9b512a543956e9540c5bb3bd294cf4139e2ac8ff71e4019e06b9b21e1d4eb +size 10138 diff --git a/CorruptedMemory/Source/CorruptedMemory/CMGameInstance.cpp b/CorruptedMemory/Source/CorruptedMemory/CMGameInstance.cpp index 3fe0b86..a7d6995 100644 --- a/CorruptedMemory/Source/CorruptedMemory/CMGameInstance.cpp +++ b/CorruptedMemory/Source/CorruptedMemory/CMGameInstance.cpp @@ -139,6 +139,16 @@ void UCMGameInstance::StartGame() } } +void UCMGameInstance::CloseServer(const FString& LobbyID) +{ + const auto Request = FHttpModule::Get().CreateRequest(); + Request->SetURL(LobbyAPI + "/lobbies/" + LobbyID); + Request->SetVerb("DELETE"); + Request->SetHeader("Authorization", "Bearer " + JwtToken); + Request->SetHeader("Accept", "application/json"); + Request->ProcessRequest(); +} + void UCMGameInstance::Init() { Super::Init(); diff --git a/CorruptedMemory/Source/CorruptedMemory/CMGameInstance.h b/CorruptedMemory/Source/CorruptedMemory/CMGameInstance.h index f99dee2..5d18682 100644 --- a/CorruptedMemory/Source/CorruptedMemory/CMGameInstance.h +++ b/CorruptedMemory/Source/CorruptedMemory/CMGameInstance.h @@ -115,6 +115,8 @@ public: void UnReady(); UFUNCTION(BlueprintCallable, Category = "Lobby") void StartGame(); + UFUNCTION(BlueprintCallable, Category = "Server") + void CloseServer(const FString& LobbyID); virtual void Init() override; diff --git a/CorruptedMemory/Source/CorruptedMemory/CM_PlayerController.cpp b/CorruptedMemory/Source/CorruptedMemory/CM_PlayerController.cpp index 174c421..8c4c318 100644 --- a/CorruptedMemory/Source/CorruptedMemory/CM_PlayerController.cpp +++ b/CorruptedMemory/Source/CorruptedMemory/CM_PlayerController.cpp @@ -11,6 +11,12 @@ void ACM_PlayerController::ServerAddGameplayTagToShelf_Implementation(AActor* Sh Cast(GetWorld()->GetAuthGameMode())->AddGameplayTagToShelf(Shelving, GameplayTag); } +void ACM_PlayerController::ServerRemoveGameplayTagToShelf_Implementation(AActor* Shelving, const FString& GameplayTag) +{ + if (!GetWorld()->GetAuthGameMode()) return; + Cast(GetWorld()->GetAuthGameMode())->RemoveGameplayTagToShelf(Shelving, GameplayTag); +} + void ACM_PlayerController::BeginPlay() { Super::BeginPlay(); diff --git a/CorruptedMemory/Source/CorruptedMemory/CM_PlayerController.h b/CorruptedMemory/Source/CorruptedMemory/CM_PlayerController.h index 1c03b70..0e7a4be 100644 --- a/CorruptedMemory/Source/CorruptedMemory/CM_PlayerController.h +++ b/CorruptedMemory/Source/CorruptedMemory/CM_PlayerController.h @@ -17,6 +17,8 @@ class CORRUPTEDMEMORY_API ACM_PlayerController : public APlayerController public: UFUNCTION(Server, Reliable) void ServerAddGameplayTagToShelf(AActor* Shelving, const FString& GameplayTag); + UFUNCTION(Server, Reliable) + void ServerRemoveGameplayTagToShelf(AActor* Shelving, const FString& GameplayTag); protected: virtual void BeginPlay() override; diff --git a/CorruptedMemory/Source/CorruptedMemory/CM_Shelving.cpp b/CorruptedMemory/Source/CorruptedMemory/CM_Shelving.cpp index 79fee10..b1e56fb 100644 --- a/CorruptedMemory/Source/CorruptedMemory/CM_Shelving.cpp +++ b/CorruptedMemory/Source/CorruptedMemory/CM_Shelving.cpp @@ -14,6 +14,18 @@ ACM_Shelving::ACM_Shelving() bReplicates = true; } +void ACM_Shelving::GameplayTagAdded() +{ + if (GameplayTags.Contains("Corrupted")) + { + Corrupted(); + } + if (GameplayTags.Contains("Scanned")) + { + Scanned(); + } +} + // Called when the game starts or when spawned void ACM_Shelving::BeginPlay() { diff --git a/CorruptedMemory/Source/CorruptedMemory/CM_Shelving.h b/CorruptedMemory/Source/CorruptedMemory/CM_Shelving.h index f92c5ce..ff6972a 100644 --- a/CorruptedMemory/Source/CorruptedMemory/CM_Shelving.h +++ b/CorruptedMemory/Source/CorruptedMemory/CM_Shelving.h @@ -15,8 +15,15 @@ public: // Sets default values for this actor's properties ACM_Shelving(); - UPROPERTY(Replicated, BlueprintReadOnly, VisibleAnywhere) + UPROPERTY(ReplicatedUsing=GameplayTagAdded, BlueprintReadOnly, VisibleAnywhere) TArray GameplayTags; + UFUNCTION(BlueprintImplementableEvent) + void Corrupted(); + UFUNCTION(BlueprintImplementableEvent) + void Scanned(); + + UFUNCTION() + void GameplayTagAdded(); protected: // Called when the game starts or when spawned diff --git a/CorruptedMemory/Source/CorruptedMemory/CorruptedMemoryCharacter.cpp b/CorruptedMemory/Source/CorruptedMemory/CorruptedMemoryCharacter.cpp index db1fa09..52b4b84 100644 --- a/CorruptedMemory/Source/CorruptedMemory/CorruptedMemoryCharacter.cpp +++ b/CorruptedMemory/Source/CorruptedMemory/CorruptedMemoryCharacter.cpp @@ -40,6 +40,7 @@ ACorruptedMemoryCharacter::ACorruptedMemoryCharacter() // //Mesh1P->SetRelativeRotation(FRotator(0.9f, -19.19f, 5.2f)); // Mesh1P->SetRelativeLocation(FVector(-30.f, 0.f, -150.f)); bReplicates = true; + PrimaryActorTick.bCanEverTick = true; } void ACorruptedMemoryCharacter::BeginPlay() @@ -85,10 +86,17 @@ void ACorruptedMemoryCharacter::SetupPlayerInputComponent(class UInputComponent* //Scanning EnhancedInputComponent->BindAction(ScanAction, ETriggerEvent::Started, this, &ACorruptedMemoryCharacter::ScanStart); - EnhancedInputComponent->BindAction(ScanAction, ETriggerEvent::Canceled, this, &ACorruptedMemoryCharacter::ScanCancel); + EnhancedInputComponent->BindAction(ScanAction, ETriggerEvent::Completed, this, &ACorruptedMemoryCharacter::ScanCancel); } } +void ACorruptedMemoryCharacter::Tick(float DeltaSeconds) +{ + Super::Tick(DeltaSeconds); + //Get the current scan percentage based on the timer elapsed and scan time + ScanPercentage = GetWorldTimerManager().GetTimerElapsed(ScanTimerHandle) / ScanTime; +} + void ACorruptedMemoryCharacter::LogServerMessage_Implementation(const FString& Message) { @@ -114,6 +122,16 @@ void ACorruptedMemoryCharacter::Client_GameStart_Implementation() OnGameStart.Broadcast(); } +void ACorruptedMemoryCharacter::Client_GameEnd_Implementation() +{ + OnGameEnd.Broadcast(); + FTimerHandle TimerHandle; + GetWorld()->GetTimerManager().SetTimer(TimerHandle, [this]() + { + Cast(GetWorld()->GetGameInstance())->CloseServer(Cast(GetWorld()->GetGameInstance())->JoinedLobbyID); + }, 10, false); +} + void ACorruptedMemoryCharacter::Move(const FInputActionValue& Value) { // input is a Vector2D @@ -154,17 +172,37 @@ void ACorruptedMemoryCharacter::ScanStart(const FInputActionValue& Value) GetWorld()->LineTraceSingleByChannel(HitResult, StartLocation, EndLocation, ECC_Visibility, TraceParams); if (!IsValid(HitResult.GetActor())) return; - if (HitResult.GetActor()->Tags.Contains("StoreShelf")) + if (HitResult.GetActor()->Tags.Contains("StoreShelf") && Cast(HitResult.GetActor())->GameplayTags.Contains("Corrupted")) { + //LastScannedShelf = Cast(HitResult.GetActor()); FString AccountName = Cast(GetWorld()->GetGameInstance())->AccountUsername; - if (Cast(HitResult.GetActor())->GameplayTags.Contains(AccountName)) return; - Cast(GetWorld()->GetFirstPlayerController())->ServerAddGameplayTagToShelf(HitResult.GetActor(), AccountName); - ServerSuccessfulScan(AccountName); + //if (Cast(HitResult.GetActor())->GameplayTags.Contains(AccountName)) return; + //Cast(GetWorld()->GetFirstPlayerController())->ServerAddGameplayTagToShelf(HitResult.GetActor(), AccountName); + if (GetWorldTimerManager().TimerExists(ScanTimerHandle)) + { + GetWorldTimerManager().ClearTimer(ScanTimerHandle); + ScanPercentage = 0.f; + } + GetWorld()->GetTimerManager().SetTimer(ScanTimerHandle, [this, AccountName, HitResult]() + { + if (Cast(HitResult.GetActor())->GameplayTags.Contains("Scanned")) return; + Cast(GetWorld()->GetFirstPlayerController())->ServerAddGameplayTagToShelf(HitResult.GetActor(), "Scanned"); + ServerSuccessfulScan(AccountName); + LastScannedShelf = nullptr; + }, 3.f, false); } } void ACorruptedMemoryCharacter::ScanCancel(const FInputActionValue& Value) { + const FString AccountName = Cast(GetWorld()->GetGameInstance())->AccountUsername; + GetWorldTimerManager().ClearTimer(ScanTimerHandle); + ScanPercentage = 0.f; + // if (IsValid(LastScannedShelf)) + // { + // LastScannedShelf = nullptr; + // Cast(GetWorld()->GetFirstPlayerController())->ServerRemoveGameplayTagToShelf(LastScannedShelf, AccountName); + // } } void ACorruptedMemoryCharacter::SetHasRifle(bool bNewHasRifle) diff --git a/CorruptedMemory/Source/CorruptedMemory/CorruptedMemoryCharacter.h b/CorruptedMemory/Source/CorruptedMemory/CorruptedMemoryCharacter.h index bc47616..b2b7040 100644 --- a/CorruptedMemory/Source/CorruptedMemory/CorruptedMemoryCharacter.h +++ b/CorruptedMemory/Source/CorruptedMemory/CorruptedMemoryCharacter.h @@ -79,8 +79,8 @@ public: 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); @@ -91,6 +91,11 @@ public: UFUNCTION(Client, Reliable) void Client_GameStart(); + UFUNCTION(Client, Reliable) + void Client_GameEnd(); + + UPROPERTY(BlueprintReadOnly) + float ScanPercentage = 0.f; protected: /** Called for movement input */ @@ -106,14 +111,22 @@ protected: // APawn interface virtual void SetupPlayerInputComponent(UInputComponent* InputComponent) override; // End of APawn interface + UPROPERTY() + FTimerHandle ScanTimerHandle; + + ACM_Shelving* LastScannedShelf = nullptr; public: /** Returns Mesh1P subobject **/ // USkeletalMeshComponent* GetMesh1P() const { return Mesh1P; } /** Returns FirstPersonCameraComponent subobject **/ UCameraComponent* GetFirstPersonCameraComponent() const { return FirstPersonCameraComponent; } + virtual void Tick(float DeltaSeconds) override; + UPROPERTY(EditDefaultsOnly) + float ScanTime = 3.f; }; + inline void ACorruptedMemoryCharacter::ServerSuccessfulScan_Implementation(const FString& Username) { if (const ACorruptedMemoryGameMode* GameMode = Cast(GetWorld()->GetAuthGameMode())) diff --git a/CorruptedMemory/Source/CorruptedMemory/CorruptedMemoryGameMode.cpp b/CorruptedMemory/Source/CorruptedMemory/CorruptedMemoryGameMode.cpp index 90f06b1..ffce1c7 100644 --- a/CorruptedMemory/Source/CorruptedMemory/CorruptedMemoryGameMode.cpp +++ b/CorruptedMemory/Source/CorruptedMemory/CorruptedMemoryGameMode.cpp @@ -32,17 +32,33 @@ void ACorruptedMemoryGameMode::PostLogin(APlayerController* NewPlayer) 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]() + GetWorld()->GetTimerManager().SetTimer(TimerHandle, [this]() { - for (const auto PlayerState : World->GetGameState()->PlayerArray) + for (const auto PlayerState : GetWorld()->GetGameState()->PlayerArray) { Cast(PlayerState->GetPlayerController()->GetCharacter())->Client_GameStart(); Cast(PlayerState->GetPlayerController()->GetCharacter())->Client_EnableUserInput(); PlayerState->GetPlayerController()->EnableInput(PlayerState->GetPlayerController()); PlayerState->GetPlayerController()->SetInputMode(FInputModeGameOnly()); } + + FTimerHandle TimerHandle2; + GetWorld()->GetTimerManager().SetTimer(TimerHandle2, [this]() + { + for (const auto PlayerState : GetWorld()->GetGameState()->PlayerArray) + { + Cast(PlayerState->GetPlayerController()->GetCharacter())->Client_GameEnd(); + Cast(PlayerState->GetPlayerController()->GetCharacter())->Client_DisableUserInput(); + PlayerState->GetPlayerController()->DisableInput(PlayerState->GetPlayerController()); + PlayerState->GetPlayerController()->SetInputMode(FInputModeUIOnly()); + } + FTimerHandle TimerHandle3; + GetWorld()->GetTimerManager().SetTimer(TimerHandle3, [this]() + { + FGenericPlatformMisc::RequestExit(false); + }, 10, false); + }, 125, false); }, 5.f, false); } } @@ -60,6 +76,12 @@ void ACorruptedMemoryGameMode::AddGameplayTagToShelf(AActor* Shelving, const FSt (*FoundShelf)->GameplayTags.Add(GameplayTag); } +void ACorruptedMemoryGameMode::RemoveGameplayTagToShelf(AActor* Shelving, const FString& GameplayTag) +{ + ACM_Shelving** FoundShelf = Shelves.FindByPredicate([Shelving](const ACM_Shelving* Shelf) { return Shelf == Shelving; }); + (*FoundShelf)->GameplayTags.Remove(GameplayTag); +} + void ACorruptedMemoryGameMode::BeginPlay() { Super::BeginPlay(); @@ -77,14 +99,28 @@ void ACorruptedMemoryGameMode::BeginPlay() SpawnPoints.Add(PlayerStartActor->GetActorTransform()); } - //Gets all store shelves in level TArray StoreShelves; UGameplayStatics::GetAllActorsWithTag(GetWorld(), "StoreShelf", StoreShelves); for (AActor* StoreShelf : StoreShelves) { Shelves.Add(Cast(StoreShelf)); } - Shelves[0]->GameplayTags.Add("Corrupted"); + + constexpr int StartCorruptedAmount = 35; + for (int i = 0; i < StartCorruptedAmount; i++) + { + ACM_Shelving* ShelfToCorrupt = Shelves[FMath::RandRange(0, Shelves.Num() - 1)]; + ShelfToCorrupt->GameplayTags.Add("Corrupted"); + } + + FTimerHandle TimerHandle; + GetWorld()->GetTimerManager().SetTimer(TimerHandle, [this]() + { + ACM_Shelving* ShelfToCorrupt = Shelves[FMath::RandRange(0, Shelves.Num() - 1)]; + if (ShelfToCorrupt->GameplayTags.Contains("Corrupted")) return; + if (ShelfToCorrupt->GameplayTags.Contains("Complete")) return; + ShelfToCorrupt->GameplayTags.Add("Corrupted"); + }, 10.f, true); } void ACorruptedMemoryGameMode::ServerSpawnPlayer_Implementation(APlayerController* PlayerController) diff --git a/CorruptedMemory/Source/CorruptedMemory/CorruptedMemoryGameMode.h b/CorruptedMemory/Source/CorruptedMemory/CorruptedMemoryGameMode.h index 0712a57..c37e8f2 100644 --- a/CorruptedMemory/Source/CorruptedMemory/CorruptedMemoryGameMode.h +++ b/CorruptedMemory/Source/CorruptedMemory/CorruptedMemoryGameMode.h @@ -26,6 +26,7 @@ public: void SuccessfulScan(const FString& Username) const; void AddGameplayTagToShelf(AActor* Shelving, const FString& GameplayTag); + void RemoveGameplayTagToShelf(AActor* Shelving, const FString& GameplayTag); protected: virtual void BeginPlay() override;