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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  1. using Preparation.Interface;
  2. using Preparation.Utility;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Threading;
  6. namespace GameClass.GameObj
  7. {
  8. public partial class Character : Moveable, ICharacter // 负责人LHR摆烂终了
  9. {
  10. #region 装弹、攻击相关的基本属性及方法
  11. private readonly object attackLock = new();
  12. public IntNumUpdateByCD BulletNum { get; }
  13. private int orgCD;
  14. public int OrgCD
  15. {
  16. get
  17. {
  18. lock (attackLock)
  19. return orgCD;
  20. }
  21. }
  22. public readonly BulletType OriBulletOfPlayer;
  23. private BulletType bulletOfPlayer;
  24. public BulletType BulletOfPlayer
  25. {
  26. get
  27. {
  28. lock (attackLock)
  29. {
  30. return bulletOfPlayer;
  31. }
  32. }
  33. set
  34. {
  35. lock (attackLock)
  36. {
  37. bulletOfPlayer = value;
  38. orgCD = (BulletFactory.BulletCD(value));
  39. BulletNum.SetCD(orgCD);
  40. Debugger.Output(this, string.Format("'s CD has been set to: {0}.", orgCD));
  41. BulletNum.SetPositiveMaxNumAndNum(BulletFactory.BulletNum(value));
  42. }
  43. }
  44. }
  45. /// <summary>
  46. /// 进行一次攻击
  47. /// </summary>
  48. /// <returns>攻击操作发出的子弹</returns>
  49. public Bullet? Attack(double angle)
  50. {
  51. lock (attackLock)
  52. {
  53. if (bulletOfPlayer == BulletType.Null)
  54. return null;
  55. if (BulletNum.TrySub(1) == 1)
  56. {
  57. XY res = Position + new XY // 子弹紧贴人物生成。
  58. (
  59. (int)(Math.Abs((Radius + BulletFactory.BulletRadius(bulletOfPlayer)) * Math.Cos(angle))) * Math.Sign(Math.Cos(angle)),
  60. (int)(Math.Abs((Radius + BulletFactory.BulletRadius(bulletOfPlayer)) * Math.Sin(angle))) * Math.Sign(Math.Sin(angle))
  61. );
  62. Bullet? bullet = BulletFactory.GetBullet(this, res, this.bulletOfPlayer);
  63. if (bullet == null) return null;
  64. if (TryAddAp()) bullet.AP.Add(GameData.ApPropAdd);
  65. FacingDirection = new(angle, bullet.AttackDistance);
  66. return bullet;
  67. }
  68. else
  69. return null;
  70. }
  71. }
  72. #endregion
  73. #region 感知相关的基本属性及方法
  74. private readonly object bgmLock = new();
  75. private Dictionary<BgmType, double> bgmDictionary = new() { { BgmType.GhostIsComing, 0 }, { BgmType.StudentIsApproaching, 0 }, { BgmType.GeneratorIsBeingFixed, 0 } };
  76. public Dictionary<BgmType, double> BgmDictionary
  77. {
  78. get
  79. {
  80. lock (bgmLock)
  81. return bgmDictionary;
  82. }
  83. }
  84. public void AddBgm(BgmType bgm, double value)
  85. {
  86. lock (bgmLock)
  87. bgmDictionary[bgm] = value;
  88. }
  89. private readonly int alertnessRadius;
  90. public int AlertnessRadius => alertnessRadius;
  91. private readonly double concealment;
  92. public double Concealment => concealment;
  93. private readonly int viewRange;
  94. public int ViewRange => viewRange;
  95. #endregion
  96. #region 交互相关的基本属性及方法
  97. private readonly int speedOfOpeningOrLocking;
  98. public int SpeedOfOpeningOrLocking
  99. {
  100. get => speedOfOpeningOrLocking;
  101. }
  102. private readonly int speedOfClimbingThroughWindows;
  103. public int SpeedOfClimbingThroughWindows
  104. {
  105. get => speedOfClimbingThroughWindows;
  106. }
  107. private readonly int speedOfOpenChest;
  108. public int SpeedOfOpenChest
  109. {
  110. get => speedOfOpenChest;
  111. }
  112. #endregion
  113. #region 血量相关的基本属性及方法
  114. private readonly ReaderWriterLockSlim hpReaderWriterLock = new();
  115. public ReaderWriterLockSlim HPReadWriterLock => hpReaderWriterLock;
  116. private long maxHp;
  117. public long MaxHp
  118. {
  119. get
  120. {
  121. HPReadWriterLock.EnterReadLock();
  122. try
  123. {
  124. return maxHp;
  125. }
  126. finally
  127. {
  128. HPReadWriterLock.ExitReadLock();
  129. }
  130. }
  131. protected set
  132. {
  133. HPReadWriterLock.EnterWriteLock();
  134. try
  135. {
  136. maxHp = value;
  137. if (hp > maxHp) hp = maxHp;
  138. }
  139. finally
  140. {
  141. HPReadWriterLock.ExitWriteLock();
  142. }
  143. }
  144. }
  145. // 最大血量
  146. protected long hp;
  147. public long HP
  148. {
  149. get
  150. {
  151. HPReadWriterLock.EnterReadLock();
  152. try
  153. {
  154. return hp;
  155. }
  156. finally
  157. {
  158. HPReadWriterLock.ExitReadLock();
  159. }
  160. }
  161. }
  162. public long SetHP(long value)
  163. {
  164. HPReadWriterLock.EnterWriteLock();
  165. try
  166. {
  167. if (value > 0)
  168. {
  169. return hp = value <= maxHp ? value : maxHp;
  170. }
  171. else
  172. return hp = 0;
  173. }
  174. finally
  175. {
  176. HPReadWriterLock.ExitWriteLock();
  177. }
  178. }
  179. /// <summary>
  180. /// 尝试减血
  181. /// </summary>
  182. /// <param name="sub">减血量</param>
  183. public long SubHp(long sub)
  184. {
  185. HPReadWriterLock.EnterWriteLock();
  186. try
  187. {
  188. long previousHp = hp;
  189. if (hp <= sub)
  190. {
  191. hp = 0;
  192. return hp;
  193. }
  194. else
  195. {
  196. hp -= sub;
  197. return sub;
  198. }
  199. }
  200. finally
  201. {
  202. HPReadWriterLock.ExitWriteLock();
  203. }
  204. }
  205. public long AddHP(long add)
  206. {
  207. HPReadWriterLock.EnterWriteLock();
  208. try
  209. {
  210. long previousHp = hp;
  211. return (hp = (hp + add > maxHp) ? maxHp : hp + add) - previousHp;
  212. }
  213. finally
  214. {
  215. HPReadWriterLock.ExitWriteLock();
  216. }
  217. }
  218. private readonly object vampireLock = new();
  219. public object VampireLock => vampire;
  220. private double vampire = 0; // 回血率:0-1之间
  221. public double Vampire
  222. {
  223. get
  224. {
  225. lock (vampireLock)
  226. return vampire;
  227. }
  228. set
  229. {
  230. lock (vampireLock)
  231. {
  232. if (value > 1)
  233. vampire = 1;
  234. else if (value < 0)
  235. vampire = 0;
  236. else
  237. vampire = value;
  238. }
  239. }
  240. }
  241. public double OriVampire { get; protected set; }
  242. private readonly object treatLock = new();
  243. private int degreeOfTreatment = 0;
  244. public int DegreeOfTreatment
  245. {
  246. get
  247. {
  248. HPReadWriterLock.EnterReadLock();
  249. try
  250. {
  251. return degreeOfTreatment;
  252. }
  253. finally
  254. {
  255. HPReadWriterLock.ExitReadLock();
  256. }
  257. }
  258. }
  259. public void SetDegreeOfTreatment0()
  260. {
  261. HPReadWriterLock.EnterWriteLock();
  262. try
  263. {
  264. degreeOfTreatment = 0;
  265. }
  266. finally
  267. {
  268. HPReadWriterLock.ExitWriteLock();
  269. }
  270. }
  271. public bool AddDegreeOfTreatment(int value, Student whoTreatYou)
  272. {
  273. HPReadWriterLock.EnterWriteLock();
  274. try
  275. {
  276. if (value >= maxHp - hp)
  277. {
  278. whoTreatYou.AddScore(GameData.StudentScoreTreat(maxHp - hp));
  279. hp = maxHp;
  280. degreeOfTreatment = 0;
  281. return true;
  282. }
  283. if (value >= GameData.basicTreatmentDegree)
  284. {
  285. whoTreatYou.AddScore(GameData.StudentScoreTreat(GameData.basicTreatmentDegree));
  286. hp += GameData.basicTreatmentDegree;
  287. degreeOfTreatment = 0;
  288. return true;
  289. }
  290. degreeOfTreatment = value;
  291. }
  292. finally
  293. {
  294. HPReadWriterLock.ExitWriteLock();
  295. }
  296. return false;
  297. }
  298. #endregion
  299. #region 查询状态相关的基本属性与方法
  300. private PlayerStateType playerState = PlayerStateType.Null;
  301. public PlayerStateType PlayerState
  302. {
  303. get
  304. {
  305. lock (actionLock)
  306. {
  307. if (playerState == PlayerStateType.Moving)
  308. return (IsMoving) ? PlayerStateType.Moving : PlayerStateType.Null;
  309. return playerState;
  310. }
  311. }
  312. }
  313. public bool NoHp()
  314. {
  315. lock (actionLock)
  316. return (playerState == PlayerStateType.Deceased || playerState == PlayerStateType.Escaped || playerState == PlayerStateType.Addicted || playerState == PlayerStateType.Rescued);
  317. }
  318. public bool Commandable()
  319. {
  320. lock (actionLock)
  321. {
  322. return (playerState != PlayerStateType.Deceased && playerState != PlayerStateType.Escaped
  323. && playerState != PlayerStateType.Addicted && playerState != PlayerStateType.Rescued
  324. && playerState != PlayerStateType.Swinging && playerState != PlayerStateType.TryingToAttack
  325. && playerState != PlayerStateType.ClimbingThroughWindows
  326. && playerState != PlayerStateType.Stunned && playerState != PlayerStateType.Charmed);
  327. }
  328. }
  329. public bool CanPinDown()
  330. {
  331. lock (actionLock)
  332. {
  333. return (playerState != PlayerStateType.Deceased && playerState != PlayerStateType.Escaped
  334. && playerState != PlayerStateType.Addicted && playerState != PlayerStateType.Rescued
  335. && playerState != PlayerStateType.Stunned && playerState != PlayerStateType.Charmed);
  336. }
  337. }
  338. public bool InteractingWithMapWithoutMoving()
  339. {
  340. lock (actionLock)
  341. {
  342. return (playerState == PlayerStateType.LockingTheDoor || playerState == PlayerStateType.OpeningTheDoor
  343. || playerState == PlayerStateType.Fixing || playerState == PlayerStateType.OpeningTheChest);
  344. }
  345. }
  346. public bool NullOrMoving()
  347. {
  348. lock (actionLock)
  349. {
  350. return (playerState == PlayerStateType.Null || playerState == PlayerStateType.Moving);
  351. }
  352. }
  353. public bool CanBeAwed()
  354. {
  355. lock (actionLock)
  356. return !(playerState == PlayerStateType.Deceased || playerState == PlayerStateType.Escaped
  357. || playerState == PlayerStateType.Addicted
  358. || playerState == PlayerStateType.Rescued || playerState == PlayerStateType.Treated
  359. || playerState == PlayerStateType.Stunned || playerState == PlayerStateType.Charmed
  360. || playerState == PlayerStateType.Null || playerState == PlayerStateType.Moving);
  361. }
  362. #endregion
  363. #region 更改状态相关的属性和方法
  364. private GameObj? whatInteractingWith = null;
  365. public GameObj? WhatInteractingWith
  366. {
  367. get
  368. {
  369. lock (actionLock)
  370. {
  371. return whatInteractingWith;
  372. }
  373. }
  374. }
  375. private long ChangePlayerState(RunningStateType running, PlayerStateType value = PlayerStateType.Null, GameObj? gameObj = null)
  376. {
  377. //只能被SetPlayerState引用
  378. if (runningState == RunningStateType.RunningSleepily)
  379. {
  380. ThreadNum.Release();
  381. }
  382. runningState = running;
  383. whatInteractingWith = gameObj;
  384. playerState = value;
  385. return ++stateNum;
  386. }
  387. private long ChangePlayerStateInOneThread(RunningStateType running, PlayerStateType value = PlayerStateType.Null, GameObj? gameObj = null)
  388. {
  389. if (runningState == RunningStateType.RunningSleepily)
  390. {
  391. ThreadNum.Release();
  392. }
  393. runningState = running;
  394. //只能被SetPlayerState引用
  395. whatInteractingWith = gameObj;
  396. playerState = value;
  397. return stateNum;
  398. }
  399. public long SetPlayerState(RunningStateType runningState, PlayerStateType value = PlayerStateType.Null, IGameObj? obj = null)
  400. {
  401. GameObj? gameObj = (GameObj?)obj;
  402. lock (actionLock)
  403. {
  404. PlayerStateType nowPlayerState = PlayerState;
  405. if (nowPlayerState == value && value != PlayerStateType.UsingSkill) return -1;
  406. GameObj? lastObj = whatInteractingWith;
  407. switch (nowPlayerState)
  408. {
  409. case PlayerStateType.Escaped:
  410. case PlayerStateType.Deceased:
  411. return -1;
  412. case PlayerStateType.Addicted:
  413. if (value == PlayerStateType.Rescued)
  414. return ChangePlayerStateInOneThread(runningState, value, gameObj);
  415. else if (value == PlayerStateType.Null || value == PlayerStateType.Deceased)
  416. return ChangePlayerState(runningState, value, gameObj);
  417. else return -1;
  418. case PlayerStateType.Rescued:
  419. if (value == PlayerStateType.Addicted)
  420. return ChangePlayerStateInOneThread(runningState, value, gameObj);
  421. else if (value == PlayerStateType.Null || value == PlayerStateType.Deceased)
  422. return ChangePlayerState(runningState, value, gameObj);
  423. else return -1;
  424. case PlayerStateType.TryingToAttack:
  425. if (value == PlayerStateType.Addicted || value == PlayerStateType.Swinging
  426. || value == PlayerStateType.Deceased || value == PlayerStateType.Stunned
  427. || value == PlayerStateType.Charmed || value == PlayerStateType.Null)
  428. return ChangePlayerState(runningState, value, gameObj);
  429. else return -1;
  430. case PlayerStateType.Stunned:
  431. case PlayerStateType.Charmed:
  432. if (value == PlayerStateType.Addicted || value == PlayerStateType.Deceased
  433. || value == PlayerStateType.Null)
  434. return ChangePlayerState(runningState, value, gameObj);
  435. else return -1;
  436. case PlayerStateType.Swinging:
  437. if (value == PlayerStateType.Addicted
  438. || value == PlayerStateType.Deceased || value == PlayerStateType.Stunned
  439. || value == PlayerStateType.Charmed || value == PlayerStateType.Null)
  440. return ChangePlayerState(runningState, value, gameObj);
  441. else return -1;
  442. case PlayerStateType.ClimbingThroughWindows:
  443. if (value == PlayerStateType.Addicted
  444. || value == PlayerStateType.Deceased || value == PlayerStateType.Stunned
  445. || value == PlayerStateType.Charmed || value == PlayerStateType.Null)
  446. {
  447. Window window = (Window)lastObj!;
  448. if (window.Stage.x != 0) ReSetPos(window.Stage);
  449. window.FinishClimbing();
  450. return ChangePlayerState(runningState, value, gameObj);
  451. }
  452. else return -1;
  453. case PlayerStateType.OpeningTheChest:
  454. if (value == PlayerStateType.Rescued) return -1;
  455. ((Chest)lastObj!).StopOpen();
  456. return ChangePlayerState(runningState, value, gameObj);
  457. case PlayerStateType.OpeningTheDoorway:
  458. if (value == PlayerStateType.Rescued) return -1;
  459. Doorway doorway = (Doorway)lastObj!;
  460. doorway.StopOpenning();
  461. return ChangePlayerState(runningState, value, gameObj);
  462. case PlayerStateType.OpeningTheDoor:
  463. if (value == PlayerStateType.Rescued) return -1;
  464. Door door = (Door)lastObj!;
  465. door.StopOpen();
  466. ReleaseTool(door.KeyType);
  467. return ChangePlayerState(runningState, value, gameObj);
  468. case PlayerStateType.UsingSkill:
  469. {
  470. if (value == PlayerStateType.Rescued) return -1;
  471. switch (CharacterType)
  472. {
  473. case CharacterType.TechOtaku:
  474. {
  475. if (typeof(CraftingBench).IsInstanceOfType(lastObj))
  476. {
  477. ((CraftingBench)lastObj!).StopSkill();
  478. return ChangePlayerState(runningState, value, gameObj);
  479. }
  480. else
  481. {
  482. if (value != PlayerStateType.UsingSkill)
  483. ((UseRobot)FindActiveSkill(ActiveSkillType.UseRobot)).NowPlayerID = (int)playerID;
  484. return ChangePlayerState(runningState, value, gameObj);
  485. }
  486. }
  487. case CharacterType.Assassin:
  488. if (value == PlayerStateType.Moving) return StateNum;
  489. else
  490. {
  491. TryDeleteInvisible();
  492. return ChangePlayerState(runningState, value, gameObj);
  493. }
  494. default:
  495. return ChangePlayerState(runningState, value, gameObj);
  496. }
  497. }
  498. default:
  499. if (value == PlayerStateType.Rescued) return -1;
  500. return ChangePlayerState(runningState, value, gameObj);
  501. }
  502. }
  503. }
  504. public long SetPlayerStateNaturally()
  505. {
  506. lock (actionLock)
  507. {
  508. runningState = RunningStateType.Null;
  509. whatInteractingWith = null;
  510. playerState = PlayerStateType.Null;
  511. return ++stateNum;
  512. }
  513. }
  514. public bool ResetPlayerState(long state, RunningStateType running = RunningStateType.Null, PlayerStateType value = PlayerStateType.Null, IGameObj? obj = null)
  515. {
  516. lock (actionLock)
  517. {
  518. if (state != stateNum) return false;
  519. this.runningState = running;
  520. whatInteractingWith = (GameObj?)obj;
  521. playerState = value;
  522. ++stateNum;
  523. return true;
  524. }
  525. }
  526. public bool ResetPlayerStateInOneThread(long state, RunningStateType running = RunningStateType.Null, PlayerStateType value = PlayerStateType.Null, IGameObj? obj = null)
  527. {
  528. lock (actionLock)
  529. {
  530. if (state != stateNum) return false;
  531. this.runningState = running;
  532. whatInteractingWith = (GameObj?)obj;
  533. playerState = value;
  534. return true;
  535. }
  536. }
  537. public bool StartThread(long stateNum, RunningStateType runningState)
  538. {
  539. lock (ActionLock)
  540. {
  541. if (this.StateNum == stateNum)
  542. {
  543. this.runningState = runningState;
  544. return true;
  545. }
  546. }
  547. return false;
  548. }
  549. public bool TryToRemoveFromGame(PlayerStateType playerStateType)
  550. {
  551. lock (actionLock)
  552. {
  553. if (SetPlayerState(RunningStateType.RunningForcibly, playerStateType) == -1) return false;
  554. TryToRemove();
  555. CanMove.Set(false);
  556. position = GameData.PosWhoDie;
  557. }
  558. return true;
  559. }
  560. #endregion
  561. private long score = 0;
  562. public long Score
  563. {
  564. get => Interlocked.Read(ref score);
  565. }
  566. /// <summary>
  567. /// 加分
  568. /// </summary>
  569. /// <param name="add">增加量</param>
  570. public virtual void AddScore(long add)
  571. {
  572. Interlocked.Add(ref score, add);
  573. //Debugger.Output(this, " 's score has been added to: " + score.ToString());
  574. }
  575. /// <summary>
  576. /// 角色所属队伍ID
  577. /// </summary>
  578. private long teamID = long.MaxValue;
  579. public long TeamID
  580. {
  581. get => Interlocked.Read(ref teamID);
  582. set => Interlocked.Exchange(ref teamID, value);
  583. }
  584. private long playerID = long.MaxValue;
  585. public long PlayerID
  586. {
  587. get => Interlocked.Read(ref playerID);
  588. set => Interlocked.Exchange(ref playerID, value);
  589. }
  590. #region 道具和buff相关属性、方法
  591. private readonly object inventoryLock = new();
  592. public object InventoryLock => inventoryLock;
  593. private Gadget[] propInventory = new Gadget[GameData.maxNumOfPropInPropInventory]
  594. {new NullProp(), new NullProp(),new NullProp() };
  595. public Gadget[] PropInventory
  596. {
  597. get
  598. {
  599. lock (inventoryLock)
  600. return propInventory;
  601. }
  602. set
  603. {
  604. lock (inventoryLock)
  605. propInventory = value;
  606. }
  607. }
  608. /// <summary>
  609. /// 使用物品栏中的道具
  610. /// </summary>
  611. /// <returns>被使用的道具</returns>
  612. public Gadget ConsumeProp(int indexing)
  613. {
  614. if (indexing < 0 || indexing >= GameData.maxNumOfPropInPropInventory)
  615. return new NullProp();
  616. lock (inventoryLock)
  617. {
  618. Gadget prop = propInventory[indexing];
  619. if (!prop.IsUsable()) return new NullProp();
  620. PropInventory[indexing] = new NullProp();
  621. return prop;
  622. }
  623. }
  624. public Gadget ConsumeProp(PropType propType)
  625. {
  626. if (propType == PropType.Null)
  627. {
  628. lock (inventoryLock)
  629. {
  630. for (int indexing = 0; indexing < GameData.maxNumOfPropInPropInventory; ++indexing)
  631. {
  632. if (PropInventory[indexing].IsUsable())
  633. {
  634. Gadget prop = PropInventory[indexing];
  635. PropInventory[indexing] = new NullProp();
  636. return prop;
  637. }
  638. }
  639. }
  640. }
  641. else
  642. {
  643. lock (inventoryLock)
  644. {
  645. for (int indexing = 0; indexing < GameData.maxNumOfPropInPropInventory; ++indexing)
  646. {
  647. if (PropInventory[indexing].GetPropType() == propType && PropInventory[indexing].IsUsable())
  648. {
  649. Gadget prop = PropInventory[indexing];
  650. PropInventory[indexing] = new NullProp();
  651. return prop;
  652. }
  653. }
  654. }
  655. }
  656. return new NullProp();
  657. }
  658. public bool UseTool(PropType propType)//占用道具,使其不能重复使用和被消耗
  659. {
  660. lock (inventoryLock)
  661. {
  662. for (int indexing = 0; indexing < GameData.maxNumOfPropInPropInventory; ++indexing)
  663. {
  664. if (PropInventory[indexing].GetPropType() == propType && PropInventory[indexing].IsUsable())
  665. {
  666. return ((Tool)PropInventory[indexing]).IsUsed = true;
  667. }
  668. }
  669. }
  670. return false;
  671. }
  672. public void ReleaseTool(PropType propType)
  673. {
  674. lock (inventoryLock)
  675. {
  676. for (int indexing = 0; indexing < GameData.maxNumOfPropInPropInventory; ++indexing)
  677. {
  678. if (PropInventory[indexing].GetPropType() == propType && ((Tool)PropInventory[indexing]).IsUsed)
  679. {
  680. ((Tool)PropInventory[indexing]).IsUsed = false;
  681. break;
  682. }
  683. }
  684. }
  685. }
  686. /// <summary>
  687. /// 如果indexing==GameData.maxNumOfPropInPropInventory表明道具栏为满
  688. /// </summary>
  689. public int IndexingOfAddProp()
  690. {
  691. int indexing = 0;
  692. lock (inventoryLock)
  693. for (; indexing < GameData.maxNumOfPropInPropInventory; ++indexing)
  694. if (propInventory[indexing].GetPropType() == PropType.Null)
  695. break;
  696. return indexing;
  697. }
  698. public void AddMoveSpeed(int buffTime, double add = 1.0) => buffManager.AddMoveSpeed(add, buffTime, newVal =>
  699. { MoveSpeed.Set(newVal < GameData.characterMaxSpeed ? newVal : GameData.characterMaxSpeed); },
  700. OrgMoveSpeed);
  701. public bool HasFasterSpeed => buffManager.HasFasterSpeed;
  702. public void AddShield(int shieldTime) => buffManager.AddShield(shieldTime);
  703. public bool HasShield => buffManager.HasShield;
  704. public void AddLife(int LIFETime) => buffManager.AddLife(LIFETime);
  705. public bool HasLIFE => buffManager.HasLIFE;
  706. public void AddAp(int time) => buffManager.AddAp(time);
  707. public bool HasAp => buffManager.HasAp;
  708. public void AddSpear(int spearTime) => buffManager.AddSpear(spearTime);
  709. public bool HasSpear => buffManager.HasSpear;
  710. public void AddClairaudience(int time) => buffManager.AddClairaudience(time);
  711. public bool HasClairaudience => buffManager.HasClairaudience;
  712. public void AddInvisible(int time) => buffManager.AddInvisible(time);
  713. public bool HasInvisible => buffManager.HasInvisible;
  714. private Array buffTypeArray = Enum.GetValues(typeof(BuffType));
  715. public Dictionary<BuffType, bool> Buff
  716. {
  717. get
  718. {
  719. Dictionary<BuffType, bool> buff = new Dictionary<BuffType, bool>();
  720. foreach (BuffType type in buffTypeArray)
  721. {
  722. if (type != BuffType.Null)
  723. buff.Add(type, GetBuffStatus(type));
  724. }
  725. return buff;
  726. }
  727. }
  728. private bool GetBuffStatus(BuffType type)
  729. {
  730. switch (type)
  731. {
  732. case BuffType.Spear:
  733. return this.HasSpear;
  734. case BuffType.AddSpeed:
  735. return this.HasFasterSpeed;
  736. case BuffType.Shield:
  737. return this.HasShield;
  738. case BuffType.AddLife:
  739. return this.HasLIFE;
  740. case BuffType.AddAp:
  741. return this.HasAp;
  742. case BuffType.Clairaudience:
  743. return this.HasClairaudience;
  744. case BuffType.Invisible:
  745. return this.HasInvisible;
  746. default:
  747. return false;
  748. }
  749. }
  750. public void TryActivatingLIFE()
  751. {
  752. if (buffManager.TryActivatingLIFE())
  753. {
  754. AddScore(GameData.ScorePropRemainHp);
  755. hp = GameData.RemainHpWhenAddLife;
  756. }
  757. }
  758. public bool TryAddAp()
  759. {
  760. if (buffManager.TryAddAp())
  761. {
  762. AddScore(GameData.ScorePropAddAp);
  763. return true;
  764. }
  765. return false;
  766. }
  767. public bool TryUseSpear()
  768. {
  769. return buffManager.TryUseSpear();
  770. }
  771. public bool TryDeleteInvisible()
  772. {
  773. return buffManager.TryDeleteInvisible();
  774. }
  775. public bool TryUseShield()
  776. {
  777. if (buffManager.TryUseShield())
  778. {
  779. AddScore(GameData.ScorePropUseShield);
  780. return true;
  781. }
  782. return false;
  783. }
  784. #endregion
  785. /* public override void Reset() // 要加锁吗?
  786. {
  787. lock (gameObjLock)
  788. {
  789. // _ = AddDeathCount();
  790. base.Reset();
  791. this.MoveSpeed = OrgMoveSpeed;
  792. HP = MaxHp;
  793. PropInventory = null;
  794. BulletOfPlayer = OriBulletOfPlayer;
  795. lock (gameObjLock)
  796. bulletNum = maxBulletNum;
  797. buffManager.ClearAll();
  798. IsInvisible = false;
  799. this.Vampire = this.OriVampire;
  800. }
  801. }*/
  802. public override bool IsRigid => true;
  803. public override ShapeType Shape => ShapeType.Circle;
  804. public override bool IgnoreCollideExecutor(IGameObj targetObj)
  805. {
  806. if (IsRemoved)
  807. return true;
  808. if (targetObj.Type == GameObjType.Gadget)
  809. {
  810. return true;
  811. }
  812. if (targetObj.Type == GameObjType.Character && XY.DistanceCeil3(targetObj.Position, this.Position) < this.Radius + targetObj.Radius - GameData.adjustLength)
  813. return true;
  814. return false;
  815. }
  816. }
  817. }