DropOutDataCache.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using cfg.GfgCfg;
  4. using UnityEngine;
  5. namespace GFGGame
  6. {
  7. public class DropOutDataCache
  8. {
  9. private static Dictionary<int, List<DropOutData>> _probDic = new Dictionary<int, List<DropOutData>>();
  10. // public static List<ItemData> GetDropItemDatas(int[] dropIds, bool doRandome)
  11. // {
  12. // List<ItemData> result = new List<ItemData>();
  13. // foreach (int dropId in dropIds)
  14. // {
  15. // ItemData itemData = GetDropItemData(dropId, doRandome);
  16. // if (itemData != null)
  17. // {
  18. // result.Add(itemData);
  19. // }
  20. // }
  21. // return result;
  22. // }
  23. public static List<ItemData> GetDropItemDatas(List<int> dropIds, bool doRandome)
  24. {
  25. List<ItemData> result = new List<ItemData>();
  26. foreach (int dropId in dropIds)
  27. {
  28. GetDropItemData(dropId, result);
  29. }
  30. return result;
  31. }
  32. public static List<ItemData> GetDropItemData(int dropId, List<ItemData> result)
  33. {
  34. List<DropOutCfg> dropOutCfgs =
  35. CommonDataManager.Tables.TblDropOutCfg.DataList.Where(a => a.Id == dropId).ToList();
  36. for (int i = 0; i < dropOutCfgs.Count; i++)
  37. {
  38. List<DropOutCfg> _dropOutCfgs = CommonDataManager.Tables.TblDropOutCfg.DataList
  39. .Where(a => a.Id == dropOutCfgs[i].Item).ToList();
  40. if (_dropOutCfgs.Count > 0)
  41. {
  42. GetDropItemData(dropOutCfgs[i].Item, result);
  43. }
  44. else
  45. {
  46. ItemData itemData = ItemUtil.createItemData(dropOutCfgs[i].Item, dropOutCfgs[i].MaxNum,
  47. dropOutCfgs[i].MinNum); // GetDropItemData(dropId, doRandome);
  48. if (dropOutCfgs[i].Item > 0 && itemData != null)
  49. {
  50. result.Add(itemData);
  51. }
  52. }
  53. }
  54. return result;
  55. }
  56. // public static List<ItemData> GetDropItemDatas(int dropId, int count)
  57. // {
  58. // List<ItemData> result = new List<ItemData>();
  59. // int tryCount = 0;
  60. // while (result.Count < count && tryCount < 1000)
  61. // {
  62. // ItemData itemData = GetDropItemData(dropId, true);
  63. // if (itemData != null)
  64. // {
  65. // result.Add(itemData);
  66. // }
  67. // tryCount++;
  68. // }
  69. // return result;
  70. // }
  71. // public static ItemData GetDropItemData(int dropId, bool doRandome)
  72. // {
  73. // ItemData itemData = null;
  74. // List<DropOutData> dropOutDatas = null;
  75. // if (!_probDic.ContainsKey(dropId))
  76. // {
  77. // InitData(dropId);
  78. // }
  79. // dropOutDatas = _probDic[dropId];
  80. // if (dropOutDatas != null)
  81. // {
  82. // float result = Random.Range(0, 1f);
  83. // foreach (DropOutData dropOutData in dropOutDatas)
  84. // {
  85. // if (result <= dropOutData.WeightEnd || !doRandome)
  86. // {
  87. // return GetItemData(dropOutData.dropOutCfg, doRandome);
  88. // }
  89. // }
  90. // }
  91. // return itemData;
  92. // }
  93. // private static void InitData(int dropId)
  94. // {
  95. // List<DropOutData> dropOutDatas = new List<DropOutData>();
  96. // _probDic[dropId] = dropOutDatas;
  97. // var arr = DropOutCfgArray.Instance.GetCfgs(dropId);
  98. // List<DropOutCfg> cfgs = new List<DropOutCfg>(arr);
  99. // float totalWeight = 0;
  100. // foreach (DropOutCfg cfg in cfgs)
  101. // {
  102. // totalWeight += cfg.weight;
  103. // }
  104. // float weightEnd = 0;
  105. // foreach (DropOutCfg cfg in cfgs)
  106. // {
  107. // DropOutData dropOutData = new DropOutData();
  108. // dropOutData.dropOutCfg = cfg;
  109. // weightEnd += cfg.weight;
  110. // dropOutData.WeightEnd = weightEnd / totalWeight;
  111. // dropOutDatas.Add(dropOutData);
  112. // }
  113. // }
  114. // private static ItemData GetItemData(DropOutCfg dropOutCfg, bool doRandomeNum)
  115. // {
  116. // if (dropOutCfg.item >= 10000000)//掉落id
  117. // {
  118. // return GetDropItemData(dropOutCfg.item, doRandomeNum);
  119. // }
  120. // else if (dropOutCfg.item > 0)
  121. // {
  122. // int num = dropOutCfg.maxNum;
  123. // if (doRandomeNum)
  124. // {
  125. // num = Random.Range(dropOutCfg.minNum, dropOutCfg.maxNum + 1);
  126. // }
  127. // if (num > 0)
  128. // {
  129. // ItemData itemData = ItemDataPool.GetItemData(dropOutCfg.item);
  130. // itemData.num = num;
  131. // return itemData;
  132. // }
  133. // }
  134. // return null;
  135. // }
  136. }
  137. }