//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, April 10, 2019
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
|
public class HazyDemonKingDungeonWin : Window
|
{
|
[SerializeField] Transform m_ContainerDungeonInfo;
|
[SerializeField] CyclicScroll m_CyclicScroll;
|
[SerializeField] HazyDemonKingPlayerBehaviour m_BelongToPlayer;
|
[SerializeField] RectTransform m_ContainerPlayerList;
|
[SerializeField] Text m_MyAtkTargetName;
|
|
[SerializeField] Transform m_ContainerInvincibleBuff;
|
[SerializeField] SmoothSlider m_BuffSlider;
|
|
[SerializeField] Vector3[] m_PlayerListPositions;
|
[SerializeField] Vector2 m_PlayerListSize;
|
|
|
DateTime invincibleBuffEndTime = DateTime.Now;
|
uint invincibleLastTime = 0;
|
|
uint myAtkSid = 0;
|
|
List<uint> playerIds = new List<uint>();
|
List<uint> clonePlayerIds = new List<uint>();
|
|
uint belongToPlayerId = 0;
|
|
private int dungeonType
|
{
|
get
|
{
|
var incidentId = hazyRegionModel.GetIncidentId(ClientDungeonStageUtility.dungeonInfo.mapId, ClientDungeonStageUtility.dungeonInfo.lineId);
|
var config = HazyRegionConfig.Get(incidentId);
|
if (config != null)
|
{
|
return config.dungeonType;
|
}
|
return 0;
|
}
|
}
|
|
HazyDemonKingModel model { get { return ModelCenter.Instance.GetModel<HazyDemonKingModel>(); } }
|
HazyRegionModel hazyRegionModel { get { return ModelCenter.Instance.GetModel<HazyRegionModel>(); } }
|
DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
|
|
#region Built-in
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
}
|
|
protected override void OnPreOpen()
|
{
|
model.onPlayerInfoRefresh += OnPlayerInfoRefresh;
|
StatusMgr.onReceiveStatus += OnReceiveStatus;
|
GlobalTimeEvent.Instance.secondEvent += PerSecond;
|
}
|
|
protected override void OnActived()
|
{
|
base.OnActived();
|
Display();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
}
|
|
protected override void OnPreClose()
|
{
|
m_BelongToPlayer.Dispose();
|
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();
|
}
|
else
|
{
|
if (m_ContainerInvincibleBuff.gameObject.activeSelf)
|
{
|
m_ContainerInvincibleBuff.SetActive(false);
|
}
|
}
|
}
|
#endregion
|
|
void Display()
|
{
|
m_ContainerDungeonInfo.SetActive(dungeonType != 0);
|
|
DisplayBelongTo();
|
DisplayPlayers();
|
DisplayMyTargetName();
|
DisplayInvincibleBuff();
|
}
|
|
void DisplayPlayers()
|
{
|
if (dungeonType == 0)
|
{
|
return;
|
}
|
|
playerIds.Clear();
|
clonePlayerIds.Clear();
|
|
foreach (var sid in model.GetPlayerIds())
|
{
|
if (!model.IsExistBelongTo(sid))
|
{
|
playerIds.Add(sid);
|
}
|
}
|
|
playerIds.Sort(Compare);
|
clonePlayerIds.AddRange(playerIds);
|
|
m_CyclicScroll.Init(playerIds);
|
}
|
|
void DisplayBelongTo()
|
{
|
if (dungeonType == 0)
|
{
|
return;
|
}
|
|
belongToPlayerId = 0;
|
foreach (var sid in model.GetPlayerIds())
|
{
|
if (model.IsExistBelongTo(sid))
|
{
|
belongToPlayerId = sid;
|
}
|
}
|
|
m_BelongToPlayer.Dispose();
|
if (belongToPlayerId == 0)
|
{
|
m_BelongToPlayer.SetActive(false);
|
m_ContainerPlayerList.localPosition = m_PlayerListPositions[1];
|
m_ContainerPlayerList.sizeDelta = m_ContainerPlayerList.sizeDelta.SetY(m_PlayerListSize.y);
|
m_CyclicScroll.rectTransform.localPosition = Vector3.zero;
|
m_CyclicScroll.rectTransform.sizeDelta = m_CyclicScroll.rectTransform.sizeDelta.SetY(m_PlayerListSize.y);
|
return;
|
}
|
m_ContainerPlayerList.sizeDelta = m_ContainerPlayerList.sizeDelta.SetY(m_PlayerListSize.x);
|
m_ContainerPlayerList.localPosition = m_PlayerListPositions[0];
|
m_CyclicScroll.rectTransform.localPosition = Vector3.zero;
|
m_CyclicScroll.rectTransform.sizeDelta = m_CyclicScroll.rectTransform.sizeDelta.SetY(m_PlayerListSize.x);
|
m_BelongToPlayer.SetActive(true);
|
m_BelongToPlayer.Display(belongToPlayerId);
|
}
|
|
void DisplayInvincibleBuff()
|
{
|
bool existInvincibleBuff = false;
|
Status_Base status_Base = null;
|
uint serverInstId = 0;
|
|
if (dungeonType != 0)
|
{
|
var actors = GAMgr.Instance.GetTypeList(E_ActorClassType.NpcFightBoss);
|
if (actors != null && actors.Count > 0)
|
{
|
serverInstId = (actors[0] as GA_NpcFightBoss).ServerInstID;
|
existInvincibleBuff = StatusMgr.Instance.IsExist(serverInstId, model.invincibleBuffId);
|
}
|
}
|
else
|
{
|
serverInstId = ClientHazyDemonKingStage.GetClientBossSid();
|
existInvincibleBuff = StatusMgr.Instance.IsExist(serverInstId, model.invincibleBuffId);
|
}
|
|
|
if (existInvincibleBuff)
|
{
|
status_Base = StatusMgr.Instance.Get(serverInstId, model.invincibleBuffId);
|
}
|
|
m_ContainerInvincibleBuff.SetActive(existInvincibleBuff);
|
|
if (existInvincibleBuff && status_Base != null)
|
{
|
invincibleBuffEndTime = status_Base.receiveTime.AddTicks(status_Base.LastTime * TimeSpan.TicksPerMillisecond);
|
invincibleLastTime = (uint)status_Base.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((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 (dungeonType == 0)
|
{
|
return;
|
}
|
|
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();
|
}
|
|
if (!model.IsExistBelongTo(belongToPlayerId))
|
{
|
foreach (var sid in model.GetPlayerIds())
|
{
|
if (model.IsExistBelongTo(sid))
|
{
|
belongToPlayerId = sid;
|
DisplayBelongTo();
|
DisplayPlayers();
|
break;
|
}
|
}
|
}
|
}
|
|
void DisplayMyTargetName()
|
{
|
if (dungeonType == 0)
|
{
|
return;
|
}
|
|
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)
|
{
|
bool lhs_isMySelf = lhs == PlayerDatas.Instance.PlayerId;
|
bool rhs_isMySelf = rhs == PlayerDatas.Instance.PlayerId;
|
if (lhs_isMySelf != rhs_isMySelf)
|
{
|
return lhs_isMySelf.CompareTo(rhs_isMySelf);
|
}
|
|
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;
|
}
|
}
|
|
}
|
|
|
|
|