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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. public int MaxGamingAddiction { get; protected set; }
  52. private int gamingAddiction;
  53. public int GamingAddiction
  54. {
  55. get => gamingAddiction;
  56. set
  57. {
  58. if (value > 0)
  59. lock (gameObjLock)
  60. gamingAddiction = value <= MaxGamingAddiction ? value : MaxGamingAddiction;
  61. else
  62. lock (gameObjLock)
  63. gamingAddiction = 0;
  64. }
  65. }
  66. private int selfHealingTimes = 1;//剩余的自愈次数
  67. public int SelfHealingTimes
  68. {
  69. get => selfHealingTimes;
  70. set
  71. {
  72. lock (gameObjLock)
  73. selfHealingTimes = (value > 0) ? value : 0;
  74. }
  75. }
  76. private int degreeOfTreatment = 0;
  77. public int DegreeOfTreatment
  78. {
  79. get => degreeOfTreatment;
  80. private set
  81. {
  82. degreeOfTreatment = value;
  83. }
  84. }
  85. public void SetDegreeOfTreatment0()
  86. {
  87. DegreeOfTreatment = 0;
  88. }
  89. public bool SetDegreeOfTreatment(int value, Student whoTreatYou)
  90. {
  91. if (value <= 0) { degreeOfTreatment = 0; return false; }
  92. if (value >= MaxHp - HP)
  93. {
  94. whoTreatYou.AddScore(GameData.StudentScoreTreat(MaxHp - HP));
  95. HP = MaxHp;
  96. degreeOfTreatment = 0;
  97. return true;
  98. }
  99. if (value >= GameData.basicTreatmentDegree)
  100. {
  101. whoTreatYou.AddScore(GameData.StudentScoreTreat(GameData.basicTreatmentDegree));
  102. HP += GameData.basicTreatmentDegree;
  103. DegreeOfTreatment = 0;
  104. return true;
  105. }
  106. DegreeOfTreatment = value;
  107. return false;
  108. }
  109. public bool AddDegreeOfTreatment(int value, Student student)
  110. {
  111. return SetDegreeOfTreatment(value + degreeOfTreatment, student);
  112. }
  113. private int timeOfRescue = 0;
  114. public int TimeOfRescue
  115. {
  116. get => Interlocked.CompareExchange(ref timeOfRescue, -1, -1);
  117. }
  118. public bool AddTimeOfRescue(int value)
  119. {
  120. return Interlocked.Add(ref timeOfRescue, value) >= GameData.basicTimeOfRescue;
  121. }
  122. public void SetTimeOfRescue(int value)
  123. {
  124. Interlocked.Exchange(ref timeOfRescue, value);
  125. }
  126. public Student(XY initPos, int initRadius, CharacterType characterType) : base(initPos, initRadius, characterType)
  127. {
  128. this.orgFixSpeed = this.fixSpeed = ((IStudentType)Occupation).FixSpeed;
  129. this.TreatSpeed = this.orgTreatSpeed = ((IStudentType)Occupation).TreatSpeed;
  130. this.MaxGamingAddiction = ((IStudentType)Occupation).MaxGamingAddiction;
  131. }
  132. }
  133. public class Golem : Student, IGolem
  134. {
  135. private Character? parent; // 主人
  136. public Character? Parent
  137. {
  138. get => parent;
  139. set
  140. {
  141. lock (gameObjLock)
  142. {
  143. parent = value;
  144. }
  145. }
  146. }
  147. public override void AddScore(long add)
  148. {
  149. if (parent == null)
  150. base.AddScore(add);
  151. else parent.AddScore(add);
  152. }
  153. public Golem(XY initPos, int initRadius, Character? parent) : base(initPos, initRadius, CharacterType.Robot)
  154. {
  155. this.parent = parent;
  156. }
  157. }
  158. }