Exposed some information related to being hit

Signed-off-by: TjgL <lithmoneo@gmail.com>
This commit is contained in:
TjgL 2025-03-14 10:36:45 +01:00
parent 96c339fcae
commit 28af663a4d
6 changed files with 24 additions and 12 deletions

Binary file not shown.

View File

@ -36,14 +36,14 @@ void ULMHealthComponent::TakeDamage_Implementation(const float Damage)
if (Damage <= 0.0f) if (Damage <= 0.0f)
return; return;
OnHit(Damage); OnDamageReceived(Damage);
OnHealthChanged.Broadcast(Health, Damage); OnHealthChanged.Broadcast(Health, Damage);
if (Health <= 0.0f) if (Health <= 0.0f)
Kill(); Kill();
} }
void ULMHealthComponent::OnHit_Implementation(const float Damage) void ULMHealthComponent::OnDamageReceived_Implementation(const float Damage)
{ {
Health = FMath::Clamp(Health - Damage, 0.0f, MaxHealth); Health = FMath::Clamp(Health - Damage, 0.0f, MaxHealth);
} }
@ -55,9 +55,10 @@ void ULMHealthComponent::Kill()
OnDeath.Broadcast(); OnDeath.Broadcast();
} }
void ULMHealthComponent::HitBoxHit(ULMHitBox* HitBox, float Damage) void ULMHealthComponent::HitBoxHit(ULMHitBox* HitBox, const float Damage, const FVector& Origin, const FHitResult& HitInfo)
{ {
TakeDamage(Damage); TakeDamage(Damage);
OnHit(Damage, Origin, HitInfo);
} }

View File

@ -12,13 +12,13 @@ ULMHitBox::ULMHitBox()
PrimaryComponentTick.bCanEverTick = true; PrimaryComponentTick.bCanEverTick = true;
} }
void ULMHitBox::OnHit(const FLMBulletInfo& BulletInfo) void ULMHitBox::OnHit(const FLMBulletInfo& BulletInfo, const FHitResult& Hit)
{ {
const float Damage = BulletInfo.Damage; const float Damage = BulletInfo.Damage;
const double Distance = FVector::Distance(BulletInfo.Origin, GetComponentLocation()); const double Distance = FVector::Distance(BulletInfo.Origin, GetComponentLocation());
const float TotalDamage = CalculateDamage(Damage, Distance, BulletInfo.Falloff, BulletInfo.MaxDistance); const float TotalDamage = CalculateDamage(Damage, Distance, BulletInfo.Falloff, BulletInfo.MaxDistance);
OnHitBoxHit.Broadcast(this, TotalDamage); OnHitBoxHit.Broadcast(this, TotalDamage, BulletInfo.Origin, Hit);
} }
bool ULMHitBox::CanBeHitByTeam(const ETeam Team) const bool ULMHitBox::CanBeHitByTeam(const ETeam Team) const

View File

@ -170,7 +170,7 @@ void ALMPlayer::FireBullets(const FLMBulletInfo Settings)
continue; continue;
HitSomething = true; HitSomething = true;
HitBox->OnHit(Settings); HitBox->OnHit(Settings, OutHit);
} }
} }

View File

@ -49,9 +49,11 @@ public:
* Called automatically when a hitbox is hit. * Called automatically when a hitbox is hit.
* @param HitBox The hitbox that was hit. * @param HitBox The hitbox that was hit.
* @param Damage The damage received by the hitbox. * @param Damage The damage received by the hitbox.
* @param Origin The origin of the damage.
* @param HitInfo Information about the ray that hit the hitbox.
*/ */
UFUNCTION() UFUNCTION()
void HitBoxHit(ULMHitBox* HitBox, float Damage); void HitBoxHit(ULMHitBox* HitBox, float Damage, const FVector& Origin, const FHitResult& HitInfo);
/** /**
* Applies the amount of damage received to the component. * Applies the amount of damage received to the component.
@ -60,7 +62,7 @@ public:
* @param Damage The damage received. * @param Damage The damage received.
*/ */
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category=Legumix) UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category=Legumix)
void OnHit(float Damage); void OnDamageReceived(float Damage);
/** /**
* Adds an amount of health to the character. * Adds an amount of health to the character.
@ -70,6 +72,15 @@ public:
UFUNCTION(BlueprintCallable, Category=Legumix, meta=(Keywords = "Refill, Health")) UFUNCTION(BlueprintCallable, Category=Legumix, meta=(Keywords = "Refill, Health"))
void AddHealth(const float AddedHealth, const bool NoLimits = false) { Health = FMath::Clamp(Health + AddedHealth, 0.0f, NoLimits ? INT_MAX : MaxHealth); } void AddHealth(const float AddedHealth, const bool NoLimits = false) { Health = FMath::Clamp(Health + AddedHealth, 0.0f, NoLimits ? INT_MAX : MaxHealth); }
/**
* Event automatically called when the character receives damages from an attack source.
* @param Damage The damage received.
* @param Origin The origin of the damage.
* @param HitInfo The collisions informations.
*/
UFUNCTION(BlueprintImplementableEvent, Category=Legumix, meta=(Keywords = "Refill"))
void OnHit(float Damage, const FVector& Origin, const FHitResult& HitInfo);
/** /**
* Completely refill the health of the component. * Completely refill the health of the component.
*/ */

View File

@ -16,11 +16,11 @@ class LEGUMEMIX_API ULMHitBox : public UCapsuleComponent
{ {
GENERATED_BODY() GENERATED_BODY()
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FHitBoxHitSignature, ULMHitBox*, HitBox, float, Damage); DECLARE_DYNAMIC_MULTICAST_DELEGATE_FourParams(FHitBoxHitSignature, ULMHitBox*, HitBox, float, Damage, const FVector&, Origin, const FHitResult&, HitInfo);
public: public:
ULMHitBox(); ULMHitBox();
void OnHit(const FLMBulletInfo& BulletInfo); void OnHit(const FLMBulletInfo& BulletInfo, const FHitResult& Hit);
void SetHealthComponent(ULMHealthComponent* NewHealthComponent) { HealthComponent = NewHealthComponent; } void SetHealthComponent(ULMHealthComponent* NewHealthComponent) { HealthComponent = NewHealthComponent; }
bool CanBeHitByTeam(ETeam Team) const; bool CanBeHitByTeam(ETeam Team) const;