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 34 kB

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