Implemented CombatAttribute
This commit is contained in:
parent
a43fc18456
commit
fe8ee2e867
@ -0,0 +1,30 @@
|
|||||||
|
// © 2024 Long Ly. All rights reserved. Any unauthorized use, reproduction, or distribution of this trademark is strictly prohibited and may result in legal action.
|
||||||
|
|
||||||
|
|
||||||
|
#include "AbilitySystem/Attributes/OLSCombatAttributeSet.h"
|
||||||
|
|
||||||
|
#include "Net/UnrealNetwork.h"
|
||||||
|
|
||||||
|
UOLSCombatAttributeSet::UOLSCombatAttributeSet()
|
||||||
|
: BaseDamage(0.0f)
|
||||||
|
, BaseHeal(0.0f)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void UOLSCombatAttributeSet::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
|
||||||
|
{
|
||||||
|
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
|
||||||
|
|
||||||
|
DOREPLIFETIME_CONDITION_NOTIFY(ThisClass, BaseDamage, COND_OwnerOnly, REPNOTIFY_Always);
|
||||||
|
DOREPLIFETIME_CONDITION_NOTIFY(ThisClass, BaseHeal, COND_OwnerOnly, REPNOTIFY_Always);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UOLSCombatAttributeSet::OnRep_BaseDamage(const FGameplayAttributeData& oldValue)
|
||||||
|
{
|
||||||
|
GAMEPLAYATTRIBUTE_REPNOTIFY(ThisClass, BaseDamage, oldValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UOLSCombatAttributeSet::OnRep_BaseHeal(const FGameplayAttributeData& oldValue)
|
||||||
|
{
|
||||||
|
GAMEPLAYATTRIBUTE_REPNOTIFY(ThisClass, BaseHeal, oldValue);
|
||||||
|
}
|
@ -229,7 +229,7 @@ void UOLSHealthAttributeSet::PostAttributeChange(const FGameplayAttribute& attri
|
|||||||
}
|
}
|
||||||
|
|
||||||
void UOLSHealthAttributeSet::ClampAttribute(const FGameplayAttribute& attribute, float& outNewValue) const
|
void UOLSHealthAttributeSet::ClampAttribute(const FGameplayAttribute& attribute, float& outNewValue) const
|
||||||
{
|
{
|
||||||
if (attribute == GetHealthAttribute())
|
if (attribute == GetHealthAttribute())
|
||||||
{
|
{
|
||||||
// Do not allow health to go negative or above max health.
|
// Do not allow health to go negative or above max health.
|
||||||
|
@ -18,7 +18,7 @@ AOLSCharacter::AOLSCharacter(const FObjectInitializer& objectInitializer) : Supe
|
|||||||
PrimaryActorTick.bCanEverTick = false;
|
PrimaryActorTick.bCanEverTick = false;
|
||||||
PrimaryActorTick.bStartWithTickEnabled = false;
|
PrimaryActorTick.bStartWithTickEnabled = false;
|
||||||
|
|
||||||
NetCullDistanceSquared = 900000000.0f;
|
SetNetCullDistanceSquared(900000000.0f);
|
||||||
|
|
||||||
LocomotionComponent = CreateDefaultSubobject<UOLSLocomotionComponent>(TEXT("Locomotion Component"));
|
LocomotionComponent = CreateDefaultSubobject<UOLSLocomotionComponent>(TEXT("Locomotion Component"));
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include "Player/OLSPlayerState.h"
|
#include "Player/OLSPlayerState.h"
|
||||||
|
|
||||||
#include "AbilitySystem/OLSAbilitySystemComponent.h"
|
#include "AbilitySystem/OLSAbilitySystemComponent.h"
|
||||||
|
#include "AbilitySystem/Attributes/OLSCombatAttributeSet.h"
|
||||||
|
#include "AbilitySystem/Attributes/OLSHealthAttributeSet.h"
|
||||||
#include "Components/GameFrameworkComponentManager.h"
|
#include "Components/GameFrameworkComponentManager.h"
|
||||||
#include "DataAssets/OLSAbilitySetPrimaryDataAsset.h"
|
#include "DataAssets/OLSAbilitySetPrimaryDataAsset.h"
|
||||||
#include "GameModes/OLSExperienceManagerComponent.h"
|
#include "GameModes/OLSExperienceManagerComponent.h"
|
||||||
@ -18,6 +20,17 @@ const FName AOLSPlayerState::NAME_OLSAbilityReady("OLSAbilitiesReady");
|
|||||||
AOLSPlayerState::AOLSPlayerState(const FObjectInitializer& objectInitializer) : Super(objectInitializer)
|
AOLSPlayerState::AOLSPlayerState(const FObjectInitializer& objectInitializer) : Super(objectInitializer)
|
||||||
{
|
{
|
||||||
// Create attribute sets here.
|
// Create attribute sets here.
|
||||||
|
|
||||||
|
AbilitySystemComponent = objectInitializer.CreateDefaultSubobject<UOLSAbilitySystemComponent>(this, TEXT("AbilitySystemComponent"));
|
||||||
|
AbilitySystemComponent->SetIsReplicated(true);
|
||||||
|
AbilitySystemComponent->SetReplicationMode(EGameplayEffectReplicationMode::Mixed);
|
||||||
|
|
||||||
|
// These attribute sets will be detected by AbilitySystemComponent::InitializeComponent. Keeping a reference so that the sets don't get garbage collected before that.
|
||||||
|
HealthSet = CreateDefaultSubobject<UOLSHealthAttributeSet>(TEXT("HealthSet"));
|
||||||
|
CombatSet = CreateDefaultSubobject<UOLSCombatAttributeSet>(TEXT("CombatSet"));
|
||||||
|
|
||||||
|
// AbilitySystemComponent needs to be updated at a high frequency.
|
||||||
|
SetNetUpdateFrequency(100.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AOLSPlayerState::SetPawnData(const UOLSPawnDataAsset* pawnData)
|
void AOLSPlayerState::SetPawnData(const UOLSPawnDataAsset* pawnData)
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
// © 2024 Long Ly. All rights reserved. Any unauthorized use, reproduction, or distribution of this trademark is strictly prohibited and may result in legal action.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "AbilitySystemComponent.h"
|
||||||
|
#include "OLSAttributeSetBase.h"
|
||||||
|
#include "OLSCombatAttributeSet.generated.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UOLSCombatAttributeSet
|
||||||
|
*
|
||||||
|
* Class that defines attributes that are necessary for applying damage or healing.
|
||||||
|
* Attribute examples include: damage, healing, attack power, and shield penetrations.
|
||||||
|
*/
|
||||||
|
UCLASS(BlueprintType)
|
||||||
|
class OLS_API UOLSCombatAttributeSet : public UOLSAttributeSetBase
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
UOLSCombatAttributeSet();
|
||||||
|
|
||||||
|
//~ Begin UObject interface.
|
||||||
|
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
|
||||||
|
//~ End UObject interface.
|
||||||
|
|
||||||
|
ATTRIBUTE_ACCESSORS(ThisClass, BaseDamage);
|
||||||
|
ATTRIBUTE_ACCESSORS(ThisClass, BaseHeal);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void OnRep_BaseDamage(const FGameplayAttributeData& oldValue);
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void OnRep_BaseHeal(const FGameplayAttributeData& oldValue);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// The base amount of damage to apply in the damage execution.
|
||||||
|
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_BaseDamage, Category = "OLS|Combat", Meta = (AllowPrivateAccess = true))
|
||||||
|
FGameplayAttributeData BaseDamage;
|
||||||
|
|
||||||
|
// The base amount of healing to apply in the heal execution.
|
||||||
|
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_BaseHeal, Category = "OLS|Combat", Meta = (AllowPrivateAccess = true))
|
||||||
|
FGameplayAttributeData BaseHeal;
|
||||||
|
};
|
@ -85,4 +85,14 @@ private:
|
|||||||
|
|
||||||
UPROPERTY(Replicated)
|
UPROPERTY(Replicated)
|
||||||
FOLSGameplayTagStackContainer StatTags;
|
FOLSGameplayTagStackContainer StatTags;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// Health attribute set used by this actor.
|
||||||
|
UPROPERTY()
|
||||||
|
TObjectPtr<const class UOLSHealthAttributeSet> HealthSet = nullptr;
|
||||||
|
|
||||||
|
// Combat attribute set used by this actor.
|
||||||
|
UPROPERTY()
|
||||||
|
TObjectPtr<const class UOLSCombatAttributeSet> CombatSet = nullptr;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user