You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Character.Student.cs 4.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using Preparation.Utility;
  2. using Preparation.Interface;
  3. using System;
  4. using System.Threading;
  5. namespace GameClass.GameObj
  6. {
  7. public class Student : Character
  8. {
  9. private readonly object fixLock = new();
  10. protected int fixSpeed;
  11. /// <summary>
  12. /// 修理电机速度
  13. /// </summary>
  14. public int FixSpeed
  15. {
  16. get
  17. {
  18. lock (fixLock)
  19. return fixSpeed;
  20. }
  21. set
  22. {
  23. lock (fixLock)
  24. {
  25. fixSpeed = value;
  26. }
  27. }
  28. }
  29. /// <summary>
  30. /// 原初修理电机速度
  31. /// </summary>
  32. protected readonly int orgFixSpeed;
  33. private readonly object treatLock = new();
  34. protected int treatSpeed = GameData.basicTreatSpeed;
  35. public int TreatSpeed
  36. {
  37. get
  38. {
  39. lock (treatLock)
  40. return treatSpeed;
  41. }
  42. set
  43. {
  44. lock (treatLock)
  45. {
  46. treatSpeed = value;
  47. }
  48. }
  49. }
  50. protected readonly int orgTreatSpeed;
  51. private readonly object addictionLock = new();
  52. private int maxGamingAddiction;
  53. public int MaxGamingAddiction
  54. {
  55. get
  56. {
  57. lock (addictionLock)
  58. return maxGamingAddiction;
  59. }
  60. protected set
  61. {
  62. lock (addictionLock)
  63. {
  64. if (value < gamingAddiction) gamingAddiction = value;
  65. maxGamingAddiction = value;
  66. }
  67. }
  68. }
  69. private int gamingAddiction;
  70. public int GamingAddiction
  71. {
  72. get
  73. {
  74. lock (addictionLock)
  75. return gamingAddiction;
  76. }
  77. set
  78. {
  79. if (value > 0)
  80. lock (addictionLock)
  81. gamingAddiction = value <= maxGamingAddiction ? value : maxGamingAddiction;
  82. else
  83. lock (addictionLock)
  84. gamingAddiction = 0;
  85. }
  86. }
  87. private int timeOfRescue = 0;
  88. public int TimeOfRescue
  89. {
  90. get => Interlocked.CompareExchange(ref timeOfRescue, -1, -1);
  91. }
  92. public bool AddTimeOfRescue(int value)
  93. {
  94. return Interlocked.Add(ref timeOfRescue, value) >= GameData.basicTimeOfRescue;
  95. }
  96. public void SetTimeOfRescue(int value)
  97. {
  98. Interlocked.Exchange(ref timeOfRescue, value);
  99. }
  100. public Student(XY initPos, int initRadius, CharacterType characterType) : base(initPos, initRadius, characterType)
  101. {
  102. this.orgFixSpeed = this.fixSpeed = ((IStudentType)Occupation).FixSpeed;
  103. this.TreatSpeed = this.orgTreatSpeed = ((IStudentType)Occupation).TreatSpeed;
  104. this.MaxGamingAddiction = ((IStudentType)Occupation).MaxGamingAddiction;
  105. }
  106. }
  107. public class Golem : Student, IGolem
  108. {
  109. private readonly object parentLock = new();
  110. private Character? parent; // 主人
  111. public Character? Parent
  112. {
  113. get
  114. {
  115. lock (parentLock)
  116. return parent;
  117. }
  118. set
  119. {
  120. lock (parentLock)
  121. {
  122. parent = value;
  123. }
  124. }
  125. }
  126. public override void AddScore(long add)
  127. {
  128. if (parent == null)
  129. base.AddScore(add);
  130. else parent.AddScore(add);
  131. }
  132. public Golem(XY initPos, int initRadius, Character? parent) : base(initPos, initRadius, CharacterType.Robot)
  133. {
  134. this.parent = parent;
  135. }
  136. }
  137. }