|
@@ -8,116 +8,31 @@ namespace GFGGame
|
|
private static Dictionary<int, List<DropOutData>> _probDic = new Dictionary<int, List<DropOutData>>();
|
|
private static Dictionary<int, List<DropOutData>> _probDic = new Dictionary<int, List<DropOutData>>();
|
|
|
|
|
|
|
|
|
|
|
|
+ // public static List<ItemData> GetDropItemDatas(int[] dropIds, bool doRandome)
|
|
|
|
+ // {
|
|
|
|
+ // List<ItemData> result = new List<ItemData>();
|
|
|
|
+ // foreach (int dropId in dropIds)
|
|
|
|
+ // {
|
|
|
|
+ // ItemData itemData = GetDropItemData(dropId, doRandome);
|
|
|
|
+ // if (itemData != null)
|
|
|
|
+ // {
|
|
|
|
+ // result.Add(itemData);
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // return result;
|
|
|
|
+ // }
|
|
public static List<ItemData> GetDropItemDatas(int[] dropIds, bool doRandome)
|
|
public static List<ItemData> GetDropItemDatas(int[] dropIds, bool doRandome)
|
|
{
|
|
{
|
|
List<ItemData> result = new List<ItemData>();
|
|
List<ItemData> result = new List<ItemData>();
|
|
foreach (int dropId in dropIds)
|
|
foreach (int dropId in dropIds)
|
|
{
|
|
{
|
|
- ItemData itemData = GetDropItemData(dropId, doRandome);
|
|
|
|
- if (itemData != null)
|
|
|
|
- {
|
|
|
|
- result.Add(itemData);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return result;
|
|
|
|
- }
|
|
|
|
|
|
+ GetDropItemData(dropId, result);
|
|
|
|
|
|
- public static List<ItemData> GetDropItemDatas(int dropId, int count)
|
|
|
|
- {
|
|
|
|
- List<ItemData> result = new List<ItemData>();
|
|
|
|
- int tryCount = 0;
|
|
|
|
- while (result.Count < count && tryCount < 1000)
|
|
|
|
- {
|
|
|
|
- ItemData itemData = GetDropItemData(dropId, true);
|
|
|
|
- if (itemData != null)
|
|
|
|
- {
|
|
|
|
- result.Add(itemData);
|
|
|
|
- }
|
|
|
|
- tryCount++;
|
|
|
|
}
|
|
}
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
- public static ItemData GetDropItemData(int dropId, bool doRandome)
|
|
|
|
- {
|
|
|
|
- ItemData itemData = null;
|
|
|
|
- List<DropOutData> dropOutDatas = null;
|
|
|
|
- if (!_probDic.ContainsKey(dropId))
|
|
|
|
- {
|
|
|
|
- InitData(dropId);
|
|
|
|
- }
|
|
|
|
- dropOutDatas = _probDic[dropId];
|
|
|
|
- if (dropOutDatas != null)
|
|
|
|
- {
|
|
|
|
- float result = Random.Range(0, 1f);
|
|
|
|
- foreach (DropOutData dropOutData in dropOutDatas)
|
|
|
|
- {
|
|
|
|
- if (result <= dropOutData.WeightEnd || !doRandome)
|
|
|
|
- {
|
|
|
|
- return GetItemData(dropOutData.dropOutCfg, doRandome);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return itemData;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private static void InitData(int dropId)
|
|
|
|
- {
|
|
|
|
- List<DropOutData> dropOutDatas = new List<DropOutData>();
|
|
|
|
- _probDic[dropId] = dropOutDatas;
|
|
|
|
- var arr = DropOutCfgArray.Instance.GetCfgs(dropId);
|
|
|
|
- List<DropOutCfg> cfgs = new List<DropOutCfg>(arr);
|
|
|
|
- float totalWeight = 0;
|
|
|
|
- foreach (DropOutCfg cfg in cfgs)
|
|
|
|
- {
|
|
|
|
- totalWeight += cfg.weight;
|
|
|
|
- }
|
|
|
|
- float weightEnd = 0;
|
|
|
|
- foreach (DropOutCfg cfg in cfgs)
|
|
|
|
- {
|
|
|
|
- DropOutData dropOutData = new DropOutData();
|
|
|
|
- dropOutData.dropOutCfg = cfg;
|
|
|
|
- weightEnd += cfg.weight;
|
|
|
|
- dropOutData.WeightEnd = weightEnd / totalWeight;
|
|
|
|
- dropOutDatas.Add(dropOutData);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private static ItemData GetItemData(DropOutCfg dropOutCfg, bool doRandomeNum)
|
|
|
|
- {
|
|
|
|
- if (dropOutCfg.item >= 10000000)//掉落id
|
|
|
|
- {
|
|
|
|
- return GetDropItemData(dropOutCfg.item, doRandomeNum);
|
|
|
|
- }
|
|
|
|
- else if (dropOutCfg.item > 0)
|
|
|
|
- {
|
|
|
|
- int num = dropOutCfg.maxNum;
|
|
|
|
- if (doRandomeNum)
|
|
|
|
- {
|
|
|
|
- num = Random.Range(dropOutCfg.minNum, dropOutCfg.maxNum + 1);
|
|
|
|
- }
|
|
|
|
- if (num > 0)
|
|
|
|
- {
|
|
|
|
- ItemData itemData = ItemDataPool.GetItemData(dropOutCfg.item);
|
|
|
|
- itemData.num = num;
|
|
|
|
- return itemData;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public static List<ItemData> GetDropItemDatas1(int[] dropIds, bool doRandome)
|
|
|
|
- {
|
|
|
|
- List<ItemData> result = new List<ItemData>();
|
|
|
|
- foreach (int dropId in dropIds)
|
|
|
|
- {
|
|
|
|
- GetDropItemDatas(dropId, result);
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- return result;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public static List<ItemData> GetDropItemDatas(int dropId, List<ItemData> result)
|
|
|
|
|
|
+ public static List<ItemData> GetDropItemData(int dropId, List<ItemData> result)
|
|
{
|
|
{
|
|
|
|
|
|
List<DropOutCfg> dropOutCfgs = DropOutCfgArray.Instance.GetCfgs(dropId);
|
|
List<DropOutCfg> dropOutCfgs = DropOutCfgArray.Instance.GetCfgs(dropId);
|
|
@@ -129,7 +44,7 @@ namespace GFGGame
|
|
if (_dropOutCfgs.Count > 0)
|
|
if (_dropOutCfgs.Count > 0)
|
|
{
|
|
{
|
|
|
|
|
|
- GetDropItemDatas(dropOutCfgs[i].item, result);
|
|
|
|
|
|
+ GetDropItemData(dropOutCfgs[i].item, result);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -142,5 +57,90 @@ namespace GFGGame
|
|
}
|
|
}
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
+ // public static List<ItemData> GetDropItemDatas(int dropId, int count)
|
|
|
|
+ // {
|
|
|
|
+ // List<ItemData> result = new List<ItemData>();
|
|
|
|
+ // int tryCount = 0;
|
|
|
|
+ // while (result.Count < count && tryCount < 1000)
|
|
|
|
+ // {
|
|
|
|
+ // ItemData itemData = GetDropItemData(dropId, true);
|
|
|
|
+ // if (itemData != null)
|
|
|
|
+ // {
|
|
|
|
+ // result.Add(itemData);
|
|
|
|
+ // }
|
|
|
|
+ // tryCount++;
|
|
|
|
+ // }
|
|
|
|
+ // return result;
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // public static ItemData GetDropItemData(int dropId, bool doRandome)
|
|
|
|
+ // {
|
|
|
|
+ // ItemData itemData = null;
|
|
|
|
+ // List<DropOutData> dropOutDatas = null;
|
|
|
|
+ // if (!_probDic.ContainsKey(dropId))
|
|
|
|
+ // {
|
|
|
|
+ // InitData(dropId);
|
|
|
|
+ // }
|
|
|
|
+ // dropOutDatas = _probDic[dropId];
|
|
|
|
+ // if (dropOutDatas != null)
|
|
|
|
+ // {
|
|
|
|
+ // float result = Random.Range(0, 1f);
|
|
|
|
+ // foreach (DropOutData dropOutData in dropOutDatas)
|
|
|
|
+ // {
|
|
|
|
+ // if (result <= dropOutData.WeightEnd || !doRandome)
|
|
|
|
+ // {
|
|
|
|
+ // return GetItemData(dropOutData.dropOutCfg, doRandome);
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // return itemData;
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // private static void InitData(int dropId)
|
|
|
|
+ // {
|
|
|
|
+ // List<DropOutData> dropOutDatas = new List<DropOutData>();
|
|
|
|
+ // _probDic[dropId] = dropOutDatas;
|
|
|
|
+ // var arr = DropOutCfgArray.Instance.GetCfgs(dropId);
|
|
|
|
+ // List<DropOutCfg> cfgs = new List<DropOutCfg>(arr);
|
|
|
|
+ // float totalWeight = 0;
|
|
|
|
+ // foreach (DropOutCfg cfg in cfgs)
|
|
|
|
+ // {
|
|
|
|
+ // totalWeight += cfg.weight;
|
|
|
|
+ // }
|
|
|
|
+ // float weightEnd = 0;
|
|
|
|
+ // foreach (DropOutCfg cfg in cfgs)
|
|
|
|
+ // {
|
|
|
|
+ // DropOutData dropOutData = new DropOutData();
|
|
|
|
+ // dropOutData.dropOutCfg = cfg;
|
|
|
|
+ // weightEnd += cfg.weight;
|
|
|
|
+ // dropOutData.WeightEnd = weightEnd / totalWeight;
|
|
|
|
+ // dropOutDatas.Add(dropOutData);
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // private static ItemData GetItemData(DropOutCfg dropOutCfg, bool doRandomeNum)
|
|
|
|
+ // {
|
|
|
|
+ // if (dropOutCfg.item >= 10000000)//掉落id
|
|
|
|
+ // {
|
|
|
|
+ // return GetDropItemData(dropOutCfg.item, doRandomeNum);
|
|
|
|
+ // }
|
|
|
|
+ // else if (dropOutCfg.item > 0)
|
|
|
|
+ // {
|
|
|
|
+ // int num = dropOutCfg.maxNum;
|
|
|
|
+ // if (doRandomeNum)
|
|
|
|
+ // {
|
|
|
|
+ // num = Random.Range(dropOutCfg.minNum, dropOutCfg.maxNum + 1);
|
|
|
|
+ // }
|
|
|
|
+ // if (num > 0)
|
|
|
|
+ // {
|
|
|
|
+ // ItemData itemData = ItemDataPool.GetItemData(dropOutCfg.item);
|
|
|
|
+ // itemData.num = num;
|
|
|
|
+ // return itemData;
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // return null;
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|