/// <summary> /// Làm mới danh sách nhiệm vụ. /// </summary> public static async Task <TaskBoard> RefreshTaskBoardAsync(this IPacketWriter writer) { var packet = await writer.SendCommandAsync(44301); if (packet == null) { return(null); } return(TaskBoard.Parse(JToken.Parse(packet.Message))); }
private async Task <TaskResult> Process(TaskBoard taskBoard) { Debug.Assert(processing); var tasks = await RefreshTaskDetails(taskBoard); if (tasks == null) { return(TaskResult.LostConnection); } return(await Process(taskBoard, tasks)); }
public async Task <List <TaskDetail> > RefreshTaskDetails(TaskBoard board) { var taskDetails = new List <TaskDetail>(); foreach (var task in board.Tasks) { var detail = await Client.RefreshTaskAsync(task.Id); if (detail == null) { return(null); } taskDetails.Add(detail); } return(taskDetails); }
public static TaskBoard Parse(JToken token) { var result = new TaskBoard(); result.DoneNum = (int)token["donenum"]; result.MaxDoneNum = (int)token["maxdonenum"]; var tasks = new List <TaskInfo>(); var taskbasedto = token["taskbasedto"]; foreach (var subToken in taskbasedto) { tasks.Add(TaskInfo.Parse(subToken)); } result.Tasks = tasks; return(result); }
private async Task <TaskResult> Process(TaskBoard taskBoard, List <TaskDetail> tasks) { Debug.Assert(processing); var market = await Client.RefreshMarketAsync(); if (market == null) { return(TaskResult.LostConnection); } var impose = await Client.RefreshImposeAsync(); if (impose == null) { return(TaskResult.LostConnection); } const int MaxWeaponCount = 20; var upgrade = await Client.RefreshUpgradeAsync(1, 0, MaxWeaponCount); if (upgrade == null) { return(TaskResult.LostConnection); } var packet = await Client.SendCommandAsync(41100, "1"); if (packet == null) { return(TaskResult.LostConnection); } var barracks = Barracks.Parse(JToken.Parse(packet.Message)); var helpers = new Dictionary <TaskType, ITaskHelper>(); // FIXME. //helpers.Add(TaskType.Food, new FoodTaskHelper(Client)); //helpers.Add(TaskType.Improve, new ImproveTaskHelper(packetWriter, infoModel, barracks)); //helpers.Add(TaskType.Impose, new ImposeTaskHelper(packetWriter, infoModel, impose)); //helpers.Add(TaskType.AttackNpc, new AttackNpcTaskHelper(packetWriter, mcuModel)); //helpers.Add(TaskType.Upgrade, new UpgradeTaskHelper(packetWriter, infoModel, upgrade)); return(await Process(taskBoard, tasks, helpers)); }
/// <summary> /// Kiểm tra xem có nhiệm vụ nào hoàn thành chưa? /// </summary> /// <param name="taskBoard">Danh sách nhiệm vụ.</param> private async Task <bool> EnsureNoCompletedTask(TaskBoard taskBoard) { Debug.Assert(processing); foreach (var task in taskBoard.Tasks) { if (task.State == TaskState.Completed) { // Hoàn thành nhiệm vụ. var packet = await Client.CompleteTaskAsync(task.Id); if (packet == null) { return(false); } Client.GetComponent <ISystemLog>().Log("[NVHN]", String.Format("Hoàn thành nhiệm vụ ID {0}", task.Id)); return(true); } } return(false); }
private async Task <TaskResult> Process(TaskBoard taskBoard, List <TaskDetail> tasks, Dictionary <TaskType, ITaskHelper> helpers) { Debug.Assert(processing); Debug.Assert(taskBoard.Tasks.Count == tasks.Count); var dailyTasks = new List <DailyTaskWrapper>(); for (int i = 0; i < tasks.Count; ++i) { var detail = tasks[i]; var type = detail.Type; if (!helpers.ContainsKey(type)) { continue; } var info = taskBoard.Tasks[i]; var helper = helpers[type]; dailyTasks.Add(new DailyTaskWrapper(taskBoard.Tasks[i], tasks[i], helper)); } return(await Process(dailyTasks)); }
/// <summary> /// Kiểm tra xem có nhận nhiều nhiệm vụ một lúc không? /// </summary> private async Task <bool> EnsureNoMultipleAcceptedTask(TaskBoard taskBoard) { Debug.Assert(processing); var acceptedTasks = taskBoard.Tasks.Where(item => item.State == TaskState.Received).ToList(); if (acceptedTasks.Count <= 1) { return(false); } // Huỷ hết. Client.GetComponent <ISystemLog>().Log("[NVHN]", "Đang nhận nhiều nhiệm vụ, huỷ tất cả!"); foreach (var task in acceptedTasks) { var packet = await Client.CancelTaskAsync(task.Id); if (packet == null) { break; } } return(true); }