Skip to content

Commit

Permalink
Merge pull request #861 from WALLOFJUSTICE/dev-23-q3-2
Browse files Browse the repository at this point in the history
* compendium + game victory stats
  • Loading branch information
WALLOFJUSTICE authored Oct 30, 2024
2 parents f511a6c + 2c540c8 commit 22672a9
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
58 changes: 58 additions & 0 deletions src/playfab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
2 changes: 2 additions & 0 deletions src/playfab.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/ui/MainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 22672a9

Please sign in to comment.