2024-04-12 11:49:22 -07:00
|
|
|
#include "GasaCharacter.h"
|
|
|
|
|
2024-04-13 08:09:22 -07:00
|
|
|
#include "AbilitySystemComponent.h"
|
2024-04-12 16:55:34 -07:00
|
|
|
#include "Camera/CameraComponent.h"
|
2024-04-12 19:05:09 -07:00
|
|
|
#include "Components/CapsuleComponent.h"
|
2024-04-12 16:55:34 -07:00
|
|
|
#include "GameFramework/CharacterMovementComponent.h"
|
|
|
|
#include "GameFramework/SpringArmComponent.h"
|
2024-04-12 19:05:09 -07:00
|
|
|
#include "Kismet/KismetSystemLibrary.h"
|
2024-04-12 16:55:34 -07:00
|
|
|
|
2024-04-13 08:09:22 -07:00
|
|
|
#include "AbilitySystem/GasaAbilitySystemComponent.h"
|
2024-04-13 15:35:19 -07:00
|
|
|
#include "AbilitySystem/GasaAttributeSet.h"
|
2024-04-22 22:10:02 -07:00
|
|
|
#include "Components/SkeletalMeshComponent.h"
|
|
|
|
#include "Engine/PostProcessVolume.h"
|
2024-04-23 15:54:17 -07:00
|
|
|
#include "Game/GasaGameInstance.h"
|
2024-04-13 08:09:22 -07:00
|
|
|
#include "Game/GasaLevelScriptActor.h"
|
2024-04-23 15:54:17 -07:00
|
|
|
#include "Game/GasaPlayerController.h"
|
2024-04-22 22:10:02 -07:00
|
|
|
#include "Materials/MaterialInstanceDynamic.h"
|
2024-04-23 15:54:17 -07:00
|
|
|
#include "Networking/GasaNetLibrary_Inlines.h"
|
|
|
|
using namespace Gasa;
|
2024-04-12 17:16:25 -07:00
|
|
|
|
2024-04-12 11:49:22 -07:00
|
|
|
AGasaCharacter::AGasaCharacter()
|
|
|
|
{
|
|
|
|
PrimaryActorTick.bCanEverTick = false;
|
|
|
|
|
2024-04-12 19:37:31 -07:00
|
|
|
HighlightColor = FLinearColor(0.8, 0.32, 0.05f, 1.f);
|
|
|
|
|
2024-04-12 16:55:34 -07:00
|
|
|
UCharacterMovementComponent*
|
|
|
|
Movement = GetCharacterMovement();
|
|
|
|
Movement->bOrientRotationToMovement = true;
|
|
|
|
Movement->bConstrainToPlane = true;
|
|
|
|
Movement->bSnapToPlaneAtStart = true;
|
|
|
|
Movement->RotationRate = FRotator(0.0, 400.f, 0.0);
|
|
|
|
|
|
|
|
bUseControllerRotationPitch = false;
|
|
|
|
bUseControllerRotationRoll = false;
|
|
|
|
bUseControllerRotationYaw = false;
|
|
|
|
|
|
|
|
USceneComponent* root_component = GetRootComponent();
|
|
|
|
USkeletalMeshComponent* mesh = GetMesh();
|
|
|
|
|
2024-04-12 11:49:22 -07:00
|
|
|
Weapon = CreateDefaultSubobject<USkeletalMeshComponent>("Weapon");
|
2024-04-12 16:55:34 -07:00
|
|
|
Weapon->SetupAttachment(mesh, FName("WeaponAttach"));
|
2024-04-12 11:49:22 -07:00
|
|
|
Weapon->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
2024-04-13 08:09:22 -07:00
|
|
|
|
|
|
|
if (bAutoAbilitySystem)
|
|
|
|
{
|
|
|
|
AbilitySystem = CreateDefaultSubobject<UGasaAbilitySystemComp>("Ability System");
|
|
|
|
AbilitySystem->SetIsReplicated(true);
|
2024-04-13 08:56:19 -07:00
|
|
|
AbilitySystem->SetReplicationMode(EGameplayEffectReplicationMode::Minimal);
|
2024-04-13 08:09:22 -07:00
|
|
|
|
2024-04-13 15:35:19 -07:00
|
|
|
Attributes = CreateDefaultSubobject<UGasaAttributeSet>("Attributes");
|
2024-04-13 08:09:22 -07:00
|
|
|
}
|
2024-04-23 15:54:17 -07:00
|
|
|
|
|
|
|
// Replication
|
|
|
|
|
|
|
|
bReplicates = false;
|
|
|
|
bNetLoadOnClient = true;
|
|
|
|
NetDormancy = DORM_Awake;
|
|
|
|
NetCullDistanceSquared = NetCullDist_Medium;
|
|
|
|
NetUpdateFrequency = 30.0f;
|
|
|
|
MinNetUpdateFrequency = 5.0f;
|
|
|
|
NetPriority = 2.0f;
|
|
|
|
|
|
|
|
ACharacter::SetReplicateMovement(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma region GameFramework
|
|
|
|
void AGasaCharacter::Controller_OnPawnPossessed()
|
|
|
|
{
|
|
|
|
NetLog("Controller confirmed possession.");
|
|
|
|
|
|
|
|
// Do stuff here that you needed to wait for the player controller be aware of you for.
|
|
|
|
BP_Controller_OnPawnPossessed();
|
|
|
|
|
|
|
|
if (Event_OnPawnReady.IsBound())
|
|
|
|
Event_OnPawnReady.Broadcast();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AGasaCharacter::ServerRPC_R_NotifyClientPawnReady_Implementation()
|
|
|
|
{
|
|
|
|
Event_OnPawnReady.Broadcast();
|
|
|
|
}
|
|
|
|
#pragma endregion GameFramework
|
|
|
|
|
|
|
|
#pragma region Highlight
|
|
|
|
void AGasaCharacter::SetHighlight(EHighlight Desired)
|
|
|
|
{
|
|
|
|
HighlightState = Desired;
|
2024-04-12 11:49:22 -07:00
|
|
|
}
|
2024-04-23 15:54:17 -07:00
|
|
|
#pragma endregion Highlight
|
2024-04-12 11:49:22 -07:00
|
|
|
|
2024-04-13 08:56:19 -07:00
|
|
|
#pragma region Pawn
|
2024-04-23 15:54:17 -07:00
|
|
|
void AGasaCharacter::OnRep_PlayerState()
|
|
|
|
{
|
|
|
|
Super::OnRep_PlayerState();
|
|
|
|
}
|
|
|
|
|
2024-04-13 08:56:19 -07:00
|
|
|
void AGasaCharacter::PossessedBy(AController* NewController)
|
|
|
|
{
|
2024-04-23 15:54:17 -07:00
|
|
|
NetLog("Pawn possessed.");
|
2024-04-13 08:56:19 -07:00
|
|
|
|
2024-04-23 15:54:17 -07:00
|
|
|
AController* OldController;
|
|
|
|
|
|
|
|
// APawn::PossessedBy
|
|
|
|
{
|
|
|
|
SetOwner(NewController);
|
|
|
|
OldController = Controller;
|
|
|
|
Controller = NewController;
|
|
|
|
|
|
|
|
ForceNetUpdate();
|
|
|
|
|
|
|
|
#if UE_WITH_IRIS
|
|
|
|
// The owning connection depends on the Controller having the new value.
|
|
|
|
UpdateOwningNetConnection();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (Controller->PlayerState != nullptr)
|
|
|
|
SetPlayerState(Controller->PlayerState);
|
|
|
|
|
|
|
|
if (APlayerController* PlayerController = Cast<APlayerController>(Controller))
|
|
|
|
{
|
|
|
|
if (GetNetMode() != NM_Standalone)
|
|
|
|
{
|
|
|
|
SetReplicates(true);
|
|
|
|
SetAutonomousProxy(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
CopyRemoteRoleFrom(GetDefault<APawn>());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (AGasaPlayerController* PC = Cast<AGasaPlayerController>(NewController))
|
|
|
|
{
|
|
|
|
PC->Event_OnPawnPossessed.AddUniqueDynamic(this, & ThisClass::Controller_OnPawnPossessed);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NetLog("Controller assigned to GasaCharacter is not derived from GasaPlayerController.", ELogV::Warning);
|
|
|
|
NetLog("Controller: Name: " + NewController->GetName() + " Class: " + NewController->GetClass()->GetName(), ELogV::Warning);
|
|
|
|
}
|
|
|
|
|
|
|
|
// cont. APawn::PossessedBy
|
|
|
|
{
|
|
|
|
// Dispatch Blueprint event if necessary
|
|
|
|
if (OldController != NewController)
|
|
|
|
{
|
|
|
|
ReceivePossessed(Controller);
|
|
|
|
NotifyControllerChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ACharacter::PossessedBy
|
|
|
|
{
|
|
|
|
// If we are controlled remotely, set animation timing to be driven by client's network updates. So timing and events remain in sync.
|
|
|
|
if (GetMesh() && IsReplicatingMovement() && (GetRemoteRole() == ROLE_AutonomousProxy && GetNetConnection() != nullptr))
|
|
|
|
GetMesh()->bOnlyAllowAutonomousTickPose = true;
|
|
|
|
}
|
2024-04-25 09:46:26 -07:00
|
|
|
|
|
|
|
#if 0
|
2024-04-13 08:56:19 -07:00
|
|
|
if (bAutoAbilitySystem)
|
|
|
|
AbilitySystem->InitAbilityActorInfo(this, this);
|
2024-04-25 09:46:26 -07:00
|
|
|
#endif
|
2024-04-13 08:56:19 -07:00
|
|
|
}
|
|
|
|
|
2024-04-23 15:54:17 -07:00
|
|
|
void AGasaCharacter::SetPlayerDefaults()
|
2024-04-13 08:56:19 -07:00
|
|
|
{
|
2024-04-23 15:54:17 -07:00
|
|
|
Super::SetPlayerDefaults();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AGasaCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
|
|
|
{
|
|
|
|
Super::SetupPlayerInputComponent(PlayerInputComponent);
|
2024-04-13 08:56:19 -07:00
|
|
|
}
|
|
|
|
#pragma endregion Pawn
|
|
|
|
|
|
|
|
#pragma region Actor
|
2024-04-12 11:49:22 -07:00
|
|
|
void AGasaCharacter::BeginPlay()
|
|
|
|
{
|
|
|
|
Super::BeginPlay();
|
2024-04-13 15:35:19 -07:00
|
|
|
|
2024-04-25 09:46:26 -07:00
|
|
|
// TODO(Ed): Find out if this is the best spot todo this
|
|
|
|
// There is also OnPossessed, PostInitializeComponents, etc...
|
2024-04-13 15:35:19 -07:00
|
|
|
if (bAutoAbilitySystem)
|
|
|
|
AbilitySystem->InitAbilityActorInfo(this, this);
|
2024-04-12 11:49:22 -07:00
|
|
|
}
|
2024-04-12 19:05:09 -07:00
|
|
|
|
|
|
|
void AGasaCharacter::Tick(float DeltaSeconds)
|
|
|
|
{
|
|
|
|
Super::Tick(DeltaSeconds);
|
2024-04-12 23:31:49 -07:00
|
|
|
|
|
|
|
USkeletalMeshComponent* mesh = GetMesh();
|
2024-04-12 19:05:09 -07:00
|
|
|
switch (HighlightState)
|
|
|
|
{
|
|
|
|
case EHighlight::Disabled:
|
2024-04-12 23:31:49 -07:00
|
|
|
{
|
|
|
|
mesh->SetRenderCustomDepth(false);
|
|
|
|
mesh->SetCustomDepthStencilValue(0.f);
|
|
|
|
Weapon->SetRenderCustomDepth(false);
|
|
|
|
Weapon->SetCustomDepthStencilValue(0.f);
|
|
|
|
}
|
2024-04-12 19:05:09 -07:00
|
|
|
break;
|
|
|
|
case EHighlight::Enabled:
|
|
|
|
{
|
2024-04-12 23:31:49 -07:00
|
|
|
mesh->SetRenderCustomDepth(true);
|
|
|
|
mesh->SetCustomDepthStencilValue(HighlightStencilDepth);
|
|
|
|
Weapon->SetRenderCustomDepth(true);
|
|
|
|
Weapon->SetCustomDepthStencilValue(HighlightStencilDepth);
|
|
|
|
|
|
|
|
APostProcessVolume* PPV = Gasa::GetLevelActor(this)->GlobalPPV;
|
|
|
|
TObjectPtr<UObject> Blendable = PPV->Settings.WeightedBlendables.Array[0].Object;
|
|
|
|
UMaterialInstanceDynamic*
|
|
|
|
MID = Cast<UMaterialInstanceDynamic>(Blendable);
|
|
|
|
MID->SetVectorParameterValue("Depth Highlight Color", HighlightColor);
|
|
|
|
#if 0
|
2024-04-12 19:05:09 -07:00
|
|
|
UCapsuleComponent* Capsule = GetCapsuleComponent();
|
|
|
|
UKismetSystemLibrary::DrawDebugCapsule(this
|
|
|
|
, Capsule->GetComponentLocation()
|
2024-04-12 23:31:49 -07:00
|
|
|
, Capsule->GetScaledCapsuleHalfHeight()^
|
2024-04-12 19:05:09 -07:00
|
|
|
, Capsule->GetScaledCapsuleRadius()
|
|
|
|
, Capsule->GetComponentRotation()
|
2024-04-12 19:37:31 -07:00
|
|
|
, HighlightColor
|
2024-04-12 19:05:09 -07:00
|
|
|
, 0.f
|
|
|
|
, 1.f
|
|
|
|
);
|
2024-04-12 23:31:49 -07:00
|
|
|
#endif
|
2024-04-12 19:05:09 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-04-13 08:56:19 -07:00
|
|
|
#pragma endregion Actor
|