ItemData.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using Codice.Client.Common;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Reflection;
  6. namespace GFGGame
  7. {
  8. public class ItemData
  9. {
  10. public int id;
  11. public int num;
  12. public bool isOnceBonus;
  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. switch(scoreType)
  49. {
  50. case (int)ConstItemAttributeType.FENG:
  51. valueBase = cfg.score1;
  52. break;
  53. case (int)ConstItemAttributeType.HUA:
  54. valueBase = cfg.score2;
  55. break;
  56. case (int)ConstItemAttributeType.XUE:
  57. valueBase = cfg.score3;
  58. break;
  59. case (int)ConstItemAttributeType.YUE:
  60. valueBase = cfg.score4;
  61. break;
  62. }
  63. AttributesDic.TryGetValue(CalculateHelper.GetItemScoreKey(scoreType, (int)ConstItemAttributeActionType.ADD_VALUE), out var valueAdd);
  64. AttributesDic.TryGetValue(CalculateHelper.GetItemScoreKey(scoreType, (int)ConstItemAttributeActionType.ADD_PERCENT), out var percentAdd);
  65. return CalculateHelper.GetItemAttribute(valueBase, percentAdd, valueAdd);
  66. }
  67. }
  68. }