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; + +}; +