SimpleExperienceSystem.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. public class SimpleExperienceSystem : IExperienceSystem
  5. {
  6. public SimpleExperienceSystem()
  7. {
  8. }
  9. public SimpleExperienceSystem(List<int> need_exp_list)
  10. {
  11. this.SetExreienceList(need_exp_list);
  12. }
  13. protected SimpleExperienceSystem(SimpleExperienceSystem other) : base(other)
  14. {
  15. this.need_exp_list_ = new List<int>(other.need_exp_list_);
  16. }
  17. public void SetExreienceList(List<int> need_exp_list)
  18. {
  19. if (need_exp_list == null || need_exp_list.Count <= 0)
  20. {
  21. this.need_exp_list_ = null;
  22. this.Update();
  23. return;
  24. }
  25. this.need_exp_list_ = need_exp_list;
  26. NDebug.Assert(0 < this.need_exp_list_.Count, "There is no element.");
  27. this.Update();
  28. }
  29. public override int GetMaxLevel()
  30. {
  31. return (this.need_exp_list_ != null) ? this.need_exp_list_.Count : 0;
  32. }
  33. protected override int GetNeedExp(int level)
  34. {
  35. if (this.need_exp_list_ == null)
  36. {
  37. return 0;
  38. }
  39. return this.need_exp_list_[level - 1];
  40. }
  41. public override void Serialize(BinaryWriter binary)
  42. {
  43. base.Serialize(binary);
  44. }
  45. public override void Update()
  46. {
  47. int level_ = this.level_;
  48. base.Update();
  49. if (level_ != this.level_ && this.onChangeLevelEvent != null)
  50. {
  51. this.onChangeLevelEvent(this);
  52. }
  53. }
  54. public void SerializeAll(BinaryWriter binary)
  55. {
  56. this.Serialize(binary);
  57. if (this.need_exp_list_ == null)
  58. {
  59. int value = 0;
  60. binary.Write(value);
  61. }
  62. else
  63. {
  64. binary.Write(this.need_exp_list_.Count);
  65. for (int i = 0; i < this.need_exp_list_.Count; i++)
  66. {
  67. binary.Write(this.need_exp_list_[i]);
  68. }
  69. }
  70. }
  71. public void DeserializeAll(BinaryReader binary, int version)
  72. {
  73. this.Deserialize(binary, version);
  74. int num = binary.ReadInt32();
  75. if (num <= 0)
  76. {
  77. this.need_exp_list_ = null;
  78. }
  79. else
  80. {
  81. if (this.need_exp_list_ == null)
  82. {
  83. this.need_exp_list_ = new List<int>();
  84. }
  85. this.need_exp_list_.Clear();
  86. for (int i = 0; i < num; i++)
  87. {
  88. this.need_exp_list_.Add(binary.ReadInt32());
  89. }
  90. }
  91. }
  92. public override object Clone()
  93. {
  94. return new SimpleExperienceSystem(this);
  95. }
  96. public Action<SimpleExperienceSystem> onChangeLevelEvent;
  97. protected List<int> need_exp_list_;
  98. }