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<int> sortedBossIds = new List<int>();
|
Dictionary<int, CrossServerBossData> bosses = new Dictionary<int, CrossServerBossData>();
|
|
public int bigBoxNpcId = 0;
|
public int smallBoxNpcId = 0;
|
public List<int> eliteMonsters = new List<int>();
|
|
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);
|
}
|
}
|
}
|
}
|
|
int m_WearyValue = 0;
|
public int wearyValue {
|
get { return m_WearyValue; }
|
set {
|
if (m_WearyValue != value)
|
{
|
m_WearyValue = value;
|
UpdateRedpoint();
|
if (bossWearyValueChangeEvent != null)
|
{
|
bossWearyValueChangeEvent();
|
}
|
}
|
}
|
}
|
|
int m_BigBoxCollectCount = 0;
|
public int bigBoxCollectCount {
|
get { return m_BigBoxCollectCount; }
|
set {
|
if (m_BigBoxCollectCount != value)
|
{
|
m_BigBoxCollectCount = value;
|
UpdateRedpoint();
|
if (bigBoxCollectCountChangeEvent != null)
|
{
|
bigBoxCollectCountChangeEvent();
|
}
|
}
|
}
|
}
|
|
int m_SmallBoxCollectCount = 0;
|
public int smallBoxCollectCount {
|
get { return m_SmallBoxCollectCount; }
|
set { m_SmallBoxCollectCount = value; }
|
}
|
|
public event Action bossWearyValueChangeEvent;
|
public event Action<int> bossSelectedEvent;
|
public event Action bigBoxCollectCountChangeEvent;
|
public event Action boxSurplusChangeEvent;
|
public event Action eliteSurplusChangeEvent;
|
|
public CrossServerBossBox boxInfo = new CrossServerBossBox();
|
public CrossServerBossElite eliteInfo = new CrossServerBossElite();
|
public Redpoint redpoint = new Redpoint(FindPreciousModel.LOOTPRECIOUs_REDPOINTID, REDPOINT);
|
|
FindPreciousModel findPreciousModel { get { return ModelCenter.Instance.GetModel<FindPreciousModel>(); } }
|
TeamModel teamModel { get { return ModelCenter.Instance.GetModel<TeamModel>(); } }
|
|
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<PlayerDeadModel>();
|
if (deadModel.playerIsDie)
|
{
|
error = 5;
|
return false;
|
}
|
|
var config = CrossServerBossConfig.Get(selectedBoss);
|
if (config.MonsterType == 4 && !findPreciousModel.IsBossUnlock(selectedBoss))
|
{
|
error = 6;
|
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;
|
case 6:
|
SysNotifyMgr.Instance.ShowTip("BossRealmHint2", NPCConfig.Get(selectedBoss).Realm);
|
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<int> GetNpcIds()
|
{
|
var npcIds = new List<int>();
|
npcIds.Add(bigBoxNpcId);
|
npcIds.Add(eliteMonsters[0]);
|
|
var lockedCount = 0;
|
foreach (var bossId in bosses.Keys)
|
{
|
if (findPreciousModel.IsBossUnlock(bossId))
|
{
|
npcIds.Add(bossId);
|
}
|
else
|
{
|
if (lockedCount < 2)
|
{
|
lockedCount++;
|
npcIds.Add(bossId);
|
}
|
}
|
}
|
|
return npcIds;
|
}
|
|
public List<int> GetShowBosses()
|
{
|
return new List<int>(sortedBossIds);
|
}
|
|
public int GetRecommendNpc()
|
{
|
if (bigBoxCollectCount < GeneralDefine.dogzBoxLimit)
|
{
|
return bigBoxNpcId;
|
}
|
|
if (wearyValue < GeneralDefine.bossWearyValues[2])
|
{
|
var preferBoss = 0;
|
for (int i = sortedBossIds.Count - 1; i >= 0; i--)
|
{
|
var bossId = sortedBossIds[i];
|
if (IsBossUnLocked(bossId))
|
{
|
if (preferBoss == 0)
|
{
|
preferBoss = bossId;
|
}
|
|
if (findPreciousModel.IsBossAlive(bossId) && findPreciousModel.IsSameBigRealmStageBoss(bossId))
|
{
|
return bossId;
|
}
|
}
|
}
|
|
if (preferBoss == 0)
|
{
|
preferBoss = sortedBossIds[0];
|
}
|
|
return preferBoss;
|
}
|
|
return eliteMonsters[0];
|
}
|
|
public int GetRecommendKillElite()
|
{
|
var Elite = eliteInfo.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) && findPreciousModel.IsBossUnlock(bossId);
|
}
|
|
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<int>();
|
|
for (int i = 0; i < _npcInfoes.NPCInfoList.Length; i++)
|
{
|
var npcInfo = _npcInfoes.NPCInfoList[i];
|
if (npcInfo.NPCID == bigBoxNpcId)
|
{
|
boxInfo.bigBoxSurplus = (int)npcInfo.Cnt;
|
updatedBigBox = true;
|
}
|
|
if (npcInfo.NPCID == smallBoxNpcId)
|
{
|
boxInfo.smallBoxSurplus = (int)npcInfo.Cnt;
|
updatedSmallBox = true;
|
}
|
|
if (eliteMonsters.Contains((int)npcInfo.NPCID))
|
{
|
eliteInfo.UpdateEliteInfo((int)npcInfo.NPCID, (int)npcInfo.Cnt);
|
updatedEliteNpcIds.Add((int)npcInfo.NPCID);
|
}
|
}
|
|
if (!updatedBigBox)
|
{
|
boxInfo.bigBoxSurplus = 0;
|
}
|
|
if (!updatedSmallBox)
|
{
|
boxInfo.smallBoxSurplus = 0;
|
}
|
|
if (boxSurplusChangeEvent != null)
|
{
|
boxSurplusChangeEvent();
|
}
|
|
foreach (var item in eliteMonsters)
|
{
|
if (!updatedEliteNpcIds.Contains(item))
|
{
|
eliteInfo.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)
|
{
|
boxInfo.UpdateBoxRefreshTime(boxRefreshSecond);
|
}
|
|
if (containElite)
|
{
|
eliteInfo.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<int, int> eliteCounts = new Dictionary<int, int>();
|
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 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;
|
}
|
}
|
|
}
|