diff --git a/Content/Legumix/Ennemy/BP_HealthComponent.uasset b/Content/Legumix/Ennemy/BP_HealthComponent.uasset index a9562d5..5dc6b9d 100644 --- a/Content/Legumix/Ennemy/BP_HealthComponent.uasset +++ b/Content/Legumix/Ennemy/BP_HealthComponent.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:915c0b02b161011d27d37d553bb135325dba261d6502638d155d7da5abef84d7 -size 40475 +oid sha256:a020ddfbb8be8268af6cc1f390ac62a655eb45b91686ed4418cb6d56f0ccc9ea +size 40801 diff --git a/Source/LegumeMix/Private/Player/LMHealthComponent.cpp b/Source/LegumeMix/Private/Player/LMHealthComponent.cpp index 7aa5ebd..06d80ab 100644 --- a/Source/LegumeMix/Private/Player/LMHealthComponent.cpp +++ b/Source/LegumeMix/Private/Player/LMHealthComponent.cpp @@ -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); } diff --git a/Source/LegumeMix/Private/Player/LMHitBox.cpp b/Source/LegumeMix/Private/Player/LMHitBox.cpp index c869bb8..59d2772 100644 --- a/Source/LegumeMix/Private/Player/LMHitBox.cpp +++ b/Source/LegumeMix/Private/Player/LMHitBox.cpp @@ -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 diff --git a/Source/LegumeMix/Private/Player/LMPlayer.cpp b/Source/LegumeMix/Private/Player/LMPlayer.cpp index 3ccc805..e527479 100644 --- a/Source/LegumeMix/Private/Player/LMPlayer.cpp +++ b/Source/LegumeMix/Private/Player/LMPlayer.cpp @@ -170,7 +170,7 @@ void ALMPlayer::FireBullets(const FLMBulletInfo Settings) continue; HitSomething = true; - HitBox->OnHit(Settings); + HitBox->OnHit(Settings, OutHit); } } diff --git a/Source/LegumeMix/Public/Player/LMHealthComponent.h b/Source/LegumeMix/Public/Player/LMHealthComponent.h index 4bbe8ea..112493c 100644 --- a/Source/LegumeMix/Public/Player/LMHealthComponent.h +++ b/Source/LegumeMix/Public/Player/LMHealthComponent.h @@ -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. */ diff --git a/Source/LegumeMix/Public/Player/LMHitBox.h b/Source/LegumeMix/Public/Player/LMHitBox.h index 3fe025f..d7730e0 100644 --- a/Source/LegumeMix/Public/Player/LMHitBox.h +++ b/Source/LegumeMix/Public/Player/LMHitBox.h @@ -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;