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 5.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 selfHealingTimes = 1;//剩余的自愈次数
  88. public int SelfHealingTimes
  89. {
  90. get => selfHealingTimes;
  91. set
  92. {
  93. lock (gameObjLock)
  94. selfHealingTimes = (value > 0) ? value : 0;
  95. }
  96. }
  97. private int degreeOfTreatment = 0;
  98. public int DegreeOfTreatment
  99. {
  100. get => degreeOfTreatment;
  101. private set
  102. {
  103. degreeOfTreatment = value;
  104. }
  105. }
  106. public void SetDegreeOfTreatment0()
  107. {
  108. DegreeOfTreatment = 0;
  109. }
  110. public bool SetDegreeOfTreatment(int value, Student whoTreatYou)
  111. {
  112. if (value <= 0) { degreeOfTreatment = 0; return false; }
  113. if (value >= MaxHp - HP)
  114. {
  115. whoTreatYou.AddScore(GameData.StudentScoreTreat(MaxHp - HP));
  116. HP = MaxHp;
  117. degreeOfTreatment = 0;
  118. return true;
  119. }
  120. if (value >= GameData.basicTreatmentDegree)
  121. {
  122. whoTreatYou.AddScore(GameData.StudentScoreTreat(GameData.basicTreatmentDegree));
  123. HP += GameData.basicTreatmentDegree;
  124. DegreeOfTreatment = 0;
  125. return true;
  126. }
  127. DegreeOfTreatment = value;
  128. return false;
  129. }
  130. public bool AddDegreeOfTreatment(int value, Student student)
  131. {
  132. return SetDegreeOfTreatment(value + degreeOfTreatment, student);
  133. }
  134. private int timeOfRescue = 0;
  135. public int TimeOfRescue
  136. {
  137. get => Interlocked.CompareExchange(ref timeOfRescue, -1, -1);
  138. }
  139. public bool AddTimeOfRescue(int value)
  140. {
  141. return Interlocked.Add(ref timeOfRescue, value) >= GameData.basicTimeOfRescue;
  142. }
  143. public void SetTimeOfRescue(int value)
  144. {
  145. Interlocked.Exchange(ref timeOfRescue, value);
  146. }
  147. public Student(XY initPos, int initRadius, CharacterType characterType) : base(initPos, initRadius, characterType)
  148. {
  149. this.orgFixSpeed = this.fixSpeed = ((IStudentType)Occupation).FixSpeed;
  150. this.TreatSpeed = this.orgTreatSpeed = ((IStudentType)Occupation).TreatSpeed;
  151. this.MaxGamingAddiction = ((IStudentType)Occupation).MaxGamingAddiction;
  152. }
  153. }
  154. public class Golem : Student, IGolem
  155. {
  156. private Character? parent; // 主人
  157. public Character? Parent
  158. {
  159. get => parent;
  160. set
  161. {
  162. lock (gameObjLock)
  163. {
  164. parent = value;
  165. }
  166. }
  167. }
  168. public override void AddScore(long add)
  169. {
  170. if (parent == null)
  171. base.AddScore(add);
  172. else parent.AddScore(add);
  173. }
  174. public Golem(XY initPos, int initRadius, Character? parent) : base(initPos, initRadius, CharacterType.Robot)
  175. {
  176. this.parent = parent;
  177. }
  178. }
  179. }