/// <summary> /// 记录玩家数据 /// </summary> /// <param name="userId"></param> /// <param name="totalSeconds"></param> /// <returns></returns> public static async Task RecordGamerInfo(long userId, int totalSeconds) { DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); ConfigComponent configComponent = Game.Scene.GetComponent <ConfigComponent>(); List <GamerInfoDB> gamerInfos = await proxyComponent.QueryJson <GamerInfoDB>($"{{UId:{userId}}}"); GamerInfoDB gamerInfo; if (gamerInfos.Count == 0) { gamerInfo = ComponentFactory.CreateWithId <GamerInfoDB>(IdGenerater.GenerateId()); } else { gamerInfo = gamerInfos[0]; } gamerInfo.UId = userId; gamerInfo.DailyOnlineTime += totalSeconds; gamerInfo.TotalOnlineTime += totalSeconds; TreasureConfig treasureConfig = configComponent.Get(typeof(TreasureConfig), ++gamerInfo.DailyTreasureCount) as TreasureConfig; // Log.Debug(gamerInfo.DailyTreasureCount + ""); // Log.Debug(JsonHelper.ToJson(treasureConfig)); if (gamerInfo.DailyOnlineTime > treasureConfig?.TotalTime) { gamerInfo.DailyOnlineTime = treasureConfig.TotalTime; } --gamerInfo.DailyTreasureCount; await proxyComponent.Save(gamerInfo); //记录玩家在线时长 await DBCommonUtil.UpdateChengjiu(userId, 107, totalSeconds); await DBCommonUtil.UpdateChengjiu(userId, 108, totalSeconds); await DBCommonUtil.UpdateChengjiu(userId, 109, totalSeconds); }
private static async void UpdateTask(Gamer gamer, int amount) { // 105 赚钱高手 当日累计赢取10000金币 10000 10000 await DBCommonUtil.UpdateTask(gamer.UserID, 105, amount); // 110 小试身手 单局赢取10000金币满 100局 if (amount >= 10000) { await DBCommonUtil.UpdateChengjiu(gamer.UserID, 110, 1); } // 111 来者不拒 单局赢取100万金币满 100局 if (amount >= 1000000) { await DBCommonUtil.UpdateChengjiu(gamer.UserID, 111, 1); } // 112 富豪克星 单局赢取一亿金币满 100局 if (amount >= 100000000) { await DBCommonUtil.UpdateChengjiu(gamer.UserID, 112, 1); } }
private static async Task UpdateChengjiu(Room room) { // Log.Debug("更新成就:房间ID为:" + room.Id); foreach (var gamer in room.GetAll()) { if (gamer == null) { Log.Error("更新成就的时候game为null"); continue; } //胜利 if (gamer.UserID == room.huPaiUid) { // Log.Debug("成就胜利"); //赢得10局游戏 await DBCommonUtil.UpdateChengjiu(gamer.UserID, 104, 1); //赢得100局游戏 await DBCommonUtil.UpdateChengjiu(gamer.UserID, 105, 1); //赢得1000局游戏 await DBCommonUtil.UpdateChengjiu(gamer.UserID, 106, 1); } //新手上路 完后10局游戏 await DBCommonUtil.UpdateChengjiu(gamer.UserID, 101, 1); // Log.Debug("不论输赢都会加一" + gamer.UserID + "任务" + 101); //已有小成 完成100局游戏 await DBCommonUtil.UpdateChengjiu(gamer.UserID, 102, 1); // Log.Debug("不论输赢都会加一" + gamer.UserID + "任务" + 102); //完成1000局游戏 await DBCommonUtil.UpdateChengjiu(gamer.UserID, 103, 1); // Log.Debug("不论输赢都会加一" + gamer.UserID + "任务" + 103); } }