From f1a4a44c8d93ebd32f7b4964fb641644d8bd3782 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Tue, 22 Oct 2024 15:19:45 -0400 Subject: [PATCH] 66. Initialize Attributes with Gameplay Effects --- .../Win64/UnrealEditor-GasaEditor.dll | 4 +- .../DT_GasaAttributeSet.json | 3 +- .../Gasa/AbilitySystem/GasaAttributeSet.cpp | 2 + .../Gasa/AbilitySystem/GasaAttributeSet.h | 41 ------------------- .../Source/Gasa/Characters/GasaCharacter.cpp | 29 +++++++++---- .../Source/Gasa/Characters/GasaCharacter.h | 10 ++++- .../Source/Gasa/Game/GasaPlayerController.cpp | 2 + .../GasaGen/GasaGen_AttributeSets.cpp | 16 -------- 8 files changed, 36 insertions(+), 71 deletions(-) diff --git a/Project/Binaries/Win64/UnrealEditor-GasaEditor.dll b/Project/Binaries/Win64/UnrealEditor-GasaEditor.dll index aa60cb9..05c5633 100644 --- a/Project/Binaries/Win64/UnrealEditor-GasaEditor.dll +++ b/Project/Binaries/Win64/UnrealEditor-GasaEditor.dll @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5d92841f5054f1f802c4ff6b6c421045e90af0d2c6668dc24d7c542ba2e1a3e9 -size 50547200 +oid sha256:5bb8dfb7210f755361a29e7293ceacfa0d1b44c427fb5a33519fd85be4d65824 +size 50546176 diff --git a/Project/Saved/AssetData/DataTableEditorLayout/DT_GasaAttributeSet.json b/Project/Saved/AssetData/DataTableEditorLayout/DT_GasaAttributeSet.json index 5d08edf..a3782b6 100644 --- a/Project/Saved/AssetData/DataTableEditorLayout/DT_GasaAttributeSet.json +++ b/Project/Saved/AssetData/DataTableEditorLayout/DT_GasaAttributeSet.json @@ -5,6 +5,7 @@ "Description": 135, "Category": 96, "BaseValue": 106, - "Name": 82 + "Name": 82, + "MinAttribute": 327 } } \ No newline at end of file diff --git a/Project/Source/Gasa/AbilitySystem/GasaAttributeSet.cpp b/Project/Source/Gasa/AbilitySystem/GasaAttributeSet.cpp index 3418eb5..101dc01 100644 --- a/Project/Source/Gasa/AbilitySystem/GasaAttributeSet.cpp +++ b/Project/Source/Gasa/AbilitySystem/GasaAttributeSet.cpp @@ -103,6 +103,8 @@ void UGasaAttributeSet::PostGameplayEffectExecute( FGameplayEffectModCallbackDat { SetMaxMana( FMath::Clamp( GetMaxMana(), 0, 99999.000000 ) ); } + + Props.Populate( Data ); } void UGasaAttributeSet::PreAttributeChange( FGameplayAttribute const& Attribute, float& NewValue ) diff --git a/Project/Source/Gasa/AbilitySystem/GasaAttributeSet.h b/Project/Source/Gasa/AbilitySystem/GasaAttributeSet.h index bf47892..5cd78a6 100644 --- a/Project/Source/Gasa/AbilitySystem/GasaAttributeSet.h +++ b/Project/Source/Gasa/AbilitySystem/GasaAttributeSet.h @@ -115,47 +115,6 @@ public: FORCEINLINE void SetVigor( float NewVal ); FORCEINLINE void SetMaxHealth( float NewVal ); FORCEINLINE void SetMaxMana( float NewVal ); - - FORCEINLINE void InitHealth( float NewVal ) - { - Health.SetBaseValue( NewVal ); - Health.SetCurrentValue( NewVal ); - } - FORCEINLINE void InitMana( float NewVal ) - { - Mana.SetBaseValue( NewVal ); - Mana.SetCurrentValue( NewVal ); - } - FORCEINLINE void InitStrength( float NewVal ) - { - Strength.SetBaseValue( NewVal ); - Strength.SetCurrentValue( NewVal ); - } - FORCEINLINE void InitIntelligence( float NewVal ) - { - Intelligence.SetBaseValue( NewVal ); - Intelligence.SetCurrentValue( NewVal ); - } - FORCEINLINE void InitResilience( float NewVal ) - { - Resilience.SetBaseValue( NewVal ); - Resilience.SetCurrentValue( NewVal ); - } - FORCEINLINE void InitVigor( float NewVal ) - { - Vigor.SetBaseValue( NewVal ); - Vigor.SetCurrentValue( NewVal ); - } - FORCEINLINE void InitMaxHealth( float NewVal ) - { - MaxHealth.SetBaseValue( NewVal ); - MaxHealth.SetCurrentValue( NewVal ); - } - FORCEINLINE void InitMaxMana( float NewVal ) - { - MaxMana.SetBaseValue( NewVal ); - MaxMana.SetCurrentValue( NewVal ); - } #pragma endregion Setters #pragma region AttributeSet diff --git a/Project/Source/Gasa/Characters/GasaCharacter.cpp b/Project/Source/Gasa/Characters/GasaCharacter.cpp index 508239c..f966578 100644 --- a/Project/Source/Gasa/Characters/GasaCharacter.cpp +++ b/Project/Source/Gasa/Characters/GasaCharacter.cpp @@ -69,10 +69,16 @@ void AGasaCharacter::InitDefaultAttributes() { UAbilitySystemComponent* ASC = GetAbilitySystemComponent(); ensure(ASC); - ensure(DefaultAttributes); - FGameplayEffectContextHandle Context = ASC->MakeEffectContext(); - FGameplayEffectSpecHandle Spec = ASC->MakeOutgoingSpec(DefaultAttributes, 1.0f, Context ); - ASC->ApplyGameplayEffectSpecToTarget( * Spec.Data, ASC ); + ensure(DefaultVitalAttributes); + ensure(DefaultPrimaryAttributes); + ensure(DefaultSecondaryAttributes); + FGameplayEffectContextHandle Context = ASC->MakeEffectContext(); + FGameplayEffectSpecHandle SpecPrimary = ASC->MakeOutgoingSpec(DefaultPrimaryAttributes, 1.0f, Context ); + FGameplayEffectSpecHandle SpecSecondary = ASC->MakeOutgoingSpec(DefaultSecondaryAttributes, 1.0f, Context ); + FGameplayEffectSpecHandle SpecVital = ASC->MakeOutgoingSpec(DefaultVitalAttributes, 1.0f, Context ); + ASC->ApplyGameplayEffectSpecToTarget( * SpecPrimary.Data, ASC ); + ASC->ApplyGameplayEffectSpecToTarget( * SpecSecondary.Data, ASC ); + ASC->ApplyGameplayEffectSpecToTarget( * SpecVital.Data, ASC ); } #pragma endregion Ability System @@ -168,11 +174,15 @@ void AGasaCharacter::PossessedBy(AController* NewController) GetMesh()->bOnlyAllowAutonomousTickPose = true; } -#if 0 - if (bAutoAbilitySystem) - { - AbilitySystem->InitAbilityActorInfo(this, this); - } +#if 1 +// if (bAutoAbilitySystem) +// { +// // Note(Ed): For the player character; this is manually called by the player controller in NetOwner_Ready() +// AbilitySystem->InitAbilityActorInfo(this, this); +// Cast(AbilitySystem)->OnAbilityActorInfoSet(); +// +// InitDefaultAttributes(); +// } #endif } @@ -196,6 +206,7 @@ void AGasaCharacter::BeginPlay() // There is also OnPossessed, PostInitializeComponents, etc... if (bAutoAbilitySystem) { + // Note(Ed): For the player character; this is manually called by the player controller in NetOwner_Ready() AbilitySystem->InitAbilityActorInfo(this, this); Cast(AbilitySystem)->OnAbilityActorInfoSet(); diff --git a/Project/Source/Gasa/Characters/GasaCharacter.h b/Project/Source/Gasa/Characters/GasaCharacter.h index 7babd28..42afc6b 100644 --- a/Project/Source/Gasa/Characters/GasaCharacter.h +++ b/Project/Source/Gasa/Characters/GasaCharacter.h @@ -13,7 +13,7 @@ UENUM(BlueprintType) enum class EHighlight : uint8 { Disabled, - Enabled, + Enabled,ddddddd }; UCLASS(Abstract) @@ -36,7 +36,13 @@ public: TObjectPtr Attributes; UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Ability System") - TSubclassOf DefaultAttributes; + TSubclassOf DefaultVitalAttributes; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Ability System") + TSubclassOf DefaultPrimaryAttributes; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Ability System") + TSubclassOf DefaultSecondaryAttributes; void InitDefaultAttributes(); #pragma endregion Ability System diff --git a/Project/Source/Gasa/Game/GasaPlayerController.cpp b/Project/Source/Gasa/Game/GasaPlayerController.cpp index f82e224..5cc06cd 100644 --- a/Project/Source/Gasa/Game/GasaPlayerController.cpp +++ b/Project/Source/Gasa/Game/GasaPlayerController.cpp @@ -78,6 +78,8 @@ void AGasaPlayerController::NetOwner_OnReady() PlayerChar->Attributes = PS->Attributes; PS->AbilitySystem->InitAbilityActorInfo(PS, PlayerChar); Cast(PS->AbilitySystem)->OnAbilityActorInfoSet(); + + PlayerChar->InitDefaultAttributes(); } Cam->AttachToActor(PlayerChar, FAttachmentTransformRules::KeepRelativeTransform); } diff --git a/Project/Source/GasaEditor/GasaGen/GasaGen_AttributeSets.cpp b/Project/Source/GasaEditor/GasaGen/GasaGen_AttributeSets.cpp index a26a175..82b8f01 100644 --- a/Project/Source/GasaEditor/GasaGen/GasaGen_AttributeSets.cpp +++ b/Project/Source/GasaEditor/GasaGen/GasaGen_AttributeSets.cpp @@ -159,22 +159,6 @@ void gen_attribute_set_from_table( UDataTable* table, FString asset_name ) FORCEINLINE void Set(float NewVal); ))); } - body.append(fmt_newline); - body.append(fmt_newline); - - // Generate initers - for ( TPair< FName, TArray>& attributes : AttributesByCategory ) - for (FAttributeSetField attribute : attributes.Value) - { - body.append(code_fmt("property", (StrC)to_string(attribute.Name), - stringize( - FORCEINLINE void Init(float NewVal) - { - .SetBaseValue(NewVal); - .SetCurrentValue(NewVal); - } - ))); - } } body.append(def_pragma(txt("endregion Setters"))); body.append(fmt_newline);