public static void LoadData()
    {
        SqliteDataReader reader = LocalDatabase.Instance.ReadFullTable("collectfield");

        while (reader.Read())
        {
            ProcessingObjInfo pbi = new ProcessingObjInfo();
            pbi.protoId = Convert.ToInt32(reader.GetString(reader.GetOrdinal("itemid")));
            pbi.tab     = Convert.ToInt32(reader.GetString(reader.GetOrdinal("tab")));
            pbi.max     = Convert.ToInt32(reader.GetString(reader.GetOrdinal("max")));
            pbi.time    = Convert.ToSingle(reader.GetString(reader.GetOrdinal("time")));
            pobInfoDict.Add(pbi.protoId, pbi);
        }
    }
    public bool AddItem(ItemIdCount po)
    {
        //--to do:
        if (cs != null)
        {
            return(false);
        }

        bool        existed    = false;
        ItemIdCount existedPob = null;

        foreach (ItemIdCount pob in itemList)
        {
            if (pob.protoId == po.protoId)
            {
                existedPob = pob;
                existed    = true;
            }
        }

        if (existed)
        {
            if (existedPob.count >= ProcessingObjInfo.GetPobMax(existedPob.protoId))
            {
                return(false);
            }
            existedPob.count += po.count;
            if (existedPob.count > ProcessingObjInfo.GetPobMax(existedPob.protoId))
            {
                existedPob.count = ProcessingObjInfo.GetPobMax(existedPob.protoId);
            }
            return(true);
        }
        else
        {
            //2.check room
            if (itemList.Count >= ProcessingConst.OBJ_MAX)
            {
                return(false);
            }
            if (po.count > ProcessingObjInfo.GetPobMax(po.protoId))
            {
                po.count = ProcessingObjInfo.GetPobMax(po.protoId);
            }
            itemList.Add(po);
            return(true);
        }
    }
    public float CountTime()
    {
        if (npcList.Count == 0)
        {
            return(0);
        }
        float time = 0;

        //--to do:
        foreach (ItemIdCount po in itemList)
        {
            if (po != null)
            {
                time += ProcessingObjInfo.GetPobTime(po.protoId) * po.count;
            }
        }
        return(time * GetFullWorkerParam(npcList));
    }
    public void SetSelect()
    {
        List <ItemIdCount> orclist   = new List <ItemIdCount>();
        List <ItemIdCount> herblist  = new List <ItemIdCount>();
        List <ItemIdCount> otherlist = new List <ItemIdCount>();

        foreach (ProcessingObjInfo pob in ProcessingObjInfo.GetAllInfo())
        {
            switch (pob.tab)
            {
            case 0: orclist.Add(new ItemIdCount(pob.protoId, pob.max)); break;

            case 1: herblist.Add(new ItemIdCount(pob.protoId, pob.max)); break;

            default: otherlist.Add(new ItemIdCount(pob.protoId, pob.max)); break;
            }
        }

        uiObj.ClearPlan();
        uiObj.AddOreList(orclist);
        uiObj.AddHerbList(herblist);
        uiObj.AddOtherList(otherlist);
        uiObj.ClearProcess();
    }
 public static bool CanProcessItem(int protoId)
 {
     return(ProcessingObjInfo.GetPobTime(protoId) > 0);
 }
    public void CreateNewTaskWithItems(List <ItemIdCount> allItems)
    {
        //1.split task
        //List<ItemIdCount> taskObjList = new List<ItemIdCount> ();

        List <List <ItemIdCount> > taskList = new List <List <ItemIdCount> > ();

        taskList.Add(new List <ItemIdCount> ());
        int startIndex = 0;        //first index has room

        foreach (ItemIdCount iic in allItems)
        {
            int countMax = ProcessingObjInfo.GetPobMax(iic.protoId);
            if (countMax < 0)
            {
                continue;
            }
            //find the first room
            while (taskList[startIndex].Count >= ProcessingConst.OBJ_MAX)
            {
                startIndex++;
                if (taskList.Count <= startIndex)
                {
                    taskList.Add(new List <ItemIdCount> ());
                }
            }
            int addIndex = startIndex;            //current index to add;
            while (iic.count > countMax)
            {
                if (taskList.Count <= addIndex)
                {
                    taskList.Add(new List <ItemIdCount> ());
                }
                if (taskList[addIndex].Count < ProcessingConst.OBJ_MAX)
                {
                    taskList[addIndex].Add(new ItemIdCount(iic.protoId, countMax));
                    iic.count -= countMax;
                }
                addIndex++;
            }
            if (taskList.Count <= addIndex)
            {
                taskList.Add(new List <ItemIdCount> ());
            }
            taskList[addIndex].Add(iic);
        }

        //2.assign npc
        //1-find all free npc
        List <CSPersonnel> freeNpc = GetFreeWorkers();

        if (freeNpc.Count == 0)
        {
            return;
        }
        //2-get free Taks room
        List <int> freeTask = new List <int> ();

        for (int i = 0; i < ProcessingConst.TASK_NUM; i++)
        {
            if (mTaskTable[i] == null || mTaskTable[i].itemList.Count == 0)
            {
                freeTask.Add(i);
            }
        }
        if (freeTask.Count == 0)
        {
            return;
        }
        int needTaskNum = taskList.Count;
        int npcNum      = freeNpc.Count;
        int freeTaskNum = freeTask.Count;
        //3-assign Npc
        int runTaskNum = Mathf.Min(needTaskNum, npcNum, freeTaskNum);
        int npcPerTask = npcNum / runTaskNum;

        if (runTaskNum == 1 && npcNum > 1)
        {
            npcPerTask = npcNum - 1;
        }
        for (int i = 0; i < runTaskNum; i++)
        {
            int taskIndex = freeTask[i];
            if (mTaskTable[taskIndex] == null)
            {
                mTaskTable[taskIndex] = new ProcessingTask();
            }
            for (int j = 0; j < npcPerTask; j++)
            {
                freeNpc[j].TrySetProcessingIndex(taskIndex);
            }
            freeNpc.RemoveRange(0, npcPerTask);
            mTaskTable[taskIndex].itemList = taskList[i];
        }

        List <int> runRange = freeTask.GetRange(0, runTaskNum);

        foreach (CSPersonnel csp in freeNpc)
        {
            if (runRange.Contains(csp.ProcessingIndex))
            {
                int changeToIndex = FindNextTaskNoStart(runRange);
                if (changeToIndex >= 0)
                {
                    csp.TrySetProcessingIndex(changeToIndex);
                }
            }
        }
        //3.start task
        for (int i = 0; i < runTaskNum; i++)
        {
            int taskIndex = freeTask[i];
            StartProcessing(taskIndex);
        }
        if (runTaskNum > 0)
        {
            CSAutocycleMgr.Instance.ShowProcessFor(taskList[0]);
        }
        //4.updateUI
        UpdateDataToUI();
    }
    public static void LoadAllData()
    {
        if (s_localDatabase != null)
        {
            return;
        }

#if UNITY_EDITOR
        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
        sw.Start();
#endif
        s_localDatabase = LoadDb();
        SkillSystem.SkData.LoadData();
        Pathea.Effect.EffectData.LoadData();
        Pathea.Projectile.ProjectileData.LoadData();
        Pathea.RequestRelation.LoadData();
        Pathea.CampData.LoadData();
        Pathea.ThreatData.LoadData();
        Pathea.DamageData.LoadData();
        HumanSoundData.LoadData();
        ItemDropData.LoadData();

        PELocalization.LoadData();

        NaturalResAsset.NaturalRes.LoadData();
        //SkillAsset.EffCastData.LoadData();
        //SkillAsset.EffSkill.LoadData();
        //SkillAsset.MergeSkill.LoadData();
        //AnimData.LoadData();
        //AnimSoundData.LoadData();

        AiAsset.AiData.LoadData();

        SoundAsset.SESoundBuff.LoadData();
        SoundAsset.SESoundStory.LoadData();
        //CharacterData.LoadCharacterData();
        StoryDoodadMap.LoadData();
        StoreRepository.LoadData();
        NpcMissionDataRepository.LoadData();
        //PlayerAttribute.LoadData();
        MissionRepository.LoadData();
        TalkRespository.LoadData();
        //NpcRandomRepository.LoadData();
        ShopRespository.LoadData();
        WareHouseManager.LoadData();
        //HeroTalkRepository.LoadData();
        MutiPlayRandRespository.LoadData();
        PromptRepository.LoadData();

        //MapIconData.LoadDate();
        //MapMaskData.LoadDate();
        CampPatrolData.LoadDate();
        Camp.LoadData();
        RepProcessor.LoadData();

        CloudManager.LoadData();
        //BattleUnitData.LoadData();
        TutorialData.LoadData();
        //RepairMachineManager.LoadData();
        MapMaskData.LoadDate();
        MessageData.LoadData();         //lz-2016.07.13 Add it
        MonsterHandbookData.LoadData(); //lz-2016.07.20 Add it
        StoryRepository.LoadData();
        RMRepository.LoadRandMission();
        MisInitRepository.LoadData();
        CameraRepository.LoadCameraPlot();
        AdRMRepository.LoadData();
        VCConfig.InitConfig();
        Cutscene.LoadData();

//		BuildBrushData.LoadBrush();
        BSPattern.LoadBrush();
        BSVoxelMatMap.Load();
        BSBlockMatMap.Load();
        BlockBuilding.LoadBuilding();
        LifeFormRule.LoadData();
        PlantInfo.LoadData();
        MetalScanData.LoadData();
        BattleConstData.LoadData();
        CustomCharactor.CustomMetaData.LoadData();
        SkillTreeInfo.LoadData();
        VArtifactUtil.LoadData();
        Pathea.ActionRelationData.LoadActionRelation();

        //colony
        CSInfoMgr.LoadData();
        ProcessingObjInfo.LoadData();
        CSTradeInfoData.LoadData();
        CampTradeIdData.LoadData();
        AbnormalTypeTreatData.LoadData();
        CSMedicineSupport.LoadData();
        //RandomItemMgr
        RandomItemDataMgr.LoadData();
        FecesData.LoadData();
        //randomdungeon
        RandomDungeonDataBase.LoadData();
        AbnormalData.LoadData();
        PEAbnormalNoticeData.LoadData();

        RelationInfo.LoadData();
        EquipSetData.LoadData();
        SuitSetData.LoadData();

        CheatData.LoadData();

        Pathea.NpcProtoDb.Load();
        Pathea.MonsterProtoDb.Load();
        Pathea.MonsterRandomDb.Load();
        Pathea.MonsterGroupProtoDb.Load();
        Pathea.RandomNpcDb.Load();
        Pathea.PlayerProtoDb.Load();
        Pathea.TowerProtoDb.Load();
        Pathea.DoodadProtoDb.Load();
        Pathea.AttPlusNPCData.Load();
        Pathea.AttPlusBuffDb.Load();
        Pathea.NpcTypeDb.Load();
        Pathea.NpcRandomTalkDb.Load();
        Pathea.NpcThinkDb.LoadData();
        Pathea.NpcEatDb.LoadData();
        Pathea.NpcRobotDb.Load();
        Pathea.NPCScheduleData.Load();
        Pathea.NpcVoiceDb.LoadData();
        InGameAidData.LoadData(); //lz-2016.08.21 add it
        MountsSkillDb.LoadData();

#if UNITY_EDITOR
        sw.Stop();
        Debug.Log("Database Loaded : " + sw.ElapsedMilliseconds);
        sw.Reset();
#else
        Debug.Log("Database Loaded");
#endif
    }