diff --git a/Content/Assets/Sounds/Pickups/Speed_Buff_Cue.uasset b/Content/Assets/Sounds/Pickups/Speed_Buff_Cue.uasset new file mode 100644 index 0000000..88eee1d Binary files /dev/null and b/Content/Assets/Sounds/Pickups/Speed_Buff_Cue.uasset differ diff --git a/Content/Assets/Sounds/Pickups/sw_Amb_OS_26.uasset b/Content/Assets/Sounds/Pickups/sw_Amb_OS_26.uasset new file mode 100644 index 0000000..1a21735 Binary files /dev/null and b/Content/Assets/Sounds/Pickups/sw_Amb_OS_26.uasset differ diff --git a/Content/Assets/sA_PickupSet_1/Fx/NiagaraSystems/NS_Energy_2.uasset b/Content/Assets/sA_PickupSet_1/Fx/NiagaraSystems/NS_Energy_2.uasset index caa9680..b63aa43 100644 Binary files a/Content/Assets/sA_PickupSet_1/Fx/NiagaraSystems/NS_Energy_2.uasset and b/Content/Assets/sA_PickupSet_1/Fx/NiagaraSystems/NS_Energy_2.uasset differ diff --git a/Content/Assets/sA_PickupSet_1/Fx/NiagaraSystems/NS_Pickup_2.uasset b/Content/Assets/sA_PickupSet_1/Fx/NiagaraSystems/NS_Pickup_2.uasset index 584d368..425ae67 100644 Binary files a/Content/Assets/sA_PickupSet_1/Fx/NiagaraSystems/NS_Pickup_2.uasset and b/Content/Assets/sA_PickupSet_1/Fx/NiagaraSystems/NS_Pickup_2.uasset differ diff --git a/Content/Blueprints/Pickups/Buff/BP_SpeedPickup.uasset b/Content/Blueprints/Pickups/Buff/BP_SpeedPickup.uasset new file mode 100644 index 0000000..ae01f6b Binary files /dev/null and b/Content/Blueprints/Pickups/Buff/BP_SpeedPickup.uasset differ diff --git a/Content/Maps/BlasterMap.umap b/Content/Maps/BlasterMap.umap index 7d5dd79..0f8bd6d 100644 Binary files a/Content/Maps/BlasterMap.umap and b/Content/Maps/BlasterMap.umap differ diff --git a/Source/Blaster/Character/BlasterCharacter.cpp b/Source/Blaster/Character/BlasterCharacter.cpp index f21ae5e..59bb229 100644 --- a/Source/Blaster/Character/BlasterCharacter.cpp +++ b/Source/Blaster/Character/BlasterCharacter.cpp @@ -256,6 +256,7 @@ void ABlasterCharacter::PostInitializeComponents() if (Buff) { Buff->Character = this; + Buff->SetInitialSpeeds(GetCharacterMovement()->MaxWalkSpeed, GetCharacterMovement()->MaxWalkSpeedCrouched); } } diff --git a/Source/Blaster/Components/BuffComponent.cpp b/Source/Blaster/Components/BuffComponent.cpp index 6c4e98a..c1f034d 100644 --- a/Source/Blaster/Components/BuffComponent.cpp +++ b/Source/Blaster/Components/BuffComponent.cpp @@ -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; +} diff --git a/Source/Blaster/Components/BuffComponent.h b/Source/Blaster/Components/BuffComponent.h index ff7d82d..4a7d4aa 100644 --- a/Source/Blaster/Components/BuffComponent.h +++ b/Source/Blaster/Components/BuffComponent.h @@ -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; }; diff --git a/Source/Blaster/Pickups/HealthPickup.cpp b/Source/Blaster/Pickups/HealthPickup.cpp index dd8f4b3..4f6518d 100644 --- a/Source/Blaster/Pickups/HealthPickup.cpp +++ b/Source/Blaster/Pickups/HealthPickup.cpp @@ -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(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(); -} diff --git a/Source/Blaster/Pickups/HealthPickup.h b/Source/Blaster/Pickups/HealthPickup.h index f2b683d..cba445d 100644 --- a/Source/Blaster/Pickups/HealthPickup.h +++ b/Source/Blaster/Pickups/HealthPickup.h @@ -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; }; diff --git a/Source/Blaster/Pickups/Pickup.cpp b/Source/Blaster/Pickups/Pickup.cpp index 30c0525..0587919 100644 --- a/Source/Blaster/Pickups/Pickup.cpp +++ b/Source/Blaster/Pickups/Pickup.cpp @@ -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(TEXT("PickupEffectComponent")); + PickupEffectComponent->SetupAttachment(RootComponent); } void APickup::BeginPlay() @@ -69,5 +74,14 @@ void APickup::Destroyed() GetActorLocation() ); } + if (PickupEffect) + { + UNiagaraFunctionLibrary::SpawnSystemAtLocation( + this, + PickupEffect, + GetActorLocation(), + GetActorRotation() + ); + } } diff --git a/Source/Blaster/Pickups/Pickup.h b/Source/Blaster/Pickups/Pickup.h index 12775d2..a8ac628 100644 --- a/Source/Blaster/Pickups/Pickup.h +++ b/Source/Blaster/Pickups/Pickup.h @@ -42,5 +42,10 @@ private: UPROPERTY(EditAnywhere) UStaticMeshComponent* PickupMesh; -public: + UPROPERTY(VisibleAnywhere) + class UNiagaraComponent* PickupEffectComponent; + + UPROPERTY(EditAnywhere) + class UNiagaraSystem* PickupEffect; + }; diff --git a/Source/Blaster/Pickups/SpeedPickup.cpp b/Source/Blaster/Pickups/SpeedPickup.cpp new file mode 100644 index 0000000..562fc52 --- /dev/null +++ b/Source/Blaster/Pickups/SpeedPickup.cpp @@ -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(OtherActor); + if (BlasterCharacter) + { + UBuffComponent* Buff = BlasterCharacter->GetBuff(); + if (Buff) + { + Buff->BuffSpeed(BaseSpeedBuff, CrouchSpeedBuff, SpeedBuffTime); + } + } + + Destroy(); +} diff --git a/Source/Blaster/Pickups/SpeedPickup.h b/Source/Blaster/Pickups/SpeedPickup.h new file mode 100644 index 0000000..6ce3b81 --- /dev/null +++ b/Source/Blaster/Pickups/SpeedPickup.h @@ -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; + +};