DropOutDataCache.cs 5.1 KB

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