ItemData.cs 2.7 KB

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