Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Shooting Range #195

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Content/Blueprints/Character/Ball/BP_Ball.uasset
Binary file not shown.
Binary file not shown.
Binary file modified Content/Maps/warmup.umap
Binary file not shown.
6 changes: 6 additions & 0 deletions Source/Cloud9/Character/Cloud9Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ UCloud9Inventory* ACloud9Character::GetInventory() const { return Inventory; }

UCloud9CharacterHealthComponent* ACloud9Character::GetHealthComponent() const { return HealthComponent; }

void ACloud9Character::AddScore()
{
Score += 1;
OnScoreChanged.Broadcast(1);
}

void ACloud9Character::UseObject()
{
// TODO: Implement UseObject
Expand Down
7 changes: 7 additions & 0 deletions Source/Cloud9/Character/Cloud9Character.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include "Cloud9Character.generated.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnScoreChanged, int, Count);

class UCloud9CharacterHealthComponent;

Expand Down Expand Up @@ -85,6 +86,8 @@ class ACloud9Character : public ACharacter

UCloud9CharacterHealthComponent* GetHealthComponent() const;

void AddScore();

void UseObject();

// Set by character movement to specify that this Character is currently sneaking.
Expand Down Expand Up @@ -125,6 +128,10 @@ class ACloud9Character : public ACharacter
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=State, meta=(AllowPrivateAccess))
UCloud9CharacterHealthComponent* HealthComponent;

/** Event called when character score changed. */
UPROPERTY(BlueprintAssignable, meta=(AllowPrivateAccess), Category=Events)
FOnScoreChanged OnScoreChanged;

/** Current number of frags made by character */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=State, meta=(AllowPrivateAccess))
int Score;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "Cloud9CharacterHealthComponent.h"

#include "Cloud9/Character/Cloud9Character.h"
#include "Cloud9/Tools/Macro/Common.h"
#include "Cloud9/Tools/Macro/Logging.h"

Expand Down Expand Up @@ -114,6 +115,12 @@ void UCloud9CharacterHealthComponent::OnTakePointDamage(
{
TakeHealthDamage(Damage); // TODO: Add factor by armor
TakeArmorDamage(0.0f); // TODO: Add armor damage calc

if (DamagedActor->IsPendingKill())
{
log(Display, "DamageCauser=%s", *DamageCauser->GetOwner()->GetName());
Cast<ACloud9Character>(DamageCauser->GetOwner())->AddScore();
}
}

void UCloud9CharacterHealthComponent::OnTakeRadialDamage(
Expand Down
27 changes: 24 additions & 3 deletions Source/Cloud9/Environment/Cloud9ShootingRange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,42 +27,63 @@ void ACloud9ShootingRange::OnConstruction(const FTransform& Transform)
void ACloud9ShootingRange::BeginPlay()
{
Super::BeginPlay();
SpawnShootingActors();
}

void ACloud9ShootingRange::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}

void ACloud9ShootingRange::OnChildActorDestroyed(AActor* DestroyedActor)
{
Actors.Remove(DestroyedActor);
SpawnShootingActors();
}

bool ACloud9ShootingRange::SpawnShootingActors()
{
if (not IsValid(Template))
{
log(Error, "Actor class not specified!");
return false;
}

int Retries = 0;
FVector Origin;
FVector BoxExtent;
GetActorBounds(false, Origin, BoxExtent);
while (Actors.Num() != Count)
{
// GridSize items can be zero (GridSnap should handle it)
let Location = EFVector::Random(BoxExtent - Origin, BoxExtent + Origin, GridSize);
let Actor = GetWorld()->SpawnActor(Class.Get(), &Location);
let Location = EFVector::Random(Origin - BoxExtent, Origin + BoxExtent, GridSize);
let Actor = GetWorld()->SpawnActor(Template, &Location, nullptr);

if (not IsValid(Actor))
{
log(Fatal, "Can't spawn actor at location = %s", *Location.ToString());
return false;
}

if (Actors | ETContainer::AnyByPredicate{[Actor](let It) { return It->IsOverlappingActor(Actor); }})
{
Actor->Destroy();

if (constexpr int MaxRetries = 10; Retries++ == MaxRetries)
{
log(
Error,
"[Range=%s] parameters seems to be invalid can't spawn specified count of Actors = %d",
*GetName(), Count
);
SetActorTickEnabled(false);
return false;
}

continue;
}

Actors.Add(Actor);
Actor->OnDestroyed.AddDynamic(this, &ACloud9ShootingRange::OnChildActorDestroyed);
}

return true;
Expand Down
5 changes: 4 additions & 1 deletion Source/Cloud9/Environment/Cloud9ShootingRange.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class CLOUD9_API ACloud9ShootingRange : public AActor

virtual void Tick(float DeltaTime) override;

UFUNCTION(BlueprintCallable)
void OnChildActorDestroyed(AActor* DestroyedActor);

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

Expand All @@ -35,7 +38,7 @@ class CLOUD9_API ACloud9ShootingRange : public AActor
int Count;

UPROPERTY(EditAnywhere, Category=Config)
TSoftClassPtr<AActor> Class;
UClass* Template;

UPROPERTY(EditAnywhere, Category=Config)
FVector ZoneSize;
Expand Down