ItemData.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. 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. CardData cardData = CardDataManager.GetCardDataById(id);
  47. if (cardData == null || !cardData.scores.ContainsKey(scoreType)) return 0;
  48. return CardDataManager.GetCardDataById(id).scores[scoreType];
  49. }
  50. switch (scoreType)
  51. {
  52. case (int)ConstItemAttributeType.FENG:
  53. valueBase = cfg.score1;
  54. break;
  55. case (int)ConstItemAttributeType.HUA:
  56. valueBase = cfg.score2;
  57. break;
  58. case (int)ConstItemAttributeType.XUE:
  59. valueBase = cfg.score3;
  60. break;
  61. case (int)ConstItemAttributeType.YUE:
  62. valueBase = cfg.score4;
  63. break;
  64. }
  65. AttributesDic.TryGetValue(CalculateHelper.GetItemScoreKey(scoreType, (int)ConstItemAttributeActionType.ADD_VALUE), out var valueAdd);
  66. AttributesDic.TryGetValue(CalculateHelper.GetItemScoreKey(scoreType, (int)ConstItemAttributeActionType.ADD_PERCENT), out var percentAdd);
  67. return CalculateHelper.GetItemAttribute(valueBase, percentAdd, valueAdd);
  68. }
  69. }
  70. }