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

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