Exemplo n.º 1
0
 /// <summary>
 /// 添加一条新任务到可接取任务数据列表
 /// </summary>
 /// <param name="taskId">Task identifier.</param>
 public void AddNewTask(string taskId)
 {
     validTaskListData();
     if (getTask(taskId) == null)
     {
         db = OpenDb();
         TaskData taskData = JsonManager.GetInstance().GetMapping <TaskData>("Tasks", taskId);
         if (taskData.Id == taskId)
         {
             //添加任务数据时把任务步骤存档字段也进行初始化
             JArray progressDataList = new JArray();
             for (int i = 0; i < taskData.Dialogs.Count; i++)
             {
                 progressDataList.Add((short)TaskDialogStatusType.Initial);
             }
             db.ExecuteQuery("insert into TasksTable (TaskId, ProgressData, CurrentDialogIndex, State, BelongToRoleId) values('" + taskId + "', '" + progressDataList.ToString() + "', 0, 0, '" + currentRoleId + "')");
             //顺手把数据写入缓存
             taskData.State = TaskStateType.CanNotAccept;
             taskData.SetCurrentDialogIndex(0);
             taskData.ProgressData = progressDataList;
             taskData.MakeJsonToModel();
             taskListData.Add(taskData);
         }
         db.CloseSqlConnection();
     }
 }
Exemplo n.º 2
0
        /// <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();
                }
            }
        }