Skip to content

Commit

Permalink
#0 Added Shooting Range stats (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
xthebat authored Feb 17, 2024
1 parent 1103bc8 commit 2618f4d
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 1 deletion.
Binary file modified Content/Blueprints/Character/BP_Cloud9Character.uasset
Binary file not shown.
Binary file modified Content/Blueprints/Character/Ball/BP_BallShootingRange.uasset
Binary file not shown.
Binary file not shown.
Binary file modified Content/Maps/warmup.umap
Binary file not shown.
3 changes: 2 additions & 1 deletion Source/Cloud9/Cloud9.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public Cloud9(ReadOnlyTargetRules Target) : base(Target)
"NavigationSystem",
"DeveloperSettings",
"AIModule",
"Niagara"
"Niagara",
"UMG"
});

// CppStandard = CppStandardVersion.Cpp17;
Expand Down
29 changes: 29 additions & 0 deletions Source/Cloud9/Environment/Cloud9ShootingRange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,45 @@
#include "Cloud9/Tools/Extensions/FVector.h"
#include "Cloud9/Tools/Extensions/TContainer.h"
#include "Components/BoxComponent.h"
#include "Components/WidgetComponent.h"

FName ACloud9ShootingRange::ZoneComponentName = "ZoneComponentName";
FName ACloud9ShootingRange::WidgetComponentName = "WidgetComponentName";

ACloud9ShootingRange::ACloud9ShootingRange()
{
PrimaryActorTick.bCanEverTick = true;
ZoneComponent = CreateDefaultSubobject<UBoxComponent>(ZoneComponentName);
WidgetComponent = CreateDefaultSubobject<UWidgetComponent>(WidgetComponentName);
WidgetComponent->SetupAttachment(ZoneComponent);
WidgetClass = nullptr;
Template = nullptr;
RootComponent = ZoneComponent;
ZoneSize = {100.0f, 100.0f, 100.0f};
Count = 1;
GridSize = FVector::OneVector;
bIsStarted = false;
TimeElapsed = 0.0f;
Killed = 0;
}

float ACloud9ShootingRange::GetKillPerMinute() const
{
if (FMath::IsNearlyZero(TimeElapsed))
{
return Killed;
}

return Killed / TimeElapsed * 60.0f;
}

void ACloud9ShootingRange::OnConstruction(const FTransform& Transform)
{
Super::OnConstruction(Transform);
ZoneComponent->SetBoxExtent(ZoneSize);
WidgetComponent->SetWidgetClass(WidgetClass);
WidgetComponent->SetRelativeRotation({0.0f, 90.0f, 0.0f});
WidgetComponent->SetDrawSize({ZoneSize.X * 2.0f, ZoneSize.Z * 2.0f});
}

void ACloud9ShootingRange::BeginPlay()
Expand All @@ -33,10 +55,17 @@ void ACloud9ShootingRange::BeginPlay()
void ACloud9ShootingRange::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

if (bIsStarted)
{
TimeElapsed += DeltaTime;
}
}

void ACloud9ShootingRange::OnChildActorDestroyed(AActor* DestroyedActor)
{
bIsStarted = true;
OnTargetDestroyed.Broadcast(++Killed);
Actors.Remove(DestroyedActor);
SpawnShootingActors();
}
Expand Down
25 changes: 25 additions & 0 deletions Source/Cloud9/Environment/Cloud9ShootingRange.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,25 @@
#include "GameFramework/Actor.h"
#include "Cloud9ShootingRange.generated.h"

class UWidgetComponent;
class UBoxComponent;

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnTargetDestroyed, int, Count);

UCLASS()
class CLOUD9_API ACloud9ShootingRange : public AActor
{
GENERATED_BODY()

public:
static FName ZoneComponentName;
static FName WidgetComponentName;

ACloud9ShootingRange();

UFUNCTION(BlueprintCallable)
float GetKillPerMinute() const;

protected:
virtual void OnConstruction(const FTransform& Transform) override;

Expand All @@ -28,15 +35,24 @@ class CLOUD9_API ACloud9ShootingRange : public AActor
UFUNCTION(BlueprintCallable)
void OnChildActorDestroyed(AActor* DestroyedActor);

UPROPERTY(BlueprintAssignable, meta=(AllowPrivateAccess), Category=Events)
FOnTargetDestroyed OnTargetDestroyed;

UPROPERTY(BlueprintReadOnly, Category=Implementation)
UBoxComponent* ZoneComponent;

UPROPERTY(BlueprintReadOnly, Category=Implementation)
UWidgetComponent* WidgetComponent;

UPROPERTY(BlueprintReadOnly, Category=Implementation)
TArray<AActor*> Actors;

UPROPERTY(EditAnywhere, Category=Config)
int Count;

UPROPERTY(EditAnywhere, Category=Config)
UClass* WidgetClass;

UPROPERTY(EditAnywhere, Category=Config)
UClass* Template;

Expand All @@ -46,6 +62,15 @@ class CLOUD9_API ACloud9ShootingRange : public AActor
UPROPERTY(EditAnywhere, Category=Config)
FVector GridSize;

UPROPERTY(BlueprintReadOnly, meta=(AllowPrivateAccess), Category=Info)
bool bIsStarted;

UPROPERTY(BlueprintReadOnly, meta=(AllowPrivateAccess), Category=Info)
int Killed;

UPROPERTY(BlueprintReadOnly, meta=(AllowPrivateAccess), Category=Info)
float TimeElapsed;

private:
bool SpawnShootingActors();
};

0 comments on commit 2618f4d

Please sign in to comment.