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

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