using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Linq; using System; using TableConfig; namespace Snxxz.UI { public class BossShowModel : Singleton { public BossShowModel() { BossShowing = false; showTargetList = new List(); TimeMgr.Instance.OnSyntonyEvent += OnSyntonyEvent; StageManager.Instance.onStageLoadFinish += OnStageLoadFinish; } GameObject bossShowCam; private ActorShowConfig actorShowModel; PlayerTaskDatas m_TaskModel; PlayerTaskDatas taskmodel { get { return m_TaskModel ?? (m_TaskModel = ModelCenter.Instance.GetModel()); } } public int NpcID { get; private set; } public int reqDungeonLineId = -1; public List showTargetList { get; private set; } public bool BossShowing { get; private set; } public Camera showCamera { get; private set; } private bool serverNotify = false; private int cacheMapId = 0; private const string BOSS_SHOW_KEY = "BossShow"; public event Action bossShowPreparedEvent; public event Action bossShowCompletedEvent; public void StartBossShow(int npcId) { try { reqDungeonLineId = -1; if (!ActorShowConfig.GetActorShowModel(PlayerDatas.Instance.baseData.MapID, npcId, out actorShowModel)) { return; } if (actorShowModel.BindMissionID != 0) { MissionDetailDates missionDetailDates = null; taskmodel.allMissionDict.TryGetValue(actorShowModel.BindMissionID, out missionDetailDates); if (missionDetailDates == null || missionDetailDates.MissionState != 1) { return; } if (GetMisstionShow(actorShowModel.BindMissionID)) { return; } SetMisstionShow(actorShowModel.BindMissionID); } if (BossShowing && StageManager.Instance.CurrentStage is DungeonStage) { return; } BossShowing = true; NpcID = npcId; if (actorShowModel.type != 3) { ActiveBossModel(true); } ActiveBossShowCam(true); CameraController.Instance.CameraObject.enabled = false; if (WindowCenter.Instance.CheckOpen()) { WindowJumpMgr.Instance.ClearJumpData(); WindowCenter.Instance.CloseImmediately(); WindowCenter.Instance.Open(); } ActiveUI(false); var _hero = PlayerDatas.Instance.hero; if (_hero != null && !_hero.ActorInfo.serverDie) { _hero.Behaviour.StopHandupAI(); } TimeMgr.Instance.Register(TimeMgr.SyntonyType.BossShow, (float)actorShowModel.length / 1000); if (actorShowModel.showNameTime > 0) { TimeMgr.Instance.Register(TimeMgr.SyntonyType.BossShowName, (float)actorShowModel.showNameTime / 1000); } if (actorShowModel.Dialogue > 0 && actorShowModel.DialogueTime > 0) { TimeMgr.Instance.Register(TimeMgr.SyntonyType.BossShowDialogue, (float)actorShowModel.DialogueTime / 1000); } if (actorShowModel.soundId > 0) { if (actorShowModel.soundTime == 0) { PlaySound(actorShowModel.soundId); } else { TimeMgr.Instance.Register(TimeMgr.SyntonyType.BossShowSound, (float)actorShowModel.soundTime / 1000); } } if (bossShowPreparedEvent != null) { bossShowPreparedEvent(); } } catch (Exception e) { BossShowing = false; Debug.LogError(e.Message); } } public void StopBossShow() { if (!BossShowing) { return; } BossShowing = false; SoundPlayer.Instance.musicAudioSource.mute = false; ActiveBossShowCam(false); if (NpcID != 0) { ActiveBossModel(false); } ActiveDialogue(false); CameraController.Instance.CameraObject.enabled = true; ActiveUI(true); if (serverNotify) { CA223_tagCMNPCShowEnd pak = new CA223_tagCMNPCShowEnd(); pak.EndType = 0; pak.NPCID = (uint)NpcID; GameNetSystem.Instance.SendInfo(pak); } var _handleFight = true; if (ActorShowConfig.GetActorShowModel(PlayerDatas.Instance.baseData.MapID, NpcID, out actorShowModel)) { if (actorShowModel.type == 3 || actorShowModel.type == 2) { _handleFight = false; CB104_tagCMClientStartFB _pak = new CB104_tagCMClientStartFB(); GameNetSystem.Instance.SendInfo(_pak); } if (actorShowModel.type == 3) { SendGuideComplete((DungeonShowType)actorShowModel.NpcID); } } var _hero = PlayerDatas.Instance.hero; if (_handleFight && _hero != null && !_hero.ActorInfo.serverDie) { int _dgDataID = ModelCenter.Instance.GetModel().GetDataMapIdByMapId(PlayerDatas.Instance.baseData.MapID); var dungeonOpen = Config.Instance.Get(_dgDataID); if (dungeonOpen != null) { if (dungeonOpen.DoFight == 1) { _hero.Behaviour.StartHandupAI(); } } else { _hero.Behaviour.StartHandupAI(); } } if (bossShowCompletedEvent != null) { bossShowCompletedEvent(); } } private void OnSyntonyEvent(TimeMgr.SyntonyType type) { if (type == TimeMgr.SyntonyType.BossShow) { StopBossShow(); } else if (type == TimeMgr.SyntonyType.BossShowName) { ActiveBossName(); } else if (type == TimeMgr.SyntonyType.BossShowDialogue) { ActiveDialogue(true); } else if (type == TimeMgr.SyntonyType.BossShowSound) { if (actorShowModel != null) { PlaySound(actorShowModel.soundId); } } } private void PlaySound(int _soundId) { SoundPlayer.Instance.musicAudioSource.mute = true; SoundPlayer.Instance.PlayUIAudio(_soundId); } private void ActiveBossShowCam(bool _active) { var prefab = UILoader.LoadPrefab(actorShowModel.cam); if (_active && (actorShowModel.type == 3 || showTargetList.Count > 0)) { bossShowCam = UnityEngine.Object.Instantiate(prefab); RaycastHit _hit; var _pos = actorShowModel.type == 3 ? new Vector3((float)actorShowModel.PosX[0] / 200, 0, actorShowModel.PosY[0] / 200) : showTargetList[0].m_Model.transform.position; var _origin = _pos; if (actorShowModel.Height.Length > 1) { _origin.x = (float)actorShowModel.Height[0] / 200; _origin.y = 0; _origin.z = (float)actorShowModel.Height[1] / 200; } _origin.y = 100f; Ray _ray = new Ray(_origin, Vector3.down); float height = 0; if (Physics.Raycast(_ray, out _hit, 100f, LayerUtility.WalkbleMask)) { height = _hit.point.y; } showCamera = GetBossShowCam(bossShowCam.transform); bossShowCam.transform.position = actorShowModel.type == 3 ? _pos.SetY(height) : showTargetList[0].m_Model.transform.position.SetY(height); if (actorShowModel != null) { bossShowCam.transform.rotation = MathUtility.GetClientRotationFromAngle(actorShowModel.NpcFace[0]); } else { bossShowCam.transform.rotation = showTargetList[0].m_Model.transform.rotation; } bossShowCam.SetActive(true); } else { if (bossShowCam != null) { bossShowCam.SetActive(false); UnityEngine.Object.Destroy(bossShowCam); } } } public void ActiveBossModel(bool _active) { if (!_active) { if (showTargetList.Count > 0) { for (int i = 0; i < showTargetList.Count; i++) { List list = GetShowActor(showTargetList[i].npcId); if (list == null) { list = new List(); showActorDic.Add(showTargetList[i].npcId, list); } showTargetList[i].Disappear(); list.Add(showTargetList[i]); } } showTargetList.Clear(); } else { showTargetList.Clear(); for (int i = 0; i < actorShowModel.NpcFace.Length; i++) { List list = GetShowActor(actorShowModel.showNpcs[i]); ShowActor showActor = null; if (list != null && list.Count > 0) { showActor = list[0]; list.RemoveAt(0); } if (showActor == null) { var _instanceid = GetInstanceId(); showActor = new ShowActor(actorShowModel.showNpcs[i], i, _instanceid, actorShowModel); m_ShowActorInstanceDict.Add(_instanceid, showActor); } else { showActor.Appear(i, actorShowModel); } showTargetList.Add(showActor); } } } private void ActiveUI(bool _active) { UIRoot uiRoot = WindowCenter.Instance.uiRoot; uiRoot.EnableCanvas(_active, uiRoot.baseCanvas, uiRoot.lifeBarCanvas, uiRoot.nameCanvas, uiRoot.normalCanvas, uiRoot.modalCanvas, uiRoot.tipsCanvas, uiRoot.systemCanvas, uiRoot.recycleBin, uiRoot.fightCanvasGroup.damageNumGroups[0].parent); if (!_active) { CameraUtility.RemoveCullingMask(CameraManager.uiCamera, LayerUtility.UIEffectLayer); if (!WindowCenter.Instance.CheckOpen()) { WindowCenter.Instance.Open(); } } else { CameraUtility.AddCullingMask(CameraManager.uiCamera, LayerUtility.UIEffectLayer); if (WindowCenter.Instance.CheckOpen()) { WindowCenter.Instance.Close(); } } } public event Action OnBossNameEvent; public void ActiveBossName() { if (OnBossNameEvent != null) { OnBossNameEvent(); } } private void ActiveDialogue(bool _show) { if (_show && !WindowCenter.Instance.CheckOpen()) { var _task = ModelCenter.Instance.GetModel(); _task._TaskNow = actorShowModel.Dialogue; WindowCenter.Instance.Open(); } else if (!_show && WindowCenter.Instance.CheckOpen()) { WindowCenter.Instance.CloseImmediately(); } } public Transform GetBossShowCamAnimator(Transform parent) { Animator animator = parent.GetComponent(); if (animator != null) { return parent; } foreach (Transform child in parent) { var trans = GetBossShowCamAnimator(child); if (trans == null) { continue; } else { return trans; } } return null; } public Camera GetBossShowCam(Transform parent) { Camera cam = parent.GetComponent(); if (cam != null) { return cam; } foreach (Transform child in parent) { cam = GetBossShowCam(child); if (cam == null) { continue; } else { return cam; } } return null; } public void OnNpcAppear(int npcID) { if (BossShowing) { return; } if (!ActorShowConfig.GetActorShowModel(PlayerDatas.Instance.baseData.MapID, npcID, out actorShowModel)) { return; } if (actorShowModel.BindMissionID == 0 || actorShowModel.type == 2) { return; } serverNotify = false; StartBossShow(npcID); } private bool GetMisstionShow(int missionID) { return LocalSave.GetBool(StringUtility.Contact(BOSS_SHOW_KEY, PlayerDatas.Instance.PlayerId, missionID)); } public void SetMisstionShow(int missionID, bool value = true) { LocalSave.SetBool(StringUtility.Contact(BOSS_SHOW_KEY, PlayerDatas.Instance.PlayerId, missionID), value); } public void StartBossShow(uint npcID) { if (BossShowing) { return; } if (!ActorShowConfig.GetActorShowModel(PlayerDatas.Instance.baseData.MapID, (int)npcID, out actorShowModel)) { return; } if (actorShowModel.type != 0) { return; } serverNotify = true; StartBossShow((int)npcID); } private void OnStageLoadFinish() { if (PlayerDatas.Instance.baseData.MapID == cacheMapId) { return; } cacheMapId = PlayerDatas.Instance.baseData.MapID; var dic = Config.Instance.GetAllValues(); ActorShowConfig _showModel = null; foreach (var cfg in dic) { if (cfg.MapID == PlayerDatas.Instance.baseData.MapID && (cfg.line == 1000 || cfg.line == reqDungeonLineId) && cfg.type == 2) { _showModel = cfg; break; } else if (cfg.MapID == PlayerDatas.Instance.baseData.MapID && cfg.type == 3) { SnxxzGame.Instance.StartCoroutine(Co_StartSceneShow(cfg)); return; } } if (_showModel != null) { SnxxzGame.Instance.StartCoroutine(Co_StartBossShow(_showModel)); } } IEnumerator Co_StartBossShow(ActorShowConfig _showModel) { StartBossShow(_showModel.NpcID); yield return null; } IEnumerator Co_StartSceneShow(ActorShowConfig _showModel) { if (GetState((DungeonShowType)_showModel.NpcID)) { yield break; } var _dungeonCfg = Config.Instance.Get(_showModel.MapID); if (_dungeonCfg != null && _dungeonCfg.FBType != 1) { var _team = ModelCenter.Instance.GetModel(); if (_team.myTeam.GetOnlineMemberCount() > 1) { SetState((DungeonShowType)_showModel.NpcID); SendGuideComplete((DungeonShowType)_showModel.NpcID); yield break; } } SetState((DungeonShowType)_showModel.NpcID); StartBossShow(_showModel.NpcID); yield return null; } public Dictionary> showActorDic = new Dictionary>(); public List GetShowActor(int npcID) { List list = null; showActorDic.TryGetValue(npcID, out list); return list; } private Dictionary m_ShowActorInstanceDict = new Dictionary(); public ShowActor GetShowActorInstance(int _instance) { if (m_ShowActorInstanceDict.ContainsKey(_instance)) { return m_ShowActorInstanceDict[_instance]; } return null; } private static int presentInstanceId = 0; public int GetInstanceId() { return presentInstanceId++; } private List m_DungeonStates = new List(); public void UpdateState(uint[] _states) { if (_states == null) { return; } var _start = (int)DungeonShowType.None / 31; if (_start < _states.Length) { var _index = 0; for (int i = _start; i < _states.Length; i++) { if (m_DungeonStates.Count <= _index) { m_DungeonStates.Add(_states[i]); } else { m_DungeonStates[_index] = _states[i]; } _index++; } } } public bool GetState(DungeonShowType _type) { int _key = (int)_type; var _start = _key / 31 - (int)DungeonShowType.None / 31; var _index = _key - (_key / 31) * 31; if (_start < m_DungeonStates.Count && _start >= 0) { return MathUtility.GetBitValue(m_DungeonStates[_start], (ushort)_index); } return false; } public void SetState(DungeonShowType _type, bool _state = true) { int _key = (int)_type; var _start = _key / 31 - (int)DungeonShowType.None / 31; var _index = _key - (_key / 31) * 31; if (_start >= m_DungeonStates.Count) { m_DungeonStates.Add((uint)MathUtility.SetBitValue(0, (ushort)_index, _state)); } else { m_DungeonStates[_start] = (uint)MathUtility.SetBitValue((int)m_DungeonStates[_start], (ushort)_index, _state); } } private void SendGuideComplete(DungeonShowType _type, bool _state = true) { CA222_tagCMSetGuideOK _pak = new CA222_tagCMSetGuideOK(); _pak.GuideIndex = (byte)_type; _pak.IsOK = _state ? (byte)1 : (byte)0; GameNetSystem.Instance.SendInfo(_pak); } public enum DungeonShowType : byte { None = 200, DemonJar = 201, FairyLand = 202, } } }