Skip to content

Commit

Permalink
#248 Added invulnerability for shield effect
Browse files Browse the repository at this point in the history
  • Loading branch information
xthebat committed Apr 29, 2024
1 parent bd6cf8c commit 8d86201
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 29 deletions.
16 changes: 10 additions & 6 deletions Source/Cloud9/Character/Components/Cloud9EffectsComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,29 @@ bool UCloud9EffectsComponent::RemoveEffect(UCloud9CharacterEffectTrait* Effect)
return true;
}

void UCloud9EffectsComponent::OnRegister()
UCloud9HealthComponent* UCloud9EffectsComponent::GetHealthComponent() const
{
Super::OnRegister();

let Character = GetOwner<ACloud9Character>();
if (not IsValid(Character))
{
log(Error, "[Component='%s'] Owner is invalid", *GetName());
return;
return nullptr;
}

let HealthComponent = Character->GetHealthComponent();
if (not IsValid(HealthComponent))
{
log(Error, "[Component='%s'] Owner HealthComponent is invalid", *GetName());
return;
return nullptr;
}

HealthComponent->OnHealthChange.AddDynamic(this, &UCloud9EffectsComponent::OnDamageApplied);
return HealthComponent;
}

void UCloud9EffectsComponent::OnComponentCreated()
{
Super::OnComponentCreated();
GetHealthComponent()->OnHealthChange.AddDynamic(this, &UCloud9EffectsComponent::OnDamageApplied);
}

void UCloud9EffectsComponent::OnDamageApplied(float Damage)
Expand Down
5 changes: 4 additions & 1 deletion Source/Cloud9/Character/Components/Cloud9EffectsComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "Cloud9EffectsComponent.generated.h"

class UCloud9HealthComponent;
class UCloud9CharacterEffectTrait;

UCLASS(Blueprintable, meta=(BlueprintSpawnableComponent))
Expand Down Expand Up @@ -40,7 +41,9 @@ class CLOUD9_API UCloud9EffectsComponent : public UActorComponent
UFUNCTION()
void OnDamageApplied(float Damage);

virtual void OnRegister() override;
UCloud9HealthComponent* GetHealthComponent() const;

virtual void OnComponentCreated() override;

virtual void TickComponent(
float DeltaTime,
Expand Down
12 changes: 6 additions & 6 deletions Source/Cloud9/Game/Cloud9GameInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,29 @@ class CLOUD9_API UCloud9GameInstance : public UGameInstance
/**
* Function gets game mode for specified World
*
* WARNING: Can only be used during game (avoid it in OnConstruction and etc)
* WARNING: Can only be used during game (avoid it in OnConstruction, etc.)
*/
static ACloud9GameMode* GetGameMode(const UWorld* World);

/**
* Function gets specialized type of game mode for specified World
* Function gets a specialized type of game mode for specified World
*
* WARNING: Can only be used during game (avoid it in OnConstruction and etc)
* WARNING: Can only be used during game (avoid it in OnConstruction, etc.)
*/
template <typename GameModeType = ACloud9GameMode>
static GameModeType* GetGameMode(const UWorld* World) { return Cast<GameModeType>(GetGameMode(World)); }

/**
* Function gets current game mode
*
* WARNING: Can only be used during game (avoid it in OnConstruction and etc)
* WARNING: Can only be used during game (avoid it in OnConstruction, etc.)
*/
ACloud9GameMode* GetGameMode() const { return GetGameMode(GetWorld()); }

/**
* Function gets specialized type of current game mode
* Function gets a specialized type of current game mode
*
* WARNING: Can only be used during game (avoid it in OnConstruction and etc)
* WARNING: Can only be used during game (avoid it in OnConstruction, etc.)
*/
template <typename GameModeType = ACloud9GameMode>
GameModeType* GetGameMode() const { return Cast<GameModeType>(GetGameMode()); }
Expand Down
13 changes: 8 additions & 5 deletions Source/Cloud9/Modes/Cloud9DefaultGameMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "Cloud9DefaultGameMode.h"

#include "EngineUtils.h"

#include "Cloud9/Tools/Macro/Common.h"
#include "Cloud9/Tools/Macro/Logging.h"
#include "Cloud9/Game/Cloud9GameInstance.h"
Expand All @@ -10,7 +12,6 @@
// ReSharper disable once CppUnusedIncludeDirective
#include "Cloud9/Character/Components/Cloud9InventoryComponent.h"
// ReSharper disable once CppUnusedIncludeDirective
#include "EngineUtils.h"
#include "Cloud9/Character/Components/Cloud9HealthComponent.h"

FName ACloud9DefaultGameMode::PlayerConfigName = TEXT("God");
Expand Down Expand Up @@ -84,7 +85,9 @@ bool ACloud9DefaultGameMode::OnWorldStart(FSavedInfo& SavedInfo)
| ETContainer::ForEach{
[PlayerConfig, BotConfig](var& Character)
{
if (let Config = Character.IsBotControlled() ? BotConfig : PlayerConfig; Config == nullptr)
let Config = Character.IsPlayerControlled() ? PlayerConfig : BotConfig;

if (Config == nullptr)
{
log(Warning, "[Character='%s'] Initialization skipped cus config wasn't specified",
*Character.GetName());
Expand All @@ -94,10 +97,10 @@ bool ACloud9DefaultGameMode::OnWorldStart(FSavedInfo& SavedInfo)
let Inventory = Character.GetInventoryComponent();
let Health = Character.GetHealthComponent();

Inventory->Initialize(PlayerConfig->WeaponConfigs, PlayerConfig->WeaponSlot);
Health->Initialize(PlayerConfig->HealthConfig);
Inventory->Initialize(Config->WeaponConfigs, Config->WeaponSlot);
Health->Initialize(Config->HealthConfig);

PlayerConfig->Effects | ETContainer::ForEach{
Config->Effects | ETContainer::ForEach{
[&Character](let EffectClass) { Character.AddCharacterEffect(EffectClass); }
};
}
Expand Down
20 changes: 9 additions & 11 deletions Source/Cloud9/Tools/Extensions/TContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace ETIterator
namespace Private_ETContainer
{
template <typename ContainerType>
auto IteratorOf(ContainerType&& Container)
auto MutableIteratorOf(ContainerType&& Container)
{
using FNakedContainerType = typename TDecay<ContainerType>::Type;
using FMutableContainerType = typename TRemoveConst<FNakedContainerType>::Type;
Expand Down Expand Up @@ -100,9 +100,7 @@ namespace ETContainer
constexpr auto operator()(ContainerType<InElementType>&& Self) const
{
var Iterator = Private_ETContainer::TFromIteratorIterator<
InElementType,
ContainerType<InElementType>
>(Self);
InElementType, ContainerType<InElementType>>(Self);
return TSequence<InElementType, decltype(Iterator)>(MoveTemp(Iterator));
}

Expand All @@ -116,7 +114,7 @@ namespace ETContainer
{
if (Self.Num() != 0)
{
return Private_ETContainer::IteratorOf(Self)
return Private_ETContainer::MutableIteratorOf(Self)
| ETIterator::Advance(FMath::RandRange(0, Self.Num() - 1))
| ETIterator::GetValue();
}
Expand Down Expand Up @@ -371,7 +369,7 @@ namespace Private_ETContainer

constexpr TIndexesIterator(ContainerType&& Container, OperatorType&& Operator)
: Container(Container)
, Iterator(IteratorOf(Container))
, Iterator(MutableIteratorOf(Container))
, Operator(Operator) {}

// ReSharper disable once CppMemberFunctionMayBeStatic
Expand Down Expand Up @@ -405,7 +403,7 @@ namespace Private_ETContainer

constexpr TWithIndexIterator(ContainerType&& Container, OperatorType&& Operator)
: Container(Container)
, Iterator(IteratorOf(Container))
, Iterator(MutableIteratorOf(Container))
, Operator(Operator) {}

// ReSharper disable once CppMemberFunctionMayBeStatic
Expand Down Expand Up @@ -448,7 +446,7 @@ namespace Private_ETContainer

constexpr TTransformIterator(ContainerType&& Container, OperatorType&& Operator)
: Container(Container)
, Iterator(IteratorOf(Container))
, Iterator(MutableIteratorOf(Container))
, Operator(Operator) {}

// ReSharper disable once CppMemberFunctionMayBeStatic
Expand Down Expand Up @@ -485,7 +483,7 @@ namespace Private_ETContainer

constexpr TFilterIterator(ContainerType&& Container, OperatorType&& Operator)
: Container(Container)
, Iterator(IteratorOf(Container))
, Iterator(MutableIteratorOf(Container))
, Operator(Operator)
, bIsFound(false) {}

Expand Down Expand Up @@ -536,7 +534,7 @@ namespace Private_ETContainer

constexpr TDropIterator(ContainerType&& Container, OperatorType&& Operator)
: Container(Container)
, Iterator(IteratorOf(Container))
, Iterator(MutableIteratorOf(Container))
, Operator(Operator) {}

constexpr void Initialize()
Expand Down Expand Up @@ -574,7 +572,7 @@ namespace Private_ETContainer

constexpr TTakeIterator(ContainerType&& Container, OperatorType&& Operator)
: Container(Container)
, Iterator(IteratorOf(Container))
, Iterator(MutableIteratorOf(Container))
, Operator(Operator) {}

constexpr void Initialize() {}
Expand Down
2 changes: 2 additions & 0 deletions Source/Cloud9/Weapon/Enums/WeaponAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#pragma once

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

UENUM(BlueprintType)
enum class EWeaponAction : uint8
{
Expand Down

0 comments on commit 8d86201

Please sign in to comment.