using System.Collections; using System.Collections.Generic; using UnityEngine; using System; namespace Snxxz.UI { [XLua.Hotfix] [XLua.LuaCallCSharp] public class CrossServerBossModel : Model, IMapInitOk, IPlayerLoginOk { public const int DATA_MAPID = 32020; public const int REDPOINT = 21302; List sortedBossIds = new List(); Dictionary bosses = new Dictionary(); public int bigBoxNpcId = 0; public int smallBoxNpcId = 0; public List eliteMonsters = new List(); int m_SelectedBoss = 0; public int selectedBoss { get { return this.m_SelectedBoss; } set { if (this.m_SelectedBoss != value) { this.m_SelectedBoss = value; if (bossSelectedEvent != null) { bossSelectedEvent(value); } } } } public int bigBoxCollectCount { get { return dogzDungeonModel.bigBoxCollectCount; } } public int smallBoxCollectCount { get { return dogzDungeonModel.smallBoxCollectCount; } } public int wearyValue { get { return dogzDungeonModel.wearyValue; } } public event Action bossSelectedEvent; public event Action bigBoxCollectCountChangeEvent; public event Action boxSurplusChangeEvent; public event Action eliteSurplusChangeEvent; public DogzDungeonBox dogzDungeonBox = new DogzDungeonBox(); public DogzDungeonElite dogzDungeonElite = new DogzDungeonElite(); public Redpoint redpoint = new Redpoint(FindPreciousModel.LOOTPRECIOUs_REDPOINTID, REDPOINT); FindPreciousModel findPreciousModel { get { return ModelCenter.Instance.GetModel(); } } DogzDungeonModel dogzDungeonModel { get { return ModelCenter.Instance.GetModel(); } } DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel(); } } TeamModel teamModel { get { return ModelCenter.Instance.GetModel(); } } public override void Init() { ParseConfig(); FuncOpen.Instance.OnFuncStateChangeEvent += OnFunctionStateChange; } public override void UnInit() { FuncOpen.Instance.OnFuncStateChangeEvent -= OnFunctionStateChange; } public void OnMapInitOk() { if (PlayerDatas.Instance.baseData.MapID == DATA_MAPID) { if (selectedBoss != 0) { MapTransferUtility.Instance.MoveToNPC(selectedBoss); } } } public void RequestEnter() { if (PlayerDatas.Instance.extersion.bossState == 1) { SysNotifyMgr.Instance.ShowTip("CrossMap11"); return; } if (!AssetVersionUtility.IsUnpriorAssetDownLoadOk()) { InGameDownLoad.Instance.TryDownLoad(InGameDownLoad.Dominant.Whole); return; } var sendInfo = new CC105_tagCMEnterCrossServer(); sendInfo.DataMapID = DATA_MAPID; GameNetSystem.Instance.SendInfo(sendInfo); } public bool CanEnter(out int error) { var mapId = PlayerDatas.Instance.baseData.MapID; var mapConfig = MapConfig.Get(mapId); if (mapConfig.MapFBType != (int)MapType.OpenCountry) { error = 1; return false; } if (teamModel.isMatching) { error = 2; return false; } if (teamModel.teamPrepare.isPreparing) { error = 3; return false; } if (CrossServerLogin.Instance.IsEnterCrossServerPreparing()) { error = 4; return false; } var deadModel = ModelCenter.Instance.GetModel(); if (deadModel.playerIsDie) { error = 5; return false; } error = 0; return true; } public void ProcessEnterError(int error) { switch (error) { case 1: SysNotifyMgr.Instance.ShowTip("InDungeon_CantGo"); break; case 2: SysNotifyMgr.Instance.ShowTip("CrossMap1"); break; case 3: SysNotifyMgr.Instance.ShowTip("CrossMap2"); break; case 4: SysNotifyMgr.Instance.ShowTip("CrossMap3"); break; case 5: SysNotifyMgr.Instance.ShowTip("CrossMap4"); break; } } public void RequestExit() { var match = new CC104_tagCMExitCrossRealm(); GameNetSystem.Instance.SendToCrossServer(match); } public bool TryGetBossData(int bossId, out CrossServerBossData data) { return bosses.TryGetValue(bossId, out data); } public List GetNpcIds() { var npcIds = new List(); npcIds.Add(bigBoxNpcId); npcIds.Add(eliteMonsters[0]); npcIds.AddRange(bosses.Keys); return npcIds; } public List GetBosses() { return new List(bosses.Keys); } public int GetRecommendNpc() { if (bigBoxCollectCount < GeneralDefine.dogzBoxLimit) { return bigBoxNpcId; } if (wearyValue < GeneralDefine.bossWearyValues[2]) { var playerLevel = PlayerDatas.Instance.baseData.LV; for (int i = sortedBossIds.Count - 1; i >= 0; i--) { var bossId = sortedBossIds[i]; var npcConfig = NPCConfig.Get(bossId); if (IsBossUnLocked(bossId) && findPreciousModel.IsBossAlive(bossId) && playerLevel >= npcConfig.NPCLV) { return bossId; } } return sortedBossIds[0]; } return eliteMonsters[0]; } public int GetRecommendKillElite() { var Elite = dogzDungeonElite.GetAliveElite(); if (Elite == 0) { Elite = eliteMonsters[0]; } return Elite; } public bool IsBossUnLocked(int _bossId) { if (_bossId == bigBoxNpcId || _bossId == smallBoxNpcId) { return true; } if (eliteMonsters.Contains(_bossId)) { return true; } return bosses.ContainsKey(_bossId) && bosses[_bossId].isUnLocked; } public void RequestBoxAndEliteSurplusInfo() { var sendInfo = new CA227_tagCMQueryNPCCntInfo(); sendInfo.MapID = DATA_MAPID; sendInfo.LineID = 0; var stringArray = new string[eliteMonsters.Count + 2]; for (int i = 0; i < eliteMonsters.Count; i++) { stringArray[i] = eliteMonsters[i].ToString(); } stringArray[eliteMonsters.Count] = bigBoxNpcId.ToString(); stringArray[eliteMonsters.Count + 1] = smallBoxNpcId.ToString(); sendInfo.NPCIDList = string.Format("[{0}]", string.Join(",", stringArray)); sendInfo.NPCIDListLen = (byte)sendInfo.NPCIDList.Length; if (CrossServerUtility.IsCrossServerBoss()) { GameNetSystem.Instance.SendToCrossServer(sendInfo); } else { GameNetSystem.Instance.SendInfo(sendInfo); } } public void RequestBoxSurplusInfo() { var sendInfo = new CA227_tagCMQueryNPCCntInfo(); sendInfo.MapID = DATA_MAPID; sendInfo.LineID = (ushort)PlayerDatas.Instance.baseData.dungeonLineId; sendInfo.NPCIDList = string.Format("[{0},{1}]", bigBoxNpcId, smallBoxNpcId); sendInfo.NPCIDListLen = (byte)sendInfo.NPCIDList.Length; if (CrossServerUtility.IsCrossServerBoss()) { GameNetSystem.Instance.SendToCrossServer(sendInfo); } else { GameNetSystem.Instance.SendInfo(sendInfo); } } public void RequestEliteSurplusInfo() { var sendInfo = new CA227_tagCMQueryNPCCntInfo(); sendInfo.MapID = DATA_MAPID; sendInfo.LineID = 0; var stringArray = new string[eliteMonsters.Count]; for (int i = 0; i < stringArray.Length; i++) { stringArray[i] = eliteMonsters[i].ToString(); } sendInfo.NPCIDList = string.Format("[{0}]", string.Join(",", stringArray)); sendInfo.NPCIDListLen = (byte)sendInfo.NPCIDList.Length; if (CrossServerUtility.IsCrossServerBoss()) { GameNetSystem.Instance.SendToCrossServer(sendInfo); } else { GameNetSystem.Instance.SendInfo(sendInfo); } } public void UpdateMonsterSurplusInfo(HA714_tagMCNPCCntList _npcInfoes) { if (_npcInfoes.MapID != DATA_MAPID) { return; } var updatedBigBox = false; var updatedSmallBox = false; var updatedEliteNpcIds = new List(); for (int i = 0; i < _npcInfoes.NPCInfoList.Length; i++) { var npcInfo = _npcInfoes.NPCInfoList[i]; if (npcInfo.NPCID == bigBoxNpcId) { dogzDungeonBox.bigBoxSurplus = (int)npcInfo.Cnt; updatedBigBox = true; } if (npcInfo.NPCID == smallBoxNpcId) { dogzDungeonBox.smallBoxSurplus = (int)npcInfo.Cnt; updatedSmallBox = true; } if (eliteMonsters.Contains((int)npcInfo.NPCID)) { dogzDungeonElite.UpdateEliteInfo((int)npcInfo.NPCID, (int)npcInfo.Cnt); updatedEliteNpcIds.Add((int)npcInfo.NPCID); } } if (!updatedBigBox) { dogzDungeonBox.bigBoxSurplus = 0; } if (!updatedSmallBox) { dogzDungeonBox.smallBoxSurplus = 0; } if (boxSurplusChangeEvent != null) { boxSurplusChangeEvent(); } foreach (var item in eliteMonsters) { if (!updatedEliteNpcIds.Contains(item)) { dogzDungeonElite.UpdateEliteInfo(item, 0); } } if (eliteSurplusChangeEvent != null) { eliteSurplusChangeEvent(); } } public void UpdateBoxOrEliteRefreshTime(HA904_tagGCDogzNPCRefreshTime _refreshTimes) { var containBox = false; var boxRefreshSecond = 0; var containElite = false; var eliteRefreshSecond = 0; for (int i = 0; i < _refreshTimes.InfoList.Length; i++) { var info = _refreshTimes.InfoList[i]; if (bigBoxNpcId == info.NPCID || smallBoxNpcId == info.NPCID) { containBox = true; boxRefreshSecond = (int)info.RefreshSecond; } if (eliteMonsters.Contains((int)info.NPCID)) { containElite = true; eliteRefreshSecond = (int)info.RefreshSecond; } } if (containBox) { dogzDungeonBox.UpdateBoxRefreshTime(boxRefreshSecond); } if (containElite) { dogzDungeonElite.UpdateEliteRefreshTime(eliteRefreshSecond); } if (WindowCenter.Instance.IsOpen("CrossServerBossWin")) { if (containBox) { RequestBoxSurplusInfo(); } if (containElite) { RequestEliteSurplusInfo(); } } } public void OnPlayerLoginOk() { UpdateRedpoint(); } private void OnFunctionStateChange(int id) { if (id == 162) { UpdateRedpoint(); } } public void UpdateRedpoint() { if (FuncOpen.Instance.IsFuncOpen(162) && TimeUtility.OpenDay >= GeneralDefine.crossServerOneVsOneOpenDay) { var wearyValueLimit = GeneralDefine.bossWearyValues[2]; var count = (wearyValueLimit - wearyValue) + (GeneralDefine.dogzBoxLimit - bigBoxCollectCount); redpoint.count = count; } else { redpoint.count = 0; } redpoint.state = redpoint.count > 0 ? RedPointState.Quantity : RedPointState.None; CrossServerUtility.UpdateCrossServerRedpoint(); } private void ParseConfig() { var configs = CrossServerBossConfig.GetValues(); foreach (var config in configs) { switch (config.MonsterType) { case 1: bigBoxNpcId = config.NPCID; break; case 2: smallBoxNpcId = config.NPCID; break; case 3: eliteMonsters.Add(config.NPCID); break; case 4: bosses[config.NPCID] = new CrossServerBossData(config.NPCID); sortedBossIds.Add(config.NPCID); break; } } sortedBossIds.Sort(CrossServerBossData.LevelCompare); } } public class CrossServerBossBox { public int bigBoxSurplus; public int smallBoxSurplus; public DateTime refreshTime { get; private set; } public event Action refreshTimeEvent; public void UpdateBoxInfo(int _big, int _small) { bigBoxSurplus = _big; smallBoxSurplus = _small; } public void UpdateBoxRefreshTime(int _seconds) { refreshTime = TimeUtility.ServerNow + new TimeSpan(_seconds * TimeSpan.TicksPerSecond); if (refreshTimeEvent != null) { refreshTimeEvent(); } } } public class CrossServerBossElite { public Dictionary eliteCounts = new Dictionary(); public int eliteSurplus { get { var count = 0; foreach (var eliteCount in eliteCounts.Values) { count += eliteCount; } return count; } } public DateTime refreshTime { get; private set; } public event Action refreshTimeEvent; public void UpdateEliteInfo(int _npcId, int _count) { eliteCounts[_npcId] = _count; } public void UpdateEliteRefreshTime(int _seconds) { refreshTime = TimeUtility.ServerNow + new TimeSpan(_seconds * TimeSpan.TicksPerSecond); if (refreshTimeEvent != null) { refreshTimeEvent(); } } public int GetAliveElite() { foreach (var EliteCount in eliteCounts) { if (EliteCount.Value > 0) { return EliteCount.Key; } } return 0; } } public class CrossServerBossData { public int id { get; private set; } public bool isUnLocked { get { return true; } } public CrossServerBossData(int _id) { this.id = _id; } public static int LevelCompare(int a, int b) { var configA = NPCConfig.Get(a); var configB = NPCConfig.Get(b); return configA.NPCLV < configB.NPCLV ? -1 : 1; } } }