chenxin
2020-10-21 146e39c5ef6bb29927cb7c00d7708fceab30a724
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using ActionGameFramework.Health;
using System;
using TowerDefense.Agents;
using TowerDefense.UI.HUD;
using UnityEngine;
using TowerDefense.Level;
using System.Collections.Generic;
using KTGMGemClient;
 
namespace TowerDefense.Towers.Projectiles
{
    [RequireComponent(typeof(Damager))]
    public class BallisticAttack : MonoBehaviour
    {
        /// <summary>
        /// 链式攻击的概率,目前只有一个链式攻击的模式,暂时不需要处理细节,先测试起来
        /// </summary>
        public float chainAttackRate = 0;
 
        /// <summary>
        /// 当前攻击塔位对应的属性ID
        /// </summary>
        public int attributeId = 0;
 
        /// <summary>
        /// The Damager attached to the object
        /// </summary>
        protected Damager damager;
 
        /// <summary>
        /// 攻击增加.
        /// </summary>
        public float attackRise { get; set; }
 
        public void DealDamage(Targetable enemy)
        {
            float finalDamage = damager.finalDamage;
            bool crit = damager.isCrit;
            if (crit)
                finalDamage += finalDamage;
 
            // 精英怪和Boss双倍攻击.
            bool doubleHit = damager.doubleHit && enemy.bElit;
            if (doubleHit)
                finalDamage *= 2;
 
            // 处理光塔对应的攻击增加:
            if (attackRise > 0)
                finalDamage += (finalDamage * attackRise);
            // 破甲状态
            if (enemy.bShieldBreak)
                finalDamage += (finalDamage * 0.1f);
 
            // 处理PVE无尽模式,buff增加的伤害
            finalDamage += ProcessEndlessBuffAttack(finalDamage);
 
            // 提前处理非当前Enemy的爆炸攻击:
            if (chainAttackRate > 0)
                AgentInsManager.instance.StartExplodeAttack((Agent)enemy, finalDamage);
 
            int tid = enemy.liveID;
            Vector3 backPos = enemy.position;
 
            // 这里也可以把碰撞点传进来
            enemy.TakeDamage(finalDamage, enemy.position, damager.alignmentProvider);
 
            // 处理塔位的技能攻击:
            ProcessTowerAttributeAttack(enemy, finalDamage, attributeId);
 
            if (!enemy.opponentAgent)
            {
                if (GameUI.instanceExists)
                    GameUI.instance.generateBloodText(backPos, finalDamage, crit, doubleHit);
                else if (EndlessGameUI.instanceExists)
                    EndlessGameUI.instance.generateBloodText(backPos, finalDamage, crit, doubleHit);
            }
 
            // 播放受击动画:
            if ((!enemy.isDead) && (enemy.liveID == tid))
                (enemy as Agent).PlayOnHit();
        }
 
        /// <summary>
        /// 处理PVE无尽模式buff增加的伤害
        /// </summary>
        /// <param name="finalDamage"></param>
        protected float ProcessEndlessBuffAttack(float finalDamage)
        {
            // 非无尽模式
            if (!EndlessBuffManager.instanceExists) return 0;
 
            List<EndlessBuffConfig> list = EndlessBuffManager.instance.GetBuffListByEffectType(EndlessBuffEffectType.Attack, attributeId);
 
            if (list.Count == 0) return 0;
 
            float ratio = 0;
            float add = 0;
 
            for (int i = 0; i < list.Count; ++i)
            {
                ratio += list[i].Config.buff_effect[1];
                add += list[i].Config.buff_effect[2];
            }
 
            return finalDamage * (1 + ratio / 100f) + add;
        }
 
        /// <summary>
        /// 处理塔位的属性攻击
        /// </summary>
        /// <param name="enemy"></param>
        /// <param name="attid"></param>
        protected void ProcessTowerAttributeAttack(Targetable enemy, float damage, int attid)
        {
            int id = (int)Math.Floor(attid / 10000.0f);
            switch (id)
            {
                case 2:  // 减速.
                    enemy.addSpeedSlowRate(0.25f);
                    enemy.SetTargetableMatColor(Color.blue);
                    break;
                case 3:  // 中毒
                    enemy.poisonAgent(damage, attid);
                    enemy.SetTargetableMatColor(Color.green);
                    break;
                case 5:  // 破甲
                    enemy.bShieldBreak = true;
                    break;
            }
            return;
        }
 
        /// <summary>
        /// Cache the damager component attached to this object
        /// </summary>
        protected virtual void Awake()
        {
            damager = GetComponent<Damager>();
            attackRise = 0.0f;
        }
    }
}