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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  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. #endregion
  357. #region 更改状态相关的属性和方法
  358. private GameObj? whatInteractingWith = null;
  359. public GameObj? WhatInteractingWith
  360. {
  361. get
  362. {
  363. lock (actionLock)
  364. {
  365. return whatInteractingWith;
  366. }
  367. }
  368. }
  369. private long ChangePlayerState(RunningStateType running, PlayerStateType value = PlayerStateType.Null, GameObj? gameObj = null)
  370. {
  371. //只能被SetPlayerState引用
  372. if (runningState == RunningStateType.RunningSleepily)
  373. {
  374. ThreadNum.Release();
  375. }
  376. runningState = running;
  377. whatInteractingWith = gameObj;
  378. playerState = value;
  379. return ++stateNum;
  380. }
  381. private long ChangePlayerStateInOneThread(RunningStateType running, PlayerStateType value = PlayerStateType.Null, GameObj? gameObj = null)
  382. {
  383. if (runningState == RunningStateType.RunningSleepily)
  384. {
  385. ThreadNum.Release();
  386. }
  387. runningState = running;
  388. //只能被SetPlayerState引用
  389. whatInteractingWith = gameObj;
  390. playerState = value;
  391. return stateNum;
  392. }
  393. public long SetPlayerState(RunningStateType runningState, PlayerStateType value = PlayerStateType.Null, IGameObj? obj = null)
  394. {
  395. GameObj? gameObj = (GameObj?)obj;
  396. lock (actionLock)
  397. {
  398. PlayerStateType nowPlayerState = PlayerState;
  399. if (nowPlayerState == value && value != PlayerStateType.UsingSkill) return -1;
  400. GameObj? lastObj = whatInteractingWith;
  401. switch (nowPlayerState)
  402. {
  403. case PlayerStateType.Escaped:
  404. case PlayerStateType.Deceased:
  405. return -1;
  406. case PlayerStateType.Addicted:
  407. if (value == PlayerStateType.Rescued)
  408. return ChangePlayerStateInOneThread(runningState, value, gameObj);
  409. else if (value == PlayerStateType.Null || value == PlayerStateType.Deceased)
  410. return ChangePlayerState(runningState, value, gameObj);
  411. else return -1;
  412. case PlayerStateType.Rescued:
  413. if (value == PlayerStateType.Addicted)
  414. return ChangePlayerStateInOneThread(runningState, value, gameObj);
  415. else if (value == PlayerStateType.Null || value == PlayerStateType.Deceased)
  416. return ChangePlayerState(runningState, value, gameObj);
  417. else return -1;
  418. case PlayerStateType.TryingToAttack:
  419. if (value == PlayerStateType.Addicted || value == PlayerStateType.Swinging
  420. || value == PlayerStateType.Deceased || value == PlayerStateType.Stunned
  421. || value == PlayerStateType.Charmed || value == PlayerStateType.Null)
  422. return ChangePlayerState(runningState, value, gameObj);
  423. else return -1;
  424. case PlayerStateType.Stunned:
  425. case PlayerStateType.Charmed:
  426. if (value == PlayerStateType.Addicted || value == PlayerStateType.Deceased
  427. || value == PlayerStateType.Null)
  428. return ChangePlayerState(runningState, value, gameObj);
  429. else return -1;
  430. case PlayerStateType.Swinging:
  431. if (value == PlayerStateType.Addicted
  432. || value == PlayerStateType.Deceased || value == PlayerStateType.Stunned
  433. || value == PlayerStateType.Charmed || value == PlayerStateType.Null)
  434. return ChangePlayerState(runningState, value, gameObj);
  435. else return -1;
  436. case PlayerStateType.ClimbingThroughWindows:
  437. if (value == PlayerStateType.Addicted
  438. || value == PlayerStateType.Deceased || value == PlayerStateType.Stunned
  439. || value == PlayerStateType.Charmed || value == PlayerStateType.Null)
  440. {
  441. Window window = (Window)lastObj!;
  442. if (window.Stage.x != 0) ReSetPos(window.Stage);
  443. window.FinishClimbing();
  444. return ChangePlayerState(runningState, value, gameObj);
  445. }
  446. else return -1;
  447. case PlayerStateType.OpeningTheChest:
  448. if (value == PlayerStateType.Rescued) return -1;
  449. ((Chest)lastObj!).StopOpen();
  450. return ChangePlayerState(runningState, value, gameObj);
  451. case PlayerStateType.OpeningTheDoorway:
  452. if (value == PlayerStateType.Rescued) return -1;
  453. Doorway doorway = (Doorway)lastObj!;
  454. doorway.StopOpenning();
  455. return ChangePlayerState(runningState, value, gameObj);
  456. case PlayerStateType.OpeningTheDoor:
  457. if (value == PlayerStateType.Rescued) return -1;
  458. Door door = (Door)lastObj!;
  459. door.StopOpen();
  460. ReleaseTool(door.DoorNum switch
  461. {
  462. 3 => PropType.Key3,
  463. 5 => PropType.Key5,
  464. _ => PropType.Key6,
  465. }
  466. );
  467. return ChangePlayerState(runningState, value, gameObj);
  468. case PlayerStateType.UsingSkill:
  469. {
  470. if (value == PlayerStateType.Rescued) return -1;
  471. switch (CharacterType)
  472. {
  473. case CharacterType.TechOtaku:
  474. {
  475. if (typeof(CraftingBench).IsInstanceOfType(lastObj))
  476. {
  477. ((CraftingBench)lastObj!).StopSkill();
  478. return ChangePlayerState(runningState, value, gameObj);
  479. }
  480. else
  481. {
  482. if (value != PlayerStateType.UsingSkill)
  483. ((UseRobot)FindActiveSkill(ActiveSkillType.UseRobot)).NowPlayerID = (int)playerID;
  484. return ChangePlayerState(runningState, value, gameObj);
  485. }
  486. }
  487. case CharacterType.Assassin:
  488. if (value == PlayerStateType.Moving) return StateNum;
  489. else
  490. {
  491. TryDeleteInvisible();
  492. return ChangePlayerState(runningState, value, gameObj);
  493. }
  494. default:
  495. return ChangePlayerState(runningState, value, gameObj);
  496. }
  497. }
  498. default:
  499. if (value == PlayerStateType.Rescued) return -1;
  500. return ChangePlayerState(runningState, value, gameObj);
  501. }
  502. }
  503. }
  504. public long SetPlayerStateNaturally()
  505. {
  506. lock (actionLock)
  507. {
  508. runningState = RunningStateType.Null;
  509. whatInteractingWith = null;
  510. playerState = PlayerStateType.Null;
  511. return ++stateNum;
  512. }
  513. }
  514. public bool ResetPlayerState(long state, RunningStateType running = RunningStateType.Null, PlayerStateType value = PlayerStateType.Null, IGameObj? obj = null)
  515. {
  516. lock (actionLock)
  517. {
  518. if (state != stateNum) return false;
  519. this.runningState = running;
  520. whatInteractingWith = (GameObj?)obj;
  521. playerState = value;
  522. ++stateNum;
  523. return true;
  524. }
  525. }
  526. public bool ResetPlayerStateInOneThread(long state, RunningStateType running = RunningStateType.Null, PlayerStateType value = PlayerStateType.Null, IGameObj? obj = null)
  527. {
  528. lock (actionLock)
  529. {
  530. if (state != stateNum) return false;
  531. this.runningState = running;
  532. whatInteractingWith = (GameObj?)obj;
  533. playerState = value;
  534. return true;
  535. }
  536. }
  537. public bool StartThread(long stateNum, RunningStateType runningState)
  538. {
  539. lock (ActionLock)
  540. {
  541. if (this.StateNum == stateNum)
  542. {
  543. this.runningState = runningState;
  544. return true;
  545. }
  546. }
  547. return false;
  548. }
  549. public bool TryToRemoveFromGame(PlayerStateType playerStateType)
  550. {
  551. lock (actionLock)
  552. {
  553. if (SetPlayerState(RunningStateType.RunningForcibly, playerStateType) == -1) return false;
  554. TryToRemove();
  555. ReSetCanMove(false);
  556. position = GameData.PosWhoDie;
  557. }
  558. return true;
  559. }
  560. #endregion
  561. private long score = 0;
  562. public long Score
  563. {
  564. get => Interlocked.Read(ref score);
  565. }
  566. /// <summary>
  567. /// 加分
  568. /// </summary>
  569. /// <param name="add">增加量</param>
  570. public virtual void AddScore(long add)
  571. {
  572. Interlocked.Add(ref score, add);
  573. //Debugger.Output(this, " 's score has been added to: " + score.ToString());
  574. }
  575. /// <summary>
  576. /// 角色所属队伍ID
  577. /// </summary>
  578. private long teamID = long.MaxValue;
  579. public long TeamID
  580. {
  581. get => Interlocked.Read(ref teamID);
  582. set => Interlocked.Exchange(ref teamID, value);
  583. }
  584. private long playerID = long.MaxValue;
  585. public long PlayerID
  586. {
  587. get => Interlocked.Read(ref playerID);
  588. set => Interlocked.Exchange(ref playerID, value);
  589. }
  590. #region 道具和buff相关属性、方法
  591. private readonly object inventoryLock = new();
  592. public object InventoryLock => inventoryLock;
  593. private Gadget[] propInventory = new Gadget[GameData.maxNumOfPropInPropInventory]
  594. {new NullProp(), new NullProp(),new NullProp() };
  595. public Gadget[] PropInventory
  596. {
  597. get
  598. {
  599. lock (inventoryLock)
  600. return propInventory;
  601. }
  602. set
  603. {
  604. lock (inventoryLock)
  605. propInventory = value;
  606. }
  607. }
  608. /// <summary>
  609. /// 使用物品栏中的道具
  610. /// </summary>
  611. /// <returns>被使用的道具</returns>
  612. public Gadget ConsumeProp(int indexing)
  613. {
  614. if (indexing < 0 || indexing >= GameData.maxNumOfPropInPropInventory)
  615. return new NullProp();
  616. lock (inventoryLock)
  617. {
  618. Gadget prop = propInventory[indexing];
  619. if (!prop.IsUsable()) return new NullProp();
  620. PropInventory[indexing] = new NullProp();
  621. return prop;
  622. }
  623. }
  624. public Gadget ConsumeProp(PropType propType)
  625. {
  626. if (propType == PropType.Null)
  627. {
  628. lock (inventoryLock)
  629. {
  630. for (int indexing = 0; indexing < GameData.maxNumOfPropInPropInventory; ++indexing)
  631. {
  632. if (PropInventory[indexing].IsUsable())
  633. {
  634. Gadget prop = PropInventory[indexing];
  635. PropInventory[indexing] = new NullProp();
  636. return prop;
  637. }
  638. }
  639. }
  640. }
  641. else
  642. {
  643. lock (inventoryLock)
  644. {
  645. for (int indexing = 0; indexing < GameData.maxNumOfPropInPropInventory; ++indexing)
  646. {
  647. if (PropInventory[indexing].GetPropType() == propType && PropInventory[indexing].IsUsable())
  648. {
  649. Gadget prop = PropInventory[indexing];
  650. PropInventory[indexing] = new NullProp();
  651. return prop;
  652. }
  653. }
  654. }
  655. }
  656. return new NullProp();
  657. }
  658. public bool UseTool(PropType propType)//占用道具,使其不能重复使用和被消耗
  659. {
  660. lock (inventoryLock)
  661. {
  662. for (int indexing = 0; indexing < GameData.maxNumOfPropInPropInventory; ++indexing)
  663. {
  664. if (PropInventory[indexing].GetPropType() == propType && PropInventory[indexing].IsUsable())
  665. {
  666. return ((Tool)PropInventory[indexing]).IsUsed = true;
  667. }
  668. }
  669. }
  670. return false;
  671. }
  672. public void ReleaseTool(PropType propType)
  673. {
  674. lock (inventoryLock)
  675. {
  676. for (int indexing = 0; indexing < GameData.maxNumOfPropInPropInventory; ++indexing)
  677. {
  678. if (PropInventory[indexing].GetPropType() == propType && ((Tool)PropInventory[indexing]).IsUsed)
  679. {
  680. ((Tool)PropInventory[indexing]).IsUsed = false;
  681. break;
  682. }
  683. }
  684. }
  685. }
  686. /// <summary>
  687. /// 如果indexing==GameData.maxNumOfPropInPropInventory表明道具栏为满
  688. /// </summary>
  689. public int IndexingOfAddProp()
  690. {
  691. int indexing = 0;
  692. lock (inventoryLock)
  693. for (; indexing < GameData.maxNumOfPropInPropInventory; ++indexing)
  694. if (propInventory[indexing].GetPropType() == PropType.Null)
  695. break;
  696. return indexing;
  697. }
  698. public void AddMoveSpeed(int buffTime, double add = 1.0) => buffManager.AddMoveSpeed(add, buffTime, newVal =>
  699. { MoveSpeed = newVal < GameData.characterMaxSpeed ? newVal : GameData.characterMaxSpeed; },
  700. OrgMoveSpeed);
  701. public bool HasFasterSpeed => buffManager.HasFasterSpeed;
  702. public void AddShield(int shieldTime) => buffManager.AddShield(shieldTime);
  703. public bool HasShield => buffManager.HasShield;
  704. public void AddLife(int LIFETime) => buffManager.AddLife(LIFETime);
  705. public bool HasLIFE => buffManager.HasLIFE;
  706. public void AddAp(int time) => buffManager.AddAp(time);
  707. public bool HasAp => buffManager.HasAp;
  708. public void AddSpear(int spearTime) => buffManager.AddSpear(spearTime);
  709. public bool HasSpear => buffManager.HasSpear;
  710. public void AddClairaudience(int time) => buffManager.AddClairaudience(time);
  711. public bool HasClairaudience => buffManager.HasClairaudience;
  712. public void AddInvisible(int time) => buffManager.AddInvisible(time);
  713. public bool HasInvisible => buffManager.HasInvisible;
  714. private Array buffTypeArray = Enum.GetValues(typeof(BuffType));
  715. public Dictionary<BuffType, bool> Buff
  716. {
  717. get
  718. {
  719. Dictionary<BuffType, bool> buff = new Dictionary<BuffType, bool>();
  720. foreach (BuffType type in buffTypeArray)
  721. {
  722. if (type != BuffType.Null)
  723. buff.Add(type, GetBuffStatus(type));
  724. }
  725. return buff;
  726. }
  727. }
  728. private bool GetBuffStatus(BuffType type)
  729. {
  730. switch (type)
  731. {
  732. case BuffType.Spear:
  733. return this.HasSpear;
  734. case BuffType.AddSpeed:
  735. return this.HasFasterSpeed;
  736. case BuffType.Shield:
  737. return this.HasShield;
  738. case BuffType.AddLife:
  739. return this.HasLIFE;
  740. case BuffType.AddAp:
  741. return this.HasAp;
  742. case BuffType.Clairaudience:
  743. return this.HasClairaudience;
  744. case BuffType.Invisible:
  745. return this.HasInvisible;
  746. default:
  747. return false;
  748. }
  749. }
  750. public void TryActivatingLIFE()
  751. {
  752. if (buffManager.TryActivatingLIFE())
  753. {
  754. AddScore(GameData.ScorePropRemainHp);
  755. hp = GameData.RemainHpWhenAddLife;
  756. }
  757. }
  758. public bool TryAddAp()
  759. {
  760. if (buffManager.TryAddAp())
  761. {
  762. AddScore(GameData.ScorePropAddAp);
  763. return true;
  764. }
  765. return false;
  766. }
  767. public bool TryUseSpear()
  768. {
  769. return buffManager.TryUseSpear();
  770. }
  771. public bool TryDeleteInvisible()
  772. {
  773. return buffManager.TryDeleteInvisible();
  774. }
  775. public bool TryUseShield()
  776. {
  777. if (buffManager.TryUseShield())
  778. {
  779. AddScore(GameData.ScorePropUseShield);
  780. return true;
  781. }
  782. return false;
  783. }
  784. #endregion
  785. /* public override void Reset() // 要加锁吗?
  786. {
  787. lock (gameObjLock)
  788. {
  789. // _ = AddDeathCount();
  790. base.Reset();
  791. this.MoveSpeed = OrgMoveSpeed;
  792. HP = MaxHp;
  793. PropInventory = null;
  794. BulletOfPlayer = OriBulletOfPlayer;
  795. lock (gameObjLock)
  796. bulletNum = maxBulletNum;
  797. buffManager.ClearAll();
  798. IsInvisible = false;
  799. this.Vampire = this.OriVampire;
  800. }
  801. }*/
  802. public override bool IsRigid => true;
  803. public override ShapeType Shape => ShapeType.Circle;
  804. public override bool IgnoreCollideExecutor(IGameObj targetObj)
  805. {
  806. if (IsRemoved)
  807. return true;
  808. if (targetObj.Type == GameObjType.Gadget)
  809. {
  810. return true;
  811. }
  812. if (targetObj.Type == GameObjType.Character && XY.DistanceCeil3(targetObj.Position, this.Position) < this.Radius + targetObj.Radius - GameData.adjustLength)
  813. return true;
  814. return false;
  815. }
  816. }
  817. }