| | |
| | | using DG.Tweening; |
| | | using JetBrains.Annotations; |
| | | using System; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using TMPro; |
| | | using TowerDefense.Level; |
| | |
| | | using UnityEngine.EventSystems; |
| | | using UnityEngine.UI; |
| | | using TowerDefense.Nodes; |
| | | using TowerDefense.Affectors; |
| | | using KTGMGemClient; |
| | | |
| | | namespace TowerDefense.UI.HUD |
| | | { |
| | |
| | | // 测试屏幕显示相关的倒计时. |
| | | protected bool bLoaded = false; |
| | | |
| | | private Timer overTimer; |
| | | |
| | | /// <summary> |
| | | /// 总兵线数 |
| | | /// </summary> |
| | |
| | | /// </summary> |
| | | private bool[,] TowerDestroyArr; |
| | | |
| | | public event Action GameOverEvent; |
| | | |
| | | /// <summary> |
| | | /// 塔升级特效预制体 |
| | | /// </summary> |
| | | public GameObject TowerUpgradeEffectPrefab; |
| | | |
| | | /// <summary> |
| | | /// 宝石出现特效预制体 |
| | | /// </summary> |
| | | public GameObject TowerAppearEffectPrefab; |
| | | |
| | | /// <summary> |
| | | /// 保存所有生成或合成的塔的最小等级,索引0 -> 火木水塔 索引1 -> 技能塔 |
| | | /// </summary> |
| | | /// <value></value> |
| | | public int MinLevel; |
| | | |
| | | public IPlacementArea selfTowerPlaceArea |
| | | { |
| | | get |
| | |
| | | } |
| | | } |
| | | |
| | | private void UpdateMinLevelArr() |
| | | { |
| | | int min = -1; |
| | | |
| | | for (int i = 0; i < m_listTower.Count; ++i) |
| | | { |
| | | if (min == -1 || m_listTower[i].currentLevel < min) |
| | | min = m_listTower[i].currentLevel; |
| | | } |
| | | |
| | | MinLevel = Mathf.Max(min, 0); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 增加一个防塔的数据结构,测试数据 |
| | | /// </summary> |
| | |
| | | public void addTower(Tower t) |
| | | { |
| | | m_listTower.Add(t); |
| | | UpdateMinLevelArr(); |
| | | |
| | | // 当前所在的位置是否攻击位置,随手瞎写:2 或者 3也就是前两排是上阵的 |
| | | if (t.gridPosition.y >= 2) |
| | |
| | | public bool towerInList(Tower t) |
| | | { |
| | | return m_listTower.Contains(t); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置已经上阵的所有塔的攻击状态,是否可以攻击 |
| | | /// </summary> |
| | | /// <param name="canAttack"></param> |
| | | public void SetAttackingTowerState(bool canAttack) |
| | | { |
| | | foreach (Tower tower in m_listTower) |
| | | { |
| | | tower.bInAttackMode = canAttack; |
| | | } |
| | | } |
| | | |
| | | public void delTower(Tower t) |
| | |
| | | break; |
| | | case State.Paused: |
| | | case State.GameOver: |
| | | // if (oldState == State.Building) |
| | | // { |
| | | // CancelGhostPlacement(); |
| | | // } |
| | | // Time.timeScale = 0f; |
| | | Debug.Log("--------------------- game over !!! ---------------------"); |
| | | if (oldState == State.Building) |
| | | CancelGhostPlacement(); |
| | | Time.timeScale = 1f; |
| | | break; |
| | | default: |
| | | throw new ArgumentOutOfRangeException("newState", newState, null); |
| | |
| | | UIPointer pointer = WrapPointer(pinfo); |
| | | Tower sTower = PickTowerInGrid(pointer); |
| | | if (sTower != null) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | if ((m_GridPosition.x >= 0) && (m_GridPosition.y >= 0)) |
| | | { |
| | | if (m_CurrentArea.isFreeAtackPos(m_GridPosition.x, m_GridPosition.y)) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | return false; |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 判断是否有不同类型的Tower,可以发生置换,仅限于火木水之间发生 |
| | | /// </summary> |
| | | /// <param name="pinfo"></param> |
| | | /// <returns></returns> |
| | | protected bool IsSubstitute(PointerInfo pinfo) |
| | | { |
| | | if (!m_CurrentTower || !IsGhostAtValidPosition()) |
| | | { |
| | | // 判断格子上的塔防: |
| | | UIPointer pointer = WrapPointer(pinfo); |
| | | Tower sTower = PickTowerInGrid(pointer); |
| | | |
| | | if (sTower && sTower != towerToMove) |
| | | { |
| | | if (towerToMove && sTower.towerFeature == EFeatureTower.NULL && towerToMove.towerFeature == EFeatureTower.NULL && sTower.bInAttackMode == towerToMove.bInAttackMode) |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取目标格子上的塔防的名字数据 |
| | | /// </summary> |
| | | /// <param name="pinfo"></param> |
| | |
| | | /// <param name="opponent"></param> |
| | | public void DestroyTowerGrid(int xidx) |
| | | { |
| | | // 这里的逻辑已经不走了 |
| | | for (int i = 0; i < AttackRowNumbers; ++i) |
| | | { |
| | | if (TowerDestroyArr[xidx, i]) continue; |
| | |
| | | } |
| | | |
| | | TowerDestroyArr[xidx, i] = true; |
| | | Tower tower = FindTowerWithGridIdx(xidx, i); |
| | | Tower tower = FindTowerWithGridIdx(xidx, 3 - i); |
| | | |
| | | if (tower) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | // 红心减少逻辑 |
| | | // HealthHeartState.instance.killHeart(false); |
| | | GameOver(); |
| | | overTimer = new Timer(1.2f, SafelyCallGameOverEvent); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 爱心数量为0,游戏结束 |
| | | /// </summary> |
| | | private void AllHeartLose() |
| | | { |
| | | // 清理技能 |
| | | EndlessBossSkillManager.instance.ClearSkillList(); |
| | | |
| | | // 停止所有兵线的出兵 |
| | | for (int i = 0; i < TotalWaveLines; ++i) |
| | | { |
| | | EndlessLevelManager.instance.StopWaveLine(i); |
| | | } |
| | | |
| | | // 让所有兵线上已经生成的所有agent播放一个死亡动画然后销毁 |
| | | WaveLineAgentInsMgr[] waveLineAgentIns = AgentInsManager.instance.GetWaveLineList(); |
| | | |
| | | for (int i = 0; i < waveLineAgentIns.Length; ++i) |
| | | { |
| | | while (waveLineAgentIns[i].listAgent.Count > 0) |
| | | { |
| | | waveLineAgentIns[i].listAgent[0].PlayDeath(); |
| | | } |
| | | } |
| | | |
| | | GameOver(); |
| | | overTimer = new Timer(1.2f, SafelyCallGameOverEvent); |
| | | } |
| | | |
| | | private void SafelyCallGameOverEvent() |
| | | { |
| | | if (GameOverEvent != null) |
| | | GameOverEvent(); |
| | | overTimer = null; |
| | | } |
| | | |
| | | public MeshRenderer temporaryMat;//移动时候的虚像材质 |
| | | |
| | | public void CheckTowerPlace(PointerInfo pointerInfo) |
| | | { |
| | | return; |
| | | //下面是为了设置一个虚拟的塔 |
| | | if (isFreeAttackGrid(pointerInfo) && m_CurrentTower.controller.towerFeature == EFeatureTower.NULL) |
| | | { |
| | | Debug.Log("得到了一个空的塔位"); |
| | | |
| | | (m_CurrentArea as TowerPlacementGridEndless).GetMeshRender(m_GridPosition.x, m_GridPosition.y, "1"); |
| | | //if(temporaryMat) |
| | | } |
| | | } |
| | | |
| | |
| | | public void onEndTowerDrag(PointerInfo pointerInfo) |
| | | { |
| | | bool bSkill = false; |
| | | if (temporaryMat != null) |
| | | { |
| | | //移动虚像隐藏 |
| | | temporaryMat.material = null; |
| | | } |
| | | |
| | | if (!m_CurrentTower || !m_CurrentTower.controller) |
| | | { |
| | | CancelPlaceTower(pointerInfo); |
| | |
| | | towerToMove = null; |
| | | } |
| | | } |
| | | else if (EndlessLevelManager.instanceExists && IsSubstitute(pointerInfo)) |
| | | { |
| | | // 可以发生置换 |
| | | UIPointer pointer = WrapPointer(pointerInfo); |
| | | // 格子上的塔 |
| | | Tower sTower = PickTowerInGrid(pointer); |
| | | |
| | | if (sTower.bInAttackMode == towerToMove.bInAttackMode) |
| | | { |
| | | IntVector2 v1 = new IntVector2(towerToMove.gridPosition.x, towerToMove.gridPosition.y); |
| | | IntVector2 v2 = new IntVector2(sTower.gridPosition.x, sTower.gridPosition.y); |
| | | |
| | | Tower newTower1 = PlaceTowerForce(EndlessRandomTower.instance.getTowerByName(sTower.towerName), v1, sTower.currentLevel + 1, false); |
| | | Tower newTower2 = PlaceTowerForce(m_CurrentTower.controller, v2, towerToMove.currentLevel + 1, false); |
| | | |
| | | if (towerToMove != null) |
| | | { |
| | | delTower(towerToMove); |
| | | towerToMove.showTower(true); |
| | | towerToMove.Sell(); |
| | | towerToMove = null; |
| | | } |
| | | |
| | | delTower(sTower); |
| | | sTower.showTower(true); |
| | | sTower.Sell(); |
| | | sTower = null; |
| | | |
| | | CancelGhostPlacement(); |
| | | |
| | | newTower1.placementArea.Occupy(newTower1.gridPosition, newTower1.dimensions); |
| | | newTower2.placementArea.Occupy(newTower2.gridPosition, newTower2.dimensions); |
| | | } |
| | | } |
| | | // 当前是Skill塔位的状态. |
| | | else if (bSkill) |
| | | { |
| | |
| | | } |
| | | else |
| | | CancelPlaceTower(pointerInfo); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 强制放置塔,主要是用于新手 |
| | | /// </summary> |
| | | /// <param name="newTower"></param> |
| | | /// <param name="pos"></param> |
| | | /// <param name="level">塔的等级</param> |
| | | public Tower PlaceTowerForce(Tower newTower, IntVector2 pos, int level, bool playEffect = true) |
| | | { |
| | | TowerPlacementGhost currentTower = Instantiate(newTower.towerGhostPrefab); |
| | | currentTower.Initialize(newTower); |
| | | Tower controller = currentTower.controller; |
| | | Tower createdTower = Instantiate(controller); |
| | | createdTower.PlayWaveLineFlash = playEffect; |
| | | createdTower.Initialize(m_CurrentArea, pos); |
| | | createdTower.SetLevel(level - 1); |
| | | |
| | | if (playEffect) |
| | | PlayUpgradeEffect(createdTower); |
| | | |
| | | addTower(createdTower); |
| | | Destroy(currentTower.gameObject); |
| | | |
| | | return createdTower; |
| | | } |
| | | |
| | | protected bool SkillPlayEndDrag(PointerInfo pointer) |
| | |
| | | // 播放特效,并处理伤害. |
| | | EndlessWaveLineManager.instance.PlayWaveLineEffect(selEff.waveLineId); |
| | | AgentInsManager.instance.ExecWavelineAttack(selEff.waveLineId, sId, sLevel, false); |
| | | ++GameConfig.EndlessPortUseSkillTowerCount; |
| | | return true; |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 播放升级特效 |
| | | /// </summary> |
| | | /// <param name="worldPos"></param> |
| | | public void PlayUpgradeEffect(Tower newTower) |
| | | { |
| | | GameObject effect = TowerUpgradeEffectPrefab; |
| | | |
| | | if (newTower.towerFeature == EFeatureTower.NULL) |
| | | { |
| | | string path = $"UI/ToBattle_{newTower.attributeId}"; |
| | | GameObject prefab = Resources.Load<GameObject>(path); |
| | | effect = Instantiate(prefab); |
| | | } |
| | | |
| | | // 在sTower的位置播放升级特效 |
| | | GameObject obj = Instantiate(effect); |
| | | obj.transform.position = newTower.transform.position; |
| | | Vector3 pos = obj.transform.position; |
| | | pos.y += 5f; |
| | | obj.transform.position = pos; |
| | | ParticleSystem ps = obj.GetComponent<ParticleSystem>(); |
| | | |
| | | if (ps == null) |
| | | ps = obj.transform.GetChild(0).GetComponent<ParticleSystem>(); |
| | | ps.Play(); |
| | | Destroy(obj, ps.main.duration); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Deselect the current tower and hides the UI |
| | | /// </summary> |
| | | public void DeselectTower() |
| | |
| | | /// <exception cref="InvalidOperationException"> |
| | | /// Throws exception if not in Build State or <see cref="m_CurrentTower"/> is not at a valid position |
| | | /// </exception> |
| | | public void PlaceTower(int lvl = 0, bool opponent = false) |
| | | public void PlaceTower(int lvl = 0, bool isUpgrade = false, bool opponent = false) |
| | | { |
| | | if (!isBuilding) |
| | | throw new InvalidOperationException("Trying to place tower when not in a Build Mode"); |
| | |
| | | |
| | | // River: 内部缓存数据,用于后期容易找到数据. |
| | | addTower(createdTower); |
| | | |
| | | CancelGhostPlacement(); |
| | | if (!isUpgrade) |
| | | PlayAppearEffect(createdTower.transform.position); |
| | | else |
| | | PlayUpgradeEffect(createdTower); |
| | | |
| | | // 处理成长骰子,复制骰子等等功能. |
| | | if (lvl == 0) |
| | | { |
| | | ProcessFeatureTower(createdTower); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 播放宝石出现特效 |
| | | /// </summary> |
| | | public void PlayAppearEffect(Vector3 worldPos) |
| | | { |
| | | GameObject obj = Instantiate(TowerAppearEffectPrefab); |
| | | obj.transform.position = worldPos; |
| | | Vector3 pos = obj.transform.position; |
| | | pos.y += 5f; |
| | | obj.transform.position = pos; |
| | | |
| | | ParticleSystem ps = obj.GetComponent<ParticleSystem>(); |
| | | |
| | | if (ps == null) |
| | | ps = obj.transform.GetChild(0).GetComponent<ParticleSystem>(); |
| | | |
| | | ps.Play(); |
| | | Destroy(obj, ps.main.duration); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 播放升级特效 |
| | | /// </summary> |
| | | /// <param name="worldPos"></param> |
| | | public void GuidePlayUpgradeEffect(Vector3 position) |
| | | { |
| | | GameObject effect = TowerUpgradeEffectPrefab; |
| | | |
| | | // 在sTower的位置播放升级特效 |
| | | GameObject obj = Instantiate(effect); |
| | | obj.transform.position = position; |
| | | Vector3 pos = obj.transform.position; |
| | | pos.y += 5f; |
| | | obj.transform.position = pos; |
| | | ParticleSystem ps = obj.GetComponent<ParticleSystem>(); |
| | | |
| | | if (ps == null) |
| | | ps = obj.transform.GetChild(0).GetComponent<ParticleSystem>(); |
| | | ps.Play(); |
| | | Destroy(obj, ps.main.duration); |
| | | } |
| | | |
| | | protected void ProcessFeatureTower(Tower ctower) |
| | |
| | | /// </summary> |
| | | protected void disableRandomTowerBtn() |
| | | { |
| | | randomTowerBtn.interactable = false; |
| | | randomTowerBtn.GetComponent<EndlessRandomTower>().ChangeBtnClick(); |
| | | //randomTowerBtn.interactable = false; |
| | | if (towerPriceText) |
| | | { |
| | | towerPriceText.color = new Color(0.5f, 0.5f, 0.5f); |
| | |
| | | towerPriceText.color = new Color(1.0f, 1.0f, 1.0f); |
| | | |
| | | if (randomTowerBtn) |
| | | randomTowerBtn.interactable = true; |
| | | { |
| | | randomTowerBtn.GetComponent<EndlessRandomTower>().ChangeBtnClickNormal(); |
| | | //randomTowerBtn.interactable = true; |
| | | } |
| | | tdBuyDisable = false; |
| | | } |
| | | |
| | |
| | | if (crit) |
| | | bloodStr += "Crt!"; |
| | | bloodStr += "-"; |
| | | bloodStr += val.ToString(); |
| | | bloodStr += ((Int64)val).ToString(); |
| | | |
| | | tm.moveBloodText(spos.x, spos.y, bloodStr, crit); |
| | | } |
| | |
| | | if (placeObj != null) |
| | | m_CurrentArea = placeObj.GetComponent<IPlacementArea>(); |
| | | placeObj = GameObject.FindGameObjectWithTag("PlaceTowerOpponent"); |
| | | EventCenter.Ins.Add((int)KTGMGemClient.EventType.EndlessHeartAllLose, AllHeartLose); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// 直接在IPlaceArea上随机放置一个Tower。这是随机放置塔防的入口类。这是入口的塔防类。 |
| | | /// </summary> |
| | | /// <param name="tow"></param> |
| | | public bool RandomPlaceTower(Tower tow, int posx = -1, int posy = -1, int lvl = 0, int forceCost = -1) |
| | | public bool RandomPlaceTower(Tower tow, int posx = -1, int posy = -1, int lvl = 0, int forceCost = -1, bool isUpgrade = false) |
| | | { |
| | | // 获取IPlaceArea. |
| | | if (m_CurrentArea == null) |
| | |
| | | int cost = TowerPrice.instance.currentTowerPrice; |
| | | if (zeroCost) |
| | | cost = 0; |
| | | |
| | | |
| | | if (forceCost != -1) |
| | | cost = forceCost; |
| | | |
| | |
| | | m_CurrentTower.Show(); |
| | | if (successfulPurchase) |
| | | { |
| | | ++GameConfig.EndlessBuyTowerCount; |
| | | // 删除towerToMove,确保塔防数据不再出现多个 |
| | | if (zeroCost && (towerToMove != null)) |
| | | { |
| | |
| | | OnSuccessBuyTower(); |
| | | SetState(State.Building); |
| | | |
| | | PlaceTower(lvl); |
| | | PlaceTower(lvl, isUpgrade); |
| | | } |
| | | |
| | | |
| | | return true; |
| | | } |
| | | |
| | |
| | | |
| | | // ATTENTION TO FIX:是否应该加入List: |
| | | addTower(createdTower); |
| | | PlayToAttackEffect(createdTower.attributeId, createdTower.transform.position); |
| | | dragTowerLevel = 0; |
| | | CancelGhostPlacement(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 播放宝石上阵特效 |
| | | /// </summary> |
| | | /// <param name="attributeId">101 火,105 水,109 木</param> |
| | | /// <param name="worldPos">世界坐标</param> |
| | | public void PlayToAttackEffect(int attributeId, Vector3 worldPos) |
| | | { |
| | | string path = $"UI/ToBattle_{attributeId}"; |
| | | GameObject prefab = Resources.Load<GameObject>(path); |
| | | GameObject obj = Instantiate(prefab); |
| | | obj.transform.position = worldPos; |
| | | Vector3 pos = obj.transform.position; |
| | | pos.y += 5f; |
| | | obj.transform.position = pos; |
| | | |
| | | ParticleSystem ps = obj.GetComponent<ParticleSystem>(); |
| | | |
| | | if (ps == null) |
| | | ps = obj.transform.GetChild(0).GetComponent<ParticleSystem>(); |
| | | |
| | | ps.Play(); |
| | | Destroy(obj, ps.main.duration); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | private void Update() |
| | | { |
| | | if (overTimer != null) |
| | | overTimer.Tick(Time.deltaTime); |
| | | |
| | | for (int ti = listTowerTimer.Count - 1; ti >= 0; ti--) |
| | | { |
| | | // 如果执行到,会在DelTower函数内删除对应的listTowerTimer. |