ItemData.cs 2.6 KB

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