void ABaseCharacter::OnDeath(float KillingDamage, FDamageEvent const& DamageEvent, APawn* PawnInstigator, AActor* DamageCauser) { bReplicateMovement = false; bTearOff = true; PlayHit(true, KillingDamage, DamageEvent, PawnInstigator, DamageCauser); DetachFromControllerPendingDestroy(); /* Disable all collision on capsule */ UCapsuleComponent* CapsuleComp = GetCapsuleComponent(); CapsuleComp->SetCollisionEnabled(ECollisionEnabled::NoCollision); CapsuleComp->SetCollisionResponseToAllChannels(ECR_Ignore); if(bRagdolledAfterDeath) { SetRagdollPhysics(); ApplyPhysicsToTheRagdolledBody(DamageEvent); } else { SetLifeSpan(TimeAfterDeathBeforeDestroy); } }
float ANimModCharacter::TakeDamage(float Damage, struct FDamageEvent const& DamageEvent, class AController* EventInstigator, class AActor* DamageCauser) { ANimModPlayerController* MyPC = Cast<ANimModPlayerController>(Controller); if (MyPC && MyPC->HasGodMode()) { return 0.f; } if (Health <= 0) { return 0; } // Modify based on game rules. ANimModGameMode* const Game = GetWorld()->GetAuthGameMode<ANimModGameMode>(); Damage = Game ? Game->ModifyDamage(Damage, this, DamageEvent, EventInstigator, DamageCauser) : 0.f; const float ActualDamage = Super::TakeDamage(Damage, DamageEvent, EventInstigator, DamageCauser); if (ActualDamage > 0.f) { Health -= (int)ActualDamage; if (Health <= 0) { Die(ActualDamage, DamageEvent, EventInstigator, DamageCauser); } else { PlayHit(ActualDamage, DamageEvent, EventInstigator ? EventInstigator->GetPawn() : NULL, DamageCauser); } MakeNoise(1.0f, EventInstigator ? EventInstigator->GetPawn() : this); } return ActualDamage; }
void ANimModCharacter::OnRep_LastTakeHitInfo() { if (LastTakeHitInfo.bKilled) { OnDeath(LastTakeHitInfo.ActualDamage, LastTakeHitInfo.GetDamageEvent(), LastTakeHitInfo.PawnInstigator.Get(), LastTakeHitInfo.DamageCauser.Get()); } else { PlayHit(LastTakeHitInfo.ActualDamage, LastTakeHitInfo.GetDamageEvent(), LastTakeHitInfo.PawnInstigator.Get(), LastTakeHitInfo.DamageCauser.Get()); } }
float ABaseCharacter::TakeDamage(float Damage, struct FDamageEvent const& DamageEvent, class AController* EventInstigator, class AActor* DamageCauser) { if (Health > 0.f) { /* Modify based based on gametype rules */ //ASGameMode* MyGameMode = Cast<ASGameMode>(GetWorld()->GetAuthGameMode()); //Damage = MyGameMode ? MyGameMode->ModifyDamage(Damage, this, DamageEvent, EventInstigator, DamageCauser) : Damage; const float ActualDamage = Super::TakeDamage(Damage, DamageEvent, EventInstigator, DamageCauser); if (ActualDamage > 0.f) { Health -= ActualDamage; if (Health <= 0) { bool bCanDie = true; /* Check the damagetype, always allow dying if the cast fails, otherwise check the property if player can die from damagetype */ if (DamageEvent.DamageTypeClass) { UShooterDamageType* DmgType = Cast<UShooterDamageType>(DamageEvent.DamageTypeClass->GetDefaultObject()); bCanDie = (DmgType == nullptr || (DmgType && DmgType->GetCanDieFrom())); } if (bCanDie) { Die(ActualDamage, DamageEvent, EventInstigator, DamageCauser); } else { /* Player cannot die from this damage type, set hitpoints to 1.0 */ Health = 1.0f; } } else { /* Shorthand for - if x != null pick1 else pick2 */ //APawn* Pawn = EventInstigator ? EventInstigator->GetPawn() : nullptr; PlayHit(false, ActualDamage, DamageEvent, EventInstigator->GetPawn(), DamageCauser); } } GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Red, FString::SanitizeFloat(Health)); return ActualDamage; } else { ApplyPhysicsToTheRagdolledBody(DamageEvent); } return 0; }
void AShooterCharacter::OnDeath(float KillingDamage, FDamageEvent const& DamageEvent, APawn* PawnInstigator, AActor* DamageCauser) { if (bIsDying) { return; } bReplicateMovement = false; bTearOff = true; bIsDying = true; PlayHit(KillingDamage, DamageEvent, PawnInstigator, DamageCauser, true); DetachFromControllerPendingDestroy(); /* Disable all collision on capsule */ UCapsuleComponent* CapsuleComp = GetCapsuleComponent(); CapsuleComp->SetCollisionEnabled(ECollisionEnabled::NoCollision); CapsuleComp->SetCollisionResponseToAllChannels(ECR_Ignore); USkeletalMeshComponent* Mesh3P = GetMesh(); if (Mesh3P) { Mesh3P->SetCollisionProfileName(TEXT("Ragdoll")); } SetActorEnableCollision(true); SetRagdollPhysics(); /* Apply physics impulse on the bone of the enemy skeleton mesh we hit (ray-trace damage only) */ if (DamageEvent.IsOfType(FPointDamageEvent::ClassID)) { FPointDamageEvent PointDmg = *((FPointDamageEvent*)(&DamageEvent)); { // TODO: Use DamageTypeClass->DamageImpulse Mesh3P->AddImpulseAtLocation(PointDmg.ShotDirection * 12000, PointDmg.HitInfo.ImpactPoint, PointDmg.HitInfo.BoneName); } } if (DamageEvent.IsOfType(FRadialDamageEvent::ClassID)) { FRadialDamageEvent RadialDmg = *((FRadialDamageEvent const*)(&DamageEvent)); { Mesh3P->AddRadialImpulse(RadialDmg.Origin, RadialDmg.Params.GetMaxRadius(), 100000 /*RadialDmg.DamageTypeClass->DamageImpulse*/, ERadialImpulseFalloff::RIF_Linear); } } }
float AShooterCharacter::TakeDamage(float Damage, struct FDamageEvent const& DamageEvent, class AController* EventInstigator, class AActor* DamageCauser) { if (Health <= 0.f) { return 0.f; } const float ActualDamage = Super::TakeDamage(Damage, DamageEvent, EventInstigator, DamageCauser); if (ActualDamage > 0.f) { Health -= ActualDamage; if (Health <= 0) { bool bCanDie = true; /* Check the damagetype, always allow dying if the cast fails, otherwise check the property if player can die from damagetype */ if (DamageEvent.DamageTypeClass) { UShooterDamageType* DmgType = Cast<UShooterDamageType>(DamageEvent.DamageTypeClass->GetDefaultObject()); bCanDie = (DmgType == nullptr || (DmgType && DmgType->GetCanDieFrom())); } if (bCanDie) { Die(ActualDamage, DamageEvent, EventInstigator, DamageCauser); } else { /* Player cannot die from this damage type, set hitpoints to 1.0 */ Health = 1.0f; } } else { /* Shorthand for - if x != null pick1 else pick2 */ APawn* Pawn = EventInstigator ? EventInstigator->GetPawn() : nullptr; PlayHit(ActualDamage, DamageEvent, Pawn, DamageCauser, false); } } return ActualDamage; }
float ALonelyMenCharacter::TakeDamage(float Damage, struct FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser) { float ActualDamage; ActualDamage = Super::TakeDamage(Damage, DamageEvent, EventInstigator, DamageCauser); if (ActualDamage > 0.f) { nCurHealth -= ActualDamage; if (nCurHealth <= 0) { PlayDie(ActualDamage, DamageEvent, EventInstigator, DamageCauser); } else { PlayHit(ActualDamage, DamageEvent, EventInstigator ? EventInstigator->GetPawn() : NULL, DamageCauser); } } return ActualDamage; }