ItemData.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System.Collections.Generic;
  2. namespace GFGGame
  3. {
  4. public class ItemData
  5. {
  6. public int id;
  7. public int num;
  8. public bool isOnceBonus;
  9. private Dictionary<int, int> AttributesDic = new Dictionary<int, int>();
  10. public void Reset()
  11. {
  12. id = 0;
  13. num = 0;
  14. isOnceBonus = false;
  15. AttributesDic.Clear();
  16. }
  17. public void SetAttributes(List<int> keys, List<int> values)
  18. {
  19. for (var i = 0; i < keys.Count; ++i)
  20. {
  21. SetAttribute(keys[i], values[i], false);
  22. }
  23. }
  24. public void SetAttribute(int key, int value, bool dispatch = true)
  25. {
  26. AttributesDic[key] = value;
  27. if (dispatch)
  28. {
  29. EventAgent.DispatchEvent(ConstMessage.ITEM_ATTRIBUTE_CHANGED, id);
  30. }
  31. }
  32. public int MainScore
  33. {
  34. get
  35. {
  36. var cfg = ItemCfgArray.Instance.GetCfg(id);
  37. return GetScore(cfg.mainScore > 0 ? cfg.mainScore : 1);
  38. }
  39. }
  40. public int GetScore(int scoreType)
  41. {
  42. int valueBase = 0;
  43. var cfg = ItemCfgArray.Instance.GetCfg(id);
  44. if (cfg.itemType == ConstItemType.CARD)
  45. {
  46. return CardDataManager.GetCardDataById(id).scores[scoreType];
  47. }
  48. switch (scoreType)
  49. {
  50. case (int)ConstItemAttributeType.FENG:
  51. valueBase = cfg.score1;
  52. break;
  53. case (int)ConstItemAttributeType.HUA:
  54. valueBase = cfg.score2;
  55. break;
  56. case (int)ConstItemAttributeType.XUE:
  57. valueBase = cfg.score3;
  58. break;
  59. case (int)ConstItemAttributeType.YUE:
  60. valueBase = cfg.score4;
  61. break;
  62. }
  63. AttributesDic.TryGetValue(CalculateHelper.GetItemScoreKey(scoreType, (int)ConstItemAttributeActionType.ADD_VALUE), out var valueAdd);
  64. AttributesDic.TryGetValue(CalculateHelper.GetItemScoreKey(scoreType, (int)ConstItemAttributeActionType.ADD_PERCENT), out var percentAdd);
  65. return CalculateHelper.GetItemAttribute(valueBase, percentAdd, valueAdd);
  66. }
  67. }
  68. }