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

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