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

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