using System;
|
using System.Collections.Generic;
|
using vnxbqy.UI;
|
using UnityEngine;
|
using UnityEngine.Events;
|
|
public class ClientCollectUtility
|
{
|
public static List<GA_NpcClientCollect> m_ArriveList = new List<GA_NpcClientCollect>();
|
|
public static UnityAction<uint, int> OnShowCollectIcon;
|
public static UnityAction<uint, int> OnHideCollectIcon;
|
public static UnityAction<uint> OnCollectFinished;
|
|
private static bool m_StartCollect;
|
private static float m_CollectTime;
|
private static uint m_CurrentSID;
|
private static float m_CollectTotalTime;
|
|
public static void StartCollect(GA_NpcClientCollect npc)
|
{
|
if (m_StartCollect)
|
{
|
if (m_CurrentSID != npc.ServerInstID)
|
{
|
StopCollect();
|
}
|
return;
|
}
|
m_CollectTime = 0;
|
m_CurrentSID = npc.ServerInstID;
|
m_CollectTotalTime = 2 * (1 - VipPrivilegeConfig.GetVipPrivilegeData(8, PlayerDatas.Instance.baseData.VIPLv) * Constants.F_DELTA);
|
NormalCollectWin.s_CollectInfo = new PrepareHandler.ClientH0812()
|
{
|
PlayerID = PlayerDatas.Instance.PlayerId,
|
PrepareState = (byte)PrepareHandler.E_PrepareType.pstMissionCollecting,
|
MaxTime = m_CollectTotalTime * 1000,
|
PrepareID = npc.NpcConfig.NPCID,
|
};
|
PrepareHandler.Instance.isPreparing = true;
|
WindowCenter.Instance.Open<NormalCollectWin>();
|
m_StartCollect = true;
|
var _hero = PlayerDatas.Instance.hero;
|
if (_hero != null && !_hero.ActorInfo.serverDie)
|
{
|
_hero.Collect();
|
}
|
}
|
|
public static void StopCollect()
|
{
|
PrepareHandler.Instance.isPreparing = false;
|
WindowCenter.Instance.Close<NormalCollectWin>();
|
m_StartCollect = false;
|
var _hero = PlayerDatas.Instance.hero;
|
if (_hero != null && !_hero.ActorInfo.serverDie)
|
{
|
if (_hero.IsCollect() && _hero.NextAction == GAStaticDefine.Act_Collect)
|
{
|
_hero.IdleImmediate();
|
}
|
}
|
}
|
|
public static void Arrive(GA_NpcClientCollect npc)
|
{
|
if (!m_ArriveList.Contains(npc))
|
{
|
if (m_ArriveList.Count == 0)
|
{
|
if (OnShowCollectIcon != null)
|
{
|
OnShowCollectIcon(npc.ServerInstID, npc.NpcConfig.NPCID);
|
}
|
}
|
|
m_ArriveList.Add(npc);
|
}
|
}
|
|
public static void Leave(GA_NpcClientCollect npc)
|
{
|
if (m_ArriveList.Contains(npc))
|
{
|
m_ArriveList.Remove(npc);
|
if (m_ArriveList.Count == 0)
|
{
|
if (OnHideCollectIcon != null)
|
{
|
OnHideCollectIcon(npc.ServerInstID, npc.NpcConfig.NPCID);
|
}
|
}
|
}
|
}
|
|
public static void Init()
|
{
|
WindowCenter.Instance.windowAfterOpenEvent -= CheckOpenCollectIcon;
|
WindowCenter.Instance.windowAfterOpenEvent += CheckOpenCollectIcon;
|
WindowCenter.Instance.windowAfterCloseEvent -= CheckCloseCollectIcon;
|
WindowCenter.Instance.windowAfterCloseEvent += CheckCloseCollectIcon;
|
}
|
|
public static void HandleCallback(E_NpcType type, int npcID, uint sid)
|
{
|
var _hero = PlayerDatas.Instance.hero;
|
if (_hero != null)
|
{
|
var _npc = _hero.SelectTarget as GA_NpcClientCollect;
|
var _checkDis = 0f;
|
|
if (_npc == null || !(_npc is GA_NpcClientCollect))
|
{
|
var _list = GAMgr.Instance.GetTypeList(E_ActorClassType.NpcClientCollect);
|
if (_list != null)
|
{
|
_list.Sort((a1, a2) =>
|
{
|
var _d1 = MathUtility.DistanceSqrtXZ(a1.Pos, _hero.Pos);
|
var _d2 = MathUtility.DistanceSqrtXZ(a2.Pos, _hero.Pos);
|
if (_d1 > _d2)
|
{
|
return 1;
|
}
|
else if (_d1 < _d2)
|
{
|
return -1;
|
}
|
return 0;
|
});
|
|
foreach (var _a in _list)
|
{
|
if (!(_a is GA_NpcClientCollect))
|
{
|
continue;
|
}
|
|
_npc = _a as GA_NpcClientCollect;
|
break;
|
}
|
}
|
}
|
|
if (_npc != null)
|
{
|
if (_hero.SelectTarget == null || !(_hero.SelectTarget is GA_NpcClientCollect))
|
{
|
_hero.SelectTarget = _npc;
|
}
|
|
_checkDis = MathUtility.DistanceSqrtXZ(_hero.Pos, _npc.Pos);
|
|
if (_checkDis < 4f)
|
{
|
if (OnShowCollectIcon != null)
|
{
|
OnShowCollectIcon(_npc.ServerInstID, _npc.NpcConfig.NPCID);
|
}
|
|
var _model = ModelCenter.Instance.GetModel<HazyGrassModel>();
|
if (_model.CanCollectClientNpc(_npc.NpcConfig.NPCID))
|
{
|
StartCollect(_npc);
|
var _dir = MathUtility.ForwardXZ(_npc.Pos, _hero.Pos);
|
_hero.Forward = _dir;
|
}
|
else
|
{
|
_model.DisplayCollectErrorTip();
|
}
|
}
|
else
|
{
|
_hero.MoveToPosition(_npc.Pos, 1f);
|
}
|
}
|
}
|
}
|
|
public static void UnInit()
|
{
|
WindowCenter.Instance.windowAfterOpenEvent -= CheckOpenCollectIcon;
|
WindowCenter.Instance.windowAfterCloseEvent -= CheckCloseCollectIcon;
|
}
|
|
private static void CheckOpenCollectIcon(Window win)
|
{
|
GA_Hero _hero = PlayerDatas.Instance.hero;
|
if (_hero == null)
|
{
|
return;
|
}
|
|
if (win is MainInterfaceWin)
|
{
|
if (m_ArriveList.Count > 0)
|
{
|
if (OnShowCollectIcon != null)
|
{
|
var _collect = _hero.SelectTarget as GA_NpcClientCollect;
|
if (_collect == null)
|
{
|
_collect = m_ArriveList[0];
|
}
|
|
OnShowCollectIcon(_collect.ServerInstID, _collect.NpcConfig.NPCID);
|
}
|
}
|
}
|
}
|
|
private static void CheckCloseCollectIcon(Window win)
|
{
|
if (win is MainInterfaceWin)
|
{
|
if (OnHideCollectIcon != null)
|
{
|
OnHideCollectIcon(0, 0);
|
}
|
}
|
}
|
|
public static void Update()
|
{
|
if (m_StartCollect)
|
{
|
GA_Hero _hero = PlayerDatas.Instance.hero;
|
|
if (_hero.SkillMgr.CurCastSkill != null && !_hero.SkillMgr.CurCastSkill.SkillCompelete)
|
{
|
return;
|
}
|
|
m_CollectTime += Time.deltaTime;
|
|
if (m_CollectTime > m_CollectTotalTime)
|
{
|
StopCollect();
|
|
GA_NpcClientCollect _npc = null;
|
|
if (m_CurrentSID > 0)
|
{
|
_npc = GAMgr.Instance.GetBySID(m_CurrentSID) as GA_NpcClientCollect;
|
|
if (_npc != null)
|
{
|
if (_npc.belongEventID != -1)
|
{
|
ClientSceneManager.Instance.NpcDead(_npc.belongEventID, _npc, _npc.NpcConfig.NPCID);
|
}
|
|
if (_hero != null)
|
{
|
if (_hero.LockTarget == _npc)
|
{
|
_hero.LockTarget = null;
|
}
|
if (_hero.SelectTarget == _npc)
|
{
|
_hero.SelectTarget = null;
|
}
|
}
|
|
GAMgr.Instance.Release(_npc);
|
}
|
|
if (OnCollectFinished != null)
|
{
|
OnCollectFinished(m_CurrentSID);
|
}
|
|
if (DungeonStage.CurrentMapType == MapType.OpenCountry)
|
{
|
var _list = GAMgr.Instance.GetTypeList(E_ActorClassType.NpcClientCollect);
|
if (_list != null)
|
{
|
foreach (var _next in _list)
|
{
|
if (_next is GA_NpcClientCollect)
|
{
|
var _collect = _next as GA_NpcClientCollect;
|
MapTransferUtility.Instance.MoveToNPC(_collect.NpcConfig.NPCID);
|
}
|
}
|
}
|
}
|
}
|
}
|
|
if (_hero.IsCollect())
|
{
|
if (!_hero.IsIdle() && !(_hero.NextAction == GAStaticDefine.Act_Collect))
|
{
|
StopCollect();
|
}
|
}
|
|
if (_hero.SelectTarget != null)
|
{
|
if (_hero.SelectTarget.ServerInstID != m_CurrentSID)
|
{
|
StopCollect();
|
}
|
}
|
}
|
}
|
|
}
|