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];
|
}
|
}
|
}
|