| | |
| | | using System;
|
| | | 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 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<int, int, int> GoldRushEvent; //营地ID,执行事件(0出发,1返程),监工数量
|
| | | public event Action<PosEvent, bool, int, int, string> PathEvent; //事件,是否返程,营地ID,第几个工人,聊天内容(后续考虑传结构数据)
|
| | |
|
| | | public const int followWorkerCount = 3; //小兵的数量,非监工
|
| | |
| | |
|
| | | 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>();
|
| | |
|
| | | bool openAutoGoldRush
|
| | | public bool openAutoGoldRush
|
| | | {
|
| | | get
|
| | | {
|
| | |
| | |
|
| | | 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;
|
| | |
|
| | |
| | | {
|
| | | DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin -= OnBeforePlayerDataInitialize;
|
| | | PlayerDatas.Instance.playerDataRefreshEvent -= OnPlayerDataRefresh;
|
| | | DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= OnPlayerLoginOk;
|
| | | }
|
| | |
|
| | | void ParseConfig()
|
| | |
| | | buyAutoCTGIDList.Add(tmpArr2[i][0]);
|
| | | }
|
| | |
|
| | | autoRefreshItemIDs = JsonMapper.ToObject<int[]>(config.Numerical3);
|
| | | }
|
| | |
|
| | | void OnBeforePlayerDataInitialize()
|
| | |
| | | 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)
|
| | | {
|
| | |
| | | {
|
| | | UpdateRedpoint();
|
| | | }
|
| | | else if (type == PlayerDataType.GoldRush)
|
| | | // 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)
|
| | | {
|
| | | SetAutoWorking(isOpenAuto, UIHelper.GetMoneyCnt(52) > 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 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)];
|
| | | }
|
| | |
|
| | |
| | | {
|
| | | campUnlockState = (int)netPack.CampState;
|
| | | if (workerUnlockState != netPack.WorkerState)
|
| | | { |
| | | {
|
| | | workerUnlockState = (int)netPack.WorkerState;
|
| | | RefreshUnLockSkinID();
|
| | | }
|
| | |
| | | warehouseIDList = netPack.WarehouseIDList;
|
| | | lastRecoverTime = (int)netPack.LastRecoverTime;
|
| | | UpdateRedpoint();
|
| | |
|
| | | ResumeAutoWorking();
|
| | | OnGoldRushInfoEvent?.Invoke();
|
| | | }
|
| | |
|
| | |
| | | {
|
| | | for (int i = 0; i < netPack.CampCnt; i++)
|
| | | {
|
| | | campInfoDict[netPack.CampList[i].CampID] = netPack.CampList[i]; ;
|
| | | campInfoDict[netPack.CampList[i].CampID] = netPack.CampList[i];
|
| | | InitWorkerSkinID(netPack.CampList[i]);
|
| | | OnGoldRushCampEvent?.Invoke(netPack.CampList[i].CampID);
|
| | |
|
| | | }
|
| | | UpdateRedpoint();
|
| | |
|
| | |
| | | foreach (var item in campInfoDict.Values)
|
| | | {
|
| | | if (item.GoldID != 0 && item.EndTime != 0)
|
| | | { |
| | | {
|
| | | cnt++;
|
| | | }
|
| | | }
|
| | |
| | | }
|
| | | return 0;
|
| | | }
|
| | |
|
| | |
|
| | | //获取营地工人
|
| | | public int GetCampWorkerCnt(int campID)
|
| | |
| | | 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 (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);
|
| | | }
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | public void SendGoldRushWarehouseAward(int index, int isAll)
|
| | | { |
| | | {
|
| | | var pack = new CB038_tagCSGoldRushWarehouseAward();
|
| | | pack.AwardIndex = (byte)index;
|
| | | pack.IsAll = (byte)isAll;
|
| | |
| | | public void GetAllAward()
|
| | | {
|
| | | if (CheckHasFinishGoldRush())
|
| | | { |
| | | {
|
| | | SendGoldRushWarehouseAward(0, 1);
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | //通知外出行为事件
|
| | | public void NotifyGoldRushEvent(int campID, int eventType, int leaderCount)
|
| | | {
|
| | | GoldRushEvent?.Invoke(campID, eventType, leaderCount);
|
| | | }
|
| | |
|
| | | //通知路径行为事件
|
| | | public void NotifyPathEvent(PosEvent posEvent, bool isBack, int tendID, int index, string content)
|
| | |
| | |
|
| | | //可解锁的监工
|
| | | Redpoint workerRedpoint = new Redpoint(MainRedDot.BlessedLandRedpoint, MainRedDot.BlessedLandRedpoint * 10 + 1);
|
| | | |
| | |
|
| | | //可领取的奖励
|
| | | Redpoint awardRedpoint = new Redpoint(MainRedDot.BlessedLandRedpoint, MainRedDot.BlessedLandRedpoint * 10 + 2);
|
| | | //营地解锁红点
|
| | |
| | |
|
| | | void UpdateRedpoint()
|
| | | {
|
| | | if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.GoldRush))
|
| | | return;
|
| | | |
| | | if (CheckCanUnLockWorker())
|
| | | {
|
| | | workerRedpoint.state = RedPointState.Simple;
|
| | |
| | | }
|
| | |
|
| | | //检查是否有可解锁的营地
|
| | | bool CheckCanUnLockCamp()
|
| | | bool CheckCanUnLockCamp()
|
| | | {
|
| | | foreach (var campID in GoldRushCampConfig.GetKeys())
|
| | | {
|
| | |
| | |
|
| | | //自动淘金 先填充营地 再填充多个监工
|
| | |
|
| | | void SetAutoWorking(bool _isOpenAuto, bool _isAutoWorking)
|
| | | { |
| | | 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;
|
| | | }
|
| | | }
|
| | |
|