using vnxbqy.UI; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; //公共材料副本 public class ClientCommonDungeonStage : DungeonStage { //static readonly Vector3 s_PlayerPosition = new Vector3(16.19f, 0.825f, 7.62f); //static readonly Vector3 s_NpcPosition = new Vector3(11.9f, 0.825f, 9.64f); //static readonly float s_PlayerAngle = -70.925f; static int[] s_StepTimes = null; static Clock s_StepClock = null; Step m_Step = Step.None; public Step step { get { return m_Step; } set { if (m_Step != value) { switch (m_Step) { case Step.Prepare: OnExitPrepare(); break; case Step.Fight: OnExitFight(); break; } m_Step = value; switch (m_Step) { case Step.Prepare: OnEnterPrepare(); break; case Step.Fight: OnEnterFight(); break; case Step.Over: OnEnterOver(); break; } } } } GA_NpcClientFightBoss s_ClientBoss = null; List s_ClientNpcs = new List(); FBGeneralTrainConfig dungeonInfo = null; DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel(); } } CommonDungeonSelectModel model { get { return ModelCenter.Instance.GetModel(); } } public override void Initialize() { base.Initialize(); step = Step.None; var dungeonConfig = DungeonConfig.Get(dungeonModel.currentDungeon.mapId * 10); if (dungeonConfig != null) { s_StepTimes = LitJson.JsonMapper.ToObject(dungeonConfig.StepTime); } dungeonModel.onDungeonResultEvent += OnDungeonResultEvent; PersonalEnemy.OnNpcAppear += OnNpcAppear; } protected override void OnStageLoadFinish() { base.OnStageLoadFinish(); dungeonInfo = FBGeneralTrainConfig.GetDungeonInfo(dungeonModel.currentDungeon.mapId, dungeonModel.currentDungeon.lineId); if (dungeonInfo == null) { ClientDungeonStageUtility.ExitNormalClientDungeon(); return; } InitializePlayer(); step = Step.Prepare; DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += PlayerLoginOk; } void InitializePlayer() { var hero = PlayerDatas.Instance.hero; if (hero != null) { hero.Pos = new Vector3(dungeonInfo.PlayerPos[0], dungeonInfo.PlayerPos[1], dungeonInfo.PlayerPos[2]); ; hero.Rotation = Quaternion.Euler(0, dungeonInfo.Angle, 0); } CameraController.Instance.Apply(); } void OnEnterPrepare() { var seconds = s_StepTimes[0]; dungeonModel.UpdateCoolDown(DungeonCoolDownType.WaitStart, (uint)seconds * 1000); s_StepClock = Clock.AlarmAfter(seconds, () => { step = Step.Fight; }); } void OnExitPrepare() { if (s_StepClock != null) { Clock.Stop(s_StepClock); s_StepClock = null; } } void OnEnterFight() { InitializeNpc(); var seconds = s_StepTimes[1]; dungeonModel.UpdateCoolDown(DungeonCoolDownType.FightStart, (uint)seconds * 1000); s_StepClock = Clock.AlarmAfter(seconds, () => { ClientDungeonStageUtility.ExitNormalClientDungeon(); }); } private void OnExitFight() { if (s_StepClock != null) { Clock.Stop(s_StepClock); s_StepClock = null; } } private void OnEnterOver() { var seconds = s_StepTimes[2]; dungeonModel.UpdateCoolDown(DungeonCoolDownType.LeaveMap, (uint)seconds * 1000); s_StepClock = Clock.AlarmAfter(seconds, () => { ClientDungeonStageUtility.ExitNormalClientDungeon(); }); } void InitializeNpc() { if (dungeonInfo == null) FBGeneralTrainConfig.GetDungeonInfo(dungeonModel.currentDungeon.mapId, dungeonModel.currentDungeon.lineId); uint hp = 0; uint hpEx = 0; var position = new Vector3(dungeonInfo.NPCPosList[0][0], dungeonInfo.NPCPosList[0][1], dungeonInfo.NPCPosList[0][2]); if (s_ClientBoss != null) { hp = (uint)(s_ClientBoss.ActorInfo.Hp % Constants.ExpPointValue); hpEx = (uint)(s_ClientBoss.ActorInfo.Hp / Constants.ExpPointValue); position = s_ClientBoss.Pos; PersonalEnemy.Release(s_ClientBoss); } PersonalEnemy.Create((uint)dungeonInfo.BossNPCID, E_ActorGroup.Enemy, position, hp, hpEx); Dictionary npcHpInfo = new Dictionary(); //用于重登时恢复npc血量 if (s_ClientNpcs.Count != 0) { foreach (var npc in s_ClientNpcs) { hp = (uint)(npc.ActorInfo.Hp % Constants.ExpPointValue); hpEx = (uint)(npc.ActorInfo.Hp / Constants.ExpPointValue); npcHpInfo[npc.NpcConfig.NPCID] = new Int2((int)hp, (int)hpEx); PersonalEnemy.Release(npc); } s_ClientNpcs.Clear(); } for (int i = 0; i < dungeonInfo.OtherNPCIDList.Length; i++) { var npcID = dungeonInfo.OtherNPCIDList[i]; if (npcHpInfo.ContainsKey(npcID)) { hp = (uint)npcHpInfo[npcID].x; hpEx = (uint)npcHpInfo[npcID].y; } else { hp = 0; hpEx = 0; } Vector3 npcPos = new Vector3(); if (i + 1 < dungeonInfo.NPCPosList.Length) { npcPos = new Vector3(dungeonInfo.NPCPosList[i + 1][0], dungeonInfo.NPCPosList[i + 1][1], dungeonInfo.NPCPosList[i + 1][2]); } PersonalEnemy.Create((uint)npcID, E_ActorGroup.Enemy, npcPos, hp, hpEx); } } private void OnDungeonResultEvent() { step = Step.Over; } private void PlayerLoginOk() { if (step < Step.Over) { InitializeNpc(); } } public override void UnInitialize() { base.UnInitialize(); dungeonModel.onDungeonResultEvent -= OnDungeonResultEvent; PersonalEnemy.OnNpcAppear -= OnNpcAppear; DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= PlayerLoginOk; if (s_ClientBoss != null) { s_ClientBoss = null; } if (s_ClientNpcs.Count != 0) { s_ClientNpcs.Clear(); } if (s_StepClock != null) { Clock.Stop(s_StepClock); s_StepClock = null; } } private void OnNpcAppear(GA_NpcClientFightNorm _npc) { if (_npc != null && _npc is GA_NpcClientFightBoss) { if (_npc.NpcConfig.NPCID == dungeonInfo.BossNPCID) s_ClientBoss = _npc as GA_NpcClientFightBoss; else { s_ClientNpcs.Add(_npc as GA_NpcClientFightBoss); } } } #if UNITY_EDITOR private void OnGUI() { if (GUILayout.Button("Exit")) { ClientDungeonStageUtility.ExitNormalClientDungeon(); } } #endif public enum Step { None, Prepare, Fight, Over, } }