DecomposeDataManager.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System.Collections.Generic;
  2. namespace GFGGame
  3. {
  4. public class DecomposeDataManager : SingletonBase<DecomposeDataManager>
  5. {
  6. Dictionary<int, List<int>> _decomposeData = new Dictionary<int, List<int>>();//所有数量大于1的换装部件数据
  7. List<int> _rewardList = new List<int>();
  8. public const int MaxCount = 999;
  9. public void Clear()
  10. {
  11. _decomposeData.Clear();
  12. }
  13. public void Add(int itemId)
  14. {
  15. int rarity = ItemCfgArray.Instance.GetCfg(itemId).rarity;
  16. if (!_decomposeData.ContainsKey(rarity))
  17. {
  18. _decomposeData.Add(rarity, new List<int>());
  19. }
  20. long count = ItemCanDecomposeCount(itemId);
  21. if (_decomposeData[rarity].IndexOf(itemId) < 0 && count > 0)
  22. {
  23. _decomposeData[rarity].Add(itemId);
  24. }
  25. }
  26. public void Remove(int itemId)
  27. {
  28. int rarity = ItemCfgArray.Instance.GetCfg(itemId).rarity;
  29. long count = ItemCanDecomposeCount(itemId);
  30. if (_decomposeData.ContainsKey(rarity) && _decomposeData[rarity].IndexOf(itemId) >= 0 && count <= 0)
  31. {
  32. _decomposeData[rarity].Remove(itemId);
  33. }
  34. }
  35. public List<int> GetDecomposeDataByRarity(int rarity)
  36. {
  37. if (!_decomposeData.ContainsKey(rarity)) return null;
  38. return _decomposeData[rarity];
  39. }
  40. public List<int> GetRewardList()
  41. {
  42. if (_rewardList.Count == 0)
  43. {
  44. DecomposeCfg[] cfgs = DecomposeCfgArray.Instance.dataArray;
  45. for (int i = 0; i < cfgs.Length; i++)
  46. {
  47. for (int j = 0; j < cfgs[i].itemsArr.Length; j++)
  48. {
  49. if (_rewardList.IndexOf(cfgs[i].itemsArr[j][0]) < 0)
  50. {
  51. _rewardList.Add(cfgs[i].itemsArr[j][0]);
  52. }
  53. }
  54. }
  55. }
  56. return _rewardList;
  57. }
  58. //物品可分解的数量
  59. public long ItemCanDecomposeCount(int itemId)
  60. {
  61. return ItemDataManager.GetItemNum(itemId) - 1;
  62. }
  63. }
  64. }