Skip to content

Commit

Permalink
#248 WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
xthebat committed Apr 25, 2024
1 parent 5341268 commit c3b755a
Show file tree
Hide file tree
Showing 13 changed files with 191 additions and 129 deletions.
8 changes: 5 additions & 3 deletions Source/Cloud9/Character/Cloud9Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include "Cloud9/Game/Cloud9DeveloperSettings.h"
#include "Cloud9/Contollers//Cloud9PlayerController.h"
#include "Cloud9/Weapon/Classes/Cloud9WeaponBase.h"
#include "Effects/Cloud9CharacterEffectInterface.h"
#include "Cloud9/Character/Effects/Cloud9CharacterEffectTrait.h"
#include "Components/Cloud9InventoryComponent.h"
#include "Components/Cloud9CharacterMovement.h"
#include "Components/Cloud9SpringArmComponent.h"
Expand Down Expand Up @@ -276,12 +276,14 @@ UCloud9HealthComponent* ACloud9Character::GetHealthComponent() const { return He

UCloud9AnimationComponent* ACloud9Character::GetAnimationComponent() const { return AnimationComponent; }

bool ACloud9Character::AddCharacterEffect(TSubclassOf<UCloud9CharacterEffectInterface> EffectClass)
// ReSharper disable once CppMemberFunctionMayBeConst
UCloud9CharacterEffectTrait* ACloud9Character::AddCharacterEffect(TSubclassOf<UCloud9CharacterEffectTrait> EffectClass)
{
return EffectsComponent->AddEffect(EffectClass);
}

bool ACloud9Character::RemoveCharacterEffect(UCloud9EffectsComponent* Effect)
// ReSharper disable once CppMemberFunctionMayBeConst
bool ACloud9Character::RemoveCharacterEffect(UCloud9CharacterEffectTrait* Effect)
{
return EffectsComponent->RemoveEffect(Effect);
}
Expand Down
6 changes: 3 additions & 3 deletions Source/Cloud9/Character/Cloud9Character.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

#include "Cloud9Character.generated.h"

class UCloud9CharacterEffectTrait;
class UCloud9EffectsComponent;
class UCloud9CharacterEffectInterface;
class UWidgetInteractionComponent;
class ACloud9PlayerController;
class UCloud9InventoryComponent;
Expand Down Expand Up @@ -116,9 +116,9 @@ class ACloud9Character : public ACharacter

UCloud9AnimationComponent* GetAnimationComponent() const;

bool AddCharacterEffect(TSubclassOf<UCloud9CharacterEffectInterface> EffectClass);
UCloud9CharacterEffectTrait* AddCharacterEffect(TSubclassOf<UCloud9CharacterEffectTrait> EffectClass);

bool RemoveCharacterEffect(UCloud9EffectsComponent* Effect);
bool RemoveCharacterEffect(UCloud9CharacterEffectTrait* Effect);

void AddScore();

Expand Down
37 changes: 19 additions & 18 deletions Source/Cloud9/Character/Components/Cloud9EffectsComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,40 @@

#include "Cloud9/Character/Components/Cloud9HealthComponent.h"
#include "Cloud9/Character/Cloud9Character.h"
#include "Cloud9/Character/Effects/Cloud9CharacterEffectTrait.h"
#include "Cloud9/Tools/Extensions/TContainer.h"

UCloud9EffectsComponent::UCloud9EffectsComponent()
{
PrimaryComponentTick.bCanEverTick = true;
}

bool UCloud9EffectsComponent::AddEffect(TSubclassOf<UCloud9CharacterEffectInterface> EffectClass)
UCloud9CharacterEffectTrait* UCloud9EffectsComponent::AddEffect(
TSubclassOf<UCloud9CharacterEffectTrait> EffectClass)
{
if (let Effect = NewObject<UObject>(this, EffectClass->StaticClass());
ICloud9CharacterEffectInterface::Execute_CanApply(Effect, this))
if (let Effect = NewObject<UCloud9CharacterEffectTrait>(this, EffectClass->StaticClass()); Effect->CanApply())
{
ICloud9CharacterEffectInterface::Execute_OnApply(Effect, this);
Effect->OnApply();

Effects.Add(Effect);

if (ICloud9CharacterEffectInterface::Execute_CanTick(Effect))
if (Effect->CanTick())
{
CanTickEffects.Add(Effect);
SetComponentTickEnabled(true);
}
else if (ICloud9CharacterEffectInterface::Execute_CanDamaged(Effect))
else if (Effect->CanDamaged())
{
CanDamagedEffects.Add(Effect);
}

return true;
return Effect;
}

return false;
return nullptr;
}

bool UCloud9EffectsComponent::RemoveEffect(UObject* Effect)
bool UCloud9EffectsComponent::RemoveEffect(UCloud9CharacterEffectTrait* Effect)
{
if (Effects.Remove(Effect) == 0)
{
Expand All @@ -52,7 +53,7 @@ bool UCloud9EffectsComponent::RemoveEffect(UObject* Effect)

SetComponentTickEnabled(CanTickEffects.Num() != 0);

ICloud9CharacterEffectInterface::Execute_OnRemove(Effect, this);
Effect->OnRemove();
return true;
}

Expand Down Expand Up @@ -81,14 +82,14 @@ void UCloud9EffectsComponent::OnDamageApplied(float Damage)
{
let Extinguished = CanDamagedEffects
| ETContainer::Filter{
[this, Damage](let It)
[Damage](let It)
{
ICloud9CharacterEffectInterface::Execute_OnApplyDamage(It, this, Damage);
return ICloud9CharacterEffectInterface::Execute_IsExtinguished(It);
It->OnApplyDamage(Damage);
return It->IsExtinguished();
}
} | ETContainer::ToArray{};

// Cache effects to remove
// Cache effects to remove preventing modification during iteration
Extinguished | ETContainer::ForEach{[this](let It) { RemoveEffect(It); }};
}

Expand All @@ -99,13 +100,13 @@ void UCloud9EffectsComponent::TickComponent(
{
let Extinguished = CanTickEffects
| ETContainer::Filter{
[this, DeltaTime](let It)
[DeltaTime](let It)
{
ICloud9CharacterEffectInterface::Execute_OnTick(It, this, DeltaTime);
return ICloud9CharacterEffectInterface::Execute_IsExtinguished(It);
It->OnTick(DeltaTime);
return It->IsExtinguished();
}
} | ETContainer::ToArray{};

// Cache effects to remove
// Cache effects to remove preventing modification during iteration
Extinguished | ETContainer::ForEach{[this](let It) { RemoveEffect(It); }};
}
19 changes: 9 additions & 10 deletions Source/Cloud9/Character/Components/Cloud9EffectsComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"

#include "Cloud9/Character/Effects/Cloud9CharacterEffectInterface.h"

#include "Cloud9EffectsComponent.generated.h"

class UCloud9CharacterEffectTrait;

UCLASS(Blueprintable, meta=(BlueprintSpawnableComponent))
class CLOUD9_API UCloud9EffectsComponent : public UActorComponent
Expand All @@ -18,25 +17,25 @@ class CLOUD9_API UCloud9EffectsComponent : public UActorComponent
public:
UCloud9EffectsComponent();

bool AddEffect(TSubclassOf<UCloud9CharacterEffectInterface> EffectClass);
UCloud9CharacterEffectTrait* AddEffect(TSubclassOf<UCloud9CharacterEffectTrait> EffectClass);

bool RemoveEffect(UObject* Effect);
bool RemoveEffect(UCloud9CharacterEffectTrait* Effect);

private:
UPROPERTY(meta=(MustImplement=ICloud9CharacterEffectInterface))
TSet<UObject*> Effects;
UPROPERTY()
TSet<UCloud9CharacterEffectTrait*> Effects;

/**
* Subset of Effects that may tick
*/
UPROPERTY(meta=(MustImplement=ICloud9CharacterEffectInterface))
TSet<UObject*> CanTickEffects;
UPROPERTY()
TSet<UCloud9CharacterEffectTrait*> CanTickEffects;

/**
* Subset of Effects that can be damaged
*/
UPROPERTY(meta=(MustImplement=ICloud9CharacterEffectInterface))
TSet<UObject*> CanDamagedEffects;
UPROPERTY()
TSet<UCloud9CharacterEffectTrait*> CanDamagedEffects;

UFUNCTION()
void OnDamageApplied(float Damage);
Expand Down
4 changes: 2 additions & 2 deletions Source/Cloud9/Character/Components/Cloud9InventoryComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ class CLOUD9_API UCloud9InventoryComponent : public UActorComponent
bool Initialize(const TArray<FWeaponConfig>& WeaponConfigs, EWeaponSlot WeaponSlot);

/**
* Function selects weapon in new slot.
* Function selects a weapon in new slot.
*
* @param Slot New slot weapon slot.
* @param Instant If set then no animation will be shown and switching will be instant.
* @param Force If set then other weapon will be selected even if animation playing
* @param Force If set, then another weapon will be selected even if animation playing
*/
UFUNCTION(BlueprintCallable)
bool SelectWeapon(EWeaponSlot Slot, bool Instant = false, bool Force = false);
Expand Down

This file was deleted.

45 changes: 0 additions & 45 deletions Source/Cloud9/Character/Effects/Cloud9CharacterEffectInterface.h

This file was deleted.

44 changes: 44 additions & 0 deletions Source/Cloud9/Character/Effects/Cloud9CharacterEffectTrait.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2024 Alexei Gladkikh

#include "Cloud9CharacterEffectTrait.h"

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

#include "Cloud9/Character/Components/Cloud9EffectsComponent.h"

bool UCloud9CharacterEffectTrait::IsExtinguished_Implementation() const { return true; }

void UCloud9CharacterEffectTrait::OnApply_Implementation() {}

void UCloud9CharacterEffectTrait::OnRemove_Implementation() {}

bool UCloud9CharacterEffectTrait::CanApply_Implementation() const { return true; }

bool UCloud9CharacterEffectTrait::CanTick_Implementation() const { return false; }

bool UCloud9CharacterEffectTrait::CanDamaged_Implementation() const { return false; }

void UCloud9CharacterEffectTrait::OnTick_Implementation(float DeltaSeconds) {}

void UCloud9CharacterEffectTrait::OnApplyDamage_Implementation(float Damage) {}

const UCloud9EffectsComponent* UCloud9CharacterEffectTrait::GetContainer() const
{
let MyOuter = GetOuter();

if (not IsValid(MyOuter))
{
log(Fatal, "Effect outer parent object wasn't specified");
return nullptr;
}

let Container = Cast<UCloud9EffectsComponent>(MyOuter);
if (not IsValid(Container))
{
log(Fatal, "Effect outer parent object is invalid");
return nullptr;
}

return Container;
}
60 changes: 60 additions & 0 deletions Source/Cloud9/Character/Effects/Cloud9CharacterEffectTrait.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) 2024 Alexei Gladkikh

#pragma once

#include "CoreMinimal.h"
#include "UObject/Object.h"

#include "Cloud9CharacterEffectTrait.generated.h"

class UCloud9EffectsComponent;

UCLASS()
class CLOUD9_API UCloud9CharacterEffectTrait : public UObject
{
GENERATED_BODY()

public:
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
bool IsExtinguished() const;

UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
void OnApply();

UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
void OnRemove();

UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
bool CanApply() const;

UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
bool CanTick() const;

UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
bool CanDamaged() const;

UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
void OnTick(float DeltaSeconds);

UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
void OnApplyDamage(float Damage);

virtual bool IsExtinguished_Implementation() const;

virtual void OnApply_Implementation();

virtual void OnRemove_Implementation();

virtual bool CanApply_Implementation() const;

virtual bool CanTick_Implementation() const;

virtual bool CanDamaged_Implementation() const;

virtual void OnTick_Implementation(float DeltaSeconds);

virtual void OnApplyDamage_Implementation(float Damage);

protected:
const UCloud9EffectsComponent* GetContainer() const;
};
Loading

0 comments on commit c3b755a

Please sign in to comment.