Exemple #1
0
        //-------------------------------------------------------------------------
        public override void onInit()
        {
            CoPlayer = Entity.getComponent <CellPlayer <DefPlayer> >();
            TbDataTaskCollectItem = EbDataMgr.Instance.getData <TbDataTaskCollectItem>(TaskData.task_id);
            ListItemData          = new List <OneItemData>();

            if (TaskData.task_state == TaskState.Init)
            {
                if (TbDataTask.AcceptNpcId == 0)
                {
                    TaskData.task_state = TaskState.Doing;
                }
                else
                {
                    TaskData.task_state = TaskState.CanDo;
                }
            }

            // 主动查询一次背包中是否有所需任务物品
            foreach (var i in TbDataTaskCollectItem.ListCollectItem)
            {
                OneItemData one_item_data = new OneItemData();
                one_item_data.item_id   = i.item_id;
                one_item_data.num_total = i.count;
                int num_cur = CoPlayer.CoBag.getItemNumByItemId(i.item_id);
                if (num_cur > i.count)
                {
                    num_cur = i.count;
                }
                one_item_data.num_cur = num_cur;

                ListItemData.Add(one_item_data);
            }

            if (TaskData.task_state == TaskState.Doing && _isDone())
            {
                TaskData.task_state = TaskState.Done;
            }

            _saveTaskData();

            if (TaskData.task_state == TaskState.Done && TbDataTask.FinishNpcId == 0)
            {
                TaskData.task_state = TaskState.Release;
                TaskMgr._serverAddDirtyTask(this);
            }
        }
Exemple #2
0
        //-------------------------------------------------------------------------
        void _loadTaskData()
        {
            ListItemData.Clear();

            foreach (var i in TbDataTaskCollectItem.ListCollectItem)
            {
                OneItemData one_item_data = new OneItemData();
                one_item_data.item_id   = i.item_id;
                one_item_data.num_cur   = 0;
                one_item_data.num_total = i.count;

                ListItemData.Add(one_item_data);
            }

            string data = null;

            if (TaskData.task_data != null && TaskData.task_data.TryGetValue(0, out data))
            {
                int      index     = 0;
                string[] list_data = data.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                while (index < list_data.Length)
                {
                    int item_id = int.Parse(list_data[index++]);
                    int num_cur = int.Parse(list_data[index++]);

                    foreach (var j in ListItemData)
                    {
                        if (j.item_id == item_id)
                        {
                            j.num_cur = num_cur;
                            break;
                        }
                    }
                }
            }
        }
Exemple #3
0
        //-------------------------------------------------------------------------
        public override void onInit()
        {
            CoPlayer = Entity.getComponent<CellPlayer<DefPlayer>>();
            TbDataTaskCollectItem = EbDataMgr.Instance.getData<TbDataTaskCollectItem>(TaskData.task_id);
            ListItemData = new List<OneItemData>();

            if (TaskData.task_state == TaskState.Init)
            {
                if (TbDataTask.AcceptNpcId == 0)
                {
                    TaskData.task_state = TaskState.Doing;
                }
                else
                {
                    TaskData.task_state = TaskState.CanDo;
                }
            }

            // 主动查询一次背包中是否有所需任务物品
            foreach (var i in TbDataTaskCollectItem.ListCollectItem)
            {
                OneItemData one_item_data = new OneItemData();
                one_item_data.item_id = i.item_id;
                one_item_data.num_total = i.count;
                int num_cur = CoPlayer.CoBag.getItemNumByItemId(i.item_id);
                if (num_cur > i.count) num_cur = i.count;
                one_item_data.num_cur = num_cur;

                ListItemData.Add(one_item_data);
            }

            if (TaskData.task_state == TaskState.Doing && _isDone())
            {
                TaskData.task_state = TaskState.Done;
            }

            _saveTaskData();

            if (TaskData.task_state == TaskState.Done && TbDataTask.FinishNpcId == 0)
            {
                TaskData.task_state = TaskState.Release;
                TaskMgr._serverAddDirtyTask(this);
            }
        }
Exemple #4
0
        //-------------------------------------------------------------------------
        void _loadTaskData()
        {
            ListItemData.Clear();

            foreach (var i in TbDataTaskCollectItem.ListCollectItem)
            {
                OneItemData one_item_data = new OneItemData();
                one_item_data.item_id = i.item_id;
                one_item_data.num_cur = 0;
                one_item_data.num_total = i.count;

                ListItemData.Add(one_item_data);
            }

            string data = null;
            if (TaskData.task_data != null && TaskData.task_data.TryGetValue(0, out data))
            {
                int index = 0;
                string[] list_data = data.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                while (index < list_data.Length)
                {
                    int item_id = int.Parse(list_data[index++]);
                    int num_cur = int.Parse(list_data[index++]);

                    foreach (var j in ListItemData)
                    {
                        if (j.item_id == item_id)
                        {
                            j.num_cur = num_cur;
                            break;
                        }
                    }
                }
            }
        }