From 5adafd6519ecb10220701184a9bd8c611229445f Mon Sep 17 00:00:00 2001 From: baz Date: Thu, 17 Apr 2025 23:05:44 +0100 Subject: [PATCH] Add base implementation of SwarmWeapon Still need to implement the Swarm actors --- Content/Weapons/Swarm/BP_SwarmActor.uasset | 3 + Content/Weapons/Swarm/BP_SwarmWeapon.uasset | 3 + Content/Weapons/Swarm/C_Swarm.uasset | 3 + Source/vampires/Weapons/SwarmWeapon.cpp | 99 +++++++++++++++++++++ Source/vampires/Weapons/SwarmWeapon.h | 51 +++++++++++ 5 files changed, 159 insertions(+) create mode 100644 Content/Weapons/Swarm/BP_SwarmActor.uasset create mode 100644 Content/Weapons/Swarm/BP_SwarmWeapon.uasset create mode 100644 Content/Weapons/Swarm/C_Swarm.uasset create mode 100644 Source/vampires/Weapons/SwarmWeapon.cpp create mode 100644 Source/vampires/Weapons/SwarmWeapon.h diff --git a/Content/Weapons/Swarm/BP_SwarmActor.uasset b/Content/Weapons/Swarm/BP_SwarmActor.uasset new file mode 100644 index 0000000..82fe8e9 --- /dev/null +++ b/Content/Weapons/Swarm/BP_SwarmActor.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:acd6b510083a053b08bfafc26e2a96b746e2fd9af490034fa10de6216cf99751 +size 25667 diff --git a/Content/Weapons/Swarm/BP_SwarmWeapon.uasset b/Content/Weapons/Swarm/BP_SwarmWeapon.uasset new file mode 100644 index 0000000..46138b4 --- /dev/null +++ b/Content/Weapons/Swarm/BP_SwarmWeapon.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f3d0ef2726f97d3a8a165d47984754523e455433cc2185baa91ced52c0c026fc +size 24287 diff --git a/Content/Weapons/Swarm/C_Swarm.uasset b/Content/Weapons/Swarm/C_Swarm.uasset new file mode 100644 index 0000000..2b32d15 --- /dev/null +++ b/Content/Weapons/Swarm/C_Swarm.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1f58ddf698ce82444c57564f5cd4725033f80fa02715644a697f4c0cea9a56da +size 4948 diff --git a/Source/vampires/Weapons/SwarmWeapon.cpp b/Source/vampires/Weapons/SwarmWeapon.cpp new file mode 100644 index 0000000..9138718 --- /dev/null +++ b/Source/vampires/Weapons/SwarmWeapon.cpp @@ -0,0 +1,99 @@ +// Louis Hobbs | 2024-2025 + + +#include "SwarmWeapon.h" + +#include "VectorTypes.h" +#include "Kismet/KismetSystemLibrary.h" +#include "vampires/EnemyCharacter.h" + + +// Sets default values +ASwarmWeapon::ASwarmWeapon() +{ + // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. + PrimaryActorTick.bCanEverTick = false; + + TimelineComponent = CreateDefaultSubobject("TimelineComponent"); + TimelineComponent->SetDirectionPropertyName(FName("TimelineDirection")); + TimelineComponent->SetLooping(true); + TimelineComponent->SetTimelineLength(1.0f); + TimelineComponent->SetTimelineLengthMode(TL_TimelineLength); + TimelineComponent->SetPlaybackPosition(0.0f, false); + + onTimelineCallback.BindUFunction(this, FName(TEXT("TimelineCallback"))); +} + +// Called when the game starts or when spawned +void ASwarmWeapon::BeginPlay() +{ + Super::BeginPlay(); + + // Spawn the swarm actors in + SwarmActors.Add(GetWorld()->SpawnActor(SwarmActor)); + SwarmActors.Add(GetWorld()->SpawnActor(SwarmActor)); + + // Start the timeline + if (SwarmCurve != nullptr) + { + TimelineComponent->AddInterpFloat(SwarmCurve, onTimelineCallback); + } + + TimelineComponent->SetPlayRate(TimelinePlayRate); + TimelineComponent->PlayFromStart(); + +} + +void ASwarmWeapon::TimelineCallback(float val) +{ + float num = SwarmActors.Num(); + + for (int i = 0; i < num; i++) + { + float actorIndex = (i + 1); + float offset = (actorIndex / num) * 360.0f; + FVector CenterLocation = GetActorLocation(); + FVector Direction = FVector(0.0, 1, 0.0); + FVector RotatedDirection = Direction.RotateAngleAxis(val * 360.0f + offset, FVector(0.0f, 0.0f, 1.0f)); + FVector NewLocation = CenterLocation + (RotatedDirection * Distance); + SwarmActors[i]->SetActorLocation(NewLocation); + } +} + +bool ASwarmWeapon::UpgradeWeapon_Implementation() +{ + if (!Super::UpgradeWeapon_Implementation()) return false; + + switch (CurrentLevel) + { + case 1: + SwarmActors.Add(GetWorld()->SpawnActor(SwarmActor)); + break; + case 2: + Distance *= 1.25f; + TimelineComponent->SetPlayRate(TimelineComponent->GetPlayRate() * 1.3f); + break; + case 3: + Damage += 10; + break; + case 4: + SwarmActors.Add(GetWorld()->SpawnActor(SwarmActor)); + break; + case 5: + Distance *= 1.25f; + TimelineComponent->SetPlayRate(TimelineComponent->GetPlayRate() * 1.3f); + break; + case 6: + Damage += 10; + break; + case 7: + SwarmActors.Add(GetWorld()->SpawnActor(SwarmActor)); + break; + default: + return false; + } + + ResetWeaponTimer(); + return true; +} + diff --git a/Source/vampires/Weapons/SwarmWeapon.h b/Source/vampires/Weapons/SwarmWeapon.h new file mode 100644 index 0000000..36fdfd5 --- /dev/null +++ b/Source/vampires/Weapons/SwarmWeapon.h @@ -0,0 +1,51 @@ +// Louis Hobbs | 2024-2025 + +#pragma once + +#include "CoreMinimal.h" +#include "Components/TimelineComponent.h" +#include "vampires/Weapon.h" +#include "SwarmWeapon.generated.h" + +UCLASS() +class VAMPIRES_API ASwarmWeapon : public AWeapon +{ + GENERATED_BODY() + +public: + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Timeline") + TObjectPtr TimelineComponent = nullptr; + + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) + TObjectPtr SwarmCurve; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + float TimelinePlayRate = 1; + + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) + TSubclassOf SwarmActor; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + float Distance = 250.0f; + + + +private: + FOnTimelineFloat onTimelineCallback; + + TArray SwarmActors; + +public: + // Sets default values for this actor's properties + ASwarmWeapon(); + +protected: + // Called when the game starts or when spawned + virtual void BeginPlay() override; + +public: + UFUNCTION() + void TimelineCallback(float val); + + virtual bool UpgradeWeapon_Implementation() override; +};