| | |
| | | using Core.Health; |
| | | using Core.Input; |
| | | using Core.Utilities; |
| | | 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 |
| | |
| | | /// </summary> |
| | | public Button randomTowerBtn; |
| | | |
| | | public Button SkillTowerBtn; |
| | | |
| | | /// <summary> |
| | | /// 飘血数字对应的prefab. |
| | | /// </summary> |
| | |
| | | /// 暴击飘字. |
| | | /// </summary> |
| | | public TextMoveDoTween bloodCrit; |
| | | |
| | | /// <summary> |
| | | /// 减速飘字 |
| | | /// </summary> |
| | | public Image SlowDownWord; |
| | | |
| | | /// <summary> |
| | | /// 暴击飘字 |
| | | /// </summary> |
| | | public Image CritWord; |
| | | |
| | | /// <summary> |
| | | /// 购买塔防按钮上的Text. |
| | |
| | | /// Current tower placeholder. Will be null if not in the <see cref="State.Building" /> state. |
| | | /// </summary> |
| | | TowerPlacementGhost m_CurrentTower; |
| | | |
| | | public bool HasTower |
| | | { |
| | | get |
| | | { |
| | | return m_CurrentTower != null; |
| | | } |
| | | } |
| | | |
| | | // TowerList用于简单记录相关的数据 |
| | | protected List<Tower> m_listTower = new List<Tower>(); |
| | |
| | | /// </summary> |
| | | public GameObject TowerAppearEffectPrefab; |
| | | |
| | | public GameObject TowerUpgradeEffectPrefabGuide;//新手导航特效Layer是UI |
| | | public GameObject TowerAppearEffectPrefabGuide;//新手导航特效Layer是UI |
| | | |
| | | |
| | | //首次购买宝石特效 |
| | | public GameObject fireAppearEffect1; |
| | | public GameObject fireAppearEffect2; |
| | | |
| | | public GameObject waterAppearEffect1; |
| | | public GameObject waterAppearEffect2; |
| | | public GameObject woodAppearEffect1; |
| | | public GameObject woodAppearEffect2; |
| | | /// <summary> |
| | | /// 保存所有生成或合成的塔的最小等级,索引0 -> 火木水塔 索引1 -> 技能塔 |
| | | /// 保存所有生成或合成的塔的最小等级 |
| | | /// </summary> |
| | | /// <value></value> |
| | | public int MinLevel; |
| | |
| | | { |
| | | foreach (Tower tower in m_listTower) |
| | | { |
| | | tower.bInAttackMode = canAttack; |
| | | tower.CanAttack = canAttack; |
| | | } |
| | | } |
| | | |
| | |
| | | SetToDragMode(newT); |
| | | |
| | | if (towerOld.towerFeature == EFeatureTower.Skill_Bomb) |
| | | m_CurrentTower.SetAttackArea(dragTowerLevel, towerOld.attributeId); |
| | | m_CurrentTower.SetAttackArea(dragTowerLevel, towerOld.ElfId); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | 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; |
| | |
| | | if (!m_CurrentTower || !IsGhostAtValidPosition()) |
| | | { |
| | | // 最大级别的Tower不能再合并了. |
| | | if (towerToMove.isAtMaxLevel) |
| | | if (towerToMove.IsMaxLevel) |
| | | return false; |
| | | |
| | | // 判断格子上的塔防: |
| | | UIPointer pointer = WrapPointer(pinfo); |
| | | Tower sTower = PickTowerInGrid(pointer); |
| | | |
| | | // 泡泡禁锢状态不允许合并 |
| | | if (sTower.IsBondage) return false; |
| | | |
| | | if (sTower && sTower != towerToMove) |
| | | { |
| | | int testLvl = dragTowerLevel; |
| | |
| | | UIPointer pointer = WrapPointer(pinfo); |
| | | Tower sTower = PickTowerInGrid(pointer); |
| | | |
| | | // 泡泡禁锢状态不允许置换 |
| | | if (sTower.IsBondage) return false; |
| | | |
| | | if (sTower && sTower != towerToMove) |
| | | { |
| | | if (towerToMove && sTower.towerFeature == EFeatureTower.NULL && towerToMove.towerFeature == EFeatureTower.NULL && sTower.bInAttackMode == towerToMove.bInAttackMode) |
| | | if (towerToMove && sTower.towerFeature == EFeatureTower.NULL && towerToMove.towerFeature == EFeatureTower.NULL && sTower.bInAttackMode && towerToMove.bInAttackMode) |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 判断是否有不同类型的Tower,可以发生置换,仅限于火木水之间发生 |
| | | /// </summary> |
| | | /// <param name="pinfo"></param> |
| | | /// <returns></returns> |
| | | protected bool IsSubstituteGuide(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) |
| | | return true; |
| | | } |
| | | } |
| | |
| | | /// <param name="tower"></param> |
| | | protected void growUpTower(Tower tower) |
| | | { |
| | | Tower newTower = EndlessRandomTower.instance.GetRandomTower(false); |
| | | Tower newTower = EndlessRandomTower.instance.GetRandomTower(EFeatureTower.NULL); |
| | | |
| | | // 所有的Tower不能升级成为FeatureTower. |
| | | int maxLoop = 20; |
| | | while (newTower.towerFeature != EFeatureTower.NULL) |
| | | { |
| | | newTower = EndlessRandomTower.instance.GetRandomTower(false); |
| | | newTower = EndlessRandomTower.instance.GetRandomTower(EFeatureTower.NULL); |
| | | maxLoop--; |
| | | if (maxLoop <= 0) |
| | | { |
| | |
| | | /// <param name="opponent"></param> |
| | | public void DestroyTowerGrid(int xidx) |
| | | { |
| | | // cx test 这里的逻辑已经不走了 |
| | | // 这里的逻辑已经不走了 |
| | | for (int i = 0; i < AttackRowNumbers; ++i) |
| | | { |
| | | if (TowerDestroyArr[xidx, i]) continue; |
| | |
| | | { |
| | | // 清理技能 |
| | | EndlessBossSkillManager.instance.ClearSkillList(); |
| | | EndlessBossHPManager.instance.SwitchHP(true); |
| | | EndlessBossHPManager.instance.SetCurrentHP(0); |
| | | |
| | | // 停止所有兵线的出兵 |
| | | for (int i = 0; i < TotalWaveLines; ++i) |
| | |
| | | |
| | | // 让所有兵线上已经生成的所有agent播放一个死亡动画然后销毁 |
| | | WaveLineAgentInsMgr[] waveLineAgentIns = AgentInsManager.instance.GetWaveLineList(); |
| | | GameOver(); |
| | | |
| | | for (int i = 0; i < waveLineAgentIns.Length; ++i) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | GameOver(); |
| | | overTimer = new Timer(1.2f, SafelyCallGameOverEvent); |
| | | } |
| | | |
| | |
| | | overTimer = null; |
| | | } |
| | | |
| | | #region 拖动时候给塔位一个标识 |
| | | |
| | | public MeshRenderer temporaryMat;//移动时候的虚像材质 |
| | | |
| | | /// <summary> |
| | | /// 查找可以合成的塔 |
| | | /// </summary> |
| | | public void CheckAllCanPlace() |
| | | { |
| | | if (m_CurrentTower != null) |
| | | { |
| | | if (m_CurrentTower.controller.towerFeature == EFeatureTower.NULL) |
| | | { |
| | | // if (m_CurrentArea != null && m_CurrentTower.controller.gridPosition.y >= 2) |
| | | // { |
| | | // //修改为只要开启格子都可以放 |
| | | // (m_CurrentArea as TowerPlacementGridEndless).CheckCanPlaceUpdate(m_CurrentTower.controller.gridPosition.x, m_CurrentTower.controller.gridPosition.y, false, ""); |
| | | // //(m_CurrentArea as TowerPlacementGridEndless).PlayPS(allPSTowerP); |
| | | // } |
| | | return; |
| | | List<IntVector2> allTowerP = null;//排除不能合成的 |
| | | // List<IntVector2> allPSTowerP = new List<IntVector2>();//需要播放升级动画的 |
| | | |
| | | if (towerToMove) |
| | | { |
| | | if (towerToMove.gridPosition.y == 0 || towerToMove.gridPosition.y == 1) |
| | | { |
| | | allTowerP = new List<IntVector2>(); |
| | | for (int i = 0; i < m_listTower.Count; i++) |
| | | { |
| | | if (m_listTower[i].bInAttackMode && towerToMove && m_listTower[i].currentLevel == dragTowerLevel && m_listTower[i].towerName == towerToMove.towerName) |
| | | { |
| | | // if (towerToMove.gridPosition != m_listTower[i].gridPosition) |
| | | // //说明可以合成 |
| | | // allPSTowerP.Add(m_listTower[i].gridPosition); |
| | | } |
| | | else |
| | | { |
| | | //把不符合条件的传进去 |
| | | allTowerP.Add(m_listTower[i].gridPosition); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | if (m_CurrentArea != null) |
| | | { |
| | | //修改为只要开启格子都可以放 |
| | | (m_CurrentArea as TowerPlacementGridEndless).CheckAllCanPlace(allTowerP); |
| | | //(m_CurrentArea as TowerPlacementGridEndless).PlayPS(allPSTowerP); |
| | | } |
| | | |
| | | } |
| | | else if (m_CurrentTower.controller.towerFeature == EFeatureTower.Skill_Fire || m_CurrentTower.controller.towerFeature == EFeatureTower.Skill_Bomb) |
| | | { |
| | | //Debug.Log("需要激活兵线下方绿色标识"); |
| | | EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessStartDragSkill, true); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 关闭所有标识 |
| | | /// </summary> |
| | | public void CloseCanPlaceRenderer() |
| | | { |
| | | if (m_CurrentTower && m_CurrentTower.controller && m_CurrentTower.controller.towerFeature == EFeatureTower.Skill_Fire || m_CurrentTower.controller.towerFeature == EFeatureTower.Skill_Bomb) |
| | | { |
| | | EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessStartDragSkill, false); |
| | | } |
| | | |
| | | if (m_CurrentArea != null) |
| | | (m_CurrentArea as TowerPlacementGridEndless).CloseCanPlaceRenderer(); |
| | | else |
| | | { |
| | | GameObject placeObj = GameObject.FindGameObjectWithTag("PlaceTower"); |
| | | if (placeObj != null) |
| | | (placeObj.GetComponent<IPlacementArea>() as TowerPlacementGridEndless).CloseCanPlaceRenderer(); |
| | | } |
| | | } |
| | | |
| | | Tower checkTowerPlaceTower;//移动时候查看鼠标是否检测到有塔 |
| | | Tower bInAttackModeTower;//在合成区的塔 |
| | | /// <summary> |
| | | /// 检查符合条件的塔 |
| | | /// </summary> |
| | | /// <param name="pointerInfo"></param> |
| | | public void CheckTowerPlace(PointerInfo pointerInfo) |
| | | { |
| | | //return; |
| | | if (m_CurrentArea != null && m_CurrentArea is TowerPlacementGridEndless) |
| | | { |
| | | checkTowerPlaceTower = isFreeAttackGridOnDrag(pointerInfo); |
| | | //下面是为了设置一个虚拟的塔 |
| | | if (checkTowerPlaceTower != null) |
| | | { |
| | | if (m_CurrentTower.controller.towerFeature == EFeatureTower.NULL) |
| | | { |
| | | if (checkTowerPlaceTower.bInAttackMode) |
| | | { |
| | | //鼠标检测到了塔 |
| | | (m_CurrentArea as TowerPlacementGridEndless).CheckCanPlaceUpdate(m_GridPosition.x, m_GridPosition.y, false, ""); |
| | | } |
| | | else |
| | | { |
| | | if (!towerToMove.bInAttackMode) |
| | | { |
| | | //没有上阵 |
| | | if (bInAttackModeTower == null) |
| | | { |
| | | bInAttackModeTower = checkTowerPlaceTower; |
| | | bInAttackModeTower.CurrentTowerLevel.SetCanPlace(true); |
| | | } |
| | | else if (bInAttackModeTower != checkTowerPlaceTower) |
| | | { |
| | | |
| | | bInAttackModeTower.CurrentTowerLevel.SetCanPlace(false); |
| | | bInAttackModeTower = checkTowerPlaceTower; |
| | | bInAttackModeTower.CurrentTowerLevel.SetCanPlace(true); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | else if (m_CurrentTower.controller.towerFeature == EFeatureTower.Skill_Fire || m_CurrentTower.controller.towerFeature == EFeatureTower.Skill_Bomb) |
| | | { |
| | | //技能宝石没有上阵 |
| | | if (bInAttackModeTower == null) |
| | | { |
| | | bInAttackModeTower = checkTowerPlaceTower; |
| | | bInAttackModeTower.CurrentTowerLevel.SetCanPlace(true); |
| | | } |
| | | else if (bInAttackModeTower != checkTowerPlaceTower) |
| | | { |
| | | |
| | | bInAttackModeTower.CurrentTowerLevel.SetCanPlace(false); |
| | | bInAttackModeTower = checkTowerPlaceTower; |
| | | bInAttackModeTower.CurrentTowerLevel.SetCanPlace(true); |
| | | } |
| | | } |
| | | } |
| | | else if ((m_GridPosition.x >= 0) && (m_GridPosition.y >= 0)) |
| | | { |
| | | //查看是否是一个空格子 |
| | | if (m_CurrentArea.isFreeAtackPos(m_GridPosition.x, m_GridPosition.y)) |
| | | { |
| | | if (m_CurrentTower.controller.towerFeature == EFeatureTower.NULL) |
| | | { |
| | | //空格子 |
| | | (m_CurrentArea as TowerPlacementGridEndless).CheckCanPlaceUpdate(m_GridPosition.x, m_GridPosition.y, true, towerToMove.towerName); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | CloseCanPlace(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | CloseCanPlace(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (m_CurrentTower.controller.towerFeature == EFeatureTower.NULL) |
| | | { |
| | | dragTowerPlacement.CloseCanPlace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | void CloseCanPlace() |
| | | { |
| | | dragTowerPlacement.CloseCanPlace(); |
| | | if (bInAttackModeTower != null) |
| | | { |
| | | bInAttackModeTower.CurrentTowerLevel.SetCanPlace(false); |
| | | bInAttackModeTower = null; |
| | | } |
| | | } |
| | | |
| | | TowerPlacementGridEndless dragTowerPlacement; |
| | | |
| | | /// <summary> |
| | | /// 目标位置是否是可攻击属性的空塔位 |
| | | /// </summary> |
| | | /// <param name="pinfo"></param> |
| | | /// <returns></returns> |
| | | protected Tower isFreeAttackGridOnDrag(PointerInfo pinfo) |
| | | { |
| | | // 判断格子上的塔防: |
| | | UIPointer pointer = WrapPointer(pinfo); |
| | | Tower sTower = PickTowerInGrid(pointer); |
| | | if (sTower != null) |
| | | { |
| | | |
| | | // if (towerToMove && sTower.currentLevel == dragTowerLevel && sTower.towerName == towerToMove.towerName) |
| | | // { |
| | | // //说明可以合成 |
| | | // return sTower; |
| | | // } |
| | | // else |
| | | // { |
| | | // return null; |
| | | // } |
| | | |
| | | if (towerToMove) |
| | | { |
| | | if (towerToMove.bInAttackMode) |
| | | { |
| | | return sTower; |
| | | } |
| | | else |
| | | { |
| | | if (sTower.currentLevel == dragTowerLevel && sTower.towerName == towerToMove.towerName) |
| | | { |
| | | //说明可以合成 |
| | | return sTower; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | return null; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// 拖动一个Tower之后,松开鼠标或者EndDrag. |
| | | /// 1: 目标点可合成,则直接合成。 |
| | |
| | | public void onEndTowerDrag(PointerInfo pointerInfo) |
| | | { |
| | | bool bSkill = false; |
| | | if (temporaryMat != null) |
| | | { |
| | | //移动虚像隐藏 |
| | | temporaryMat.material = null; |
| | | } |
| | | |
| | | if (!m_CurrentTower || !m_CurrentTower.controller) |
| | | { |
| | | CancelPlaceTower(pointerInfo); |
| | |
| | | if (m_CurrentTower.controller.towerFeature != EFeatureTower.NULL) |
| | | bSkill = true; |
| | | |
| | | if (GameConfig.IsNewbie) |
| | | { |
| | | bool isCanChange = false; |
| | | if (EndlessLevelManager.instanceExists && IsSubstituteGuide(pointerInfo)) |
| | | { |
| | | isCanChange = CheckCanChangePos(pointerInfo); |
| | | } |
| | | if (isCanChange) |
| | | { |
| | | GuideCtrl.Ins.DragDone(); |
| | | Debug.Log("交换了位置"); |
| | | } |
| | | else |
| | | { |
| | | GuideCtrl.Ins.EndDrag5_1(); |
| | | CancelPlaceTower(pointerInfo); |
| | | Debug.Log("没有放置在火塔上"); |
| | | } |
| | | |
| | | return; |
| | | } |
| | | |
| | | // 判断目标位置是否有Tower且类型和等级一致,如果没有,则GhostTower删除,原Tower显示。 |
| | | if (isValidateCombineTarget(pointerInfo)) |
| | | { |
| | | TryPlaceTower(pointerInfo); |
| | | EndlessRandomTower.instance.UpdateDescDisplay(); |
| | | } |
| | | else if (isFreeAttackGrid(pointerInfo) && !bSkill) |
| | | { |
| | | if (!TryPlaceTower(pointerInfo, false, true)) return; |
| | | if (!TryPlaceTower(pointerInfo, false)) |
| | | { |
| | | CancelPlaceTower(pointerInfo); |
| | | Debug.Log("这里需要返回原位"); |
| | | return; |
| | | } |
| | | |
| | | // 删除towerToMove,确保塔防数据不再出现多个 |
| | | if (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); |
| | | } |
| | | CheckCanChangePos(pointerInfo); |
| | | } |
| | | // 当前是Skill塔位的状态. |
| | | else if (bSkill) |
| | |
| | | CancelPlaceTower(pointerInfo); |
| | | } |
| | | |
| | | private bool CheckCanChangePos(PointerInfo pointerInfo) |
| | | { |
| | | // 可以发生置换 |
| | | UIPointer pointer = WrapPointer(pointerInfo); |
| | | // 格子上的塔 |
| | | Tower sTower = PickTowerInGrid(pointer); |
| | | if (sTower == null) |
| | | return false; |
| | | |
| | | 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); |
| | | |
| | | if (m_CurrentArea == null) |
| | | { |
| | | CancelGhostPlacement(); |
| | | towerToMove.showTower(true); |
| | | return false; |
| | | } |
| | | else |
| | | { |
| | | 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); |
| | | |
| | | //强制交换塔的时候检查自身充能条 |
| | | newTower1.CheckCtrl(); |
| | | newTower2.CheckCtrl(); |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 强制放置塔,主要是用于新手 |
| | | /// </summary> |
| | |
| | | Tower controller = currentTower.controller; |
| | | Tower createdTower = Instantiate(controller); |
| | | createdTower.PlayWaveLineFlash = playEffect; |
| | | createdTower.Initialize(m_CurrentArea, pos); |
| | | createdTower.SetLevel(level - 1); |
| | | createdTower.Initialize(m_CurrentArea, pos, level - 1); |
| | | |
| | | if (playEffect) |
| | | PlayUpgradeEffect(createdTower); |
| | | |
| | | addTower(createdTower); |
| | | Destroy(currentTower.gameObject); |
| | | |
| | |
| | | ray = m_Camera.ScreenPointToRay(tp.currentPosition) |
| | | }; |
| | | |
| | | int sId = towerToMove.attributeId; |
| | | int sId = towerToMove.ElfId; |
| | | int sLevel = towerToMove.currentLevel; |
| | | |
| | | // 火是列攻击: |
| | |
| | | if (towerToMove) |
| | | { |
| | | towerToMove.showTower(true); |
| | | towerToMove.CheckCtrl(); |
| | | |
| | | // 处理复制骰子: |
| | | if (towerToMove.towerFeature == EFeatureTower.CopyCat) |
| | |
| | | /// Attempt to position a tower at the given location |
| | | /// </summary> |
| | | /// <param name="pointerInfo">The pointer we're using to position the tower</param> |
| | | public bool TryPlaceTower(PointerInfo pointerInfo, bool force = false, bool zeroCost = false) |
| | | public bool TryPlaceTower(PointerInfo pointerInfo, bool force = false) |
| | | { |
| | | UIPointer pointer = WrapPointer(pointerInfo); |
| | | |
| | |
| | | return false; |
| | | } |
| | | |
| | | BuyTower(pointer, force, zeroCost); |
| | | |
| | | return true; |
| | | return BuyTower(pointer, force); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | throw new InvalidOperationException("Selected Tower is null"); |
| | | } |
| | | if (currentSelectedTower.isAtMaxLevel) |
| | | if (currentSelectedTower.IsMaxLevel) |
| | | { |
| | | return; |
| | | } |
| | | int upgradeCost = currentSelectedTower.GetCostForNextLevel(); |
| | | bool successfulUpgrade = EndlessLevelManager.instance.Currency.TryPurchase(upgradeCost); |
| | | if (successfulUpgrade) |
| | | { |
| | | currentSelectedTower.UpgradeTower(); |
| | | } |
| | | currentSelectedTower.UpgradeTower(); |
| | | DeselectTower(); |
| | | } |
| | | |
| | |
| | | { |
| | | throw new InvalidOperationException("Selected Tower is null"); |
| | | } |
| | | if (currentSelectedTower.isAtMaxLevel) |
| | | if (currentSelectedTower.IsMaxLevel) |
| | | return false; |
| | | |
| | | // 直接随机升级,零成本。 |
| | | // 1:记录当前Tower的Level,删除当前的Tower. 2:从TowerLib中随机找一个高一级别的Tower. |
| | | string towerName = currentSelectedTower.towerName; |
| | | if (currentSelectedTower.towerFeature == EFeatureTower.NULL) |
| | | |
| | | if (currentSelectedTower.towerFeature == EFeatureTower.NULL && GameConfig.CreateRandomTower) |
| | | towerName = ""; |
| | | int towerLvl = currentSelectedTower.currentLevel + 1; |
| | | int posx = currentSelectedTower.gridPosition.x; |
| | |
| | | { |
| | | throw new InvalidOperationException("Selected Tower is null"); |
| | | } |
| | | int sellValue = currentSelectedTower.GetSellLevel(); |
| | | if (EndlessLevelManager.instanceExists && sellValue > 0) |
| | | { |
| | | EndlessLevelManager.instance.Currency.AddCurrency(sellValue); |
| | | currentSelectedTower.Sell(); |
| | | currentSelectedTower.Sell(); |
| | | |
| | | // 从列表中删除Tower. |
| | | delTower(currentSelectedTower); |
| | | } |
| | | // 从列表中删除Tower. |
| | | delTower(currentSelectedTower); |
| | | DeselectTower(); |
| | | } |
| | | |
| | |
| | | { |
| | | return; |
| | | } |
| | | int cost = m_CurrentTower.controller.purchaseCost; |
| | | bool successfulPurchase = EndlessLevelManager.instance.Currency.TryPurchase(cost); |
| | | if (successfulPurchase) |
| | | { |
| | | PlaceTower(); |
| | | } |
| | | PlaceTower(); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// Throws exception when not in a build mode or when tower is not a valid position |
| | | /// </exception> |
| | | /// </summary> |
| | | public void BuyTower(UIPointer pointer, bool force = false, bool zeroCost = false) |
| | | public bool BuyTower(UIPointer pointer, bool force = false) |
| | | { |
| | | if (!isBuilding) return; |
| | | if (!isBuilding) return false; |
| | | |
| | | // 判断是否格子上重复放置塔防 |
| | | if (!m_CurrentTower || !IsGhostAtValidPosition()) |
| | |
| | | if (!pointer.raycast.HasValue || pointer.raycast.Value.collider == null) |
| | | { |
| | | CancelGhostPlacement(); |
| | | return; |
| | | return false; |
| | | } |
| | | PlaceGhost(pointer); |
| | | } |
| | | return; |
| | | return true; |
| | | } |
| | | |
| | | // 这是判断是否超出了格子 |
| | |
| | | if (!pointer.raycast.HasValue || pointer.raycast.Value.collider == null) |
| | | { |
| | | CancelGhostPlacement(); |
| | | return; |
| | | return false; |
| | | } |
| | | |
| | | int cost = m_CurrentTower.controller.purchaseCost; |
| | | if (zeroCost) |
| | | cost = 0; |
| | | bool successfulPurchase = EndlessLevelManager.instance.Currency.TryPurchase(cost); |
| | | bool successfulPurchase = EndlessLevelManager.instance.Currency.TryPurchase(0); |
| | | if (successfulPurchase) |
| | | { |
| | | PlaceGhost(pointer); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <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); |
| | | newTower.CurrentTowerLevel.PlayUpGradeEffect(); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | if (m_CurrentTower == null || m_CurrentArea == null) |
| | | return false; |
| | | |
| | | return EndlessLevelManager.instance.Currency.CanAfford(m_CurrentTower.controller.purchaseCost); |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <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 isUpgrade = false, bool opponent = false) |
| | | public void PlaceTower(int lvl = 0, bool isUpgrade = false, bool opponent = false, bool isFirstAppear = false) |
| | | { |
| | | if (!isBuilding) |
| | | throw new InvalidOperationException("Trying to place tower when not in a Build Mode"); |
| | |
| | | // River: 内部缓存数据,用于后期容易找到数据. |
| | | addTower(createdTower); |
| | | CancelGhostPlacement(); |
| | | if (!isUpgrade) |
| | | if (isFirstAppear) |
| | | { |
| | | PlayFirstAppearEffect(createdTower.towerName, createdTower.transform.position); |
| | | } |
| | | else if (!isUpgrade) |
| | | { |
| | | PlayAppearEffect(createdTower.transform.position); |
| | | } |
| | | else |
| | | { |
| | | PlayUpgradeEffect(createdTower); |
| | | } |
| | | |
| | | // 处理成长骰子,复制骰子等等功能. |
| | | if (lvl == 0) |
| | | { |
| | | ProcessFeatureTower(createdTower); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 播放首次宝石出现特效 |
| | | /// </summary> |
| | | public void PlayFirstAppearEffect(string towerName, Vector3 worldPos) |
| | | { |
| | | if (towerName.StartsWith("GrowUpTower")) |
| | | { |
| | | //火元素 |
| | | PlayAppearEffect(worldPos, fireAppearEffect1); |
| | | PlayAppearEffect(worldPos, fireAppearEffect2); |
| | | if (Application.platform == RuntimePlatform.WindowsEditor) |
| | | { |
| | | //UnityEditor.EditorApplication.isPaused = true; |
| | | } |
| | | } |
| | | else if (towerName.StartsWith("BlinkTower")) |
| | | { |
| | | //木元素 |
| | | PlayAppearEffect(worldPos, woodAppearEffect1); |
| | | PlayAppearEffect(worldPos, woodAppearEffect2); |
| | | |
| | | } |
| | | else if (towerName.StartsWith("CopyCatTower")) |
| | | { |
| | | //水元素 |
| | | PlayAppearEffect(worldPos, waterAppearEffect1); |
| | | PlayAppearEffect(worldPos, waterAppearEffect2); |
| | | } |
| | | } |
| | | void PlayAppearEffect(Vector3 worldPos, GameObject prefab) |
| | | { |
| | | 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); |
| | | } |
| | | |
| | | public void PlayAppearEffectGuide(Vector3 worldPos) |
| | | { |
| | | GameObject obj = Instantiate(TowerAppearEffectPrefabGuide); |
| | | 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> |
| | |
| | | Destroy(obj, ps.main.duration); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 播放升级特效 |
| | | /// </summary> |
| | | /// <param name="worldPos"></param> |
| | | public void GuidePlayUpgradeEffect(Vector3 position) |
| | | { |
| | | GameObject effect = TowerUpgradeEffectPrefab; |
| | | |
| | | // 在sTower的位置播放升级特效 |
| | | GameObject obj = Instantiate(effect); |
| | | GameObject obj = Instantiate(TowerUpgradeEffectPrefabGuide); |
| | | obj.transform.position = position; |
| | | |
| | | Vector3 pos = obj.transform.position; |
| | | pos.y += 5f; |
| | | obj.transform.position = pos; |
| | |
| | | |
| | | if (ps == null) |
| | | ps = obj.transform.GetChild(0).GetComponent<ParticleSystem>(); |
| | | |
| | | ps.Play(); |
| | | Destroy(obj, ps.main.duration); |
| | | } |
| | |
| | | if (!towerPriceText) |
| | | { |
| | | towerPriceText = randomTowerBtn.transform.Find("cashText").GetComponent<TextMeshProUGUI>(); |
| | | //towerPriceText1 = SkillTowerBtn.transform.Find("cashText").GetComponent<TextMeshProUGUI>(); |
| | | if (towerPriceText) |
| | | towerPriceText.text = tpMgr.currentTowerPrice.ToString(); |
| | | // if (towerPriceText1) |
| | | // towerPriceText1.text = tpMgr.currentTowerPrice.ToString(); |
| | | } |
| | | else |
| | | { |
| | | towerPriceText.text = tpMgr.currentTowerPrice.ToString(); |
| | | //towerPriceText1.text = tpMgr.currentTowerPrice.ToString(); |
| | | } |
| | | |
| | | // 无法支付新的塔防价格,按钮变灰. |
| | |
| | | if (towerPriceText) |
| | | { |
| | | towerPriceText.color = new Color(0.5f, 0.5f, 0.5f); |
| | | //towerPriceText1.color = new Color(0.5f, 0.5f, 0.5f); |
| | | } |
| | | tdBuyDisable = true; |
| | | } |
| | |
| | | return; |
| | | |
| | | if (towerPriceText) |
| | | { |
| | | towerPriceText.color = new Color(1.0f, 1.0f, 1.0f); |
| | | //towerPriceText1.color = new Color(1.0f, 1.0f, 1.0f); |
| | | } |
| | | |
| | | if (randomTowerBtn) |
| | | { |
| | |
| | | /// <param name="val"></param> |
| | | public void generateBloodText(Vector3 wpos, float val, bool crit = false, bool doubleHit = false, bool poison = false) |
| | | { |
| | | if (Mathf.FloorToInt(val) == 0) return; |
| | | |
| | | Vector3 spos = m_Camera.WorldToScreenPoint(wpos); |
| | | TextMoveDoTween tm; |
| | | if (crit) |
| | |
| | | } |
| | | if (tm) |
| | | { |
| | | tm.GetComponent<Transform>().SetParent(GameObject.Find("MainUI").GetComponent<Transform>(), true); |
| | | string bloodStr = ""; |
| | | if (doubleHit) |
| | | bloodStr += "Dble!"; |
| | | if (crit) |
| | | bloodStr += "Crt!"; |
| | | bloodStr += "-"; |
| | | tm.GetComponent<Transform>().SetParent(GameObject.Find("MainUI/TextPanel").GetComponent<Transform>(), true); |
| | | string bloodStr = "-"; |
| | | bloodStr += ((Int64)val).ToString(); |
| | | |
| | | tm.moveBloodText(spos.x, spos.y, bloodStr, crit); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 减速飘字 |
| | | /// </summary> |
| | | public void FloatSlowDownWord(Vector3 worldPos) |
| | | { |
| | | Vector3 screenPos = m_Camera.WorldToScreenPoint(worldPos); |
| | | GameObject obj = Instantiate(SlowDownWord.gameObject); |
| | | obj.GetComponent<Transform>().SetParent(GameObject.Find("MainUI/TextPanel").GetComponent<Transform>(), false); |
| | | obj.GetComponent<TextMoveDoTween>().FloatSlowDownWord(screenPos.x, screenPos.y); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 暴击飘字 |
| | | /// </summary> |
| | | public void FloatCritWord(Vector3 worldPos) |
| | | { |
| | | Vector3 screenPos = m_Camera.WorldToScreenPoint(worldPos); |
| | | GameObject obj = Instantiate(CritWord.gameObject); |
| | | obj.GetComponent<Transform>().SetParent(GameObject.Find("MainUI/TextPanel").GetComponent<Transform>(), false); |
| | | obj.GetComponent<TextMoveDoTween>().FloatCritWord(screenPos.x, screenPos.y); |
| | | } |
| | | |
| | | private void Start() |
| | |
| | | // 获取相应的放置区域。 |
| | | GameObject placeObj = GameObject.FindGameObjectWithTag("PlaceTower"); |
| | | if (placeObj != null) |
| | | { |
| | | m_CurrentArea = placeObj.GetComponent<IPlacementArea>(); |
| | | dragTowerPlacement = placeObj.GetComponent<IPlacementArea>() as TowerPlacementGridEndless; |
| | | } |
| | | placeObj = GameObject.FindGameObjectWithTag("PlaceTowerOpponent"); |
| | | EventCenter.Ins.Add((int)KTGMGemClient.EventType.EndlessHeartAllLose, AllHeartLose); |
| | | } |
| | |
| | | /// 直接在IPlaceArea上随机放置一个Tower。这是随机放置塔防的入口类。这是入口的塔防类。 |
| | | /// </summary> |
| | | /// <param name="tow"></param> |
| | | public bool RandomPlaceTower(Tower tow, int posx = -1, int posy = -1, int lvl = 0, int forceCost = -1, bool isUpgrade = false) |
| | | public bool RandomPlaceTower(Tower tow, int posx = -1, int posy = -1, int lvl = 0, int forceCost = -1, bool isUpgrade = false, bool isFirstAppear = false) |
| | | { |
| | | // 获取IPlaceArea. |
| | | if (m_CurrentArea == null) |
| | |
| | | bool successfulPurchase = EndlessLevelManager.instance.Currency.TryPurchase(cost); |
| | | if (!successfulPurchase) return false; |
| | | |
| | | EndlessRandomTower.instance.UpdateDescDisplay(); |
| | | SetUpGhostTower(tow); |
| | | //Debug.Log("设置影子塔防."); |
| | | m_CurrentTower.Show(); |
| | |
| | | OnSuccessBuyTower(); |
| | | SetState(State.Building); |
| | | |
| | | PlaceTower(lvl, isUpgrade); |
| | | PlaceTower(lvl, isUpgrade, false, isFirstAppear); |
| | | } |
| | | |
| | | return true; |
| | |
| | | RaycastHit output; |
| | | // River: Raycast的碰撞是游戏内物品的Collider进行碰撞检测的 |
| | | bool hasHit = Physics.Raycast(uiPointer.ray, out output, float.MaxValue, towerSelectionLayer); |
| | | if (!hasHit)//|| uiPointer.overUI) |
| | | if (!hasHit || uiPointer.overUI) |
| | | { |
| | | //Debug.Log("没有点中或者点中了UI:" + hasHit.ToString() + "," + uiPointer.overUI.ToString()); |
| | | return; |
| | |
| | | var controller = output.collider.GetComponent<Tower>(); |
| | | if (controller != null) |
| | | { |
| | | // 泡泡禁锢状态不允许拖动 |
| | | if (controller.IsBondage) return; |
| | | |
| | | SelectTower(controller); |
| | | } |
| | | |
| | | // 计算偏移值. |
| | | CalSelTowerScreenOffset(info, controller); |
| | | } |
| | | |
| | | public void OnPressed(PointerInfo info) |
| | | { |
| | | UIPointer uiPointer = WrapPointer(info); |
| | | RaycastHit output; |
| | | bool hasHit = Physics.Raycast(uiPointer.ray, out output, float.MaxValue, towerSelectionLayer); |
| | | |
| | | if (uiPointer.overUI) return; |
| | | |
| | | if (hasHit) |
| | | { |
| | | Tower controller = output.collider.GetComponent<Tower>(); |
| | | if (controller != null) |
| | | controller.OnPressed(); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | base.Awake(); |
| | | |
| | | DOTween.Init(true, true, LogBehaviour.Verbose).SetCapacity(200, 10); |
| | | randomTowerBtn = transform.Find("BottomCanvas/Panel/TowerBuyBtn").GetComponent<Button>(); |
| | | //DOTween.Init(true, true, LogBehaviour.Verbose).SetCapacity(200, 10); |
| | | |
| | | state = State.Normal; |
| | | m_Camera = GetComponent<Camera>(); |
| | | m_Camera = GameObject.Find("SceneCamera3D").GetComponent<Camera>(); |
| | | //m_Camera = GetComponent<Camera>(); |
| | | TowerDestroyArr = new bool[5, AttackRowNumbers]; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 战场内所有的Tower实例都需要升级相关的数据. |
| | | /// 找到相同类型的所有Tower,然后进行局内升级的修改。 |
| | | /// </summary> |
| | | /// <param name="td"></param> |
| | | protected void towerUpgradeInBattle(TowerLevelUp tlu) |
| | | { |
| | | foreach (Tower tower in m_listTower) |
| | | { |
| | | if (tlu.towerName != tower.towerName) |
| | | continue; |
| | | tower.upGradeInSceneTL(); |
| | | } |
| | | return; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | return currentEventSystem.IsPointerOverGameObject(pointerId); |
| | | } |
| | | |
| | | WaveLineSelEffect currentEffect; |
| | | /// <summary> |
| | | /// Move the ghost to the pointer's position |
| | | /// </summary> |
| | |
| | | if (npt.overWaveLine) |
| | | { |
| | | WaveLineSelEffect selEff = npt.wavelineHit.Value.collider.GetComponent<WaveLineSelEffect>(); |
| | | if (selEff) |
| | | selEff.SetWaveLineSel(true); |
| | | if (selEff != currentEffect) |
| | | { |
| | | if (currentEffect != null) |
| | | { |
| | | currentEffect.SetParticleSystem(false); |
| | | } |
| | | currentEffect = selEff; |
| | | currentEffect.SetParticleSystem(true); |
| | | } |
| | | //selEff.SetWaveLineSel(true); |
| | | } |
| | | else |
| | | { |
| | | if (currentEffect != null) |
| | | { |
| | | currentEffect.SetParticleSystem(false); |
| | | currentEffect = null; |
| | | } |
| | | } |
| | | } |
| | | // 炸弹是区域攻击显示: |
| | | if (m_CurrentTower.controller.towerFeature == EFeatureTower.Skill_Bomb) |
| | | else if (m_CurrentTower.controller.towerFeature == EFeatureTower.Skill_Bomb) |
| | | { |
| | | // 测试代码与战场区域碰撞,碰撞后显示攻击区域: |
| | | BattleAreaRaycast(ref npt); |
| | |
| | | // Place the ghost |
| | | Tower controller = m_CurrentTower.controller; |
| | | Tower createdTower = Instantiate(controller); |
| | | createdTower.Initialize(m_CurrentArea, m_GridPosition); |
| | | createdTower.SetLevel(dragTowerLevel); |
| | | createdTower.Initialize(m_CurrentArea, m_GridPosition, dragTowerLevel); |
| | | |
| | | // ATTENTION TO FIX:是否应该加入List: |
| | | addTower(createdTower); |
| | | PlayToAttackEffect(createdTower.attributeId, createdTower.transform.position); |
| | | PlayToAttackEffect(createdTower.ElfId, createdTower.transform.position); |
| | | dragTowerLevel = 0; |
| | | CancelGhostPlacement(); |
| | | } |
| | |
| | | /// <summary> |
| | | /// 播放宝石上阵特效 |
| | | /// </summary> |
| | | /// <param name="attributeId">101 火,105 水,109 木</param> |
| | | /// <param name="ElfId">101 火,201 水,301 木</param> |
| | | /// <param name="worldPos">世界坐标</param> |
| | | public void PlayToAttackEffect(int attributeId, Vector3 worldPos) |
| | | public void PlayToAttackEffect(int ElfId, Vector3 worldPos) |
| | | { |
| | | string path = $"UI/ToBattle_{attributeId}"; |
| | | string path = $"UI/DengChang_{ElfId}"; |
| | | |
| | | GameObject prefab = Resources.Load<GameObject>(path); |
| | | GameObject obj = Instantiate(prefab); |
| | | obj.transform.position = worldPos; |