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.1 kB

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