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

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