wangguan
2020-12-10 e7661242ed216f071872e8205acef11b9477837b
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
using UnityEngine.UI;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using TowerDefense.Level;
using Core.Utilities;
using TowerDefense.Agents;
using Core.Health;
using TowerDefense.UI.HUD;
using TowerDefense.Towers;
using TowerDefense.Towers.Projectiles;
 
/**
 * 水精灵技能-冷冻气息控制脚本
 * @Author: chenxin
 * @Date: 2020-11-12 14:41:23
 */
namespace KTGMGemClient
{
    public class FreezeBreath : MonoBehaviour
    {
        public Image ProgressImg;
 
        private int currentProgress;
 
        /// <summary>
        /// 充能时间(s)
        /// </summary>
        public static float ChargeTime { get; private set; } = 10f;
 
        /// <summary>
        /// 伤害时间
        /// </summary>
        public float EffectTime { get; private set; } = 2f;
 
        /// <summary>
        /// 伤害结算次数
        /// </summary>
        /// <value></value>
        public int DamageCount { get; private set; } = 6;
 
        /// <summary>
        /// 整个技能时间
        /// </summary>
        public float SkillTime { get; private set; } = 2.5f;
 
        /// <summary>
        /// 当前的充能进度
        /// </summary>
        public int CurrentProgress { get; private set; }
 
        /// <summary>
        /// 喷冰特效
        /// </summary>
        public GameObject FreezeJet;
 
        public int ReleaseCount { get; set; }
 
        public void SetCtrlProgress(int progress)
        {
            if (progress == (int)Mathf.Floor(ChargeTime))
                progress = 0;
 
            ProgressImg.rectTransform.DOKill();
            SetProgress(progress, false);
        }
 
        public void SetProgress(int progress, bool ani = true)
        {
            if (CurrentProgress == progress) return;
 
            CurrentProgress = progress;
            ProgressImg.rectTransform.DOScaleY(progress / ChargeTime, ani ? 0.3f : 0);
        }
 
        public void SetProgress(float progress)
        {
            ProgressImg.rectTransform.DOScaleY(progress / ChargeTime, 0);
            CurrentProgress = (int)Mathf.Floor(progress);
        }
 
        /// <summary>
        /// 释放冷冻气息
        /// </summary>
        /// <param name="waveLineId">哪条兵线</param>
        /// <param name="damage">伤害值</param>
        public void ReleaseFreeze(int waveLineId, Tower tower, IAlignmentProvider alignmentProvider)
        {
            WaveLineAgentInsMgr[] agentInsMgrs = AgentInsManager.instance.GetWaveLineList();
            WaveLineAgentInsMgr waveLineAgentInsMgr = agentInsMgrs[waveLineId];
            List<Agent> list = waveLineAgentInsMgr.listAgent;
 
            if (list.Count == 0) return;
 
            List<Agent> agentList = new List<Agent>();
 
            for (int i = 0; i < list.Count; ++i)
            {
                agentList.Add(list[i]);
            }
 
            // 一次性死亡数量
            int deathCount = 0;
 
            while (agentList.Count > 0)
            {
                Agent agent = agentList[0];
                agentList.Remove(agentList[0]);
 
                if (agent.isDead) continue;
 
                if (agent.AgentType == SpawnAgentType.Normal)
                {
                    float damage = GetFinalDamage(tower, agent);
                    bool needFrost = BallisticAttack.HandleWaterFrost(201, agent, ref damage);
                    agent.addSpeedSlowRate(0.15f);
                    agent.PlayOnHitImmediately();
 
                    if (!agent.HasSlowDownText)
                    {
                        EndlessGameUI.instance.FloatSlowDownWord(agent.position);
                        agent.HasSlowDownText = true;
                    }
 
 
                    agent.TakeDamage(damage, agent.position, alignmentProvider);
 
                    if (agent.isDead)
                        ++deathCount;
                    else if (needFrost)
                    {
                        agent.IsFrost = true;
                        agent.FrostRemainTime = FrostTimeAdd.DefaultFrostTime;
                        FrostTimeAdd frostTimeAdd = (FrostTimeAdd)EndlessBuffManager.instance.GetBuffInstanceByType(EndlessBuffEffectType.FrostTimeAdd);
 
                        if (frostTimeAdd != null)
                            agent.FrostRemainTime = frostTimeAdd.GetFrostTime(201);
                    }
                }
                else if (agent.AgentType == SpawnAgentType.BubbleBomb)
                    EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessBossSkillBubbleBombGetHit, (agent as BubbleBombAgent).Id);
            }
 
            if (deathCount > 1)
                EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessOneTimeKillCount, deathCount);
        }
 
        private float GetFinalDamage(Tower tower, Agent agent)
        {
            if (tower == null || agent == null) return 0;
 
            int elfId = 201;
            // 基础伤害 = elf_info 基础攻击力 * elf_upgrade 攻击比率 / 1000f
            float basicDamage = ElfInfoData.GetBasicDamage(elfId, tower.currentLevel);
            elf_info info = ElfInfoData.GetDataById(elfId);
 
            // 处理PVE无尽模式,buff增加的伤害
            if (EndlessBuffManager.instanceExists)
                basicDamage += EndlessBuffManager.instance.ProcessEndlessBuffAttack(basicDamage, elfId);
 
            bool crit = BallisticAttack.IsCrit(elfId);
 
            if (crit)
            {
                float basicCritDamageRate = info != null ? info.b_critdmg / 1000f : 0f;
                basicDamage *= 1 + basicCritDamageRate + BallisticAttack.GetCritDamageRate(elfId);
            }
 
            return basicDamage;
        }
 
        public void PlayFreezeEffect(int waveLineId)
        {
            WaveLineAgentInsMgr[] agentInsMgrs = AgentInsManager.instance.GetWaveLineList();
            WaveLineAgentInsMgr waveLineAgentInsMgr = agentInsMgrs[waveLineId];
            List<Agent> list = waveLineAgentInsMgr.listAgent;
 
            if (list.Count == 0) return;
 
            GameObject obj = Poolable.TryGetPoolable(FreezeJet);
            ParticleSystem ps = obj.GetComponent<ParticleSystem>();
 
            if (ps == null) ps = obj.transform.GetChild(0).GetComponent<ParticleSystem>();
 
            ps.transform.position = EndlessLevelManager.instance.WaveManager.GetWaveEndPos(waveLineId);
            ps.Play();
            AudioSourceManager.Ins.Play(AudioEnum.WaterTowerSkill);
 
        }
    }
}