void ACharacterTargetSystem::cleanUpTargets(UWorld* currentGameWorld) { // clean up all previous focused enemies for (TObjectIterator<ABasicEnemy> enemyFocusIterator; enemyFocusIterator; ++enemyFocusIterator) { if (enemyFocusIterator->GetWorld() == currentGameWorld) { ABasicEnemy* enemyChar = *enemyFocusIterator; if (!enemyChar->IsPendingKill()) { enemyChar->hideFocusComponent(); enemyChar->removeFocus(); enemyChar->disableMenu(); } } } // clean up all previous focused enemies for (TObjectIterator<ABasicNpc> npcFocusIterator; npcFocusIterator; ++npcFocusIterator) { if (npcFocusIterator->GetWorld() == currentGameWorld) { ABasicNpc* npcChar = *npcFocusIterator; npcChar->hideFocusComponent(); npcChar->removeFocus(); } } }
// check only for enemies which are free to target in the given range bool ACharacterTargetSystem::checkFreeTargetEnemies(ACharacter* player, UWorld* currentGameWorld, float distance) { ABasicEnemy* enemyChar; bool enemyFreeForTarget = false; float distanceToTarget = distance; // TODO for (TObjectIterator<ABasicEnemy> enemyIterator; enemyIterator; ++enemyIterator) { if (enemyIterator->GetWorld() == currentGameWorld) { enemyChar = *enemyIterator; float distanceToPlayer = enemyChar->GetDistanceTo(player); if (!enemyChar->IsPendingKill() && distanceToPlayer < distanceToTarget) { bool isEnemySkipped = enemyChar->bSkippedTarget; if (!isEnemySkipped) { enemyFreeForTarget = true; } } } } return enemyFreeForTarget; }
bool ASkill::SphereTrace(AActor* actorToIgnore, const FVector& start, const FVector& end, const float radius, TArray<FHitResult>& hitOut, ECollisionChannel traceChannel /* = ECC_Pawn */) { FCollisionQueryParams traceParams(FName(TEXT("Sphere Trace")), true, actorToIgnore); traceParams.bTraceComplex = true; traceParams.bReturnPhysicalMaterial = false; traceParams.AddIgnoredActor(actorToIgnore); TObjectIterator<APlayerController> pc; if (!pc) return false; DrawDebugSphere(pc->GetWorld(), start, radius, 8, FColor::Red, true); return pc->GetWorld()->SweepMultiByChannel(hitOut, start, end, FQuat(), traceChannel, FCollisionShape::MakeSphere(radius), traceParams); }
void AFPSCharacter::GetMyHealth() { if (GEngine) { TObjectIterator< APlayerController > ThePC; UWorld* TheWorld = ThePC->GetWorld(); AFPSGM* MyGM = Cast<AFPSGM>(UGameplayStatics::GetGameMode(TheWorld)); if (MyGM != NULL) { GEngine->AddOnScreenDebugMessage(1, 5.f, FColor::Red, FString::FromInt(MyGM->Health)); } } }
void ACharacterTargetSystem::makeAllNpcsFocusable(UWorld* currentGameWorld) { ABasicNpc* npcChar; for (TObjectIterator<ABasicNpc> npcFreeIterator; npcFreeIterator; ++npcFreeIterator) { if (npcFreeIterator->GetWorld() == currentGameWorld) { npcChar = *npcFreeIterator; if (npcChar) { npcChar->bSkippedTarget = false; } } } }
void ACharacterTargetSystem::makeAllEnemiesFocusable(UWorld* currentGameWorld) { ABasicEnemy* enemyChar; for (TObjectIterator<ABasicEnemy> enemyFreeIterator; enemyFreeIterator; ++enemyFreeIterator) { if (enemyFreeIterator->GetWorld() == currentGameWorld) { enemyChar = *enemyFreeIterator; if (enemyChar && !enemyChar->IsPendingKill()) { enemyChar->bSkippedTarget = false; } } } }
void ACharacterTargetSystem::findNPCTargetByDistance(ACharacter* player, UWorld* currentGameWorld, float distance) { ABasicNpc* npcChar; float distanceToPlayer; float distanceToTarget = distance; bool npcFreeForTarget = checkFreeTargetNpcs(currentGameWorld); // if every enemy has been skipped, set all to be focusable again if (!npcFreeForTarget) { makeAllNpcsFocusable(currentGameWorld); } // get distance to enemy that can be focused for (TObjectIterator<ABasicNpc> npcFocusIterator; npcFocusIterator; ++npcFocusIterator) { if (npcFocusIterator->GetWorld() == currentGameWorld) { npcChar = *npcFocusIterator; if (npcChar && player && npcChar->bSkippedTarget == false) { distanceToPlayer = npcChar->GetDistanceTo(player); if (distanceToPlayer < distanceToTarget) { npcChar->bSkippedTarget = true; npcChar->setFocus(); targetedNpc = npcChar; break; } else { npcChar->removeFocus(); targetedNpc = nullptr; } } else { npcChar->removeFocus(); targetedNpc = nullptr; } } } }
void ACharacterTargetSystem::findEnemyTargetByDistance(ACharacter* player, UWorld* currentGameWorld, float distance) { ABasicEnemy* enemyChar; float distanceToPlayer; float distanceToTarget = distance; //TODO CHECK THIS IN DISTANCE bool enemyFreeForTarget = checkFreeTargetEnemies(player, currentGameWorld, distance); // if every enemy has been skipped, set all to be focusable again if (!enemyFreeForTarget) { makeAllEnemiesFocusable(currentGameWorld); } // get distance to enemy that can be focused for (TObjectIterator<ABasicEnemy> enemyFocusIterator; enemyFocusIterator; ++enemyFocusIterator) { if (enemyFocusIterator->GetWorld() == currentGameWorld) { enemyChar = *enemyFocusIterator; if (enemyChar && !enemyChar->IsPendingKill() && player && enemyChar->bSkippedTarget == false) { distanceToPlayer = enemyChar->GetDistanceTo(player); if (distanceToPlayer < distanceToTarget) { enemyChar->bSkippedTarget = true; enemyChar->setFocus(); targetedEnemy = enemyChar; break; } else { enemyChar->removeFocus(); } } else { enemyChar->removeFocus(); targetedEnemy = nullptr; } } } }
bool ACharacterTargetSystem::checkFreeTargetNpcs(UWorld* currentGameWorld) { ABasicNpc* npcChar; bool npcFreeForTarget = false; // check if every enemy has been focused yet for (TObjectIterator<ABasicNpc> npcIterator; npcIterator; ++npcIterator) { if (npcIterator->GetWorld() == currentGameWorld) { npcChar = *npcIterator; bool isEnemySkipped = npcChar->bSkippedTarget; if (!isEnemySkipped) { npcFreeForTarget = true; } } } return npcFreeForTarget; }
void UAdvancedSessionsLibrary::GetNumberOfNetworkPlayers(int32 &NumNetPlayers) { //Get an actor to GetWorld() from TObjectIterator<AActor> Itr; if (!Itr) { UE_LOG(AdvancedSessionsLog, Warning, TEXT("GetNumberOfNetworkPlayers Failed to get iterator!")); return; } //~~~~~~~~~~~~ //Get World UWorld* TheWorld = Itr->GetWorld(); if (!TheWorld) { UE_LOG(AdvancedSessionsLog, Warning, TEXT("GetNumberOfNetworkPlayers Failed to get World()!")); return; } TArray<class APlayerState*>& PlayerArray = (TheWorld->GetGameState()->PlayerArray); NumNetPlayers = PlayerArray.Num(); }