| | |
| | | using TowerDefense.Towers.Data; |
| | | using TowerDefense.Towers.Placement; |
| | | using UnityEngine; |
| | | using UnityEngine.UI; |
| | | using KTGMGemClient; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | |
| | | [RequireComponent(typeof(EndlessWaveManager))] |
| | | public class EndlessLevelManager : Singleton<EndlessLevelManager> |
| | | { |
| | | /// <summary> |
| | | /// 起始关卡 |
| | | /// </summary>' |
| | | /// <value></value> |
| | | protected int startLevel { get; set; } = 1; |
| | | |
| | | /// <summary> |
| | | /// 当前的关卡等级 |
| | | /// </summary> |
| | |
| | | /// </summary> |
| | | public List<Node> StartingNodeList; |
| | | |
| | | public List<Node> EndNodeList; |
| | | |
| | | /// <summary> |
| | | /// 已经完成的关卡数量 |
| | | /// </summary> |
| | |
| | | /// 新手第一关是否完成 |
| | | /// </summary> |
| | | private bool isFirstLevelCompleted = false; |
| | | |
| | | private bool isStopSecondWaveCompleted = false; |
| | | |
| | | /// <summary> |
| | | /// 赛道长度 |
| | | /// </summary> |
| | | private float tunelLength; |
| | | |
| | | private List<Vector3> homeBasePositionList; |
| | | |
| | | /// <summary> |
| | | /// 根据赛道id(1~5)获得基地坐标 |
| | | /// </summary> |
| | | /// <param name="tunelId"></param> |
| | | /// <returns></returns> |
| | | public Vector3 GetHomeBasePosition(int tunelId) |
| | | { |
| | | return homeBasePositionList[tunelId - 1]; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据赛道id(1~5)和赛道类型获得世界坐标 |
| | | /// </summary> |
| | | /// <param name="tunelId"></param> |
| | | /// <param name="tunelType"></param> |
| | | public Vector3 GetTunelWorldPosition(int tunelId, EndlessBossSkillTunelType tunelType) |
| | | { |
| | | Vector3 startPos = StartingNodeList[tunelId - 1].transform.position; |
| | | Vector3 ret = new Vector3(startPos.x, startPos.y, startPos.z); |
| | | float add = 0; |
| | | |
| | | switch (tunelType) |
| | | { |
| | | case EndlessBossSkillTunelType.Top: |
| | | break; |
| | | case EndlessBossSkillTunelType.Center: |
| | | add = -(tunelLength / 2); |
| | | break; |
| | | case EndlessBossSkillTunelType.Bottom: |
| | | add = -tunelLength; |
| | | break; |
| | | } |
| | | |
| | | ret.z += add; |
| | | |
| | | return ret; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 切换基地 |
| | |
| | | // Iterate through home bases and subscribe |
| | | NumberOfHomeBases = HomeBases.Length; |
| | | NumberOfHomeBasesLeft = NumberOfHomeBases; |
| | | |
| | | for (int i = 0; i < NumberOfHomeBases; i++) |
| | | { |
| | | HomeBases[i].homebaseIdx = i % MAX_TOWER; |
| | | HomeBases[i].died += OnHomeBaseDestroyed; |
| | | } |
| | | } |
| | | |
| | | private void Start() |
| | | { |
| | | EndlessBuffSelect.instance.BuffSelectCompleted += OnBuffSelectCompleted; |
| | | EndlessGameUI.instance.GameOverEvent += SafelyCallLevelCompleted; |
| | | |
| | | homeBasePositionList = new List<Vector3>(); |
| | | tunelLength = Mathf.Abs(StartingNodeList[0].transform.position.z - EndNodeList[0].transform.position.z); |
| | | |
| | | for (int i = 0; i < StartingNodeList.Count; ++i) |
| | | { |
| | | Vector3 startPos = StartingNodeList[i].transform.position; |
| | | Vector3 pos = new Vector3(); |
| | | pos.x = startPos.x; |
| | | pos.y = startPos.y; |
| | | pos.z = startPos.z - tunelLength; |
| | | homeBasePositionList.Add(pos); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | protected virtual void Update() |
| | | { |
| | | if (EndlessGameUI.instance.state == EndlessGameUI.State.GameOver) return; |
| | | |
| | | if (alwaysGainCurrency || !alwaysGainCurrency && EndlessLeveltate != LevelState.Building && EndlessLeveltate != LevelState.Intro) |
| | | { |
| | | CurrencyGainer.Tick(Time.deltaTime); |
| | | } |
| | | |
| | | // buff选择完成,开始波次 |
| | | if (!isBuffSelectCompleted) |
| | | { |
| | | isBuffSelectCompleted = true; |
| | | WaveManager.StartWaves(CurrentLevel); |
| | | if (CurrentLevel > startLevel) |
| | | WaveManager.InitPort(CurrentLevel); |
| | | EndlessUIStart.instance.Restart(); |
| | | WaveManager.StartWaves(CurrentLevel); |
| | | } |
| | | |
| | | // 本关卡所有波次全部生成完成 && 敌人全部被清理了,然后就去尝试进入下一关 |
| | |
| | | |
| | | if (WaveManager != null) |
| | | WaveManager.AllWaveCompleted -= AllWaveCompleted; |
| | | |
| | | // Iterate through home bases and unsubscribe |
| | | for (int i = 0; i < NumberOfHomeBases; i++) |
| | | { |
| | | HomeBases[i].died -= OnHomeBaseDestroyed; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | protected virtual void AllWaveCompleted() |
| | | { |
| | | IsAllWaveCompleted = true; |
| | | int score = EndlessPortData.GetLevelScore(CurrentLevel); |
| | | Debug.Log($"--------------------- 通过第{CurrentLevel}关,+{score}分 ---------------------"); |
| | | // 关卡通过,加分 |
| | | EndlessScoreManager.instance.AddScore(score); |
| | | EndlessBossSkillManager.instance.ClearSkillList(); |
| | | EndlessBossCtrl.instance.ChangeState(EndlessBossActionState.Death); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 新手更新关卡 |
| | | /// </summary> |
| | | public void NewbieUpdateLevel() |
| | | { |
| | | ++CurrentLevel; |
| | | EndlessBuffData.InitEndlessBuffPool(CurrentLevel); |
| | | WaveManager.InitPort(CurrentLevel); |
| | | IsAllWaveCompleted = false; |
| | | EndlessUIStart.instance.Restart(); |
| | | WaveManager.StartWaves(CurrentLevel); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 延迟进入下一关 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | private IEnumerator DelayToNextLevel() |
| | | { |
| | | yield return new WaitForSeconds(5f); |
| | | yield return new WaitForSeconds(2f); |
| | | BeginLevel(); |
| | | } |
| | | |
| | |
| | | private void BeginLevel() |
| | | { |
| | | if (EndlessGameUI.instance.state == EndlessGameUI.State.GameOver) return; |
| | | |
| | | EndlessBuffData.InitEndlessBuffPool(CurrentLevel); |
| | | |
| | | if (CurrentLevel == startLevel) |
| | | |
| | | WaveManager.InitPort(CurrentLevel); |
| | | |
| | | if (!GameConfig.IsNewbie) |
| | | ShowSelectBuffUI(); |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// buff选择完成 |
| | | /// buff选择完成p |
| | | /// </summary> |
| | | /// <param name="index"></param> |
| | | public void OnBuffSelectCompleted(int index) |
| | | { |
| | | isBuffSelectCompleted = false; |
| | | EndlessBuffManager.instance.AddBuff(EndlessBuffData.GetBuffByIndex(index)); |
| | | EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessBuffRefresh); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | WaveManager.RestartAllWave(); |
| | | EndlessGameUI.instance.SetAttackingTowerState(true); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 停止第二关波次 |
| | | /// </summary> |
| | | public void StopSecondWave() |
| | | { |
| | | if (!isStopSecondWaveCompleted) |
| | | { |
| | | isStopSecondWaveCompleted = true; |
| | | PauseWave(); |
| | | } |
| | | EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.SkillStep); |
| | | } |
| | | } |
| | | } |