public void UpdateData(TaskData data) { taskData = data; currentDialog = taskData.GetCurrentDialog(); scene = JsonManager.GetInstance().GetMapping <SceneData>("Scenes", taskData.BelongToSceneId); npc = JsonManager.GetInstance().GetMapping <NpcData>("Npcs", taskData.BelongToNpcId); areaNames = JsonManager.GetInstance().GetJson("AreaNames"); areaName = areaNames[scene.BelongToAreaName] != null ? areaNames[scene.BelongToAreaName]["Name"].ToString() : ""; EventTriggerListener.Get(ScoutBtn.gameObject).onClick = onClick; }
/// <summary> /// 检测任务对话状态(任务对话的进度在这里来更新, 每次验证任务对话类型,然后判断是否可以完成,如果可以完成则CurrentDialogIndex+1) /// </summary> /// <param name="taskId">Task identifier.</param> /// <param name="auto">If set to <c>true</c> auto.</param> /// <param name="selectedNo">If set to <c>true</c> selected no.</param> public void CheckTaskDialog(string taskId, bool auto = false, bool selectedNo = false) { TaskData data = getTask(taskId); if (data != null) { if (data.State == TaskStateType.Completed) { // db.CloseSqlConnection(); return; } string triggerNewBackTaskDataId = ""; TaskDialogType dialogType = data.GetCurrentDialog().Type; bool canModify = false; JArray pushData = new JArray(); TaskDialogData dialog = data.GetCurrentDialog(); data.State = TaskStateType.Accepted; if (data.GetCurrentDialogStatus() == TaskDialogStatusType.Initial) { if (dialogType == TaskDialogType.JustTalk || dialogType == TaskDialogType.Notice) { //交谈步骤和信息显示步骤直接变为已读状态 data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); } else { //其他状态的话需要等待下一个步骤提交时检测是否可以完成,所以先HoldOn data.SetCurrentDialogStatus(TaskDialogStatusType.HoldOn); bool loadEvents = false; //如果是动态战斗事件步骤需要在这里创建动态战斗事件 if (dialogType == TaskDialogType.EventFightWined) { // Debug.LogWarning("如果是动态战斗事件步骤需要在这里创建动态战斗事件"); //创建一个区域大地图的战斗事件 CreateNewEvent(SceneEventType.Battle, dialog.StringValue, UserModel.CurrentUserData.CurrentAreaSceneName); loadEvents = true; } //如果是区域大地图野外任务事件步骤需要在这里创建动态任务事件 if (dialogType == TaskDialogType.CreateTaskIsBindedWithEvent) { // Debug.LogWarning("如果是区域大地图野外任务事件步骤需要在这里创建动态任务事件"); //创建一个区域大地图的战斗事件 AddNewTask(dialog.StringValue); CreateNewEvent(SceneEventType.Task, dialog.StringValue, UserModel.CurrentUserData.CurrentAreaSceneName); loadEvents = true; } if (loadEvents) { //加载动态事件列表 Messenger.Broadcast <string>(NotifyTypes.GetActiveEventsInArea, UserModel.CurrentUserData.CurrentAreaSceneName); } } dialog = data.GetCurrentDialog(); pushData.Add(new JArray(dialog.Index.ToString(), dialog.Type, dialog.TalkMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; } else { RoleData hostRole; switch (dialogType) { case TaskDialogType.Choice: if (!auto) { triggerNewBackTaskDataId = selectedNo ? data.GetCurrentDialog().BackNoTaskDataId : data.GetCurrentDialog().BackYesTaskDataId; data.SetCurrentDialogStatus(selectedNo ? TaskDialogStatusType.ReadNo : TaskDialogStatusType.ReadYes); //输出步骤执行结果信息 pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, data.GetCurrentDialogStatus() == TaskDialogStatusType.ReadYes ? dialog.YesMsg : dialog.NoMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; } break; case TaskDialogType.ConvoyNpc: //暂时没考虑好怎么做护送npc任务 data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, dialog.YesMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; break; case TaskDialogType.FightWined: case TaskDialogType.EventFightWined: if (IsFightWined(dialog.StringValue)) { data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, dialog.YesMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; } break; case TaskDialogType.JustTalk: case TaskDialogType.Notice: canModify = true; break; case TaskDialogType.RecruitedThePartner: if (GetRoleDataByRoleId(dialog.StringValue) != null) { data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, dialog.YesMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; } break; case TaskDialogType.SendItem: if (CostItemFromBag(dialog.StringValue, dialog.IntValue)) { DbManager.Instance.UpdateUsedItemRecords(dialog.StringValue, dialog.IntValue); data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, dialog.YesMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; } break; case TaskDialogType.UsedTheBook: hostRole = GetHostRoleData(); if (hostRole != null) { for (int i = 0; i < hostRole.ResourceBookDataIds.Count; i++) { if (hostRole.ResourceBookDataIds[i] == dialog.StringValue) { data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, dialog.YesMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; break; } } } break; case TaskDialogType.UsedTheSkillOneTime: if (GetUsedTheSkillTimes(dialog.StringValue) > 0) { data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, dialog.YesMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; } break; case TaskDialogType.UsedTheWeapon: hostRole = GetHostRoleData(); if (hostRole.ResourceWeaponDataId == dialog.StringValue) { data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, dialog.YesMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; } break; case TaskDialogType.WeaponPowerPlusSuccessed: if (GetWeaponPowerPlusSuccessedTimes(dialog.IntValue) > 0) { data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, dialog.YesMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; } break; case TaskDialogType.SendResource: // if (CostResource((ResourceType)Enum.Parse(typeof(ResourceType), dialog.StringValue), dialog.IntValue)) { if (GetResourceNum((ResourceType)Enum.Parse(typeof(ResourceType), dialog.StringValue)) >= dialog.IntValue) { data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, dialog.YesMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; } break; case TaskDialogType.TheHour: if (FramePanelCtrl.CurrentTimeIndex == dialog.IntValue) { data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, dialog.YesMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; } break; case TaskDialogType.PushRoleToWinshop: PushNewRoleToWinShop(dialog.StringValue); data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, dialog.YesMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; break; case TaskDialogType.CreateTaskIsBindedWithEvent: if (IsTaskCompleted(dialog.StringValue)) { data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, dialog.YesMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; } break; default: break; } if (canModify && data.CheckCompleted()) { data.State = TaskStateType.Completed; } } TaskStateType currentState = data.State; if (canModify) { db = OpenDb(); //如果是可循环的任务这里需要置为可接受,否则置为已完成 if (data.State == TaskStateType.Completed && data.CanRepeat) { data.State = TaskStateType.CanAccept; for (int a = 0; a < data.ProgressData.Count; a++) { data.ProgressData[a] = (short)TaskDialogStatusType.Initial; } data.SetCurrentDialogIndex(0); } //update data db.ExecuteQuery("update TasksTable set ProgressData = '" + data.ProgressData.ToString() + "', CurrentDialogIndex = " + data.CurrentDialogIndex + ", State = " + ((int)data.State) + " where TaskId ='" + taskId + "' and BelongToRoleId = '" + currentRoleId + "'"); db.CloseSqlConnection(); int index = taskListData.FindIndex(item => item.Id == taskId); //update cache if (taskListData.Count > index) { taskListData[index] = data; } } //触发新任务 if (triggerNewBackTaskDataId != "" && triggerNewBackTaskDataId != "0") { AddNewTaskExceptType(triggerNewBackTaskDataId, TaskType.IsBindedWithEvent); //检测任务状态 checkAddedTasksStatus(); } if (currentState == TaskStateType.Completed) { //添加任务奖励物品 //查询背包是否已满 bool enoughBagSeat = false; // int hasNum = GetItemNumLeftInBag(); //还剩余的背包位子 // if (hasNum > 0) { // enoughBagSeat = true; // } //任务掉落的物品没有背包限制 List <DropData> drops = PushItemToBag(data.Rewards, true); if (drops.Count > 0) { Messenger.Broadcast <List <DropData> >(NotifyTypes.ShowDropsListPanel, drops); } //如果是就职任务则提示就职成功 if (data.IsInaugurationTask) { HostData = GetHostRoleData(); if (HostData.Occupation == OccupationType.None) { //加入门派 HostData.Occupation = data.InaugurationOccupation; HostData.Disposed(); db = OpenDb(); db.ExecuteQuery("update RolesTable set RoleData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(HostData)) + "' where Id = " + HostData.PrimaryKeyId); //判断兵器是否属于本门派 WeaponData currentWeapon = JsonManager.GetInstance().GetMapping <WeaponData>("Weapons", HostData.ResourceWeaponDataId); if (currentWeapon.Occupation != OccupationType.None && currentWeapon.Occupation != HostData.Occupation) { SqliteDataReader sqReader = db.ExecuteQuery("select * from WeaponsTable where BeUsingByRoleId = '" + currentRoleId + "' and BelongToRoleId ='" + currentRoleId + "'"); while (sqReader.Read()) { //将兵器先卸下 int dataId = sqReader.GetInt32(sqReader.GetOrdinal("Id")); db.ExecuteQuery("update WeaponsTable set BeUsingByRoleId = '' where Id = " + dataId); } } db.CloseSqlConnection(); //检查下是否有新兵器需要 CheckNewWeaponIdsOfWorkshop(UserModel.CurrentUserData.CurrentCitySceneId); Messenger.Broadcast(NotifyTypes.MakeCheckNewFlags); //判断城镇界面的新增提示 AlertCtrl.Show(string.Format("你已成功加入{0}!", Statics.GetOccupationName(HostData.Occupation))); } else { AlertCtrl.Show("你已是有门有派之人, 不可在此另行拜师!"); } } //任务完成后出发后续任务 addChildrenTasks(data.Id); //任务完成后移除区域大地图上的任务事件 RemoveTaskEvent(data.Id); } Messenger.Broadcast <JArray>(NotifyTypes.CheckTaskDialogEcho, pushData); if (data.GetCurrentDialogStatus() == TaskDialogStatusType.ReadNo || data.GetCurrentDialogStatus() == TaskDialogStatusType.ReadYes) { data.NextDialogIndex(); } } }
string getDialogDesc(TaskDialogData dialog) { string result = ""; if (dialog != null) { string noticeColor = "#F57729"; switch (dialog.Type) { case TaskDialogType.Choice: return(string.Format("目标:前往<color=\"" + noticeColor + "\">{0}</color>,<color=\"" + noticeColor + "\">{1}</color>的<color=\"" + noticeColor + "\">{2}</color>有困难需要你的帮助", areaName, scene.Name, npc.Name)); case TaskDialogType.JustTalk: case TaskDialogType.Notice: return(string.Format("目标:前往<color=\"" + noticeColor + "\">{0}</color>的<color=\"" + noticeColor + "\">{1}</color>找<color=\"" + noticeColor + "\">{2}</color>交谈", areaName, scene.Name, npc.Name)); default: return(""); case TaskDialogType.ConvoyNpc: string[] fen = dialog.StringValue.Split(new char[] { '_' }); return(string.Format("目标:护送<color=\"" + noticeColor + "\">{0}</color>到达<color=\"" + noticeColor + "\">{1}</color>({2})", JsonManager.GetInstance().GetMapping <NpcData>("Npcs", fen[0]).Name, fen[1], dialog.Completed ? "<color=\"#00FF00\">已到达</color>" : "<color=\"#FF0000\">未到达</color>") + (dialog.Completed ? string.Format(" (完成!{0}在{1}等你回复)", npc.Name, scene.Name) : "")); case TaskDialogType.FightWined: return(string.Format("目标:在战斗[<color=\"" + noticeColor + "\">{0}</color>]中获胜({1})", JsonManager.GetInstance().GetMapping <FightData>("Fights", dialog.StringValue).Name, dialog.Completed ? "<color=\"#00FF00\">已获胜</color>" : "<color=\"#FF0000\">未获胜</color>") + (dialog.Completed ? string.Format(" (<color=\"#00FF00\">完成!</color>{0}在{1}等你回复)", npc.Name, scene.Name) : "")); case TaskDialogType.EventFightWined: return(string.Format("目标:在野外战斗[<color=\"" + noticeColor + "\">{0}</color>]中获胜({1})", JsonManager.GetInstance().GetMapping <FightData>("Fights", dialog.StringValue).Name, dialog.Completed ? "<color=\"#00FF00\">已获胜</color>" : "<color=\"#FF0000\">未获胜</color>") + (dialog.Completed ? string.Format(" (<color=\"#00FF00\">完成!</color>{0}在{1}等你回复)", npc.Name, scene.Name) : "")); case TaskDialogType.RecruitedThePartner: RoleData role = JsonManager.GetInstance().GetMapping <RoleData>("RoleDatas", dialog.StringValue); return(string.Format("结识对象:<color=\"{0}\">{1}</color>\n目标: 在<color=\"" + noticeColor + "\">{2}</color>的酒馆里与<color=\"" + noticeColor + "\">{1}</color>结识", dialog.Completed ? "#00FF00" : "#FF0000", role.Name, JsonManager.GetInstance().GetMapping <SceneData>("Scenes", role.HometownCityId).Name) + (dialog.Completed ? string.Format(" (完成!{0}在{1}等你回复)", npc.Name, scene.Name) : "")); case TaskDialogType.SendItem: return(string.Format("需要物品:<color=\"{0}\">{1}</color>\n目标: 收集到{2}个<color=\"" + noticeColor + "\">{1}</color>", dialog.Completed ? "#00FF00" : "#FF0000", JsonManager.GetInstance().GetMapping <ItemData>("ItemDatas", dialog.StringValue).Name, dialog.IntValue) + (dialog.Completed ? string.Format(" (<color=\"#00FF00\">完成!</color>{0}在{1}等你回复)", npc.Name, scene.Name) : "")); case TaskDialogType.SendResource: return(string.Format("需要资源:<color=\"{0}\">{1}</color>\n目标: 收集到{2}个<color=\"" + noticeColor + "\">{1}</color>", dialog.Completed ? "#00FF00" : "#FF0000", Statics.GetResourceName((ResourceType)Enum.Parse(typeof(ResourceType), dialog.StringValue)), dialog.IntValue) + (dialog.Completed ? string.Format(" (<color=\"#00FF00\">完成!</color>{0}在{1}等你回复)", npc.Name, scene.Name) : "")); case TaskDialogType.UsedTheBook: return(string.Format("装备秘籍:<color=\"{0}\">{1}</color>\n目标: 将秘籍<color=\"" + noticeColor + "\">{1}</color>装备上", dialog.Completed ? "#00FF00" : "#FF0000", JsonManager.GetInstance().GetMapping <BookData>("Books", dialog.StringValue).Name) + (dialog.Completed ? string.Format(" (<color=\"#00FF00\">完成!</color>{0}在{1}等你回复)", npc.Name, scene.Name) : "")); case TaskDialogType.UsedTheSkillOneTime: return(string.Format("施展招式:<color=\"{0}\">{1}</color>\n目标: 将招式<color=\"" + noticeColor + "\">{1}</color>施展一次", dialog.Completed ? "#00FF00" : "#FF0000", JsonManager.GetInstance().GetMapping <SkillData>("Skills", dialog.StringValue).Name) + (dialog.Completed ? string.Format(" (<color=\"#00FF00\">完成!</color>{0}在{1}等你回复)", npc.Name, scene.Name) : "")); case TaskDialogType.UsedTheWeapon: return(string.Format("装备兵器:<color=\"{0}\">{1}</color>\n目标: 将兵器<color=\"" + noticeColor + "\">{1}</color>装备上", dialog.Completed ? "#00FF00" : "#FF0000", JsonManager.GetInstance().GetMapping <WeaponData>("Weapons", dialog.StringValue).Name) + (dialog.Completed ? string.Format(" (<color=\"#00FF00\">完成!</color>{0}在{1}等你回复)", npc.Name, scene.Name) : "")); case TaskDialogType.WeaponPowerPlusSuccessed: return(string.Format("目标:招式施展时爆发<color=\"{0}\">{1}倍伤害</color>", dialog.Completed ? "#00FF00" : "#FF0000", dialog.IntValue == 1 ? "1.25" : dialog.IntValue == 2 ? "1.5" : "2") + (dialog.Completed ? string.Format(" (<color=\"#00FF00\">完成!</color>{0}在{1}等你回复)", npc.Name, scene.Name) : "")); case TaskDialogType.TheHour: return(string.Format("目标:在<color=\"" + noticeColor + "\">{0}</color>时前往<color=\"" + noticeColor + "\">{1}</color>的<color=\"" + noticeColor + "\">{2}</color>找<color=\"" + noticeColor + "\">{3}</color>交谈({4})", Statics.GetTimeName(dialog.IntValue), areaName, scene.Name, npc.Name, dialog.Completed ? "<color=\"#00FF00\">时辰已到</color>" : "<color=\"#FF0000\">时辰未到</color>")); case TaskDialogType.PushRoleToWinshop: return(string.Format("目标:前往<color=\"" + noticeColor + "\">{0}</color>的<color=\"" + noticeColor + "\">{1}</color>找<color=\"" + noticeColor + "\">{2}</color>交谈后可以结识新的侠客", areaName, scene.Name, npc.Name)); case TaskDialogType.CreateTaskIsBindedWithEvent: return(string.Format("目标:前往<color=\"" + noticeColor + "\">{0}</color>野外区域寻找线索", areaName)); } } return(result); }