//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, April 10, 2019
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
|
public class HazyDemonKingDungeonWin : Window
|
{
|
[SerializeField] CyclicScroll m_CyclicScroll;
|
[SerializeField] Text m_MyAtkTargetName;
|
|
[SerializeField] Transform m_ContainerInvincibleBuff;
|
[SerializeField] SmoothSlider m_BuffSlider;
|
|
|
DateTime invincibleBuffEndTime = DateTime.Now;
|
uint invincibleLastTime = 0;
|
|
uint myAtkSid = 0;
|
|
List<uint> playerIds = new List<uint>();
|
List<uint> clonePlayerIds = new List<uint>();
|
|
HazyDemonKingModel model { get { return ModelCenter.Instance.GetModel<HazyDemonKingModel>(); } }
|
DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
|
|
#region Built-in
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
}
|
|
protected override void OnPreOpen()
|
{
|
Display();
|
|
model.onPlayerInfoRefresh += OnPlayerInfoRefresh;
|
StatusMgr.onReceiveStatus += OnReceiveStatus;
|
GlobalTimeEvent.Instance.secondEvent += PerSecond;
|
}
|
|
protected override void OnAfterOpen()
|
{
|
}
|
|
protected override void OnPreClose()
|
{
|
m_CyclicScroll.Dispose();
|
model.onPlayerInfoRefresh -= OnPlayerInfoRefresh;
|
StatusMgr.onReceiveStatus -= OnReceiveStatus;
|
GlobalTimeEvent.Instance.secondEvent -= PerSecond;
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
|
protected override void LateUpdate()
|
{
|
if (TimeUtility.ServerNow < invincibleBuffEndTime)
|
{
|
m_BuffSlider.delay = 0.2f;
|
DisplayInvincibleProgress();
|
}
|
}
|
#endregion
|
|
void Display()
|
{
|
DisplayPlayers();
|
DisplayMyTargetName();
|
DisplayInvincibleBuff();
|
}
|
|
void DisplayPlayers()
|
{
|
playerIds.Clear();
|
clonePlayerIds.Clear();
|
playerIds.AddRange(model.GetPlayerIds());
|
playerIds.Sort(Compare);
|
clonePlayerIds.AddRange(playerIds);
|
|
m_CyclicScroll.Init(playerIds);
|
}
|
|
void DisplayInvincibleBuff()
|
{
|
var actors = GAMgr.Instance.GetTypeList(E_ActorClassType.NpcFightBoss);
|
bool existInvincibleBuff = false;
|
|
Status_Base status_Base = null;
|
|
if (actors != null && actors.Count > 0)
|
{
|
var serverInstId = (actors[0] as GA_NpcFightBoss).ServerInstID;
|
existInvincibleBuff = StatusMgr.Instance.IsExist(serverInstId, model.invincibleBuffId);
|
|
if (existInvincibleBuff)
|
{
|
status_Base = StatusMgr.Instance.Get(serverInstId, model.invincibleBuffId);
|
}
|
}
|
|
m_ContainerInvincibleBuff.gameObject.SetActive(existInvincibleBuff);
|
|
if (existInvincibleBuff && status_Base != null)
|
{
|
invincibleBuffEndTime = status_Base.receiveTime.AddTicks(status_Base.h0605.LastTime * TimeSpan.TicksPerMillisecond);
|
invincibleLastTime = status_Base.h0605.LastTime;
|
}
|
m_BuffSlider.delay = 0f;
|
DisplayInvincibleProgress();
|
}
|
|
void DisplayInvincibleProgress()
|
{
|
var milliSeconds = Mathf.CeilToInt((float)(invincibleBuffEndTime - TimeUtility.ServerNow).TotalMilliseconds);
|
if (invincibleLastTime == 0)
|
{
|
invincibleLastTime = (uint)milliSeconds;
|
}
|
var progress = Mathf.Clamp01(1 - (float)milliSeconds / invincibleLastTime);
|
m_BuffSlider.value = progress;
|
}
|
|
private void OnPlayerInfoRefresh()
|
{
|
DisplayPlayers();
|
}
|
|
private void OnReceiveStatus(int buffId)
|
{
|
if (buffId == model.invincibleBuffId)
|
{
|
DisplayInvincibleBuff();
|
}
|
}
|
|
private void PerSecond()
|
{
|
if (clonePlayerIds.Count > 0)
|
{
|
clonePlayerIds.Sort(Compare);
|
}
|
|
if (clonePlayerIds.Count == playerIds.Count)
|
{
|
for (int i = 0; i < clonePlayerIds.Count; i++)
|
{
|
if (clonePlayerIds[i] != playerIds[i])
|
{
|
DisplayPlayers();
|
return;
|
}
|
}
|
}
|
|
var _sid = model.GetPlayerAtkTarget(PlayerDatas.Instance.PlayerId);
|
if (_sid != myAtkSid)
|
{
|
DisplayMyTargetName();
|
}
|
}
|
|
void DisplayMyTargetName()
|
{
|
m_MyAtkTargetName.text = string.Empty;
|
|
myAtkSid = model.GetPlayerAtkTarget(PlayerDatas.Instance.PlayerId);
|
var actor = GAMgr.Instance.GetBySID(myAtkSid);
|
|
if (actor != null)
|
{
|
if (actor is GA_NpcClientFightBoss)
|
{
|
m_MyAtkTargetName.text = (actor as GA_NpcClientFightBoss).NpcConfig.charName;
|
}
|
else if (actor is GA_NpcFightBoss)
|
{
|
m_MyAtkTargetName.text = (actor as GA_NpcFightBoss).NpcConfig.charName;
|
}
|
else if (actor is GA_Player)
|
{
|
m_MyAtkTargetName.text = UIHelper.ServerStringTrim((actor as GA_Player).ActorInfo.PlayerName);
|
}
|
}
|
}
|
|
int Compare(uint lhs, uint rhs)
|
{
|
var lhs_bossBelong = model.IsExistBelongTo(lhs);
|
var rhs_bossBelong = model.IsExistBelongTo(rhs);
|
if (lhs_bossBelong != rhs_bossBelong)
|
{
|
return -lhs_bossBelong.CompareTo(rhs_bossBelong);
|
}
|
var playerId = PlayerDatas.Instance.baseData.PlayerID;
|
var lhs_atkself = model.GetPlayerAtkTarget(lhs) == playerId;
|
var rhs_atkself = model.GetPlayerAtkTarget(rhs) == playerId;
|
if (lhs_atkself != rhs_atkself)
|
{
|
return -lhs_atkself.CompareTo(rhs_atkself);
|
}
|
return 0;
|
}
|
}
|
|
}
|
|
|
|
|