ItemData.cs 2.9 KB

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