-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
293 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
Source/Cloud9/Character/Components/Cloud9EffectsComponent.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// Copyright (c) 2024 Alexei Gladkikh | ||
|
||
#include "Cloud9EffectsComponent.h" | ||
|
||
#include "Cloud9/Tools/Macro/Common.h" | ||
#include "Cloud9/Tools/Macro/Logging.h" | ||
|
||
#include "Cloud9/Character/Components/Cloud9HealthComponent.h" | ||
#include "Cloud9/Character/Cloud9Character.h" | ||
#include "Cloud9/Tools/Extensions/TContainer.h" | ||
|
||
UCloud9EffectsComponent::UCloud9EffectsComponent() | ||
{ | ||
PrimaryComponentTick.bCanEverTick = true; | ||
} | ||
|
||
bool UCloud9EffectsComponent::AddEffect(TSubclassOf<UCloud9CharacterEffectInterface> EffectClass) | ||
{ | ||
if (let Effect = NewObject<UObject>(this, EffectClass->StaticClass()); | ||
ICloud9CharacterEffectInterface::Execute_CanApply(Effect, this)) | ||
{ | ||
ICloud9CharacterEffectInterface::Execute_OnApply(Effect, this); | ||
|
||
Effects.Add(Effect); | ||
|
||
if (ICloud9CharacterEffectInterface::Execute_CanTick(Effect)) | ||
{ | ||
CanTickEffects.Add(Effect); | ||
SetComponentTickEnabled(true); | ||
} | ||
else if (ICloud9CharacterEffectInterface::Execute_CanDamaged(Effect)) | ||
{ | ||
CanDamagedEffects.Add(Effect); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool UCloud9EffectsComponent::RemoveEffect(UObject* Effect) | ||
{ | ||
if (Effects.Remove(Effect) == 0) | ||
{ | ||
log(Warning, "[Actor='%s'] Effect '%s' not found", *GetName(), *Effect->GetName()); | ||
return false; | ||
} | ||
|
||
CanDamagedEffects.Remove(Effect); | ||
CanTickEffects.Remove(Effect); | ||
|
||
SetComponentTickEnabled(CanTickEffects.Num() != 0); | ||
|
||
ICloud9CharacterEffectInterface::Execute_OnRemove(Effect, this); | ||
return true; | ||
} | ||
|
||
void UCloud9EffectsComponent::OnRegister() | ||
{ | ||
Super::OnRegister(); | ||
|
||
let Character = GetOwner<ACloud9Character>(); | ||
if (not IsValid(Character)) | ||
{ | ||
log(Error, "[Component='%s'] Owner is invalid", *GetName()); | ||
return; | ||
} | ||
|
||
let HealthComponent = Character->GetHealthComponent(); | ||
if (not IsValid(HealthComponent)) | ||
{ | ||
log(Error, "[Component='%s'] Owner HealthComponent is invalid", *GetName()); | ||
return; | ||
} | ||
|
||
HealthComponent->OnHealthChange.AddDynamic(this, &UCloud9EffectsComponent::OnDamageApplied); | ||
} | ||
|
||
void UCloud9EffectsComponent::OnDamageApplied(float Damage) | ||
{ | ||
let Extinguished = CanDamagedEffects | ||
| ETContainer::Filter{ | ||
[this, Damage](let It) | ||
{ | ||
ICloud9CharacterEffectInterface::Execute_OnApplyDamage(It, this, Damage); | ||
return ICloud9CharacterEffectInterface::Execute_IsExtinguished(It); | ||
} | ||
} | ETContainer::ToArray{}; | ||
|
||
// Cache effects to remove | ||
Extinguished | ETContainer::ForEach{[this](let It) { RemoveEffect(It); }}; | ||
} | ||
|
||
void UCloud9EffectsComponent::TickComponent( | ||
float DeltaTime, | ||
ELevelTick TickType, | ||
FActorComponentTickFunction* ThisTickFunction) | ||
{ | ||
let Extinguished = CanTickEffects | ||
| ETContainer::Filter{ | ||
[this, DeltaTime](let It) | ||
{ | ||
ICloud9CharacterEffectInterface::Execute_OnTick(It, this, DeltaTime); | ||
return ICloud9CharacterEffectInterface::Execute_IsExtinguished(It); | ||
} | ||
} | ETContainer::ToArray{}; | ||
|
||
// Cache effects to remove | ||
Extinguished | ETContainer::ForEach{[this](let It) { RemoveEffect(It); }}; | ||
} |
51 changes: 51 additions & 0 deletions
51
Source/Cloud9/Character/Components/Cloud9EffectsComponent.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) 2024 Alexei Gladkikh | ||
|
||
#pragma once | ||
|
||
#include "CoreMinimal.h" | ||
#include "Components/ActorComponent.h" | ||
|
||
#include "Cloud9/Character/Effects/Cloud9CharacterEffectInterface.h" | ||
|
||
#include "Cloud9EffectsComponent.generated.h" | ||
|
||
|
||
UCLASS(Blueprintable, meta=(BlueprintSpawnableComponent)) | ||
class CLOUD9_API UCloud9EffectsComponent : public UActorComponent | ||
{ | ||
GENERATED_BODY() | ||
|
||
public: | ||
UCloud9EffectsComponent(); | ||
|
||
bool AddEffect(TSubclassOf<UCloud9CharacterEffectInterface> EffectClass); | ||
|
||
bool RemoveEffect(UObject* Effect); | ||
|
||
private: | ||
UPROPERTY(meta=(MustImplement=ICloud9CharacterEffectInterface)) | ||
TSet<UObject*> Effects; | ||
|
||
/** | ||
* Subset of Effects that may tick | ||
*/ | ||
UPROPERTY(meta=(MustImplement=ICloud9CharacterEffectInterface)) | ||
TSet<UObject*> CanTickEffects; | ||
|
||
/** | ||
* Subset of Effects that can be damaged | ||
*/ | ||
UPROPERTY(meta=(MustImplement=ICloud9CharacterEffectInterface)) | ||
TSet<UObject*> CanDamagedEffects; | ||
|
||
UFUNCTION() | ||
void OnDamageApplied(float Damage); | ||
|
||
virtual void OnRegister() override; | ||
|
||
virtual void TickComponent( | ||
float DeltaTime, | ||
ELevelTick TickType, | ||
FActorComponentTickFunction* ThisTickFunction | ||
) override; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
Source/Cloud9/Character/Effects/Cloud9CharacterEffectInterface.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Copyright (c) 2024 Alexei Gladkikh | ||
|
||
#include "Cloud9CharacterEffectInterface.h" |
45 changes: 45 additions & 0 deletions
45
Source/Cloud9/Character/Effects/Cloud9CharacterEffectInterface.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) 2024 Alexei Gladkikh | ||
|
||
#pragma once | ||
|
||
#include "CoreMinimal.h" | ||
#include "UObject/Interface.h" | ||
#include "Cloud9CharacterEffectInterface.generated.h" | ||
|
||
class UCloud9EffectsComponent; | ||
|
||
UINTERFACE() | ||
class UCloud9CharacterEffectInterface : public UInterface | ||
{ | ||
GENERATED_BODY() | ||
}; | ||
|
||
class CLOUD9_API ICloud9CharacterEffectInterface | ||
{ | ||
GENERATED_BODY() | ||
|
||
public: | ||
UFUNCTION(BlueprintCallable, BlueprintNativeEvent) | ||
bool IsExtinguished() const; | ||
|
||
UFUNCTION(BlueprintCallable, BlueprintNativeEvent) | ||
bool OnApply(UCloud9EffectsComponent* Container); | ||
|
||
UFUNCTION(BlueprintCallable, BlueprintNativeEvent) | ||
bool OnRemove(UCloud9EffectsComponent* Container); | ||
|
||
UFUNCTION(BlueprintCallable, BlueprintNativeEvent) | ||
bool CanApply(const UCloud9EffectsComponent* Container); | ||
|
||
UFUNCTION(BlueprintCallable, BlueprintNativeEvent) | ||
bool CanTick(); | ||
|
||
UFUNCTION(BlueprintCallable, BlueprintNativeEvent) | ||
bool CanDamaged(); | ||
|
||
UFUNCTION(BlueprintCallable, BlueprintNativeEvent) | ||
void OnTick(const UCloud9EffectsComponent* Container, float DeltaSeconds); | ||
|
||
UFUNCTION(BlueprintCallable, BlueprintNativeEvent) | ||
void OnApplyDamage(const UCloud9EffectsComponent* Container, float Damage); | ||
}; |
Oops, something went wrong.