Cleaned up code per lesson 108
This commit is contained in:
@@ -8,9 +8,7 @@
|
||||
|
||||
void UAuraAbilitySystemComponent::AbilityActorInfoSet()
|
||||
{
|
||||
OnGameplayEffectAppliedDelegateToSelf.AddUObject( this, &UAuraAbilitySystemComponent::EffectApplied);
|
||||
//const FAuraGameplayTags& GameplayTags = FAuraGameplayTags::Get();
|
||||
//GameplayTags.Attributes_Secondary_Armor.ToString();
|
||||
OnGameplayEffectAppliedDelegateToSelf.AddUObject( this, &UAuraAbilitySystemComponent::ClientEffectApplied);
|
||||
}
|
||||
|
||||
void UAuraAbilitySystemComponent::AddCharacterAbilities(const TArray<TSubclassOf<UGameplayAbility>>& StartupAbilities)
|
||||
@@ -58,8 +56,8 @@ void UAuraAbilitySystemComponent::AbilityInputTagReleased(const FGameplayTag& In
|
||||
}
|
||||
}
|
||||
|
||||
void UAuraAbilitySystemComponent::EffectApplied(UAbilitySystemComponent* AbilitySystemComponent,
|
||||
const FGameplayEffectSpec& EffectSpec, FActiveGameplayEffectHandle ActiveEffectHandle)
|
||||
void UAuraAbilitySystemComponent::ClientEffectApplied_Implementation(UAbilitySystemComponent* AbilitySystemComponent,
|
||||
const FGameplayEffectSpec& EffectSpec, FActiveGameplayEffectHandle ActiveEffectHandle)
|
||||
{
|
||||
//GEngine->AddOnScreenDebugMessage(1,8.f, FColor::Blue,FString("Effect Applied!"));
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ AAuraCharacter::AAuraCharacter()
|
||||
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();
|
||||
}
|
||||
@@ -33,7 +32,6 @@ void AAuraCharacter::PossessedBy(AController* NewController)
|
||||
void AAuraCharacter::OnRep_PlayerState()
|
||||
{
|
||||
Super::OnRep_PlayerState();
|
||||
//UE_LOG(LogTemp, Warning, TEXT("AuraCharacter.cpp - OnRep_PlayerState"));
|
||||
InitAbilityActorInfo(); //Init Ability Actor Info for the Client
|
||||
}
|
||||
|
||||
@@ -55,14 +53,11 @@ void AAuraCharacter::InitAbilityActorInfo() //Function to Init Ability Actor Inf
|
||||
AbilitySystemComponent = AuraPlayerState->GetAbilitySystemComponent();
|
||||
AttributeSet = AuraPlayerState->GetAttributeSet();
|
||||
|
||||
//UE_LOG(LogTemp, Warning, TEXT("AuraCharacter.cpp - InitAbilityActorInfo - AttributeSet"));
|
||||
if (AAuraPlayerController* AuraPlayerController = Cast<AAuraPlayerController>(GetController()))
|
||||
{
|
||||
|
||||
//UE_LOG(LogTemp, Warning, TEXT("AuraCharacter.cpp - InitAbilityActorInfo - Cast "));
|
||||
if (AAuraHUD* AuraHUD = Cast<AAuraHUD>(AuraPlayerController->GetHUD()))
|
||||
{
|
||||
//UE_LOG(LogTemp, Warning, TEXT("AuraCharacter.cpp - InitAbilityActorInfo - InitOverlay"));
|
||||
AuraHUD->InitOverlay(AuraPlayerController, AuraPlayerState, AbilitySystemComponent, AttributeSet);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// Copyright Echo Devgroup
|
||||
|
||||
#include "AbilitySystemBlueprintLibrary.h"
|
||||
#include "Player/AuraPlayerController.h"
|
||||
|
||||
#include "AbilitySystemBlueprintLibrary.h"
|
||||
#include "AuraGameplayTags.h"
|
||||
#include "EnhancedInputSubsystems.h"
|
||||
#include "NavigationPath.h"
|
||||
#include "NavigationSystem.h"
|
||||
#include "AbilitySystem/AuraAbilitySystemComponent.h"
|
||||
#include "AbilitySystem/AuraAbilitySystemLibrary.h"
|
||||
#include "Components/SplineComponent.h"
|
||||
@@ -14,7 +15,6 @@
|
||||
AAuraPlayerController::AAuraPlayerController()
|
||||
{
|
||||
bReplicates = true;
|
||||
|
||||
Spline = CreateDefaultSubobject<USplineComponent>("Spline");
|
||||
}
|
||||
|
||||
@@ -23,11 +23,30 @@ void AAuraPlayerController::PlayerTick(float DeltaTime)
|
||||
Super::PlayerTick(DeltaTime);
|
||||
|
||||
CursorTrace();
|
||||
AutoRun();
|
||||
|
||||
}
|
||||
|
||||
void AAuraPlayerController::AutoRun()
|
||||
{
|
||||
if (!bAutoRunning) return;
|
||||
if (APawn* ControlledPawn = GetPawn())
|
||||
{
|
||||
const FVector LocationOnSpline = Spline->FindLocationClosestToWorldLocation(ControlledPawn->GetActorLocation(), ESplineCoordinateSpace::World);
|
||||
const FVector Direction = Spline->FindDirectionClosestToWorldLocation(LocationOnSpline, ESplineCoordinateSpace::World);
|
||||
ControlledPawn->AddMovementInput(Direction);
|
||||
|
||||
const float DistanceToDestination = (LocationOnSpline - CachedDestination).Length();
|
||||
if (DistanceToDestination <= AutoRunAcceptanceRadius)
|
||||
{
|
||||
bAutoRunning = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AAuraPlayerController::CursorTrace()
|
||||
{
|
||||
FHitResult CursorHit;
|
||||
|
||||
GetHitResultUnderCursor(ECC_Visibility, false, CursorHit);
|
||||
if (!CursorHit.bBlockingHit) return;
|
||||
AActor* HitActor = CursorHit.GetActor();
|
||||
@@ -35,54 +54,17 @@ void AAuraPlayerController::CursorTrace()
|
||||
|
||||
LastActor = ThisActor;
|
||||
ThisActor = Enemy;
|
||||
|
||||
/**
|
||||
*Line trace from curso. There are several scenarios
|
||||
* A. LastActor is null && ThisActor is null
|
||||
* - Do nothing
|
||||
* B. LastActor is null && ThisActor is valid
|
||||
* - Highlight ThisActor
|
||||
* C. LastActor is valid && ThisActor is null
|
||||
* - UnHighlight LastActor
|
||||
* D. LastAcrot is valid && ThisActor is valid but not equal
|
||||
* - UnHighligh LastActor
|
||||
* - Highlight ThisActor
|
||||
* E. LastActor is same as ThisActor
|
||||
* - Do Nothing
|
||||
*/
|
||||
|
||||
if (LastActor == nullptr)
|
||||
if (LastActor != ThisActor)
|
||||
{
|
||||
if (ThisActor != nullptr)
|
||||
{
|
||||
//Case B
|
||||
ThisActor->HighlightActor();
|
||||
//UE_LOG(LogTemp, Warning, TEXT("Case B"));
|
||||
}
|
||||
if (LastActor) LastActor->UnHighlightActor();
|
||||
if (ThisActor) ThisActor->HighlightActor();
|
||||
}
|
||||
else //LastActor is Valid
|
||||
{
|
||||
if (ThisActor == nullptr)
|
||||
{
|
||||
LastActor->UnHighlightActor();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (LastActor != ThisActor) // Case D
|
||||
{
|
||||
LastActor->UnHighlightActor();
|
||||
ThisActor->HighlightActor();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void AAuraPlayerController::AbilityInputTagPressed(FGameplayTag InputTag)
|
||||
{
|
||||
//For Debug of key pressed
|
||||
//GEngine->AddOnScreenDebugMessage(1, 3.f, FColor::Red, *InputTag.ToString());
|
||||
GEngine->AddOnScreenDebugMessage(1, 3.f, FColor::Red, *InputTag.ToString());
|
||||
|
||||
//Are we targetting something?
|
||||
if (InputTag.MatchesTagExact(FAuraGameplayTags::Get().Input_InputTag_LMB))
|
||||
@@ -97,37 +79,65 @@ void AAuraPlayerController::AbilityInputTagReleased(FGameplayTag InputTag)
|
||||
{
|
||||
|
||||
//For Debug of Key Held
|
||||
//GEngine->AddOnScreenDebugMessage(1, 3.f, FColor::Red, *InputTag.ToString());
|
||||
GEngine->AddOnScreenDebugMessage(2, 3.f, FColor::Blue, *InputTag.ToString());
|
||||
if (!InputTag.MatchesTagExact(FAuraGameplayTags::Get().Input_InputTag_LMB))
|
||||
{
|
||||
if (GetASC()) GetASC()->AbilityInputTagReleased(InputTag);
|
||||
return;
|
||||
}
|
||||
|
||||
if (GetASC() == nullptr) return;
|
||||
GetASC()->AbilityInputTagReleased(InputTag);
|
||||
if (bTargeting)
|
||||
{
|
||||
if (GetASC()) GetASC()->AbilityInputTagReleased(InputTag);
|
||||
}
|
||||
else
|
||||
{
|
||||
APawn* ControlledPawn = GetPawn();
|
||||
//Why no Splines?
|
||||
const FString msg = FString::Printf(TEXT("NavPoints: ActorLoc: %s - CachedLoc: %s"), *ControlledPawn->GetActorLocation().ToString(), *CachedDestination.ToString());
|
||||
GEngine->AddOnScreenDebugMessage(5,8.f, FColor::Blue,msg);
|
||||
|
||||
if (FollowTime <= ShortPressThreshold && ControlledPawn)
|
||||
{
|
||||
UNavigationPath* NavPath = UNavigationSystemV1::FindPathToLocationSynchronously(this, ControlledPawn->GetActorLocation(), CachedDestination);
|
||||
if (NavPath)
|
||||
{
|
||||
//DrawDebugLine(GetWorld(), ControlledPawn->GetActorLocation(), CachedDestination, FColor::Green, false, 2.0f, 0, 2.0f);
|
||||
Spline->ClearSplinePoints();
|
||||
for (const FVector& PointLoc : NavPath->PathPoints)
|
||||
{
|
||||
Spline->AddSplinePoint(PointLoc, ESplineCoordinateSpace::World);
|
||||
DrawDebugSphere(GetWorld(), PointLoc, 8.f, 8, FColor::Green, false, 5.f);
|
||||
CachedDestination = NavPath->PathPoints.Last();
|
||||
}
|
||||
bAutoRunning = true;
|
||||
}
|
||||
}
|
||||
FollowTime = 0.f;
|
||||
bTargeting = false;
|
||||
}
|
||||
}
|
||||
|
||||
void AAuraPlayerController::AbilityInputTagHeld(FGameplayTag InputTag)
|
||||
{
|
||||
//For Debug of Key Held
|
||||
//GEngine->AddOnScreenDebugMessage(1, 3.f, FColor::Red, *InputTag.ToString());
|
||||
//GEngine->AddOnScreenDebugMessage(3, 3.f, FColor::Green, *InputTag.ToString());
|
||||
|
||||
if (!InputTag.MatchesTagExact(FAuraGameplayTags::Get().Input_InputTag_LMB))
|
||||
{
|
||||
if (GetASC() == nullptr) return;
|
||||
GetASC()->AbilityInputTagHeld(InputTag);
|
||||
|
||||
if (GetASC()) GetASC()->AbilityInputTagHeld(InputTag);
|
||||
return;
|
||||
}
|
||||
if (bTargeting)
|
||||
{
|
||||
if (GetASC())
|
||||
{
|
||||
GetASC()->AbilityInputTagHeld(InputTag);
|
||||
}
|
||||
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 (CursorHit.bBlockingHit) CachedDestination = CursorHit.ImpactPoint;
|
||||
|
||||
if (APawn* ControlledPawn = GetPawn())
|
||||
{
|
||||
@@ -138,6 +148,7 @@ void AAuraPlayerController::AbilityInputTagHeld(FGameplayTag InputTag)
|
||||
|
||||
}
|
||||
|
||||
|
||||
UAuraAbilitySystemComponent* AAuraPlayerController::GetASC()
|
||||
{
|
||||
if (AuraAbilitySystemComponent == nullptr)
|
||||
@@ -147,18 +158,6 @@ UAuraAbilitySystemComponent* AAuraPlayerController::GetASC()
|
||||
return AuraAbilitySystemComponent;
|
||||
}
|
||||
|
||||
/* //cheated and skipped ahead to try and fix error :(
|
||||
void AAuraPlayerController::HightlightActor(AActor* Actor)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void AAuraPlayerController::UnHightlightActor(AActor* Actor)
|
||||
{
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
void AAuraPlayerController::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
@@ -187,7 +186,7 @@ void AAuraPlayerController::SetupInputComponent()
|
||||
UAuraInputComponent* AuraInputComponent = CastChecked<UAuraInputComponent>(InputComponent);
|
||||
AuraInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AAuraPlayerController::Move);
|
||||
|
||||
AuraInputComponent->BindAbilityActions(InputConfig, this, &ThisClass::AbilityInputTagPressed, &ThisClass::AbilityInputTagHeld, &ThisClass::AbilityInputTagHeld);
|
||||
AuraInputComponent->BindAbilityActions(InputConfig, this, &ThisClass::AbilityInputTagPressed, &ThisClass::AbilityInputTagReleased, &ThisClass::AbilityInputTagHeld);
|
||||
}
|
||||
|
||||
void AAuraPlayerController::Move(const FInputActionValue& InputActionValue)
|
||||
|
||||
Reference in New Issue
Block a user