Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* compendium + game victory stats #861

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading