|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- using Preparation.Utility;
- using Preparation.Interface;
- using System;
- using System.Threading;
-
- namespace GameClass.GameObj
- {
- public class Student : Character
- {
- private readonly object fixLock = new();
- protected int fixSpeed;
- /// <summary>
- /// 修理电机速度
- /// </summary>
- public int FixSpeed
- {
- get
- {
- lock (fixLock)
- return fixSpeed;
- }
- set
- {
- lock (fixLock)
- {
- fixSpeed = value;
- }
- }
- }
- /// <summary>
- /// 原初修理电机速度
- /// </summary>
- protected readonly int orgFixSpeed;
-
- private readonly object treatLock = new();
- protected int treatSpeed = GameData.basicTreatSpeed;
- public int TreatSpeed
- {
- get
- {
- lock (treatLock)
- return treatSpeed;
- }
- set
- {
- lock (treatLock)
- {
- treatSpeed = value;
- }
- }
- }
- protected readonly int orgTreatSpeed;
-
- private readonly object addictionLock = new();
- private int maxGamingAddiction;
- public int MaxGamingAddiction
- {
- get
- {
- lock (addictionLock)
- return maxGamingAddiction;
- }
- protected set
- {
- lock (addictionLock)
- {
- if (value < gamingAddiction) gamingAddiction = value;
- maxGamingAddiction = value;
- }
- }
- }
- private int gamingAddiction;
- public int GamingAddiction
- {
- get
- {
- lock (addictionLock)
- return gamingAddiction;
- }
- set
- {
- if (value > 0)
- lock (addictionLock)
- gamingAddiction = value <= maxGamingAddiction ? value : maxGamingAddiction;
- else
- lock (addictionLock)
- gamingAddiction = 0;
- }
- }
-
- private int degreeOfTreatment = 0;
- public int DegreeOfTreatment
- {
- get => degreeOfTreatment;
- private set
- {
- degreeOfTreatment = value;
- }
- }
- public void SetDegreeOfTreatment0()
- {
- DegreeOfTreatment = 0;
- }
- public bool SetDegreeOfTreatment(int value, Student whoTreatYou)
- {
- if (value <= 0) { degreeOfTreatment = 0; return false; }
- if (value >= MaxHp - HP)
- {
- whoTreatYou.AddScore(GameData.StudentScoreTreat(MaxHp - HP));
- HP = MaxHp;
- degreeOfTreatment = 0;
- return true;
- }
- if (value >= GameData.basicTreatmentDegree)
- {
- whoTreatYou.AddScore(GameData.StudentScoreTreat(GameData.basicTreatmentDegree));
- HP += GameData.basicTreatmentDegree;
- DegreeOfTreatment = 0;
- return true;
- }
- DegreeOfTreatment = value;
- return false;
- }
- public bool AddDegreeOfTreatment(int value, Student student)
- {
- return SetDegreeOfTreatment(value + degreeOfTreatment, student);
- }
-
- private int timeOfRescue = 0;
- public int TimeOfRescue
- {
- get => Interlocked.CompareExchange(ref timeOfRescue, -1, -1);
- }
- public bool AddTimeOfRescue(int value)
- {
- return Interlocked.Add(ref timeOfRescue, value) >= GameData.basicTimeOfRescue;
- }
- public void SetTimeOfRescue(int value)
- {
- Interlocked.Exchange(ref timeOfRescue, value);
- }
-
- public Student(XY initPos, int initRadius, CharacterType characterType) : base(initPos, initRadius, characterType)
- {
- this.orgFixSpeed = this.fixSpeed = ((IStudentType)Occupation).FixSpeed;
- this.TreatSpeed = this.orgTreatSpeed = ((IStudentType)Occupation).TreatSpeed;
- this.MaxGamingAddiction = ((IStudentType)Occupation).MaxGamingAddiction;
- }
- }
- public class Golem : Student, IGolem
- {
- private Character? parent; // 主人
- public Character? Parent
- {
- get => parent;
- set
- {
- lock (gameObjLock)
- {
- parent = value;
- }
- }
- }
- public override void AddScore(long add)
- {
- if (parent == null)
- base.AddScore(add);
- else parent.AddScore(add);
- }
- public Golem(XY initPos, int initRadius, Character? parent) : base(initPos, initRadius, CharacterType.Robot)
- {
- this.parent = parent;
- }
- }
- }
|