using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using TableConfig;
|
using System;
|
|
namespace Snxxz.UI
|
{
|
public class DogzDungeonModel : Model
|
{
|
|
public const int DOGZDUNGEON_REDPOINT = 76009;
|
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;
|
if (bossWearyValueChangeEvent != null)
|
{
|
bossWearyValueChangeEvent();
|
}
|
}
|
}
|
}
|
|
int m_BigBoxCollectCount = 0;
|
public int bigBoxCollectCount
|
{
|
get { return m_BigBoxCollectCount; }
|
set
|
{
|
if (m_BigBoxCollectCount != value)
|
{
|
m_BigBoxCollectCount = value;
|
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();
|
Redpoint redpoint = new Redpoint(DOGZDUNGEON_REDPOINT);
|
|
FindPreciousModel findPreciousModel { get { return ModelCenter.Instance.GetModel<FindPreciousModel>(); } }
|
|
public int bigBoxNpcId = 0;
|
public int smallBoxNpcId = 0;
|
public List<int> eliteMonsters = new List<int>();
|
|
public override void Init()
|
{
|
ParseConfig();
|
}
|
|
public override void UnInit()
|
{
|
}
|
|
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 < 2) //未疲劳
|
{
|
return bigBoxNpcId;//大宝箱npc id
|
}
|
|
if (wearyValue < GeneralConfig.Instance.bossWearyValues[2])
|
{
|
var playerLevel = PlayerDatas.Instance.baseData.LV;
|
for (int i = sortedBossIds.Count - 1; i >= 0; i--)
|
{
|
var bossId = sortedBossIds[i];
|
var dogzConfig = Config.Instance.Get<DogzDungeonConfig>(bossId);
|
if (dogzConfig.MonsterType == 3 || dogzConfig.MonsterType == 4)
|
{
|
var npcConfig = Config.Instance.Get<NPCConfig>(bossId);
|
if (IsBossUnLocked(bossId) && findPreciousModel.IsBossAlive(bossId) && playerLevel >= npcConfig.NPCLV)
|
{
|
return bossId;
|
}
|
}
|
}
|
|
return sortedBossIds[0];
|
}
|
|
return bigBoxNpcId;//大宝箱 npcid
|
}
|
|
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 updatedBox = false;
|
var updatedElite = false;
|
for (int i = 0; i < _npcInfoes.NPCInfoList.Length; i++)
|
{
|
var npcInfo = _npcInfoes.NPCInfoList[i];
|
if (npcInfo.NPCID == bigBoxNpcId)
|
{
|
dogzDungeonBox.bigBoxSurplus = (int)npcInfo.Cnt;
|
updatedBox = true;
|
}
|
|
if (npcInfo.NPCID == smallBoxNpcId)
|
{
|
dogzDungeonBox.smallBoxSurplus = (int)npcInfo.Cnt;
|
updatedBox = true;
|
}
|
|
if (eliteMonsters.Contains((int)npcInfo.NPCID))
|
{
|
dogzDungeonElite.UpdateEliteInfo((int)npcInfo.NPCID, (int)npcInfo.Cnt);
|
updatedElite = true;
|
}
|
}
|
|
if (updatedBox)
|
{
|
if (boxSurplusChangeEvent != null)
|
{
|
boxSurplusChangeEvent();
|
}
|
}
|
|
if (updatedElite)
|
{
|
if (eliteSurplusChangeEvent != null)
|
{
|
eliteSurplusChangeEvent();
|
}
|
}
|
|
}
|
|
public void UpdateBoxOrEliteRefreshTime(HA904_tagGCDogzNPCRefreshTime _refreshTimes)
|
{
|
for (int i = 0; i < _refreshTimes.InfoList.Length; i++)
|
{
|
var info = _refreshTimes.InfoList[i];
|
if (bigBoxNpcId == info.NPCID || smallBoxNpcId == info.NPCID)
|
{
|
dogzDungeonBox.UpdateBoxRefreshTime((int)info.RefreshSecond);
|
RequestBoxSurplusInfo();
|
}
|
|
if (eliteMonsters.Contains((int)info.NPCID))
|
{
|
dogzDungeonElite.UpdateEliteRefreshTime((int)info.RefreshSecond);
|
RequestEliteSurplusInfo();
|
}
|
}
|
}
|
|
private void ParseConfig()
|
{
|
var configs = Config.Instance.GetAllValues<DogzDungeonConfig>();
|
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 = DateTime.Now + new TimeSpan(_seconds * TimeSpan.TicksPerSecond);
|
DebugEx.Log("宝箱刷新时间:" + refreshTime);
|
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 = DateTime.Now + new TimeSpan(_seconds * TimeSpan.TicksPerSecond);
|
if (refreshTimeEvent != null)
|
{
|
refreshTimeEvent();
|
}
|
DebugEx.Log("精英刷新时间:" + refreshTime);
|
}
|
|
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
|
{
|
var config = Config.Instance.Get<NPCConfig>(id);
|
return PlayerDatas.Instance.baseData.LV >= config.NPCLV;
|
}
|
}
|
|
public DogzDungeonBossData(int _id)
|
{
|
this.id = _id;
|
}
|
|
public static int LevelCompare(int a, int b)
|
{
|
var configA = Config.Instance.Get<NPCConfig>(a);
|
var configB = Config.Instance.Get<NPCConfig>(b);
|
|
return configA.NPCLV < configB.NPCLV ? -1 : 1;
|
}
|
}
|
|
}
|