wangguan
2020-10-21 a51fc78ac1055d24fe68d8d091fedd148302c1e5
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
using System.Collections.Generic;
 
/**
 * endless_port 无尽模式关卡配置表数据处理类
 * @Author: chenxin
 * @Date: 2020-10-10 17:11:23
 */
namespace KTGMGemClient
{
    public class EndlessPortConfig
    {
        /// <summary>
        /// 配置表数据
        /// </summary>
        public endless_port Config;
 
        /// <summary>
        /// 预先随机好的敌人数据,spawnAgent时直接取这个数据,不再动态随机
        /// </summary>
        public endless_enemy EnemyData;
    }
 
    public class EndlessPortData
    {
        /// <summary>
        /// 无尽模式关卡配置表
        /// </summary>
        private static List<endless_port> endlessPortList;
 
        private static List<EndlessPortConfig> portConfigList;
 
        /// <summary>
        /// 最大关卡
        /// </summary>
        /// <value></value>
        private static int maxLevel { get; set; }
        public static int MaxLevel
        {
            get { return maxLevel; }
        }
 
        /// <summary>
        /// 数据初始化
        /// </summary>
        public static void Init()
        {
            endlessPortList = JsonDataCenter.GetList<endless_port>();
            portConfigList = new List<EndlessPortConfig>();
 
            foreach (endless_port data in endlessPortList)
            {
                if (data.level > maxLevel)
                    maxLevel = data.level;
 
                EndlessPortConfig param = new EndlessPortConfig();
                param.Config = data;
                param.EnemyData = EndlessEnemyData.GetDataById(data.enemy_id);
                portConfigList.Add(param);
            }
        }
 
        /// <summary>
        /// 根据关卡等级获取boss资源id
        /// </summary>
        /// <param name="level">关卡等级</param>
        /// <returns>如果返回-1查找失败</returns>
        public static int GetResIdByLevel(int level)
        {
            foreach (endless_port data in endlessPortList)
            {
                if (data.level == level)
                    return data.resource;
            }
 
            return -1;
        }
 
        /// <summary>
        /// 根据关卡等级获取关卡的所有波数据,如果本波次敌人数量为0,直接忽略掉
        /// </summary>
        /// <param name="level">关卡等级</param>
        /// <returns></returns>
        public static List<List<EndlessPortConfig>> GetLevelWaveData(int level)
        {
            List<List<EndlessPortConfig>> ret = new List<List<EndlessPortConfig>>();
 
            for (int i = 0; i < 5; ++i)
            {
                ret.Add(new List<EndlessPortConfig>());
            }
 
            foreach (EndlessPortConfig data in portConfigList)
            {
                if (data.Config.level != level || data.Config.amount == 0) continue;
 
                ret[data.Config.wave - 1].Add(data);
            }
 
            for (int i = 0; i < ret.Count; ++i)
            {
                if (ret[i].Count == 0)
                {
                    ret.Remove(ret[i]);
                    --i;
                }
            }
 
            return ret;
        }
 
        /// <summary>
        /// 根据关卡等级和波次获得该波次的所有敌人数量
        /// </summary>
        /// <param name="level"></param>
        /// <param name="wave"></param>
        /// <returns></returns>
        public static int GetWaveEnemiesCount(int level, int wave)
        {
            List<List<EndlessPortConfig>> list = GetLevelWaveData(level);
 
            if (list.Count == 0) return 0;
 
            List<EndlessPortConfig> waveData = list[wave];
            int ret = 0;
 
            for (int i = 0; i < waveData.Count; ++i)
            {
                ret += waveData[i].Config.amount;
            }
 
            return ret;
        }
    }
}