208 lines
5.3 KiB
C++
208 lines
5.3 KiB
C++
// Copyright Echo Devgroup
|
|
|
|
#include "AbilitySystemBlueprintLibrary.h"
|
|
#include "Player/AuraPlayerController.h"
|
|
|
|
#include "AuraGameplayTags.h"
|
|
#include "EnhancedInputSubsystems.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)
|
|
{
|
|
Super::PlayerTick(DeltaTime);
|
|
|
|
CursorTrace();
|
|
}
|
|
|
|
void AAuraPlayerController::CursorTrace()
|
|
{
|
|
FHitResult CursorHit;
|
|
GetHitResultUnderCursor(ECC_Visibility, false, CursorHit);
|
|
if (!CursorHit.bBlockingHit) return;
|
|
AActor* HitActor = CursorHit.GetActor();
|
|
IEnemyInterface* Enemy = Cast<IEnemyInterface>(HitActor);
|
|
|
|
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 (ThisActor != nullptr)
|
|
{
|
|
//Case B
|
|
ThisActor->HighlightActor();
|
|
//UE_LOG(LogTemp, Warning, TEXT("Case B"));
|
|
}
|
|
}
|
|
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());
|
|
|
|
//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)
|
|
{
|
|
|
|
}
|
|
|
|
void AAuraPlayerController::UnHightlightActor(AActor* Actor)
|
|
{
|
|
|
|
}
|
|
*/
|
|
|
|
void AAuraPlayerController::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
check(AuraContext);
|
|
|
|
UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer());
|
|
if (Subsystem)
|
|
{
|
|
Subsystem->AddMappingContext(AuraContext,0);
|
|
}
|
|
|
|
bShowMouseCursor = true;
|
|
DefaultMouseCursor = EMouseCursor::Default;
|
|
|
|
FInputModeGameAndUI InputModeData;
|
|
InputModeData.SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock);
|
|
InputModeData.SetHideCursorDuringCapture(false);
|
|
SetInputMode(InputModeData);
|
|
|
|
}
|
|
|
|
void AAuraPlayerController::SetupInputComponent()
|
|
{
|
|
Super::SetupInputComponent();
|
|
|
|
UAuraInputComponent* AuraInputComponent = CastChecked<UAuraInputComponent>(InputComponent);
|
|
AuraInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AAuraPlayerController::Move);
|
|
|
|
AuraInputComponent->BindAbilityActions(InputConfig, this, &ThisClass::AbilityInputTagPressed, &ThisClass::AbilityInputTagHeld, &ThisClass::AbilityInputTagHeld);
|
|
}
|
|
|
|
void AAuraPlayerController::Move(const FInputActionValue& InputActionValue)
|
|
{
|
|
const FVector2D InputAxisVector = InputActionValue.Get<FVector2D>();
|
|
const FRotator Rotation = GetControlRotation();
|
|
const FRotator YawRotation(0.f, Rotation.Yaw, 0.f);
|
|
|
|
const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
|
|
const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
|
|
|
|
if (APawn* ControlledPawn = GetPawn<APawn>())
|
|
{
|
|
ControlledPawn->AddMovementInput(ForwardDirection, InputAxisVector.Y);
|
|
ControlledPawn->AddMovementInput(RightDirection, InputAxisVector.X);
|
|
}
|
|
}
|