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 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 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>();
|
|
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 override void Init()
|
{
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin += OnBeforePlayerDataInitialize;
|
PlayerDatas.Instance.playerDataRefreshEvent += OnPlayerDataRefresh;
|
|
m_MaxWorkerCount = GoldRushWorkerConfig.GetKeys().Count;
|
|
ParseConfig();
|
}
|
|
public override void Release()
|
{
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin -= OnBeforePlayerDataInitialize;
|
PlayerDatas.Instance.playerDataRefreshEvent -= OnPlayerDataRefresh;
|
}
|
|
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 OnPlayerDataRefresh(PlayerDataType type)
|
{
|
//unLockMoneyType未赋值则不会刷新 减少运行
|
if (type == unLockMoneyType)
|
{
|
UpdateRedpoint();
|
}
|
else if (type == PlayerDataType.GoldRush)
|
{
|
SetAutoWorking(isOpenAuto, UIHelper.GetMoneyCnt(52) > 0);
|
}
|
}
|
|
|
public int GetRandommSkinID()
|
{
|
//从已解锁中随机
|
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();
|
OnGoldRushInfoEvent?.Invoke();
|
}
|
|
public void UpdateGoldRushCampInfo(HB037_tagSCGoldRushCampInfo netPack)
|
{
|
for (int i = 0; i < netPack.CampCnt; i++)
|
{
|
campInfoDict[netPack.CampList[i].CampID] = 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 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;
|
}
|
|
// 0-发布淘金(消耗淘金令);1-刷新淘金;2-开始淘金或调整监工数;3-取消淘金
|
public void SendGoldRushOP(int opType, int campID, int workerCnt)
|
{
|
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 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)
|
{
|
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;
|
|
}
|
|
|
//自动淘金 先填充营地 再填充多个监工
|
|
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();
|
}
|
|
|
}
|
|