void AUTDomGameMode::AnnounceMatchStart() { if (bAnnounceTeam) { for (FConstPlayerControllerIterator Iterator = GetWorld()->GetPlayerControllerIterator(); Iterator; ++Iterator) { AUTPlayerController* NextPlayer = Cast<AUTPlayerController>(*Iterator); AUTTeamInfo* Team = (NextPlayer && Cast<AUTPlayerState>(NextPlayer->PlayerState)) ? Cast<AUTPlayerState>(NextPlayer->PlayerState)->Team : NULL; if (Team) { NextPlayer->ClientReceiveLocalizedMessage(GameMessageClass, Team->TeamIndex + 9, NextPlayer->PlayerState, NULL, NULL); } } } else { BroadcastLocalized(this, UUTGameMessage::StaticClass(), 0, NULL, NULL, NULL); } }
void AUTBetrayalPlayerState::RogueTimer() { AUTPlayerController* PC = Cast<AUTPlayerController>(GetOwner()); RemainingRogueTime--; if (RemainingRogueTime < 0) { RogueExpired(); if (PC != NULL) { AUTBetrayalGameMode* Game = GetWorld()->GetAuthGameMode<AUTBetrayalGameMode>(); if (Game != NULL) { PC->ClientReceiveLocalizedMessage(Game->AnnouncerMessageClass, 5); } } } else if (RemainingRogueTime < 3 && PC != NULL) { PC->ClientPlaySound(RogueFadingSound); } }
void FArtemis::Tick(float DeltaTime) { if (GIsEditor) { return; } // Avoid double ticking if (LastFrameCounter > 0 && LastFrameCounter == GFrameCounter) { return; } LastFrameCounter = GFrameCounter; // We may be going 120hz, don't spam the device DeltaTimeAccumulator += DeltaTime; if (DeltaTimeAccumulator < FrameTimeMinimum) { return; } DeltaTimeAccumulator = 0; // Setup JSON object TSharedRef<FJsonObject> RootJson(new FJsonObject()); TSharedRef<FJsonObject> PlayerJson(new FJsonObject()); TSharedRef<FJsonObject> EnvironmentJson(new FJsonObject()); RootJson->SetObjectField("Player", PlayerJson); RootJson->SetObjectField("Environment", EnvironmentJson); // Setup JSON writer to be used before returning FString Buffer; TSharedRef<TJsonWriter<> > Writer = TJsonWriterFactory<>::Create(&Buffer); AUTPlayerController* UTPC = nullptr; AUTGameState* GS = nullptr; const TIndirectArray<FWorldContext>& AllWorlds = GEngine->GetWorldContexts(); for (const FWorldContext& Context : AllWorlds) { UWorld* World = Context.World(); if (World && World->WorldType == EWorldType::Game) { UTPC = Cast<AUTPlayerController>(GEngine->GetFirstLocalPlayerController(World)); if (UTPC) { UUTLocalPlayer* UTLP = Cast<UUTLocalPlayer>(UTPC->GetLocalPlayer()); if (UTLP == nullptr || UTLP->IsMenuGame()) { UTPC = nullptr; continue; } GS = World->GetGameState<AUTGameState>(); break; } } } if (!UTPC || !GS) { RootJson->SetStringField("State", "MainMenu"); FJsonSerializer::Serialize(RootJson, Writer); WritePipe(Buffer); return; } // Update environment data if (GS->GetGameModeClass()) { EnvironmentJson->SetStringField("GameMode", GS->GetGameModeClass()->GetName()); } EnvironmentJson->SetBoolField("MatchStarted", GS->HasMatchStarted()); EnvironmentJson->SetNumberField("GoalScore", GS->GoalScore); // Insert GameState JsonReport GS->MakeJsonReport(EnvironmentJson); // The JsonReport may contain all players, which is a bit too much if (EnvironmentJson->HasField("Players")) { EnvironmentJson->RemoveField("Players"); } // Update player data // If character not found player must be spectating(?) if (!UTPC->GetUTCharacter()) { RootJson->SetStringField("State", "Spectating"); } // If dead, don't try reading HP/Armor else if (UTPC->GetUTCharacter()->IsDead()) { RootJson->SetStringField("State", "Dead"); PlayerJson->SetNumberField("Health", 0); PlayerJson->SetNumberField("Armor", 0); } // Player is found and alive else { // Update HP and armor RootJson->SetStringField("State", "Alive"); PlayerJson->SetNumberField("Health", UTPC->GetUTCharacter()->Health); PlayerJson->SetNumberField("Armor", UTPC->GetUTCharacter()->ArmorAmount); // Update player powerups data TSharedRef<FJsonObject> InventoryJson(new FJsonObject()); PlayerJson->SetObjectField("Inventory", InventoryJson); InventoryJson->SetBoolField("HasJumpBoots", false); InventoryJson->SetBoolField("HasInvisibility", false); InventoryJson->SetBoolField("HasBerserk", false); InventoryJson->SetBoolField("HasUDamage", false); InventoryJson->SetBoolField("HasThighPads", false); InventoryJson->SetBoolField("HasShieldBelt", false); InventoryJson->SetBoolField("HasChestArmor", false); InventoryJson->SetBoolField("HasHelmet", false); for (TInventoryIterator<> It(UTPC->GetUTCharacter()); It; ++It) { AUTInventory* InventoryItem = (*It); // Using Contains here because pickups might have slighty different names in different contexts if (InventoryItem->GetClass()->GetName().Contains("Armor_ThighPads")) { InventoryJson->SetBoolField("HasThighPads", true); } else if (InventoryItem->GetClass()->GetName().Contains("Armor_ShieldBelt")) { InventoryJson->SetBoolField("HasShieldBelt", true); } else if (InventoryItem->GetClass()->GetName().Contains("Armor_Chest")) { InventoryJson->SetBoolField("HasChestArmor", true); } else if (InventoryItem->GetClass()->GetName().Contains("Armor_Helmet")) { InventoryJson->SetBoolField("HasHelmet", true); } else if (InventoryItem->GetClass()->GetName().Contains("JumpBoots")) { InventoryJson->SetBoolField("HasJumpBoots", true); } else if (InventoryItem->GetClass()->GetName().Contains("Invis")) { InventoryJson->SetBoolField("HasInvisibility", true); } else if (InventoryItem->GetClass()->GetName().Contains("Berserk")) { InventoryJson->SetBoolField("HasBerserk", true); } else if (InventoryItem->GetClass()->GetName().Contains("UDamage")) { InventoryJson->SetBoolField("HasUDamage", true); } } // Update player weapon data TSharedRef<FJsonObject> WeaponJson(new FJsonObject()); PlayerJson->SetObjectField("Weapon", WeaponJson); if (UTPC->GetUTCharacter()->GetWeapon()) { WeaponJson->SetStringField("Name", UTPC->GetUTCharacter()->GetWeapon()->GetClass()->GetName()); WeaponJson->SetNumberField("Ammo", UTPC->GetUTCharacter()->GetWeapon()->Ammo); WeaponJson->SetNumberField("MaxAmmo", UTPC->GetUTCharacter()->GetWeapon()->MaxAmmo); WeaponJson->SetBoolField("IsFiring", UTPC->GetUTCharacter()->GetWeapon()->IsFiring()); WeaponJson->SetNumberField("FireMode", UTPC->GetUTCharacter()->GetWeapon()->GetCurrentFireMode()); WeaponJson->SetNumberField("ZoomState", UTPC->GetUTCharacter()->GetWeapon()->ZoomState); } else { WeaponJson->SetStringField("Name", "None"); } } // Insert PlayerState JsonReport TSharedRef<FJsonObject> PlayerStateJson(new FJsonObject()); PlayerJson->SetObjectField("State", PlayerStateJson); if (UTPC->UTPlayerState) { UTPC->UTPlayerState->MakeJsonReport(PlayerStateJson); } FJsonSerializer::Serialize(RootJson, Writer); WritePipe(Buffer); }
void AUTDomGameMode::SetEndGameFocus(AUTPlayerState* Winner) { AControlPoint* WinningBase = NULL; if (Winner != NULL) { // find control point owned by winning player for (uint8 n = 0; n < DomGameState->GameControlPoints.Num(); n++) { if (DomGameState->GameControlPoints[n]->ControllingTeam != NULL && DomGameState->GameControlPoints[n]->TeamNum == Winner->GetTeamNum() && DomGameState->GameControlPoints[n]->ActorIsNearMe(Winner)) { WinningBase = DomGameState->GameControlPoints[n]; break; } } if (WinningBase == NULL) { // find control point owned by winning player for (uint8 n = 0; n < DomGameState->GameControlPoints.Num(); n++) { if ((DomGameState->GameControlPoints[n]->ControllingPawn == Winner) && (DomGameState->GameControlPoints[n]->ControllingTeam != NULL) && (DomGameState->GameControlPoints[n]->TeamNum == Winner->GetTeamNum())) { WinningBase = DomGameState->GameControlPoints[n]; break; } } } // no winning player control point found, so find the first control point owned by winning team if (WinningBase == NULL) { for (uint8 i = 0; i < DomGameState->GameControlPoints.Num(); i++) { if ((DomGameState->GameControlPoints[i]->ControllingTeam != NULL) && (DomGameState->GameControlPoints[i]->TeamNum == Winner->GetTeamNum())) { WinningBase = DomGameState->GameControlPoints[i]; break; } } } } // If we don't have a winner, view 1st base if (WinningBase == NULL && DomGameState->GameControlPoints[0] != NULL) { WinningBase = DomGameState->GameControlPoints[0]; } if (WinningBase) { EndGameFocus = WinningBase; EndGameFocus->bAlwaysRelevant = true; } for (FConstControllerIterator Iterator = GetWorld()->GetControllerIterator(); Iterator; ++Iterator) { AUTPlayerController* Controller = Cast<AUTPlayerController>(*Iterator); if ((EndGameFocus != NULL) && Controller && Controller->UTPlayerState) { Controller->GameHasEnded(EndGameFocus, Controller->UTPlayerState->Team == Winner->Team); } } }