| using System;  | 
| using LitJson;  | 
|   | 
| using System.Collections.Generic;  | 
| using System.Linq;  | 
|   | 
| //淘金功能  | 
| public class GoldRushManager : GameSystemManager<GoldRushManager>  | 
| {  | 
|     public const int funcID = 8;  | 
|     int campUnlockState;  | 
|     int workerUnlockState;  | 
|     public int panningCnt;  //累计总次数  | 
|     public int lastRecoverTime;  // 上次免费恢复淘金令时间戳,为0时可不用倒计时  | 
|     public int housekeeperEndTime;   // 自动管家到期时间戳,有值同时也代表免费试用已使用  | 
|     public byte[] warehouseIDList;  //完成的,包含0空,主要用于领取的索引  | 
|     public Dictionary<int, HB037_tagSCGoldRushCampInfo.tagSCGoldRushCamp> campInfoDict = new Dictionary<int, HB037_tagSCGoldRushCampInfo.tagSCGoldRushCamp>();  | 
|     public Dictionary<int, List<int>> tmpCampWorkerSkinIDDict = new Dictionary<int, List<int>>(); //最后一次营地淘金对应的皮肤(预分配),纯粹用于显示模型  | 
|   | 
|     public event Action<int> OnGoldRushCampEvent;    //服务端通知营地信息  | 
|     public event Action OnGoldRushInfoEvent;  | 
|   | 
|   | 
|     //行为事件  | 
|     public event Action<int> OnRefreshItemEvent; //刷新淘金道具  | 
|     public event Action<PosEvent, bool, int, int, string> PathEvent; //事件,是否返程,营地ID,第几个工人,聊天内容(后续考虑传结构数据)  | 
|   | 
|     public const int followWorkerCount = 3;   //小兵的数量,非监工  | 
|   | 
|     public int m_MaxWorkerCount;   //配表的最大数量  | 
|     //监工的数量,解锁影响  | 
|     public int maxWorkerCount  | 
|     {  | 
|         get  | 
|         {  | 
|             int count = 0;  | 
|             for (int i = 1; i <= m_MaxWorkerCount; i++)  | 
|             {  | 
|                 if (IsWorkerUnLock(i))  | 
|                 {  | 
|                     count++;  | 
|                 }  | 
|             }  | 
|             return count;  | 
|         }  | 
|     }  | 
|     public List<int> skinIDs = new List<int>(); //随机的监工皮肤 ,已解锁  | 
|   | 
|     public int selectCampID;  | 
|     bool m_IsAutoWorking;   //是否暂停  | 
|     //是否在执行自动管家,没有淘金令时暂停,仓库满暂停  | 
|     public bool isAutoWorking  | 
|     {  | 
|         get  | 
|         {  | 
|             return m_IsAutoWorking && isOpenAuto;  | 
|         }  | 
|     }  | 
|     public bool isOpenAuto; //是否开启自动管家,重登会取消  | 
|   | 
|     public event Action OnAutoWorkingEvent;  | 
|   | 
|     //自动刷新物品,判断是ture开 false关, 因默认开启故值相反存储0是开,1是关  | 
|     public bool isAutoRefreshItem  | 
|     {  | 
|         get  | 
|         {  | 
|             //第十个数用于存储是否开启自动刷新,其他数用于存储物品等级  | 
|             var value = QuickSetting.Instance.GetQuickSettingValue<int>(QuickSettingType.AutoGoldRush, 10);  | 
|             return value == 0;  | 
|         }  | 
|         set  | 
|         {  | 
|             QuickSetting.Instance.SetQuickSetting<int>(QuickSettingType.AutoGoldRush, Convert.ToInt32(!value), 10);  | 
|   | 
|             QuickSetting.Instance.SendPackage();  | 
|         }  | 
|     }  | 
|   | 
|   | 
|   | 
|     //配置  | 
|     public int refreshMoneyType;  | 
|     public int[] refreshMoneyList;  | 
|     public Dictionary<int, int> itemIDUnLockFuncIDDict = new Dictionary<int, int>();  | 
|   | 
|     public bool openAutoGoldRush  | 
|     {  | 
|         get  | 
|         {  | 
|             return housekeeperEndTime > 0 && TimeUtility.AllSeconds < housekeeperEndTime;  | 
|         }  | 
|     }  | 
|   | 
|     //淘金仓库(已完成任务未领取的存储)上限  | 
|     int warehouseBaseCnt;  | 
|     int warehouseAddCnt;  | 
|     public int warehouseMaxCnt  | 
|     {  | 
|         get  | 
|         {  | 
|             return warehouseBaseCnt + (openAutoGoldRush ? warehouseAddCnt : 0);  | 
|         }  | 
|     }  | 
|   | 
|     //淘金令(任务未做的)上限  | 
|     int goldRushMissionBaseCnt;  | 
|     int goldRushMissionAddCnt;  | 
|     public int goldRushMissionMaxCnt  | 
|     {  | 
|         get  | 
|         {  | 
|             return goldRushMissionBaseCnt + (openAutoGoldRush ? goldRushMissionAddCnt : 0);  | 
|         }  | 
|     }  | 
|   | 
|     public int restoreMissionSeconds;   //自动恢复任务时间  | 
|   | 
|     public int freeAutoDays;   //免费试用天数  | 
|   | 
|     public List<int> buyAutoDaysList = new List<int>();   //购买自动管家天数  | 
|     public List<int> buyAutoCTGIDList = new List<int>();   //购买自动管家CTGID  | 
|     public int[] autoRefreshItemIDs;    //自动刷新物品ID列表  | 
|   | 
|   | 
|     public PlayerDataType unLockMoneyType; //刷新用  | 
|     public float lastAssignWorkTime;  | 
|     public float lastCallBackTime;  | 
|   | 
|   | 
|     public override void Init()  | 
|     {  | 
|         DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin += OnBeforePlayerDataInitialize;  | 
|         PlayerDatas.Instance.playerDataRefreshEvent += OnPlayerDataRefresh;  | 
|         DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOk;  | 
|   | 
|   | 
|         m_MaxWorkerCount = GoldRushWorkerConfig.GetKeys().Count;  | 
|   | 
|         ParseConfig();  | 
|     }  | 
|   | 
|     public override void Release()  | 
|     {  | 
|         DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin -= OnBeforePlayerDataInitialize;  | 
|         PlayerDatas.Instance.playerDataRefreshEvent -= OnPlayerDataRefresh;  | 
|         DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= OnPlayerLoginOk;  | 
|     }  | 
|   | 
|     void ParseConfig()  | 
|     {  | 
|         var config = FuncConfigConfig.Get("GoldRushRefresh");  | 
|         refreshMoneyType = int.Parse(config.Numerical2);  | 
|         refreshMoneyList = JsonMapper.ToObject<int[]>(config.Numerical3);  | 
|         itemIDUnLockFuncIDDict = ConfigParse.ParseIntDict(config.Numerical5);  | 
|   | 
|         config = FuncConfigConfig.Get("GoldRush");  | 
|         var countArr = ConfigParse.GetMultipleStr<int>(config.Numerical1);  | 
|         warehouseBaseCnt = countArr[0];  | 
|         warehouseAddCnt = countArr[1];  | 
|         countArr = ConfigParse.GetMultipleStr<int>(config.Numerical2);  | 
|         goldRushMissionBaseCnt = countArr[0];  | 
|         goldRushMissionAddCnt = countArr[1];  | 
|         restoreMissionSeconds = int.Parse(config.Numerical3) * 60;  | 
|   | 
|         config = FuncConfigConfig.Get("GoldRushAuto");  | 
|         var tmpArr = JsonMapper.ToObject<int[]>(config.Numerical1);  | 
|         freeAutoDays = tmpArr[0];  | 
|         for (int i = 1; i < tmpArr.Length; i++)  | 
|         {  | 
|             buyAutoDaysList.Add(tmpArr[i]);  | 
|         }  | 
|         var tmpArr2 = JsonMapper.ToObject<int[][]>(config.Numerical2);  | 
|         for (int i = 0; i < tmpArr2.Length; i++)  | 
|         {  | 
|             buyAutoCTGIDList.Add(tmpArr2[i][0]);  | 
|         }  | 
|   | 
|         autoRefreshItemIDs = JsonMapper.ToObject<int[]>(config.Numerical3);  | 
|     }  | 
|   | 
|     void OnBeforePlayerDataInitialize()  | 
|     {  | 
|         campUnlockState = 0;  | 
|         workerUnlockState = 0;  | 
|         panningCnt = 0;  | 
|         housekeeperEndTime = 0;  | 
|         warehouseIDList = new byte[0];  | 
|         lastRecoverTime = 0;  | 
|         campInfoDict.Clear();  | 
|         isOpenAuto = false;  | 
|     }  | 
|   | 
|   | 
|     void OnPlayerLoginOk()  | 
|     {  | 
|         //自动淘金未解锁的设置不勾选  | 
|         for (int i = 0; i < autoRefreshItemIDs.Length; i++)  | 
|         {  | 
|             var itemID = autoRefreshItemIDs[i];  | 
|             if (IsLock(itemID, out int funcID) && GetAutoItemLV(i) != 0)  | 
|             {  | 
|                 SetAutoItemLV(i, 0);  | 
|             }  | 
|         }  | 
|     }  | 
|   | 
|   | 
|     void OnPlayerDataRefresh(PlayerDataType type)  | 
|     {  | 
|         //unLockMoneyType未赋值则不会刷新 减少运行  | 
|         if (type == unLockMoneyType)  | 
|         {  | 
|             UpdateRedpoint();  | 
|         }  | 
|         // else if (type == PlayerDataType.GoldRush)  | 
|         // {  | 
|         //     ResumeAutoWorking();  | 
|         // }  | 
|     }  | 
|   | 
|     int skinIDIndex;  | 
|     public int GetRandommSkinID()  | 
|     {  | 
|         var skinID = skinIDs[skinIDIndex % skinIDs.Count];  | 
|         skinIDIndex++;  | 
|         //从已解锁中随机  | 
|         return skinID;  | 
|     }  | 
|   | 
|     //参考:  | 
|     //未发布 goldid = 0 endtime不定(完成或者从未开始)  | 
|     //已发布未进行 goldid != 0 endtime = 0  | 
|     //已发布进行中 goldid != 0 endtime !=0  | 
|     //预分配监工皮肤  | 
|     void InitWorkerSkinID(HB037_tagSCGoldRushCampInfo.tagSCGoldRushCamp campInfo)  | 
|     {  | 
|         if (campInfo.EndTime == 0 && forceStopCampID == 0)  | 
|         {  | 
|             if (tmpCampWorkerSkinIDDict.ContainsKey(campInfo.CampID))  | 
|             {  | 
|                 tmpCampWorkerSkinIDDict[campInfo.CampID].Clear();  | 
|             }  | 
|             return;  | 
|         }  | 
|         if (campInfo.GoldID != 0 && campInfo.EndTime != 0)  | 
|         {  | 
|             if (tmpCampWorkerSkinIDDict.ContainsKey(campInfo.CampID) && tmpCampWorkerSkinIDDict[campInfo.CampID].Count != 0)  | 
|             {  | 
|                 return;  | 
|             }  | 
|             tmpCampWorkerSkinIDDict[campInfo.CampID] = new List<int>();  | 
|             for (int i = 0; i < campInfo.WorkerCnt; i++)  | 
|             {  | 
|                 tmpCampWorkerSkinIDDict[campInfo.CampID].Add(GetRandommSkinID());  | 
|             }  | 
|   | 
|         }  | 
|     }  | 
|   | 
|     public int GetWorkerSkinID(int campID, int index)  | 
|     {  | 
|         if (tmpCampWorkerSkinIDDict.ContainsKey(campID))  | 
|         {   | 
|             var skinIDs = tmpCampWorkerSkinIDDict[campID];  | 
|             if (index < skinIDs.Count)  | 
|             {  | 
|                 return skinIDs[index];  | 
|             }  | 
|             else  | 
|             {  | 
|                 var skinID = GetRandommSkinID();  | 
|                 skinIDs.Add(skinID);  | 
|                 return skinID;  | 
|             }  | 
|         }  | 
|   | 
|         //没有预分配则随机  | 
|         return skinIDs[UnityEngine.Random.Range(0, skinIDs.Count)];  | 
|     }  | 
|   | 
|     void RefreshUnLockSkinID()  | 
|     {  | 
|         skinIDs.Clear();  | 
|         foreach (var item in GoldRushWorkerConfig.GetValues())  | 
|         {  | 
|             if (IsWorkerUnLock(item.WorkerID))  | 
|             {  | 
|                 skinIDs.Add(item.SkinID);  | 
|             }  | 
|         }  | 
|     }  | 
|   | 
|     public void UpdateGoldRushInfo(HB036_tagSCGoldRushInfo netPack)  | 
|     {  | 
|         campUnlockState = (int)netPack.CampState;  | 
|         if (workerUnlockState != netPack.WorkerState)  | 
|         {  | 
|             workerUnlockState = (int)netPack.WorkerState;  | 
|             RefreshUnLockSkinID();  | 
|         }  | 
|         panningCnt = (int)netPack.PanningCnt;  | 
|         housekeeperEndTime = (int)netPack.HousekeeperEndTime;  | 
|         warehouseIDList = netPack.WarehouseIDList;  | 
|         lastRecoverTime = (int)netPack.LastRecoverTime;  | 
|         UpdateRedpoint();  | 
|   | 
|         ResumeAutoWorking();  | 
|         OnGoldRushInfoEvent?.Invoke();  | 
|     }  | 
|   | 
|     public void UpdateGoldRushCampInfo(HB037_tagSCGoldRushCampInfo netPack)  | 
|     {  | 
|         for (int i = 0; i < netPack.CampCnt; i++)  | 
|         {  | 
|             campInfoDict[netPack.CampList[i].CampID] = netPack.CampList[i];  | 
|             InitWorkerSkinID(netPack.CampList[i]);  | 
|             OnGoldRushCampEvent?.Invoke(netPack.CampList[i].CampID);  | 
|   | 
|         }  | 
|         UpdateRedpoint();  | 
|   | 
|     }  | 
|   | 
|     //获取淘金仓库总量含正在执行的  | 
|     public int GetWarehouseCnt()  | 
|     {  | 
|         //排查0  | 
|         int cnt = 0;  | 
|         foreach (var item in warehouseIDList)  | 
|         {  | 
|             if (item != 0)  | 
|             {  | 
|                 cnt++;  | 
|             }  | 
|         }  | 
|         foreach (var item in campInfoDict.Values)  | 
|         {  | 
|             if (item.GoldID != 0 && item.EndTime != 0)  | 
|             {  | 
|                 cnt++;  | 
|             }  | 
|         }  | 
|         return cnt;  | 
|     }  | 
|   | 
|     //获取淘金ID  | 
|     public int GetCampGoldID(int campID)  | 
|     {  | 
|         if (campInfoDict.ContainsKey(campID))  | 
|         {  | 
|             return campInfoDict[campID].GoldID;  | 
|         }  | 
|         return 0;  | 
|     }  | 
|   | 
|   | 
|     //获取营地工人  | 
|     public int GetCampWorkerCnt(int campID)  | 
|     {  | 
|         if (campInfoDict.ContainsKey(campID))  | 
|         {  | 
|             return campInfoDict[campID].WorkerCnt;  | 
|         }  | 
|         return 0;  | 
|     }  | 
|   | 
|     public int GetEmptyWorkerCount()  | 
|     {  | 
|         int count = 0;  | 
|         foreach (var item in campInfoDict.Values)  | 
|         {  | 
|             count += item.WorkerCnt;  | 
|         }  | 
|         return maxWorkerCount - count;  | 
|     }  | 
|   | 
|     //获取营地刷新次数  | 
|     public int GetCampRefreshCnt(int campID)  | 
|     {  | 
|         if (campInfoDict.ContainsKey(campID))  | 
|         {  | 
|             return campInfoDict[campID].RefreshCnt;  | 
|         }  | 
|         return 0;  | 
|     }  | 
|   | 
|     //获取营地结束时间,0代表未开始  | 
|     public int GetCampEndTime(int campID)  | 
|     {  | 
|         if (campInfoDict.ContainsKey(campID))  | 
|         {  | 
|             if (campInfoDict[campID].GoldID == 0)  | 
|             {  | 
|                 return 0;  | 
|             }  | 
|             return (int)campInfoDict[campID].EndTime;  | 
|         }  | 
|         return 0;  | 
|     }  | 
|   | 
|     //有可进行和进行中的  | 
|     public bool HasWork()  | 
|     {  | 
|         return campInfoDict.Values.Any(x => x.GoldID != 0);  | 
|     }  | 
|   | 
|     //进行中的  | 
|     public bool HasWorking(int campID)  | 
|     {  | 
|         if (campInfoDict.ContainsKey(campID))  | 
|         {  | 
|             return campInfoDict[campID].GoldID != 0 && campInfoDict[campID].EndTime != 0;  | 
|         }  | 
|         return false;  | 
|     }  | 
|   | 
|     public string GetCampItemName(GoldRushItemConfig config)  | 
|     {  | 
|         return UIHelper.AppendColor(config.ItemLV, Language.Get("L1113", config.ItemLV) + " " + ItemConfig.Get(config.ItemID).ItemName);  | 
|     }  | 
|   | 
|   | 
|     //营地是否已解锁  | 
|     public bool IsCampUnLock(int campID)  | 
|     {  | 
|         return (campUnlockState & (1 << campID)) != 0;  | 
|     }  | 
|   | 
|     //工人是否已解锁  | 
|     public bool IsWorkerUnLock(int workerID)  | 
|     {  | 
|         return (workerUnlockState & (1 << workerID)) != 0;  | 
|     }  | 
|   | 
|     public int forceStopCampID;  | 
|     // 0-发布淘金(消耗淘金令);1-刷新淘金;2-开始淘金或调整监工数;3-取消淘金  | 
|     public void SendGoldRushOP(int opType, int campID, int workerCnt)  | 
|     {  | 
|         if (opType == 3)  | 
|         {  | 
|             forceStopCampID = campID;  | 
|         }  | 
|         if (opType == 2 && workerCnt < GetCampWorkerCnt(campID))  | 
|         {   | 
|             forceStopCampID = campID;  | 
|         }  | 
|         var pack = new CB036_tagCSGoldRushOP();  | 
|         pack.OPType = (byte)opType;  | 
|         pack.CampID = (byte)campID;  | 
|         pack.WorkerCnt = (byte)workerCnt;  | 
|         GameNetSystem.Instance.SendInfo(pack);  | 
|         if (opType <= 1)  | 
|         {  | 
|             OnRefreshItemEvent?.Invoke(campID);  | 
|         }  | 
|     }  | 
|   | 
|     //解锁  0-营地;1-监工  | 
|     public void SendGoldRushUnlock(int unlockType, int id)  | 
|     {  | 
|         var pack = new CB037_tagCSGoldRushUnlock();  | 
|         pack.UnlockType = (byte)unlockType;  | 
|         pack.UnlockID = (byte)id;  | 
|         GameNetSystem.Instance.SendInfo(pack);  | 
|     }  | 
|   | 
|     public void SendGoldRushWarehouseAward(int index, int isAll)  | 
|     {  | 
|         var pack = new CB038_tagCSGoldRushWarehouseAward();  | 
|         pack.AwardIndex = (byte)index;  | 
|         pack.IsAll = (byte)isAll;  | 
|         GameNetSystem.Instance.SendInfo(pack);  | 
|     }  | 
|   | 
|     public void GetAllAward()  | 
|     {  | 
|         if (CheckHasFinishGoldRush())  | 
|         {  | 
|             SendGoldRushWarehouseAward(0, 1);  | 
|         }  | 
|     }  | 
|   | 
|   | 
|   | 
|     //通知路径行为事件  | 
|     public void NotifyPathEvent(PosEvent posEvent, bool isBack, int tendID, int index, string content)  | 
|     {  | 
|         PathEvent?.Invoke(posEvent, isBack, tendID, index, content);  | 
|     }  | 
|   | 
|   | 
|     //红点:可领取,可解锁的监工  | 
|     Redpoint redpoint = new Redpoint(MainRedDot.MainAffairsRedpoint, MainRedDot.BlessedLandRedpoint);  | 
|   | 
|     //可解锁的监工  | 
|     Redpoint workerRedpoint = new Redpoint(MainRedDot.BlessedLandRedpoint, MainRedDot.BlessedLandRedpoint * 10 + 1);  | 
|   | 
|     //可领取的奖励  | 
|     Redpoint awardRedpoint = new Redpoint(MainRedDot.BlessedLandRedpoint, MainRedDot.BlessedLandRedpoint * 10 + 2);  | 
|     //营地解锁红点  | 
|     Redpoint campRedpoint = new Redpoint(MainRedDot.MainAffairsRedpoint, MainRedDot.BlessedLandRedpoint * 10);  | 
|   | 
|     void UpdateRedpoint()  | 
|     {  | 
|         if (CheckCanUnLockWorker())  | 
|         {  | 
|             workerRedpoint.state = RedPointState.Simple;  | 
|         }  | 
|         else  | 
|         {  | 
|             workerRedpoint.state = RedPointState.None;  | 
|         }  | 
|   | 
|         if (CheckHasFinishGoldRush())  | 
|         {  | 
|             awardRedpoint.state = RedPointState.Simple;  | 
|         }  | 
|         else  | 
|         {  | 
|             awardRedpoint.state = RedPointState.None;  | 
|         }  | 
|   | 
|   | 
|         campRedpoint.state = CheckCanUnLockCamp() ? RedPointState.Simple : RedPointState.None;  | 
|     }  | 
|   | 
|     //玩家数据类型  | 
|     void InitUnlockMoney(int type)  | 
|     {  | 
|         unLockMoneyType = UIHelper.moneyTypeToPlayerDataType[type];  | 
|     }  | 
|   | 
|     //检查是否有可解锁的监工  | 
|     bool CheckCanUnLockWorker()  | 
|     {  | 
|         foreach (var workerID in GoldRushWorkerConfig.GetKeys())  | 
|         {  | 
|             if (IsWorkerUnLock(workerID))  | 
|             {  | 
|                 continue;  | 
|             }  | 
|             var config = GoldRushWorkerConfig.Get(workerID);  | 
|             if (config.MoneyUnlock.Length != 0)  | 
|             {  | 
|                 InitUnlockMoney(config.MoneyUnlock[0]);  | 
|   | 
|                 if (UIHelper.GetMoneyCnt(config.MoneyUnlock[0]) < config.MoneyUnlock[1])  | 
|                 {  | 
|                     continue;  | 
|                 }  | 
|             }  | 
|   | 
|             if (config.PlayerLVUnlock != 0 && PlayerDatas.Instance.baseData.LV < config.PlayerLVUnlock)  | 
|             {  | 
|                 continue;  | 
|             }  | 
|   | 
|             return true;  | 
|         }  | 
|         return false;  | 
|     }  | 
|   | 
|     bool CheckHasFinishGoldRush()  | 
|     {  | 
|         //非0  | 
|         foreach (var id in warehouseIDList)  | 
|         {  | 
|             if (id != 0)  | 
|             {  | 
|                 return true;  | 
|             }  | 
|         }  | 
|         return false;  | 
|     }  | 
|   | 
|     //获取已完成的营地数量  | 
|     public int GetFinishGoldRushCount()  | 
|     {  | 
|         int cnt = 0;  | 
|         foreach (var id in warehouseIDList)  | 
|         {  | 
|             if (id != 0)  | 
|             {  | 
|                 ++cnt;  | 
|             }  | 
|         }  | 
|         return cnt;  | 
|     }  | 
|   | 
|     //检查是否有可解锁的营地  | 
|     bool CheckCanUnLockCamp()  | 
|     {  | 
|         foreach (var campID in GoldRushCampConfig.GetKeys())  | 
|         {  | 
|             if (IsCampUnLock(campID))  | 
|             {  | 
|                 continue;  | 
|             }  | 
|   | 
|             var config = GoldRushCampConfig.Get(campID);  | 
|             if (config.MoneyUnlock.Length != 0)  | 
|             {  | 
|                 InitUnlockMoney(config.MoneyUnlock[0]);  | 
|   | 
|                 if (UIHelper.GetMoneyCnt(config.MoneyUnlock[0]) < config.MoneyUnlock[1])  | 
|                 {  | 
|                     continue;  | 
|                 }  | 
|             }  | 
|   | 
|             if (config.PanningUnlock != 0 && panningCnt < config.PanningUnlock)  | 
|             {  | 
|                 continue;  | 
|             }  | 
|   | 
|   | 
|             return true;  | 
|   | 
|         }  | 
|         return false;  | 
|     }  | 
|   | 
|   | 
|     //0 已解锁 1 次数锁 2 金钱锁  | 
|     public int GetCampLockState(int campID)  | 
|     {  | 
|         if (IsCampUnLock(campID))  | 
|         {  | 
|             return 0;  | 
|         }  | 
|         var config = GoldRushCampConfig.Get(campID);  | 
|         if (config.PanningUnlock != 0)  | 
|         {  | 
|             return 1;  | 
|         }  | 
|   | 
|         if (config.MoneyUnlock.Length != 0)  | 
|         {  | 
|             return 2;  | 
|         }  | 
|   | 
|         return 0;  | 
|   | 
|     }  | 
|   | 
|     //0 已解锁 1 等级锁 2 金钱锁  | 
|     public int GetWorkerLockState(int workerID)  | 
|     {  | 
|         if (IsWorkerUnLock(workerID))  | 
|         {  | 
|             return 0;  | 
|         }  | 
|         var config = GoldRushWorkerConfig.Get(workerID);  | 
|         if (config.PlayerLVUnlock != 0)  | 
|         {  | 
|             return 1;  | 
|         }  | 
|   | 
|         if (config.MoneyUnlock.Length != 0)  | 
|         {  | 
|             return 2;  | 
|         }  | 
|   | 
|         return 0;  | 
|   | 
|     }  | 
|   | 
|   | 
|     //自动淘金 先填充营地 再填充多个监工  | 
|   | 
|     public void SetAutoWorking(bool _isOpenAuto, bool _isAutoWorking)  | 
|     {  | 
|         isOpenAuto = _isOpenAuto;  | 
|         m_IsAutoWorking = _isAutoWorking;  | 
|         OnAutoWorkingEvent?.Invoke();  | 
|     }  | 
|   | 
|   | 
|     //自动淘金的物品,按物品id配置索引存储  | 
|     // 返回值0代表不勾选,数值代表等级,因默认是0,所以存储上 9代表不勾选,0代表等级1, 后续加1  | 
|     public int GetAutoItemLV(int index)  | 
|     {  | 
|         var value = QuickSetting.Instance.GetQuickSettingValue<int>(QuickSettingType.AutoGoldRush, index);  | 
|         if (value == 9)  | 
|         {  | 
|             return 0;  | 
|         }  | 
|         return value + 1;  | 
|     }  | 
|   | 
|     //设置自动淘金的物品,按物品id配置索引存储  | 
|     // 参数0代表不勾选,数值代表等级,因默认是0,所以存储上 9代表不勾选,0代表等级1, 后续加1  | 
|     public void SetAutoItemLV(int index, int value)  | 
|     {  | 
|         if (value == 0)  | 
|         {  | 
|             value = 9;  | 
|         }  | 
|         else  | 
|         {  | 
|             value--;  | 
|         }  | 
|         QuickSetting.Instance.SetQuickSetting<int>(QuickSettingType.AutoGoldRush, value, index);  | 
|         QuickSetting.Instance.SendPackage();  | 
|     }  | 
|   | 
|     void OnSecondEvent()  | 
|     {  | 
|         if (!isAutoWorking || !isOpenAuto)  | 
|         {  | 
|             return;  | 
|         }  | 
|   | 
|         if (UIHelper.GetMoneyCnt(52) <= 0 && !HasWork())  | 
|         {  | 
|             PauseAutoWorking();  | 
|             SysNotifyMgr.Instance.ShowTip("GoldRush10");  | 
|             return;  | 
|         }  | 
|         if (GetFinishGoldRushCount() >= warehouseMaxCnt)  | 
|         {  | 
|             PauseAutoWorking();  | 
|             SysNotifyMgr.Instance.ShowTip("GoldRush9");  | 
|             return;  | 
|         }  | 
|         if (GetWarehouseCnt() >= warehouseMaxCnt)  | 
|         {  | 
|             return;  | 
|         }  | 
|   | 
|         AutoWorking();  | 
|     }  | 
|   | 
|     public void StartAutoWorking()  | 
|     {  | 
|         GlobalTimeEvent.Instance.secondEvent += OnSecondEvent;  | 
|         SetAutoWorking(true, true);  | 
|     }  | 
|   | 
|     public void StopAutoWorking()  | 
|     {  | 
|         GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent;  | 
|   | 
|         SetAutoWorking(false, false);  | 
|     }  | 
|   | 
|     public void PauseAutoWorking()  | 
|     {  | 
|         GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent;  | 
|         SetAutoWorking(isOpenAuto, false);  | 
|     }  | 
|   | 
|     public void ResumeAutoWorking()  | 
|     {  | 
|         if (UIHelper.GetMoneyCnt(52) <= 0)  | 
|         {  | 
|             return;  | 
|         }  | 
|         if (GetFinishGoldRushCount() >= warehouseMaxCnt)  | 
|         {  | 
|             return;  | 
|         }  | 
|         if (!UIManager.Instance.IsOpened<AffairBaseWin>())  | 
|         {  | 
|             return;  | 
|         }  | 
|   | 
|         if (isOpenAuto && !isAutoWorking)  | 
|         {  | 
|             SysNotifyMgr.Instance.ShowTip("GoldRush11");  | 
|             StartAutoWorking();  | 
|         }  | 
|     }  | 
|   | 
|     void AutoWorking()  | 
|     {  | 
|         bool isRefreshing = false;  | 
|         //先刷营地  | 
|         foreach (var campID in campInfoDict.Keys)  | 
|         {  | 
|             var campInfo = campInfoDict[campID];  | 
|             if (campInfo.GoldID != 0 && campInfo.EndTime != 0)  | 
|             {  | 
|                 //正在采集中  | 
|                 continue;  | 
|             }  | 
|             var lockState = GetCampLockState(campID);  | 
|             if (lockState != 0)  | 
|             {  | 
|                 //未解锁  | 
|                 continue;  | 
|             }  | 
|   | 
|             if (campInfo.GoldID == 0)  | 
|             {  | 
|                 if (UIHelper.GetMoneyCnt(52) <= 0)  | 
|                 {  | 
|                     continue;  | 
|                 }  | 
|                 SendGoldRushOP(0, campID, 0);  | 
|                 isRefreshing = true;  | 
|             }  | 
|             else  | 
|             {  | 
|                 //是否满足条件  | 
|                 var config = GoldRushItemConfig.Get(campInfo.GoldID);  | 
|                 var needLV = GetAutoItemLV(Array.IndexOf(autoRefreshItemIDs, config.ItemID));  | 
|   | 
|                 if (needLV == 0 || config.ItemLV < needLV)  | 
|                 {  | 
|                     if (!isAutoRefreshItem)  | 
|                     {  | 
|                         continue;  | 
|                     }  | 
|                     if (!UIHelper.CheckMoneyCount(refreshMoneyType, GetRefreshMoney(campID), 0))  | 
|                     {  | 
|                         continue;  | 
|                     }  | 
|   | 
|                     //存在货币不足也会同时请求刷新的情况  | 
|                     SendGoldRushOP(1, campID, 0);  | 
|                     isRefreshing = true;  | 
|                     continue;  | 
|                 }  | 
|   | 
|                 isRefreshing = true;  | 
|                 //开始采集  | 
|                 SendGoldRushOP(2, campID, 1);  | 
|             }  | 
|         }  | 
|   | 
|         //填充监工  | 
|         if (isRefreshing) return;  | 
|   | 
|         foreach (var campID in campInfoDict.Keys)  | 
|         {  | 
|             var campInfo = campInfoDict[campID];  | 
|             var config = GoldRushItemConfig.Get(campInfo.GoldID);  | 
|             if (campInfo.GoldID != 0 && campInfo.EndTime != 0)  | 
|             {  | 
|                 //正在采集中 增加监工, 一次循环只增加一个监工  | 
|                 if (campInfo.WorkerCnt < config.WorkerMax && GetEmptyWorkerCount() > 0)  | 
|                 {  | 
|                     SendGoldRushOP(2, campID, campInfo.WorkerCnt + 1);  | 
|                     break;  | 
|                 }  | 
|   | 
|             }  | 
|   | 
|         }  | 
|     }  | 
|   | 
|     public int GetRefreshMoney(int campID)  | 
|     {  | 
|         var refreshCnt = GetCampRefreshCnt(campID);  | 
|         return refreshMoneyList[Math.Min(refreshCnt, refreshMoneyList.Length - 1)];  | 
|     }  | 
|       | 
|     public bool IsLock(int itemID, out int funcID)  | 
|     {  | 
|         funcID = 0;  | 
|         if (itemIDUnLockFuncIDDict.ContainsKey(itemID))  | 
|         {  | 
|             funcID = itemIDUnLockFuncIDDict[itemID];  | 
|             if (!FuncOpen.Instance.IsFuncOpen(funcID))  | 
|             {  | 
|                 return true;  | 
|             }  | 
|   | 
|             return false;  | 
|         }  | 
|         return false;  | 
|     }  | 
| }  | 
|   |