ItemData.cs 2.8 KB

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