Merge remote-tracking branch 'origin/master'

This commit is contained in:
Emilie Schott 2025-03-14 11:58:58 +01:00
commit 8064a47c2c
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)
return;
OnHit(Damage);
OnDamageReceived(Damage);
OnHealthChanged.Broadcast(Health, Damage);
if (Health <= 0.0f)
Kill();
}
void ULMHealthComponent::OnHit_Implementation(const float Damage)
void ULMHealthComponent::OnDamageReceived_Implementation(const float Damage)
{
Health = FMath::Clamp(Health - Damage, 0.0f, MaxHealth);
}
@ -55,9 +55,10 @@ void ULMHealthComponent::Kill()
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);
OnHit(Damage, Origin, HitInfo);
}

View File

@ -12,13 +12,13 @@ ULMHitBox::ULMHitBox()
PrimaryComponentTick.bCanEverTick = true;
}
void ULMHitBox::OnHit(const FLMBulletInfo& BulletInfo)
void ULMHitBox::OnHit(const FLMBulletInfo& BulletInfo, const FHitResult& Hit)
{
const float Damage = BulletInfo.Damage;
const double Distance = FVector::Distance(BulletInfo.Origin, GetComponentLocation());
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

View File

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

View File

@ -49,9 +49,11 @@ public:
* Called automatically when a hitbox is hit.
* @param HitBox The hitbox that was hit.
* @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()
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.
@ -60,7 +62,7 @@ public:
* @param Damage The damage received.
*/
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category=Legumix)
void OnHit(float Damage);
void OnDamageReceived(float Damage);
/**
* Adds an amount of health to the character.
@ -70,6 +72,15 @@ public:
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); }
/**
* 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.
*/

View File

@ -16,11 +16,11 @@ class LEGUMEMIX_API ULMHitBox : public UCapsuleComponent
{
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:
ULMHitBox();
void OnHit(const FLMBulletInfo& BulletInfo);
void OnHit(const FLMBulletInfo& BulletInfo, const FHitResult& Hit);
void SetHealthComponent(ULMHealthComponent* NewHealthComponent) { HealthComponent = NewHealthComponent; }
bool CanBeHitByTeam(ETeam Team) const;