using System;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
|
namespace vnxbqy.UI
|
{
|
|
public class BossFirstBloodModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk, IOpenServerActivity
|
{
|
|
|
ImpactRankModel impactRankModel
|
{
|
get
|
{
|
return ModelCenter.Instance.GetModel<ImpactRankModel>();
|
}
|
}
|
|
public int selectIndex = 0;
|
public int selectNPCID = 0;
|
|
public struct FirstKillTimeInfo
|
{
|
public string name;
|
public string time;
|
}
|
|
Dictionary<int, int> FirstKillStateInfo = new Dictionary<int, int>(); // 击杀奖励状态
|
public Dictionary<int, FirstKillTimeInfo> firstKillTimeInfo = new Dictionary<int, FirstKillTimeInfo>(); // 首杀名和时间
|
private Dictionary<int, Redpoint> m_Redpoints = new Dictionary<int, Redpoint>();
|
private Dictionary<int, Redpoint> m_RedPackRedpoints = new Dictionary<int, Redpoint>();
|
|
public List<string> npcIDConfig;
|
public bool IsOpen
|
{
|
get
|
{
|
return impactRankModel.IsOpen;
|
}
|
}
|
|
public bool priorityOpen
|
{
|
get
|
{
|
//var state = impactRankRedpoint.state;
|
//return state == RedPointState.Simple || state == RedPointState.GetReward;
|
return false;
|
}
|
}
|
|
public const int Redpoint_BossKillRank = 25900;
|
public Redpoint rankRedpoint = new Redpoint(MainRedDot.REDPOINT_OPENRANK, Redpoint_BossKillRank);
|
|
public bool IsAdvance
|
{
|
get
|
{
|
return false;
|
}
|
}
|
|
|
public Int2 GetFirstNPCRedPoint()
|
{
|
//先找红点,没有红点则找最低级未领奖励的BOSS
|
Int2 npcinfo = Int2.zero;
|
int i = 0;
|
foreach (var key in npcIDConfig)
|
{
|
var npcID = int.Parse(key);
|
var _redpoint = m_Redpoints[npcID];
|
if (_redpoint.state != RedPointState.None)
|
{
|
npcinfo.x = i;
|
npcinfo.y = npcID;
|
return npcinfo;
|
}
|
i++;
|
}
|
i = 0;
|
foreach (var key in npcIDConfig)
|
{
|
var npcID = int.Parse(key);
|
var state = GetPersonalKillAwardState(npcID);
|
if (GetPersonalKillAwardState(npcID) != 2)
|
{
|
npcinfo.x = i;
|
npcinfo.y = npcID;
|
return npcinfo;
|
}
|
i++;
|
}
|
return npcinfo;
|
}
|
|
public void UpdateAllRedPoint()
|
{
|
foreach (var _key in m_Redpoints.Keys)
|
{
|
UpdateRedPoint(_key, GetPersonalKillAwardState(_key) == 1 ? RedPointState.Simple : RedPointState.None);
|
}
|
}
|
|
public void UpdateRedPoint(int npcID, RedPointState state)
|
{
|
var _redpoint = m_Redpoints[npcID];
|
|
_redpoint.state = m_RedPackRedpoints[npcID].state == RedPointState.None ? state : m_RedPackRedpoints[npcID].state;
|
}
|
|
|
public event Action<int> onStateUpdate;
|
|
public override void Init()
|
{
|
OpenServerActivityCenter.Instance.Register(100, this);
|
InitNpcInfo();
|
DTCA003_tagUniversalGameRecInfo.onGetUniversalGameInfo += OnGetUniversalGameInfo;
|
}
|
private void SendGameRec()
|
{
|
var pak = new CA001_tagViewUniversalGameRec();
|
pak.ViewType = 31;
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
public event Action<int> OnFirstKillInfo;
|
private void OnGetUniversalGameInfo(HA003_tagUniversalGameRecInfo package)
|
{
|
if (package.Type == 31)
|
{
|
for (int i = 0; i < package.Count; i++)
|
{
|
int npcID = (int)package.UniversalGameRec[i].Value1;
|
firstKillTimeInfo[(int)package.UniversalGameRec[i].Value1] = new FirstKillTimeInfo()
|
{
|
name = package.UniversalGameRec[i].StrValue3,
|
time = package.UniversalGameRec[i].StrValue2,
|
|
};
|
if (!WindowCenter.Instance.IsOpen<BossFirstBloodWin>() && OnFirstKillInfo != null)
|
OnFirstKillInfo(npcID);
|
}
|
UpdateAllRedPackPoint();
|
UpdateAllRedPoint();
|
}
|
|
}
|
|
public int GetBossKillAwardState(int npcID)
|
{
|
//0 未击杀 1 可领取 2 已领取
|
if (firstKillTimeInfo.ContainsKey(npcID) && !string.IsNullOrEmpty(firstKillTimeInfo[npcID].name))
|
{
|
//无数据为可领取
|
if (!FirstKillStateInfo.ContainsKey(npcID)) return 1;
|
|
int state = FirstKillStateInfo[npcID];
|
if (state/10 % 10 == 0)
|
return 1;
|
else
|
return 2;
|
}
|
return 0;
|
}
|
public void UpdateAllRedPackPoint()
|
{
|
foreach (var _key in m_RedPackRedpoints.Keys)
|
{
|
UpdateRedPackPoint(_key);
|
}
|
}
|
|
public void UpdateRedPackPoint(int npcID)
|
{
|
var state = GetBossKillAwardState(npcID) == 1 ? RedPointState.Simple : RedPointState.None;
|
m_RedPackRedpoints[npcID].state = state;
|
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
FirstKillStateInfo.Clear();
|
firstKillTimeInfo.Clear();
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
SendGameRec();
|
}
|
|
public void InitNpcInfo()
|
{
|
npcIDConfig = BOSSFirstKillConfig.GetKeys();
|
npcIDConfig.Sort((string x, string y) =>
|
{
|
var infoX = BOSSFirstKillConfig.Get(x);
|
var infoY = BOSSFirstKillConfig.Get(y);
|
return infoX.Sort.CompareTo(infoY.Sort);
|
});
|
|
foreach (var key in npcIDConfig)
|
{
|
var npcID = int.Parse(key);
|
var infoX = BOSSFirstKillConfig.Get(key);
|
m_Redpoints.Add(npcID, new Redpoint(Redpoint_BossKillRank, Redpoint_BossKillRank * 100 + infoX.Sort));
|
m_RedPackRedpoints.Add(npcID, new Redpoint(Redpoint_BossKillRank * 100 + infoX.Sort, (Redpoint_BossKillRank * 100 + infoX.Sort)*10));
|
|
}
|
}
|
|
public int GetNPCRedPackPointID(int npcID)
|
{
|
var infoX = BOSSFirstKillConfig.Get(npcID);
|
return (Redpoint_BossKillRank * 100 + infoX.Sort) * 10;
|
|
}
|
|
public override void UnInit()
|
{
|
DTCA003_tagUniversalGameRecInfo.onGetUniversalGameInfo -= OnGetUniversalGameInfo;
|
}
|
public event Action<int> UpdatePersonnalKillEvent;
|
public void BossFirstKillStateInfo(HAB01_tagMCBossFirstKillStateInfo package)
|
{
|
for (int i=0; i < package.BossCount; i++)
|
{
|
FirstKillStateInfo[(int)package.FirstKillStateList[i].NPCID] = (int)package.FirstKillStateList[i].FKState;
|
if (UpdatePersonnalKillEvent != null)
|
UpdatePersonnalKillEvent((int)package.FirstKillStateList[i].NPCID);
|
}
|
UpdateAllRedPackPoint();
|
UpdateAllRedPoint();
|
}
|
|
public int GetPersonalKillAwardState(int npcID)
|
{
|
//0 未击杀 1 可领取 2 已领取
|
if (FirstKillStateInfo.ContainsKey(npcID))
|
{
|
int state = FirstKillStateInfo[npcID];
|
if (state % 10 == 0)
|
return 0;
|
if (state % 10 > 0 && state/100 == 0)
|
return 1;
|
if (state % 10 > 0 && state / 100 == 1)
|
return 2;
|
}
|
return 0;
|
}
|
|
public bool IsAlreadyFirstKill(int npcID)
|
{
|
if (firstKillTimeInfo.ContainsKey(npcID))
|
return true;
|
return false;
|
}
|
}
|
}
|