chenxin
2020-12-01 944950c86ab3be21c22b7c15039cf2e572efdc90
Assets/Scripts/TowerDefense/Towers/Tower.cs
@@ -1,5 +1,4 @@
using KTGMGemClient;
using System.Collections;
using System;
using ActionGameFramework.Health;
using Core.Utilities;
@@ -38,6 +37,7 @@
    public class Tower : Targetable
    {
        public readonly float INSCENE_TU_DAMAGE = 30f;
        public static readonly int MAX_LEVEL = 4;
        /// <summary>
@@ -59,12 +59,8 @@
        /// 当前塔防对应的MonsterMaterial,自身和对方显示不同的Mat.
        /// </summary>
        public Material materialMonsterSelf;
        public Material materialMonsterOppo;
        /// <summary>
        /// 0 空状态  1 等待状态  2 攻击状态.
        /// </summary>
        protected int curActionState = 0;
        public Material materialMonsterOppo;
        /// <summary>
        /// 塔防对应的充能状态.
@@ -405,26 +401,6 @@
            }
        }
        /// <summary>
        /// This function is called when the object becomes enabled and active.
        /// </summary>
        void OnEnable()
        {
            // if (bulletCtl != null)
            // {
            //     Debug.Log("打开了bulletCtl");
            //     bulletCtl.gameObject.SetActive(true);
            // }
            // if (energyCtl != null)
            // {
            //     Debug.Log("打开了energyCtl");
            //     energyCtl.gameObject.SetActive(true);
            // }
        }
        public void CheckCtrl()
        {
            if (bulletCtl != null)
@@ -461,44 +437,6 @@
        }
        /// <summary>
        /// 初始化当前塔防的局内升级,lvl从1开始.
        /// </summary>
        /// <param name="lvl"></param>
        public void initInSceneTowerLevel(int lvl)
        {
            inSceneTowerLevel = lvl;
            if (lvl <= 1)
            {
                ResetInSceneTowerLevel();
                return;
            }
            // 设置攻击数据的加强,暂时是测试数据,后面需要读取表格数据处理:
            float damageAdd = 0;
            // float damageAdd = (inSceneTowerLevel - 1) * INSCENE_TU_DAMAGE;
            for (int ti = 0; ti < levels.Length; ti++)
            {
                if (levels[ti].levelDamager)
                {
                    levels[ti].levelDamager.doubleHit = bDoubleHitElit;
                    levels[ti].levelDamager.inSceneUpGradeDamage = damageAdd;
                }
            }
        }
        protected void ResetInSceneTowerLevel()
        {
            for (int ti = 0; ti < levels.Length; ti++)
            {
                if (levels[ti].levelDamager)
                {
                    levels[ti].levelDamager.inSceneUpGradeDamage = 0;
                    levels[ti].levelDamager.doubleHit = bDoubleHitElit;
                }
            }
            return;
        }
        /// <summary>
        /// 升级当前塔防的局内等级,需要播放相关的特效
        /// </summary>
        public void upGradeInSceneTL()
@@ -507,16 +445,6 @@
            // 设置攻击数据的加强,暂时是测试数据,后面需要读取表格数据处理:
            float damageAdd = inSceneTowerLevel * INSCENE_TU_DAMAGE;
            for (int ti = 0; ti < levels.Length; ti++)
            {
                if (levels[ti].levelDamager)
                {
                    levels[ti].levelDamager.inSceneUpGradeDamage = damageAdd;
                    levels[ti].levelDamager.towerName = name;
                    levels[ti].levelDamager.bSet = true;
                }
            }
            Debug.Log("Upgrade Tower name is:" + name);
@@ -543,14 +471,6 @@
        public IPlacementArea placementArea { get; private set; }
        /// <summary>
        /// The purchase cost of the tower
        /// </summary>
        public int purchaseCost
        {
            get { return levels[0].cost; }
        }
        /// <summary>
        /// The event that fires off when a player deletes a tower
        /// </summary>
        public Action towerDeleted;
@@ -559,16 +479,6 @@
        /// The event that fires off when a tower has been destroyed
        /// </summary>
        public Action towerDestroyed;
        /// <summary>
        /// 放置到目标位置
        /// </summary>
        /// <param name="destination"></param>
        public virtual void SetToDestination(IntVector2 destination)
        {
            gridPosition = destination;
            transform.position = placementArea.GridToWorld(destination, dimensions);
        }
        /// <summary>
        /// Provide the tower with data to initialize with
@@ -588,38 +498,18 @@
            }
            SetLevel(lvl);
            if (LevelManager.instanceExists)
            {
                LevelManager.instance.levelStateChanged += OnLevelStateChanged;
            }
            else if (EndlessLevelManager.instanceExists)
                EndlessLevelManager.instance.LevelStateChanged += OnLevelStateChanged;
            // 查找Targetter:
            Targetter target = GetComponentInChildren<Targetter>();
            if (target)
            {
                target.bOpponent = opponentSide;
            }
            else
                Debug.Log("在当前的Tower中找不到Targetter.");
            //
            // 初始化当前的局内Tower等级数据
            initInSceneTowerLevel(SceneTowerLvl.getInSceneTowerLvl(towerName));
        }
        /// <summary>
        /// Provides information on the cost to upgrade
        /// </summary>
        /// <returns>Returns -1 if the towers is already at max level, other returns the cost to upgrade</returns>
        public int GetCostForNextLevel()
        {
            if (isAtMaxLevel)
            {
                return -1;
            }
            return levels[currentLevel + 1].cost;
        }
        /// <summary>
@@ -646,38 +536,7 @@
            // Invoke base kill method
            Kill();
        }
        /// <summary>
        /// Provides the value recived for selling this tower
        /// </summary>
        /// <returns>A sell value of the tower</returns>
        public int GetSellLevel()
        {
            return GetSellLevel(currentLevel);
        }
        /// <summary>
        /// Provides the value recived for selling this tower of a particular level
        /// </summary>
        /// <param name="level">Level of tower</param>
        /// <returns>A sell value of the tower</returns>
        public int GetSellLevel(int level)
        {
            // sell for full price if waves haven't started yet
            if (LevelManager.instanceExists && LevelManager.instance.levelState == LevelState.Building
                || EndlessLevelManager.instanceExists && EndlessLevelManager.instance.EndlessLeveltate == LevelState.Building)
            {
                int cost = 0;
                for (int i = 0; i <= level; i++)
                {
                    cost += levels[i].cost;
                }
                return cost;
            }
            return levels[currentLevel].sell;
        }
        /// <summary>
        /// Used to (try to) upgrade the tower data
        /// </summary>
@@ -737,9 +596,6 @@
        public override void Remove()
        {
            base.Remove();
            // 清空局内升级数据:
            ResetInSceneTowerLevel();
            attackRise = 0.0f;
            placementArea.Clear(gridPosition, dimensions);
            Destroy(gameObject);
@@ -779,10 +635,6 @@
            // initialize TowerLevel
            currentTowerLevel.Initialize(this, enemyLayerMask, configuration.alignmentProvider);
            // health data
            ScaleHealth();
            //
            // disable affectors
            LevelState levelState = LevelState.Intro;
            if (LevelManager.instanceExists)
@@ -792,25 +644,6 @@
            bool initialise = levelState == LevelState.AllEnemiesSpawned || levelState == LevelState.SpawningEnemies;
            initialise = false;
            currentTowerLevel.SetAffectorState(initialise, gridPosition.x);
        }
        /// <summary>
        /// Scales the health based on the previous health
        /// Requires override when the rules for scaling health on upgrade changes
        /// </summary>
        protected virtual void ScaleHealth()
        {
            configuration.SetMaxHealth(currentTowerLevel.maxHealth);
            if (currentLevel == 0)
            {
                configuration.SetHealth(currentTowerLevel.maxHealth);
            }
            else
            {
                int currentHealth = Mathf.FloorToInt(configuration.normalisedHealth * currentTowerLevel.maxHealth);
                configuration.SetHealth(currentHealth);
            }
        }
        /// <summary>