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

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