DropOutDataCache.cs 5.0 KB

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