using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
|
using System;
|
|
namespace Snxxz.UI
|
{
|
[XLua.LuaCallCSharp]
|
public class DogzDungeonModel : Model, IPlayerLoginOk
|
{
|
|
public const int DOGZDUNGEON_REDPOINT = 77002;
|
public const int DATA_MAPID = 21110;
|
|
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();
|
crossServerBossModel.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();
|
crossServerBossModel.UpdateRedpoint();
|
if (bigBoxCollectCountChangeEvent != null)
|
{
|
bigBoxCollectCountChangeEvent();
|
}
|
}
|
}
|
}
|
|
int m_SmallBoxCollectCount = 0;
|
public int smallBoxCollectCount {
|
get { return m_SmallBoxCollectCount; }
|
set { m_SmallBoxCollectCount = value; }
|
}
|
|
public event Action<int> bossSelectedEvent;
|
public event Action bossWearyValueChangeEvent;
|
public event Action bigBoxCollectCountChangeEvent;
|
public event Action boxSurplusChangeEvent;
|
public event Action eliteSurplusChangeEvent;
|
|
List<int> sortedBossIds = new List<int>();
|
Dictionary<int, DogzDungeonBossData> bosses = new Dictionary<int, DogzDungeonBossData>();
|
public DogzDungeonBox dogzDungeonBox = new DogzDungeonBox();
|
public DogzDungeonElite dogzDungeonElite = new DogzDungeonElite();
|
public Redpoint redpoint = new Redpoint(FindPreciousModel.LOOTPRECIOUs_REDPOINTID, DOGZDUNGEON_REDPOINT);
|
|
FindPreciousModel findPreciousModel { get { return ModelCenter.Instance.GetModel<FindPreciousModel>(); } }
|
CrossServerBossModel crossServerBossModel { get { return ModelCenter.Instance.GetModel<CrossServerBossModel>(); } }
|
|
public int bigBoxNpcId = 0;
|
public int smallBoxNpcId = 0;
|
public List<int> eliteMonsters = new List<int>();
|
|
public override void Init()
|
{
|
ParseConfig();
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFunctionStateChange;
|
}
|
|
public override void UnInit()
|
{
|
FuncOpen.Instance.OnFuncStateChangeEvent -= OnFunctionStateChange;
|
}
|
|
public bool TryGetBossData(int _bossId, out DogzDungeonBossData _data)
|
{
|
return bosses.TryGetValue(_bossId, out _data);
|
}
|
|
public List<int> GetNpcIds()
|
{
|
var npcIds = new List<int>();
|
npcIds.Add(bigBoxNpcId);
|
npcIds.Add(eliteMonsters[0]);
|
npcIds.AddRange(bosses.Keys);
|
|
return npcIds;
|
}
|
|
public List<int> GetBosses()
|
{
|
return new List<int>(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;
|
GameNetSystem.Instance.SendInfo(sendInfo);
|
}
|
|
public void RequestBoxSurplusInfo()
|
{
|
var sendInfo = new CA227_tagCMQueryNPCCntInfo();
|
sendInfo.MapID = DATA_MAPID;
|
sendInfo.LineID = 0;
|
sendInfo.NPCIDList = string.Format("[{0},{1}]", bigBoxNpcId, smallBoxNpcId);
|
sendInfo.NPCIDListLen = (byte)sendInfo.NPCIDList.Length;
|
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;
|
GameNetSystem.Instance.SendInfo(sendInfo);
|
}
|
|
public void UpdateMonsterSurplusInfo(HA714_tagMCNPCCntList _npcInfoes)
|
{
|
if (_npcInfoes.MapID != DATA_MAPID)
|
{
|
return;
|
}
|
|
var updatedBigBox = false;
|
var updatedSmallBox = false;
|
var updatedElite = false;
|
var updatedEliteNpcIds = new List<int>();
|
|
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);
|
updatedElite = true;
|
}
|
}
|
|
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("DogzDungeonWin"))
|
{
|
if (containBox)
|
{
|
RequestBoxSurplusInfo();
|
}
|
|
if (containElite)
|
{
|
RequestEliteSurplusInfo();
|
}
|
}
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
UpdateRedpoint();
|
}
|
|
private void OnFunctionStateChange(int id)
|
{
|
if (id == 138)
|
{
|
UpdateRedpoint();
|
}
|
}
|
|
private void UpdateRedpoint()
|
{
|
if (!FuncOpen.Instance.IsFuncOpen(138))
|
{
|
redpoint.count = 0;
|
}
|
else
|
{
|
var wearyValueLimit = GeneralDefine.bossWearyValues[2];
|
var count = (wearyValueLimit - wearyValue) + (GeneralDefine.dogzBoxLimit - bigBoxCollectCount);
|
redpoint.count = count;
|
}
|
|
redpoint.state = redpoint.count > 0 ? RedPointState.Quantity : RedPointState.None;
|
}
|
|
private void ParseConfig()
|
{
|
var configs = DogzDungeonConfig.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 DogzDungeonBossData(config.NPCID);
|
sortedBossIds.Add(config.NPCID);
|
break;
|
}
|
}
|
|
sortedBossIds.Sort(DogzDungeonBossData.LevelCompare);
|
}
|
|
}
|
|
public class DogzDungeonBox
|
{
|
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 DogzDungeonElite
|
{
|
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 DogzDungeonBossData
|
{
|
public int id { get; private set; }
|
public bool isUnLocked {
|
get {
|
return true;
|
}
|
}
|
|
public DogzDungeonBossData(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;
|
}
|
}
|
|
}
|