blaster/Source/Blaster/Character/BlasterCharacter.cpp

675 lines
17 KiB
C++
Raw Normal View History

2022-04-28 10:18:21 +00:00
// Fill out your copyright notice in the Description page of Project Settings.
#include "BlasterCharacter.h"
2022-05-05 22:41:35 +00:00
#include "Blaster/Blaster.h"
2022-04-30 11:09:28 +00:00
#include "Blaster/Components/CombatComponent.h"
2022-05-07 15:11:53 +00:00
#include "Blaster/GameMode/BlasterGameMode.h"
2022-05-07 10:03:33 +00:00
#include "Blaster/PlayerController/BlasterPlayerController.h"
2022-05-09 14:33:48 +00:00
#include "Blaster/PlayerState/BlasterPlayerState.h"
2022-04-30 10:26:25 +00:00
#include "Blaster/Weapon/Weapon.h"
2022-04-28 10:41:43 +00:00
#include "Camera/CameraComponent.h"
2022-05-03 17:50:47 +00:00
#include "Components/CapsuleComponent.h"
2022-04-29 21:38:34 +00:00
#include "Components/WidgetComponent.h"
2022-04-28 13:30:18 +00:00
#include "GameFramework/CharacterMovementComponent.h"
2022-04-28 10:41:43 +00:00
#include "GameFramework/SpringArmComponent.h"
2022-05-08 18:59:54 +00:00
#include "Kismet/GameplayStatics.h"
2022-05-03 21:14:04 +00:00
#include "Kismet/KismetMathLibrary.h"
2022-04-30 10:26:25 +00:00
#include "Net/UnrealNetwork.h"
2022-05-08 18:59:54 +00:00
#include "Particles/ParticleSystemComponent.h"
2022-04-28 10:41:43 +00:00
2022-04-28 10:18:21 +00:00
ABlasterCharacter::ABlasterCharacter()
{
PrimaryActorTick.bCanEverTick = true;
2022-05-07 18:34:40 +00:00
SpawnCollisionHandlingMethod = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
2022-04-28 10:41:43 +00:00
CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
CameraBoom->SetupAttachment(GetMesh());
2022-05-12 13:37:49 +00:00
CameraBoom->TargetArmLength = 600.f;
2022-04-28 12:39:36 +00:00
CameraBoom->bUsePawnControlRotation = true;
2022-04-28 10:41:43 +00:00
FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);
FollowCamera->bUsePawnControlRotation = false;
2022-04-28 13:30:18 +00:00
bUseControllerRotationYaw = false;
GetCharacterMovement()->bOrientRotationToMovement = true;
2022-04-29 21:38:34 +00:00
OverheadWidget = CreateDefaultSubobject<UWidgetComponent>(TEXT("OverheadWidget"));
OverheadWidget->SetupAttachment(RootComponent);
2022-04-30 11:09:28 +00:00
Combat = CreateDefaultSubobject<UCombatComponent>(TEXT("CombatComponent"));
2022-05-06 21:55:01 +00:00
Combat->SetIsReplicated(true);
2022-04-30 15:10:07 +00:00
GetCharacterMovement()->NavAgentProps.bCanCrouch = true;
2022-05-12 13:37:49 +00:00
GetCapsuleComponent()->SetCollisionResponseToChannel(ECollisionChannel::ECC_Camera, ECollisionResponse::ECR_Ignore);
2022-05-05 22:41:35 +00:00
GetMesh()->SetCollisionObjectType(ECC_SkeletalMesh);
2022-05-12 13:37:49 +00:00
GetMesh()->SetCollisionResponseToChannel(ECollisionChannel::ECC_Camera, ECollisionResponse::ECR_Ignore);
GetMesh()->SetCollisionResponseToChannel(ECollisionChannel::ECC_Visibility, ECollisionResponse::ECR_Block);
2022-05-04 12:57:48 +00:00
GetCharacterMovement()->RotationRate = FRotator(0.f, 850.f, 0.f);
2022-05-12 13:37:49 +00:00
2022-05-04 09:28:00 +00:00
TurningInPlace = ETurningInPlace::ETIP_NotTurning;
2022-05-04 12:27:45 +00:00
NetUpdateFrequency = 66.f;
MinNetUpdateFrequency = 33.f;
2022-05-08 16:35:37 +00:00
DissolveTimeline = CreateDefaultSubobject<UTimelineComponent>(TEXT("DissolveTimelineComponent"));
2022-04-28 10:18:21 +00:00
}
2022-04-30 10:26:25 +00:00
void ABlasterCharacter::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME_CONDITION(ABlasterCharacter, OverlappingWeapon, COND_OwnerOnly);
2022-05-07 09:04:11 +00:00
DOREPLIFETIME(ABlasterCharacter, Health);
2022-05-10 14:03:35 +00:00
DOREPLIFETIME(ABlasterCharacter, bDisableGameplay);
2022-04-30 10:26:25 +00:00
}
2022-05-06 10:43:18 +00:00
void ABlasterCharacter::OnRep_ReplicatedMovement()
{
Super::OnRep_ReplicatedMovement();
SimProxiesTurn();
TimeSinceLastMovementReplication = 0.f;
}
2022-05-07 18:34:40 +00:00
void ABlasterCharacter::Eliminated()
{
2022-05-08 17:31:58 +00:00
if (Combat && Combat->EquippedWeapon)
{
Combat->EquippedWeapon->Dropped();
}
2022-05-07 18:34:40 +00:00
MulticastEliminated();
2022-05-12 13:37:49 +00:00
GetWorldTimerManager().SetTimer(
EliminationTimer,
this,
&ABlasterCharacter::EliminationTimerFinished,
EliminationDelay
);
2022-05-07 18:34:40 +00:00
}
void ABlasterCharacter::MulticastEliminated_Implementation()
2022-05-07 17:10:32 +00:00
{
2022-05-09 16:39:41 +00:00
if (BlasterPlayerController)
{
BlasterPlayerController->SetHUDWeaponAmmo(0);
}
2022-05-07 17:10:32 +00:00
bEliminated = true;
PlayEliminatedMontage();
2022-05-08 17:31:58 +00:00
// Start dissolve effect
2022-05-08 16:35:37 +00:00
if (DissolveMaterialInstance)
{
DynamicDissolveMaterialInstance = UMaterialInstanceDynamic::Create(DissolveMaterialInstance, this);
GetMesh()->SetMaterial(0, DynamicDissolveMaterialInstance);
DynamicDissolveMaterialInstance->SetScalarParameterValue(TEXT("Dissolve"), 0.55f);
DynamicDissolveMaterialInstance->SetScalarParameterValue(TEXT("Glow"), 200.f);
}
StartDissolve();
2022-05-08 17:31:58 +00:00
// Disable character movement
GetCharacterMovement()->DisableMovement();
GetCharacterMovement()->StopMovementImmediately();
2022-05-10 14:03:35 +00:00
bDisableGameplay = true;
2022-05-17 22:41:31 +00:00
if (Combat)
{
Combat->FireButtonPressed(false);
}
2022-05-08 17:31:58 +00:00
// Disable collision
GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);
GetMesh()->SetCollisionEnabled(ECollisionEnabled::NoCollision);
2022-05-08 18:59:54 +00:00
// Elimination bot
if (EliminationBotEffect)
{
const FVector EliminationBotSpawnPoint(GetActorLocation().X, GetActorLocation().Y, GetActorLocation().Z + 200.f);
2022-05-12 13:37:49 +00:00
EliminationBotComponent = UGameplayStatics::SpawnEmitterAtLocation(
GetWorld(),
EliminationBotEffect,
EliminationBotSpawnPoint,
GetActorRotation()
);
2022-05-08 18:59:54 +00:00
}
if (EliminationBotSound)
{
2022-05-12 13:37:49 +00:00
UGameplayStatics::SpawnSoundAtLocation(
this,
EliminationBotSound,
GetActorLocation()
);
2022-05-08 18:59:54 +00:00
}
2022-05-07 15:11:53 +00:00
}
2022-05-07 18:34:40 +00:00
void ABlasterCharacter::EliminationTimerFinished()
{
2022-05-12 13:37:49 +00:00
ABlasterGameMode* BlasterGameMode = GetWorld()->GetAuthGameMode<ABlasterGameMode>();
if (BlasterGameMode)
2022-05-07 18:34:40 +00:00
{
2022-05-12 13:37:49 +00:00
BlasterGameMode->RequestRespawn(this, Controller);
2022-05-07 18:34:40 +00:00
}
}
2022-05-12 13:37:49 +00:00
void ABlasterCharacter::Destroyed()
2022-05-05 22:41:35 +00:00
{
2022-05-12 13:37:49 +00:00
Super::Destroyed();
2022-05-05 22:41:35 +00:00
2022-05-12 13:37:49 +00:00
if (EliminationBotComponent)
2022-05-05 22:41:35 +00:00
{
2022-05-12 13:37:49 +00:00
EliminationBotComponent->DestroyComponent();
}
2022-05-17 22:41:31 +00:00
ABlasterGameMode* BlasterGameMode = Cast<ABlasterGameMode>(UGameplayStatics::GetGameMode(this));
bool bMatchNotInProgress = BlasterGameMode && BlasterGameMode->GetMatchState() != MatchState::InProgress;
if (Combat && Combat->EquippedWeapon && bMatchNotInProgress)
2022-05-12 13:37:49 +00:00
{
Combat->EquippedWeapon->Destroy();
2022-05-05 22:41:35 +00:00
}
}
2022-05-12 13:37:49 +00:00
void ABlasterCharacter::BeginPlay()
2022-05-07 11:03:19 +00:00
{
2022-05-12 13:37:49 +00:00
Super::BeginPlay();
2022-05-07 11:03:19 +00:00
UpdateHUDHealth();
2022-05-12 13:37:49 +00:00
if (HasAuthority())
2022-05-07 17:10:32 +00:00
{
2022-05-12 13:37:49 +00:00
OnTakeAnyDamage.AddDynamic(this, &ABlasterCharacter::ReceiveDamage);
2022-05-07 17:10:32 +00:00
}
2022-05-12 13:37:49 +00:00
}
2022-05-07 15:11:53 +00:00
2022-05-12 13:37:49 +00:00
void ABlasterCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
RotateInPlace(DeltaTime);
HideCameraIfCharacterClose();
PollInit();
2022-05-07 11:03:19 +00:00
}
2022-05-10 14:03:35 +00:00
void ABlasterCharacter::RotateInPlace(float DeltaTime)
2022-04-28 10:18:21 +00:00
{
2022-05-10 14:03:35 +00:00
if (bDisableGameplay)
{
bUseControllerRotationYaw = false;
TurningInPlace = ETurningInPlace::ETIP_NotTurning;
return;
}
2022-05-12 13:37:49 +00:00
if (GetLocalRole() > ENetRole::ROLE_SimulatedProxy && IsLocallyControlled())
2022-05-06 10:43:18 +00:00
{
AimOffset(DeltaTime);
}
else
{
TimeSinceLastMovementReplication += DeltaTime;
if (TimeSinceLastMovementReplication > 0.25f)
{
OnRep_ReplicatedMovement();
}
CalculateAO_Pitch();
}
2022-05-10 14:03:35 +00:00
}
2022-05-06 10:43:18 +00:00
2022-05-12 13:37:49 +00:00
void ABlasterCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
2022-05-10 14:03:35 +00:00
{
2022-05-12 13:37:49 +00:00
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &ABlasterCharacter::Jump);
PlayerInputComponent->BindAxis("MoveForward", this, &ABlasterCharacter::MoveForward);
PlayerInputComponent->BindAxis("MoveRight", this, &ABlasterCharacter::MoveRight);
PlayerInputComponent->BindAxis("Turn", this, &ABlasterCharacter::Turn);
PlayerInputComponent->BindAxis("LookUp", this, &ABlasterCharacter::LookUp);
PlayerInputComponent->BindAction("Equip", IE_Pressed, this, &ABlasterCharacter::EquipButtonPressed);
PlayerInputComponent->BindAction("Crouch", IE_Pressed, this, &ABlasterCharacter::CrouchButtonPressed);
PlayerInputComponent->BindAction("Aim", IE_Pressed, this, &ABlasterCharacter::AimButtonPressed);
PlayerInputComponent->BindAction("Aim", IE_Released, this, &ABlasterCharacter::AimButtonReleased);
PlayerInputComponent->BindAction("Fire", IE_Pressed, this, &ABlasterCharacter::FireButtonPressed);
PlayerInputComponent->BindAction("Fire", IE_Released, this, &ABlasterCharacter::FireButtonReleased);
PlayerInputComponent->BindAction("Reload", IE_Pressed, this, &ABlasterCharacter::ReloadButtonPressed);
2022-05-09 14:33:48 +00:00
}
2022-05-12 13:37:49 +00:00
void ABlasterCharacter::PostInitializeComponents()
2022-05-09 14:33:48 +00:00
{
2022-05-12 13:37:49 +00:00
Super::PostInitializeComponents();
if (Combat)
2022-05-09 14:33:48 +00:00
{
2022-05-12 13:37:49 +00:00
Combat->Character = this;
}
}
void ABlasterCharacter::PlayFireMontage(bool bAiming)
{
if (Combat == nullptr || Combat->EquippedWeapon == nullptr) return;
UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance();
if (AnimInstance && FireWeaponMontage)
{
AnimInstance->Montage_Play(FireWeaponMontage);
FName SectionName;
SectionName = bAiming ? FName("RifleADS") : FName("RifleHip");
AnimInstance->Montage_JumpToSection(SectionName);
}
}
void ABlasterCharacter::PlayReloadMontage()
{
if (Combat == nullptr || Combat->EquippedWeapon == nullptr) return;
UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance();
if (AnimInstance && ReloadMontage)
{
AnimInstance->Montage_Play(ReloadMontage);
FName SectionName;
switch (Combat->EquippedWeapon->GetWeaponType())
2022-05-09 14:33:48 +00:00
{
2022-05-12 13:37:49 +00:00
case EWeaponType::EWT_AssaultRifle:
SectionName = FName("Rifle");
break;
2022-05-09 14:33:48 +00:00
}
2022-05-12 13:37:49 +00:00
AnimInstance->Montage_JumpToSection(SectionName);
2022-05-09 14:33:48 +00:00
}
2022-04-28 10:18:21 +00:00
}
2022-05-12 13:37:49 +00:00
void ABlasterCharacter::PlayEliminatedMontage()
2022-04-28 10:18:21 +00:00
{
2022-05-12 13:37:49 +00:00
UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance();
if (AnimInstance && EliminatedMontage)
{
AnimInstance->Montage_Play(EliminatedMontage);
}
}
2022-04-28 10:18:21 +00:00
2022-05-12 13:37:49 +00:00
void ABlasterCharacter::PlayHitReactMontage()
{
if (Combat == nullptr || Combat->EquippedWeapon == nullptr) return;
2022-04-30 14:08:00 +00:00
2022-05-12 13:37:49 +00:00
UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance();
if (AnimInstance && HitReactMontage)
{
AnimInstance->Montage_Play(HitReactMontage);
FName SectionName("FromFront");
AnimInstance->Montage_JumpToSection(SectionName);
}
}
void ABlasterCharacter::ReceiveDamage(AActor* DamagedActor, float Damage, const UDamageType* DamageType, AController* InstigatorController, AActor* DamageCauser)
{
Health = FMath::Clamp(Health - Damage, 0.f, MaxHealth);
UpdateHUDHealth();
if (Health > 0.f)
{
PlayHitReactMontage();
}
if (Health == 0.f)
{
ABlasterGameMode* BlasterGameMode = GetWorld()->GetAuthGameMode<ABlasterGameMode>();
if (BlasterGameMode)
{
BlasterPlayerController = BlasterPlayerController == nullptr ? Cast<ABlasterPlayerController>(Controller) : BlasterPlayerController;
ABlasterPlayerController* AttackerController = Cast<ABlasterPlayerController>(InstigatorController);
BlasterGameMode->PlayerEliminated(this, BlasterPlayerController, AttackerController);
}
}
2022-04-28 10:18:21 +00:00
}
2022-04-28 12:39:36 +00:00
void ABlasterCharacter::MoveForward(float Value)
{
2022-05-10 14:03:35 +00:00
if (bDisableGameplay) return;
2022-04-28 12:39:36 +00:00
if (Controller != nullptr && Value != 0.f)
{
const FRotator YawRotation(0.f, Controller->GetControlRotation().Yaw, 0.f);
const FVector Direction(FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X));
AddMovementInput(Direction, Value);
}
}
void ABlasterCharacter::MoveRight(float Value)
{
2022-05-10 14:03:35 +00:00
if (bDisableGameplay) return;
2022-04-28 12:39:36 +00:00
if (Controller != nullptr && Value != 0.f)
{
const FRotator YawRotation(0.f, Controller->GetControlRotation().Yaw, 0.f);
const FVector Direction(FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y));
AddMovementInput(Direction, Value);
}
}
void ABlasterCharacter::Turn(float Value)
{
AddControllerYawInput(Value);
}
void ABlasterCharacter::LookUp(float Value)
{
AddControllerPitchInput(Value);
}
2022-04-30 10:26:25 +00:00
2022-04-30 11:09:28 +00:00
void ABlasterCharacter::EquipButtonPressed()
{
2022-05-10 14:03:35 +00:00
if (bDisableGameplay) return;
2022-04-30 14:08:00 +00:00
if (Combat)
2022-04-30 11:09:28 +00:00
{
2022-04-30 14:08:00 +00:00
if (HasAuthority())
{
Combat->EquipWeapon(OverlappingWeapon);
}
else
{
ServerEquipButtonPressed();
}
2022-04-30 11:09:28 +00:00
}
}
2022-05-12 13:37:49 +00:00
void ABlasterCharacter::ServerEquipButtonPressed_Implementation()
2022-05-09 20:19:20 +00:00
{
2022-05-12 13:37:49 +00:00
EquipButtonPressed();
2022-05-09 20:19:20 +00:00
}
2022-04-30 15:10:07 +00:00
void ABlasterCharacter::CrouchButtonPressed()
{
2022-05-10 14:03:35 +00:00
if (bDisableGameplay) return;
2022-04-30 15:10:07 +00:00
if (bIsCrouched)
{
UnCrouch();
}
else
{
Crouch();
}
}
2022-05-12 13:37:49 +00:00
void ABlasterCharacter::ReloadButtonPressed()
2022-04-30 15:38:03 +00:00
{
2022-05-10 14:03:35 +00:00
if (bDisableGameplay) return;
2022-04-30 15:38:03 +00:00
if (Combat)
{
2022-05-12 13:37:49 +00:00
Combat->Reload();
2022-04-30 15:38:03 +00:00
}
}
2022-05-12 13:37:49 +00:00
void ABlasterCharacter::AimButtonPressed()
2022-04-30 15:38:03 +00:00
{
2022-05-10 14:03:35 +00:00
if (bDisableGameplay) return;
2022-04-30 15:38:03 +00:00
if (Combat)
{
2022-05-12 13:37:49 +00:00
Combat->SetAiming(true);
2022-04-30 15:38:03 +00:00
}
}
2022-05-12 13:37:49 +00:00
void ABlasterCharacter::AimButtonReleased()
2022-05-10 14:03:35 +00:00
{
if (bDisableGameplay) return;
if (Combat)
{
2022-05-12 13:37:49 +00:00
Combat->SetAiming(false);
2022-05-10 14:03:35 +00:00
}
}
2022-05-12 13:37:49 +00:00
float ABlasterCharacter::CalculateSpeed()
2022-05-10 14:03:35 +00:00
{
2022-05-12 13:37:49 +00:00
FVector Velocity = GetVelocity();
Velocity.Z = 0.f;
return Velocity.Size();
2022-05-10 14:03:35 +00:00
}
2022-05-03 21:14:04 +00:00
void ABlasterCharacter::AimOffset(float DeltaTime)
{
if (Combat && Combat->EquippedWeapon == nullptr) return;
2022-05-12 13:37:49 +00:00
float Speed = CalculateSpeed();
bool bIsInAir = GetCharacterMovement()->IsFalling();
2022-05-03 21:14:04 +00:00
if (Speed == 0.f && !bIsInAir) // Standing still, not jumping
{
2022-05-06 10:43:18 +00:00
bRotateRootBone = true;
2022-05-12 13:37:49 +00:00
FRotator CurrentAimRotation = FRotator(0.f, GetBaseAimRotation().Yaw, 0.f);
FRotator DeltaAimRotation = UKismetMathLibrary::NormalizedDeltaRotator(CurrentAimRotation, StartingAimRotation);
2022-05-03 21:14:04 +00:00
AO_Yaw = DeltaAimRotation.Yaw;
2022-05-04 12:09:01 +00:00
if (TurningInPlace == ETurningInPlace::ETIP_NotTurning)
{
InterpAO_Yaw = AO_Yaw;
}
bUseControllerRotationYaw = true;
2022-05-04 09:28:00 +00:00
TurnInPlace(DeltaTime);
2022-05-03 21:14:04 +00:00
}
if (Speed > 0.f || bIsInAir) // Running or jumping
{
2022-05-06 10:43:18 +00:00
bRotateRootBone = false;
2022-05-03 21:14:04 +00:00
StartingAimRotation = FRotator(0.f, GetBaseAimRotation().Yaw, 0.f);
AO_Yaw = 0.f;
bUseControllerRotationYaw = true;
2022-05-04 09:28:00 +00:00
TurningInPlace = ETurningInPlace::ETIP_NotTurning;
2022-05-03 21:14:04 +00:00
}
2022-05-06 10:43:18 +00:00
CalculateAO_Pitch();
}
void ABlasterCharacter::CalculateAO_Pitch()
{
2022-05-03 21:14:04 +00:00
AO_Pitch = GetBaseAimRotation().Pitch;
2022-05-03 21:36:35 +00:00
if (AO_Pitch > 90.f && !IsLocallyControlled())
{
// map pitch from [270, 360) to [-90, 0)
2022-05-12 13:37:49 +00:00
FVector2D InRange(270.f, 360.f);
FVector2D OutRange(-90.f, 0.f);
2022-05-03 21:36:35 +00:00
AO_Pitch = FMath::GetMappedRangeValueClamped(InRange, OutRange, AO_Pitch);
}
2022-05-03 21:14:04 +00:00
}
2022-05-06 10:43:18 +00:00
void ABlasterCharacter::SimProxiesTurn()
{
if (Combat == nullptr || Combat->EquippedWeapon == nullptr) return;
bRotateRootBone = false;
2022-05-12 13:37:49 +00:00
float Speed = CalculateSpeed();
2022-05-06 10:43:18 +00:00
if (Speed > 0.f)
{
TurningInPlace = ETurningInPlace::ETIP_NotTurning;
return;
}
2022-05-12 13:37:49 +00:00
2022-05-06 10:43:18 +00:00
ProxyRotationLastFrame = ProxyRotation;
ProxyRotation = GetActorRotation();
ProxyYaw = UKismetMathLibrary::NormalizedDeltaRotator(ProxyRotation, ProxyRotationLastFrame).Yaw;
2022-05-12 13:37:49 +00:00
2022-05-06 10:43:18 +00:00
if (FMath::Abs(ProxyYaw) > TurnThreshold)
{
if (ProxyYaw > TurnThreshold)
{
TurningInPlace = ETurningInPlace::ETIP_Right;
}
else if (ProxyYaw < -TurnThreshold)
{
TurningInPlace = ETurningInPlace::ETIP_Left;
}
else
{
TurningInPlace = ETurningInPlace::ETIP_NotTurning;
}
return;
}
TurningInPlace = ETurningInPlace::ETIP_NotTurning;
2022-05-12 13:37:49 +00:00
2022-05-06 10:43:18 +00:00
}
2022-05-12 13:37:49 +00:00
void ABlasterCharacter::Jump()
2022-04-30 14:08:00 +00:00
{
2022-05-12 13:37:49 +00:00
if (bDisableGameplay) return;
if (bIsCrouched)
{
UnCrouch();
}
else
{
Super::Jump();
}
}
void ABlasterCharacter::FireButtonPressed()
{
if (bDisableGameplay) return;
if (Combat)
{
Combat->FireButtonPressed(true);
}
}
void ABlasterCharacter::FireButtonReleased()
{
if (bDisableGameplay) return;
if (Combat)
{
Combat->FireButtonPressed(false);
}
2022-04-30 14:08:00 +00:00
}
2022-05-04 09:28:00 +00:00
void ABlasterCharacter::TurnInPlace(float DeltaTime)
{
if (AO_Yaw > 90.f)
{
TurningInPlace = ETurningInPlace::ETIP_Right;
}
else if (AO_Yaw < -90.f)
{
TurningInPlace = ETurningInPlace::ETIP_Left;
}
2022-05-04 12:09:01 +00:00
if (TurningInPlace != ETurningInPlace::ETIP_NotTurning)
{
InterpAO_Yaw = FMath::FInterpTo(InterpAO_Yaw, 0.f, DeltaTime, 4.f);
AO_Yaw = InterpAO_Yaw;
if (FMath::Abs(AO_Yaw) < 15.f)
{
TurningInPlace = ETurningInPlace::ETIP_NotTurning;
StartingAimRotation = FRotator(0.f, GetBaseAimRotation().Yaw, 0.f);
}
}
2022-05-04 09:28:00 +00:00
}
2022-05-05 21:03:09 +00:00
void ABlasterCharacter::HideCameraIfCharacterClose()
{
if (!IsLocallyControlled()) return;
2022-05-06 10:43:18 +00:00
if ((FollowCamera->GetComponentLocation() - GetActorLocation()).Size() < CameraThreshold)
2022-05-05 21:03:09 +00:00
{
GetMesh()->SetVisibility(false);
if (Combat && Combat->EquippedWeapon && Combat->EquippedWeapon->GetWeaponMesh())
{
Combat->EquippedWeapon->GetWeaponMesh()->bOwnerNoSee = true;
}
2022-05-06 10:43:18 +00:00
}
else
2022-05-05 21:03:09 +00:00
{
GetMesh()->SetVisibility(true);
if (Combat && Combat->EquippedWeapon && Combat->EquippedWeapon->GetWeaponMesh())
{
Combat->EquippedWeapon->GetWeaponMesh()->bOwnerNoSee = false;
}
}
}
2022-05-07 09:04:11 +00:00
void ABlasterCharacter::OnRep_Health()
{
2022-05-07 11:03:19 +00:00
UpdateHUDHealth();
2022-05-07 17:10:32 +00:00
if (Health > 0.f)
{
PlayHitReactMontage();
}
2022-05-07 11:03:19 +00:00
}
void ABlasterCharacter::UpdateHUDHealth()
{
2022-05-07 15:11:53 +00:00
BlasterPlayerController = BlasterPlayerController == nullptr ? Cast<ABlasterPlayerController>(Controller) : BlasterPlayerController;
2022-05-07 11:03:19 +00:00
if (BlasterPlayerController)
{
BlasterPlayerController->SetHUDHealth(Health, MaxHealth);
}
2022-05-07 09:04:11 +00:00
}
2022-05-12 13:37:49 +00:00
void ABlasterCharacter::PollInit()
{
if (BlasterPlayerState == nullptr)
{
BlasterPlayerState = GetPlayerState<ABlasterPlayerState>();
if (BlasterPlayerState)
{
// Initialize Score now we have the PlayerState
BlasterPlayerState->IncreaseScore(0.f);
BlasterPlayerState->IncreaseDefeats(0);
}
}
}
2022-05-08 16:35:37 +00:00
void ABlasterCharacter::UpdateDissolveMaterial(float DissolveValue)
{
if (DynamicDissolveMaterialInstance)
{
DynamicDissolveMaterialInstance->SetScalarParameterValue(TEXT("Dissolve"), DissolveValue);
}
}
void ABlasterCharacter::StartDissolve()
{
DissolveTrack.BindDynamic(this, &ABlasterCharacter::UpdateDissolveMaterial);
if (DissolveCurve && DissolveTimeline)
{
DissolveTimeline->AddInterpFloat(DissolveCurve, DissolveTrack);
DissolveTimeline->Play();
}
}
2022-04-30 10:26:25 +00:00
void ABlasterCharacter::SetOverlappingWeapon(AWeapon* Weapon)
{
if (OverlappingWeapon)
{
OverlappingWeapon->ShowPickupWidget(false);
}
OverlappingWeapon = Weapon;
if (IsLocallyControlled())
{
if (OverlappingWeapon)
{
OverlappingWeapon->ShowPickupWidget(true);
}
}
}
2022-05-12 13:37:49 +00:00
void ABlasterCharacter::OnRep_OverlappingWeapon(AWeapon* LastWeapon)
{
if (OverlappingWeapon)
{
OverlappingWeapon->ShowPickupWidget(true);
}
if (LastWeapon)
{
LastWeapon->ShowPickupWidget(false);
}
}
2022-04-30 14:48:34 +00:00
bool ABlasterCharacter::IsWeaponEquipped()
{
return Combat && Combat->EquippedWeapon;
}
2022-04-30 15:38:03 +00:00
bool ABlasterCharacter::IsAiming()
{
return Combat && Combat->bAiming;
}
2022-05-03 22:43:10 +00:00
AWeapon* ABlasterCharacter::GetEquippedWeapon()
{
if (Combat == nullptr) return nullptr;
return Combat->EquippedWeapon;
}
2022-05-05 18:14:17 +00:00
FVector ABlasterCharacter::GetHitTarget() const
{
if (Combat == nullptr) return FVector();
return Combat->HitTarget;
}
2022-05-09 21:16:55 +00:00
ECombatState ABlasterCharacter::GetCombatState() const
{
if (Combat == nullptr) return ECombatState::ECS_MAX;
return Combat->CombatState;
2022-05-12 13:37:49 +00:00
}