void APBPainPlataform::InflictDamage() { if (ActiveCharacter != nullptr) { GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::White, "Apply Damage"); ActiveCharacter->TakeDamage(DamageSeverity, FDamageEvent(), nullptr, this); } }
void AProjectile::Prox_Implementation(AActor* otherActor, UPrimitiveComponent* otherComp, int32 otherBodyIndex, bool bFromSweep, const FHitResult& sweepResult) { if (otherComp != otherActor->GetRootComponent()) { return; } otherActor->TakeDamage(damage, FDamageEvent(), NULL, this); Destroy(); }
void ASCharacter::IncrementHunger() { Hunger = FMath::Clamp(Hunger + IncrementHungerAmount, 0.0f, GetMaxHunger()); if (Hunger > CriticalHungerThreshold) { // Apply damage to self. // TODO: Set DamageType TakeDamage(10.0f, FDamageEvent(), GetController(), this); } }
void AGhost::NotifyActorBeginOverlap(AActor *OtherActor) { Super::NotifyActorBeginOverlap(OtherActor); if (!IsPendingKill()) { auto Player = static_cast<APacmanPlayer*>(OtherActor); // Timer is paused only when player is in hunt mode if (Player->IsHunter()) { TakeDamage(100.f, FDamageEvent(), Player->GetController(), Player); } else { Player->TakeDamage(100.f, FDamageEvent(), GetController(), this); } UGameplayStatics::PlaySound2D(this, CollisionSound); } }
void AClashOfBallsBall::DoDamage_Implementation(AActor *Actor) { AClashOfBallsBall *enemy = Cast<AClashOfBallsBall>(Actor); if (enemy) { float dmg = (GetVelocity().X + GetVelocity().Y + GetVelocity().Z) / DamageMultiplier; if (dmg < 0) { dmg *= -1; } enemy->TakeDamage(dmg, FDamageEvent(), this->GetInstigatorController(), this); } }
void ANimModCharacter::KilledBy(APawn* EventInstigator) { if (Role == ROLE_Authority && !bIsDying) { AController* Killer = NULL; if (EventInstigator != NULL) { Killer = EventInstigator->Controller; LastHitBy = NULL; } Die(Health, FDamageEvent(UDamageType::StaticClass()), Killer, NULL); } }
void ASCharacter::KilledBy(class APawn* EventInstigator) { if (Role == ROLE_Authority && !bIsDying) { AController* Killer = nullptr; if (EventInstigator != nullptr) { Killer = EventInstigator->Controller; LastHitBy = nullptr; } Die(Health, FDamageEvent(UDamageType::StaticClass()), Killer, nullptr); } }
void AMeteorProjectile::OnHit(AActor* SelfActor, AActor* OtherActor, FVector NormalImpulse, const FHitResult& Hit) { UE_LOG(LogTemp, Display, TEXT("METEOR HIT")); TArray<FOverlapResult> res; if (GetWorld()->OverlapMultiByChannel(res, GetActorLocation(), FQuat::Identity, ECollisionChannel::ECC_Visibility, FCollisionShape::MakeSphere(300))) { for (auto a : res) { if (a.Actor.IsValid() && Cast<ABaseGamer>(a.Actor.Get())) { a.Actor->TakeDamage(FMath::FRandRange(6000, 16000), FDamageEvent(), GetInstigator() ? GetInstigator()->GetController() : nullptr, this); } } } //DrawDebugSphere(GetWorld(), GetActorLocation(), 300, 16, FColor::Red, false, 1); Destroy(); }
void AAssaultWeapon::WeaponTrace() { static FName WeaponFireTag = FName(TEXT("WeaponTrace")); static FName MuzzleSocket = FName(TEXT("MuzzleFlashSocket")); // Start from the muzzle's position FVector StartPos = WeaponMesh->GetSocketLocation(MuzzleSocket); // Get forward vector of MyPawn FVector Forward = MyPawn->GetActorForwardVector(); // Calculate end position FVector EndPos = StartPos + Forward * WeaponRange; // Perform trace to retrieve hit info FCollisionQueryParams TraceParams(WeaponFireTag, true, Instigator); TraceParams.bTraceAsyncScene = true; TraceParams.bReturnPhysicalMaterial = true; // This fires the ray and checks against all objects w/ collision FHitResult Hit(ForceInit); GetWorld()->LineTraceSingleByObjectType(Hit, StartPos, EndPos, FCollisionObjectQueryParams::AllObjects,TraceParams); // Did this hit anything? If its a dwarf call their takedamage of assault weapon with the assault weapons "Damage" variable if (Hit.bBlockingHit) { UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), HitEffect, Hit.ImpactPoint, FRotator(0,0,0), true); Dwarf = Cast<ADwarfCharacter>(Hit.GetActor()); if(Dwarf){ Dwarf->TakeDamage(Damage, FDamageEvent(), GetInstigatorController(), this); } } }
void ALD35Character::OnFire() { if (IsInAlternateForm) { FVector trgPos = FindComponentByClass<UCameraComponent>()->GetComponentLocation() + GetActorRotation().RotateVector(FVector(140, 0, 0)); //DrawDebugSphere(GetWorld(), trgPos, 150, 8, FColor::Red, false, 0.5f); TArray<FOverlapResult> res; if (GetWorld()->OverlapMultiByChannel(res, trgPos, FQuat::Identity, ECollisionChannel::ECC_WorldDynamic, FCollisionShape::MakeSphere(150))) { for (auto& a : res) { if (a.Actor.Get() && a.Actor != this) { a.Actor->TakeDamage(1, FDamageEvent(), this->GetController(), this); } } } if (FMath::Rand() % 3 == 0) { UGameplayStatics::PlaySoundAtLocation(this, TransformSound, GetActorLocation()); } return; } // try and fire a projectile if (ProjectileClass != NULL) { USceneComponent* cam = FindComponentByClass<UCameraComponent>(); if (cam) { FRotator SpawnRotation = cam->GetComponentRotation(); FVector SpawnLocation = cam->GetComponentLocation(); TArray<UActorComponent*> childComponents = GetComponentsByTag(USceneComponent::StaticClass(), "Gun"); for (auto& b : childComponents) { if (auto a = Cast<USceneComponent>(b)) { if (a->ComponentHasTag(TEXT("Gun"))) { SpawnRotation = a->GetComponentRotation(); SpawnLocation = a->GetComponentLocation(); //UE_LOG(LogTemp, Display, TEXT("NM %s %s %s %s %s"), *a->GetName(), *cam->GetName(), *SpawnLocation.ToString(), *cam->GetComponentLocation().ToString(), *a->GetRelativeTransform().ToString()); } } } UWorld* const World = GetWorld(); if (World != NULL) { // spawn the projectile at the muzzle FActorSpawnParameters params; params.Instigator = this; World->SpawnActor<ALD35Projectile>(ProjectileClass, SpawnLocation, SpawnRotation, params); } } } // try and play the sound if specified if (FireSound != NULL) { UGameplayStatics::PlaySoundAtLocation(this, ShootCrossbowSound, GetActorLocation()); } }
void ABaseCharacter::FellOutOfWorld(const class UDamageType& DmgType) { Die(Health, FDamageEvent(DmgType.GetClass()), NULL, NULL); }
void ANimModCharacter::FellOutOfWorld(const class UDamageType& dmgType) { Die(Health, FDamageEvent(dmgType.GetClass()), NULL, NULL); }
void AZombieShooterPlayerController::DebugPressed() { GetPawn()->TakeDamage(25, FDamageEvent(), this, GetPawn()); }
AActor* UWeaponComponent::PlotHitLine(float LineLength, AController* Instigator, TSubclassOf<UDamageType> DamageType, UGameplaySystemComponent* GameplaySystem) { if (this->GetOwner() == nullptr) return nullptr; AController* OwnerAsController = dynamic_cast<AController*>(this->GetOwner()); if (OwnerAsController == nullptr) return nullptr; if (OwnerAsController->GetPawn() == nullptr) return nullptr; FVector TraceStart = OwnerAsController->GetPawn()->GetActorLocation(); FVector TraceEnd = OwnerAsController->GetPawn()->GetActorLocation(); { FRotator Rotation = OwnerAsController->GetControlRotation(); TraceEnd += Rotation.RotateVector(FVector(LineLength, 0, 0)); } // Setup the trace query FCollisionQueryParams TraceParams = FCollisionQueryParams(); TraceParams.AddIgnoredActor(OwnerAsController->GetPawn()); TraceParams.bTraceAsyncScene = true; FCollisionResponseParams CollisionParams = FCollisionResponseParams(); FHitResult HitResult; if (this->GetWorld()->LineTraceSingleByChannel(HitResult, TraceStart, TraceEnd, ECC_GameTraceChannel1, TraceParams, CollisionParams)) { if (GameplaySystem == nullptr) return nullptr; APawn* TargetAsPawn = dynamic_cast<APawn*>(HitResult.Actor.Get()); if (TargetAsPawn) { TargetAsPawn->GetController()->TakeDamage(GameplaySystem->GetInfightAttackPoints(), FDamageEvent(DamageType), Instigator, Instigator->GetPawn()); } return HitResult.GetActor(); } else { return nullptr; } }
void ARifleWeapon::Fire() { Super::Fire(); // Casting FVector CamLoc; FRotator CamRot; ThePlayer->Controller->GetPlayerViewPoint(CamLoc, CamRot); // Get the camera position and rotation const FVector StartTrace = Mesh1P->GetSocketLocation(TEXT("MuzzleFlashSocket")); // CamLoc; // trace start is the camera location const FVector Direction = CamRot.Vector(); const FVector EndTrace = StartTrace + Direction *MainFire.FireDistance; // Perform trace to retrieve hit info FCollisionQueryParams TraceParams(FName(TEXT("WeaponTrace")), true, this); TraceParams.bTraceAsyncScene = true; TraceParams.bReturnPhysicalMaterial = true; TraceParams.AddIgnoredActor(ThePlayer); //print("Fire Event"); FHitResult Hit(ForceInit); if (GetWorld()->LineTraceSingleByChannel(Hit, StartTrace, EndTrace, ECC_WorldStatic, TraceParams)) { //printr("Hit Something"); // if (GEngine) GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, Hit.GetActor()->GetName()); ABaseCharacter* EnemyPlayer = Cast<ABaseCharacter>(Hit.GetActor()); // typecast to the item class to the hit actor if (EnemyPlayer) { BP_HitEnemy(Hit); //printr("Apply Damage"); //EnemyPlayer->TakeDamage(Player, currentWeapon->MainDamage, 0); EnemyPlayer->TakeDamage(MainFire.FireDamage, FDamageEvent(), ThePlayer->Controller, ThePlayer); // Hit event // Spawn blood effect //UGameplayStatics::SpawnEmitterAtLocation(this, HitFX, Hit.Location, Hit.Normal.Rotation(), true); } } /* /// Beam Weapon if (Cast<UBeamWeapon>(currentWeapon)) { // Casting FVector CamLoc; FRotator CamRot; Cast<AInventoryTutorialCharacter>(Player)->Controller->GetPlayerViewPoint(CamLoc, CamRot); // Get the camera position and rotation const FVector StartTrace = Mesh->GetSocketLocation(TEXT("FireSocket")); // CamLoc; // trace start is the camera location const FVector Direction = CamRot.Vector(); const FVector EndTrace = StartTrace + Direction * Cast<UBeamWeapon>(currentWeapon)->MainFireDistance; // Perform trace to retrieve hit info FCollisionQueryParams TraceParams(FName(TEXT("WeaponTrace")), true, this); TraceParams.bTraceAsyncScene = true; TraceParams.bReturnPhysicalMaterial = true; TraceParams.AddIgnoredActor(Player); FHitResult Hit(ForceInit); if (GetWorld()->LineTraceSingle(Hit, StartTrace, EndTrace, ECC_WorldStatic, TraceParams)) { // if (GEngine) GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, Hit.GetActor()->GetName()); AWarrior* EnemyPlayer = Cast<AWarrior>(Hit.GetActor()); // typecast to the item class to the hit actor if (EnemyPlayer) { EnemyPlayer->MyTakeDamage(Player, currentWeapon->MainDamage, 0); if (GEngine) GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, Hit.BoneName.GetPlainNameString()); DrawDebugLine( GetWorld(), StartTrace, Hit.Location, FColor(255, 0, 0), false, 3, 0, 1 ); } } } */ /* // try and fire a projectile if (ProjectileClass != NULL) { const FRotator SpawnRotation = GetControlRotation(); // MuzzleOffset is in camera space, so transform it to world space before offsetting from the character location to find the final muzzle position const FVector SpawnLocation = GetActorLocation() + SpawnRotation.RotateVector(GunOffset); UWorld* const World = GetWorld(); if (World != NULL) { // spawn the projectile at the muzzle World->SpawnActor<AShooterProjectile>(ProjectileClass, SpawnLocation, SpawnRotation); } } // try and play the sound if specified if (FireSound != NULL) { UGameplayStatics::PlaySoundAtLocation(this, FireSound, GetActorLocation()); } */ }