the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 107 lines 2.9 kB view raw
1#include "stdafx.h" 2 3#include "Durango\ServiceConfig\Events-XBLA.8-149E11AEEvents.h" 4 5#include "..\Minecraft.World\DurangoStats.h" 6 7#include "GameProgress.h" 8 9namespace WFC = Windows::Foundation::Collections; 10namespace MXSA = Microsoft::Xbox::Services::Achievements; 11namespace CC = concurrency; 12 13GameProgress *GameProgress::instance = NULL; 14 15void GameProgress::Flush(int iPad) 16{ 17 if (instance == NULL) 18 instance = new GameProgress(); 19 20 instance->updatePlayer(iPad); 21} 22 23void GameProgress::Tick() 24{ 25 if (instance == NULL) 26 instance = new GameProgress(); 27 28 long long currentTime = System::currentTimeMillis(); 29 if ( (currentTime - instance->m_lastUpdate) > (UPDATE_FREQUENCY / 4) ) 30 { 31 instance->updatePlayer(instance->m_nextPad); 32 instance->m_nextPad = ++instance->m_nextPad % MAX_LOCAL_PLAYERS; 33 instance->m_lastUpdate = currentTime; 34 } 35} 36 37GameProgress::GameProgress() 38{ 39 m_nextPad = 0; 40 m_lastUpdate = 0; 41} 42 43void GameProgress::updatePlayer(int iPad) 44{ 45 if ( ProfileManager.IsGuest(iPad) || !ProfileManager.IsSignedInLive(iPad) ) return; 46 47 PlayerUID uid; 48 ProfileManager.GetXUID(iPad, &uid, true); 49 50 WXS::User^ user = ProfileManager.GetUser(iPad); 51 52 if (user == nullptr) return; 53 54 MXS::XboxLiveContext ^xlc = ref new MXS::XboxLiveContext(user); 55 56 // Get these while they are still valid. 57 LPCGUID playerSession = DurangoStats::getPlayerSession(); 58 59 CC::create_task( 60 xlc->AchievementService->GetAchievementsForTitleIdAsync( 61 ref new Platform::String(uid.toString().c_str()), // Xuid 62 0x149E11AE, // TitleId 63 MXSA::AchievementType::Persistent, // Use regular achievements (not challenges) 64 false, // Unlocked only 65 MXSA::AchievementOrderBy::UnlockTime, // Order (we don't really care) 66 0, // skipItems (start index) 67 200 // MaxItems 68 ) 69 ).then( [this,iPad,uid,playerSession] (CC::task<MXSA::AchievementsResult^> resultTask) 70 { 71 try 72 { 73 int achievementsUnlocked = 0; 74 75 MXSA::AchievementsResult^ result = resultTask.get(); 76 if(result) 77 { 78 for (unsigned int i = 0, iMax = result->Items->Size; i < iMax; i++) 79 { 80 MXSA::Achievement^ ach = result->Items->GetAt(i); 81 if (ach->ProgressState == MXSA::AchievementProgressState::Achieved) 82 achievementsUnlocked++; 83 } 84 85 float gameprogress; 86 if (EventWriteGameProgress( 87 uid.toString().c_str(), 88 playerSession, 89 gameprogress = calcGameProgress(achievementsUnlocked) ) 90 == 0) 91 { 92 app.DebugPrintf("<%ls> GameProgress(%.1f)\n", uid.toString().c_str(), gameprogress); 93 } 94 } 95 } 96 catch (Platform::Exception ^ex) 97 { 98 app.DebugPrintf("GameProgress:: Error, couldn't contact the achievments service (?): %ls", ex->Message->Data()); 99 } 100 }); 101 102} 103 104float GameProgress::calcGameProgress(int achievementsUnlocked) 105{ 106 return (float) achievementsUnlocked / 0.60f; 107}