GameDataArgs ReadGameData(DBQuery query) { GameDataArgs gameData = new GameDataArgs(); object[] row = query.Rows[0]; gameData.TowerFloors = new int[6]; for (int i = 0; i < gameData.TowerFloors.Length; i++) { gameData.TowerFloors[i] = (int)row[i + 1]; } gameData.Level = (int)row[7]; gameData.Exp = (int)row[8]; gameData.Tutorial = (ulong)row[9]; return(gameData); }
void GameData_Fetched_Handler(Task t) { HTask task = (HTask)t; if (task.Query.Rows.Count <= 0) { // game data doesnt exist for this user yet string sql = string.Format("INSERT INTO game_data SET account_id={0},tower_floor_0=1;", task.Client.AccountId); t.Type = (int)HTask.HTaskType.GameData_Fetch; AddDBQuery(sql, t); // Also give this user 100 coins SpendCoinsArgs args = new SpendCoinsArgs(); args.Coins = -100; args.SpendOn = 0; AddTask(new HTask(HTask.HTaskType.SpendCoins, task.Client, args)); } else { GameDataArgs gameData = ReadGameData(task.Query); task.Client.SendGameData(gameData); } }
private void _client_OnGameDataResponse(object sender, GameDataArgs e) { _gi.GameData = e; GameInfoValidator.Instance.Save(_gi); _waitingForResponse = false; }
void PuzzleComplete_Validate_Handler(Task t) { HTask task = (HTask)t; GameDataArgs gameData = ReadGameData(t.Query); object[] args = (object[])t.Args; PuzzleCompleteArgs pca = (PuzzleCompleteArgs)args[0]; AuthStringManager.AuthAccountInfo aai = (AuthStringManager.AuthAccountInfo)args[1]; if (pca.TowerIndex < 0 || pca.TowerIndex >= gameData.TowerFloors.Length) { // Invalid tower number RecordError(task.Client.AccountId, "Invalid floor number submitted: " + pca.TowerIndex); } else { if (pca.FloorNumber > gameData.TowerFloors[pca.TowerIndex]) { // Trying to complete a puzzle further ahead than the current progress?! RecordError(task.Client.AccountId, string.Format("Out of order completion - got:{0}, expected{1}", pca.FloorNumber, gameData.TowerFloors[pca.TowerIndex])); } else { // This is the expected puzzle or a repeat of a previous puzzle // Move to the next puzzle on this floor if (pca.FloorNumber == gameData.TowerFloors[pca.TowerIndex]) { gameData.TowerFloors[pca.TowerIndex]++; } VipDataArgs vda = VipData.Create(aai.Vip); float expBonus = pca.NoExpBonus ? 1 : vda.ExpBonus; // Level up? double baseExp = Balance.BaseExp(pca.TowerIndex); double bonusExp = Balance.BonusExp(pca.TowerIndex, pca.CompletionTime); double total = (baseExp + bonusExp) * expBonus; int exp = (int)total; gameData.Exp += exp; int expForNextLevel = Balance.ExpForNextLevel(gameData.Level); while (gameData.Exp >= expForNextLevel) { gameData.Level++; gameData.Exp -= expForNextLevel; expForNextLevel = Balance.ExpForNextLevel(gameData.Level); } // Unlock next tower? if (pca.TowerIndex < (gameData.TowerFloors.Length - 1) && gameData.TowerFloors[pca.TowerIndex + 1] == 0 && gameData.Level >= Balance.UnlockThreshold(pca.TowerIndex)) { gameData.TowerFloors[pca.TowerIndex + 1] = 1; } // Save changes string sql = string.Format("UPDATE game_data SET tower0={0}, tower1={1}, tower2={2}, tower3={3}, tower4={4}, tower5={5}, level={6}, exp={7} WHERE account_id={8};", gameData.TowerFloors[0], gameData.TowerFloors[1], gameData.TowerFloors[2], gameData.TowerFloors[3], gameData.TowerFloors[4], gameData.TowerFloors[5], gameData.Level, gameData.Exp, task.Client.AccountId); AddDBQuery(sql, null, false); task.Client.SendGameData(gameData); // Store this completion record sql = string.Format("SELECT * FROM floor_records WHERE account_id={0} AND tower={1} AND floor={2};", task.Client.AccountId, pca.TowerIndex, pca.FloorNumber); task.Type = (int)HTask.HTaskType.FloorRecord_Process; AddDBQuery(sql, task); } } }