First Submit

This commit is contained in:
Arnaud Jamin
2023-10-02 01:32:41 -04:00
parent c34574e841
commit 1aabdb5c4e
445 changed files with 93851 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
using UnrealBuildTool;
using System.Collections.Generic;
public class CogSampleTarget : TargetRules
{
public CogSampleTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Game;
DefaultBuildSettings = BuildSettingsVersion.V2;
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_1;
ExtraModuleNames.Add("CogSample");
}
}
@@ -0,0 +1 @@
#include "CogAbilitySystemComponent.h"
@@ -0,0 +1,22 @@
#pragma once
#include "CoreMinimal.h"
#include "AttributeSet.h"
#include "AbilitySystemComponent.h"
#include "CogAbilitySystemComponent.generated.h"
UCLASS(BlueprintType)
class UCogAbilitySystemComponent : public UAbilitySystemComponent
{
GENERATED_BODY()
public:
template <class T>
const T* GetAttributeSet() const
{
UClass* DesiredClass = T::StaticClass();
check(DesiredClass->IsChildOf(UAttributeSet::StaticClass()));
return Cast<T>(Super::GetAttributeSet(DesiredClass));
}
};
+7
View File
@@ -0,0 +1,7 @@
#pragma once
#include "CoreMinimal.h"
#ifndef USE_COG
#define USE_COG (ENABLE_DRAW_DEBUG && !NO_LOGGING)
#endif
+35
View File
@@ -0,0 +1,35 @@
using UnrealBuildTool;
public class CogSample : ModuleRules
{
public CogSample(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[]
{
"CogDebug",
"Core",
"CoreUObject",
"Engine",
"EnhancedInput",
"GameplayAbilities",
"GameplayTags",
"HeadMountedDisplay",
"InputCore",
"NetCore",
});
if (Target.Configuration != UnrealTargetConfiguration.Shipping && Target.Type != TargetRules.TargetType.Server)
{
PublicDependencyModuleNames.AddRange(new string[]
{
"CogImgui",
"CogWindow",
"CogEngine",
"CogInput",
"CogAbility",
});
}
}
}
@@ -0,0 +1,145 @@
#include "CogSampleAttributeSet_Health.h"
#include "CogSampleCharacter.h"
#include "GameplayEffectExtension.h"
#include "Net/Core/PushModel/PushModel.h"
#include "Net/UnrealNetwork.h"
//--------------------------------------------------------------------------------------------------------------------------
UCogSampleAttributeSet_Health::UCogSampleAttributeSet_Health()
{
InitMaxHealth(1000.0f);
InitHealth(1000.0f);
InitHealthRegen(10.0f);
InitMaxArmor(500.f);
InitArmorRegen(0.f);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Health::OnRep_Health(const FGameplayAttributeData& PrevHealth)
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UCogSampleAttributeSet_Health, Health, PrevHealth);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Health::OnRep_MaxHealth(const FGameplayAttributeData& PrevMaxHealth)
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UCogSampleAttributeSet_Health, MaxHealth, PrevMaxHealth);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Health::OnRep_HealthRegen(const FGameplayAttributeData& PrevHealthRegen)
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UCogSampleAttributeSet_Health, HealthRegen, PrevHealthRegen);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Health::OnRep_Armor(const FGameplayAttributeData& PrevArmor)
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UCogSampleAttributeSet_Health, Armor, PrevArmor);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Health::OnRep_MaxArmor(const FGameplayAttributeData& PrevMaxArmor)
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UCogSampleAttributeSet_Health, MaxArmor, PrevMaxArmor);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Health::OnRep_ArmorRegen(const FGameplayAttributeData& PrevArmorRegen)
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UCogSampleAttributeSet_Health, ArmorRegen, PrevArmorRegen);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Health::OnRep_DamageResistance(const FGameplayAttributeData& PrevDamageResistance)
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UCogSampleAttributeSet_Health, DamageResistance, PrevDamageResistance);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Health::GetLifetimeReplicatedProps(TArray<class FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
FDoRepLifetimeParams Params;
Params.bIsPushBased = true;
Params.RepNotifyCondition = REPNOTIFY_Always;
DOREPLIFETIME_WITH_PARAMS_FAST(UCogSampleAttributeSet_Health, Health, Params);
DOREPLIFETIME_WITH_PARAMS_FAST(UCogSampleAttributeSet_Health, MaxHealth, Params);
DOREPLIFETIME_WITH_PARAMS_FAST(UCogSampleAttributeSet_Health, HealthRegen, Params);
DOREPLIFETIME_WITH_PARAMS_FAST(UCogSampleAttributeSet_Health, Armor, Params);
DOREPLIFETIME_WITH_PARAMS_FAST(UCogSampleAttributeSet_Health, MaxArmor, Params);
DOREPLIFETIME_WITH_PARAMS_FAST(UCogSampleAttributeSet_Health, ArmorRegen, Params);
DOREPLIFETIME_WITH_PARAMS_FAST(UCogSampleAttributeSet_Health, DamageResistance, Params);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Health::PreAttributeBaseChange(const FGameplayAttribute& Attribute, float& NewValue) const
{
Super::PreAttributeBaseChange(Attribute, NewValue);
ClampAttributes(Attribute, NewValue);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Health::PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue)
{
Super::PreAttributeChange(Attribute, NewValue);
ClampAttributes(Attribute, NewValue);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Health::PostAttributeChange(const FGameplayAttribute& Attribute, float OldValue, float NewValue)
{
Super::PostAttributeChange(Attribute, OldValue, NewValue);
if (Attribute == GetMaxHealthAttribute())
{
UCogSampleFunctionLibrary_Gameplay::AdjustAttributeForMaxChange(GetOwningAbilitySystemComponent(), Health, OldValue, NewValue, GetHealthAttribute());
}
else if (Attribute == GetMaxArmorAttribute())
{
UCogSampleFunctionLibrary_Gameplay::AdjustAttributeForMaxChange(GetOwningAbilitySystemComponent(), Armor, OldValue, NewValue, GetArmorAttribute());
}
else
{
ClampAttributes(Attribute, NewValue);
}
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Health::PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data)
{
Super::PostGameplayEffectExecute(Data);
ACogSampleCharacter* Character = Cast<ACogSampleCharacter>(Data.Target.AbilityActorInfo->AvatarActor.Get());
const float CurentHealth = GetHealth();
if (CurentHealth <= 0.0f && bOutOfHealth == false)
{
const FGameplayEffectContextHandle& EffectContext = Data.EffectSpec.GetEffectContext();
Character->OnKilled(EffectContext.GetOriginalInstigator(), EffectContext.GetEffectCauser(), Data.EffectSpec, Data.EvaluatedData.Magnitude);
}
else if (CurentHealth > 0.0f && bOutOfHealth)
{
const FGameplayEffectContextHandle& EffectContext = Data.EffectSpec.GetEffectContext();
Character->OnRevived(EffectContext.GetOriginalInstigator(), EffectContext.GetEffectCauser(), Data.EffectSpec, Data.EvaluatedData.Magnitude);
}
bOutOfHealth = CurentHealth <= 0.0f;
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Health::ClampAttributes(const FGameplayAttribute& Attribute, float& NewValue) const
{
if (Attribute == GetHealthAttribute())
{
NewValue = FMath::Clamp(NewValue, 0.0f, GetMaxHealth());
}
else if (Attribute == GetArmorAttribute())
{
NewValue = FMath::Clamp(NewValue, 0.0f, GetMaxArmor());
}
}
@@ -0,0 +1,82 @@
#pragma once
#include "CoreMinimal.h"
#include "AttributeSet.h"
#include "AbilitySystemComponent.h"
#include "CogSampleFunctionLibrary_Gameplay.h"
#include "CogSampleAttributeSet_Health.generated.h"
UCLASS()
class UCogSampleAttributeSet_Health : public UAttributeSet
{
GENERATED_BODY()
public:
friend struct FCogSampleDamageStatics;
UCogSampleAttributeSet_Health();
ATTRIBUTE_ACCESSORS(UCogSampleAttributeSet_Health, Health);
ATTRIBUTE_ACCESSORS(UCogSampleAttributeSet_Health, MaxHealth);
ATTRIBUTE_ACCESSORS(UCogSampleAttributeSet_Health, HealthRegen)
ATTRIBUTE_ACCESSORS(UCogSampleAttributeSet_Health, Armor);
ATTRIBUTE_ACCESSORS(UCogSampleAttributeSet_Health, MaxArmor);
ATTRIBUTE_ACCESSORS(UCogSampleAttributeSet_Health, ArmorRegen)
ATTRIBUTE_ACCESSORS(UCogSampleAttributeSet_Health, DamageResistance)
UFUNCTION()
virtual void OnRep_Health(const FGameplayAttributeData& PrevHealth);
UFUNCTION()
virtual void OnRep_MaxHealth(const FGameplayAttributeData& PrevMaxHealth);
UFUNCTION()
virtual void OnRep_HealthRegen(const FGameplayAttributeData& PrevHealthRegen);
UFUNCTION()
virtual void OnRep_Armor(const FGameplayAttributeData& PrevArmor);
UFUNCTION()
virtual void OnRep_MaxArmor(const FGameplayAttributeData& PrevMaxArmor);
UFUNCTION()
virtual void OnRep_ArmorRegen(const FGameplayAttributeData& PrevArmorRegen);
UFUNCTION()
virtual void OnRep_DamageResistance(const FGameplayAttributeData& PrevDamageResistance);
virtual void GetLifetimeReplicatedProps(TArray<class FLifetimeProperty>& OutLifetimeProps) const override;
virtual void PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue) override;
virtual void PostAttributeChange(const FGameplayAttribute& Attribute, float OldValue, float NewValue) override;
virtual void PreAttributeBaseChange(const FGameplayAttribute& Attribute, float& NewValue) const override;
virtual void PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data) override;
private:
UPROPERTY(BlueprintReadOnly, Category = "Health", ReplicatedUsing = OnRep_Health, meta = (AllowPrivateAccess = "true"))
FGameplayAttributeData Health;
UPROPERTY(BlueprintReadOnly, Category = "Health", ReplicatedUsing = OnRep_MaxHealth, meta = (AllowPrivateAccess = "true"))
FGameplayAttributeData MaxHealth;
UPROPERTY(BlueprintReadOnly, Category = "Health", ReplicatedUsing = OnRep_HealthRegen, meta = (AllowPrivateAccess = "true"))
FGameplayAttributeData HealthRegen;
UPROPERTY(BlueprintReadOnly, Category = "Armor", ReplicatedUsing = OnRep_Armor, meta = (AllowPrivateAccess = "true"))
FGameplayAttributeData Armor;
UPROPERTY(BlueprintReadOnly, Category = "Armor", ReplicatedUsing = OnRep_MaxArmor, meta = (AllowPrivateAccess = "true"))
FGameplayAttributeData MaxArmor;
UPROPERTY(BlueprintReadOnly, Category = "Armor", ReplicatedUsing = OnRep_ArmorRegen, meta = (AllowPrivateAccess = "true"))
FGameplayAttributeData ArmorRegen;
UPROPERTY(BlueprintReadOnly, Category = "Armor", ReplicatedUsing = OnRep_DamageResistance, meta = (AllowPrivateAccess = "true"))
FGameplayAttributeData DamageResistance;
void ClampAttributes(const FGameplayAttribute& Attribute, float& NewValue) const;
bool bOutOfHealth = false;
};
@@ -0,0 +1,64 @@
#include "CogSampleAttributeSet_Misc.h"
#include "Net/Core/PushModel/PushModel.h"
#include "Net/UnrealNetwork.h"
//--------------------------------------------------------------------------------------------------------------------------
UCogSampleAttributeSet_Misc::UCogSampleAttributeSet_Misc()
{
InitScale(1.0f);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Misc::OnRep_Scale(const FGameplayAttributeData& PrevScale)
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UCogSampleAttributeSet_Misc, Scale, PrevScale);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Misc::GetLifetimeReplicatedProps(TArray<class FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
FDoRepLifetimeParams Params;
Params.bIsPushBased = true;
Params.RepNotifyCondition = REPNOTIFY_Always;
DOREPLIFETIME_WITH_PARAMS_FAST(UCogSampleAttributeSet_Misc, Scale, Params);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Misc::PreAttributeBaseChange(const FGameplayAttribute& Attribute, float& NewValue) const
{
Super::PreAttributeBaseChange(Attribute, NewValue);
ClampAttributes(Attribute, NewValue);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Misc::PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue)
{
Super::PreAttributeChange(Attribute, NewValue);
ClampAttributes(Attribute, NewValue);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Misc::PostAttributeChange(const FGameplayAttribute& Attribute, float OldValue, float NewValue)
{
Super::PostAttributeChange(Attribute, OldValue, NewValue);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Misc::PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data)
{
Super::PostGameplayEffectExecute(Data);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Misc::ClampAttributes(const FGameplayAttribute& Attribute, float& NewValue) const
{
if (Attribute == GetScaleAttribute())
{
NewValue = FMath::Clamp(NewValue, 0.15f, 10.0f);
}
}
@@ -0,0 +1,39 @@
#pragma once
#include "CoreMinimal.h"
#include "AttributeSet.h"
#include "AbilitySystemComponent.h"
#include "CogSampleFunctionLibrary_Gameplay.h"
#include "CogSampleAttributeSet_Misc.generated.h"
UCLASS()
class UCogSampleAttributeSet_Misc : public UAttributeSet
{
GENERATED_BODY()
public:
friend struct FCogSampleDamageStatics;
UCogSampleAttributeSet_Misc();
ATTRIBUTE_ACCESSORS(UCogSampleAttributeSet_Misc, Scale);
UFUNCTION()
virtual void OnRep_Scale(const FGameplayAttributeData& PrevScale);
virtual void GetLifetimeReplicatedProps(TArray<class FLifetimeProperty>& OutLifetimeProps) const override;
virtual void PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue) override;
virtual void PostAttributeChange(const FGameplayAttribute& Attribute, float OldValue, float NewValue) override;
virtual void PreAttributeBaseChange(const FGameplayAttribute& Attribute, float& NewValue) const override;
virtual void PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data) override;
private:
UPROPERTY(BlueprintReadOnly, Category = "Scale", ReplicatedUsing = OnRep_Scale, meta = (AllowPrivateAccess = "true"))
FGameplayAttributeData Scale;
void ClampAttributes(const FGameplayAttribute& Attribute, float& NewValue) const;
};
@@ -0,0 +1,87 @@
#include "CogSampleAttributeSet_Speed.h"
#include "Net/Core/PushModel/PushModel.h"
#include "Net/UnrealNetwork.h"
//--------------------------------------------------------------------------------------------------------------------------
UCogSampleAttributeSet_Speed::UCogSampleAttributeSet_Speed()
{
InitSpeed(600.0f);
InitMinSpeed(0.0f);
InitMaxSpeed(5000.0f);
InitMaxAcceleration(2000.0f);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Speed::OnRep_Speed(const FGameplayAttributeData& PrevSpeed)
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UCogSampleAttributeSet_Speed, Speed, PrevSpeed);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Speed::OnRep_MinSpeed(const FGameplayAttributeData& PrevMinSpeed)
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UCogSampleAttributeSet_Speed, MinSpeed, PrevMinSpeed);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Speed::OnRep_MaxSpeed(const FGameplayAttributeData& PrevMaxSpeed)
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UCogSampleAttributeSet_Speed, MaxSpeed, PrevMaxSpeed);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Speed::OnRep_MaxAcceleration(const FGameplayAttributeData& PrevMaxAcceleration)
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UCogSampleAttributeSet_Speed, MaxAcceleration, PrevMaxAcceleration);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Speed::GetLifetimeReplicatedProps(TArray<class FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
FDoRepLifetimeParams Params;
Params.bIsPushBased = true;
Params.RepNotifyCondition = REPNOTIFY_Always;
DOREPLIFETIME_WITH_PARAMS_FAST(UCogSampleAttributeSet_Speed, Speed, Params);
DOREPLIFETIME_WITH_PARAMS_FAST(UCogSampleAttributeSet_Speed, MinSpeed, Params);
DOREPLIFETIME_WITH_PARAMS_FAST(UCogSampleAttributeSet_Speed, MaxSpeed, Params);
DOREPLIFETIME_WITH_PARAMS_FAST(UCogSampleAttributeSet_Speed, MaxAcceleration, Params);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Speed::PreAttributeBaseChange(const FGameplayAttribute& Attribute, float& NewValue) const
{
Super::PreAttributeBaseChange(Attribute, NewValue);
ClampAttributes(Attribute, NewValue);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Speed::PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue)
{
Super::PreAttributeChange(Attribute, NewValue);
ClampAttributes(Attribute, NewValue);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Speed::PostAttributeChange(const FGameplayAttribute& Attribute, float OldValue, float NewValue)
{
Super::PostAttributeChange(Attribute, OldValue, NewValue);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Speed::PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data)
{
Super::PostGameplayEffectExecute(Data);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Speed::ClampAttributes(const FGameplayAttribute& Attribute, float& NewValue) const
{
if (Attribute == GetSpeedAttribute())
{
NewValue = FMath::Clamp(NewValue, GetMinSpeed(), GetMaxSpeed());
}
}
@@ -0,0 +1,59 @@
#pragma once
#include "CoreMinimal.h"
#include "AttributeSet.h"
#include "AbilitySystemComponent.h"
#include "CogSampleFunctionLibrary_Gameplay.h"
#include "CogSampleAttributeSet_Speed.generated.h"
UCLASS()
class UCogSampleAttributeSet_Speed : public UAttributeSet
{
GENERATED_BODY()
public:
UCogSampleAttributeSet_Speed();
UFUNCTION()
virtual void OnRep_Speed(const FGameplayAttributeData& PrevSpeed);
UFUNCTION()
virtual void OnRep_MinSpeed(const FGameplayAttributeData& PrevMinSpeed);
UFUNCTION()
virtual void OnRep_MaxSpeed(const FGameplayAttributeData& PrevMaxSpeed);
UFUNCTION()
virtual void OnRep_MaxAcceleration(const FGameplayAttributeData& PrevMaxAcceleration);
virtual void GetLifetimeReplicatedProps(TArray<class FLifetimeProperty>& OutLifetimeProps) const override;
virtual void PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue) override;
virtual void PostAttributeChange(const FGameplayAttribute& Attribute, float OldValue, float NewValue) override;
virtual void PreAttributeBaseChange(const FGameplayAttribute& Attribute, float& NewValue) const override;
virtual void PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data) override;
private:
UPROPERTY(BlueprintReadOnly, Category = "Speed", ReplicatedUsing = OnRep_Speed, meta = (AllowPrivateAccess = "true"))
FGameplayAttributeData Speed;
UPROPERTY(BlueprintReadOnly, Category = "Speed", ReplicatedUsing = OnRep_MinSpeed, meta = (AllowPrivateAccess = "true"))
FGameplayAttributeData MinSpeed;
UPROPERTY(BlueprintReadOnly, Category = "Speed", ReplicatedUsing = OnRep_MaxSpeed, meta = (AllowPrivateAccess = "true"))
FGameplayAttributeData MaxSpeed;
UPROPERTY(BlueprintReadOnly, Category = "Speed", ReplicatedUsing = OnRep_MaxAcceleration, meta = (AllowPrivateAccess = "true"))
FGameplayAttributeData MaxAcceleration;
void ClampAttributes(const FGameplayAttribute& Attribute, float& NewValue) const;
public:
ATTRIBUTE_ACCESSORS(UCogSampleAttributeSet_Speed, Speed);
ATTRIBUTE_ACCESSORS(UCogSampleAttributeSet_Speed, MinSpeed);
ATTRIBUTE_ACCESSORS(UCogSampleAttributeSet_Speed, MaxSpeed);
ATTRIBUTE_ACCESSORS(UCogSampleAttributeSet_Speed, MaxAcceleration);
};
@@ -0,0 +1,99 @@
#include "CogSampleAttributeSet_Stamina.h"
#include "Net/Core/PushModel/PushModel.h"
#include "Net/UnrealNetwork.h"
//--------------------------------------------------------------------------------------------------------------------------
UCogSampleAttributeSet_Stamina::UCogSampleAttributeSet_Stamina()
{
InitMinStamina(-500.0f);
InitStamina(1000.0f);
InitMaxStamina(1000.0f);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Stamina::OnRep_Stamina(const FGameplayAttributeData& PrevStamina)
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UCogSampleAttributeSet_Stamina, Stamina, PrevStamina);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Stamina::OnRep_MinStamina(const FGameplayAttributeData& PrevMinStamina)
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UCogSampleAttributeSet_Stamina, MinStamina, PrevMinStamina);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Stamina::OnRep_MaxStamina(const FGameplayAttributeData& PrevMaxStamina)
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UCogSampleAttributeSet_Stamina, MaxStamina, PrevMaxStamina);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Stamina::OnRep_StaminaRegen(const FGameplayAttributeData& PrevStaminaRegen)
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UCogSampleAttributeSet_Stamina, StaminaRegen, PrevStaminaRegen);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Stamina::GetLifetimeReplicatedProps(TArray<class FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
FDoRepLifetimeParams Params;
Params.bIsPushBased = true;
Params.RepNotifyCondition = REPNOTIFY_Always;
DOREPLIFETIME_WITH_PARAMS_FAST(UCogSampleAttributeSet_Stamina, Stamina, Params);
DOREPLIFETIME_WITH_PARAMS_FAST(UCogSampleAttributeSet_Stamina, MinStamina, Params);
DOREPLIFETIME_WITH_PARAMS_FAST(UCogSampleAttributeSet_Stamina, MaxStamina, Params);
DOREPLIFETIME_WITH_PARAMS_FAST(UCogSampleAttributeSet_Stamina, StaminaRegen, Params);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Stamina::PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue)
{
Super::PreAttributeChange(Attribute, NewValue);
if (Attribute == GetStaminaAttribute())
{
NewValue = FMath::Clamp(NewValue, GetMinStamina(), GetMaxStamina());
}
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Stamina::PreAttributeBaseChange(const FGameplayAttribute& Attribute, float& NewValue) const
{
Super::PreAttributeBaseChange(Attribute, NewValue);
ClampAttributes(Attribute, NewValue);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Stamina::PostAttributeChange(const FGameplayAttribute& Attribute, float OldValue, float NewValue)
{
Super::PostAttributeChange(Attribute, OldValue, NewValue);
if (Attribute == GetMaxStaminaAttribute())
{
UCogSampleFunctionLibrary_Gameplay::AdjustAttributeForMaxChange(GetOwningAbilitySystemComponent(), Stamina, OldValue, NewValue, GetStaminaAttribute());
}
else
{
ClampAttributes(Attribute, NewValue);
}
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Stamina::PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data)
{
Super::PostGameplayEffectExecute(Data);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleAttributeSet_Stamina::ClampAttributes(const FGameplayAttribute& Attribute, float& NewValue) const
{
if (Attribute == GetStaminaAttribute())
{
NewValue = FMath::Clamp(NewValue, GetMinStamina(), GetMaxStamina());
}
}
@@ -0,0 +1,59 @@
#pragma once
#include "CoreMinimal.h"
#include "AttributeSet.h"
#include "AbilitySystemComponent.h"
#include "CogSampleFunctionLibrary_Gameplay.h"
#include "CogSampleAttributeSet_Stamina.generated.h"
UCLASS()
class UCogSampleAttributeSet_Stamina : public UAttributeSet
{
GENERATED_BODY()
public:
UCogSampleAttributeSet_Stamina();
UFUNCTION()
virtual void OnRep_Stamina(const FGameplayAttributeData& PrevStamina);
UFUNCTION()
virtual void OnRep_MinStamina(const FGameplayAttributeData& PrevMinStamina);
UFUNCTION()
virtual void OnRep_MaxStamina(const FGameplayAttributeData& PrevMaxStamina);
UFUNCTION()
virtual void OnRep_StaminaRegen(const FGameplayAttributeData& PrevStaminaRegen);
virtual void GetLifetimeReplicatedProps(TArray<class FLifetimeProperty>& OutLifetimeProps) const override;
virtual void PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue) override;
virtual void PostAttributeChange(const FGameplayAttribute& Attribute, float OldValue, float NewValue) override;
virtual void PreAttributeBaseChange(const FGameplayAttribute& Attribute, float& NewValue) const override;
virtual void PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data) override;
private:
UPROPERTY(BlueprintReadOnly, Category = "Stamina", ReplicatedUsing = OnRep_Stamina, meta = (AllowPrivateAccess = "true"))
FGameplayAttributeData Stamina;
UPROPERTY(BlueprintReadOnly, Category = "Stamina", ReplicatedUsing = OnRep_MinStamina, meta = (AllowPrivateAccess = "true"))
FGameplayAttributeData MinStamina;
UPROPERTY(BlueprintReadOnly, Category = "Stamina", ReplicatedUsing = OnRep_MaxStamina, meta = (AllowPrivateAccess = "true"))
FGameplayAttributeData MaxStamina;
UPROPERTY(BlueprintReadOnly, Category = "Stamina", ReplicatedUsing = OnRep_StaminaRegen, meta = (AllowPrivateAccess = "true"))
FGameplayAttributeData StaminaRegen;
void ClampAttributes(const FGameplayAttribute& Attribute, float& NewValue) const;
public:
ATTRIBUTE_ACCESSORS(UCogSampleAttributeSet_Stamina, Stamina);
ATTRIBUTE_ACCESSORS(UCogSampleAttributeSet_Stamina, StaminaRegen)
ATTRIBUTE_ACCESSORS(UCogSampleAttributeSet_Stamina, MinStamina);
ATTRIBUTE_ACCESSORS(UCogSampleAttributeSet_Stamina, MaxStamina);
};
+479
View File
@@ -0,0 +1,479 @@
#include "CogSampleCharacter.h"
#include "Camera/CameraComponent.h"
#include "CogDebugLogMacros.h"
#include "CogSampleAttributeSet_Health.h"
#include "CogSampleAttributeSet_Misc.h"
#include "CogSampleCharacterMovementComponent.h"
#include "CogSampleLogCategories.h"
#include "CogSampleTagLibrary.h"
#include "Components/CapsuleComponent.h"
#include "Components/InputComponent.h"
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "GameFramework/CheatManagerDefines.h"
#include "GameFramework/Controller.h"
#include "GameFramework/SpringArmComponent.h"
#include "Net/Core/PushModel/PushModel.h"
#include "Net/UnrealNetwork.h"
#if USE_COG
#include "CogDebugDraw.h"
#include "CogDebugPlot.h"
#endif //USE_COG
//--------------------------------------------------------------------------------------------------------------------------
ACogSampleCharacter::ACogSampleCharacter(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer.SetDefaultSubobjectClass<UCogSampleCharacterMovementComponent>(ACharacter::CharacterMovementComponentName))
{
// Set size for collision capsule
GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f);
// Don't rotate when the controller rotates. Let that just affect the camera.
bUseControllerRotationPitch = false;
bUseControllerRotationYaw = false;
bUseControllerRotationRoll = false;
// Configure character movement
GetCharacterMovement()->bOrientRotationToMovement = true; // Character moves in the direction of input...
GetCharacterMovement()->RotationRate = FRotator(0.0f, 500.0f, 0.0f); // ...at this rotation rate
// Note: For faster iteration times these variables, and many more, can be tweaked in the Character Blueprint
// instead of recompiling to adjust them
GetCharacterMovement()->JumpZVelocity = 700.f;
GetCharacterMovement()->AirControl = 0.35f;
GetCharacterMovement()->MaxWalkSpeed = 500.f;
GetCharacterMovement()->MinAnalogWalkSpeed = 20.f;
GetCharacterMovement()->BrakingDecelerationWalking = 2000.f;
// Create a camera boom (pulls in towards the player if there is a collision)
CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
CameraBoom->SetupAttachment(RootComponent);
CameraBoom->TargetArmLength = 400.0f; // The camera follows at this distance behind the character
CameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller
// Create a follow camera
FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation
FollowCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm
AbilitySystem = CreateDefaultSubobject<UAbilitySystemComponent>(TEXT("AbilitySystem"));
AbilitySystem->SetIsReplicated(true);
AbilitySystem->SetReplicationMode(EGameplayEffectReplicationMode::Mixed);
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleCharacter::GetLifetimeReplicatedProps(TArray< FLifetimeProperty >& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
FDoRepLifetimeParams Params;
Params.bIsPushBased = true;
Params.Condition = COND_OwnerOnly;
DOREPLIFETIME_WITH_PARAMS_FAST(ACogSampleCharacter, ActiveAbilityHandles, Params);
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleCharacter::BeginPlay()
{
Super::BeginPlay();
if (APlayerController* PlayerController = Cast<APlayerController>(Controller))
{
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer()))
{
Subsystem->AddMappingContext(DefaultMappingContext, 0);
}
}
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleCharacter::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
Super::EndPlay(EndPlayReason);
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleCharacter::MarkComponentsAsPendingKill()
{
Super::MarkComponentsAsPendingKill();
ShutdownAbilitySystem();
}
//--------------------------------------------------------------------------------------------------------------------------
UAbilitySystemComponent* ACogSampleCharacter::GetAbilitySystemComponent() const
{
return AbilitySystem;
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleCharacter::InitializeAbilitySystem()
{
if (bIsInitialized)
{
return;
}
AbilitySystem->InitAbilityActorInfo(this, this);
if (AbilitySystem->IsOwnerActorAuthoritative())
{
for (const TSubclassOf<UAttributeSet>& AttributeSet : AttributeSets)
{
if (IsValid(AttributeSet) == false)
{
continue;
}
UAttributeSet* AttributeSetInstance = NewObject<UAttributeSet>(this, AttributeSet);
AbilitySystem->AddAttributeSetSubobject(AttributeSetInstance);
}
for (TSubclassOf<UGameplayEffect> Effect : Effects)
{
AbilitySystem->BP_ApplyGameplayEffectToSelf(Effect, 1, AbilitySystem->MakeEffectContext());
}
for (FPassiveAbilityInfo& AbilityInfo : PassiveAbilities)
{
const FGameplayAbilitySpec Spec(AbilityInfo.Ability, 1, INDEX_NONE, this);
AbilitySystem->GiveAbility(Spec);
}
for (FActiveAbilityInfo& AbilityInfo : ActiveAbilities)
{
const FGameplayAbilitySpec Spec(AbilityInfo.Ability, 1, INDEX_NONE, this);
FGameplayAbilitySpecHandle Handle = AbilitySystem->GiveAbility(Spec);
ActiveAbilityHandles.Add(Handle);
}
MARK_PROPERTY_DIRTY_FROM_NAME(ACogSampleCharacter, ActiveAbilityHandles, this);
}
//----------------------------------------
// Register to Tag change events
//----------------------------------------
GhostTagDelegateHandle = AbilitySystem->RegisterGameplayTagEvent(Tag_Status_Ghost, EGameplayTagEventType::NewOrRemoved).AddUObject(this, &ACogSampleCharacter::OnGhostTagNewOrRemoved);
//----------------------------------------
// Register to Attribute change events
//----------------------------------------
if (const UCogSampleAttributeSet_Misc* MiscAttributeSet = Cast<UCogSampleAttributeSet_Misc>(AbilitySystem->GetAttributeSet(UCogSampleAttributeSet_Misc::StaticClass())))
{
ScaleAttributeDelegateHandle = AbilitySystem->GetGameplayAttributeValueChangeDelegate(MiscAttributeSet->GetScaleAttribute()).AddUObject(this, &ACogSampleCharacter::OnScaleAttributeChanged);
}
//----------------------------------------
// Register to GameplayEffect events
//----------------------------------------
GameplayEffectAddedHandle = AbilitySystem->OnActiveGameplayEffectAddedDelegateToSelf.AddUObject(this, &ACogSampleCharacter::OnGameplayEffectAdded);
GameplayEffectRemovedHandle = AbilitySystem->OnAnyGameplayEffectRemovedDelegate().AddUObject(this, &ACogSampleCharacter::OnGameplayEffectRemoved);
bIsInitialized = true;
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleCharacter::ShutdownAbilitySystem()
{
//----------------------------------------
// Unregister to Attribute events
//----------------------------------------
if (const UCogSampleAttributeSet_Misc* MiscAttributeSet = Cast<UCogSampleAttributeSet_Misc>(AbilitySystem->GetAttributeSet(UCogSampleAttributeSet_Misc::StaticClass())))
{
AbilitySystem->GetGameplayAttributeValueChangeDelegate(MiscAttributeSet->GetScaleAttribute()).Remove(ScaleAttributeDelegateHandle);
}
//----------------------------------------
// Unregister to Tags events
//----------------------------------------
AbilitySystem->UnregisterGameplayTagEvent(GhostTagDelegateHandle, Tag_Status_Ghost, EGameplayTagEventType::NewOrRemoved);
//----------------------------------------
// Unregister to GameplayEffect events
//----------------------------------------
AbilitySystem->OnActiveGameplayEffectAddedDelegateToSelf.Remove(GameplayEffectAddedHandle);
AbilitySystem->OnAnyGameplayEffectRemovedDelegate().Remove(GameplayEffectRemovedHandle);
AbilitySystem->ClearActorInfo();
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleCharacter::PossessedBy(AController* NewController)
{
Super::PossessedBy(NewController);
InitializeAbilitySystem();
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleCharacter::OnAcknowledgePossession(APlayerController* InController)
{
InitializeAbilitySystem();
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
{
if (UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(PlayerInputComponent)) {
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Started, this, &ACharacter::Jump);
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping);
EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &ACogSampleCharacter::Move);
EnhancedInputComponent->BindAction(MoveZAction, ETriggerEvent::Triggered, this, &ACogSampleCharacter::MoveZ);
EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &ACogSampleCharacter::Look);
int32 AbilityIndex = 0;
for (const FActiveAbilityInfo& AbilityInfo : ActiveAbilities)
{
EnhancedInputComponent->BindAction(AbilityInfo.InputAction, ETriggerEvent::Started, this, &ACogSampleCharacter::OnAbilityInputStarted, AbilityIndex);
EnhancedInputComponent->BindAction(AbilityInfo.InputAction, ETriggerEvent::Completed, this, &ACogSampleCharacter::OnAbilityInputCompleted, AbilityIndex);
AbilityIndex++;
}
int32 ItemIndex = 0;
for (const UInputAction* ItemAction : ItemActions)
{
EnhancedInputComponent->BindAction(ItemAction, ETriggerEvent::Started, this, &ACogSampleCharacter::ActivateItem, ItemIndex);
ItemIndex++;
}
}
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleCharacter::OnAbilityInputStarted(const FInputActionValue& Value, int32 Index)
{
if (ActiveAbilityHandles.IsValidIndex(Index) == false)
{
return;
}
FGameplayAbilitySpecHandle Handle = ActiveAbilityHandles[Index];
FGameplayAbilitySpec* Spec = AbilitySystem->FindAbilitySpecFromHandle(Handle);
if (Spec == nullptr)
{
return;
}
Spec->InputPressed = true;
AbilitySystem->TryActivateAbility(Handle);
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleCharacter::OnAbilityInputCompleted(const FInputActionValue& Value, int32 Index)
{
if (ActiveAbilityHandles.IsValidIndex(Index) == false)
{
return;
}
FGameplayAbilitySpecHandle Handle = ActiveAbilityHandles[Index];
FGameplayAbilitySpec* Spec = AbilitySystem->FindAbilitySpecFromHandle(Handle);
if (Spec == nullptr)
{
return;
}
Spec->InputPressed = false;
UGameplayAbility* Ability= Spec->GetPrimaryInstance();
if (Ability == nullptr)
{
return;
}
if (Spec->IsActive() == false)
{
return;
}
if (Ability->bReplicateInputDirectly && AbilitySystem->IsOwnerActorAuthoritative() == false)
{
AbilitySystem->ServerSetInputReleased(Spec->Handle);
}
AbilitySystem->AbilitySpecInputReleased(*Spec);
AbilitySystem->InvokeReplicatedEvent(EAbilityGenericReplicatedEvent::InputReleased, Spec->Handle, Spec->ActivationInfo.GetActivationPredictionKey());
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleCharacter::ActivateItem(const FInputActionValue& Value, int32 Index)
{
COG_LOG_ACTOR(LogCogInput, ELogVerbosity::Verbose, this, TEXT("%d"), Index);
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleCharacter::Move(const FInputActionValue& Value)
{
const FVector2D MovementVector = Value.Get<FVector2D>();
if (Controller != nullptr)
{
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
AddMovementInput(ForwardDirection, MovementVector.Y);
AddMovementInput(RightDirection, MovementVector.X);
}
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleCharacter::MoveZ(const FInputActionValue& Value)
{
const float ZInput = Value.Get<float>();
if (Controller != nullptr)
{
AddMovementInput(FVector::UpVector, ZInput);
}
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleCharacter::Look(const FInputActionValue& Value)
{
const FVector2D LookAxisVector = Value.Get<FVector2D>();
if (Controller != nullptr)
{
AddControllerYawInput(LookAxisVector.X);
AddControllerPitchInput(LookAxisVector.Y);
}
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleCharacter::OnDamageReceived(float ReceivedDamage, float IncomingDamage, AActor* DamageDealer, const FGameplayEffectSpec& EffectSpec)
{
#if USE_COG
FCogAbilityDamageParams Params;
Params.ReceivedDamage = ReceivedDamage;
Params.IncomingDamage = IncomingDamage;
Params.DamageDealer = DamageDealer;
Params.DamageReceiver = this;
OnDamageEventDelegate.Broadcast(Params);
#endif //USE_COG
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleCharacter::OnDamageDealt(float ReceivedDamage, float IncomingDamage, AActor* DamageReceiver, const FGameplayEffectSpec& EffectSpec)
{
#if USE_COG
FCogAbilityDamageParams Params;
Params.ReceivedDamage = ReceivedDamage;
Params.IncomingDamage = IncomingDamage;
Params.DamageDealer = this;
Params.DamageReceiver = DamageReceiver;
OnDamageEventDelegate.Broadcast(Params);
#endif //USE_COG
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleCharacter::OnKilled(AActor* InInstigator, AActor* InCauser, const FGameplayEffectSpec& InEffectSpec, float InMagnitude)
{
if (AbilitySystem != nullptr)
{
FGameplayEventData Payload;
Payload.EventTag = Tag_GameplayEvent_Killed;
Payload.Instigator = InInstigator;
Payload.Target = AbilitySystem->GetAvatarActor();
Payload.OptionalObject = InEffectSpec.Def;
Payload.ContextHandle = InEffectSpec.GetEffectContext();
Payload.InstigatorTags = *InEffectSpec.CapturedSourceTags.GetAggregatedTags();
Payload.TargetTags = *InEffectSpec.CapturedTargetTags.GetAggregatedTags();
Payload.EventMagnitude = InMagnitude;
FScopedPredictionWindow NewScopedWindow(AbilitySystem, true);
AbilitySystem->HandleGameplayEvent(Payload.EventTag, &Payload);
}
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleCharacter::OnRevived(AActor* InInstigator, AActor* InCauser, const FGameplayEffectSpec& InEffectSpec, float InMagnitude)
{
if (AbilitySystem != nullptr)
{
FGameplayEventData Payload;
Payload.EventTag = Tag_GameplayEvent_Revived;
Payload.Instigator = InInstigator;
Payload.Target = AbilitySystem->GetAvatarActor();
Payload.OptionalObject = InEffectSpec.Def;
Payload.ContextHandle = InEffectSpec.GetEffectContext();
Payload.InstigatorTags = *InEffectSpec.CapturedSourceTags.GetAggregatedTags();
Payload.TargetTags = *InEffectSpec.CapturedTargetTags.GetAggregatedTags();
Payload.EventMagnitude = InMagnitude;
FScopedPredictionWindow NewScopedWindow(AbilitySystem, true);
AbilitySystem->HandleGameplayEvent(Payload.EventTag, &Payload);
}
}
// ----------------------------------------------------------------------------------------------------------------
void ACogSampleCharacter::OnGameplayEffectAdded(UAbilitySystemComponent* AbilitySystemComponent, const FGameplayEffectSpec& GameplayEffectSpec, FActiveGameplayEffectHandle Handle)
{
#if USE_COG
FCogDebugPlot::PlotEvent(this, "Effects", GameplayEffectSpec.Def->GetFName(), GameplayEffectSpec.GetDuration() == 0.0f)
.AddParam("Name", AbilitySystemComponent->CleanupName(GetNameSafe(GameplayEffectSpec.Def)))
.AddParam("Effect Instigator", GetNameSafe(GameplayEffectSpec.GetEffectContext().GetInstigator()))
.AddParam("Effect Level", GameplayEffectSpec.GetLevel())
.AddParam("Effect Duration", GameplayEffectSpec.GetDuration());
#endif //USE_COG
}
// ----------------------------------------------------------------------------------------------------------------
void ACogSampleCharacter::OnGameplayEffectRemoved(const FActiveGameplayEffect& RemovedGameplayEffect)
{
#if USE_COG
FCogDebugPlot::PlotEventStop(this, "Effects", RemovedGameplayEffect.Spec.Def->GetFName());
#endif //USE_COG
}
// ----------------------------------------------------------------------------------------------------------------
void ACogSampleCharacter::OnGhostTagNewOrRemoved(const FGameplayTag InTag, int32 NewCount)
{
#if UE_WITH_CHEAT_MANAGER
check(InTag == Tag_Status_Ghost);
bool bHasGhostTags = NewCount > 0;
if (bIsGhost == bHasGhostTags)
{
return;
}
bIsGhost = bHasGhostTags;
SetActorEnableCollision(bIsGhost == false);
CameraBoom->bDoCollisionTest = bIsGhost == false;
if (UCogSampleCharacterMovementComponent* MovementComponent = Cast<UCogSampleCharacterMovementComponent>(GetMovementComponent()))
{
MovementComponent->bCheatFlying = bIsGhost;
MovementComponent->SetMovementMode(bIsGhost ? MOVE_Flying : MOVE_Falling);
}
if (APlayerController* PlayerController = Cast<APlayerController>(Controller))
{
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer()))
{
if (bIsGhost)
{
Subsystem->AddMappingContext(GhostMappingContext, 0);
}
else
{
Subsystem->RemoveMappingContext(GhostMappingContext);
}
}
}
#endif //UE_WITH_CHEAT_MANAGER
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleCharacter::OnScaleAttributeChanged(const FOnAttributeChangeData& Data)
{
SetActorScale3D(FVector(Data.NewValue));
}
+187
View File
@@ -0,0 +1,187 @@
#pragma once
#include "CoreMinimal.h"
#include "CogDefines.h"
#include "AbilitySystemInterface.h"
#include "ActiveGameplayEffectHandle.h"
#include "AttributeSet.h"
#include "GameFramework/Character.h"
#include "GameplayAbilitySpecHandle.h"
#include "GameplayTagContainer.h"
#include "InputActionValue.h"
#if USE_COG
#include "CogAbilityDamageActorInterface.h"
#include "CogDebugFilteredActorInterface.h"
#endif //USE_COG
#include "CogSampleCharacter.generated.h"
class UAbilitySystemComponent;
class UCogAbilitySystemComponent;
class UCameraComponent;
class UGameplayAbility;
class UGameplayEffect;
class UInputAction;
class UInputMappingContext;
class USpringArmComponent;
struct FActiveGameplayEffect;
struct FGameplayEffectSpec;
struct FOnAttributeChangeData;
//--------------------------------------------------------------------------------------------------------------------------
USTRUCT(BlueprintType)
struct FActiveAbilityInfo
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadOnly)
TSubclassOf<UGameplayAbility> Ability;
UPROPERTY(EditAnywhere, BlueprintReadOnly)
UInputAction* InputAction = nullptr;
};
//--------------------------------------------------------------------------------------------------------------------------
USTRUCT(BlueprintType)
struct FPassiveAbilityInfo
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadOnly)
TSubclassOf<UGameplayAbility> Ability;
UPROPERTY(EditAnywhere, BlueprintReadOnly)
bool ActivateWhenGiven = false;
};
//--------------------------------------------------------------------------------------------------------------------------
UCLASS(config=Game)
class ACogSampleCharacter : public ACharacter
, public IAbilitySystemInterface
#if USE_COG
, public ICogDebugFilteredActorInterface
, public ICogAbilityDamageActorInterface
#endif //USE_COG
{
GENERATED_BODY()
public:
ACogSampleCharacter(const FObjectInitializer& ObjectInitializer);
//----------------------------------------------------------------------------------------------------------------------
// ACharacter overrides
//----------------------------------------------------------------------------------------------------------------------
virtual void BeginPlay();
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason);
virtual void MarkComponentsAsPendingKill() override;
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
virtual void PossessedBy(AController* NewController) override;
#if USE_COG
virtual FCogAbilityOnDamageEvent& OnDamageEvent() override { return OnDamageEventDelegate; }
virtual bool IsActorFilteringDebug() const override { return true; }
#endif //USE_COG
void OnAcknowledgePossession(APlayerController* InController);
void OnDamageReceived(float DamageAmount, float UnmitigatedDamageAmount, AActor* DamageDealer, const FGameplayEffectSpec& EffectSpec);
void OnDamageDealt(float DamageAmount, float UnmitigatedDamageAmount, AActor* DamageReceiver, const FGameplayEffectSpec& EffectSpec);
void OnKilled(AActor* InInstigator, AActor* InCauser, const FGameplayEffectSpec& InEffectSpec, float InMagnitude);
void OnRevived(AActor* InInstigator, AActor* InCauser, const FGameplayEffectSpec& InEffectSpec, float InMagnitude);
USpringArmComponent* GetCameraBoom() const { return CameraBoom; }
UCameraComponent* GetFollowCamera() const { return FollowCamera; }
UFUNCTION(BlueprintPure)
UAbilitySystemComponent* GetAbilitySystemComponent() const override;
//----------------------------------------------------------------------------------------------------------------------
/** Camera boom positioning the camera behind the character */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
USpringArmComponent* CameraBoom;
/** Follow camera */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
UCameraComponent* FollowCamera;
/** MappingContext */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
UInputMappingContext* DefaultMappingContext;
/** MappingContext */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
UInputMappingContext* GhostMappingContext;
/** Jump Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
UInputAction* JumpAction;
/** Move Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
UInputAction* MoveAction;
/** Move Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
UInputAction* MoveZAction;
/** Look Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
UInputAction* LookAction;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
TArray<UInputAction*> ItemActions;
UPROPERTY(BlueprintReadOnly, Category = Ability, meta = (AllowPrivateAccess = "true"))
UAbilitySystemComponent* AbilitySystem = nullptr;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Ability)
TArray<TSubclassOf<UAttributeSet>> AttributeSets;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Ability)
TArray<FActiveAbilityInfo> ActiveAbilities;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Ability)
TArray<FPassiveAbilityInfo> PassiveAbilities;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Ability)
TArray<TSubclassOf<UGameplayEffect>> Effects;
#if USE_COG
FCogAbilityOnDamageEvent OnDamageEventDelegate;
#endif //USE_COG
private:
void InitializeAbilitySystem();
void ShutdownAbilitySystem();
void Move(const FInputActionValue& Value);
void MoveZ(const FInputActionValue& Value);
void Look(const FInputActionValue& Value);
void OnAbilityInputStarted(const FInputActionValue& Value, int32 Index);
void OnAbilityInputCompleted(const FInputActionValue& Value, int32 Index);
void ActivateItem(const FInputActionValue& Value, int32 Index);
void OnGameplayEffectAdded(UAbilitySystemComponent* AbilitySystemComponent, const FGameplayEffectSpec& GameplayEffectSpec, FActiveGameplayEffectHandle Handle);
void OnGameplayEffectRemoved(const FActiveGameplayEffect& RemovedGameplayEffect);
void OnGhostTagNewOrRemoved(const FGameplayTag InTag, int32 NewCount);
void OnScaleAttributeChanged(const FOnAttributeChangeData& Data);
UPROPERTY(Replicated, Transient)
TArray<FGameplayAbilitySpecHandle> ActiveAbilityHandles;
FDelegateHandle GameplayEffectAddedHandle;
FDelegateHandle GameplayEffectRemovedHandle;
FDelegateHandle GhostTagDelegateHandle;
FDelegateHandle ScaleAttributeDelegateHandle;
bool bIsGhost = false;
bool bIsInitialized = false;
};
@@ -0,0 +1,301 @@
#include "CogSampleCharacterMovementComponent.h"
#include "AbilitySystemComponent.h"
#include "AbilitySystemGlobals.h"
#include "CogDebugDraw.h"
#include "CogDebugPlot.h"
#include "CogSampleAttributeSet_Speed.h"
#include "CogSampleLogCategories.h"
#include "CogSampleTagLibrary.h"
#include "Components/CapsuleComponent.h"
#include "GameFramework/Character.h"
//--------------------------------------------------------------------------------------------------------------------------
// UCogSampleCharacterMovementComponent::FCogSampleSavedMove
//--------------------------------------------------------------------------------------------------------------------------
uint8 UCogSampleCharacterMovementComponent::FCogSampleSavedMove::GetCompressedFlags() const
{
uint8 Result = Super::GetCompressedFlags();
if (SavedRequestSprint)
{
Result |= FLAG_Custom_0;
}
return Result;
}
//--------------------------------------------------------------------------------------------------------------------------
bool UCogSampleCharacterMovementComponent::FCogSampleSavedMove::CanCombineWith(const FSavedMovePtr& NewMove, ACharacter* Character, float MaxDelta) const
{
//----------------------------------------------------------------------------------------------
// Set which moves can be combined together. This will depend on the bit flags that are used.
//----------------------------------------------------------------------------------------------
if (SavedRequestSprint != ((FCogSampleSavedMove*)&NewMove)->SavedRequestSprint)
{
return false;
}
return Super::CanCombineWith(NewMove, Character, MaxDelta);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleCharacterMovementComponent::FCogSampleSavedMove::SetMoveFor(ACharacter* Character, float InDeltaTime, FVector const& NewAccel, FNetworkPredictionData_Client_Character& ClientData)
{
Super::SetMoveFor(Character, InDeltaTime, NewAccel, ClientData);
if (UCogSampleCharacterMovementComponent* CharacterMovement = Cast<UCogSampleCharacterMovementComponent>(Character->GetCharacterMovement()))
{
SavedRequestSprint = CharacterMovement->bIsSprinting;
}
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleCharacterMovementComponent::FCogSampleSavedMove::PrepMoveFor(ACharacter* Character)
{
Super::PrepMoveFor(Character);
}
//--------------------------------------------------------------------------------------------------------------------------
// UCogSampleCharacterMovementComponent::FCogSampleNetworkPredictionData_Client
//--------------------------------------------------------------------------------------------------------------------------
UCogSampleCharacterMovementComponent::FCogSampleNetworkPredictionData_Client::FCogSampleNetworkPredictionData_Client(const UCharacterMovementComponent& ClientMovement)
: Super(ClientMovement)
{
}
//--------------------------------------------------------------------------------------------------------------------------
FSavedMovePtr UCogSampleCharacterMovementComponent::FCogSampleNetworkPredictionData_Client::AllocateNewMove()
{
return FSavedMovePtr(new FCogSampleSavedMove());
}
//--------------------------------------------------------------------------------------------------------------------------
// UCogSampleCharacterMovementComponent
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleCharacterMovementComponent::UpdateFromCompressedFlags(uint8 Flags)
{
Super::UpdateFromCompressedFlags(Flags);
//-------------------------------------------------------------------------------------------------------------------
// The Flags parameter contains the compressed input flags that are stored in the saved move.
// UpdateFromCompressed flags simply copies the flags from the saved move into the movement component.
// It basically just resets the movement component to the state when the move was made so it can simulate from there.
//-------------------------------------------------------------------------------------------------------------------
//-----------------------
// Sprint
//-----------------------
bIsSprinting = (Flags & FSavedMove_Character::FLAG_Custom_0) != 0;
}
//--------------------------------------------------------------------------------------------------------------------------
FNetworkPredictionData_Client* UCogSampleCharacterMovementComponent::GetPredictionData_Client() const
{
check(PawnOwner != NULL);
if (!ClientPredictionData)
{
UCogSampleCharacterMovementComponent* MutableThis = const_cast<UCogSampleCharacterMovementComponent*>(this);
MutableThis->ClientPredictionData = new FCogSampleNetworkPredictionData_Client(*this);
}
return ClientPredictionData;
}
//--------------------------------------------------------------------------------------------------------------------------
float UCogSampleCharacterMovementComponent::GetMaxSpeed() const
{
UAbilitySystemComponent* AbilitySystemComponent = UAbilitySystemGlobals::GetAbilitySystemComponentFromActor(GetPawnOwner(), true);
if (AbilitySystemComponent == nullptr)
{
return Super::GetMaxSpeed();
}
if (AbilitySystemComponent->HasMatchingGameplayTag(Tag_Status_Immobilized))
{
return 0.0f;
}
if (AbilitySystemComponent->HasMatchingGameplayTag(Tag_Status_Stunned))
{
return 0.0f;
}
if (AbilitySystemComponent->HasMatchingGameplayTag(Tag_Status_Dead))
{
return 0.0f;
}
if (AbilitySystemComponent->HasMatchingGameplayTag(Tag_Status_Revived))
{
return 0.0f;
}
const float Speed = AbilitySystemComponent->GetNumericAttribute(UCogSampleAttributeSet_Speed::GetSpeedAttribute());
return Speed;
}
//--------------------------------------------------------------------------------------------------------------------------
float UCogSampleCharacterMovementComponent::GetMaxAcceleration() const
{
UAbilitySystemComponent* AbilitySystemComponent = UAbilitySystemGlobals::GetAbilitySystemComponentFromActor(GetPawnOwner(), true);
if (AbilitySystemComponent == nullptr)
{
return Super::GetMaxAcceleration();
}
const float MaxAccel = AbilitySystemComponent->GetNumericAttribute(UCogSampleAttributeSet_Speed::GetMaxAccelerationAttribute());
return MaxAccel;
}
//--------------------------------------------------------------------------------------------------------------------------
FRotator UCogSampleCharacterMovementComponent::GetDeltaRotation(float DeltaTime) const
{
UAbilitySystemComponent* AbilitySystemComponent = UAbilitySystemGlobals::GetAbilitySystemComponentFromActor(GetPawnOwner(), true);
if (AbilitySystemComponent == nullptr)
{
return Super::GetDeltaRotation(DeltaTime);
}
if (AbilitySystemComponent->HasMatchingGameplayTag(Tag_Status_Stunned))
{
return FRotator::ZeroRotator;
}
if (AbilitySystemComponent->HasMatchingGameplayTag(Tag_Status_Dead))
{
return FRotator::ZeroRotator;
}
if (AbilitySystemComponent->HasMatchingGameplayTag(Tag_Status_Revived))
{
return FRotator::ZeroRotator;
}
return Super::GetDeltaRotation(DeltaTime);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleCharacterMovementComponent::StartSprinting()
{
bIsSprinting = true;
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleCharacterMovementComponent::StopSprinting()
{
bIsSprinting = false;
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleCharacterMovementComponent::FCogSampleSavedMove::Clear()
{
Super::Clear();
SavedRequestSprint = false;
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleCharacterMovementComponent::BeginPlay()
{
Super::BeginPlay();
#if ENABLE_COG
const ACharacter* Character = GetCharacterOwner();
const UCapsuleComponent* CapsuleComponent = Character->GetCapsuleComponent();
DebugLastBottomLocation = Character->GetActorLocation() - FVector::UpVector * CapsuleComponent->GetScaledCapsuleHalfHeight();
#endif //ENABLE_COG
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleCharacterMovementComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
#if ENABLE_COG
const ACharacter* Character = GetCharacterOwner();
const UCapsuleComponent* CapsuleComponent = Character->GetCapsuleComponent();
if (FCogDebugSettings::IsDebugActiveForActor(GetPawnOwner()))
{
FCogDebugPlot::PlotValue(GetPawnOwner(), "Move Input X", GetPendingInputVector().X);
FCogDebugPlot::PlotValue(GetPawnOwner(), "Move Input Y", GetPendingInputVector().Y);
FCogDebugPlot::PlotValue(GetPawnOwner(), "Move Input Local X", FVector::DotProduct(GetPawnOwner()->GetActorRightVector(), GetPendingInputVector()));
FCogDebugPlot::PlotValue(GetPawnOwner(), "Move Input Local Y", FVector::DotProduct(GetPawnOwner()->GetActorForwardVector(), GetPendingInputVector()));
}
#endif //ENABLE_COG
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
#if ENABLE_COG
const FVector DebugBottomLocation = Character->GetActorLocation() - FVector::UpVector * CapsuleComponent->GetScaledCapsuleHalfHeight();
if (FCogDebugSettings::IsDebugActiveForActor(GetPawnOwner()))
{
const FRotator Rotation = Character->GetActorRotation();
const FVector LocalVelocity = Rotation.UnrotateVector(Velocity);
const FVector LocalAcceleration = Rotation.UnrotateVector(GetCurrentAcceleration());
const FVector VelocityDelta = (Velocity - DebugLastVelocity) / DeltaTime;
const FVector LocalVelocityDelta = Rotation.UnrotateVector(VelocityDelta);
FCogDebugPlot::PlotValue(Character, "Location X", DebugBottomLocation.X);
FCogDebugPlot::PlotValue(Character, "Location Y", DebugBottomLocation.Y);
FCogDebugPlot::PlotValue(Character, "Location Z", DebugBottomLocation.Z);
FCogDebugPlot::PlotValue(Character, "Rotation Yaw", Character->GetActorRotation().Yaw);
FCogDebugPlot::PlotValue(Character, "Acceleration X", GetCurrentAcceleration().X);
FCogDebugPlot::PlotValue(Character, "Acceleration Y", GetCurrentAcceleration().Y);
FCogDebugPlot::PlotValue(Character, "Acceleration Z", GetCurrentAcceleration().Z);
FCogDebugPlot::PlotValue(Character, "Acceleration Local X", LocalAcceleration.X);
FCogDebugPlot::PlotValue(Character, "Acceleration Local Y", LocalAcceleration.Y);
FCogDebugPlot::PlotValue(Character, "Acceleration Local Z", LocalAcceleration.Z);
FCogDebugPlot::PlotValue(Character, "Velocity X", Velocity.X);
FCogDebugPlot::PlotValue(Character, "Velocity Y", Velocity.Y);
FCogDebugPlot::PlotValue(Character, "Velocity Z", Velocity.Z);
FCogDebugPlot::PlotValue(Character, "Velocity Local X", LocalVelocity.X);
FCogDebugPlot::PlotValue(Character, "Velocity Local Y", LocalVelocity.Y);
FCogDebugPlot::PlotValue(Character, "Velocity Local Z", LocalVelocity.Z);
FCogDebugPlot::PlotValue(Character, "Velocity Delta X", VelocityDelta.X);
FCogDebugPlot::PlotValue(Character, "Velocity Delta Y", VelocityDelta.Y);
FCogDebugPlot::PlotValue(Character, "Velocity Delta Z", VelocityDelta.Z);
FCogDebugPlot::PlotValue(Character, "Velocity Delta Local X", LocalVelocityDelta.X);
FCogDebugPlot::PlotValue(Character, "Velocity Delta Local Y", LocalVelocityDelta.Y);
FCogDebugPlot::PlotValue(Character, "Velocity Delta Local Z", LocalVelocityDelta.Z);
FCogDebugPlot::PlotValue(Character, "Speed", Velocity.Length());
const FVector Delta = DebugBottomLocation - DebugLastBottomLocation;
const FColor Color = DebugIsPositionCorrected ? FColor::Blue : FColor::Yellow;
if (Delta.IsNearlyZero() == false)
{
FCogDebugDraw::Arrow(LogCogPosition, this, DebugLastBottomLocation, DebugBottomLocation, Color, true, 0);
}
const FColor CapsuleColor = CapsuleComponent->GetCollisionEnabled() == ECollisionEnabled::NoCollision ? FColor::Black : FColor::White;
FCogDebugDraw::Capsule(LogCogCollision, this, CapsuleComponent->GetComponentLocation(), CapsuleComponent->GetScaledCapsuleHalfHeight(), CapsuleComponent->GetScaledCapsuleRadius(), CapsuleComponent->GetComponentQuat(), CapsuleColor, false, 0);
FCogDebugDraw::Axis(LogCogCollision, this, CapsuleComponent->GetComponentLocation(), CapsuleComponent->GetComponentRotation(), 50.0f, false, 0);
}
DebugLastBottomLocation = DebugBottomLocation;
DebugLastVelocity = Velocity;
DebugIsPositionCorrected = false;
#endif //ENABLE_COG
}
//--------------------------------------------------------------------------------------------------------------------------
bool UCogSampleCharacterMovementComponent::ClientUpdatePositionAfterServerUpdate()
{
bool Result = Super::ClientUpdatePositionAfterServerUpdate();
#if ENABLE_COG
DebugIsPositionCorrected = true;
#endif //ENABLE_COG
return Result;
}
@@ -0,0 +1,76 @@
#pragma once
#include "CoreMinimal.h"
#include "CogDefines.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "CogSampleCharacterMovementComponent.generated.h"
//--------------------------------------------------------------------------------------------------------------------------
UCLASS()
class UCogSampleCharacterMovementComponent : public UCharacterMovementComponent
{
GENERATED_BODY()
class FCogSampleSavedMove : public FSavedMove_Character
{
public:
typedef FSavedMove_Character Super;
///@brief Resets all saved variables.
virtual void Clear() override;
///@brief Store input commands in the compressed flags.
virtual uint8 GetCompressedFlags() const override;
///@brief This is used to check whether or not two moves can be combined into one.
///Basically you just check to make sure that the saved variables are the same.
virtual bool CanCombineWith(const FSavedMovePtr& NewMove, ACharacter* Character, float MaxDelta) const override;
///@brief Sets up the move before sending it to the server.
virtual void SetMoveFor(ACharacter* Character, float InDeltaTime, FVector const& NewAccel, class FNetworkPredictionData_Client_Character& ClientData) override;
///@brief Sets variables on character movement component before making a predictive correction.
virtual void PrepMoveFor(class ACharacter* Character) override;
// Sprint
uint8 SavedRequestSprint : 1;
};
class FCogSampleNetworkPredictionData_Client : public FNetworkPredictionData_Client_Character
{
public:
FCogSampleNetworkPredictionData_Client(const UCharacterMovementComponent& ClientMovement);
typedef FNetworkPredictionData_Client_Character Super;
///@brief Allocates a new copy of our custom saved move
virtual FSavedMovePtr AllocateNewMove() override;
};
public:
virtual void BeginPlay() override;
virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
virtual float GetMaxSpeed() const override;
virtual float GetMaxAcceleration() const override;
virtual FRotator GetDeltaRotation(float DeltaTime) const;
virtual void UpdateFromCompressedFlags(uint8 Flags) override;
virtual class FNetworkPredictionData_Client* GetPredictionData_Client() const override;
virtual bool ClientUpdatePositionAfterServerUpdate() override;
UFUNCTION(BlueprintCallable)
void StartSprinting();
UFUNCTION(BlueprintCallable)
void StopSprinting();
private:
bool bIsSprinting = false;
#if USE_COG
FVector DebugLastBottomLocation = FVector::ZeroVector;
FVector DebugLastVelocity = FVector::ZeroVector;
bool DebugIsPositionCorrected = false;
#endif //USE_COG
};
@@ -0,0 +1,97 @@
#include "CogSampleExecCalculation_Damage.h"
#include "CogSampleAttributeSet_Health.h"
#include "CogSampleCharacter.h"
#include "CogSampleTagLibrary.h"
//--------------------------------------------------------------------------------------------------------------------------
struct FCogSampleDamageStatics
{
DECLARE_ATTRIBUTE_CAPTUREDEF(DamageResistance);
FCogSampleDamageStatics()
{
DEFINE_ATTRIBUTE_CAPTUREDEF(UCogSampleAttributeSet_Health, DamageResistance, Target, false);
}
};
//--------------------------------------------------------------------------------------------------------------------------
static const FCogSampleDamageStatics& DamageStatics()
{
static FCogSampleDamageStatics __FCogSampleDamageStatics;
return __FCogSampleDamageStatics;
}
//--------------------------------------------------------------------------------------------------------------------------
UCogSampleExecCalculation_Damage::UCogSampleExecCalculation_Damage()
{
RelevantAttributesToCapture.Add(FCogSampleDamageStatics().DamageResistanceDef);
#if WITH_EDITORONLY_DATA
ValidTransientAggregatorIdentifiers.AddTag(Tag_Effect_Data_Damage);
InvalidScopedModifierAttributes.Add(FCogSampleDamageStatics().DamageResistanceDef);
#endif // #if WITH_EDITORONLY_DATA
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleExecCalculation_Damage::Execute_Implementation(const FGameplayEffectCustomExecutionParameters& ExecutionParams, OUT FGameplayEffectCustomExecutionOutput& OutExecutionOutput) const
{
const FGameplayEffectSpec& EffectSpec = ExecutionParams.GetOwningSpec();
const FGameplayEffectContextHandle Context = EffectSpec.GetContext();
FAggregatorEvaluateParameters EvaluationParameters;
EvaluationParameters.SourceTags = EffectSpec.CapturedSourceTags.GetAggregatedTags();
EvaluationParameters.TargetTags = EffectSpec.CapturedTargetTags.GetAggregatedTags();
UAbilitySystemComponent* TargetAbilitySystem = ExecutionParams.GetTargetAbilitySystemComponent();
UAbilitySystemComponent* SourceAbilitySystem = ExecutionParams.GetSourceAbilitySystemComponent();
ACogSampleCharacter* TargetCharacter = (TargetAbilitySystem != nullptr) ? Cast<ACogSampleCharacter>(TargetAbilitySystem->AbilityActorInfo.IsValid() ? TargetAbilitySystem->GetAvatarActor() : nullptr) : nullptr;
ACogSampleCharacter* SourceCharacter = (SourceAbilitySystem != nullptr) ? Cast<ACogSampleCharacter>(SourceAbilitySystem->AbilityActorInfo.IsValid() ? SourceAbilitySystem->GetAvatarActor() : nullptr) : nullptr;
if (TargetCharacter == nullptr)
{
return;
}
FGameplayTagContainer SpecAssetTags;
EffectSpec.GetAllAssetTags(SpecAssetTags);
//-----------------------------------------------------------------------------------------------------
// Get flat Damage
//-----------------------------------------------------------------------------------------------------
float IncomingDamage = 0.0f;
ExecutionParams.AttemptCalculateTransientAggregatorMagnitude(Tag_Effect_Data_Damage, EvaluationParameters, IncomingDamage);
//-----------------------------------------------------------------------------------------------------
// Apply resistances
//-----------------------------------------------------------------------------------------------------
float ReceivedDamage = 0.0f;
if (TargetAbilitySystem->HasMatchingGameplayTag(Tag_Status_Immune_Damage) == false)
{
float Resistances = 0.0f;
ExecutionParams.AttemptCalculateCapturedAttributeMagnitude(DamageStatics().DamageResistanceDef, EvaluationParameters, Resistances);
Resistances = FMath::Min(Resistances, 1.0f);
ReceivedDamage = IncomingDamage * (1.0f - Resistances);
}
if (SpecAssetTags.HasTag(Tag_Effect_Type_Damage_Kill))
{
IncomingDamage = TargetAbilitySystem->GetNumericAttribute(UCogSampleAttributeSet_Health::GetMaxHealthAttribute());
ReceivedDamage = IncomingDamage;
}
//-----------------------------------------------------------------------------------------------------
// Apply Damage
//-----------------------------------------------------------------------------------------------------
if (ReceivedDamage > 0.0f)
{
OutExecutionOutput.AddOutputModifier(FGameplayModifierEvaluatedData(UCogSampleAttributeSet_Health::GetHealthAttribute(), EGameplayModOp::Additive, -ReceivedDamage));
TargetCharacter->OnDamageReceived(ReceivedDamage, IncomingDamage, SourceCharacter, EffectSpec);
if (SourceCharacter != nullptr)
{
SourceCharacter->OnDamageDealt(ReceivedDamage, IncomingDamage, TargetCharacter, EffectSpec);
}
}
}
@@ -0,0 +1,16 @@
#pragma once
#include "CoreMinimal.h"
#include "GameplayEffectExecutionCalculation.h"
#include "CogSampleExecCalculation_Damage.generated.h"
UCLASS()
class UCogSampleExecCalculation_Damage : public UGameplayEffectExecutionCalculation
{
GENERATED_BODY()
public:
UCogSampleExecCalculation_Damage();
virtual void Execute_Implementation(const FGameplayEffectCustomExecutionParameters& ExecutionParams, OUT FGameplayEffectCustomExecutionOutput& OutExecutionOutput) const override;
};
@@ -0,0 +1,76 @@
#include "CogSampleExecCalculation_Heal.h"
#include "CogSampleAttributeSet_Health.h"
#include "CogSampleCharacter.h"
#include "CogSampleTagLibrary.h"
//--------------------------------------------------------------------------------------------------------------------------
struct FCogSampleHealStatics
{
FCogSampleHealStatics()
{
}
};
//--------------------------------------------------------------------------------------------------------------------------
static const FCogSampleHealStatics& HealStatics()
{
static FCogSampleHealStatics __FCogSampleHealStatics;
return __FCogSampleHealStatics;
}
//--------------------------------------------------------------------------------------------------------------------------
UCogSampleExecCalculation_Heal::UCogSampleExecCalculation_Heal()
{
#if WITH_EDITORONLY_DATA
ValidTransientAggregatorIdentifiers.AddTag(Tag_Effect_Data_Heal);
#endif // #if WITH_EDITORONLY_DATA
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleExecCalculation_Heal::Execute_Implementation(const FGameplayEffectCustomExecutionParameters& ExecutionParams, OUT FGameplayEffectCustomExecutionOutput& OutExecutionOutput) const
{
const FGameplayEffectSpec& EffectSpec = ExecutionParams.GetOwningSpec();
const FGameplayEffectContextHandle Context = EffectSpec.GetContext();
FAggregatorEvaluateParameters EvaluationParameters;
EvaluationParameters.SourceTags = EffectSpec.CapturedSourceTags.GetAggregatedTags();
EvaluationParameters.TargetTags = EffectSpec.CapturedTargetTags.GetAggregatedTags();
UAbilitySystemComponent* TargetAbilitySystem = ExecutionParams.GetTargetAbilitySystemComponent();
UAbilitySystemComponent* SourceAbilitySystem = ExecutionParams.GetSourceAbilitySystemComponent();
FGameplayTagContainer SpecAssetTags;
EffectSpec.GetAllAssetTags(SpecAssetTags);
//-----------------------------------------------------------------------------------------------------
// Get flat Heal
//-----------------------------------------------------------------------------------------------------
float Heal = 0.0f;
ExecutionParams.AttemptCalculateTransientAggregatorMagnitude(Tag_Effect_Data_Heal, EvaluationParameters, Heal);
//-----------------------------------------------------------------------------------------------------
// Apply modifiers
//-----------------------------------------------------------------------------------------------------
const bool IsDead = TargetAbilitySystem->HasMatchingGameplayTag(Tag_Status_Dead);
const bool IsEffectReviving = SpecAssetTags.HasTag(Tag_Effect_Type_Heal_Revive);
if (IsDead && IsEffectReviving == false)
{
return;
}
if (SpecAssetTags.HasTag(Tag_Effect_Type_Heal_Full))
{
Heal = TargetAbilitySystem->GetNumericAttribute(UCogSampleAttributeSet_Health::GetMaxHealthAttribute());
}
//-----------------------------------------------------------------------------------------------------
// Apply Heal
//-----------------------------------------------------------------------------------------------------
if (Heal > 0.0f)
{
OutExecutionOutput.AddOutputModifier(FGameplayModifierEvaluatedData(UCogSampleAttributeSet_Health::GetHealthAttribute(), EGameplayModOp::Additive, Heal));
}
}
@@ -0,0 +1,16 @@
#pragma once
#include "CoreMinimal.h"
#include "GameplayEffectExecutionCalculation.h"
#include "CogSampleExecCalculation_Heal.generated.h"
UCLASS()
class UCogSampleExecCalculation_Heal : public UGameplayEffectExecutionCalculation
{
GENERATED_BODY()
public:
UCogSampleExecCalculation_Heal();
virtual void Execute_Implementation(const FGameplayEffectCustomExecutionParameters& ExecutionParams, OUT FGameplayEffectCustomExecutionOutput& OutExecutionOutput) const override;
};
@@ -0,0 +1,24 @@
#include "CogSampleFunctionLibrary_Gameplay.h"
#include "AbilitySystemComponent.h"
#include "GameplayEffectTypes.h"
//--------------------------------------------------------------------------------------------------------------------------
void UCogSampleFunctionLibrary_Gameplay::AdjustAttributeForMaxChange(UAbilitySystemComponent* AbilityComponent, FGameplayAttributeData& AffectedAttribute, float OldValue, float NewMaxValue, const FGameplayAttribute& AffectedAttributeProperty)
{
if (AbilityComponent == nullptr)
{
return;
}
if (FMath::IsNearlyEqual(OldValue, NewMaxValue))
{
return;
}
// Change current value to maintain the current Val / Max percent
const float CurrentValue = AffectedAttribute.GetCurrentValue();
const float NewDelta = (OldValue > 0.f) ? (CurrentValue * NewMaxValue / OldValue) - CurrentValue : NewMaxValue;
AbilityComponent->ApplyModToAttributeUnsafe(AffectedAttributeProperty, EGameplayModOp::Additive, NewDelta);
}
@@ -0,0 +1,24 @@
#pragma once
#include "CoreMinimal.h"
#include "CogSampleFunctionLibrary_Gameplay.generated.h"
class UAbilitySystemComponent;
struct FGameplayAttribute;
struct FGameplayAttributeData;
#define ATTRIBUTE_ACCESSORS(ClassName, PropertyName) \
GAMEPLAYATTRIBUTE_PROPERTY_GETTER(ClassName, PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_GETTER(PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_SETTER(PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_INITTER(PropertyName)
UCLASS(meta = (ScriptName = "CogSampleFunctionLibrary_Gameplay"))
class UCogSampleFunctionLibrary_Gameplay : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
static void AdjustAttributeForMaxChange(UAbilitySystemComponent* AbilityComponent, FGameplayAttributeData& AffectedAttribute, float OldValue, float NewMaxValue, const FGameplayAttribute& AffectedAttributeProperty);
};
+12
View File
@@ -0,0 +1,12 @@
#include "CogSampleGameMode.h"
//--------------------------------------------------------------------------------------------------------------------------
ACogSampleGameMode::ACogSampleGameMode()
{
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleGameMode::BeginPlay()
{
Super::BeginPlay();
}
+18
View File
@@ -0,0 +1,18 @@
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "CogSampleGameMode.generated.h"
UCLASS(minimalapi)
class ACogSampleGameMode : public AGameModeBase
{
GENERATED_BODY()
public:
ACogSampleGameMode();
void BeginPlay();
};
+256
View File
@@ -0,0 +1,256 @@
#include "CogSampleGameState.h"
#include "AssetRegistry/AssetRegistryModule.h"
#include "AssetRegistry/IAssetRegistry.h"
#include "CogDefines.h"
#include "GameFramework/Character.h"
#include "GameFramework/GameMode.h"
#include "GameFramework/GameState.h"
#include "Modules/ModuleManager.h"
#if USE_COG
#include "CogAbilityDataAsset_Abilities.h"
#include "CogAbilityDataAsset_Cheats.h"
#include "CogAbilityDataAsset_Pools.h"
#include "CogAbilityDataAsset_Tweaks.h"
#include "CogAbilityModule.h"
#include "CogAbilityWindow_Abilities.h"
#include "CogAbilityWindow_Attributes.h"
#include "CogAbilityWindow_Cheats.h"
#include "CogAbilityWindow_Damages.h"
#include "CogAbilityWindow_Effects.h"
#include "CogAbilityWindow_Pools.h"
#include "CogAbilityWindow_Tags.h"
#include "CogAbilityWindow_Tweaks.h"
#include "CogDebugDefines.h"
#include "CogDebugPlot.h"
#include "CogEngineDataAsset_Collisions.h"
#include "CogEngineModule.h"
#include "CogEngineWindow_Collisions.h"
#include "CogEngineWindow_DebugSettings.h"
#include "CogEngineWindow_ImGui.h"
#include "CogEngineWindow_LogCategories.h"
#include "CogEngineWindow_NetEmulation.h"
#include "CogEngineWindow_OutputLog.h"
#include "CogEngineWindow_Plots.h"
#include "CogEngineWindow_Scalability.h"
#include "CogEngineWindow_Selection.h"
#include "CogEngineWindow_Skeleton.h"
#include "CogEngineWindow_Stats.h"
#include "CogEngineWindow_Time.h"
#include "CogImguiModule.h"
#include "CogInputDataAsset_Actions.h"
#include "CogInputWindow_Actions.h"
#include "CogInputWindow_Gamepad.h"
#include "CogSampleTagLibrary.h"
#include "CogWindowManager.h"
#endif //USE_COG
//--------------------------------------------------------------------------------------------------------------------------
template<typename T>
T* GetFirstAssetByClass()
{
IAssetRegistry& AssetRegistry = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry")).Get();
TArray<FAssetData> Assets;
AssetRegistry.GetAssetsByClass(T::StaticClass()->GetClassPathName(), Assets, true);
if (Assets.Num() == 0)
{
return nullptr;
}
UObject* Asset = Assets[0].GetAsset();
T* CastedAsset = Cast<T>(Asset);
return CastedAsset;
}
//--------------------------------------------------------------------------------------------------------------------------
ACogSampleGameState::ACogSampleGameState(const FObjectInitializer & ObjectInitializer)
: Super(ObjectInitializer)
{
SetActorTickEnabled(true);
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.SetTickFunctionEnable(true);
PrimaryActorTick.bStartWithTickEnabled = true;
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleGameState::BeginPlay()
{
Super::BeginPlay();
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleGameState::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
Super::EndPlay(EndPlayReason);
#if USE_COG
if (CogWindowManager != nullptr)
{
CogWindowManager->Shutdown();
}
#endif //USE_COG
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleGameState::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
#if USE_COG
TickCog(DeltaSeconds);
#endif //USE_COG
}
#if USE_COG
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleGameState::TickCog(float DeltaSeconds)
{
//---------------------------------------
// Wait for the viewport to be set
//---------------------------------------
if (GEngine->GameViewport != nullptr)
{
if (CogWindowManager == nullptr)
{
InitializeCog();
}
else
{
CogWindowManager->Tick(DeltaSeconds);
}
}
extern ENGINE_API float GAverageFPS;
extern ENGINE_API float GAverageMS;
FCogDebugPlot::PlotValue(this, "Frame Rate", GAverageFPS);
FCogDebugPlot::PlotValue(this, "Frame Time", GAverageMS);
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleGameState::InitializeCog()
{
TSharedPtr<SCogImguiWidget> Widget = FCogImguiModule::Get().CreateImGuiViewport(GEngine->GameViewport, [this](float DeltaTime) { RenderCog(DeltaTime); });
FCogImguiModule::Get().SetToggleInputKey(FCogImGuiKeyInfo(EKeys::Insert));
CogWindowManager = NewObject<UCogWindowManager>(this);
CogWindowManagerRef = CogWindowManager;
CogWindowManager->Initialize(GetWorld(), Widget);
//---------------------------------------
// Engine
//---------------------------------------
CogWindowManager->CreateWindow<UCogEngineWindow_DebugSettings>("Engine.Debug Settings");
CogWindowManager->CreateWindow<UCogEngineWindow_ImGui>("Engine.ImGui");
CogWindowManager->CreateWindow<UCogEngineWindow_LogCategories>("Engine.Log Categories");
CogWindowManager->CreateWindow<UCogEngineWindow_NetEmulation>("Engine.Net Emulation");
CogWindowManager->CreateWindow<UCogEngineWindow_OutputLog>("Engine.Output Log");
CogWindowManager->CreateWindow<UCogEngineWindow_Plots>("Engine.Plots");
CogWindowManager->CreateWindow<UCogEngineWindow_Scalability>("Engine.Scalability");
CogWindowManager->CreateWindow<UCogEngineWindow_Skeleton>("Engine.Skeleton");
CogWindowManager->CreateWindow<UCogEngineWindow_Time>("Engine.Time");
UCogEngineWindow_Stats* StatsWindow = CogWindowManager->CreateWindow<UCogEngineWindow_Stats>("Engine.Stats");
//---------------------------------------
// Selection
//---------------------------------------
UCogEngineWindow_Selection* SelectionWindow = CogWindowManager->CreateWindow<UCogEngineWindow_Selection>("Engine.Selection");
TArray<TSubclassOf<AActor>> SubClasses
{
AActor::StaticClass(),
AGameModeBase::StaticClass(),
AGameStateBase::StaticClass(),
ACharacter::StaticClass()
};
SelectionWindow->SetActorSubClasses(SubClasses);
SelectionWindow->SetCurrentActorSubClass(ACharacter::StaticClass());
SelectionWindow->SetTraceType(UEngineTypes::ConvertToTraceType(ECollisionChannel::ECC_Pawn));
//---------------------------------------
// Collision
//---------------------------------------
UCogEngineWindow_Collisions* CollisionsWindow = CogWindowManager->CreateWindow<UCogEngineWindow_Collisions>("Engine.Collision");
CollisionsWindow->SetCollisionsAsset(GetFirstAssetByClass<UCogEngineDataAsset_Collisions>());
//---------------------------------------
// Attributes
//---------------------------------------
CogWindowManager->CreateWindow<UCogAbilityWindow_Attributes>("Gameplay.Attributes");
//---------------------------------------
// Effects
//---------------------------------------
UCogAbilityWindow_Effects* EffectsWindow = CogWindowManager->CreateWindow<UCogAbilityWindow_Effects>("Gameplay.Effects");
EffectsWindow->NegativeEffectTag = Tag_Effect_Alignment_Negative;
EffectsWindow->PositiveEffectTag = Tag_Effect_Alignment_Positive;
//---------------------------------------
// Abilities
//---------------------------------------
UCogAbilityWindow_Abilities* AbilitiesWindow = CogWindowManager->CreateWindow<UCogAbilityWindow_Abilities>("Gameplay.Abilities");
AbilitiesWindow->AbilitiesAsset = GetFirstAssetByClass<UCogAbilityDataAsset_Abilities>();
//---------------------------------------
// Cheats
//---------------------------------------
UCogAbilityWindow_Cheats* CheatsWindow = CogWindowManager->CreateWindow<UCogAbilityWindow_Cheats>("Gameplay.Cheats");
CheatsWindow->CheatsAsset = GetFirstAssetByClass<UCogAbilityDataAsset_Cheats>();
//---------------------------------------
// Tweaks
//---------------------------------------
UCogAbilityWindow_Tweaks* TweaksWindow = CogWindowManager->CreateWindow<UCogAbilityWindow_Tweaks>("Gameplay.Tweaks");
TweaksWindow->TweaksAsset = GetFirstAssetByClass<UCogAbilityDataAsset_Tweaks>();
//---------------------------------------
// Damages
//---------------------------------------
CogWindowManager->CreateWindow<UCogAbilityWindow_Damages>("Gameplay.Damages");
//---------------------------------------
// Tags
//---------------------------------------
UCogAbilityWindow_Tags* TagsWindow = CogWindowManager->CreateWindow<UCogAbilityWindow_Tags>("Gameplay.Tags");
//---------------------------------------
// Pools
//---------------------------------------
UCogAbilityWindow_Pools* PoolsWindow = CogWindowManager->CreateWindow<UCogAbilityWindow_Pools>("Gameplay.Pools");
PoolsWindow->PoolsAsset = GetFirstAssetByClass<UCogAbilityDataAsset_Pools>();
//---------------------------------------
// Input Actions
//---------------------------------------
UCogInputWindow_Actions* ActionsWindow = CogWindowManager->CreateWindow<UCogInputWindow_Actions>("Input.Actions");
ActionsWindow->ActionsAsset = GetFirstAssetByClass<UCogInputDataAsset_Actions>();
//---------------------------------------
// Gamepad
//---------------------------------------
UCogInputWindow_Gamepad* GamepadWindow = CogWindowManager->CreateWindow<UCogInputWindow_Gamepad>("Input.Gamepad");
GamepadWindow->ActionsAsset = GetFirstAssetByClass<UCogInputDataAsset_Actions>();
//---------------------------------------
// Main Menu Widget
//---------------------------------------
CogWindowManager->AddMainMenuWidget(SelectionWindow);
CogWindowManager->AddMainMenuWidget(StatsWindow);
CogWindowManager->RebuildMenu();
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSampleGameState::RenderCog(float DeltaTime)
{
static bool ShowImGuiDemo = false;
if (ShowImGuiDemo)
{
ImGui::ShowDemoWindow(&ShowImGuiDemo);
}
CogWindowManager->Render(DeltaTime);
}
#endif //USE_COG
+32
View File
@@ -0,0 +1,32 @@
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameStateBase.h"
#include "CogDefines.h"
#include "CogSampleGameState.generated.h"
class UCogWindowManager;
UCLASS()
class ACogSampleGameState : public AGameStateBase
{
GENERATED_BODY()
ACogSampleGameState(const FObjectInitializer& ObjectInitializer);
virtual void BeginPlay() override;
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
virtual void Tick(float DeltaSeconds) override;
private:
UPROPERTY()
TObjectPtr<UObject> CogWindowManagerRef = nullptr;
#if USE_COG
void InitializeCog();
void TickCog(float DeltaTime);
void RenderCog(float DeltaTime);
TObjectPtr<UCogWindowManager> CogWindowManager = nullptr;
#endif //USE_COG
};
@@ -0,0 +1,27 @@
#include "CogSampleLogCategories.h"
#include "AbilitySystemLog.h"
#include "CogDefines.h"
#if USE_COG
#include "CogDebugLogCategoryManager.h"
#endif //USE_COG
DEFINE_LOG_CATEGORY(LogCogCollision);
DEFINE_LOG_CATEGORY(LogCogInput);
DEFINE_LOG_CATEGORY(LogCogPosition);
namespace CogSampleLog
{
void RegiterAllLogCategories()
{
#if USE_COG
FCogDebugLogCategoryManager::AddLogCategory(LogAbilitySystem);
FCogDebugLogCategoryManager::AddLogCategory(LogGameplayEffects);
FCogDebugLogCategoryManager::AddLogCategory(LogCogCollision);
FCogDebugLogCategoryManager::AddLogCategory(LogCogInput);
FCogDebugLogCategoryManager::AddLogCategory(LogCogPosition);
#endif //USE_COG
}
}
+10
View File
@@ -0,0 +1,10 @@
#include "CoreMinimal.h"
DECLARE_LOG_CATEGORY_EXTERN(LogCogCollision, Warning, All);
DECLARE_LOG_CATEGORY_EXTERN(LogCogInput, Warning, All);
DECLARE_LOG_CATEGORY_EXTERN(LogCogPosition, Warning, All);
namespace CogSampleLog
{
void RegiterAllLogCategories();
}
+33
View File
@@ -0,0 +1,33 @@
#include "CogSampleModule.h"
#include "CogSampleLogCategories.h"
#include "Modules/ModuleManager.h"
//--------------------------------------------------------------------------------------------------------------------------
class FCogSampleModule : public IModuleInterface
{
public:
/** IModuleInterface implementation */
virtual void StartupModule() override;
virtual void ShutdownModule() override;
private:
};
#define LOCTEXT_NAMESPACE "FCogInputModule"
//--------------------------------------------------------------------------------------------------------------------------
void FCogSampleModule::StartupModule()
{
CogSampleLog::RegiterAllLogCategories();
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogSampleModule::ShutdownModule()
{
}
#undef LOCTEXT_NAMESPACE
IMPLEMENT_PRIMARY_GAME_MODULE(FCogSampleModule, CogSample, "CogSample");
+5
View File
@@ -0,0 +1,5 @@
#pragma once
#include "CoreMinimal.h"
@@ -0,0 +1,41 @@
#include "CogSamplePlayerController.h"
#include "CogDefines.h"
#include "CogSampleCharacter.h"
#include "Net/UnrealNetwork.h"
#if USE_COG
#include "CogAbilityReplicator.h"
#include "CogDebugDefines.h"
#include "CogDebugReplicator.h"
#include "CogEngineReplicator.h"
#endif //USE_COG
//--------------------------------------------------------------------------------------------------------------------------
ACogSamplePlayerController::ACogSamplePlayerController()
{
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSamplePlayerController::BeginPlay()
{
Super::BeginPlay();
#if USE_COG
ACogDebugReplicator::Create(this);
ACogAbilityReplicator::Create(this);
ACogEngineReplicator::Create(this);
#endif //USE_COG
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogSamplePlayerController::AcknowledgePossession(APawn* P)
{
Super::AcknowledgePossession(P);
if (ACogSampleCharacter* PossessedCharacter = Cast<ACogSampleCharacter>(P))
{
PossessedCharacter->OnAcknowledgePossession(this);
}
}
@@ -0,0 +1,23 @@
#pragma once
#include "CoreMinimal.h"
#include "AbilitySystemInterface.h"
#include "GameFramework/PlayerController.h"
#include "CogSamplePlayerController.generated.h"
UCLASS(config=Game)
class ACogSamplePlayerController : public APlayerController
{
GENERATED_BODY()
public:
ACogSamplePlayerController();
virtual void BeginPlay() override;
virtual void AcknowledgePossession(APawn* P);
private:
};
+26
View File
@@ -0,0 +1,26 @@
#include "CogSampleTagLibrary.h"
UE_DEFINE_GAMEPLAY_TAG(Tag_Effect_Alignment_Negative, "Effect.Alignment.Negative");
UE_DEFINE_GAMEPLAY_TAG(Tag_Effect_Alignment_Positive, "Effect.Alignment.Positive");
UE_DEFINE_GAMEPLAY_TAG(Tag_Effect_Data_Amount, "Effect.Data.Amount");
UE_DEFINE_GAMEPLAY_TAG(Tag_Effect_Data_Damage, "Effect.Data.Damage");
UE_DEFINE_GAMEPLAY_TAG(Tag_Effect_Data_Heal, "Effect.Data.Heal");
UE_DEFINE_GAMEPLAY_TAG(Tag_Effect_Type_Damage_Kill, "Effect.Type.Damage.Kill");
UE_DEFINE_GAMEPLAY_TAG(Tag_Effect_Type_Heal_Full, "Effect.Type.Heal.Full");
UE_DEFINE_GAMEPLAY_TAG(Tag_Effect_Type_Heal_Revive, "Effect.Type.Heal.Revive");
UE_DEFINE_GAMEPLAY_TAG(Tag_GameplayEvent_Killed, "GameplayEvent.Killed");
UE_DEFINE_GAMEPLAY_TAG(Tag_GameplayEvent_Revived, "GameplayEvent.Revived");
UE_DEFINE_GAMEPLAY_TAG(Tag_Status_Dead, "Effect.Status.Dead");
UE_DEFINE_GAMEPLAY_TAG(Tag_Status_Ghost, "Effect.Status.Ghost");
UE_DEFINE_GAMEPLAY_TAG(Tag_Status_Immobilized, "Effect.Status.Immobilized");
UE_DEFINE_GAMEPLAY_TAG(Tag_Status_Immune_Damage, "Effect.Status.Immune.Damage");
UE_DEFINE_GAMEPLAY_TAG(Tag_Status_Revived, "Effect.Status.Revived");
UE_DEFINE_GAMEPLAY_TAG(Tag_Status_Silenced, "Effect.Status.Silenced");
UE_DEFINE_GAMEPLAY_TAG(Tag_Status_Stunned, "Effect.Status.Stunned");
UE_DEFINE_GAMEPLAY_TAG(Tag_Unit_Hero, "Unit.Hero");
UE_DEFINE_GAMEPLAY_TAG(Tag_Unit_Creature, "Unit.Creature");
+32
View File
@@ -0,0 +1,32 @@
#pragma once
#include "CoreMinimal.h"
#include "NativeGameplayTags.h"
UE_DECLARE_GAMEPLAY_TAG_EXTERN(Tag_Effect_Alignment_Negative);
UE_DECLARE_GAMEPLAY_TAG_EXTERN(Tag_Effect_Alignment_Positive);
UE_DECLARE_GAMEPLAY_TAG_EXTERN(Tag_Effect_Data_Amount);
UE_DECLARE_GAMEPLAY_TAG_EXTERN(Tag_Effect_Data_Damage);
UE_DECLARE_GAMEPLAY_TAG_EXTERN(Tag_Effect_Data_Heal);
UE_DECLARE_GAMEPLAY_TAG_EXTERN(Tag_Effect_Type_Damage_Kill);
UE_DECLARE_GAMEPLAY_TAG_EXTERN(Tag_Effect_Type_Heal_Full);
UE_DECLARE_GAMEPLAY_TAG_EXTERN(Tag_Effect_Type_Heal_Revive);
UE_DECLARE_GAMEPLAY_TAG_EXTERN(Tag_GameplayEvent_Killed);
UE_DECLARE_GAMEPLAY_TAG_EXTERN(Tag_GameplayEvent_Revived);
UE_DECLARE_GAMEPLAY_TAG_EXTERN(Tag_Status_Dead);
UE_DECLARE_GAMEPLAY_TAG_EXTERN(Tag_Status_Ghost);
UE_DECLARE_GAMEPLAY_TAG_EXTERN(Tag_Status_Immobilized);
UE_DECLARE_GAMEPLAY_TAG_EXTERN(Tag_Status_Immune_Damage);
UE_DECLARE_GAMEPLAY_TAG_EXTERN(Tag_Status_Revived);
UE_DECLARE_GAMEPLAY_TAG_EXTERN(Tag_Status_Silenced);
UE_DECLARE_GAMEPLAY_TAG_EXTERN(Tag_Status_Stunned);
UE_DECLARE_GAMEPLAY_TAG_EXTERN(Tag_Unit_Hero);
UE_DECLARE_GAMEPLAY_TAG_EXTERN(Tag_Unit_Creature);
+13
View File
@@ -0,0 +1,13 @@
using UnrealBuildTool;
using System.Collections.Generic;
public class CogSampleEditorTarget : TargetRules
{
public CogSampleEditorTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Editor;
DefaultBuildSettings = BuildSettingsVersion.V2;
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_1;
ExtraModuleNames.Add("CogSample");
}
}