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

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