| | |
| | | public State state { get; private set; } |
| | | |
| | | /// <summary> |
| | | /// 局内塔防类型的升级数据 |
| | | /// </summary> |
| | | public List<SceneTowerLvl> sceneTowerLvlList; |
| | | |
| | | /// <summary> |
| | | /// The currently selected tower |
| | | /// </summary> |
| | | public LayerMask placementAreaMask; |
| | |
| | | /// </summary> |
| | | protected int uiCtlProgresss = 0; |
| | | |
| | | /// <summary> |
| | | /// 宝石升级特效 |
| | | /// </summary> |
| | | public GameObject TowerUpgradeEffect; |
| | | |
| | | /// <summary> |
| | | /// 宝石出现特效 |
| | | /// </summary> |
| | | public GameObject TowerAppearEffect; |
| | | |
| | | /// <summary> |
| | | /// Fires when the <see cref="State"/> changes |
| | |
| | | public void delTower(Tower t) |
| | | { |
| | | // 删除Tower之前去掉充能条数据. |
| | | if( t.bInAttackMode) |
| | | if (t.bInAttackMode) |
| | | t.DisableTowerUICtrl(); |
| | | |
| | | // 删除Tower有可能对应的Timer. |
| | |
| | | towerOld.showTower(false); |
| | | towerToMove = towerOld; |
| | | |
| | | if( towerOld.bInAttackMode) |
| | | if (towerOld.bInAttackMode) |
| | | { |
| | | int pro = towerOld.GetTowerUICtrlProgress(); |
| | | uiCtlProgresss = pro; |
| | |
| | | SetToDragMode(newT); |
| | | |
| | | if (towerOld.towerFeature == EFeatureTower.Skill_Bomb) |
| | | m_CurrentTower.SetAttackArea(dragTowerLevel, towerOld.attributeId); |
| | | m_CurrentTower.SetAttackArea(dragTowerLevel, towerOld.ElfId); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | if (m_CurrentTower == null || !IsGhostAtValidPosition()) |
| | | { |
| | | // 最大级别的Tower不能再合并了. |
| | | if (towerToMove.isAtMaxLevel) |
| | | if (towerToMove.IsMaxLevel) |
| | | return false; |
| | | |
| | | // 判断格子上的塔防: |
| | |
| | | Tower tw = FindTowerWithGridIdx(m_GridPosition.x, m_GridPosition.y); |
| | | if (tw != null) |
| | | { |
| | | LevelManager.instance.startWaveLine(m_GridPosition.x, false, tw.attributeId); |
| | | |
| | | LevelManager.instance.startWaveLine(m_GridPosition.x, false, tw.ElfId); |
| | | |
| | | // 顺便设置界面的进展 |
| | | if (uiCtlProgresss > 0) |
| | | { |
| | |
| | | ray = m_Camera.ScreenPointToRay(tp.currentPosition) |
| | | }; |
| | | |
| | | int sId = towerToMove.attributeId; |
| | | int sId = towerToMove.ElfId; |
| | | int sLevel = towerToMove.currentLevel; |
| | | |
| | | // 火是列攻击: |
| | |
| | | { |
| | | throw new InvalidOperationException("Selected Tower is null"); |
| | | } |
| | | if (currentSelectedTower.isAtMaxLevel) |
| | | if (currentSelectedTower.IsMaxLevel) |
| | | { |
| | | return; |
| | | } |
| | | int upgradeCost = currentSelectedTower.GetCostForNextLevel(); |
| | | bool successfulUpgrade = LevelManager.instance.currency.TryPurchase(upgradeCost); |
| | | if (successfulUpgrade) |
| | | { |
| | | currentSelectedTower.UpgradeTower(); |
| | | } |
| | | //towerUI.Hide(); |
| | | currentSelectedTower.UpgradeTower(); |
| | | DeselectTower(); |
| | | } |
| | | |
| | |
| | | { |
| | | throw new InvalidOperationException("Selected Tower is null"); |
| | | } |
| | | if (currentSelectedTower.isAtMaxLevel) |
| | | if (currentSelectedTower.IsMaxLevel) |
| | | return false; |
| | | |
| | | // 直接随机升级,零成本。 |
| | |
| | | { |
| | | throw new InvalidOperationException("Selected Tower is null"); |
| | | } |
| | | int sellValue = currentSelectedTower.GetSellLevel(); |
| | | if (LevelManager.instanceExists && sellValue > 0) |
| | | { |
| | | LevelManager.instance.currency.AddCurrency(sellValue); |
| | | currentSelectedTower.Sell(); |
| | | currentSelectedTower.Sell(); |
| | | |
| | | // 从列表中删除Tower. |
| | | delTower(currentSelectedTower); |
| | | } |
| | | // 从列表中删除Tower. |
| | | delTower(currentSelectedTower); |
| | | DeselectTower(); |
| | | } |
| | | |
| | |
| | | { |
| | | return; |
| | | } |
| | | int cost = m_CurrentTower.controller.purchaseCost; |
| | | bool successfulPurchase = LevelManager.instance.currency.TryPurchase(cost); |
| | | if (successfulPurchase) |
| | | { |
| | | PlaceTower(); |
| | | } |
| | | PlaceTower(); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | //UpgradeSelectedTower(); |
| | | // 新的代码,合并升级为随机塔防类型. |
| | | randomUpgradeTower(); |
| | | |
| | | } |
| | | } |
| | | else |
| | |
| | | CancelGhostPlacement(); |
| | | return; |
| | | } |
| | | int cost = m_CurrentTower.controller.purchaseCost; |
| | | if (zeroCost) |
| | | cost = 0; |
| | | bool successfulPurchase = LevelManager.instance.currency.TryPurchase(cost); |
| | | if (successfulPurchase) |
| | | PlaceGhost(pointer); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 播放升级特效 |
| | | /// </summary> |
| | | /// <param name="worldPos"></param> |
| | | public void PlayUpgradeEffect(Tower newTower) |
| | | { |
| | | GameObject effect = TowerUpgradeEffect; |
| | | |
| | | if (newTower.towerFeature == EFeatureTower.NULL) |
| | | { |
| | | PlaceGhost(pointer); |
| | | string path = $"UI/ToBattle_{newTower.ElfId}"; |
| | | 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> |
| | |
| | | { |
| | | return false; |
| | | } |
| | | return LevelManager.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 opponent = false) |
| | | public void PlaceTower(int lvl = 0, bool opponent = false, bool isUpgrade = false) |
| | | { |
| | | if (!isBuilding) |
| | | throw new InvalidOperationException("Trying to place tower when not in a Build Mode"); |
| | |
| | | |
| | | CancelGhostPlacement(); |
| | | |
| | | if (!opponent) |
| | | { |
| | | if (!isUpgrade) |
| | | PlayAppearEffect(createdTower.transform.position); |
| | | else |
| | | PlayUpgradeEffect(createdTower); |
| | | } |
| | | |
| | | // 处理成长骰子,复制骰子等等功能. |
| | | if (lvl == 0) |
| | | { |
| | | ProcessFeatureTower(createdTower); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 播放宝石出现特效 |
| | | /// </summary> |
| | | public void PlayAppearEffect(Vector3 worldPos) |
| | | { |
| | | GameObject obj = Instantiate(TowerAppearEffect); |
| | | 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> |
| | |
| | | if (lvl == 0) |
| | | { |
| | | Tower tw = OpponentMgr.instance.getTower(tposx, tposy); |
| | | LevelManager.instance.startWaveLine(tposx, true, tw.attributeId); |
| | | LevelManager.instance.startWaveLine(tposx, true, tw.ElfId); |
| | | } |
| | | |
| | | } |
| | |
| | | /// <param name="x"></param> |
| | | /// <param name="y"></param> |
| | | /// <param name="val"></param> |
| | | public void generateBloodText(Vector3 wpos, float val, bool crit = false, bool doubleHit = false, bool poison = false) |
| | | public void generateBloodText(Vector3 wpos, float val, bool crit = false, bool poison = false) |
| | | { |
| | | if (Mathf.FloorToInt(val) == 0) return; |
| | | |
| | | Vector3 spos = m_Camera.WorldToScreenPoint(wpos); |
| | | TextMoveDoTween tm; |
| | | if (crit) |
| | |
| | | { |
| | | tm.GetComponent<Transform>().SetParent(GameObject.Find("BattleMainUI").GetComponent<Transform>(), true); |
| | | string bloodStr = ""; |
| | | if (doubleHit) |
| | | bloodStr += "Dble!"; |
| | | if (crit) |
| | | bloodStr += "Crt!"; |
| | | bloodStr += "-"; |
| | |
| | | /// 直接在IPlaceArea上随机放置一个Tower。这是随机放置塔防的入口类。这是入口的塔防类。 |
| | | /// </summary> |
| | | /// <param name="tow"></param> |
| | | public void RandomPlaceTower(Tower tow, int posx = -1, int posy = -1, int lvl = 0) |
| | | public void RandomPlaceTower(Tower tow, int posx = -1, int posy = -1, int lvl = 0, bool isUpgrade = false) |
| | | { |
| | | // 获取IPlaceArea. |
| | | if (m_CurrentArea == null) |
| | |
| | | OnSuccessBuyTower(); |
| | | SetState(State.Building); |
| | | |
| | | PlaceTower(lvl); |
| | | PlaceTower(lvl, false, isUpgrade); |
| | | } |
| | | } |
| | | |
| | |
| | | if (!LevelManager.instance) |
| | | return; |
| | | |
| | | } |
| | | |
| | | /// <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> |
| | |
| | | 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); |
| | | dragTowerLevel = 0; |
| | | CancelGhostPlacement(); |
| | | PlayToAttackEffect(createdTower.ElfId, createdTower.transform.position); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 播放宝石上阵特效 |
| | | /// </summary> |
| | | /// <param name="ElfId">101 火,201 水,301 木</param> |
| | | /// <param name="worldPos">世界坐标</param> |
| | | public void PlayToAttackEffect(int ElfId, Vector3 worldPos) |
| | | { |
| | | string path = $"UI/ToBattle_{ElfId}"; |
| | | 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> |
| | | /// 更新每一个 |
| | | /// </summary> |
| | | protected void updateSceneTowerUpgradeStatus() |
| | | { |
| | | bool zeroTower = m_listTower.Count == 0; |
| | | int tlen = sceneTowerLvlList.Count; |
| | | /* for( int ti = 0;ti<tlen;ti ++) |
| | | { |
| | | SceneTowerLvl stl = sceneTowerLvlList[ti]; |
| | | bool cashEnable = LevelManager.instance.currency.currentCurrency >= stl.upgradeCash; |
| | | if (zeroTower) |
| | | cashEnable = false; |
| | | if( cashEnable != stl.canInteract) |
| | | { |
| | | stl.enableSceneTower(cashEnable); |
| | | } |
| | | }*/ |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Modifies the valid rendering of the ghost tower once there is enough currency |
| | | /// </summary> |
| | | protected virtual void OnCurrencyChanged() |
| | |
| | | var tpMgr = TowerPrice.instance; |
| | | if (tpMgr.currentTowerPrice > LevelManager.instance.currency.currentCurrency) |
| | | disableRandomTowerBtn(); |
| | | |
| | | // 处理场景内升级相关的内容 |
| | | updateSceneTowerUpgradeStatus(); |
| | | |
| | | |
| | | if (!isBuilding || m_CurrentTower == null || m_CurrentArea == null) |
| | | { |