| | |
| | | { |
| | | public static UnityAction<uint> OnCollectFinished; |
| | | private static List<uint> m_ArrivedList = new List<uint>(); |
| | | public static event UnityAction<uint, int> OnArrive; |
| | | public static event UnityAction<uint, int> OnLeave; |
| | | |
| | | private bool m_IsMainWinOpen = false; |
| | | |
| | | protected override void OnInit(GameNetPackBasic package) |
| | | { |
| | | base.OnInit(package); |
| | | |
| | | WindowCenter.Instance.windowAfterOpenEvent += CheckOpenCollectIcon; |
| | | WindowCenter.Instance.windowAfterCloseEvent += AfterCloseMainWin; |
| | | |
| | | NPCInteractProcessor.s_NpcInteractEvent += HandleCallback; |
| | | } |
| | | |
| | | private void HandleCallback(E_NpcType type, int npcID, uint sid) |
| | | { |
| | | var _hero = PlayerDatas.Instance.hero; |
| | | if (_hero != null) |
| | | { |
| | | if (_hero.SelectTarget == null) |
| | | { |
| | | if (sid == ServerInstID) |
| | | { |
| | | OnClick(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | var _collect = _hero.SelectTarget as GA_NpcClientCollect; |
| | | if (_collect != null) |
| | | { |
| | | float _chkDistSqrt = MathUtility.DistanceSqrtXZ(_hero.Pos, _collect.Pos); |
| | | |
| | | // 这里判断是否要走向此对象 |
| | | if (_chkDistSqrt < 4) |
| | | { |
| | | if (OnArrive != null) |
| | | { |
| | | OnArrive(_collect.ServerInstID, _collect.NpcConfig.NPCID); |
| | | } |
| | | |
| | | var _model = ModelCenter.Instance.GetModel<HazyGrassModel>(); |
| | | if (_model.CanCollectClientNpc(_collect.NpcConfig.NPCID)) |
| | | { |
| | | _collect.StartCollect(); |
| | | } |
| | | else |
| | | { |
| | | _model.DisplayCollectErrorTip(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | _hero.MoveToPosition(_collect.Pos, 1.5f); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (sid == ServerInstID) |
| | | { |
| | | OnClick(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | protected override void OnUnit() |
| | | { |
| | | base.OnUnit(); |
| | | |
| | | if (m_ArrivedList.Contains(ServerInstID)) |
| | | { |
| | | m_ArrivedList.Remove(ServerInstID); |
| | | } |
| | | |
| | | if (OnLeave != null) |
| | | { |
| | | OnLeave(ServerInstID, NpcConfig.NPCID); |
| | | } |
| | | |
| | | WindowCenter.Instance.windowAfterOpenEvent -= CheckOpenCollectIcon; |
| | | WindowCenter.Instance.windowAfterCloseEvent -= AfterCloseMainWin; |
| | | } |
| | | |
| | | private void CheckOpenCollectIcon(Window obj) |
| | | { |
| | | if (obj is MainInterfaceWin) |
| | | { |
| | | m_IsMainWinOpen = true; |
| | | |
| | | if (NpcConfig.NPCID != GeneralDefine.GatherSoulDZ) |
| | | { |
| | | GA_Hero _hero = PlayerDatas.Instance.hero; |
| | | |
| | | if (_hero != null) |
| | | { |
| | | float _distSqrt = MathUtility.DistanceSqrtXZ(_hero.Pos, Pos); |
| | | |
| | | if (_distSqrt < Mathf.Pow(NpcConfig.ModelRadius + 0.4f + GeneralDefine.CloseNpcDist, 2)) |
| | | { |
| | | Arrive(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void AfterCloseMainWin(Window obj) |
| | | { |
| | | if (obj is MainInterfaceWin) |
| | | { |
| | | m_IsMainWinOpen = false; |
| | | Leave(); |
| | | } |
| | | ClientCollectUtility.Leave(this); |
| | | } |
| | | |
| | | public override void OnClick() |
| | |
| | | float _chkDistSqrt = MathUtility.DistanceSqrtXZ(_hero.Pos, Pos); |
| | | |
| | | // 这里判断是否要走向此对象 |
| | | if (_chkDistSqrt < 4) |
| | | { |
| | | if (OnArrive != null) |
| | | { |
| | | OnArrive(ServerInstID, NpcConfig.NPCID); |
| | | } |
| | | |
| | | var _model = ModelCenter.Instance.GetModel<HazyGrassModel>(); |
| | | if (_model.CanCollectClientNpc(NpcConfig.NPCID)) |
| | | { |
| | | StartCollect(); |
| | | } |
| | | else |
| | | { |
| | | _model.DisplayCollectErrorTip(); |
| | | } |
| | | } |
| | | else |
| | | if (_chkDistSqrt > 4) |
| | | { |
| | | _hero.MoveToPosition(Pos, 1.5f); |
| | | } |
| | | } |
| | | |
| | | private bool m_StartCollect; |
| | | private float m_CollectTime; |
| | | |
| | | public void StartCollect() |
| | | { |
| | | if (m_StartCollect) |
| | | { |
| | | return; |
| | | } |
| | | m_CollectTime = 0; |
| | | NormalCollectWin.s_CollectInfo = new PrepareHandler.ClientH0812() |
| | | { |
| | | PlayerID = PlayerDatas.Instance.PlayerId, |
| | | PrepareState = (byte)PrepareHandler.E_PrepareType.pstMissionCollecting, |
| | | MaxTime = 2000, |
| | | PrepareID = 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 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.IdleImmediate(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | protected override void OnUpdate() |
| | | { |
| | | if (m_StartCollect) |
| | | { |
| | | GA_Hero m_Hero = PlayerDatas.Instance.hero; |
| | | |
| | | m_CollectTime += Time.deltaTime; |
| | | |
| | | if (m_CollectTime > 2f) |
| | | { |
| | | StopCollect(); |
| | | |
| | | if (m_Hero != null) |
| | | { |
| | | if (m_Hero.LockTarget == this) |
| | | { |
| | | m_Hero.LockTarget = null; |
| | | } |
| | | if (m_Hero.SelectTarget == this) |
| | | { |
| | | m_Hero.SelectTarget = null; |
| | | } |
| | | } |
| | | |
| | | if (belongEventID != -1) |
| | | { |
| | | ClientSceneManager.Instance.NpcDead(belongEventID, this, NpcConfig.NPCID); |
| | | } |
| | | else |
| | | { |
| | | if (OnCollectFinished != null) |
| | | { |
| | | OnCollectFinished(ServerInstID); |
| | | } |
| | | } |
| | | |
| | | GAMgr.Instance.Release(this); |
| | | } |
| | | |
| | | if (!m_Hero.IsIdle() && !m_Hero.IsCollect()) |
| | | { |
| | | StopCollect(); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | public override void OnUnSelect() |
| | | { |
| | | base.OnUnSelect(); |
| | | if (OnLeave != null) |
| | | { |
| | | OnLeave(ServerInstID, NpcConfig.NPCID); |
| | | } |
| | | |
| | | ClientCollectUtility.Leave(this); |
| | | } |
| | | |
| | | protected override void OnFixedUpdate() |
| | |
| | | |
| | | if (_distSqrt < Mathf.Pow(NpcConfig.ModelRadius + 0.4f + GeneralDefine.CloseNpcDist, 2)) |
| | | { |
| | | Arrive(); |
| | | ClientCollectUtility.Arrive(this); |
| | | } |
| | | else |
| | | { |
| | | Leave(); |
| | | ClientCollectUtility.Leave(this); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void Arrive() |
| | | { |
| | | if (OnArrive != null) |
| | | { |
| | | OnArrive(ServerInstID, NpcConfig.NPCID); |
| | | } |
| | | |
| | | if (!m_ArrivedList.Contains(ServerInstID)) |
| | | { |
| | | m_ArrivedList.Add(ServerInstID); |
| | | } |
| | | } |
| | | |
| | | public void Leave() |
| | | { |
| | | if (m_ArrivedList.Contains(ServerInstID)) |
| | | { |
| | | if (OnLeave != null) |
| | | { |
| | | OnLeave(ServerInstID, NpcConfig.NPCID); |
| | | } |
| | | m_ArrivedList.Remove(ServerInstID); |
| | | } |
| | | } |
| | | } |