protected override async void Run(Session session, C2G_Chengjiu message, Action <G2C_Chengjiu> reply) { G2C_Chengjiu response = new G2C_Chengjiu(); try { List <TaskInfo> taskInfoList = new List <TaskInfo>(); ConfigComponent configCom = Game.Scene.GetComponent <ConfigComponent>(); DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); List <ChengjiuInfo> chengjiuInfoList = await proxyComponent.QueryJson <ChengjiuInfo>($"{{UId:{message.Uid}}}"); if (chengjiuInfoList.Count < configCom.GetAll(typeof(ChengjiuConfig)).Length) { foreach (ChengjiuConfig config in configCom.GetAll(typeof(ChengjiuConfig))) { List <ChengjiuInfo> infos = await proxyComponent.QueryJson <ChengjiuInfo> ($"{{UId:{message.Uid},TaskId:{ config.Id}}}"); if (infos.Count <= 0) { ChengjiuInfo info = ComponentFactory.CreateWithId <ChengjiuInfo>(IdGenerater.GenerateId()); info.UId = message.Uid; info.Name = config.Name; info.TaskId = (int)config.Id; info.Target = config.Target; info.Reward = config.Reward; info.Desc = config.Desc; info.CurProgress = 0; await proxyComponent.Save(info); } } } chengjiuInfoList = await proxyComponent.QueryJson <ChengjiuInfo>($"{{UId:{message.Uid}}}"); for (int i = 0; i < chengjiuInfoList.Count; ++i) { TaskInfo taskInfo = new TaskInfo(); ChengjiuInfo chengjiu = chengjiuInfoList[i]; taskInfo.Id = chengjiu.TaskId; taskInfo.TaskName = chengjiu.Name; taskInfo.Desc = chengjiu.Desc; taskInfo.Reward = chengjiu.Reward; taskInfo.IsComplete = chengjiu.IsComplete; taskInfo.IsGet = chengjiu.IsGet; taskInfo.Progress = chengjiu.CurProgress; taskInfo.Target = chengjiu.Target; taskInfoList.Add(taskInfo); } response.ChengjiuList = taskInfoList; reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
protected override async void Run(Session session, C2G_UpdateChengjiu message, Action <G2C_UpdateChengjiu> reply) { G2C_UpdateChengjiu response = new G2C_UpdateChengjiu(); try { DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); TaskInfo taskInfo = new TaskInfo(); response.TaskPrg = new TaskInfo(); ChengjiuInfo progress = new ChengjiuInfo(); List <ChengjiuInfo> chengjiuInfoList = await proxyComponent.QueryJson <ChengjiuInfo>($"{{UId:{message.UId},TaskId:{message.TaskPrg.Id}}}"); if (chengjiuInfoList.Count > 0) { for (int i = 0; i < chengjiuInfoList.Count; ++i) { progress = chengjiuInfoList[i]; progress.TaskId = message.TaskPrg.Id; if (message.TaskPrg.IsGet) { progress.IsGet = true; } else { ++progress.CurProgress; if (progress.CurProgress == progress.Target) { progress.IsComplete = true; } else { progress.IsComplete = false; } } await proxyComponent.Save(progress); } taskInfo.Id = progress.TaskId; taskInfo.IsGet = progress.IsGet; taskInfo.IsComplete = progress.IsComplete; taskInfo.Progress = progress.CurProgress; response.TaskPrg = taskInfo; } else { response.Message = "不存在该任务ID"; response.TaskPrg = null; } reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
/// <summary> /// 更新成就 /// </summary> /// <param name="UId"></param> /// <param name="taskId"></param> /// <param name="progress"></param> public static async Task UpdateChengjiu(long UId, int taskId, int progress) { DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); List <ChengjiuInfo> chengjiuInfoList = await proxyComponent.QueryJson <ChengjiuInfo>($"{{UId:{UId},TaskId:{taskId}}}"); // Log.Debug("UId:" + UId + " " + "更新成就" + taskId); // Log.Debug("用户:" + UId + "成就" + "taskId" + JsonHelper.ToJson(chengjiuInfoList)); if (chengjiuInfoList.Count <= 0) { // Log.Debug("成就写入数据库"); ChengjiuInfo info = ComponentFactory.CreateWithId <ChengjiuInfo>(IdGenerater.GenerateId()); ChengjiuConfig config = ConfigHelp.Get <ChengjiuConfig>(taskId); info.IsGet = false; info.UId = UId; if (config != null) { info.Name = config.Name; info.TaskId = (int)config.Id; info.IsComplete = false; info.Target = config.Target; info.Reward = config.Reward; info.Desc = config.Desc; info.CurProgress = 0; } else { Log.Warning("config:" + taskId + "数据为空"); } await proxyComponent.Save(info); chengjiuInfoList = await proxyComponent.QueryJson <ChengjiuInfo>($"{{UId:{UId},TaskId:{taskId}}}"); //Log.Debug("用户:" + UId + "成就" + "taskId" + JsonHelper.ToJson(chengjiuInfoList)); } if (chengjiuInfoList.Count > 0) { //Log.Debug("增加成就"); chengjiuInfoList[0].CurProgress += progress; if (chengjiuInfoList[0].CurProgress >= chengjiuInfoList[0].Target) { chengjiuInfoList[0].IsComplete = true; } else { chengjiuInfoList[0].IsComplete = false; } await proxyComponent.Save(chengjiuInfoList[0]); } }