Ejemplo n.º 1
0
        private bool CreateTask(Task_TableItem taskRes, int param = -1)
        {
            if (taskRes == null)
            {
                return(false);
            }

            var index = GetTaskIndex();

            if (index <= 0)
            {
                return(false);
            }

            var info = CreateTaskInfo(taskRes, param);

            if (info == null)
            {
                return(false);
            }

            info.index  = index;
            info.number = campTaskData.taskDic.Count + campTaskData.completeTasks.Count + 1;
            campTaskData.taskDic[index] = info;

            Debug.Log("CreateTask " + info.number);
            //for (int i = 0; i < campTaskData.taskDic.Count; ++i)
            //{
            //    campTaskData.taskDic[i].index = i;
            //}
            //if (campTaskData.taskDic.Count < TableMgr.singleton.ValueTable.camp_task_max_count)

            //info.index = campTaskData.taskDic.Count;

            //int index = 0;
            //for(int i = 0;i < campTaskData.taskDic.Count;++i)
            //{
            //    if (i != campTaskData.taskDic[i].index)
            //    {
            //        index = i;
            //        break;
            //    }
            //    index++;
            //}

            //info.index = index;
            //campTaskData.taskDic.Insert(index, info);
            //Debug.Log("CreateTask " + index);

            return(true);
        }
Ejemplo n.º 2
0
        private TaskInfo CreateTaskInfo(Task_TableItem task, int param)
        {
            var taskTypeRes = TableMgr.singleton.CampTaskTypeTable.GetItemByID(task.type);

            if (taskTypeRes == null)
            {
                return(null);
            }

            var info = new TaskInfo();

            info.taskID   = task.id;
            info.taskType = task.type;

            if (param > 0)
            {
                info.taskParam = param - 1;
            }

            switch ((TaskType)task.type)
            {
            //case TaskType.Finish_Battle:
            //    {
            //        info.conditionValue = GetFinishTaskCount(task.type) + task.value + campSetRes.taskDifficulty;
            //    }
            //    break;
            case TaskType.Occupy_Building:
            {
                if (info.taskParam >= 0)
                {
                    var pointData = CampsiteMgr.singleton.GetPointByIndex(info.taskParam);
                    if (pointData == null)
                    {
                        return(null);
                    }

                    info.conditionValue = 1;
                    return(info);
                }
                else
                {
                    CampsitePointMgr pointData = null;
                    for (int i = 0; i < campSetRes.CampBuildingArr.Length; ++i)
                    {
                        pointData = CampsiteMgr.singleton.GetPointByIndex(i);
                        if (pointData == null)
                        {
                            continue;
                        }

                        if (!pointData.isUnlock)
                        {
                            info.taskParam      = i;
                            info.conditionValue = 1;
                            return(info);
                        }
                    }
                }

                return(null);
            }

            case TaskType.Equip_Gun:
            {
                if (info.taskParam < 0)
                {
                    List <int> buildingList = new List <int>();
                    for (int i = 0; i < campSetRes.CampBuildingArr.Length; ++i)
                    {
                        var pointData = CampsiteMgr.singleton.GetPointByIndex(i);
                        if (pointData == null)
                        {
                            continue;
                        }

                        if (pointData.isUnlock)
                        {
                            buildingList.Add(campSetRes.CampBuildingArr[i]);
                        }
                    }

                    if (buildingList.Count > 0)
                    {
                        info.taskParam = BaseRandom.Next(0, buildingList.Count);
                    }
                    else
                    {
                        return(null);
                    }
                }

                info.conditionValue = GetFinishTaskCount(task.type) * task.value *
                                      campSetRes.taskDifficulty +
                                      campSetRes.AutoLevelArr[info.taskParam];
            }
            break;

            case TaskType.LvUp_Building:
            {
                if (info.taskParam < 0)
                {
                    //var index = GetFinishTaskCount(task.type) + GetContainTaskCount(task.type);
                    //Debug.Log("index " + index);
                    //var pointData = CampsiteMgr.singleton.GetPointByIndex(index);
                    //if (pointData == null)
                    //    return null;

                    //if (!pointData.isUnlock)
                    //{
                    //    return null;
                    //}
                    int index = -1;
                    for (int i = 0; i < campSetRes.CampBuildingArr.Length; ++i)
                    {
                        var pointData = CampsiteMgr.singleton.GetPointByIndex(i);
                        if (pointData == null)
                        {
                            continue;
                        }

                        if (pointData.isUnlock)
                        {
                            index = i;
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (index <= GetFinishTaskParam(task.type))
                    {
                        return(null);
                    }

                    info.taskParam = index;
                }

                info.conditionValue = (int)(task.value * campSetRes.taskDifficulty *
                                            campSetRes.id * 0.3f) + 5;
            }
            break;

            case TaskType.Buildings_Level:
            {
                info.conditionValue = task.value * campSetRes.taskDifficulty *
                                      campSetRes.id / 2;
            }
            break;

            case TaskType.LevelUp_Gun:
            {
                if (info.taskParam < 0)
                {
                    var typeList = PlayerDataMgr.singleton.GetGunCardTypeList();
                    if (typeList.Count <= 0)
                    {
                        return(null);
                    }

                    info.taskParam = typeList[BaseRandom.Next(0, typeList.Count)];
                }
                info.conditionValue = GetFinishTaskCount(task.type) * 2 + task.value + campSetRes.taskDifficulty;
            }
            break;

            case TaskType.Supplies_Add:
            {
                //if (CampsiteMgr.singleton.TotalRewardRate <= 0.0f)
                //{
                //    return null;
                //}

                info.conditionValue = (BigInteger)(CampsiteMgr.singleton.TotalRewardRate *
                                                   task.value * campSetRes.taskDifficulty);
            }
            break;

            case TaskType.Cost_Gold:
            case TaskType.Get_Gold:
            {
                info.conditionValue = (BigInteger)(IdleRewardMgr.singleton.GetGoldPerMinute() *
                                                   (GetFinishTaskCount(task.type) + 1) * task.value * 0.5f *
                                                   campSetRes.taskDifficulty);
            }
            break;

            case TaskType.Quick_Reward:
            case TaskType.Open_Box:
            case TaskType.Fuse_Gun:
            case TaskType.Explore_Gold:
            case TaskType.Lv10_Gun:
            case TaskType.Finish_Battle:
            {
                info.conditionValue = task.value;
            }
            break;

            case TaskType.Epic_Gun:
            {
                info.conditionValue = 1;
            }
            break;

            case TaskType.Auto_Level:
            {
                if (info.taskParam < 0)
                {
                    int index = 0;
                    for (int i = 0; i < campSetRes.CampBuildingArr.Length; ++i)
                    {
                        var pointData = CampsiteMgr.singleton.GetPointByIndex(i);
                        if (pointData == null)
                        {
                            continue;
                        }

                        if (pointData.isUnlock)
                        {
                            index = i;
                        }
                        else
                        {
                            break;
                        }
                    }

                    info.taskParam = index;
                }

                var data = CampsiteMgr.singleton.GetPointByIndex(info.taskParam);
                if (data == null)
                {
                    return(null);
                }
                info.conditionValue = 1;
            }
            break;
            }

            return(info);
        }