Lesson 105 - Set up move to click.

This commit is contained in:
2025-10-16 14:33:58 -04:00
parent 99439dcee7
commit d436c459ec
108 changed files with 11025 additions and 21587 deletions

View File

@@ -4,17 +4,62 @@
#include "AbilitySystem/AuraAbilitySystemComponent.h"
#include "AuraGameplayTags.h"
#include "AbilitySystem/GameplayAbility/AuraGameplayAbility.h"
void UAuraAbilitySystemComponent::AbilityActorInfoSet()
{
OnGameplayEffectAppliedDelegateToSelf.AddUObject( this, &UAuraAbilitySystemComponent::EffectApplied);
const FAuraGameplayTags& GameplayTags = FAuraGameplayTags::Get();
//const FAuraGameplayTags& GameplayTags = FAuraGameplayTags::Get();
//GameplayTags.Attributes_Secondary_Armor.ToString();
}
void UAuraAbilitySystemComponent::AddCharacterAbilities(const TArray<TSubclassOf<UGameplayAbility>>& StartupAbilities)
{
for (const TSubclassOf<UGameplayAbility> AbilityClass : StartupAbilities)
{
FGameplayAbilitySpec AbilitySpec = FGameplayAbilitySpec(AbilityClass, 1); //Cannot be Const if GiveAbilityAndActivateOnce
if (const UAuraGameplayAbility* AuraAbility = Cast<UAuraGameplayAbility>(AbilitySpec.Ability))
{
//AbilitySpec.DynamicAbilityTags is depreciated, use GetDynamicSpecSourceTags() instead.
AbilitySpec.GetDynamicSpecSourceTags().AddTag(AuraAbility->StartupInputTag);
GiveAbility(AbilitySpec);
}
}
}
void UAuraAbilitySystemComponent::AbilityInputTagHeld(const FGameplayTag& InputTag)
{
if (!InputTag.IsValid()) return;
for (FGameplayAbilitySpec& AbilitySpec : GetActivatableAbilities())
{
//AbilitySpec.DynamicAbilityTags is depreciated, use GetDynamicSpecSourceTags() instead.
if (AbilitySpec.GetDynamicSpecSourceTags().HasTagExact(InputTag))
{
AbilitySpecInputPressed(AbilitySpec);
if (!AbilitySpec.IsActive())
{
TryActivateAbility(AbilitySpec.Handle);
}
}
}
}
void UAuraAbilitySystemComponent::AbilityInputTagReleased(const FGameplayTag& InputTag)
{
if (!InputTag.IsValid()) return;
for (FGameplayAbilitySpec& AbilitySpec : GetActivatableAbilities())
{
//AbilitySpec.DynamicAbilityTags is depreciated, use GetDynamicSpecSourceTags() instead.
if (AbilitySpec.GetDynamicSpecSourceTags().HasTagExact(InputTag))
{
AbilitySpecInputPressed(AbilitySpec);
}
}
}
void UAuraAbilitySystemComponent::EffectApplied(UAbilitySystemComponent* AbilitySystemComponent,
const FGameplayEffectSpec& EffectSpec, FActiveGameplayEffectHandle ActiveEffectHandle)
const FGameplayEffectSpec& EffectSpec, FActiveGameplayEffectHandle ActiveEffectHandle)
{
//GEngine->AddOnScreenDebugMessage(1,8.f, FColor::Blue,FString("Effect Applied!"));

View File

@@ -29,11 +29,22 @@ void FAuraGameplayTags::InitializeNativeGameplayTags()
GameplayTags.Attributes_Secondary_HealthRegeneration = UGameplayTagsManager::Get().AddNativeGameplayTag(FName("Attributes.Secondary.HealthRegeneration"), FString(""));
GameplayTags.Attributes_Secondary_ManaRegeneration = UGameplayTagsManager::Get().AddNativeGameplayTag(FName("Attributes.Secondary.ManaRegeneration"), FString(""));
//Tertiary Stats - Resistances - Physical, Arcane, Fire, Lightning
GameplayTags.Attributes_Resistance_Physical = UGameplayTagsManager::Get().AddNativeGameplayTag(FName("Attributes.Resistance.Physical"), FString(""));
GameplayTags.Attributes_Resistance_Arcane = UGameplayTagsManager::Get().AddNativeGameplayTag(FName("Attributes.Resistance.Arcane"), FString(""));
GameplayTags.Attributes_Resistance_Fire = UGameplayTagsManager::Get().AddNativeGameplayTag(FName("Attributes.Resistance.Fire"), FString(""));
GameplayTags.Attributes_Resistance_Lightning = UGameplayTagsManager::Get().AddNativeGameplayTag(FName("Attributes.Resistance.Lightning"), FString(""));
/*
*Input Tags
*
*/
GameplayTags.Input_InputTag_LMB = UGameplayTagsManager::Get().AddNativeGameplayTag(FName("Input.InputTag.LMB"), FString("Input Tag - Left Mouse Button"));
GameplayTags.Input_InputTag_RMB = UGameplayTagsManager::Get().AddNativeGameplayTag(FName("Input.InputTag.RMB"), FString("Input Tag - Right Mouse Button"));
GameplayTags.Input_InputTag_1 = UGameplayTagsManager::Get().AddNativeGameplayTag(FName("Input.InputTag.1"), FString("Input Tag - Input 1"));
GameplayTags.Input_InputTag_2 = UGameplayTagsManager::Get().AddNativeGameplayTag(FName("Input.InputTag.2"), FString("Input Tag - Input 2"));
GameplayTags.Input_InputTag_3 = UGameplayTagsManager::Get().AddNativeGameplayTag(FName("Input.InputTag.3"), FString("Input Tag - Input 3"));
GameplayTags.Input_InputTag_4 = UGameplayTagsManager::Get().AddNativeGameplayTag(FName("Input.InputTag.4"), FString("Input Tag - Input 4"));
GameplayTags.Input_InputTag_5 = UGameplayTagsManager::Get().AddNativeGameplayTag(FName("Input.InputTag.5"), FString("Input Tag - Input 5"));
GameplayTags.Input_InputTag_6 = UGameplayTagsManager::Get().AddNativeGameplayTag(FName("Input.InputTag.6"), FString("Input Tag - Input 6"));
GameplayTags.Input_InputTag_7 = UGameplayTagsManager::Get().AddNativeGameplayTag(FName("Input.InputTag.7"), FString("Input Tag - Input 7"));
GameplayTags.Input_InputTag_8 = UGameplayTagsManager::Get().AddNativeGameplayTag(FName("Input.InputTag.8"), FString("Input Tag - Input 8"));
GameplayTags.Input_InputTag_9 = UGameplayTagsManager::Get().AddNativeGameplayTag(FName("Input.InputTag.9"), FString("Input Tag - Input 9"));
GameplayTags.Input_InputTag_10 = UGameplayTagsManager::Get().AddNativeGameplayTag(FName("Input.InputTag.10"), FString("Input Tag - Input 10"));
}

View File

@@ -27,6 +27,7 @@ void AAuraCharacter::PossessedBy(AController* NewController)
Super::PossessedBy(NewController);
//UE_LOG(LogTemp, Warning, TEXT("AuraCharacter.cpp - PossessedBy"));
InitAbilityActorInfo(); //Init Ability Actor Info for the Server
AddCharacterAbilities();
}
void AAuraCharacter::OnRep_PlayerState()

View File

@@ -3,6 +3,7 @@
#include "Character/AuraCharacterBase.h"
#include "AbilitySystemComponent.h"
#include "AbilitySystem/AuraAbilitySystemComponent.h"
AAuraCharacterBase::AAuraCharacterBase()
{
@@ -47,4 +48,13 @@ void AAuraCharacterBase::InitializeDefaultAttributes() const
ApplyEffectToSelf(DefaultVitalAttributes, 1.f);
}
void AAuraCharacterBase::AddCharacterAbilities()
{
UAuraAbilitySystemComponent* AuraASC = CastChecked<UAuraAbilitySystemComponent>(AbilitySystemComponent);
if (!HasAuthority()) return;
AuraASC->AddCharacterAbilities(StartupAbilities);
}

View File

@@ -1,14 +1,21 @@
// Copyright Echo Devgroup
#include "AbilitySystemBlueprintLibrary.h"
#include "Player/AuraPlayerController.h"
#include "AuraGameplayTags.h"
#include "EnhancedInputSubsystems.h"
#include "EnhancedInputComponent.h"
#include "AbilitySystem/AuraAbilitySystemComponent.h"
#include "AbilitySystem/AuraAbilitySystemLibrary.h"
#include "Components/SplineComponent.h"
#include "Input/AuraInputComponent.h"
#include "Interact/EnemyInterface.h"
AAuraPlayerController::AAuraPlayerController()
{
bReplicates = true;
Spline = CreateDefaultSubobject<USplineComponent>("Spline");
}
void AAuraPlayerController::PlayerTick(float DeltaTime)
@@ -49,7 +56,7 @@ void AAuraPlayerController::CursorTrace()
if (ThisActor != nullptr)
{
//Case B
//ThisActor->HighlightActor();
ThisActor->HighlightActor();
//UE_LOG(LogTemp, Warning, TEXT("Case B"));
}
}
@@ -57,14 +64,14 @@ void AAuraPlayerController::CursorTrace()
{
if (ThisActor == nullptr)
{
//LastActor->UnHighlightActor();
LastActor->UnHighlightActor();
}
else
{
if (LastActor != ThisActor) // Case D
{
//LastActor->UnHighlightActor();
//ThisActor->HighlightActor();
LastActor->UnHighlightActor();
ThisActor->HighlightActor();
}
}
@@ -72,6 +79,74 @@ void AAuraPlayerController::CursorTrace()
}
void AAuraPlayerController::AbilityInputTagPressed(FGameplayTag InputTag)
{
//For Debug of key pressed
//GEngine->AddOnScreenDebugMessage(1, 3.f, FColor::Red, *InputTag.ToString());
//Are we targetting something?
if (InputTag.MatchesTagExact(FAuraGameplayTags::Get().Input_InputTag_LMB))
{
bTargeting = ThisActor ? true : false;
bAutoRunning = false;
}
}
void AAuraPlayerController::AbilityInputTagReleased(FGameplayTag InputTag)
{
//For Debug of Key Held
//GEngine->AddOnScreenDebugMessage(1, 3.f, FColor::Red, *InputTag.ToString());
if (GetASC() == nullptr) return;
GetASC()->AbilityInputTagReleased(InputTag);
}
void AAuraPlayerController::AbilityInputTagHeld(FGameplayTag InputTag)
{
//For Debug of Key Held
//GEngine->AddOnScreenDebugMessage(1, 3.f, FColor::Red, *InputTag.ToString());
if (!InputTag.MatchesTagExact(FAuraGameplayTags::Get().Input_InputTag_LMB))
{
if (GetASC() == nullptr) return;
GetASC()->AbilityInputTagHeld(InputTag);
}
if (bTargeting)
{
if (GetASC())
{
GetASC()->AbilityInputTagHeld(InputTag);
}
}
else
{
FollowTime += GetWorld()->GetDeltaSeconds(); //Add delta seconds to FollowTime
FHitResult Hit;
if (GetHitResultUnderCursor(ECC_Visibility, false, Hit))
{
CachedDestination = Hit.Location;
}
if (APawn* ControlledPawn = GetPawn())
{
const FVector WorldDirection = (CachedDestination - ControlledPawn->GetActorLocation()).GetSafeNormal();
ControlledPawn->AddMovementInput(WorldDirection);
}
}
}
UAuraAbilitySystemComponent* AAuraPlayerController::GetASC()
{
if (AuraAbilitySystemComponent == nullptr)
{
AuraAbilitySystemComponent = Cast<UAuraAbilitySystemComponent>(UAbilitySystemBlueprintLibrary::GetAbilitySystemComponent(GetPawn<APawn>()));
}
return AuraAbilitySystemComponent;
}
/* //cheated and skipped ahead to try and fix error :(
void AAuraPlayerController::HightlightActor(AActor* Actor)
{
@@ -109,10 +184,10 @@ void AAuraPlayerController::SetupInputComponent()
{
Super::SetupInputComponent();
UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(InputComponent);
UAuraInputComponent* AuraInputComponent = CastChecked<UAuraInputComponent>(InputComponent);
AuraInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AAuraPlayerController::Move);
EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AAuraPlayerController::Move);
AuraInputComponent->BindAbilityActions(InputConfig, this, &ThisClass::AbilityInputTagPressed, &ThisClass::AbilityInputTagHeld, &ThisClass::AbilityInputTagHeld);
}
void AAuraPlayerController::Move(const FInputActionValue& InputActionValue)