chenxin
2020-11-28 ee2cbc86ed58ae03a092b67690d3869ebe78fd20
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
using System;
using System.Collections.Generic;
using ActionGameFramework.Audio;
using ActionGameFramework.Health;
using Core.Health;
using TowerDefense.Targetting;
using TowerDefense.Towers;
using TowerDefense.Towers.Projectiles;
using UnityEngine;
using KTGMGemClient;
using TowerDefense.Agents;
using TowerDefense.Level;
 
namespace TowerDefense.Affectors
{
    /// <summary>
    /// The common effect for handling firing projectiles to attack
    /// 
    /// Requires an ILauncher but it is not automatically added
    /// Add an ILauncher implementation to this GameObject before you add this script
    /// </summary>
    [RequireComponent(typeof(ILauncher))]
    public class AttackAffector : Affector, ITowerRadiusProvider
    {
        /// <summary>
        /// The projectile used to attack
        /// </summary>
        public GameObject projectile;
 
        /// <summary>
        /// 木塔最后一击是特殊攻击,需要替换projectile
        /// </summary>
        public GameObject woodProjectile_SP;
        // 
        protected GameObject projectile1;
        protected GameObject projectile2;
 
        /// <summary>
        /// The list of points to launch the projectiles from
        /// </summary>
        public Transform[] projectilePoints;
 
        /// <summary>
        /// The reference to the center point where the tower will search from
        /// </summary>
        public Transform epicenter;
 
        /// <summary>
        /// Configuration for when the tower does splash damage
        /// </summary>
        public bool isMultiAttack;
 
        /// <summary>
        /// 如果是多目标攻击,最多攻击目标
        /// </summary>
        public int maxAttackNum = 1;
 
        /// <summary>
        /// The fire rate in fires-per-second
        /// </summary>
        [SerializeField]
        private float projectileFireRate = 1;
 
        public float FireRate
        {
            get { return 1 / GetFireDuration(); }
        }
 
        /// <summary>
        /// 是否木属性数据
        /// </summary>
        public bool bWoodAffector = false;
 
        /// <summary>
        /// The audio source to play when firing
        /// </summary>
        public RandomAudioSource randomAudioSource;
 
        /// <summary>
        /// Gets the targetter
        /// </summary>
        public Targetter towerTargetter;
 
        /// <summary>
        /// Color of effect radius visualization
        /// </summary>
        public Color radiusEffectColor;
 
        /// <summary>
        /// Search condition
        /// </summary>
        public Filter searchCondition;
 
        /// <summary>
        /// Fire condition
        /// </summary>
        public Filter fireCondition;
 
        /// <summary>
        /// The reference to the attached launcher
        /// </summary>
        protected ILauncher m_Launcher;
 
        /// <summary>
        /// The time before firing is possible
        /// </summary>
        protected float m_FireTimer;
 
        protected float freezeBreathTimer;
 
        /// <summary>
        /// Reference to the current tracked enemy
        /// </summary>
        protected Targetable m_TrackingEnemy;
 
        public TowerLevel towerLevel;
 
        /// <summary>
        /// 处理装弹时间.
        /// </summary>
        protected float fillBulletTime = 0.0f;
 
        /// <summary>
        /// 火精灵充能时间
        /// </summary>
        protected float energyCalTime = 0;
 
        protected float fInEnergy = 0;
 
        protected float fBackupTimer = 0.0f;
 
        /// <summary>
        /// 水精灵的充能时间
        /// </summary>
        protected float freezeBreathCallTime = 0;
 
        protected float inFreezeBreath;
 
        protected float freezeBreathBackTimer = 0;
 
        private int towerAttributeId;
 
        /// <summary>
        /// 火精灵技能固定攻击倍速
        /// </summary>
        /// <value></value>
        protected float fireSpeed { get; set; } = 5f;
 
        /// <summary>
        /// 木属性精灵蓄力时间
        /// </summary>
        protected float woodChargeTime { get; set; } = 1.5f;
 
        protected float woodRemainChargeTime { get; set; }
 
        /// <summary>
        /// 蓄力特效时间
        /// </summary>
        protected float woodChargeEffectTime { get; set; }
 
        /// <summary>
        /// 木属性精灵蓄力特效
        /// </summary>
        public ParticleSystem WoodChargeEffect;
 
        public Transform WoodChargeTransform;
 
        /// <summary>
        /// 木属性正在瞄准的Agent
        /// </summary>
        protected Agent woodAimAgent;
 
        /// <summary>
        /// 火精灵攻击最终攻击倍速,里面计算了buff增加的倍速
        /// </summary>
        /// <value></value>
        public float finalFireSpeed
        {
            get
            {
                FireRateAdd fireRateAdd = (FireRateAdd)EndlessBuffManager.instance.GetBuffInstanceByType(EndlessBuffEffectType.FireRateAdd);
                float rateAdd = 0;
 
                if (fireRateAdd != null)
                    rateAdd = fireRateAdd.GetFireSpeedAdd(towerPtr.attributeId);
                return rateAdd > 1 ? rateAdd : fireSpeed;
            }
        }
 
        /// <summary>
        /// Gets the search rate from the targetter
        /// </summary>
        public float searchRate
        {
            get { return towerTargetter.searchRate; }
            set { towerTargetter.searchRate = value; }
        }
 
        /// <summary>
        /// Gets the targetable
        /// </summary>
        public Targetable trackingEnemy
        {
            get { return m_TrackingEnemy; }
        }
 
        /// <summary>
        /// Gets or sets the attack radius
        /// </summary>
        public float effectRadius
        {
            get { return towerTargetter.effectRadius; }
        }
 
        public Color effectColor
        {
            get { return radiusEffectColor; }
        }
 
        public Targetter targetter
        {
            get { return towerTargetter; }
        }
 
        /// <summary>
        /// Initializes the attack affector
        /// </summary>
        public override void Initialize(IAlignmentProvider affectorAlignment)
        {
            Initialize(affectorAlignment, -1);
        }
 
        /// <summary>
        /// 返回可能存在的Targetter.
        /// </summary>
        /// <returns></returns>
        public override TowerDefense.Targetting.Targetter GetTargetter()
        {
            return targetter;
        }
 
        /// <summary>
        /// Initialises the  attack affector with a layer mask
        /// </summary>
        public override void Initialize(IAlignmentProvider affectorAlignment, LayerMask mask)
        {
            base.Initialize(affectorAlignment, mask);
            SetUpTimers();
 
            towerTargetter.ResetTargetter();
            towerTargetter.alignment = affectorAlignment;
            towerTargetter.acquiredTarget += OnAcquiredTarget;
            // towerTargetter.lostTarget += OnLostTarget;
            GetAudioEnum();
 
            myTower = transform.parent.GetComponent<TowerLevel>();
 
        }
        private AudioEnum audioEnum;//当前音乐的种类
 
        void GetAudioEnum()
        {
            if (transform.parent.name.StartsWith("GrowUpTower"))
            {
                //火元素
                audioEnum = AudioEnum.FireTAttack;
            }
            else if (transform.parent.name.StartsWith("BlinkTower"))
            {
                //木元素
                audioEnum = AudioEnum.WoodTAttack;
            }
            else if (transform.parent.name.StartsWith("CopyCatTower"))
            {
                //水元素
                audioEnum = AudioEnum.WaterTAttack;
            }
        }
 
        void OnDestroy()
        {
            towerTargetter.acquiredTarget -= OnAcquiredTarget;
            // towerTargetter.lostTarget -= OnLostTarget;
        }
 
        void OnAcquiredTarget(Targetable acquiredTarget)
        {
            // m_TrackingEnemy = acquiredTarget;
        }
 
        public Damager damagerProjectile
        {
            get { return projectile == null ? null : projectile.GetComponent<Damager>(); }
        }
 
        public Damager damagerProjectile1
        {
            get { return projectile == null ? null : projectile.GetComponent<Damager>(); }
        }
 
        public Damager damagerProjectile2
        {
            get { return projectile == null ? null : projectile.GetComponent<Damager>(); }
        }
 
 
        /// <summary>
        /// Returns the total projectile damage 
        /// </summary>
        public float GetProjectileDamage()
        {
            var splash = projectile.GetComponent<SplashDamager>();
            float splashDamage = splash != null ? splash.damage : 0;
            return damagerProjectile.finalDamage + splashDamage;
        }
 
        /// <summary>
        /// Initialise the RepeatingTimer
        /// </summary>
        protected virtual void SetUpTimers()
        {
            m_Launcher = GetComponent<ILauncher>();
        }
 
        TowerLevel myTower;
        bool fireState = false;
        protected void updateTowerSkillData()
        {
            HandleBullet();
            HandleEnergy();
            HandleFreezeBreath();
        }
 
        // 处理木精灵装填子弹
        private void HandleBullet()
        {
            if (woodRemainChargeTime > 0f)
                woodRemainChargeTime -= Time.deltaTime;
 
            if (woodChargeEffectTime > 0f)
            {
                woodChargeEffectTime -= Time.deltaTime;
                UpdateWoodAim();
 
                if (woodChargeEffectTime <= 0)
                {
                    towerPtr.IsWoodCharge = false;
                    CancelWoodAim();
                    WoodChargeEffect.Stop();
                }
            }
 
            // 预留出来装填子弹的时间.
            if (fillBulletTime > 0)
            {
                fillBulletTime -= Time.deltaTime;
                if (fillBulletTime <= 0.3f)
                {
                    if (towerPtr && towerPtr.bulletCtl)
                        towerPtr.bulletCtl.ResetToMaxBullet();
                }
 
                if (fillBulletTime <= 0)
                {
                    fillBulletTime = 0;
                }
            }
        }
 
        /// <summary>
        /// 更新木属性瞄准
        /// </summary>
        private void UpdateWoodAim()
        {
            // 离得最近的 Agent
            Agent agent = AgentInsManager.instance.GetMinDisAgent(waveLineID, false);
 
            if (agent != null)
            {
                // 还没有瞄准目标,直接分配
                if (woodAimAgent == null)
                {
                    woodAimAgent = agent;
                    towerPtr.WoodAimAgent = agent;
 
                    if (agent.WoodAimCount == 0)
                        agent.PlayWoodAimEffect();
 
                    ++agent.WoodAimCount;
                }
                // 有小怪走到之前瞄准目标的前面 或者 之前瞄准的目标死亡,切换瞄准目标
                else if (woodAimAgent.Id != agent.Id)
                {
                    if (woodAimAgent.WoodAimCount > 0)
                    {
                        --woodAimAgent.WoodAimCount;
 
                        if (woodAimAgent.WoodAimCount == 0)
                            woodAimAgent.StopWoodAimEffect();
                    }
 
                    woodAimAgent = agent;
                    towerPtr.WoodAimAgent = agent;
 
                    if (agent.WoodAimCount == 0)
                        agent.PlayWoodAimEffect();
 
                    ++agent.WoodAimCount;
                }
            }
        }
 
        /// <summary>
        /// 取消木属性瞄准
        /// </summary>
        private void CancelWoodAim()
        {
            if (woodAimAgent != null)
            {
                if (woodAimAgent.WoodAimCount > 0)
                {
                    --woodAimAgent.WoodAimCount;
 
                    if (woodAimAgent.WoodAimCount == 0)
                        woodAimAgent.StopWoodAimEffect();
                }
            }
 
            woodAimAgent = null;
        }
 
        // 处理火精灵充能
        private void HandleEnergy()
        {
            // 充能时间的处理
            if (towerPtr && towerPtr.energyCtl)
            {
                if (fInEnergy <= 0)
                {
                    energyCalTime += Time.deltaTime;
                    float process = energyCalTime % 11.0f;
                    int proint = (int)Math.Floor(process);
                    proint += towerPtr.uiProOffset;
                    towerPtr.energyCtl.SetEnergyProcessFloat(process);
                    if (proint == 10)
                    {
                        fireState = true;
                        fInEnergy = finalFireSpeed;
                        myTower.SetFireMatSpeed(true);//设置了火宝石快速攻击
                        // 设置多倍攻击速度
                        fBackupTimer = m_FireTimer;
                        m_FireTimer = m_FireTimer / finalFireSpeed;
 
                        towerPtr.uiProOffset = 0;
                        towerPtr.PlayEnergyEffect(true);
                    }
                }
                else
                {
                    fInEnergy -= Time.deltaTime;
                    if (fInEnergy <= 0)
                    {
                        myTower.SetFireMatSpeed(false);//恢复了火宝石攻击速度
 
                        fireState = false;
                        EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.FireTowerChargeEnd);
                        fInEnergy = 0.0f;
                        energyCalTime = 0.0f;
                        towerPtr.energyCtl.SetEnergyProgress(0);
 
                        // 恢复正常攻击速度 
                        m_FireTimer = fBackupTimer;
 
                        towerPtr.PlayEnergyEffect(false);
 
                    }
                }
            }
        }
 
        // 处理水精灵的充能
        private void HandleFreezeBreath()
        {
            if (towerPtr && towerPtr.FreezeBreathCtrl)
            {
                Damager damager = projectile.gameObject.GetComponent<Damager>();
                float finalDamage = damager.damage;
 
                List<EndlessBuffConfig> list = EndlessBuffManager.instance.GetBuffListByEffectType(EndlessBuffEffectType.AttackAdd, towerPtr.attributeId);
                float ratio = 0;
                float add = 0;
 
                if (list.Count > 0)
                {
                    for (int i = 0; i < list.Count; ++i)
                    {
                        ratio += list[i].Config.buff_effect[1];
                        add += list[i].Config.buff_effect[2];
                    }
                }
 
                finalDamage += (ratio / 100f) * finalDamage + add;
 
                if (inFreezeBreath <= 0)
                {
                    freezeBreathCallTime += Time.deltaTime;
                    float process = freezeBreathCallTime % (FreezeBreath.ChargeTime + 1);
                    int processInt = (int)Mathf.Floor(process);
                    processInt += towerPtr.FreezeBreathProgressOffset;
                    towerPtr.FreezeBreathCtrl.SetProgress(process);
 
                    if (processInt == (int)Mathf.Floor(FreezeBreath.ChargeTime))
                    {
                        inFreezeBreath = towerPtr.FreezeBreathCtrl.SkillTime;
                        towerPtr.FreezeBreathProgressOffset = 0;
                        towerPtr.PlayFreezeBreathEffect(true);
                        towerPtr.FreezeBreathCtrl.ReleaseCount = 1;
                        towerPtr.FreezeBreathCtrl.PlayFreezeEffect(waveLineID);
                        towerPtr.FreezeBreathCtrl.ReleaseFreeze(waveLineID, finalDamage, damager.alignmentProvider);
                    }
                }
                else
                {
                    inFreezeBreath -= Time.deltaTime;
                    int time = Mathf.FloorToInt(towerPtr.FreezeBreathCtrl.EffectTime / (towerPtr.FreezeBreathCtrl.DamageCount - 1) * 10);
                    int interval = Mathf.FloorToInt(inFreezeBreath * 10);
                    int offset = Mathf.FloorToInt(towerPtr.FreezeBreathCtrl.SkillTime * 10) - Mathf.FloorToInt(towerPtr.FreezeBreathCtrl.EffectTime * 10);
 
                    if (interval == time * (towerPtr.FreezeBreathCtrl.DamageCount - towerPtr.FreezeBreathCtrl.ReleaseCount - 1) + offset && towerPtr.FreezeBreathCtrl.ReleaseCount < towerPtr.FreezeBreathCtrl.DamageCount)
                    {
                        ++towerPtr.FreezeBreathCtrl.ReleaseCount;
                        towerPtr.FreezeBreathCtrl.ReleaseFreeze(waveLineID, finalDamage, damager.alignmentProvider);
                    }
 
                    if (inFreezeBreath <= 0)
                    {
                        inFreezeBreath = 0;
                        freezeBreathCallTime = 0;
                        towerPtr.FreezeBreathCtrl.SetProgress(0);
                        towerPtr.PlayFreezeBreathEffect(false);
                    }
                }
            }
        }
 
        /// <summary>
        /// This function is called when the object becomes enabled and active.
        /// </summary>
        void OnEnable()
        {
            if (towerPtr && towerPtr.energyCtl)
            {
                if (fireState)
                {
                    myTower.SetFireMatSpeed(true);//设置了火宝石快速攻击
 
                    towerPtr.PlayEnergyEffect(true);
                }
            }
 
            // 如果在木属性蓄力期间,让瞄准动画播放
            if (towerPtr && towerPtr.IsWoodCharge && woodAimAgent != null)
                woodAimAgent.PlayWoodAimEffect();
        }
 
        /// <summary>
        /// This function is called when the behaviour becomes disabled or inactive.
        /// </summary>
        void OnDisable()
        {
            if (towerPtr && towerPtr.energyCtl)
            {
                towerPtr.PlayEnergyEffect(false, false);
            }
 
            if (towerPtr && towerPtr.FreezeBreathCtrl)
                towerPtr.PlayFreezeBreathEffect(false, false);
        }
 
        /// <summary>
        /// 获取子弹发射时间间隔
        /// </summary>
        public float GetFireDuration()
        {
            DecreaseTowerAttackCD endlessBuff = (DecreaseTowerAttackCD)EndlessBuffManager.instance.GetBuffInstanceByType(EndlessBuffEffectType.DecreaseTowerAttackCD);
 
            return endlessBuff != null ? endlessBuff.GetDecreaseCD(towerPtr.attributeId, 1 / projectileFireRate) : 1 / projectileFireRate;
        }
 
        /// <summary>
        /// Update the timers
        /// </summary>
        protected virtual void Update()
        {
            if (m_Launcher == null || towerPtr != null && !towerPtr.CanAttack) return;
 
            // 处理当前Affector所在Tower对应的技能
            updateTowerSkillData();
 
            m_FireTimer -= Time.deltaTime;
            m_TrackingEnemy = targetter.GetTarget(waveLineID, bWoodAffector);
 
            if (m_TrackingEnemy != null && m_FireTimer < 0)
            {
                m_FireTimer = GetFireDuration();
 
                if (fInEnergy > 0)
                    m_FireTimer /= finalFireSpeed;
 
                towerLevel.FireSpeed = fInEnergy > 0 ? finalFireSpeed : 1f;
 
                if (towerPtr && towerPtr.bulletCtl != null)
                {
                    int bnum = towerPtr.bulletCtl.GetCtlProgress();
 
                    // 蓄力时间内不攻击
                    if (bnum == 0 || woodRemainChargeTime > 0f) return;
                }
 
                if (towerPtr && towerPtr.FreezeBreathCtrl != null)
                {
                    // 冷冻气息期间不攻击
                    if (inFreezeBreath > 0.0001f) return;
                }
 
                towerLevel.ChangeState(TowerActionState.Attack);
            }
        }
 
        /// <summary>
        /// Common logic when attacking
        /// 调用攻击的核心函数,由这个函数发起真正的攻击,多目标或者单目标
        /// </summary>
        public virtual void FireProjectile()
        {
            // 不再处理多子弹攻击,确保只有一个弹道
            isMultiAttack = false;
            m_TrackingEnemy = targetter.GetTarget(waveLineID, bWoodAffector);
 
            GameObject go = damagerProjectile.gameObject;
 
            if (m_TrackingEnemy == null || fillBulletTime > 0) return;
 
            go.GetComponent<Damager>().IsEnhancedBullet = false;
 
            // 处理子弹充能相关的内容
            if (towerPtr && towerPtr.bulletCtl != null)
            {
                int bnum = towerPtr.bulletCtl.decBullet();
                // 暴击子弹的数量,如果获得相应buff可能会修改暴击子弹数量
                int critBulletNum = towerPtr.bulletCtl.CritBulletNum;
 
                if (bnum < critBulletNum)
                {
                    if (bnum == 0)
                        // 不需要装填时间
                        fillBulletTime = 0.1f;
 
                    //这里需要替换特效
                    var poolable = Core.Utilities.Poolable.TryGetPoolable<Core.Utilities.Poolable>(woodProjectile_SP);
                    go = poolable.gameObject;
                    Damager tmpDamager = go.GetComponent<Damager>();
                    tmpDamager.damageMulti = 10.0f;
                    tmpDamager.damage = damagerProjectile.damage;
                    tmpDamager.IsEnhancedBullet = true;
                }
 
                // 下一颗子弹是强化子弹,然后直接蓄力
                if (bnum - 1 >= 0 && bnum - 1 < critBulletNum)
                {
                    woodRemainChargeTime = woodChargeTime;
                    towerPtr.IsWoodCharge = true;
                    DecreaseWoodChargeTime decreaseWoodChargeTime = (DecreaseWoodChargeTime)EndlessBuffManager.instance.GetBuffInstanceByType(EndlessBuffEffectType.DecreaseWoodChargeTime);
 
                    if (decreaseWoodChargeTime != null)
                        woodRemainChargeTime = decreaseWoodChargeTime.GetWoodChargeTime(woodChargeTime);
 
                    woodChargeEffectTime = woodRemainChargeTime + 0.5f / towerLevel.ActionAnimator.speed;
                    WoodChargeEffect.Play();
                }
            }
            else
            {
                if (towerPtr)
                    towerPtr.setTowerState(true);
            }
 
            if (isMultiAttack)
            {
                List<Targetable> enemies = towerTargetter.GetAllTargets();
                if ((enemies != null) && (Targetter.bSearchTarget))
                    m_Launcher.Launch(enemies, projectile, projectilePoints, maxAttackNum);
            }
            else
            {
                if (Targetter.bSearchTarget)
                {
                    m_Launcher.Launch(m_TrackingEnemy, go, projectilePoints);
                    if (AudioSourceManager.Ins)
                        AudioSourceManager.Ins.Play(audioEnum);
                }
            }
            if (randomAudioSource != null)
            {
                if (Targetter.bSearchTarget)
                    randomAudioSource.PlayRandomClip();
            }
        }
 
        /// <summary>
        /// A delegate to compare distances of components
        /// </summary>
        /// <param name="first"></param>
        /// <param name="second"></param>
        protected virtual int ByDistance(Targetable first, Targetable second)
        {
            float firstSqrMagnitude = Vector3.SqrMagnitude(first.position - epicenter.position);
            float secondSqrMagnitude = Vector3.SqrMagnitude(second.position - epicenter.position);
            return firstSqrMagnitude.CompareTo(secondSqrMagnitude);
        }
 
#if UNITY_EDITOR
        /// <summary>
        /// Draws the search area
        /// </summary>
        void OnDrawGizmosSelected()
        {
            Gizmos.DrawWireSphere(epicenter.position, towerTargetter.effectRadius);
        }
#endif
    }
 
    /// <summary>
    /// A delegate for boolean calculation logic
    /// </summary>
    public delegate bool Filter();
}