DecomposeDataManager.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. int 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. int 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. return _decomposeData[rarity];
  38. }
  39. public List<int> GetRewardList()
  40. {
  41. if (_rewardList.Count == 0)
  42. {
  43. DecomposeCfg[] cfgs = DecomposeCfgArray.Instance.dataArray;
  44. for (int i = 0; i < cfgs.Length; i++)
  45. {
  46. for (int j = 0; j < cfgs[i].itemsArr.Length; j++)
  47. {
  48. if (_rewardList.IndexOf(cfgs[i].itemsArr[j][0]) < 0)
  49. {
  50. _rewardList.Add(cfgs[i].itemsArr[j][0]);
  51. }
  52. }
  53. }
  54. }
  55. return _rewardList;
  56. }
  57. //物品可分解的数量
  58. public int ItemCanDecomposeCount(int itemId)
  59. {
  60. return ItemDataManager.GetItemNum(itemId) - 1;
  61. }
  62. }
  63. }