コード例 #1
0
        /// <summary>
        /// 创建任务
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="taskId">任务配置ID</param>
        /// <param name="triggerModeList">任务触发条件参数</param>
        /// <param name="completedModeList">任务完成条件参数</param>
        /// <param name="rewardModeList">任务奖励条件参数</param>
        /// <param name="taskType"></param>
        /// <returns></returns>
        public T CreateTask <T>(long taskId, List <TaskCreaterParams> triggerModeList, List <TaskCreaterParams> completedModeList, List <TaskCreaterParams> rewardModeList, int taskType = 1) where T : TaskBase
        {
            Type taskImplType;

            if (this.m_taskImplDict.TryGetValue(taskType, out taskImplType))
            {
                T taskImpl = Activator.CreateInstance(taskImplType, taskId) as T;

                for (int i = 0; i < triggerModeList.Count; ++i)
                {
                    TaskTriggerMode triggerMode = (TaskTriggerMode)triggerModeList[i].Condition;

                    Type triggerImplType;
                    if (this.m_taskTriggerConditionDict.TryGetValue(triggerMode, out triggerImplType))
                    {
                        TaskTriggerCondition triggerImpl = Activator.CreateInstance(triggerImplType, triggerModeList[i].Data) as TaskTriggerCondition;

                        taskImpl.AddTaskTriggerCondition(triggerImpl);
                    }
                    else
                    {
                        throw new Exception("trigger mode :" + triggerMode + " not implement");
                    }
                }

                for (int i = 0; i < completedModeList.Count; ++i)
                {
                    TaskCompleteMode completeMode = (TaskCompleteMode)completedModeList[i].Condition;

                    Type triggerCompleteImplType;
                    if (this.m_taskCompleteDict.TryGetValue(completeMode, out triggerCompleteImplType))
                    {
                        TaskCompleteCondition completeTaskConditionImpl = Activator.CreateInstance(triggerCompleteImplType, completedModeList[i].Data) as TaskCompleteCondition;

                        taskImpl.AddTaskCompleteCondition(completeTaskConditionImpl);
                    }
                    else
                    {
                        throw new Exception("completed mode :" + completeMode + " not implement");
                    }
                }

                for (int i = 0; i < rewardModeList.Count; ++i)
                {
                    TaskRewardMode rewardMode = (TaskRewardMode)rewardModeList[i].Condition;

                    Type rewardImpl;
                    if (this.m_taskRewardDict.TryGetValue(rewardMode, out rewardImpl))
                    {
                        TaskRewardBase taskRewardImpl = Activator.CreateInstance(rewardImpl, rewardModeList[i].Data) as TaskRewardBase;

                        taskImpl.AddTaskRewardInfo(taskRewardImpl);
                    }
                    else
                    {
                        throw new Exception("reward mode :" + rewardMode + " not implement");
                    }
                }

                return(taskImpl);
            }

            return(null);
        }
コード例 #2
0
ファイル: TaskBase.cs プロジェクト: kingpowervrg/my_seeker
        //public void PrintContent()
        //{
        //    Debug.Log(string.Format("当前任务id = {0} , uuid = {1}", this.m_taskId, this.m_taskUUID));
        //}

        /// <summary>
        /// 添加任务触发条件
        /// </summary>
        /// <param name="taskTriggerCondition"></param>
        public void AddTaskTriggerCondition(TaskTriggerCondition taskTriggerCondition)
        {
            this.m_taskTriggerConditionList.Add(taskTriggerCondition);
        }