From 2c540c8d55e3f7981e9637a9c029f2893ff725eb Mon Sep 17 00:00:00 2001 From: WALL OF JUSTICE <-> Date: Thu, 31 Oct 2024 01:31:14 +1100 Subject: [PATCH] * compendium + game victory stats --- src/menu.cpp | 3 +++ src/playfab.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++ src/playfab.hpp | 2 ++ src/ui/MainMenu.cpp | 3 +++ 4 files changed, 66 insertions(+) diff --git a/src/menu.cpp b/src/menu.cpp index a51a402a5..03bc6aa5a 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -9638,6 +9638,9 @@ void doEndgame(bool saveHighscore, bool onServerDisconnect) { conductGameChallenges[CONDUCT_BOOTS_SPEED] = 1; } achievementObserver.updateGlobalStat(STEAM_GSTAT_GAMES_WON, clientnum); +#ifdef USE_PLAYFAB + playfabUser.gameEnd(); +#endif for ( int c = 0; c < MAXPLAYERS; ++c ) { diff --git a/src/playfab.cpp b/src/playfab.cpp index 5a9da898e..abecd6e5d 100644 --- a/src/playfab.cpp +++ b/src/playfab.cpp @@ -26,6 +26,64 @@ void PlayfabUser_t::OnEventsWrite(const PlayFab::EventsModels::WriteEventsRespon logInfo("Successfully stored events"); } +void PlayfabUser_t::compendiumResearch(std::string category, std::string section) +{ + if ( !bLoggedIn ) + { + return; + } + + PlayFab::EventsModels::WriteEventsRequest eventRequest; + PlayFab::EventsModels::EventContents eventContent; + eventContent.EventNamespace = "custom.game"; + eventContent.Name = "research"; + eventContent.Payload["category"] = category; + eventContent.Payload["section"] = section; + eventRequest.Events.push_back(eventContent); + PlayFab::PlayFabEventsAPI::WriteTelemetryEvents(eventRequest, OnEventsWrite, OnCloudScriptFailure); +} + +void PlayfabUser_t::gameEnd() +{ + if ( !bLoggedIn ) + { + return; + } + + if ( gameModeManager.getMode() != GameModeManager_t::GAME_MODE_DEFAULT ) + { + return; + } + PlayFab::EventsModels::WriteEventsRequest eventRequest; + PlayFab::EventsModels::EventContents eventContent; + eventContent.EventNamespace = "custom.game"; + eventContent.Name = "gameend"; + eventContent.Payload["class"] = client_classes[clientnum]; + eventContent.Payload["multiplayer"] = multiplayer; + eventContent.Payload["victory"] = victory; + int players = 1; + if ( multiplayer == SERVER || (multiplayer == SINGLE && splitscreen) ) + { + for ( int i = 1; i < MAXPLAYERS; ++i ) + { + if ( !client_disconnected[i] ) + { + ++players; + } + } + } + eventContent.Payload["numplayers"] = players; + eventContent.Payload["version"] = VERSION; + eventContent.Payload["splitscreen"] = (multiplayer == SINGLE && splitscreen) ? 1 : 0; + eventContent.Payload["race"] = stats[clientnum]->playerRace; + eventContent.Payload["appearance"] = stats[clientnum]->stat_appearance; + eventContent.Payload["sex"] = stats[clientnum]->sex; + eventContent.Payload["controller"] = inputs.hasController(clientnum) ? 1 : 0; + eventContent.Payload["theme"] = *cvar_disableHoliday ? 0 : 1; + eventRequest.Events.push_back(eventContent); + PlayFab::PlayFabEventsAPI::WriteTelemetryEvents(eventRequest, OnEventsWrite, OnCloudScriptFailure); +} + void PlayfabUser_t::gameBegin() { if ( !bLoggedIn ) diff --git a/src/playfab.hpp b/src/playfab.hpp index 6c233e2ff..e0b47f8d0 100644 --- a/src/playfab.hpp +++ b/src/playfab.hpp @@ -48,6 +48,8 @@ class PlayfabUser_t void getLeaderboardAroundMe(std::string lid); void getLeaderboardTop100Alternate(std::string lid); void gameBegin(); + void gameEnd(); + void compendiumResearch(std::string category, std::string section); void globalStat(int index, int player); struct PlayerCheckLeaderboardData_t diff --git a/src/ui/MainMenu.cpp b/src/ui/MainMenu.cpp index 37de314ab..54e19cd6b 100644 --- a/src/ui/MainMenu.cpp +++ b/src/ui/MainMenu.cpp @@ -39167,6 +39167,9 @@ namespace MainMenu { playSound(632 + local_rng.rand() % 2, 92); steamAchievement("BARONY_ACH_CURIOSITY"); +#ifdef USE_PLAYFAB + playfabUser.compendiumResearch(compendium_current, compendium_contents_current[compendium_current]); +#endif to_unlock->setText(""); auto* unlockStatus = compendium_current == "monsters" ? &Compendium_t::CompendiumMonsters_t::unlocks