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

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