From e7db6372d801f300c6f5b4eccd5c1ddcef355813 Mon Sep 17 00:00:00 2001 From: Oleg Petruny Date: Sun, 10 Nov 2024 13:19:04 +0100 Subject: [PATCH 1/5] AgeOfWar minigame --- .../AgeOfWar/BP_Minigame_AgeOfWar.uasset | 4 +- .../AgeOfWar/UI_Minigame_AgeOfWar.uasset | 3 + .../BP_Minigame_AgeOfWarUnit_Base.uasset | 3 + ...BP_Minigame_AgeOfWarUnit_FirstMelee.uasset | 3 + ...BP_Minigame_AgeOfWarUnit_FirstRange.uasset | 3 + .../BP_Minigame_AgeOfWarUnit_FirstTank.uasset | 3 + .../Fishing/UI_Minigame_Fishing.uasset | 4 +- Content/Levels/Test/L_Test.umap | 4 +- Content/Levels/Test/L_Test_BuiltData.uasset | 4 +- .../Minigame/AgeOfWar/AgeOfWarManager.cpp | 34 +++++++- .../Minigame/AgeOfWar/AgeOfWarManager.h | 26 ++++++ .../Minigame/AgeOfWar/AgeOfWarUnit.cpp | 84 +++++++++++++++++++ .../Private/Minigame/AgeOfWar/AgeOfWarUnit.h | 74 ++++++++++++++++ 13 files changed, 240 insertions(+), 9 deletions(-) create mode 100644 Content/Blueprints/Minigames/AgeOfWar/UI_Minigame_AgeOfWar.uasset create mode 100644 Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_Base.uasset create mode 100644 Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstMelee.uasset create mode 100644 Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstRange.uasset create mode 100644 Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstTank.uasset create mode 100644 Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.cpp create mode 100644 Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.h diff --git a/Content/Blueprints/Minigames/AgeOfWar/BP_Minigame_AgeOfWar.uasset b/Content/Blueprints/Minigames/AgeOfWar/BP_Minigame_AgeOfWar.uasset index 9146144..895e73b 100644 --- a/Content/Blueprints/Minigames/AgeOfWar/BP_Minigame_AgeOfWar.uasset +++ b/Content/Blueprints/Minigames/AgeOfWar/BP_Minigame_AgeOfWar.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f824f9463511401dd695e86e2d6552cd74f848042adb901442355d379a3e6015 -size 20104 +oid sha256:bfba9f57eeadaeb16c2816753739eddb5d4998c706c1d37265019f3d367bf8db +size 117797 diff --git a/Content/Blueprints/Minigames/AgeOfWar/UI_Minigame_AgeOfWar.uasset b/Content/Blueprints/Minigames/AgeOfWar/UI_Minigame_AgeOfWar.uasset new file mode 100644 index 0000000..3ff9b75 --- /dev/null +++ b/Content/Blueprints/Minigames/AgeOfWar/UI_Minigame_AgeOfWar.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:af517d6e39525d50ced0a91902c5c66cee5ccd9163f437b383490274c8f10e24 +size 152299 diff --git a/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_Base.uasset b/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_Base.uasset new file mode 100644 index 0000000..8a670fd --- /dev/null +++ b/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_Base.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fc5241f0309901748105c0db83cf1816e1967ed59b581585fc2d30592a891ade +size 21133 diff --git a/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstMelee.uasset b/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstMelee.uasset new file mode 100644 index 0000000..179cd0e --- /dev/null +++ b/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstMelee.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e97530e0d19c9723523efe8e89dc6041bb2d402d66077f62603271811148d857 +size 20500 diff --git a/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstRange.uasset b/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstRange.uasset new file mode 100644 index 0000000..716efd6 --- /dev/null +++ b/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstRange.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8c8ca38d1d4d1e8df6ce890237d4ec03c3a28fcd9caaf9ca5743943132710b79 +size 22390 diff --git a/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstTank.uasset b/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstTank.uasset new file mode 100644 index 0000000..85233d4 --- /dev/null +++ b/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstTank.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:47e26221cdcd59092d748bcf7aac3c452cd4a0426d5f1c9a2fc1213e96b52b68 +size 21087 diff --git a/Content/Blueprints/Minigames/Fishing/UI_Minigame_Fishing.uasset b/Content/Blueprints/Minigames/Fishing/UI_Minigame_Fishing.uasset index 64dd046..d45693e 100644 --- a/Content/Blueprints/Minigames/Fishing/UI_Minigame_Fishing.uasset +++ b/Content/Blueprints/Minigames/Fishing/UI_Minigame_Fishing.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0b21c235dd6368de617fd3183dcc5a5b150bbc193c80b4bdf6aba4a3f5b3d6b6 -size 486905 +oid sha256:306c27ad9488349c97e003ec5c4e49d5f3383bd33c407c89ee9dc25dd4039148 +size 486840 diff --git a/Content/Levels/Test/L_Test.umap b/Content/Levels/Test/L_Test.umap index 90f2678..7a90a35 100644 --- a/Content/Levels/Test/L_Test.umap +++ b/Content/Levels/Test/L_Test.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:517227541cd118fc0c58a1ccaebb377531a4b888a9ee45394fe2531cbc3e434d -size 2257413 +oid sha256:520faeaddd669b27882a385975b18fe5e8c98508d77f395f186f20f069951012 +size 2262578 diff --git a/Content/Levels/Test/L_Test_BuiltData.uasset b/Content/Levels/Test/L_Test_BuiltData.uasset index 3bea8a6..216ce28 100644 --- a/Content/Levels/Test/L_Test_BuiltData.uasset +++ b/Content/Levels/Test/L_Test_BuiltData.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9bc37c40c0e26300a7832402eaed47bb71875dce9b428ba2e852c9c80aa98423 -size 19969242 +oid sha256:6aa7b92951a49c50d63d075885fd2b0c00041360b6721a5c84d2a16f68f8c562 +size 586263 diff --git a/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.cpp b/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.cpp index e1976ad..9b01484 100644 --- a/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.cpp +++ b/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.cpp @@ -3,11 +3,29 @@ #include "AgeOfWarManager.h" +#include "Camera/CameraComponent.h" + +#include "AgeOfWarUnit.h" #include "MainGameModeBase.h" #include "PlayerBase.h" +TMap AAgeOfWarManager::unitStats = {}; + +const FAgeOfWarUnitStats& AAgeOfWarManager::UnitGetStats(TSubclassOf unitClass) +{ + return unitStats[unitClass]; +} + AAgeOfWarManager::AAgeOfWarManager() -{} +{ + auto root = CreateDefaultSubobject(TEXT("Scene")); + + camera = CreateDefaultSubobject(TEXT("Camera")); + camera->AttachToComponent(root, FAttachmentTransformRules::KeepRelativeTransform); + + basePlayer = static_cast(CreateDefaultSubobject(TEXT("BasePlayer"), AAgeOfWarUnit::StaticClass(), baseClass, true, false)); + baseComputer = static_cast(CreateDefaultSubobject(TEXT("BaseComputer"), AAgeOfWarUnit::StaticClass(), baseClass, true, false)); +} void AAgeOfWarManager::Start(APlayerBase* playerPawn, FMinigameEndCallback delegate) { @@ -17,11 +35,25 @@ void AAgeOfWarManager::Start(APlayerBase* playerPawn, FMinigameEndCallback deleg AMinigame::Start(playerPawn, delegate); player->LockPlayer(FPlayerLock::All()); + player->SwitchToView(this); + + FillUnitStats(); } void AAgeOfWarManager::End() { + unitStats.Empty(); + + player->ReturnPlayerView(); player->UnlockPlayer(FPlayerLock::All()); AMinigame::End(); } + +void AAgeOfWarManager::UnitKill(AAgeOfWarUnit* unit) +{} + +void AAgeOfWarManager::AddUnitStats(TSubclassOf unitClass, FAgeOfWarUnitStats stats) +{ + unitStats.Add(unitClass, stats); +} diff --git a/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.h b/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.h index b414c2f..0f9a842 100644 --- a/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.h +++ b/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.h @@ -12,8 +12,34 @@ class AAgeOfWarManager : public AMinigame GENERATED_BODY() public: + static const struct FAgeOfWarUnitStats& UnitGetStats(TSubclassOf unitClass); + AAgeOfWarManager(); virtual void Start(class APlayerBase* playerPawn, FMinigameEndCallback delegate) override; virtual void End() override; + + void UnitKill(class AAgeOfWarUnit* unit); + +protected: + UFUNCTION(BlueprintImplementableEvent) + void FillUnitStats(); + + UFUNCTION(BlueprintCallable) + static void AddUnitStats(TSubclassOf unitClass, struct FAgeOfWarUnitStats stats); + + static TMap unitStats; + + UPROPERTY(EditAnywhere) + class UCameraComponent* camera; + + UPROPERTY(EditDefaultsOnly) + class TSubclassOf baseClass; + UPROPERTY(EditAnywhere) + class AAgeOfWarUnit* basePlayer; + UPROPERTY(EditAnywhere) + class AAgeOfWarUnit* baseComputer; + + + }; diff --git a/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.cpp b/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.cpp new file mode 100644 index 0000000..17ff2bd --- /dev/null +++ b/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.cpp @@ -0,0 +1,84 @@ +// Oleg Petruny proprietary. + + +#include "AgeOfWarUnit.h" + +#include "AgeOfWarManager.h" + +const FAgeOfWarUnitStats& AAgeOfWarUnit::GetStats() +{ + if(!stats) + stats = &AAgeOfWarManager::UnitGetStats(GetClass()); + + if(ensureAlways(stats)) + { + auto errorMsg = FString::Printf(TEXT("AgeOfWarManager instance doesn't contain %s class stats... Destroying actor"), &GetClass()->GetName()); + UE_LOG(LogTemp, Log, TEXT("%s"), *errorMsg); + GEngine->AddOnScreenDebugMessage(-1, 20.0f, FColor::Red, errorMsg); + static FAgeOfWarUnitStats s{}; + stats = &s; + Destroy(); + } + + return *stats; +} + +void AAgeOfWarUnit::BeginPlay() +{ + health = GetStats().health; +} + +void AAgeOfWarUnit::EndPlay(const EEndPlayReason::Type EndPlayReason) +{} + +void AAgeOfWarUnit::Tick(float deltaTime) +{ + Super::Tick(deltaTime); + + if(GetStats().moveSpeed <= 0) + return; + + // move unit forward + auto moveStep = GetActorForwardVector() * GetStats().moveSpeed; + FHitResult hit; + this->AddActorWorldOffset(moveStep, true, &hit, ETeleportType::None); + + // check if blocked + if(!hit.bBlockingHit) + return; + + forwardUnit = Cast(hit.GetActor()); + if(!forwardUnit) // something is wrong, only block with units + { + Destroy(); + return; + } + + // iterate to attackable unit + for(int i = 1; forwardUnit->team == team && i < GetStats().attackDistance; i += forwardUnit->GetStats().unitSize) + forwardUnit = forwardUnit->forwardUnit; + + // if forward unit is in the same team skip attack + if(forwardUnit->team == team) + return; + + // attack the forward unit + if(lastAttackTimestamp + GetStats().attackRate - FPlatformTime::Seconds() < 0) + { + lastAttackTimestamp = FPlatformTime::Seconds(); + forwardUnit->Damage(GetStats().attackDamage); + } +} + +void AAgeOfWarUnit::Damage(const int32 damage) +{ + health -= damage; + + if(health > 0) + return; + + if(IsValid(manager)) + manager->UnitKill(this); + else + Destroy(); +} diff --git a/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.h b/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.h new file mode 100644 index 0000000..84f45c8 --- /dev/null +++ b/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.h @@ -0,0 +1,74 @@ +// Oleg Petruny proprietary. + +#pragma once + +#include "GameFramework/Actor.h" + +#include "AgeOfWarUnit.generated.h" + +USTRUCT(BlueprintType) +struct FAgeOfWarUnitStats +{ + GENERATED_BODY() + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FText name = FText::GetEmpty(); + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + int32 price = 100; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + int32 health = 5; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + float moveSpeed = 1.0f; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + int32 attackDamage = 1; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + int32 attackDistance = 1; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + float attackRate = 1.0f; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + int32 unitSize = 1; + +}; + +UCLASS(Blueprintable, MinimalAPI, Abstract) +class AAgeOfWarUnit : public AActor +{ + GENERATED_BODY() + +public: + enum class UnitTeam + { + Player, + AI + }; + + UFUNCTION(BlueprintPure) + const FAgeOfWarUnitStats& GetStats(); + + class AAgeOfWarManager* manager = nullptr; + const FAgeOfWarUnitStats* stats = nullptr; + UnitTeam team; + +protected: + virtual void BeginPlay() override; + virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; + virtual void Tick(float deltaTime) override; + + void Damage(const int32 damage); + + AAgeOfWarUnit* forwardUnit = nullptr; + +private: + int32 health; + FTimerHandle attackTimer; + double lastAttackTimestamp = 0; + +}; + -- 2.45.2 From 6946217c7e46785458652dd70b6b964d0d0d8224 Mon Sep 17 00:00:00 2001 From: Oleg Petruny Date: Sun, 17 Nov 2024 22:20:05 +0100 Subject: [PATCH 2/5] Minigame without AI --- .../Lost_Edge/Config/DefaultEngine.ini | 1 + .../Blueprints/Items/BP_CompanionCube.uasset | 4 +- .../AgeOfWar/BP_Minigame_AgeOfWar.uasset | 4 +- .../AgeOfWar/UI_Minigame_AgeOfWar.uasset | 4 +- .../BP_Minigame_AgeOfWarUnit_Base.uasset | 4 +- ...BP_Minigame_AgeOfWarUnit_FirstMelee.uasset | 4 +- ...BP_Minigame_AgeOfWarUnit_FirstRange.uasset | 4 +- .../BP_Minigame_AgeOfWarUnit_FirstTank.uasset | 4 +- .../Lost_Edge/Content/Levels/Test/L_Test.umap | 4 +- .../Private/Interactable/Interactable.cpp | 24 +++++----- .../Private/Interactable/Interactable.h | 2 +- .../Minigame/AgeOfWar/AgeOfWarManager.cpp | 35 +++++++++++--- .../Minigame/AgeOfWar/AgeOfWarManager.h | 18 +++---- .../Minigame/AgeOfWar/AgeOfWarUnit.cpp | 47 +++++++++++++------ .../Private/Minigame/AgeOfWar/AgeOfWarUnit.h | 25 +++++++--- .../Minigame/CrossyRoad/CrossyRoadManager.cpp | 6 +-- .../Minigame/SubwaySurf/SubwaySurfManager.cpp | 6 +-- 17 files changed, 122 insertions(+), 74 deletions(-) diff --git a/UnrealProject/Lost_Edge/Config/DefaultEngine.ini b/UnrealProject/Lost_Edge/Config/DefaultEngine.ini index fbd6426..369b66a 100644 --- a/UnrealProject/Lost_Edge/Config/DefaultEngine.ini +++ b/UnrealProject/Lost_Edge/Config/DefaultEngine.ini @@ -139,6 +139,7 @@ ManualIPAddress= +Profiles=(Name="Vehicle",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="Vehicle",CustomResponses=,HelpMessage="Vehicle object that blocks Vehicle, WorldStatic, and WorldDynamic. All other channels will be set to default.") +Profiles=(Name="UI",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility"),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldStatic object that overlaps all actors by default. All new custom channels will use its own default response. ") +Profiles=(Name="Interactable",CollisionEnabled=QueryAndPhysics,bCanModify=True,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Interactable")),HelpMessage="WorldDynamic objects derived from AInteractable.") ++Profiles=(Name="AgeOfWarUnit",CollisionEnabled=QueryOnly,bCanModify=True,ObjectTypeName="Vehicle",CustomResponses=((Channel="WorldStatic",Response=ECR_Ignore),(Channel="WorldDynamic",Response=ECR_Ignore),(Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore),(Channel="PhysicsBody",Response=ECR_Ignore),(Channel="Destructible",Response=ECR_Ignore)),HelpMessage="Minigame object") +DefaultChannelResponses=(Channel=ECC_GameTraceChannel1,DefaultResponse=ECR_Ignore,bTraceType=True,bStaticObject=False,Name="Interactable") -ProfileRedirects=(OldName="BlockingVolume",NewName="InvisibleWall") -ProfileRedirects=(OldName="InterpActor",NewName="IgnoreOnlyPawn") diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Items/BP_CompanionCube.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Items/BP_CompanionCube.uasset index b8610db..ba9951d 100644 --- a/UnrealProject/Lost_Edge/Content/Blueprints/Items/BP_CompanionCube.uasset +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Items/BP_CompanionCube.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2b9660bb6e1de93ac49a75a29779ac8bbac2f4230b1aec0f7eca4604a8f79467 -size 23557 +oid sha256:1195d0ee2ffdfd23b58c5b83519c0c26bf91b3df3a623d52411462876b9d9848 +size 25381 diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/BP_Minigame_AgeOfWar.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/BP_Minigame_AgeOfWar.uasset index 895e73b..35f9a4f 100644 --- a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/BP_Minigame_AgeOfWar.uasset +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/BP_Minigame_AgeOfWar.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bfba9f57eeadaeb16c2816753739eddb5d4998c706c1d37265019f3d367bf8db -size 117797 +oid sha256:eb79e9917fe826eb430ee33c9f2f3899bab8a193eb230ce24017fb13c4179e7f +size 366061 diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/UI_Minigame_AgeOfWar.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/UI_Minigame_AgeOfWar.uasset index 3ff9b75..71b6ab2 100644 --- a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/UI_Minigame_AgeOfWar.uasset +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/UI_Minigame_AgeOfWar.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:af517d6e39525d50ced0a91902c5c66cee5ccd9163f437b383490274c8f10e24 -size 152299 +oid sha256:48d61e4adb9f190548560d1e42f2d07c60564a988ba877f70e528c204e544709 +size 181823 diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_Base.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_Base.uasset index 8a670fd..d0c20a2 100644 --- a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_Base.uasset +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_Base.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fc5241f0309901748105c0db83cf1816e1967ed59b581585fc2d30592a891ade -size 21133 +oid sha256:12a1a84218555e73e3f9ef1f3db30bf3e1ca2b427a041839128f111e97d80263 +size 23941 diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstMelee.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstMelee.uasset index 179cd0e..aaadec9 100644 --- a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstMelee.uasset +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstMelee.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e97530e0d19c9723523efe8e89dc6041bb2d402d66077f62603271811148d857 -size 20500 +oid sha256:905f95b9ba7239185a27a95f0dc44c394705c7ae7c1edf38274a29cb8d5eeed7 +size 23343 diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstRange.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstRange.uasset index 716efd6..1766f2a 100644 --- a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstRange.uasset +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstRange.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8c8ca38d1d4d1e8df6ce890237d4ec03c3a28fcd9caaf9ca5743943132710b79 -size 22390 +oid sha256:685d868675c82a533270e268390749c68bd14f8d1d08059ee090a24748e2998d +size 26335 diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstTank.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstTank.uasset index 85233d4..8e12740 100644 --- a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstTank.uasset +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstTank.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:47e26221cdcd59092d748bcf7aac3c452cd4a0426d5f1c9a2fc1213e96b52b68 -size 21087 +oid sha256:8202a38d55de0cc6f348780d036e2c08fcc2d0860e28ce6649346ec71989f49a +size 23930 diff --git a/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap b/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap index 7a90a35..435c279 100644 --- a/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap +++ b/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:520faeaddd669b27882a385975b18fe5e8c98508d77f395f186f20f069951012 -size 2262578 +oid sha256:bdd549e2cfccd08d1cf7a9347d806405311dbd11d371bb8677428ef5aba7f9ed +size 2265093 diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Interactable/Interactable.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Interactable/Interactable.cpp index 832cae8..1094c03 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Interactable/Interactable.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Interactable/Interactable.cpp @@ -55,25 +55,25 @@ void AInteractable::BeginPlay() } } - GetComponents(meshes); - for(auto mesh : meshes) + GetComponents(collisions, true); + for(auto collision : collisions) { if(activatorTypes) { - mesh->SetCollisionProfileName(TEXT("Interactable")); + collision->SetCollisionProfileName(TEXT("Interactable")); } if(activatorTypes & static_cast(EActivatorType::Saw)) { - mesh->CustomDepthStencilValue = 128; - mesh->CustomDepthStencilWriteMask = ERendererStencilMask::ERSM_Default; - mesh->SetRenderCustomDepth(true); + collision->CustomDepthStencilValue = 128; + collision->CustomDepthStencilWriteMask = ERendererStencilMask::ERSM_Default; + collision->SetRenderCustomDepth(true); } if(activatorTypes & static_cast(EActivatorType::Use)) { - mesh->CustomDepthStencilWriteMask = ERendererStencilMask::ERSM_Default; - mesh->SetRenderCustomDepth(true); + collision->CustomDepthStencilWriteMask = ERendererStencilMask::ERSM_Default; + collision->SetRenderCustomDepth(true); } } @@ -120,8 +120,8 @@ void AInteractable::_Activate(EActivatorType type) if(activated & static_cast(EActivatorType::Use)) { - for(auto mesh : meshes) - mesh->SetCustomDepthStencilValue(132); + for(auto collision : collisions) + collision->SetCustomDepthStencilValue(132); } Activate(type); @@ -155,8 +155,8 @@ void AInteractable::_Deactivate(EActivatorType type) if(!(activated & static_cast(EActivatorType::Use))) { - for(auto mesh : meshes) - mesh->SetCustomDepthStencilValue(0); + for(auto collision : collisions) + collision->SetCustomDepthStencilValue(0); } Deactivate(type); diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Interactable/Interactable.h b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Interactable/Interactable.h index 33d4358..1b84e93 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Interactable/Interactable.h +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Interactable/Interactable.h @@ -58,7 +58,7 @@ protected: TMap modificators; class APlayerBase* player = nullptr; - TArray meshes; + TArray collisions; }; diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.cpp index 9b01484..7f566a9 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.cpp @@ -4,6 +4,7 @@ #include "AgeOfWarManager.h" #include "Camera/CameraComponent.h" +#include "Components/ChildActorComponent.h" #include "AgeOfWarUnit.h" #include "MainGameModeBase.h" @@ -13,6 +14,8 @@ TMap AAgeOfWarManager::unitStats = {}; const FAgeOfWarUnitStats& AAgeOfWarManager::UnitGetStats(TSubclassOf unitClass) { + check(unitStats.Contains(*unitClass)); + return unitStats[unitClass]; } @@ -21,10 +24,7 @@ AAgeOfWarManager::AAgeOfWarManager() auto root = CreateDefaultSubobject(TEXT("Scene")); camera = CreateDefaultSubobject(TEXT("Camera")); - camera->AttachToComponent(root, FAttachmentTransformRules::KeepRelativeTransform); - - basePlayer = static_cast(CreateDefaultSubobject(TEXT("BasePlayer"), AAgeOfWarUnit::StaticClass(), baseClass, true, false)); - baseComputer = static_cast(CreateDefaultSubobject(TEXT("BaseComputer"), AAgeOfWarUnit::StaticClass(), baseClass, true, false)); + camera->SetupAttachment(root); } void AAgeOfWarManager::Start(APlayerBase* playerPawn, FMinigameEndCallback delegate) @@ -38,6 +38,16 @@ void AAgeOfWarManager::Start(APlayerBase* playerPawn, FMinigameEndCallback deleg player->SwitchToView(this); FillUnitStats(); + TArray units; + GetComponents(units); + for(auto& unit : units) + { + if(auto proxy = Cast(unit->GetChildActor())) + { + proxy->manager = this; + proxy->UpdateStats(); + } + } } void AAgeOfWarManager::End() @@ -50,10 +60,21 @@ void AAgeOfWarManager::End() AMinigame::End(); } -void AAgeOfWarManager::UnitKill(AAgeOfWarUnit* unit) -{} - void AAgeOfWarManager::AddUnitStats(TSubclassOf unitClass, FAgeOfWarUnitStats stats) { unitStats.Add(unitClass, stats); } + +FAgeOfWarUnitStats AAgeOfWarManager::GetUnitStats(TSubclassOf unitClass) +{ + return UnitGetStats(unitClass); +} + +void AAgeOfWarManager::SpawnUnit(TSubclassOf unitClass, FTransform transform, bool computer) +{ + FActorSpawnParameters spawnParams{}; + spawnParams.Owner = this; + auto unit = GetWorld()->SpawnActor(*unitClass, transform, spawnParams); + unit->team = computer ? UnitTeam::AI : UnitTeam::Player; + unit->manager = this; +} diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.h b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.h index 0f9a842..099e729 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.h +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.h @@ -19,27 +19,23 @@ public: virtual void Start(class APlayerBase* playerPawn, FMinigameEndCallback delegate) override; virtual void End() override; - void UnitKill(class AAgeOfWarUnit* unit); + UFUNCTION(BlueprintImplementableEvent) + void OnUnitKill(class AAgeOfWarUnit* unit); protected: UFUNCTION(BlueprintImplementableEvent) void FillUnitStats(); - UFUNCTION(BlueprintCallable) static void AddUnitStats(TSubclassOf unitClass, struct FAgeOfWarUnitStats stats); + UFUNCTION(BlueprintPure) + static struct FAgeOfWarUnitStats GetUnitStats(TSubclassOf unitClass); + + UFUNCTION(BlueprintCallable) + void SpawnUnit(TSubclassOf unitClass, FTransform transform, bool computer = false); static TMap unitStats; UPROPERTY(EditAnywhere) class UCameraComponent* camera; - UPROPERTY(EditDefaultsOnly) - class TSubclassOf baseClass; - UPROPERTY(EditAnywhere) - class AAgeOfWarUnit* basePlayer; - UPROPERTY(EditAnywhere) - class AAgeOfWarUnit* baseComputer; - - - }; diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.cpp index 17ff2bd..efb92fb 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.cpp @@ -3,39 +3,55 @@ #include "AgeOfWarUnit.h" +#include "Components/StaticMeshComponent.h" + #include "AgeOfWarManager.h" +#include const FAgeOfWarUnitStats& AAgeOfWarUnit::GetStats() { if(!stats) stats = &AAgeOfWarManager::UnitGetStats(GetClass()); - if(ensureAlways(stats)) - { - auto errorMsg = FString::Printf(TEXT("AgeOfWarManager instance doesn't contain %s class stats... Destroying actor"), &GetClass()->GetName()); - UE_LOG(LogTemp, Log, TEXT("%s"), *errorMsg); - GEngine->AddOnScreenDebugMessage(-1, 20.0f, FColor::Red, errorMsg); - static FAgeOfWarUnitStats s{}; - stats = &s; - Destroy(); - } - return *stats; } -void AAgeOfWarUnit::BeginPlay() +void AAgeOfWarUnit::UpdateStats() { health = GetStats().health; } +void AAgeOfWarUnit::BeginPlay() +{ + if(manager) + { + UpdateStats(); + } + + Super::BeginPlay(); +} + void AAgeOfWarUnit::EndPlay(const EEndPlayReason::Type EndPlayReason) -{} +{ + Super::EndPlay(EndPlayReason); +} + +AAgeOfWarUnit::AAgeOfWarUnit() +{ + //auto root = CreateDefaultSubobject(TEXT("Scene")); + // + //collision = CreateDefaultSubobject(TEXT("Collision")); + //collision->SetCollisionProfileName(TEXT("AgeOfWarUnit")); + + PrimaryActorTick.bCanEverTick = true; + PrimaryActorTick.bStartWithTickEnabled = true; +} void AAgeOfWarUnit::Tick(float deltaTime) { Super::Tick(deltaTime); - if(GetStats().moveSpeed <= 0) + if(!manager || GetStats().moveSpeed <= 0) return; // move unit forward @@ -68,17 +84,20 @@ void AAgeOfWarUnit::Tick(float deltaTime) lastAttackTimestamp = FPlatformTime::Seconds(); forwardUnit->Damage(GetStats().attackDamage); } + GEngine->AddOnScreenDebugMessage(4, 5.0f, FColor::Yellow, FString::Printf(TEXT("Time %f"), lastAttackTimestamp + GetStats().attackRate - FPlatformTime::Seconds())); } void AAgeOfWarUnit::Damage(const int32 damage) { + GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, FString::Printf(TEXT("Damage %d taken by %s"), damage, *GetClass()->GetName())); + health -= damage; if(health > 0) return; if(IsValid(manager)) - manager->UnitKill(this); + manager->OnUnitKill(this); else Destroy(); } diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.h b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.h index 84f45c8..d1652d5 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.h +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.h @@ -37,35 +37,46 @@ struct FAgeOfWarUnitStats }; +UENUM(BlueprintType) +enum class UnitTeam : uint8 +{ + Player, + AI +}; + UCLASS(Blueprintable, MinimalAPI, Abstract) class AAgeOfWarUnit : public AActor { GENERATED_BODY() public: - enum class UnitTeam - { - Player, - AI - }; + AAgeOfWarUnit(); + virtual void Tick(float deltaTime) override; UFUNCTION(BlueprintPure) const FAgeOfWarUnitStats& GetStats(); - class AAgeOfWarManager* manager = nullptr; + UFUNCTION(BlueprintCallable) + void UpdateStats(); + const FAgeOfWarUnitStats* stats = nullptr; + class AAgeOfWarManager* manager = nullptr; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) UnitTeam team; protected: virtual void BeginPlay() override; virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; - virtual void Tick(float deltaTime) override; void Damage(const int32 damage); AAgeOfWarUnit* forwardUnit = nullptr; private: + UPROPERTY(EditAnywhere) + class UBoxComponent* collision; + int32 health; FTimerHandle attackTimer; double lastAttackTimestamp = 0; diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/CrossyRoad/CrossyRoadManager.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/CrossyRoad/CrossyRoadManager.cpp index 1c6a8e7..c7794e6 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/CrossyRoad/CrossyRoadManager.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/CrossyRoad/CrossyRoadManager.cpp @@ -24,13 +24,13 @@ ACrossyRoadManager::ACrossyRoadManager() auto root = CreateDefaultSubobject(TEXT("Scene")); playerPos = CreateDefaultSubobject(TEXT("PlayerPos")); - playerPos->AttachToComponent(root, FAttachmentTransformRules::KeepRelativeTransform); + playerPos->SetupAttachment(root); camera = CreateDefaultSubobject(TEXT("Camera")); - camera->AttachToComponent(root, FAttachmentTransformRules::KeepRelativeTransform); + camera->SetupAttachment(root); mannequin = CreateDefaultSubobject(TEXT("Mannequin")); - mannequin->AttachToComponent(root, FAttachmentTransformRules::KeepRelativeTransform); + mannequin->SetupAttachment(root); } void ACrossyRoadManager::Start(APlayerBase* playerPawn, FMinigameEndCallback delegate) diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/SubwaySurf/SubwaySurfManager.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/SubwaySurf/SubwaySurfManager.cpp index 16b8f00..9b0746a 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/SubwaySurf/SubwaySurfManager.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/SubwaySurf/SubwaySurfManager.cpp @@ -24,13 +24,13 @@ ASubwaySurfManager::ASubwaySurfManager() auto root = CreateDefaultSubobject(TEXT("Scene")); playerPos = CreateDefaultSubobject(TEXT("PlayerPos")); - playerPos->AttachToComponent(root, FAttachmentTransformRules::KeepRelativeTransform); + playerPos->SetupAttachment(root); camera = CreateDefaultSubobject(TEXT("Camera")); - camera->AttachToComponent(root, FAttachmentTransformRules::KeepRelativeTransform); + camera->SetupAttachment(root); mannequin = CreateDefaultSubobject(TEXT("Mannequin")); - mannequin->AttachToComponent(root, FAttachmentTransformRules::KeepRelativeTransform); + mannequin->SetupAttachment(root); } void ASubwaySurfManager::Start(APlayerBase* playerPawn, FMinigameEndCallback delegate) -- 2.45.2 From cbb8a5bc140da19362e1de46ee97759b82f8246f Mon Sep 17 00:00:00 2001 From: Oleg Petruny Date: Sun, 10 Nov 2024 13:19:04 +0100 Subject: [PATCH 3/5] AgeOfWar minigame --- .../AgeOfWar/BP_Minigame_AgeOfWar.uasset | 4 +- .../AgeOfWar/UI_Minigame_AgeOfWar.uasset | 3 + .../BP_Minigame_AgeOfWarUnit_Base.uasset | 3 + ...BP_Minigame_AgeOfWarUnit_FirstMelee.uasset | 3 + ...BP_Minigame_AgeOfWarUnit_FirstRange.uasset | 3 + .../BP_Minigame_AgeOfWarUnit_FirstTank.uasset | 3 + .../Fishing/UI_Minigame_Fishing.uasset | 4 +- .../Levels/Test/L_Test_BuiltData.uasset | 4 +- .../Minigame/AgeOfWar/AgeOfWarManager.cpp | 34 +++++++- .../Minigame/AgeOfWar/AgeOfWarManager.h | 26 ++++++ .../Minigame/AgeOfWar/AgeOfWarUnit.cpp | 84 +++++++++++++++++++ .../Private/Minigame/AgeOfWar/AgeOfWarUnit.h | 74 ++++++++++++++++ 12 files changed, 238 insertions(+), 7 deletions(-) create mode 100644 UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/UI_Minigame_AgeOfWar.uasset create mode 100644 UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_Base.uasset create mode 100644 UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstMelee.uasset create mode 100644 UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstRange.uasset create mode 100644 UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstTank.uasset create mode 100644 UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.cpp create mode 100644 UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.h diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/BP_Minigame_AgeOfWar.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/BP_Minigame_AgeOfWar.uasset index 9146144..895e73b 100644 --- a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/BP_Minigame_AgeOfWar.uasset +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/BP_Minigame_AgeOfWar.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f824f9463511401dd695e86e2d6552cd74f848042adb901442355d379a3e6015 -size 20104 +oid sha256:bfba9f57eeadaeb16c2816753739eddb5d4998c706c1d37265019f3d367bf8db +size 117797 diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/UI_Minigame_AgeOfWar.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/UI_Minigame_AgeOfWar.uasset new file mode 100644 index 0000000..3ff9b75 --- /dev/null +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/UI_Minigame_AgeOfWar.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:af517d6e39525d50ced0a91902c5c66cee5ccd9163f437b383490274c8f10e24 +size 152299 diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_Base.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_Base.uasset new file mode 100644 index 0000000..8a670fd --- /dev/null +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_Base.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fc5241f0309901748105c0db83cf1816e1967ed59b581585fc2d30592a891ade +size 21133 diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstMelee.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstMelee.uasset new file mode 100644 index 0000000..179cd0e --- /dev/null +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstMelee.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e97530e0d19c9723523efe8e89dc6041bb2d402d66077f62603271811148d857 +size 20500 diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstRange.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstRange.uasset new file mode 100644 index 0000000..716efd6 --- /dev/null +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstRange.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8c8ca38d1d4d1e8df6ce890237d4ec03c3a28fcd9caaf9ca5743943132710b79 +size 22390 diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstTank.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstTank.uasset new file mode 100644 index 0000000..85233d4 --- /dev/null +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstTank.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:47e26221cdcd59092d748bcf7aac3c452cd4a0426d5f1c9a2fc1213e96b52b68 +size 21087 diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/Fishing/UI_Minigame_Fishing.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/Fishing/UI_Minigame_Fishing.uasset index 64dd046..d45693e 100644 --- a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/Fishing/UI_Minigame_Fishing.uasset +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/Fishing/UI_Minigame_Fishing.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0b21c235dd6368de617fd3183dcc5a5b150bbc193c80b4bdf6aba4a3f5b3d6b6 -size 486905 +oid sha256:306c27ad9488349c97e003ec5c4e49d5f3383bd33c407c89ee9dc25dd4039148 +size 486840 diff --git a/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test_BuiltData.uasset b/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test_BuiltData.uasset index 3bea8a6..216ce28 100644 --- a/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test_BuiltData.uasset +++ b/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test_BuiltData.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9bc37c40c0e26300a7832402eaed47bb71875dce9b428ba2e852c9c80aa98423 -size 19969242 +oid sha256:6aa7b92951a49c50d63d075885fd2b0c00041360b6721a5c84d2a16f68f8c562 +size 586263 diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.cpp index e1976ad..9b01484 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.cpp @@ -3,11 +3,29 @@ #include "AgeOfWarManager.h" +#include "Camera/CameraComponent.h" + +#include "AgeOfWarUnit.h" #include "MainGameModeBase.h" #include "PlayerBase.h" +TMap AAgeOfWarManager::unitStats = {}; + +const FAgeOfWarUnitStats& AAgeOfWarManager::UnitGetStats(TSubclassOf unitClass) +{ + return unitStats[unitClass]; +} + AAgeOfWarManager::AAgeOfWarManager() -{} +{ + auto root = CreateDefaultSubobject(TEXT("Scene")); + + camera = CreateDefaultSubobject(TEXT("Camera")); + camera->AttachToComponent(root, FAttachmentTransformRules::KeepRelativeTransform); + + basePlayer = static_cast(CreateDefaultSubobject(TEXT("BasePlayer"), AAgeOfWarUnit::StaticClass(), baseClass, true, false)); + baseComputer = static_cast(CreateDefaultSubobject(TEXT("BaseComputer"), AAgeOfWarUnit::StaticClass(), baseClass, true, false)); +} void AAgeOfWarManager::Start(APlayerBase* playerPawn, FMinigameEndCallback delegate) { @@ -17,11 +35,25 @@ void AAgeOfWarManager::Start(APlayerBase* playerPawn, FMinigameEndCallback deleg AMinigame::Start(playerPawn, delegate); player->LockPlayer(FPlayerLock::All()); + player->SwitchToView(this); + + FillUnitStats(); } void AAgeOfWarManager::End() { + unitStats.Empty(); + + player->ReturnPlayerView(); player->UnlockPlayer(FPlayerLock::All()); AMinigame::End(); } + +void AAgeOfWarManager::UnitKill(AAgeOfWarUnit* unit) +{} + +void AAgeOfWarManager::AddUnitStats(TSubclassOf unitClass, FAgeOfWarUnitStats stats) +{ + unitStats.Add(unitClass, stats); +} diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.h b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.h index b414c2f..0f9a842 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.h +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.h @@ -12,8 +12,34 @@ class AAgeOfWarManager : public AMinigame GENERATED_BODY() public: + static const struct FAgeOfWarUnitStats& UnitGetStats(TSubclassOf unitClass); + AAgeOfWarManager(); virtual void Start(class APlayerBase* playerPawn, FMinigameEndCallback delegate) override; virtual void End() override; + + void UnitKill(class AAgeOfWarUnit* unit); + +protected: + UFUNCTION(BlueprintImplementableEvent) + void FillUnitStats(); + + UFUNCTION(BlueprintCallable) + static void AddUnitStats(TSubclassOf unitClass, struct FAgeOfWarUnitStats stats); + + static TMap unitStats; + + UPROPERTY(EditAnywhere) + class UCameraComponent* camera; + + UPROPERTY(EditDefaultsOnly) + class TSubclassOf baseClass; + UPROPERTY(EditAnywhere) + class AAgeOfWarUnit* basePlayer; + UPROPERTY(EditAnywhere) + class AAgeOfWarUnit* baseComputer; + + + }; diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.cpp new file mode 100644 index 0000000..17ff2bd --- /dev/null +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.cpp @@ -0,0 +1,84 @@ +// Oleg Petruny proprietary. + + +#include "AgeOfWarUnit.h" + +#include "AgeOfWarManager.h" + +const FAgeOfWarUnitStats& AAgeOfWarUnit::GetStats() +{ + if(!stats) + stats = &AAgeOfWarManager::UnitGetStats(GetClass()); + + if(ensureAlways(stats)) + { + auto errorMsg = FString::Printf(TEXT("AgeOfWarManager instance doesn't contain %s class stats... Destroying actor"), &GetClass()->GetName()); + UE_LOG(LogTemp, Log, TEXT("%s"), *errorMsg); + GEngine->AddOnScreenDebugMessage(-1, 20.0f, FColor::Red, errorMsg); + static FAgeOfWarUnitStats s{}; + stats = &s; + Destroy(); + } + + return *stats; +} + +void AAgeOfWarUnit::BeginPlay() +{ + health = GetStats().health; +} + +void AAgeOfWarUnit::EndPlay(const EEndPlayReason::Type EndPlayReason) +{} + +void AAgeOfWarUnit::Tick(float deltaTime) +{ + Super::Tick(deltaTime); + + if(GetStats().moveSpeed <= 0) + return; + + // move unit forward + auto moveStep = GetActorForwardVector() * GetStats().moveSpeed; + FHitResult hit; + this->AddActorWorldOffset(moveStep, true, &hit, ETeleportType::None); + + // check if blocked + if(!hit.bBlockingHit) + return; + + forwardUnit = Cast(hit.GetActor()); + if(!forwardUnit) // something is wrong, only block with units + { + Destroy(); + return; + } + + // iterate to attackable unit + for(int i = 1; forwardUnit->team == team && i < GetStats().attackDistance; i += forwardUnit->GetStats().unitSize) + forwardUnit = forwardUnit->forwardUnit; + + // if forward unit is in the same team skip attack + if(forwardUnit->team == team) + return; + + // attack the forward unit + if(lastAttackTimestamp + GetStats().attackRate - FPlatformTime::Seconds() < 0) + { + lastAttackTimestamp = FPlatformTime::Seconds(); + forwardUnit->Damage(GetStats().attackDamage); + } +} + +void AAgeOfWarUnit::Damage(const int32 damage) +{ + health -= damage; + + if(health > 0) + return; + + if(IsValid(manager)) + manager->UnitKill(this); + else + Destroy(); +} diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.h b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.h new file mode 100644 index 0000000..84f45c8 --- /dev/null +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.h @@ -0,0 +1,74 @@ +// Oleg Petruny proprietary. + +#pragma once + +#include "GameFramework/Actor.h" + +#include "AgeOfWarUnit.generated.h" + +USTRUCT(BlueprintType) +struct FAgeOfWarUnitStats +{ + GENERATED_BODY() + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FText name = FText::GetEmpty(); + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + int32 price = 100; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + int32 health = 5; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + float moveSpeed = 1.0f; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + int32 attackDamage = 1; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + int32 attackDistance = 1; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + float attackRate = 1.0f; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + int32 unitSize = 1; + +}; + +UCLASS(Blueprintable, MinimalAPI, Abstract) +class AAgeOfWarUnit : public AActor +{ + GENERATED_BODY() + +public: + enum class UnitTeam + { + Player, + AI + }; + + UFUNCTION(BlueprintPure) + const FAgeOfWarUnitStats& GetStats(); + + class AAgeOfWarManager* manager = nullptr; + const FAgeOfWarUnitStats* stats = nullptr; + UnitTeam team; + +protected: + virtual void BeginPlay() override; + virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; + virtual void Tick(float deltaTime) override; + + void Damage(const int32 damage); + + AAgeOfWarUnit* forwardUnit = nullptr; + +private: + int32 health; + FTimerHandle attackTimer; + double lastAttackTimestamp = 0; + +}; + -- 2.45.2 From 579100f45cd02c884fd3d740c398575ffbfde316 Mon Sep 17 00:00:00 2001 From: Oleg Petruny Date: Sun, 17 Nov 2024 22:20:05 +0100 Subject: [PATCH 4/5] Minigame without AI --- .../Lost_Edge/Config/DefaultEngine.ini | 1 + .../Blueprints/Items/BP_CompanionCube.uasset | 4 +- .../AgeOfWar/BP_Minigame_AgeOfWar.uasset | 4 +- .../AgeOfWar/UI_Minigame_AgeOfWar.uasset | 4 +- .../BP_Minigame_AgeOfWarUnit_Base.uasset | 4 +- ...BP_Minigame_AgeOfWarUnit_FirstMelee.uasset | 4 +- ...BP_Minigame_AgeOfWarUnit_FirstRange.uasset | 4 +- .../BP_Minigame_AgeOfWarUnit_FirstTank.uasset | 4 +- .../Lost_Edge/Content/Levels/Test/L_Test.umap | 4 +- .../Private/Interactable/Interactable.cpp | 24 +++++----- .../Private/Interactable/Interactable.h | 2 +- .../Minigame/AgeOfWar/AgeOfWarManager.cpp | 35 +++++++++++--- .../Minigame/AgeOfWar/AgeOfWarManager.h | 18 +++---- .../Minigame/AgeOfWar/AgeOfWarUnit.cpp | 47 +++++++++++++------ .../Private/Minigame/AgeOfWar/AgeOfWarUnit.h | 25 +++++++--- .../Minigame/CrossyRoad/CrossyRoadManager.cpp | 6 +-- .../Minigame/SubwaySurf/SubwaySurfManager.cpp | 6 +-- 17 files changed, 122 insertions(+), 74 deletions(-) diff --git a/UnrealProject/Lost_Edge/Config/DefaultEngine.ini b/UnrealProject/Lost_Edge/Config/DefaultEngine.ini index fbd6426..369b66a 100644 --- a/UnrealProject/Lost_Edge/Config/DefaultEngine.ini +++ b/UnrealProject/Lost_Edge/Config/DefaultEngine.ini @@ -139,6 +139,7 @@ ManualIPAddress= +Profiles=(Name="Vehicle",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="Vehicle",CustomResponses=,HelpMessage="Vehicle object that blocks Vehicle, WorldStatic, and WorldDynamic. All other channels will be set to default.") +Profiles=(Name="UI",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility"),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldStatic object that overlaps all actors by default. All new custom channels will use its own default response. ") +Profiles=(Name="Interactable",CollisionEnabled=QueryAndPhysics,bCanModify=True,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Interactable")),HelpMessage="WorldDynamic objects derived from AInteractable.") ++Profiles=(Name="AgeOfWarUnit",CollisionEnabled=QueryOnly,bCanModify=True,ObjectTypeName="Vehicle",CustomResponses=((Channel="WorldStatic",Response=ECR_Ignore),(Channel="WorldDynamic",Response=ECR_Ignore),(Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore),(Channel="PhysicsBody",Response=ECR_Ignore),(Channel="Destructible",Response=ECR_Ignore)),HelpMessage="Minigame object") +DefaultChannelResponses=(Channel=ECC_GameTraceChannel1,DefaultResponse=ECR_Ignore,bTraceType=True,bStaticObject=False,Name="Interactable") -ProfileRedirects=(OldName="BlockingVolume",NewName="InvisibleWall") -ProfileRedirects=(OldName="InterpActor",NewName="IgnoreOnlyPawn") diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Items/BP_CompanionCube.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Items/BP_CompanionCube.uasset index b8610db..ba9951d 100644 --- a/UnrealProject/Lost_Edge/Content/Blueprints/Items/BP_CompanionCube.uasset +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Items/BP_CompanionCube.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2b9660bb6e1de93ac49a75a29779ac8bbac2f4230b1aec0f7eca4604a8f79467 -size 23557 +oid sha256:1195d0ee2ffdfd23b58c5b83519c0c26bf91b3df3a623d52411462876b9d9848 +size 25381 diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/BP_Minigame_AgeOfWar.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/BP_Minigame_AgeOfWar.uasset index 895e73b..35f9a4f 100644 --- a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/BP_Minigame_AgeOfWar.uasset +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/BP_Minigame_AgeOfWar.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bfba9f57eeadaeb16c2816753739eddb5d4998c706c1d37265019f3d367bf8db -size 117797 +oid sha256:eb79e9917fe826eb430ee33c9f2f3899bab8a193eb230ce24017fb13c4179e7f +size 366061 diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/UI_Minigame_AgeOfWar.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/UI_Minigame_AgeOfWar.uasset index 3ff9b75..71b6ab2 100644 --- a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/UI_Minigame_AgeOfWar.uasset +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/UI_Minigame_AgeOfWar.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:af517d6e39525d50ced0a91902c5c66cee5ccd9163f437b383490274c8f10e24 -size 152299 +oid sha256:48d61e4adb9f190548560d1e42f2d07c60564a988ba877f70e528c204e544709 +size 181823 diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_Base.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_Base.uasset index 8a670fd..d0c20a2 100644 --- a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_Base.uasset +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_Base.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fc5241f0309901748105c0db83cf1816e1967ed59b581585fc2d30592a891ade -size 21133 +oid sha256:12a1a84218555e73e3f9ef1f3db30bf3e1ca2b427a041839128f111e97d80263 +size 23941 diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstMelee.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstMelee.uasset index 179cd0e..aaadec9 100644 --- a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstMelee.uasset +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstMelee.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e97530e0d19c9723523efe8e89dc6041bb2d402d66077f62603271811148d857 -size 20500 +oid sha256:905f95b9ba7239185a27a95f0dc44c394705c7ae7c1edf38274a29cb8d5eeed7 +size 23343 diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstRange.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstRange.uasset index 716efd6..1766f2a 100644 --- a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstRange.uasset +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstRange.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8c8ca38d1d4d1e8df6ce890237d4ec03c3a28fcd9caaf9ca5743943132710b79 -size 22390 +oid sha256:685d868675c82a533270e268390749c68bd14f8d1d08059ee090a24748e2998d +size 26335 diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstTank.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstTank.uasset index 85233d4..8e12740 100644 --- a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstTank.uasset +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstTank.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:47e26221cdcd59092d748bcf7aac3c452cd4a0426d5f1c9a2fc1213e96b52b68 -size 21087 +oid sha256:8202a38d55de0cc6f348780d036e2c08fcc2d0860e28ce6649346ec71989f49a +size 23930 diff --git a/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap b/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap index 278e2c4..435c279 100644 --- a/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap +++ b/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:26ba9021d327e31a02433e566da5b6428681e17f2ae92ad100200f30c073dea3 -size 2257698 +oid sha256:bdd549e2cfccd08d1cf7a9347d806405311dbd11d371bb8677428ef5aba7f9ed +size 2265093 diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Interactable/Interactable.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Interactable/Interactable.cpp index 832cae8..1094c03 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Interactable/Interactable.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Interactable/Interactable.cpp @@ -55,25 +55,25 @@ void AInteractable::BeginPlay() } } - GetComponents(meshes); - for(auto mesh : meshes) + GetComponents(collisions, true); + for(auto collision : collisions) { if(activatorTypes) { - mesh->SetCollisionProfileName(TEXT("Interactable")); + collision->SetCollisionProfileName(TEXT("Interactable")); } if(activatorTypes & static_cast(EActivatorType::Saw)) { - mesh->CustomDepthStencilValue = 128; - mesh->CustomDepthStencilWriteMask = ERendererStencilMask::ERSM_Default; - mesh->SetRenderCustomDepth(true); + collision->CustomDepthStencilValue = 128; + collision->CustomDepthStencilWriteMask = ERendererStencilMask::ERSM_Default; + collision->SetRenderCustomDepth(true); } if(activatorTypes & static_cast(EActivatorType::Use)) { - mesh->CustomDepthStencilWriteMask = ERendererStencilMask::ERSM_Default; - mesh->SetRenderCustomDepth(true); + collision->CustomDepthStencilWriteMask = ERendererStencilMask::ERSM_Default; + collision->SetRenderCustomDepth(true); } } @@ -120,8 +120,8 @@ void AInteractable::_Activate(EActivatorType type) if(activated & static_cast(EActivatorType::Use)) { - for(auto mesh : meshes) - mesh->SetCustomDepthStencilValue(132); + for(auto collision : collisions) + collision->SetCustomDepthStencilValue(132); } Activate(type); @@ -155,8 +155,8 @@ void AInteractable::_Deactivate(EActivatorType type) if(!(activated & static_cast(EActivatorType::Use))) { - for(auto mesh : meshes) - mesh->SetCustomDepthStencilValue(0); + for(auto collision : collisions) + collision->SetCustomDepthStencilValue(0); } Deactivate(type); diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Interactable/Interactable.h b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Interactable/Interactable.h index 33d4358..1b84e93 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Interactable/Interactable.h +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Interactable/Interactable.h @@ -58,7 +58,7 @@ protected: TMap modificators; class APlayerBase* player = nullptr; - TArray meshes; + TArray collisions; }; diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.cpp index 9b01484..7f566a9 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.cpp @@ -4,6 +4,7 @@ #include "AgeOfWarManager.h" #include "Camera/CameraComponent.h" +#include "Components/ChildActorComponent.h" #include "AgeOfWarUnit.h" #include "MainGameModeBase.h" @@ -13,6 +14,8 @@ TMap AAgeOfWarManager::unitStats = {}; const FAgeOfWarUnitStats& AAgeOfWarManager::UnitGetStats(TSubclassOf unitClass) { + check(unitStats.Contains(*unitClass)); + return unitStats[unitClass]; } @@ -21,10 +24,7 @@ AAgeOfWarManager::AAgeOfWarManager() auto root = CreateDefaultSubobject(TEXT("Scene")); camera = CreateDefaultSubobject(TEXT("Camera")); - camera->AttachToComponent(root, FAttachmentTransformRules::KeepRelativeTransform); - - basePlayer = static_cast(CreateDefaultSubobject(TEXT("BasePlayer"), AAgeOfWarUnit::StaticClass(), baseClass, true, false)); - baseComputer = static_cast(CreateDefaultSubobject(TEXT("BaseComputer"), AAgeOfWarUnit::StaticClass(), baseClass, true, false)); + camera->SetupAttachment(root); } void AAgeOfWarManager::Start(APlayerBase* playerPawn, FMinigameEndCallback delegate) @@ -38,6 +38,16 @@ void AAgeOfWarManager::Start(APlayerBase* playerPawn, FMinigameEndCallback deleg player->SwitchToView(this); FillUnitStats(); + TArray units; + GetComponents(units); + for(auto& unit : units) + { + if(auto proxy = Cast(unit->GetChildActor())) + { + proxy->manager = this; + proxy->UpdateStats(); + } + } } void AAgeOfWarManager::End() @@ -50,10 +60,21 @@ void AAgeOfWarManager::End() AMinigame::End(); } -void AAgeOfWarManager::UnitKill(AAgeOfWarUnit* unit) -{} - void AAgeOfWarManager::AddUnitStats(TSubclassOf unitClass, FAgeOfWarUnitStats stats) { unitStats.Add(unitClass, stats); } + +FAgeOfWarUnitStats AAgeOfWarManager::GetUnitStats(TSubclassOf unitClass) +{ + return UnitGetStats(unitClass); +} + +void AAgeOfWarManager::SpawnUnit(TSubclassOf unitClass, FTransform transform, bool computer) +{ + FActorSpawnParameters spawnParams{}; + spawnParams.Owner = this; + auto unit = GetWorld()->SpawnActor(*unitClass, transform, spawnParams); + unit->team = computer ? UnitTeam::AI : UnitTeam::Player; + unit->manager = this; +} diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.h b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.h index 0f9a842..099e729 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.h +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.h @@ -19,27 +19,23 @@ public: virtual void Start(class APlayerBase* playerPawn, FMinigameEndCallback delegate) override; virtual void End() override; - void UnitKill(class AAgeOfWarUnit* unit); + UFUNCTION(BlueprintImplementableEvent) + void OnUnitKill(class AAgeOfWarUnit* unit); protected: UFUNCTION(BlueprintImplementableEvent) void FillUnitStats(); - UFUNCTION(BlueprintCallable) static void AddUnitStats(TSubclassOf unitClass, struct FAgeOfWarUnitStats stats); + UFUNCTION(BlueprintPure) + static struct FAgeOfWarUnitStats GetUnitStats(TSubclassOf unitClass); + + UFUNCTION(BlueprintCallable) + void SpawnUnit(TSubclassOf unitClass, FTransform transform, bool computer = false); static TMap unitStats; UPROPERTY(EditAnywhere) class UCameraComponent* camera; - UPROPERTY(EditDefaultsOnly) - class TSubclassOf baseClass; - UPROPERTY(EditAnywhere) - class AAgeOfWarUnit* basePlayer; - UPROPERTY(EditAnywhere) - class AAgeOfWarUnit* baseComputer; - - - }; diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.cpp index 17ff2bd..efb92fb 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.cpp @@ -3,39 +3,55 @@ #include "AgeOfWarUnit.h" +#include "Components/StaticMeshComponent.h" + #include "AgeOfWarManager.h" +#include const FAgeOfWarUnitStats& AAgeOfWarUnit::GetStats() { if(!stats) stats = &AAgeOfWarManager::UnitGetStats(GetClass()); - if(ensureAlways(stats)) - { - auto errorMsg = FString::Printf(TEXT("AgeOfWarManager instance doesn't contain %s class stats... Destroying actor"), &GetClass()->GetName()); - UE_LOG(LogTemp, Log, TEXT("%s"), *errorMsg); - GEngine->AddOnScreenDebugMessage(-1, 20.0f, FColor::Red, errorMsg); - static FAgeOfWarUnitStats s{}; - stats = &s; - Destroy(); - } - return *stats; } -void AAgeOfWarUnit::BeginPlay() +void AAgeOfWarUnit::UpdateStats() { health = GetStats().health; } +void AAgeOfWarUnit::BeginPlay() +{ + if(manager) + { + UpdateStats(); + } + + Super::BeginPlay(); +} + void AAgeOfWarUnit::EndPlay(const EEndPlayReason::Type EndPlayReason) -{} +{ + Super::EndPlay(EndPlayReason); +} + +AAgeOfWarUnit::AAgeOfWarUnit() +{ + //auto root = CreateDefaultSubobject(TEXT("Scene")); + // + //collision = CreateDefaultSubobject(TEXT("Collision")); + //collision->SetCollisionProfileName(TEXT("AgeOfWarUnit")); + + PrimaryActorTick.bCanEverTick = true; + PrimaryActorTick.bStartWithTickEnabled = true; +} void AAgeOfWarUnit::Tick(float deltaTime) { Super::Tick(deltaTime); - if(GetStats().moveSpeed <= 0) + if(!manager || GetStats().moveSpeed <= 0) return; // move unit forward @@ -68,17 +84,20 @@ void AAgeOfWarUnit::Tick(float deltaTime) lastAttackTimestamp = FPlatformTime::Seconds(); forwardUnit->Damage(GetStats().attackDamage); } + GEngine->AddOnScreenDebugMessage(4, 5.0f, FColor::Yellow, FString::Printf(TEXT("Time %f"), lastAttackTimestamp + GetStats().attackRate - FPlatformTime::Seconds())); } void AAgeOfWarUnit::Damage(const int32 damage) { + GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, FString::Printf(TEXT("Damage %d taken by %s"), damage, *GetClass()->GetName())); + health -= damage; if(health > 0) return; if(IsValid(manager)) - manager->UnitKill(this); + manager->OnUnitKill(this); else Destroy(); } diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.h b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.h index 84f45c8..d1652d5 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.h +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.h @@ -37,35 +37,46 @@ struct FAgeOfWarUnitStats }; +UENUM(BlueprintType) +enum class UnitTeam : uint8 +{ + Player, + AI +}; + UCLASS(Blueprintable, MinimalAPI, Abstract) class AAgeOfWarUnit : public AActor { GENERATED_BODY() public: - enum class UnitTeam - { - Player, - AI - }; + AAgeOfWarUnit(); + virtual void Tick(float deltaTime) override; UFUNCTION(BlueprintPure) const FAgeOfWarUnitStats& GetStats(); - class AAgeOfWarManager* manager = nullptr; + UFUNCTION(BlueprintCallable) + void UpdateStats(); + const FAgeOfWarUnitStats* stats = nullptr; + class AAgeOfWarManager* manager = nullptr; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) UnitTeam team; protected: virtual void BeginPlay() override; virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; - virtual void Tick(float deltaTime) override; void Damage(const int32 damage); AAgeOfWarUnit* forwardUnit = nullptr; private: + UPROPERTY(EditAnywhere) + class UBoxComponent* collision; + int32 health; FTimerHandle attackTimer; double lastAttackTimestamp = 0; diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/CrossyRoad/CrossyRoadManager.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/CrossyRoad/CrossyRoadManager.cpp index 1c6a8e7..c7794e6 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/CrossyRoad/CrossyRoadManager.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/CrossyRoad/CrossyRoadManager.cpp @@ -24,13 +24,13 @@ ACrossyRoadManager::ACrossyRoadManager() auto root = CreateDefaultSubobject(TEXT("Scene")); playerPos = CreateDefaultSubobject(TEXT("PlayerPos")); - playerPos->AttachToComponent(root, FAttachmentTransformRules::KeepRelativeTransform); + playerPos->SetupAttachment(root); camera = CreateDefaultSubobject(TEXT("Camera")); - camera->AttachToComponent(root, FAttachmentTransformRules::KeepRelativeTransform); + camera->SetupAttachment(root); mannequin = CreateDefaultSubobject(TEXT("Mannequin")); - mannequin->AttachToComponent(root, FAttachmentTransformRules::KeepRelativeTransform); + mannequin->SetupAttachment(root); } void ACrossyRoadManager::Start(APlayerBase* playerPawn, FMinigameEndCallback delegate) diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/SubwaySurf/SubwaySurfManager.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/SubwaySurf/SubwaySurfManager.cpp index 16b8f00..9b0746a 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/SubwaySurf/SubwaySurfManager.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/SubwaySurf/SubwaySurfManager.cpp @@ -24,13 +24,13 @@ ASubwaySurfManager::ASubwaySurfManager() auto root = CreateDefaultSubobject(TEXT("Scene")); playerPos = CreateDefaultSubobject(TEXT("PlayerPos")); - playerPos->AttachToComponent(root, FAttachmentTransformRules::KeepRelativeTransform); + playerPos->SetupAttachment(root); camera = CreateDefaultSubobject(TEXT("Camera")); - camera->AttachToComponent(root, FAttachmentTransformRules::KeepRelativeTransform); + camera->SetupAttachment(root); mannequin = CreateDefaultSubobject(TEXT("Mannequin")); - mannequin->AttachToComponent(root, FAttachmentTransformRules::KeepRelativeTransform); + mannequin->SetupAttachment(root); } void ASubwaySurfManager::Start(APlayerBase* playerPawn, FMinigameEndCallback delegate) -- 2.45.2 From 8c01cab7c8f4233afd050b2e05758897c4f1dbcf Mon Sep 17 00:00:00 2001 From: Oleg Petruny Date: Fri, 22 Nov 2024 19:47:34 +0100 Subject: [PATCH 5/5] finalization --- .../Lost_Edge/Config/DefaultEngine.ini | 6 +- .../AgeOfWar/BP_Minigame_AgeOfWar.uasset | 4 +- .../AgeOfWar/UI_Minigame_AgeOfWar.uasset | 4 +- .../BP_Minigame_AgeOfWarUnit_Base.uasset | 4 +- ...BP_Minigame_AgeOfWarUnit_FirstMelee.uasset | 4 +- ...BP_Minigame_AgeOfWarUnit_FirstRange.uasset | 4 +- .../BP_Minigame_AgeOfWarUnit_FirstTank.uasset | 4 +- .../Lost_Edge/Content/Levels/Test/L_Test.umap | 4 +- .../Lost_Edge/Private/CommonFunctions.cpp | 12 +++ .../Lost_Edge/Private/CommonFunctions.h | 2 + .../Minigame/AgeOfWar/AgeOfWarManager.cpp | 17 +++++ .../Minigame/AgeOfWar/AgeOfWarManager.h | 2 + .../Minigame/AgeOfWar/AgeOfWarUnit.cpp | 73 ++++++++++++++++--- .../Private/Minigame/AgeOfWar/AgeOfWarUnit.h | 22 +++++- 14 files changed, 134 insertions(+), 28 deletions(-) diff --git a/UnrealProject/Lost_Edge/Config/DefaultEngine.ini b/UnrealProject/Lost_Edge/Config/DefaultEngine.ini index 369b66a..c9b460d 100644 --- a/UnrealProject/Lost_Edge/Config/DefaultEngine.ini +++ b/UnrealProject/Lost_Edge/Config/DefaultEngine.ini @@ -139,7 +139,8 @@ ManualIPAddress= +Profiles=(Name="Vehicle",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="Vehicle",CustomResponses=,HelpMessage="Vehicle object that blocks Vehicle, WorldStatic, and WorldDynamic. All other channels will be set to default.") +Profiles=(Name="UI",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility"),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldStatic object that overlaps all actors by default. All new custom channels will use its own default response. ") +Profiles=(Name="Interactable",CollisionEnabled=QueryAndPhysics,bCanModify=True,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Interactable")),HelpMessage="WorldDynamic objects derived from AInteractable.") -+Profiles=(Name="AgeOfWarUnit",CollisionEnabled=QueryOnly,bCanModify=True,ObjectTypeName="Vehicle",CustomResponses=((Channel="WorldStatic",Response=ECR_Ignore),(Channel="WorldDynamic",Response=ECR_Ignore),(Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore),(Channel="PhysicsBody",Response=ECR_Ignore),(Channel="Destructible",Response=ECR_Ignore)),HelpMessage="Minigame object") ++Profiles=(Name="AgeOfWarUnitPlayer",CollisionEnabled=QueryOnly,bCanModify=True,ObjectTypeName="Vehicle",CustomResponses=((Channel="WorldStatic",Response=ECR_Ignore),(Channel="WorldDynamic",Response=ECR_Ignore),(Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore),(Channel="PhysicsBody",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore),(Channel="Interactable")),HelpMessage="Minigame object") ++Profiles=(Name="AgeOfWarUnitComputer",CollisionEnabled=QueryOnly,bCanModify=True,ObjectTypeName="Destructible",CustomResponses=((Channel="WorldStatic",Response=ECR_Ignore),(Channel="WorldDynamic",Response=ECR_Ignore),(Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore),(Channel="PhysicsBody",Response=ECR_Ignore),(Channel="Destructible",Response=ECR_Ignore),(Channel="Interactable")),HelpMessage="Minigame object") +DefaultChannelResponses=(Channel=ECC_GameTraceChannel1,DefaultResponse=ECR_Ignore,bTraceType=True,bStaticObject=False,Name="Interactable") -ProfileRedirects=(OldName="BlockingVolume",NewName="InvisibleWall") -ProfileRedirects=(OldName="InterpActor",NewName="IgnoreOnlyPawn") @@ -151,6 +152,9 @@ ManualIPAddress= +ProfileRedirects=(OldName="StaticMeshComponent",NewName="BlockAllDynamic") +ProfileRedirects=(OldName="SkeletalMeshActor",NewName="PhysicsActor") +ProfileRedirects=(OldName="InvisibleActor",NewName="InvisibleWallDynamic") ++ProfileRedirects=(OldName="AgeOfWarUnitComputer",NewName="AgeOfWarUnitPlayerZone") ++ProfileRedirects=(OldName="AgeOfWarUnit",NewName="AgeOfWarUnitPlayer") ++ProfileRedirects=(OldName="AgeOfWarUnitPlayerZone",NewName="AgeOfWarUnitComputer") -CollisionChannelRedirects=(OldName="Static",NewName="WorldStatic") -CollisionChannelRedirects=(OldName="Dynamic",NewName="WorldDynamic") -CollisionChannelRedirects=(OldName="VehicleMovement",NewName="Vehicle") diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/BP_Minigame_AgeOfWar.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/BP_Minigame_AgeOfWar.uasset index 35f9a4f..8ae7155 100644 --- a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/BP_Minigame_AgeOfWar.uasset +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/BP_Minigame_AgeOfWar.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:eb79e9917fe826eb430ee33c9f2f3899bab8a193eb230ce24017fb13c4179e7f -size 366061 +oid sha256:5e9165dea307bfecba98443cb3889799bc4f656fc85e226377392c4fd839cea0 +size 496980 diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/UI_Minigame_AgeOfWar.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/UI_Minigame_AgeOfWar.uasset index 71b6ab2..08c3412 100644 --- a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/UI_Minigame_AgeOfWar.uasset +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/UI_Minigame_AgeOfWar.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:48d61e4adb9f190548560d1e42f2d07c60564a988ba877f70e528c204e544709 -size 181823 +oid sha256:bd73e8683b46355038b4921e52202d05b44eebfd571f83a1feb38656267e960d +size 212213 diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_Base.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_Base.uasset index d0c20a2..19d16fb 100644 --- a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_Base.uasset +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_Base.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:12a1a84218555e73e3f9ef1f3db30bf3e1ca2b427a041839128f111e97d80263 -size 23941 +oid sha256:9be205b5bf17894060db9e19a165ef429b0a0a01286c0e166db769dc45376b9b +size 42295 diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstMelee.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstMelee.uasset index aaadec9..38b45f8 100644 --- a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstMelee.uasset +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstMelee.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:905f95b9ba7239185a27a95f0dc44c394705c7ae7c1edf38274a29cb8d5eeed7 -size 23343 +oid sha256:a6f29c6ad1559cd22960b40f851bb7873a0e923695c2fab06d02db94d7900e3a +size 23540 diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstRange.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstRange.uasset index 1766f2a..777ac8b 100644 --- a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstRange.uasset +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstRange.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:685d868675c82a533270e268390749c68bd14f8d1d08059ee090a24748e2998d -size 26335 +oid sha256:89f21d2809ef7f853839bd572a95c180b5c2668a3243197f9a74bcadc94d6d5d +size 25523 diff --git a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstTank.uasset b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstTank.uasset index 8e12740..06efab6 100644 --- a/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstTank.uasset +++ b/UnrealProject/Lost_Edge/Content/Blueprints/Minigames/AgeOfWar/Units/BP_Minigame_AgeOfWarUnit_FirstTank.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8202a38d55de0cc6f348780d036e2c08fcc2d0860e28ce6649346ec71989f49a -size 23930 +oid sha256:6a92537e1f82b2e1745b363b518751a61f9efefb223159701950f1f835e1b469 +size 23008 diff --git a/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap b/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap index 435c279..33667b3 100644 --- a/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap +++ b/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bdd549e2cfccd08d1cf7a9347d806405311dbd11d371bb8677428ef5aba7f9ed -size 2265093 +oid sha256:6d6d75c266fe70db878a1a4c8ad461c4f31dd3c92662074f083295eff4bf0d13 +size 2265074 diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CommonFunctions.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CommonFunctions.cpp index 6248b2e..3a5e4fa 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CommonFunctions.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CommonFunctions.cpp @@ -39,6 +39,18 @@ void UCommonFunctions::DestroyActorRecursively(AActor* actor) actor->Destroy(); } +TArray UCommonFunctions::GetRandomIntArray(int32 size, int32 min, int32 max) +{ + if(size <= 0) + return {}; + + TArray arr; + arr.Reserve(size); + for(int32 i = 0; i < size; ++i) + arr.Add(FMath::RandRange(min, max)); + return arr; +} + ALevelBase* UCommonFunctions::GetCurrentLevelScript(UObject* obj) diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CommonFunctions.h b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CommonFunctions.h index 903cead..b5c9b17 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CommonFunctions.h +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CommonFunctions.h @@ -21,6 +21,8 @@ public: UFUNCTION(BlueprintCallable, Category = Actor) static void DestroyActorRecursively(class AActor* actor); + UFUNCTION(BlueprintPure) + static TArray GetRandomIntArray(int32 size = 16, int32 min = 0, int32 max = 16); UFUNCTION(BlueprintCallable, Category = Level) diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.cpp index 7f566a9..659903b 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.cpp @@ -15,6 +15,11 @@ TMap AAgeOfWarManager::unitStats = {}; const FAgeOfWarUnitStats& AAgeOfWarManager::UnitGetStats(TSubclassOf unitClass) { check(unitStats.Contains(*unitClass)); + //if(!unitStats.Contains(*unitClass)) + //{ + // static FAgeOfWarUnitStats empty; + // return empty; + //} return unitStats[unitClass]; } @@ -52,6 +57,10 @@ void AAgeOfWarManager::Start(APlayerBase* playerPawn, FMinigameEndCallback deleg void AAgeOfWarManager::End() { + for(auto& unit : spawnedUnits) + unit->Destroy(); + spawnedUnits.Empty(); + unitStats.Empty(); player->ReturnPlayerView(); @@ -60,6 +69,12 @@ void AAgeOfWarManager::End() AMinigame::End(); } +void AAgeOfWarManager::UnitKill(AAgeOfWarUnit* unit) +{ + OnUnitKill(unit); + spawnedUnits.Remove(unit); +} + void AAgeOfWarManager::AddUnitStats(TSubclassOf unitClass, FAgeOfWarUnitStats stats) { unitStats.Add(unitClass, stats); @@ -77,4 +92,6 @@ void AAgeOfWarManager::SpawnUnit(TSubclassOf unitClass, FTransfor auto unit = GetWorld()->SpawnActor(*unitClass, transform, spawnParams); unit->team = computer ? UnitTeam::AI : UnitTeam::Player; unit->manager = this; + unit->UpdateStats(); + spawnedUnits.Add(unit); } diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.h b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.h index 099e729..dbcdcb9 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.h +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarManager.h @@ -19,6 +19,7 @@ public: virtual void Start(class APlayerBase* playerPawn, FMinigameEndCallback delegate) override; virtual void End() override; + void UnitKill(class AAgeOfWarUnit* unit); UFUNCTION(BlueprintImplementableEvent) void OnUnitKill(class AAgeOfWarUnit* unit); @@ -38,4 +39,5 @@ protected: UPROPERTY(EditAnywhere) class UCameraComponent* camera; + TSet spawnedUnits; }; diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.cpp index efb92fb..88a4826 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.cpp @@ -8,6 +8,13 @@ #include "AgeOfWarManager.h" #include +namespace +{ + constexpr auto PlayerCollision = TEXT("AgeOfWarUnitPlayer"); + constexpr auto ComputerCollision = TEXT("AgeOfWarUnitComputer"); + constexpr auto TagNoAuto = TEXT("NoAuto"); +} + const FAgeOfWarUnitStats& AAgeOfWarUnit::GetStats() { if(!stats) @@ -19,6 +26,25 @@ const FAgeOfWarUnitStats& AAgeOfWarUnit::GetStats() void AAgeOfWarUnit::UpdateStats() { health = GetStats().health; + attackStartRange = GetStats().attackStartRange; + + switch(team) + { + case UnitTeam::AI: + root->SetCollisionProfileName(ComputerCollision); + allyblocker->SetCollisionProfileName(PlayerCollision); + break; + case UnitTeam::Player: + root->SetCollisionProfileName(PlayerCollision); + allyblocker->SetCollisionProfileName(ComputerCollision); + break; + default: + break; + } + allyblocker->SetBoxExtent(root->GetUnscaledBoxExtent(), false); + allyblocker->SetCollisionEnabled(ECollisionEnabled::NoCollision); + + OnUpdateStats(); } void AAgeOfWarUnit::BeginPlay() @@ -29,6 +55,8 @@ void AAgeOfWarUnit::BeginPlay() } Super::BeginPlay(); + + world = GetWorld(); } void AAgeOfWarUnit::EndPlay(const EEndPlayReason::Type EndPlayReason) @@ -38,10 +66,12 @@ void AAgeOfWarUnit::EndPlay(const EEndPlayReason::Type EndPlayReason) AAgeOfWarUnit::AAgeOfWarUnit() { - //auto root = CreateDefaultSubobject(TEXT("Scene")); - // - //collision = CreateDefaultSubobject(TEXT("Collision")); - //collision->SetCollisionProfileName(TEXT("AgeOfWarUnit")); + root = CreateDefaultSubobject(TEXT("Collision")); + allyblocker = CreateDefaultSubobject(TEXT("AllyBlocker")); + allyblocker->SetupAttachment(root); + traceStart = CreateDefaultSubobject(TEXT("TraceStart")); + traceStart->SetupAttachment(root); + traceStart->AddRelativeLocation(FVector(0, 0, 200)); PrimaryActorTick.bCanEverTick = true; PrimaryActorTick.bStartWithTickEnabled = true; @@ -54,10 +84,26 @@ void AAgeOfWarUnit::Tick(float deltaTime) if(!manager || GetStats().moveSpeed <= 0) return; - // move unit forward + // try move + FHitResult moveHit; auto moveStep = GetActorForwardVector() * GetStats().moveSpeed; + this->AddActorWorldOffset(moveStep, true, &moveHit, ETeleportType::None); + if(moveHit.bBlockingHit) + allyblocker->SetCollisionEnabled(ECollisionEnabled::QueryOnly); + else + allyblocker->SetCollisionEnabled(ECollisionEnabled::NoCollision); + + // look for units forward FHitResult hit; - this->AddActorWorldOffset(moveStep, true, &hit, ETeleportType::None); + auto startLocation = traceStart->GetComponentLocation(); + auto endLocation = startLocation + (GetActorRotation().Vector() * attackStartRange * (moveHit.bBlockingHit ? 5 : 1)); + world->LineTraceSingleByChannel( + hit, + startLocation, + endLocation, + ECollisionChannel::ECC_GameTraceChannel1 + ); + DrawDebugLine(GetWorld(), startLocation, endLocation, FColor::Red, false, deltaTime * 10, 0, 4.0f); // check if blocked if(!hit.bBlockingHit) @@ -71,7 +117,7 @@ void AAgeOfWarUnit::Tick(float deltaTime) } // iterate to attackable unit - for(int i = 1; forwardUnit->team == team && i < GetStats().attackDistance; i += forwardUnit->GetStats().unitSize) + for(int i = 1; forwardUnit->team == team && i < GetStats().attackUnitDistance; i += forwardUnit->GetStats().unitSize) forwardUnit = forwardUnit->forwardUnit; // if forward unit is in the same team skip attack @@ -89,15 +135,24 @@ void AAgeOfWarUnit::Tick(float deltaTime) void AAgeOfWarUnit::Damage(const int32 damage) { - GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, FString::Printf(TEXT("Damage %d taken by %s"), damage, *GetClass()->GetName())); + if(killed) + return; + + GEngine->AddOnScreenDebugMessage((int32)GetClass()->GetUniqueID(), 5.0f, FColor::Yellow, FString::Printf(TEXT("%d"), health)); health -= damage; if(health > 0) return; + killed = true; + if(IsValid(manager)) - manager->OnUnitKill(this); + { + manager->UnitKill(this); + } else + { Destroy(); + } } diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.h b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.h index d1652d5..1184f8e 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.h +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/AgeOfWar/AgeOfWarUnit.h @@ -27,7 +27,10 @@ struct FAgeOfWarUnitStats int32 attackDamage = 1; UPROPERTY(EditAnywhere, BlueprintReadWrite) - int32 attackDistance = 1; + int32 attackUnitDistance = 1; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + float attackStartRange = 100; UPROPERTY(EditAnywhere, BlueprintReadWrite) float attackRate = 1.0f; @@ -69,17 +72,28 @@ protected: virtual void BeginPlay() override; virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; + UFUNCTION(BlueprintImplementableEvent) + void OnUpdateStats(); + void Damage(const int32 damage); AAgeOfWarUnit* forwardUnit = nullptr; -private: - UPROPERTY(EditAnywhere) - class UBoxComponent* collision; + UPROPERTY(EditAnywhere, BlueprintReadWrite) + class UBoxComponent* root; + UPROPERTY(EditAnywhere, BlueprintReadWrite) + class UBoxComponent* allyblocker; + UPROPERTY(EditAnywhere) + class USceneComponent* traceStart; + +private: int32 health; + float attackStartRange; FTimerHandle attackTimer; double lastAttackTimestamp = 0; + UWorld* world; + bool killed = false; }; -- 2.45.2