wangguan
2020-11-27 89746ce2ee33c5430601ef1bf3b5b03325c601ad
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
using System.Collections.Generic;
using System;
 
/**
 * PVE(无尽模式)怪物配置数据表处理类
 * @Author: chenxin
 * @Date: 2020-10-12 12:13:44
 */
namespace KTGMGemClient
{
    public class EndlessEnemyData
    {
        /// <summary>
        /// 无尽模式怪物配置表
        /// </summary>
        private static List<endless_enemy> endlessEnemyList;
 
        /// <summary>
        /// 根据怪物类型来分类一下数据
        /// </summary>
        private static Dictionary<int, List<endless_enemy>> typeDic;
 
        private static Random random;
 
        public static void Init()
        {
            endlessEnemyList = JsonDataCenter.GetList<endless_enemy>();
            typeDic = new Dictionary<int, List<endless_enemy>>();
            random = new Random();
 
            foreach (endless_enemy data in endlessEnemyList)
            {
                if (!typeDic.ContainsKey(data.type))
                    typeDic.Add(data.type, new List<endless_enemy>());
 
                typeDic[data.type].Add(data);
            }
        }
 
        /// <summary>
        /// 根据怪物id获取怪物数据
        /// </summary>
        /// <param name="id">id > 0:获取指定id的小怪,
        /// id = -1:从类型为1(小怪)随机,
        /// id = -2:从类型为2(精英怪)随机
        /// id = -3:从所有小怪中随机</param>
        /// <returns></returns>
        public static endless_enemy GetDataById(int id)
        {
            if (id > 0)
            {
                foreach (endless_enemy data in endlessEnemyList)
                {
                    if (data.id == id)
                        return data;
                }
 
                return null;
            }
 
            List<endless_enemy> list = endlessEnemyList;
 
            if (id == -1 || id == -2)
                list = typeDic[-id];
 
            if (list.Count == 0)
                throw new ArgumentException("id 不规范 or 没有对应的怪物数据");
 
            int index = random.Next(list.Count);
 
            return list[index];
        }
    }
}