DropOutDataCache.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 = CommonDataManager.Tables.TblDropOutCfg.GetGroup1ById(dropId);
  35. for (int i = 0; i < dropOutCfgs.Count; i++)
  36. {
  37. List<DropOutCfg> _dropOutCfgs = CommonDataManager.Tables.TblDropOutCfg.DataList
  38. .Where(a => a.Id == dropOutCfgs[i].Item).ToList();
  39. if (_dropOutCfgs.Count > 0)
  40. {
  41. GetDropItemData(dropOutCfgs[i].Item, result);
  42. }
  43. else
  44. {
  45. ItemData itemData = ItemUtil.createItemData(dropOutCfgs[i].Item, dropOutCfgs[i].MaxNum,
  46. dropOutCfgs[i].MinNum); // GetDropItemData(dropId, doRandome);
  47. if (dropOutCfgs[i].Item > 0 && itemData != null)
  48. {
  49. result.Add(itemData);
  50. }
  51. }
  52. }
  53. return result;
  54. }
  55. // public static List<ItemData> GetDropItemDatas(int dropId, int count)
  56. // {
  57. // List<ItemData> result = new List<ItemData>();
  58. // int tryCount = 0;
  59. // while (result.Count < count && tryCount < 1000)
  60. // {
  61. // ItemData itemData = GetDropItemData(dropId, true);
  62. // if (itemData != null)
  63. // {
  64. // result.Add(itemData);
  65. // }
  66. // tryCount++;
  67. // }
  68. // return result;
  69. // }
  70. // public static ItemData GetDropItemData(int dropId, bool doRandome)
  71. // {
  72. // ItemData itemData = null;
  73. // List<DropOutData> dropOutDatas = null;
  74. // if (!_probDic.ContainsKey(dropId))
  75. // {
  76. // InitData(dropId);
  77. // }
  78. // dropOutDatas = _probDic[dropId];
  79. // if (dropOutDatas != null)
  80. // {
  81. // float result = Random.Range(0, 1f);
  82. // foreach (DropOutData dropOutData in dropOutDatas)
  83. // {
  84. // if (result <= dropOutData.WeightEnd || !doRandome)
  85. // {
  86. // return GetItemData(dropOutData.dropOutCfg, doRandome);
  87. // }
  88. // }
  89. // }
  90. // return itemData;
  91. // }
  92. // private static void InitData(int dropId)
  93. // {
  94. // List<DropOutData> dropOutDatas = new List<DropOutData>();
  95. // _probDic[dropId] = dropOutDatas;
  96. // var arr = DropOutCfgArray.Instance.GetCfgs(dropId);
  97. // List<DropOutCfg> cfgs = new List<DropOutCfg>(arr);
  98. // float totalWeight = 0;
  99. // foreach (DropOutCfg cfg in cfgs)
  100. // {
  101. // totalWeight += cfg.weight;
  102. // }
  103. // float weightEnd = 0;
  104. // foreach (DropOutCfg cfg in cfgs)
  105. // {
  106. // DropOutData dropOutData = new DropOutData();
  107. // dropOutData.dropOutCfg = cfg;
  108. // weightEnd += cfg.weight;
  109. // dropOutData.WeightEnd = weightEnd / totalWeight;
  110. // dropOutDatas.Add(dropOutData);
  111. // }
  112. // }
  113. // private static ItemData GetItemData(DropOutCfg dropOutCfg, bool doRandomeNum)
  114. // {
  115. // if (dropOutCfg.item >= 10000000)//掉落id
  116. // {
  117. // return GetDropItemData(dropOutCfg.item, doRandomeNum);
  118. // }
  119. // else if (dropOutCfg.item > 0)
  120. // {
  121. // int num = dropOutCfg.maxNum;
  122. // if (doRandomeNum)
  123. // {
  124. // num = Random.Range(dropOutCfg.minNum, dropOutCfg.maxNum + 1);
  125. // }
  126. // if (num > 0)
  127. // {
  128. // ItemData itemData = ItemDataPool.GetItemData(dropOutCfg.item);
  129. // itemData.num = num;
  130. // return itemData;
  131. // }
  132. // }
  133. // return null;
  134. // }
  135. }
  136. }