chenxin
2020-12-02 cc7ed63c3efab2640c9cc56225519ab187fd7cbc
Assets/Scripts/TowerDefense/Towers/Tower.cs
@@ -36,8 +36,6 @@
    /// </summary>
    public class Tower : Targetable
    {
        public static readonly int MAX_LEVEL = 4;
        /// <summary>
        /// A generalised name common to a levels
        /// </summary>
@@ -52,13 +50,6 @@
        /// 是否是特色骰子,如果是,则选择一个Enum类型。
        /// </summary>
        public EFeatureTower towerFeature = EFeatureTower.NULL;
        /// <summary>
        /// 当前塔防对应的MonsterMaterial,自身和对方显示不同的Mat.
        /// </summary>
        public Material materialMonsterSelf;
        public Material materialMonsterOppo;
        /// <summary>
        /// 塔防对应的充能状态.
@@ -77,17 +68,15 @@
        /// <summary>
        /// The tower levels associated with this tower
        /// </summary>
        public TowerLevel[] levels;
        [SerializeField]
        private TowerLevel towerLevel;
        public TowerLevel CurrentTowerLevel { get; private set; }
        /// <summary>
        /// 当前塔防对应的AttributeID.
        /// 精灵id,一一对应 elf_info表中的id,唯一的区分每一种精灵塔
        /// </summary>
        public int attributeId;
        /// <summary>
        /// 当前的Tower在游戏内UI界面上用到的Image数据,再以后应该是直接在表格内配置才合适
        /// </summary>
        public Sprite uiImage;
        public int ElfId;
        /// <summary>
        /// The physics mask the tower searches on
@@ -100,16 +89,6 @@
        public int currentLevel { get; protected set; }
        protected bool m_bInAttackMode = false;
        /// <summary>
        /// 精英怪和Boss双倍伤害.
        /// </summary>
        public bool bDoubleHitElit = false;
        /// <summary>
        /// Reference to the data of the current level
        /// </summary>
        public TowerLevel currentTowerLevel { get; protected set; }
        /// <summary>
        /// 攻击增加
@@ -135,14 +114,6 @@
        /// </summary>
        public Agent WoodAimAgent;
        /// <summary>
        /// 塔防数据的局内升级
        /// </summary>
        public int inSceneTowerLevel
        {
            get; set;
        }
        public int uiProOffset
        {
            get { return progressOffset; }
@@ -152,9 +123,9 @@
        /// <summary>
        /// Gets whether the tower can level up anymore
        /// </summary>
        public bool isAtMaxLevel
        public bool IsMaxLevel
        {
            get { return currentLevel == levels.Length - 1; }
            get { return currentLevel == ElfUpgradeData.MaxTowerLevel - 1; }
        }
        /// <summary>
@@ -219,25 +190,25 @@
            set
            {
                m_bInAttackMode = value;
                currentTowerLevel.SetAffectorState(m_bInAttackMode, gridPosition.x);
                currentTowerLevel.SetAttackState(value);
                CurrentTowerLevel.SetAffectorState(m_bInAttackMode, gridPosition.x);
                CurrentTowerLevel.SetAttackState(value);
                if (value)
                {
                    if (opponentSide)
                    {
                        OpponentMgr.instance.SetTowerAttID(gridPosition.x, attributeId, currentLevel);
                        OpponentMgr.instance.SetTowerAttID(gridPosition.x, ElfId, currentLevel);
                    }
                    else
                    {
                        if (LevelManager.instanceExists)
                        {
                            LevelManager.instance.SetTowerAttID(gridPosition.x, attributeId, currentLevel);
                            LevelManager.instance.SetTowerAttID(gridPosition.x, ElfId, currentLevel);
                            WaveLineSelMgr.instance.attackTowerFixed(gridPosition.x);
                        }
                        else if (EndlessLevelManager.instanceExists)
                        {
                            EndlessLevelManager.instance.SetTowerAttID(gridPosition.x, attributeId, currentLevel);
                            EndlessLevelManager.instance.SetTowerAttID(gridPosition.x, ElfId, currentLevel);
                            EndlessWaveLineManager.instance.AttackTowerFixed(gridPosition.x, PlayWaveLineFlash);
                        }
                    }
@@ -439,16 +410,10 @@
        /// </summary>
        public void upGradeInSceneTL()
        {
            inSceneTowerLevel++;
            // cx test
            // 设置攻击数据的加强,暂时是测试数据,后面需要读取表格数据处理:
            float damageAdd = inSceneTowerLevel;
            Debug.Log("Upgrade Tower name is:" + name);
            // 播放相关的特效
            currentTowerLevel.PlayUpGradeEffect();
            CurrentTowerLevel.PlayUpGradeEffect();
        }
        /// <summary>
@@ -456,7 +421,7 @@
        /// </summary>
        public TowerPlacementGhost towerGhostPrefab
        {
            get { return levels[currentLevel].towerGhostPrefab; }
            get { return towerLevel.towerGhostPrefab; }
        }
        /// <summary>
@@ -535,13 +500,13 @@
            // Invoke base kill method
            Kill();
        }
        /// <summary>
        /// Used to (try to) upgrade the tower data
        /// </summary>
        public virtual bool UpgradeTower()
        {
            if (isAtMaxLevel)
            if (IsMaxLevel)
            {
                return false;
            }
@@ -576,10 +541,8 @@
        /// </returns>
        public virtual bool UpgradeTowerToLevel(int level)
        {
            if (level < 0 || isAtMaxLevel || level >= levels.Length)
            {
                return false;
            }
            if (level < 0 || IsMaxLevel || level >= ElfUpgradeData.MaxTowerLevel) return false;
            SetLevel(level);
            return true;
        }
@@ -616,23 +579,19 @@
        /// <summary>
        /// Cache and update oftenly used data
        /// </summary>
        public void SetLevel(int level)
        protected void SetLevel(int level)
        {
            if (level < 0 || level >= levels.Length)
            {
                return;
            }
            if (level < 0 || level >= ElfUpgradeData.MaxTowerLevel) return;
            currentLevel = level;
            if (currentTowerLevel != null)
            {
                Destroy(currentTowerLevel.gameObject);
            }
            // instantiate the visual representation
            currentTowerLevel = Instantiate(levels[currentLevel], transform);
            // cx test 不需要删除,直接刷新等级显示还有body的显示即可
            if (CurrentTowerLevel != null)
                Destroy(CurrentTowerLevel.gameObject);
            // initialize TowerLevel
            currentTowerLevel.Initialize(this, enemyLayerMask, configuration.alignmentProvider);
            CurrentTowerLevel = Instantiate(towerLevel, transform);
            CurrentTowerLevel.Initialize(this, enemyLayerMask, configuration.alignmentProvider);
            CurrentTowerLevel.SetShowLevel(level + 1);
            // disable affectors
            LevelState levelState = LevelState.Intro;
@@ -642,7 +601,7 @@
                levelState = EndlessLevelManager.instance.EndlessLeveltate;
            bool initialise = levelState == LevelState.AllEnemiesSpawned || levelState == LevelState.SpawningEnemies;
            initialise = false;
            currentTowerLevel.SetAffectorState(initialise, gridPosition.x);
            CurrentTowerLevel.SetAffectorState(initialise, gridPosition.x);
        }
        /// <summary>
@@ -652,8 +611,7 @@
        {
            bool initialise = current == LevelState.AllEnemiesSpawned || current == LevelState.SpawningEnemies;
            initialise = false;
            //currentTowerLevel.SetAffectorState(initialise);
            currentTowerLevel.SetAffectorState(bInAttackMode, gridPosition.x);
            CurrentTowerLevel.SetAffectorState(bInAttackMode, gridPosition.x);
        }
    }
}