161 - Updating the Shield

This commit is contained in:
Kingsmedia 2022-05-23 11:47:49 +02:00
parent 6a5eecca49
commit 4ee3b3e9f8
3 changed files with 39 additions and 12 deletions

View File

@ -184,6 +184,7 @@ void ABlasterCharacter::BeginPlay()
Super::BeginPlay();
UpdateHUDHealth();
UpdateHUDShield();
if (HasAuthority())
{
OnTakeAnyDamage.AddDynamic(this, &ABlasterCharacter::ReceiveDamage);
@ -352,8 +353,26 @@ void ABlasterCharacter::PlayHitReactMontage()
void ABlasterCharacter::ReceiveDamage(AActor* DamagedActor, float Damage, const UDamageType* DamageType, AController* InstigatorController, AActor* DamageCauser)
{
if (bEliminated) return;
Health = FMath::Clamp(Health - Damage, 0.f, MaxHealth);
float DamageToHealth = Damage;
if (Shield > 0)
{
if (Shield >= Damage)
{
Shield = FMath::Clamp(Shield - Damage, 0.f, MaxShield);
DamageToHealth = 0.f;
}
else
{
DamageToHealth = FMath::Clamp(DamageToHealth - (Damage - Shield), 0.f, Damage);
Shield = 0.f;
}
}
Health = FMath::Clamp(Health - DamageToHealth, 0.f, MaxHealth);
UpdateHUDHealth();
UpdateHUDShield();
if (Health > 0.f)
{
PlayHitReactMontage();

View File

@ -158,7 +158,7 @@ void ABlasterPlayerController::SetHUDHealth(float Health, float MaxHealth)
}
else
{
bInitializeCharacterOverlay = true;
bInitializeHealth = true;
HUDHealth = Health;
HUDMaxHealth = MaxHealth;
}
@ -180,7 +180,7 @@ void ABlasterPlayerController::SetHUDShield(float Shield, float MaxShield)
}
else
{
bInitializeCharacterOverlay = true;
bInitializeShield = true;
HUDShield = Shield;
HUDMaxShield = MaxShield;
}
@ -200,7 +200,7 @@ void ABlasterPlayerController::SetHUDScore(float Score)
}
else
{
bInitializeCharacterOverlay = true;
bInitializeScore = true;
HUDScore = Score;
}
}
@ -218,7 +218,7 @@ void ABlasterPlayerController::SetHUDDefeats(int32 Defeats)
}
else
{
bInitializeCharacterOverlay = true;
bInitializeDefeats = true;
HUDDefeats = Defeats;
}
}
@ -261,6 +261,7 @@ void ABlasterPlayerController::SetHUDGrenades(int32 Grenades)
BlasterHUD->CharacterOverlay->GrenadesAmount->SetText(FText::FromString(GrenadesText));
} else
{
bInitializeGrenades = true;
HUDGrenades = Grenades;
}
}
@ -362,16 +363,15 @@ void ABlasterPlayerController::PollInit()
CharacterOverlay = BlasterHUD->CharacterOverlay;
if (CharacterOverlay)
{
SetHUDHealth(HUDHealth, HUDMaxHealth);
SetHUDShield(HUDShield, HUDMaxShield);
SetHUDScore(HUDScore);
SetHUDDefeats(HUDDefeats);
if (bInitializeHealth) SetHUDHealth(HUDHealth, HUDMaxHealth);
if (bInitializeShield) SetHUDShield(HUDShield, HUDMaxShield);
if (bInitializeScore) SetHUDScore(HUDScore);
if (bInitializeDefeats) SetHUDDefeats(HUDDefeats);
ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(GetPawn());
if (BlasterCharacter && BlasterCharacter->GetCombat())
{
SetHUDGrenades(BlasterCharacter->GetCombat()->GetGrenades());
if (bInitializeGrenades) SetHUDGrenades(BlasterCharacter->GetCombat()->GetGrenades());
}
}
}
}

View File

@ -101,14 +101,22 @@ private:
UPROPERTY()
class UCharacterOverlay* CharacterOverlay;
bool bInitializeCharacterOverlay = false;
bool bInitializeHealth = false;
float HUDHealth;
float HUDMaxHealth;
bool bInitializeShield = false;
float HUDShield;
float HUDMaxShield;
bool bInitializeScore = false;
float HUDScore;
bool bInitializeDefeats = false;
int32 HUDDefeats;
bool bInitializeGrenades = false;
int32 HUDGrenades;
};