ItemData.cs 2.6 KB

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