|
|
|
|
|
|
| #include "CombatDamageableBox.h"
|
| #include "Components/StaticMeshComponent.h"
|
| #include "TimerManager.h"
|
| #include "Engine/World.h"
|
|
|
| ACombatDamageableBox::ACombatDamageableBox()
|
| {
|
| PrimaryActorTick.bCanEverTick = false;
|
|
|
|
|
| RootComponent = Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
|
|
|
|
|
| Mesh->SetCollisionProfileName(FName("BlockAllDynamic"));
|
|
|
|
|
| Mesh->SetSimulatePhysics(true);
|
|
|
|
|
| Mesh->bNavigationRelevant = false;
|
| }
|
|
|
| void ACombatDamageableBox::RemoveFromLevel()
|
| {
|
|
|
| Destroy();
|
| }
|
|
|
| void ACombatDamageableBox::EndPlay(EEndPlayReason::Type EndPlayReason)
|
| {
|
| Super::EndPlay(EndPlayReason);
|
|
|
|
|
| GetWorld()->GetTimerManager().ClearTimer(DeathTimer);
|
| }
|
|
|
| void ACombatDamageableBox::ApplyDamage(float Damage, AActor* DamageCauser, const FVector& DamageLocation, const FVector& DamageImpulse)
|
| {
|
|
|
| if (CurrentHP > 0.0f)
|
| {
|
|
|
| CurrentHP -= Damage;
|
|
|
|
|
| if (CurrentHP <= 0.0f)
|
| {
|
| HandleDeath();
|
| }
|
|
|
|
|
| Mesh->AddImpulseAtLocation(DamageImpulse * Mesh->GetMass(), DamageLocation);
|
|
|
|
|
| OnBoxDamaged(DamageLocation, DamageImpulse);
|
| }
|
| }
|
|
|
| void ACombatDamageableBox::HandleDeath()
|
| {
|
|
|
| Mesh->SetCollisionObjectType(ECC_Visibility);
|
|
|
|
|
| OnBoxDestroyed();
|
|
|
|
|
| GetWorld()->GetTimerManager().SetTimer(DeathTimer, this, &ACombatDamageableBox::RemoveFromLevel, DeathDelayTime);
|
| }
|
|
|
| void ACombatDamageableBox::ApplyHealing(float Healing, AActor* Healer)
|
| {
|
|
|
| }
|
|
|
| void ACombatDamageableBox::NotifyDanger(const FVector& DangerLocation, AActor* DangerSource)
|
| {
|
|
|
| }
|
|
|
|
|