void ALivingBomb::Explode() { ClientDestroyTerrain(GetActorLocation(), 7.0f); TArray<AActor*> overlap; GetOverlappingActors(overlap); for (AActor* actor : overlap) { ATotemCharacter* shaman = Cast<ATotemCharacter>(actor); if (shaman) { if (shaman->GetController() != GetOwner()) { ATotemPlayerController* own = Cast<ATotemPlayerController>(GetOwner()); if (own) { shaman->ReduceHealth(ExplosionDamage, own, AbilityType::FIRE, FName("LivingBomb")); } } } ABaseTotem* BaseTotem = Cast<ABaseTotem>(actor); if (BaseTotem && !BaseTotem->IsPendingKill()) { ATotemPlayerController* TotemPlayerController = Cast<ATotemPlayerController>(GetOwner()); if (TotemPlayerController) { BaseTotem->ReduceHealth(ExplosionDamage, TotemPlayerController); } } } SpawnParticle(); }
void ALivingBomb::DamageNearby(float DeltaTime) { TArray<AActor*> overlap; GetOverlappingActors(overlap); for (AActor* actor : overlap) { ATotemCharacter* shaman = Cast<ATotemCharacter>(actor); if (shaman) { if (shaman->GetController() != GetOwner()) { ATotemPlayerController* own = Cast<ATotemPlayerController>(GetOwner()); if (own) { shaman->ReduceHealth(Damage * DeltaTime, own, AbilityType::FIRE, FName("BombCharge")); } } } ABaseTotem* BaseTotem = Cast<ABaseTotem>(actor); if (BaseTotem && !BaseTotem->IsPendingKill()) { ATotemPlayerController* TotemPlayerController = Cast<ATotemPlayerController>(GetOwner()); if (TotemPlayerController) { BaseTotem->ReduceHealth(Damage * DeltaTime * .25, TotemPlayerController); } } } }
void ACyclone::Tick(float DeltaSeconds) { Super::Tick(DeltaSeconds); if (CurrentSwerveDuration <= 0.0f && HasAuthority()) { bool negate = true; if (CurrentSwerveSpeed < 0) { negate = false; } if (RandomizeSwerve) { CurrentSwerveDuration = ((float)rand() / RAND_MAX) * (MaxSwerveDuration - MinSwerveDuration) + MinSwerveDuration; CurrentSwerveSpeed = ((float)rand() / RAND_MAX) * (MaxSwerveSpeed - MinSwerveSpeed) + MinSwerveSpeed; } else { CurrentSwerveDuration = MaxSwerveDuration; CurrentSwerveSpeed = MaxSwerveSpeed; } if (negate) { CurrentSwerveSpeed *= -1; } if (FirstSwerve) { CurrentSwerveSpeed = CurrentSwerveSpeed * 2 / 3; CurrentSwerveDuration = CurrentSwerveDuration * 2 / 3; FirstSwerve = false; } } else { CurrentSwerveDuration -= DeltaSeconds; } TArray<AActor*> overlapped; GetOverlappingActors(overlapped); for (AActor* Actor : overlapped) { ABaseTotem* BaseTotem = Cast<ABaseTotem>(Actor); if (BaseTotem) { if (HasAuthority()) { ATotemPlayerController* TotemPlayerController = Cast<ATotemPlayerController>(GetOwner()); if (TotemPlayerController) { BaseTotem->ReduceHealth(Damage * DeltaSeconds, TotemPlayerController); } } } } }
/*Sets up the supplies and merchants within a village, makes it eaiser to set up within the UE*/ void AResourceVolume::BeginPlay(){ TArray<AActor*> actors; GetOverlappingActors(actors, AResourceNode::StaticClass()); for (AActor* actor : actors){ AResourceNode* tempSupplies = Cast<AResourceNode>(actor); if (supplyType == SuppliesEnums::All || tempSupplies->currentSupplyType == supplyType){ resources.Add(tempSupplies); } } }
void ALightningStorm::Tick(float DeltaTime) { Super::Tick(DeltaTime); TArray<AActor*> OverlappingActors; GetOverlappingActors(OverlappingActors, ASwoim::StaticClass()); int FireCounter = 0; TArray<ASwoim*> HitSwoimers; for (auto& first : OverlappingActors) { for (auto& second : OverlappingActors) { float d = FVector::Dist(first->GetActorLocation(), second->GetActorLocation()); if (d > 0 && d < ArcDistance) { HitSwoimers.Add(Cast<ASwoim>(second)); } } } if (HitSwoimers.Num() > 1) { int32 CurInt = FMath::RandRange(0, HitSwoimers.Num() - 1); int32 NextInt = FMath::RandRange(0, HitSwoimers.Num() - 1); for (int i = LightiningsArray.Num(); i < FMath::Min(HitSwoimers.Num(), NumOfLights); i++) { LightiningsArray.Add(Fire(HitSwoimers[CurInt], HitSwoimers[NextInt])); CurInt = NextInt; NextInt = FMath::RandRange(0, HitSwoimers.Num() - 1); } } UE_LOG(LogTemp, Warning, TEXT("LightiningsArray %d"), LightiningsArray.Num()); bool IsCompeleted = true; for (auto& Lightining : LightiningsArray) { if (!Lightining->HasCompleted()) { IsCompeleted = false; } } if (IsCompeleted) { LightiningsArray.Empty(); } }
void AShooterPickup::RespawnPickup() { bIsActive = true; PickedUpBy = NULL; OnRespawned(); TArray<AActor*> OverlappingPawns; GetOverlappingActors(OverlappingPawns, AShooterCharacter::StaticClass()); for (int32 i = 0; i < OverlappingPawns.Num(); i++) { PickupOnTouch(Cast<AShooterCharacter>(OverlappingPawns[i])); } }
void AMop::OnActorOverlapBegin(AActor* OtherActor) { if (OtherActor != GetOwner()) { //Create an array to hold all of the overlapping actors on the player TArray<AActor*> OverlappingActors; GetOverlappingActors(OverlappingActors, AEnemyInteractable::StaticClass()); //Run enemyinteraction on every enemy the mop is colliding with. for (int i = 0; i < OverlappingActors.Num(); i++) { Cast<AEnemyInteractable>(OverlappingActors[i])->EnemyInteract(this); } } }
void AFireWall::Tick(float DeltaTime) { TArray<AActor*> overlapped; GetOverlappingActors(overlapped); for (AActor* Actor : overlapped) { ATotemCharacter* TotemCharacter = Cast<ATotemCharacter>(Actor); if (TotemCharacter) { //To make sure I won't hit myself if (TotemCharacter->GetController() != GetOwner() && !Cast<AFireShaman>(TotemCharacter)) { //Here, I plan to apply damage to character //for now, just modify the value to see what happened if (HasAuthority()) { ATotemPlayerController* own = Cast<ATotemPlayerController>(GetOwner()); if (own) { TotemCharacter->ReduceHealth(Damage * DeltaTime, own, AbilityType::FIRE, FName("Firewall")); } } } } /*ABaseTotem* BaseTotem = Cast<ABaseTotem>(Actor); if (BaseTotem) { if (HasAuthority()) { ATotemPlayerController* TotemPlayerController = Cast<ATotemPlayerController>(GetOwner()); if (TotemPlayerController) { BaseTotem->ReduceHealth(Damage * DeltaTime, TotemPlayerController); } } }*/ AAirCurrent* AirCurrent = Cast<AAirCurrent>(Actor); if (AirCurrent) { Destroy(); } } }
void ATotemCharacter::Tick(float DeltaTime) { Super::Tick(DeltaTime); if (TimeSinceHit > 0.0f) { TimeSinceHit -= DeltaTime; } else { PreviousHit.controller = nullptr; PreviousHit.type = AbilityType::NONE; PreviousHit.name = ""; } if (bThirdPersonDeathCamLerp) { if (Controller) { Controller->SetControlRotation(FRotator(-1.0f * DeathCamAngle, 0, 0)); } } if (bThirdPersonCamLerp || bThirdPersonDeathCamLerp ) { CameraBoom->TargetArmLength = FMath::Lerp<float>(CameraBoom->TargetArmLength, ThirdPersonCamDistance, DeltaTime*4.0f); } else { CameraBoom->TargetArmLength = FMath::Lerp<float>(CameraBoom->TargetArmLength, 0, DeltaTime*4.0f); } if (bIsDead && (ThirdPersonCamDistance!= ThirdPersonDeathCamDistance)) { ThirdPersonCamDistance = ThirdPersonDeathCamDistance; } if ( ((FMath::Abs(CameraBoom->TargetArmLength - ThirdPersonCamDistance) < 0.5f) && bIsDead && bThirdPersonDeathCamLerp)) { ATotemPlayerController *PC = Cast<ATotemPlayerController>(Controller); if (PC) { if (HasAuthority()) { PC->HandleDead(FVector(0, 0, 0), FRotator(0, 0, 0)); } bThirdPersonDeathCamLerp = false; } } if (bDeathEffectFired && RayCastOnGround() ) { FireMaterialEffect(); bDeathEffectFired = false; } if ((CameraBoom->TargetArmLength > 0.5f) && (!bIsShamanVisible)) { if (GEngine->GetGamePlayer(GetWorld(), 0)->PlayerController == Controller) { MakeSelfVisible(); bIsShamanVisible = true; } } if ((CameraBoom->TargetArmLength <= 0.5f) && (bIsShamanVisible)) { if (GEngine->GetGamePlayer(GetWorld(), 0)->PlayerController == Controller) { MakeSelfInvisible(); bIsShamanVisible = false; } } if (Controller && FirstTick) { if (GEngine->GetGamePlayer(GetWorld(), 0)->PlayerController == Controller) { MakeSelfInvisible(); bIsShamanVisible = false; } FirstTick = false; } ATotemPlayerState *TotemPlayerState = Cast<ATotemPlayerState>(PlayerState); if (TotemPlayerState && bFirstSpawn) { SetActorLocation(TotemPlayerState->StartingLocation); SetActorRotation(TotemPlayerState->StartingRotation); bFirstSpawn = false; } if (bReborn && HasAuthority()) { TotalRebornDuration -= DeltaTime; if (TotalRebornDuration < 0.0f) { bReborn = false; ExitReborn(); } } if (HasAuthority()) { if (bBeingKnockedBack) { TimeSinceKnockedBack -= DeltaTime; if (TimeSinceKnockedBack < 0.0f) { bBeingKnockedBack = false; } } #if (WRITE_METRICS > 1) if (DeltaTime >= .025) { ATotemPlayerController* control = Cast<ATotemPlayerController>(Controller); if(control) { ATotemPlayerState* state = Cast<ATotemPlayerState>(control->PlayerState); if(state) { std::string team; switch (state->Team) { case ETeam::RED_TEAM: team = "Red"; break; case ETeam::BLUE_TEAM: team = "Blue"; break; default: team = "None"; break; } Metrics::WriteToFile(std::string(TCHAR_TO_UTF8(*(state->MyName))), team, std::string("Frame rate hit"), std::string(std::to_string(DeltaTime) + "ms"), std::string(std::to_string(1.0f/DeltaTime) + "fps")); } } } #endif } //Keep track of how long has passed since the last attack TimeSinceAttack += DeltaTime; ShotPressedDuration += DeltaTime; //If shot is pressed and enough time has been pressed if (ShotPressed && TimeSinceAttack >= TimeBetweenShots) { //And you either can rapid fire or no shot has been fired since the shot button was pressed if (CanRapidFire || !ShotFired) { OnFire(); ShotFired = true; TimeSinceAttack = 0.0f; } } else if (!ShotPressed) { ShotPressedDuration = 0; } //If get hit by cyclone, then the shaman cannnot move if (HasAuthority()) { TArray<AActor* > OverlappedActors; TArray<ACyclone* > OverlappedCyclones; GetOverlappingActors(OverlappedActors); for (int32 i = 0; i < OverlappedActors.Num(); i++) { ACyclone* Cyclone = Cast<ACyclone>(OverlappedActors[i]); if (Cyclone && !Cyclone->IsPendingKill()) { //overlap myself doesn't count if (Cyclone->GetOwner() != GetController()) { OverlappedCyclones.Add(Cyclone); } } } if (OverlappedCyclones.Num() == 0) { //Do this to prevent bCanMove be replictated every frame if (!bCanMove) { bCanMove = true; } AttachCyclone = nullptr; } else if (OverlappedCyclones.Num() > 0) { if (bCanMove) { bCanMove = false; } if (AttachCyclone) { FVector CycloneVelocity = AttachCyclone->ProjectileMovement->Velocity; ATotemPlayerController* own = Cast<ATotemPlayerController>(AttachCyclone->GetOwner()); if (own) { ReduceHealth(AttachCyclone->Damage * DeltaTime, own, AbilityType::WIND, FName(TEXT("Cyclone"))); //every second reduce Damage amount of health } LaunchCharacter(CycloneVelocity, true, true); } //CharacterMovement->Velocity = CycloneVelocity; } } //temporary solution, maybe later we need more fancy stuff. if (bIsDead && HasAuthority()) { CurrentDeadBodyDuration -= DeltaTime; if (CurrentDeadBodyDuration <= 0) { Destroy(); } } if (bClickedThisFrame) { bClickedThisFrame = false; if (Controller) { APlayerController* control = Cast<APlayerController>(Controller); if (control) { if (!control->IsInputKeyDown(EKeys::LeftMouseButton)) { LeftUp(); } } } } if (bRightButtonDownThisFrame) { bRightButtonDownThisFrame = false; if (Controller) { APlayerController* control = Cast<APlayerController>(Controller); if (control) { if (!control->IsInputKeyDown(EKeys::RightMouseButton)) { RightUp(); } } } } //CheckShiftKey(); }