using System.Collections; using vnxbqy.UI; using UnityEngine.SceneManagement; using UnityEngine; using System; public class AdventureStage : Singleton { public bool IsInAdventureStage { get; private set; } private Vector3 m_CacheHeroPos; private GA_NpcClientFunc m_Npc; private GA_NpcClientCollect m_Precious; private SFXController m_SfxController; private bool dungeonFightWinOpenRecord = false; const int s_PreciousNpcId = 40208014; private uint preciousServerInstId = 0; public event Action onLoadAdventureStage; public event Action onExitAdventureStage; HazyRegionModel hazyRegionModel { get { return ModelCenter.Instance.GetModel(); } } public void Enter() { IsInAdventureStage = true; m_CacheHeroPos = PlayerDatas.Instance.hero.Pos; SnxxzGame.Instance.StartCoroutine(_Enter()); } public void Exit() { IsInAdventureStage = false; ClientDungeonStageUtility.RequestExitClientDungeon(); SnxxzGame.Instance.StartCoroutine(_Exit()); } private IEnumerator _Enter() { WindowCenter.Instance.Open(); WindowCenter.Instance.Close(); if (!AssetSource.sceneFromEditor) { AssetBundleUtility.Instance.Sync_LoadAll("maps/map140_qy"); } var waitTime = Time.time + 1f; var _async = SceneManager.LoadSceneAsync("Map140_Qy", LoadSceneMode.Additive); yield return _async; while (Time.time < waitTime) { yield return null; } var _hero = PlayerDatas.Instance.hero; if (_hero != null) { _hero.StopPathFind(); _hero.Behaviour.StopHandupAI(); _hero.Behaviour.StopKillUntilDieAI(); _hero.Pos = new Vector3(142f, 18.742f, 144f); } CameraController.Instance.Apply(); SoundPlayer.Instance.PlayBackGroundMusic(35); yield return null; WindowCenter.Instance.Close(); WindowCenter.Instance.Open(); dungeonFightWinOpenRecord = WindowCenter.Instance.IsOpen(); if (!dungeonFightWinOpenRecord) { WindowCenter.Instance.Open(); } BossShowModel.Instance.bossShowCompletedEvent -= BossShowCompletedEvent; BossShowModel.Instance.bossShowCompletedEvent += BossShowCompletedEvent; HazyRegionDialogueWin.onDialogueComplete -= OnDialogueComplete; HazyRegionDialogueWin.onDialogueComplete += OnDialogueComplete; if (onLoadAdventureStage != null) { onLoadAdventureStage(); } } private void BossShowCompletedEvent() { m_Npc = GAMgr.Instance.ReqClntNoFightNpc((uint)hazyRegionModel.GetAdventureNpcId(), E_ActorGroup.FuncNpc); m_Npc.Pos = new Vector3(142.551f, 18.742f, 145.981f); m_Npc.Rotation = Quaternion.Euler(0f, 185f, 0f); NPCInteractProcessor.s_NpcInteractEvent -= OnNpcTalkEvent; NPCInteractProcessor.s_NpcInteractEvent += OnNpcTalkEvent; SnxxzGame.Instance.StartCoroutine(Co_NpcTalk()); } IEnumerator Co_NpcTalk() { yield return WaitingForSecondConst.WaitMS500; if (m_Npc != null && !m_Npc.ActorInfo.serverDie) { m_Npc.OnClick(); } } private IEnumerator _Exit() { NPCInteractProcessor.s_NpcInteractEvent -= OnNpcTalkEvent; BossShowModel.Instance.bossShowCompletedEvent -= BossShowCompletedEvent; HazyRegionDialogueWin.onDialogueComplete -= OnDialogueComplete; ClientCollectUtility.OnCollectFinished -= OnCollectFinished; if (!m_Npc.ActorInfo.serverDie) { GAMgr.Instance.ServerDie(m_Npc.ServerInstID); GAMgr.Instance.Release(m_Npc); } if (m_Precious != null) { GAMgr.Instance.ServerDie(m_Precious.ServerInstID); GAMgr.Instance.Release(m_Precious); m_Precious = null; } if (m_SfxController != null) { SFXPlayUtility.Instance.Release(m_SfxController); m_SfxController = null; } WindowCenter.Instance.Open(); WindowCenter.Instance.Close(); if (SceneManager.GetSceneByName("Map140_Qy") != null) { var _async = SceneManager.UnloadSceneAsync("Map140_Qy"); yield return _async; if (!AssetSource.sceneFromEditor) { AssetBundleUtility.Instance.UnloadAssetBundle("maps/map140_qy", true, false); } } var _hero = PlayerDatas.Instance.hero; if (_hero != null) { _hero.Pos = m_CacheHeroPos; } CameraController.Instance.Apply(); var dataMapId = MapUtility.GetDataMapId(PlayerDatas.Instance.baseData.MapID); var mapResConfig = MapResourcesConfig.GetConfig(dataMapId, PlayerDatas.Instance.baseData.dungeonLineId); if (mapResConfig != null) { SoundPlayer.Instance.PlayBackGroundMusic(mapResConfig.Music); } yield return null; WindowCenter.Instance.Open(); WindowCenter.Instance.Close(); if (!dungeonFightWinOpenRecord) { WindowCenter.Instance.Close(); } if (onExitAdventureStage != null) { onExitAdventureStage(); } } private void OnDialogueComplete() { m_SfxController = SFXPlayUtility.Instance.Play(20039, m_Npc.Pos, Vector3.forward); m_Precious = GAMgr.Instance.ReqClntNoFightNpc(s_PreciousNpcId, E_ActorGroup.Collect); m_Precious.Pos = m_Npc.Pos; m_Precious.Rotation = Quaternion.Euler(0f, 185f, 0f); ClientSceneManager.Instance.lastDeadPos = m_Precious.Pos; preciousServerInstId = m_Precious.ServerInstID; PlayerDatas.Instance.hero.SelectTarget = m_Precious; if (!m_Npc.ActorInfo.serverDie) { GAMgr.Instance.ServerDie(m_Npc.ServerInstID); GAMgr.Instance.Release(m_Npc); } ClientCollectUtility.OnCollectFinished -= OnCollectFinished; ClientCollectUtility.OnCollectFinished += OnCollectFinished; if (hazyRegionModel.auto) { ClientCollectUtility.HandleCallback(E_NpcType.Collect, s_PreciousNpcId, m_Precious.ServerInstID); } } private void OnCollectFinished(uint sid) { if (preciousServerInstId == sid) { hazyRegionModel.SendSwitchAdventureState(hazyRegionModel.processingIncidentId, 3); } } private void OnNpcTalkEvent(E_NpcType type, int npcid, uint sid) { if (E_NpcType.Func == type) { if (m_Npc != null) { if (m_Npc.NpcConfig.NPCID == npcid && m_Npc.ServerInstID == sid) { if (!WindowCenter.Instance.IsOpen()) { hazyRegionModel.StartAdventureDialogue(); WindowCenter.Instance.Close(); } } } } } }