- started adding logic to write out local player stats when not running from steam
This commit is contained in:
parent
36af9f3d9f
commit
e573ec8690
|
@ -5175,6 +5175,9 @@ void Game::DumpCRCWorldLogIfRequired(string fileSuffix) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveStatsToSteam(Game* game, Stats& endStats) {
|
void saveStatsToSteam(Game* game, Stats& endStats) {
|
||||||
|
|
||||||
|
const double MIN_PLAY_TIME_MINUTES = 10.0;
|
||||||
|
|
||||||
Steam* steamInstance = CacheManager::getCachedItem<Steam*>(GameConstants::steamCacheInstanceKey);
|
Steam* steamInstance = CacheManager::getCachedItem<Steam*>(GameConstants::steamCacheInstanceKey);
|
||||||
if (steamInstance != NULL) {
|
if (steamInstance != NULL) {
|
||||||
printf("\nSTEAM detected, writing out end game stats for player!\n");
|
printf("\nSTEAM detected, writing out end game stats for player!\n");
|
||||||
|
@ -5237,12 +5240,15 @@ void saveStatsToSteam(Game* game, Stats& endStats) {
|
||||||
if (factionIndex == game->getWorld()->getThisFactionIndex()) {
|
if (factionIndex == game->getWorld()->getThisFactionIndex()) {
|
||||||
//printf("\nWriting out game stats for Faction Index: %d won status: %d\n",factionIndex,endStats.getVictory(factionIndex));
|
//printf("\nWriting out game stats for Faction Index: %d won status: %d\n",factionIndex,endStats.getVictory(factionIndex));
|
||||||
if (endStats.getVictory(factionIndex)) {
|
if (endStats.getVictory(factionIndex)) {
|
||||||
if(steamInstance->isUnlocked(EnumParser<SteamAchievementName>::getString(ACH_WIN_ONE_GAME).c_str()) == false) {
|
double elapsedGameMinutes = (game->getWorld()->getStats()->getFramesToCalculatePlaytime() / GameConstants::updateFps / 60.0);
|
||||||
steamInstance->unlock(EnumParser<SteamAchievementName>::getString(ACH_WIN_ONE_GAME).c_str());
|
if(elapsedGameMinutes >= MIN_PLAY_TIME_MINUTES) {
|
||||||
}
|
if(steamInstance->isUnlocked(EnumParser<SteamAchievementName>::getString(ACH_WIN_ONE_GAME).c_str()) == false) {
|
||||||
if (NetworkManager::getInstance().isNetworkGame()) {
|
steamInstance->unlock(EnumParser<SteamAchievementName>::getString(ACH_WIN_ONE_GAME).c_str());
|
||||||
if(steamInstance->isUnlocked(EnumParser<SteamAchievementName>::getString(ACH_WIN_ONE_GAME_ONLINE).c_str()) == false) {
|
}
|
||||||
steamInstance->unlock(EnumParser<SteamAchievementName>::getString(ACH_WIN_ONE_GAME_ONLINE).c_str());
|
if (NetworkManager::getInstance().isNetworkGame()) {
|
||||||
|
if(steamInstance->isUnlocked(EnumParser<SteamAchievementName>::getString(ACH_WIN_ONE_GAME_ONLINE).c_str()) == false) {
|
||||||
|
steamInstance->unlock(EnumParser<SteamAchievementName>::getString(ACH_WIN_ONE_GAME_ONLINE).c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5254,6 +5260,56 @@ void saveStatsToSteam(Game* game, Stats& endStats) {
|
||||||
//printf("\nSTEAM Refresh Stats!\n");
|
//printf("\nSTEAM Refresh Stats!\n");
|
||||||
steamInstance->requestRefreshStats();
|
steamInstance->requestRefreshStats();
|
||||||
}
|
}
|
||||||
|
// Local Player stats for now just write out to player-stats.ini
|
||||||
|
// We'll clean this up to use an interface that both steam and lcoal comply with so the 'update' logic
|
||||||
|
// doesn't need to be duplicated.
|
||||||
|
else {
|
||||||
|
printf("\n**STEAM NOT detected, writing out NON STEAM end game stats for player!\n");
|
||||||
|
string saveFilePlayerLocalStats = "player-stats.ini";
|
||||||
|
if(getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) != "") {
|
||||||
|
saveFilePlayerLocalStats = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) + saveFilePlayerLocalStats;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
string userData = Config::getInstance().getString("UserData_Root","");
|
||||||
|
if(userData != "") {
|
||||||
|
endPathWithSlash(userData);
|
||||||
|
}
|
||||||
|
saveFilePlayerLocalStats = userData + saveFilePlayerLocalStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
Properties playerLocalStats;
|
||||||
|
if(fileExists(saveFilePlayerLocalStats)) {
|
||||||
|
playerLocalStats.load(saveFilePlayerLocalStats);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write out achievements here
|
||||||
|
for (int factionIndex = 0;
|
||||||
|
factionIndex < game->getWorld()->getFactionCount(); ++factionIndex) {
|
||||||
|
if (factionIndex == game->getWorld()->getThisFactionIndex()) {
|
||||||
|
//printf("\nWriting out game stats for Faction Index: %d won status: %d\n",factionIndex,endStats.getVictory(factionIndex));
|
||||||
|
if (endStats.getVictory(factionIndex)) {
|
||||||
|
double elapsedGameMinutes = (game->getWorld()->getStats()->getFramesToCalculatePlaytime() / GameConstants::updateFps / 60.0);
|
||||||
|
if(elapsedGameMinutes >= MIN_PLAY_TIME_MINUTES) {
|
||||||
|
if(playerLocalStats.getBool(EnumParser<SteamAchievementName>::getString(ACH_WIN_ONE_GAME).c_str()) == false) {
|
||||||
|
playerLocalStats.setBool(EnumParser<SteamAchievementName>::getString(ACH_WIN_ONE_GAME).c_str(),true);
|
||||||
|
}
|
||||||
|
if (NetworkManager::getInstance().isNetworkGame()) {
|
||||||
|
if(playerLocalStats.getBool(EnumParser<SteamAchievementName>::getString(ACH_WIN_ONE_GAME_ONLINE).c_str()) == false) {
|
||||||
|
playerLocalStats.setBool(EnumParser<SteamAchievementName>::getString(ACH_WIN_ONE_GAME_ONLINE).c_str(),true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//printf("\nPlayer won the game with at least 10 minutes of play: %f!\n",elapsedGameMinutes);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//printf("\nPlayer won the game BUT NOT with at least 10 minutes of play: %f!\n",elapsedGameMinutes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
playerLocalStats.save(saveFilePlayerLocalStats);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::exitGameState(Program *program, Stats &endStats) {
|
void Game::exitGameState(Program *program, Stats &endStats) {
|
||||||
|
|
Loading…
Reference in New Issue