162 - Shield Buffs
This commit is contained in:
parent
4ee3b3e9f8
commit
5c4a41202f
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -154,8 +154,8 @@ private:
|
|||
UPROPERTY(EditAnywhere, Category= "Player Stats")
|
||||
float MaxShield = 100.f;
|
||||
|
||||
UPROPERTY(ReplicatedUsing = OnRep_Shield, VisibleAnywhere, Category= "Player Stats")
|
||||
float Shield = 50.f;
|
||||
UPROPERTY(ReplicatedUsing = OnRep_Shield, EditAnywhere, Category= "Player Stats")
|
||||
float Shield = 0.f;
|
||||
|
||||
UFUNCTION()
|
||||
void OnRep_Shield(float LastShield);
|
||||
|
@ -221,6 +221,9 @@ public:
|
|||
FORCEINLINE float GetHealth() const { return Health; }
|
||||
FORCEINLINE void SetHealth(float Amount) { Health = Amount; }
|
||||
FORCEINLINE float GetMaxHealth() const { return MaxHealth; }
|
||||
FORCEINLINE float GetShield() const { return Shield; }
|
||||
FORCEINLINE void SetShield(float Amount) { Shield = Amount; }
|
||||
FORCEINLINE float GetMaxShield() const { return MaxShield; }
|
||||
ECombatState GetCombatState() const;
|
||||
FORCEINLINE UCombatComponent* GetCombat() const { return Combat; }
|
||||
FORCEINLINE UBuffComponent* GetBuff() const { return Buff; }
|
||||
|
|
|
@ -18,6 +18,13 @@ void UBuffComponent::Heal(float HealAmount, float HealingTime)
|
|||
AmountToHeal += HealAmount;
|
||||
}
|
||||
|
||||
void UBuffComponent::ReplenishShield(float ShieldAmount, float ReplenishTime)
|
||||
{
|
||||
bReplenishingShield = true;
|
||||
ShieldReplenishRate = ShieldAmount / ReplenishTime;
|
||||
ShieldReplenishAmount += ShieldAmount;
|
||||
}
|
||||
|
||||
void UBuffComponent::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
@ -28,6 +35,7 @@ void UBuffComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorC
|
|||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||||
|
||||
HealRampUp(DeltaTime);
|
||||
ShieldRampUp(DeltaTime);
|
||||
}
|
||||
|
||||
|
||||
|
@ -47,6 +55,22 @@ void UBuffComponent::HealRampUp(float DeltaTime)
|
|||
}
|
||||
}
|
||||
|
||||
void UBuffComponent::ShieldRampUp(float DeltaTime)
|
||||
{
|
||||
if (!bReplenishingShield || Character == nullptr || Character->IsEliminated()) return;
|
||||
|
||||
const float ReplenishThisFrame = ShieldReplenishRate * DeltaTime;
|
||||
Character->SetShield(FMath::Clamp(Character->GetShield() + ReplenishThisFrame, 0, Character->GetMaxShield()));
|
||||
Character->UpdateHUDShield();
|
||||
ShieldReplenishAmount -= ReplenishThisFrame;
|
||||
|
||||
if (ShieldReplenishAmount <= 0 || Character->GetShield() >= Character->GetMaxShield())
|
||||
{
|
||||
bReplenishingShield = false;
|
||||
ShieldReplenishAmount = 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
void UBuffComponent::BuffSpeed(float BuffBaseSpeed, float BuffCrouchSpeed, float BuffTime)
|
||||
{
|
||||
if (Character == nullptr) return;
|
||||
|
|
|
@ -17,6 +17,7 @@ public:
|
|||
friend class ABlasterCharacter;
|
||||
|
||||
void Heal(float HealAmount, float HealingTime);
|
||||
void ReplenishShield(float ShieldAmount, float ReplenishTime);
|
||||
void BuffSpeed(float BuffBaseSpeed, float BuffCrouchSpeed, float BuffTime);
|
||||
void BuffJump(float BuffJumpVelocity, float BuffTime);
|
||||
void SetInitialSpeeds(float BaseSpeed, float CrouchSpeed);
|
||||
|
@ -24,6 +25,7 @@ public:
|
|||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
void HealRampUp(float DeltaTime);
|
||||
void ShieldRampUp(float DeltaTime);
|
||||
|
||||
private:
|
||||
UPROPERTY()
|
||||
|
@ -34,6 +36,11 @@ private:
|
|||
float HealingRate = 0;
|
||||
float AmountToHeal = 0.f;
|
||||
|
||||
// Shield Buff
|
||||
bool bReplenishingShield = false;
|
||||
float ShieldReplenishRate = 0;
|
||||
float ShieldReplenishAmount = 0.f;
|
||||
|
||||
// Speed Buff
|
||||
FTimerHandle SpeedBuffTimer;
|
||||
void ResetSpeeds();
|
||||
|
|
|
@ -32,6 +32,6 @@ private:
|
|||
float HealAmount = 100.f;
|
||||
|
||||
UPROPERTY(EditAnywhere)
|
||||
float HealingTime = 5.f;
|
||||
float HealingTime = 2.f;
|
||||
|
||||
};
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "ShieldPickup.h"
|
||||
|
||||
#include "Blaster/Character/BlasterCharacter.h"
|
||||
#include "Blaster/Components/BuffComponent.h"
|
||||
|
||||
void AShieldPickup::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->ReplenishShield(ShieldReplenishAmount, ShieldReplenishTime);
|
||||
}
|
||||
}
|
||||
|
||||
Destroy();
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Pickup.h"
|
||||
#include "ShieldPickup.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class BLASTER_API AShieldPickup : 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 ShieldReplenishAmount = 100.f;
|
||||
|
||||
UPROPERTY(EditAnywhere)
|
||||
float ShieldReplenishTime = 2.f;
|
||||
|
||||
};
|
Loading…
Reference in New Issue