158 - Speed Buffs

This commit is contained in:
Kingsmedia 2022-05-23 01:06:42 +02:00
parent babbfda3cf
commit 1f473d78ce
15 changed files with 147 additions and 38 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -256,6 +256,7 @@ void ABlasterCharacter::PostInitializeComponents()
if (Buff)
{
Buff->Character = this;
Buff->SetInitialSpeeds(GetCharacterMovement()->MaxWalkSpeed, GetCharacterMovement()->MaxWalkSpeedCrouched);
}
}

View File

@ -4,6 +4,7 @@
#include "BuffComponent.h"
#include "Blaster/Character/BlasterCharacter.h"
#include "GameFramework/CharacterMovementComponent.h"
UBuffComponent::UBuffComponent()
{
@ -18,13 +19,20 @@ void UBuffComponent::Heal(float HealAmount, float HealingTime)
AmountToHeal += HealAmount;
}
void UBuffComponent::BeginPlay()
{
Super::BeginPlay();
}
void UBuffComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
HealRampUp(DeltaTime);
}
void UBuffComponent::HealRampUp(float DeltaTime)
{
if (!bHealing || Character == nullptr || Character->IsEliminated()) return;
@ -41,10 +49,46 @@ void UBuffComponent::HealRampUp(float DeltaTime)
}
}
void UBuffComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
void UBuffComponent::BuffSpeed(float BuffBaseSpeed, float BuffCrouchSpeed, float BuffTime)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
if (Character == nullptr) return;
HealRampUp(DeltaTime);
Character->GetWorldTimerManager().SetTimer(
SpeedBuffTimer,
this,
&UBuffComponent::ResetSpeeds,
BuffTime
);
if (Character->GetCharacterMovement())
{
Character->GetCharacterMovement()->MaxWalkSpeed = BuffBaseSpeed;
Character->GetCharacterMovement()->MaxWalkSpeedCrouched = BuffCrouchSpeed;
MulticastSpeedBuff(BuffBaseSpeed, BuffCrouchSpeed);
}
}
void UBuffComponent::MulticastSpeedBuff_Implementation(float BaseSpeed, float CrouchSpeed)
{
if (Character->GetCharacterMovement())
{
Character->GetCharacterMovement()->MaxWalkSpeed = BaseSpeed;
Character->GetCharacterMovement()->MaxWalkSpeedCrouched = CrouchSpeed;
}
}
void UBuffComponent::ResetSpeeds()
{
if (Character && Character->GetCharacterMovement())
{
Character->GetCharacterMovement()->MaxWalkSpeed = InitialBaseSpeed;
Character->GetCharacterMovement()->MaxWalkSpeedCrouched = InitialCrouchSpeed;
MulticastSpeedBuff(InitialBaseSpeed, InitialCrouchSpeed);
}
}
void UBuffComponent::SetInitialSpeeds(float BaseSpeed, float CrouchSpeed)
{
InitialBaseSpeed = BaseSpeed;
InitialCrouchSpeed = CrouchSpeed;
}

View File

@ -7,17 +7,18 @@
#include "BuffComponent.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class BLASTER_API UBuffComponent : public UActorComponent
{
GENERATED_BODY()
public:
public:
UBuffComponent();
friend class ABlasterCharacter;
void Heal(float HealAmount, float HealingTime);
void BuffSpeed(float BuffBaseSpeed, float BuffCrouchSpeed, float BuffTime);
void SetInitialSpeeds(float BaseSpeed, float CrouchSpeed);
protected:
virtual void BeginPlay() override;
void HealRampUp(float DeltaTime);
@ -26,12 +27,19 @@ private:
UPROPERTY()
class ABlasterCharacter* Character;
// Heal Buff
bool bHealing = false;
float HealingRate = 0;
float AmountToHeal = 0.f;
public:
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
// Speed Buff
FTimerHandle SpeedBuffTimer;
void ResetSpeeds();
float InitialBaseSpeed;
float InitialCrouchSpeed;
UFUNCTION(NetMulticast, Reliable)
void MulticastSpeedBuff(float BaseSpeed, float CrouchSpeed);
public:
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
};

View File

@ -3,16 +3,12 @@
#include "HealthPickup.h"
#include "NiagaraComponent.h"
#include "NiagaraFunctionLibrary.h"
#include "Blaster/Character/BlasterCharacter.h"
#include "Blaster/Components/BuffComponent.h"
AHealthPickup::AHealthPickup()
{
bReplicates = true;
PickupEffectComponent = CreateDefaultSubobject<UNiagaraComponent>(TEXT("PickupEffectComponent"));
PickupEffectComponent->SetupAttachment(RootComponent);
}
void AHealthPickup::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex,
@ -32,18 +28,3 @@ void AHealthPickup::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AA
Destroy();
}
void AHealthPickup::Destroyed()
{
if (PickupEffect)
{
UNiagaraFunctionLibrary::SpawnSystemAtLocation(
this,
PickupEffect,
GetActorLocation(),
GetActorRotation()
);
}
Super::Destroyed();
}

View File

@ -16,7 +16,6 @@ class BLASTER_API AHealthPickup : public APickup
public:
AHealthPickup();
virtual void Destroyed() override;
protected:
virtual void OnSphereOverlap(
@ -34,11 +33,5 @@ private:
UPROPERTY(EditAnywhere)
float HealingTime = 5.f;
UPROPERTY(VisibleAnywhere)
class UNiagaraComponent* PickupEffectComponent;
UPROPERTY(EditAnywhere)
class UNiagaraSystem* PickupEffect;
};

View File

@ -3,6 +3,8 @@
#include "Pickup.h"
#include "NiagaraComponent.h"
#include "NiagaraFunctionLibrary.h"
#include "Blaster/Weapon/WeaponTypes.h"
#include "Components/SphereComponent.h"
#include "Kismet/GameplayStatics.h"
@ -29,6 +31,9 @@ APickup::APickup()
PickupMesh->SetRelativeScale3D(FVector(5.f, 5.f, 5.f));
PickupMesh->SetRenderCustomDepth(true);
PickupMesh->SetCustomDepthStencilValue(CUSTOM_DEPTH_PURPLE);
PickupEffectComponent = CreateDefaultSubobject<UNiagaraComponent>(TEXT("PickupEffectComponent"));
PickupEffectComponent->SetupAttachment(RootComponent);
}
void APickup::BeginPlay()
@ -69,5 +74,14 @@ void APickup::Destroyed()
GetActorLocation()
);
}
if (PickupEffect)
{
UNiagaraFunctionLibrary::SpawnSystemAtLocation(
this,
PickupEffect,
GetActorLocation(),
GetActorRotation()
);
}
}

View File

@ -42,5 +42,10 @@ private:
UPROPERTY(EditAnywhere)
UStaticMeshComponent* PickupMesh;
public:
UPROPERTY(VisibleAnywhere)
class UNiagaraComponent* PickupEffectComponent;
UPROPERTY(EditAnywhere)
class UNiagaraSystem* PickupEffect;
};

View File

@ -0,0 +1,25 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "SpeedPickup.h"
#include "Blaster/Character/BlasterCharacter.h"
#include "Blaster/Components/BuffComponent.h"
void ASpeedPickup::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex,
bool bFromSweep, const FHitResult& SweepResult)
{
Super::OnSphereOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(OtherActor);
if (BlasterCharacter)
{
UBuffComponent* Buff = BlasterCharacter->GetBuff();
if (Buff)
{
Buff->BuffSpeed(BaseSpeedBuff, CrouchSpeedBuff, SpeedBuffTime);
}
}
Destroy();
}

View File

@ -0,0 +1,38 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Pickup.h"
#include "SpeedPickup.generated.h"
/**
*
*/
UCLASS()
class BLASTER_API ASpeedPickup : public APickup
{
GENERATED_BODY()
protected:
virtual void OnSphereOverlap(
UPrimitiveComponent* OverlappedComponent,
AActor* OtherActor,
UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex,
bool bFromSweep,
const FHitResult& SweepResult
) override;
private:
UPROPERTY(EditAnywhere)
float BaseSpeedBuff = 1600.f;
UPROPERTY(EditAnywhere)
float CrouchSpeedBuff = 850.f;
UPROPERTY(EditAnywhere)
float SpeedBuffTime = 30.f;
};