wangguan
2020-10-21 c4b8dbd94f555b599bc847b7fa8a2e1c6caf31e1
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
using Core.Utilities;
using System.Collections.Generic;
using KTGMGemClient;
using UnityEngine;
using TowerDefense.Towers;
 
namespace TowerDefense.Level
{
    /// <summary>
    /// 无尽模式buff管理器
    /// </summary>
    public class EndlessBuffManager : Singleton<EndlessBuffManager>
    {
        /// <summary>
        /// 玩家拥有的buff列表
        /// </summary>
        public List<EndlessBuffConfig> BuffList;
 
        protected override void Awake()
        {
            base.Awake();
 
            BuffList = new List<EndlessBuffConfig>();
        }
 
        /// <summary>
        /// 玩家获得一个buff
        /// </summary>
        public void AddBuff(EndlessBuffConfig buff)
        {
            if (buff.LifeCycleType == EndlessBuffLifeCycleType.Once)
            {
                switch (buff.EffectType)
                {
                    case EndlessBuffEffectType.Gold:
                        // 一次性增加金币
                        EndlessLevelManager.instance.Currency.AddCurrency(buff.Config.buff_effect[1]);
                        break;
                    case EndlessBuffEffectType.ObtainTower:
                        // 是否到了技能时间
                        bool canSkill = EndlessUIStart.instance.GameStartTime <= EndlessRandomTower.SKILL_TOWER_TIME;
                        Tower newTower = EndlessRandomTower.instance.GetRandomTower(canSkill);
 
                        if (!EndlessRandomTower.instance.RandomPlaceTower(newTower, buff.Config.buff_effect[1] - 1, 0))
                            EndlessLevelManager.instance.Currency.AddCurrency(buff.Config.buff_effect[2]);
                        break;
                }
 
                return;
            }
 
            BuffList.Add(buff);
        }
 
        /// <summary>
        /// 直接从buff列表中移除某一个buff
        /// </summary>
        /// <param name="buff"></param>
        public void RemoveBuff(EndlessBuffConfig buff)
        {
            BuffList.Remove(buff);
        }
 
        /// <summary>
        /// 更新buff列表,以波为单位,一个波次结束后调用此方法去更新buff列表
        /// 这个方法主要是处理buff的生命周期,把无效的移除掉
        /// </summary>
        /// <param name="waves">一次更新的波数,默认以一波为一个节点去更新</param>
        public void UpdateBuffList(int waves = 1)
        {
            int len = BuffList.Count;
 
            for (int i = 0; i < len; ++i)
            {
                if (BuffList[i].LifeCycleType == EndlessBuffLifeCycleType.LimitedWave)
                {
                    BuffList[i].TackEffectWaves += waves;
 
                    if (BuffList[i].TackEffectWaves >= BuffList[i].TotalEffectWaves)
                    {
                        // 超过波次数量限制,移除掉
                        BuffList.Remove(BuffList[i]);
                        len = BuffList.Count;
                    }
                }
            }
        }
 
        /// <summary>
        /// 根据buff效果类型获得buff列表数据
        /// </summary>
        /// <param name="type">buff效果类型</param>
        /// <param name="id">宝石技能id</param>
        public List<EndlessBuffConfig> GetBuffListByEffectType(EndlessBuffEffectType type, int id)
        {
            List<EndlessBuffConfig> ret = new List<EndlessBuffConfig>();
            // 暂且先这么处理吧 如果1:火 2:水 3:木
            int attributeId = (int)Mathf.Floor(id / 10000f);
 
            for (int i = 0; i < BuffList.Count; ++i)
            {
                if (BuffList[i].EffectType == type)
                {
                    bool isWork = false;
 
                    switch (BuffList[i].UseTarget)
                    {
                        case EndlessBuffUseTarget.All:
                            isWork = true;
                            break;
                        case EndlessBuffUseTarget.Element:
                            isWork = attributeId == BuffList[i].Config.target_type[1];
                            break;
                        case EndlessBuffUseTarget.Designated:
                            isWork = id == BuffList[i].Config.target_type[1];
                            break;
                    }
 
                    if (isWork)
                        ret.Add(BuffList[i]);
                }
            }
 
            return ret;
        }
    }
}