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

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