#include "LocationGameState.h" #include "game_server/InternalGameServer.h" #include #include #include namespace { int fail(const char* message) { std::cerr << message << '\n'; return EXIT_FAILURE; } } // namespace int main() { const std::filesystem::path repositoryRoot = std::filesystem::path(__FILE__).parent_path().parent_path().parent_path(); std::filesystem::current_path(repositoryRoot); FRG::LocationDefinition definition; definition.config.id = "test_location"; FRG::NpcData npc; npc.id = "npc"; npc.name = "Test NPC"; npc.hp = 75.f; definition.npcs.push_back(npc); FRG::InteractiveObjectData object; object.id = "object"; object.base.name = "Test Object"; object.base.meshPath = "unused.mesh"; object.isActive = true; definition.interactiveObjects.push_back(object); FRG::TriggerZoneDefinition trigger; trigger.id = "trigger"; trigger.enabled = true; definition.triggerZones.push_back(trigger); FRG::TeleportDefinition teleport; teleport.id = "teleport"; teleport.active = false; definition.teleports.push_back(teleport); FRG::LocationGameState state; if (!state.setup(definition, {})) return fail("First setup must initialize runtime fields"); if (state.npcs.size() != 1 || state.interactiveObjects.size() != 1) return fail("Definitions were not applied"); state.npcs.at("npc")->hp = 12.f; state.interactiveObjects.at("object")->isActive = false; state.triggerZones.at("trigger").enabled = false; state.teleportZones.at("teleport") = true; state.hasPersistentState = true; if (state.setup(definition, {})) return fail("Persistent setup must not reinitialize runtime fields"); if (state.npcs.at("npc")->hp != 12.f || state.interactiveObjects.at("object")->isActive || state.triggerZones.at("trigger").enabled || !state.teleportZones.at("teleport")) { return fail("Repeated setup did not preserve runtime state"); } FRG::PlayerStateMap noPlayers; state.update(50, noPlayers, false); FRG::CampaignConfig battleZone; battleZone.id = "battle_zone"; battleZone.questsPath = "resources/config/quests_battle_zone.json"; FRG::InternalGameServer server; server.startCampaign(battleZone, {}, false, true); const auto snapshot = server.snapshot(); const auto bot = snapshot->players.find("battle_zone_test_bot"); if (bot == snapshot->players.end()) return fail("Battle Zone test bot was not created"); const auto stand = static_cast(FRG::AnimationState::STAND); const auto walk = static_cast(FRG::AnimationState::WALK); if (bot->second.state.animationFrameCounts[stand] <= 1 || bot->second.state.animationFrameCounts[walk] <= 1) { return fail("Battle Zone test bot animation metadata was not loaded"); } FRG::InternalGameServer networkServer; networkServer.startCampaign(battleZone, {}, true, false); const auto networkSnapshot = networkServer.snapshot(); if (networkSnapshot->players.count("player") != 1) return fail("Network campaign shared player was not created"); if (networkSnapshot->players.count("battle_zone_test_bot") != 0) return fail("Network campaign unexpectedly created the test bot"); return EXIT_SUCCESS; }