PlayerController.cs 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using Spine.Unity;
  4. using Sirenix.OdinInspector;
  5. using UnityEngine.InputSystem;
  6. using TMPro;
  7. public enum PlayerAttackState
  8. {
  9. Idle = 0,
  10. WalkForward = 1,
  11. WalkBack = 2,
  12. }
  13. public class PlayerController : MoveCharacter
  14. {
  15. [Header("玩家属性")]
  16. public int playerId;
  17. public Vector2 pos;
  18. public bool canJump;
  19. public Animator aniCollider;
  20. [Header("玩家组件")]
  21. public UIHP uiMp;
  22. private Spirits spirits;
  23. public Collider soulCollector;
  24. public SkeletonMecanim skeletonMecanim;
  25. private SpiritSystem spiritSystem;
  26. private ScreenShake ss;
  27. private ConductController conductController;
  28. [Header("蓝耗")]
  29. public float mp;
  30. public float totalMp;
  31. public float totalMp_2Players; //双人模式下总蓝量
  32. public bool isMpRepel = true;
  33. public bool isRapedReply;
  34. public float mpReplySpeed;
  35. public float mpReplySpeed_2Players; //双人模式下蓝量回复速度
  36. public float rapidReplySpeed;
  37. public float lostMp;
  38. public float addMp = 10;
  39. public GameObject soul;
  40. public GameObject rapidReplyEffect;
  41. [Tooltip("场上每多一个同种类兵种,召唤兵种蓝耗+x")] public float[] addCostMp;
  42. [Header("移动属性")]
  43. public Vector2 moveVec; //玩家不动时移动数据
  44. [HideInInspector]
  45. public Vector2 leftDir;
  46. [Header("冲刺属性")]
  47. public float rushSpeed = 100;
  48. public float rushCostMp = 5;
  49. public Vector3 rushDir;
  50. public float rushInvincibleTime = 0.2f;
  51. [HideInInspector]
  52. public float rushTime;
  53. public float totalRushTime = 0.5f;
  54. [HideInInspector]
  55. public float cacheRushTime; //无法Rush时按下Rush键不会Rush,手感不好,缓存几帧,在这几帧内落地会立即Rush;
  56. public float totalCacheRushTime = 0.1f;
  57. public float sprintCostMp = 5;
  58. [Header("跳跃属性")]
  59. public float jumpSpeed = 10;
  60. public float airJumpSpeed = 10;
  61. public int airJumped;
  62. public int airJumpNumber = 1; //最大跳跃次数
  63. public float canAirJumpSpeed = 5;//y轴速度大于这个值时不能进行空中跳跃
  64. [HideInInspector]
  65. public float canJumpTime; //离开平台后仍然可以跳跃的时间,用于提升手感
  66. public float leaveGroundCanJumpTime = 0.1f;
  67. [HideInInspector]
  68. public float cacheJumpTime; //即将落地时按下跳跃键不会跳跃,手感不好,缓存几帧,在这几帧内落地会立即跳跃;
  69. public float totalCacheJumpTime = 0.1f;
  70. [Header("飞行属性")]
  71. public float flySpeed = 5;
  72. public float playerMaxFlyHeight;
  73. [Header("召唤属性")]
  74. public float totalSummonTime;
  75. [HideInInspector]
  76. public float summonTime;
  77. public float onlySummonTime;
  78. [HideInInspector]
  79. public float restSummonTime;
  80. private SoldierLevelRecord slr;
  81. [HideInInspector]
  82. public float cacheDir; //召唤的时候按左右召唤结束不会响应手感不好,缓存一下,召唤后摇期间有左右响应的话会转向
  83. [HideInInspector]
  84. public bool cacheRush; //召唤的时候按冲刺结束不会响应手感不好,缓存一下,召唤后摇期间按下冲刺的话会冲刺
  85. [HideInInspector]
  86. public float cacheSummonTime; //无法召唤时按下召唤键不会召唤,手感不好,缓存几帧,在这几帧内落地会立即召唤;
  87. [HideInInspector]
  88. public int cacheSummonId;
  89. [Header("召唤使魔")]
  90. public TextMeshProUGUI[] demonicNums;
  91. public GameObject[] cannotConductFXs;
  92. public List<GameObject> demonicPrefabs;
  93. public List<Vector3> demonicSummonPos;
  94. public Dictionary<int, List<Demonic>> demonicDic; //0:弓兵,1:胖子,2:棒子,3:融合后的弓兵,4:融合后的胖子,5:融合后的棒子
  95. [LabelText("动作结束后无敌帧时间")] public float addSummonInvincibleTime = 0.1f;
  96. [Header("攻击")]
  97. public PlayerAttackState attackState;
  98. public float attackMoveSpeed = 5f;
  99. [HideInInspector]
  100. public float cacheAttackTime; //无法攻击时按下攻击键不会攻击,手感不好,缓存几帧,在这几帧内落地会立即攻击;
  101. public float totalCacheAttackTime = 0.1f;
  102. [Header("复活")]
  103. public float reviveTime; //复活时间
  104. public float totalReviveTime;
  105. [Header("锁魂塔")]
  106. public GameObject curSoulTower;
  107. //指挥功能
  108. private float conductTime; //指挥按键长按时间
  109. private int nowConductButton = -1; //现在按下的指挥键(0.J/1.K/2.L/-1.无)
  110. private int cacheConductId;
  111. [Header("召唤相应时间")] [Tooltip("在此时间内松手为召唤")] public float totalCacheSummonTime;
  112. [Header("融魂相应时间")] [Tooltip("在此时间以外松手为融魂")] public float[] canConductTime;
  113. public bool[] conductCanRelease; //能否进入指挥技蓄力状态
  114. public ConductReadyTip conductReadyTip; //指挥技就绪
  115. private bool isReadyConduct;
  116. [Header("时间倍率")] [Tooltip("时间速度放慢到正常的几倍")] public float timeSlowingMultiplier;
  117. [DisplayOnly]public float fixedDeltaTime;
  118. public float readyTipFxTime;
  119. //攻击力
  120. [Header("增加攻击力特效")]
  121. public GameObject attackEffect;
  122. [Header("攻击力献祭比例")]
  123. public float addRate;
  124. //泰山压顶
  125. [Header("泰山压顶")]
  126. public GameObject mountain;
  127. public Vector3 mountainOffset;
  128. public float largeX;
  129. //气功波
  130. public GameObject wavePowerObj;
  131. [Header("气功波伤害基数")] public int wavePowerDamage;
  132. //御剑术
  133. public GameObject flyingSwordsObj;
  134. //怨气弹
  135. public GameObject angryBulletObj;
  136. [Header("怨气弹数量基数")] public int angryBulletNum;
  137. public bool btnJumpPress
  138. {
  139. get
  140. {
  141. //return Input.GetKeyDown(KeyCode.Space) || isClickBtnJump;
  142. return isClickBtnJump;
  143. }
  144. }
  145. [HideInInspector]
  146. public bool isClickBtnJump;
  147. public bool btnRushPress
  148. {
  149. get
  150. {
  151. //return Input.GetKeyDown(KeyCode.LeftShift) || isClickBtnRush;
  152. return isClickBtnRush;
  153. }
  154. }
  155. [HideInInspector]
  156. public bool isClickBtnRush;
  157. public bool btnRushKeep
  158. {
  159. get
  160. {
  161. //return Input.GetKey(KeyCode.LeftShift) || isKeepBtnRush;
  162. return LBisHold || isKeepBtnRush;
  163. }
  164. }
  165. [HideInInspector]
  166. public bool isKeepBtnRush;
  167. public bool btnEastPress
  168. {
  169. get
  170. {
  171. return isClickBtnEast;
  172. }
  173. }
  174. [HideInInspector]
  175. public bool isClickBtnEast;
  176. public bool btnEastUp
  177. {
  178. get
  179. {
  180. return isBtnEastUp;
  181. }
  182. }
  183. [HideInInspector]
  184. public bool isBtnEastUp;
  185. public bool btnSouthPress
  186. {
  187. get
  188. {
  189. //return Input.GetKeyDown(KeyCode.K) || isClickBtnSouth;
  190. return isClickBtnSouth;
  191. }
  192. }
  193. [HideInInspector]
  194. public bool isClickBtnSouth;
  195. public bool btnSouthUp
  196. {
  197. get
  198. {
  199. //return Input.GetKeyDown(KeyCode.K) || isClickBtnSouth;
  200. return isBtnSouthUp;
  201. }
  202. }
  203. [HideInInspector]
  204. public bool isBtnSouthUp;
  205. public bool btnWestPress
  206. {
  207. get
  208. {
  209. return isClickBtnWest;
  210. }
  211. }
  212. [HideInInspector]
  213. public bool isClickBtnWest;
  214. public bool btnWestUp
  215. {
  216. get
  217. {
  218. return isBtnWestUp;
  219. }
  220. }
  221. [HideInInspector]
  222. public bool isBtnWestUp;
  223. public bool btnNorthPress
  224. {
  225. get
  226. {
  227. return isClickBtnNorth;
  228. }
  229. }
  230. [HideInInspector]
  231. public bool isClickBtnNorth;
  232. public bool btnNorthUp
  233. {
  234. get
  235. {
  236. return isBtnNorthUp;
  237. }
  238. }
  239. [HideInInspector]
  240. public bool isBtnNorthUp;
  241. public bool btnSpiritSummon
  242. {
  243. get
  244. {
  245. //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
  246. return isSpiritSummon;
  247. }
  248. }
  249. [HideInInspector]
  250. public bool isSpiritSummon;
  251. public bool btnSpiritSummon1
  252. {
  253. get
  254. {
  255. //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
  256. return isSpiritSummon1;
  257. }
  258. }
  259. [HideInInspector]
  260. public bool isSpiritSummon1;
  261. public bool btnSpiritSummon2
  262. {
  263. get
  264. {
  265. //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
  266. return isSpiritSummon2;
  267. }
  268. }
  269. [HideInInspector]
  270. public bool isSpiritSummon2;
  271. public bool btnSpiritSummon3
  272. {
  273. get
  274. {
  275. //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
  276. return isSpiritSummon3;
  277. }
  278. }
  279. [HideInInspector]
  280. public bool isSpiritSummon3;
  281. public bool btnNorthKeep
  282. {
  283. get
  284. {
  285. //return Input.GetKey(KeyCode.I) || isKeepBtnNorth;
  286. return isKeepBtnNorth;
  287. }
  288. }
  289. [HideInInspector]
  290. public bool isKeepBtnNorth;
  291. public override void Init()
  292. {
  293. base.Init();
  294. uiHp = GameManager.instance.p1uiHP;
  295. uiMp = GameManager.instance.p1uiMP;
  296. uiMp.pc = this;
  297. mp = totalMp;
  298. uiMp.Show(mp, totalMp);
  299. demonicNums = new TextMeshProUGUI[3];
  300. for (int i = 0; i < 3; i++)
  301. {
  302. demonicNums[i] = GameManager.instance.demonicNum[i].GetComponentInChildren<TextMeshProUGUI>();
  303. }
  304. cannotConductFXs = new GameObject[3];
  305. for (int i = 0; i < 3; i++)
  306. {
  307. cannotConductFXs[i] = GameManager.instance.demonicNum[i].transform.GetChild(3).gameObject;
  308. }
  309. }
  310. public override void Awake()
  311. {
  312. base.Awake();
  313. PlayerInput playerInput = transform.GetComponent<PlayerInput>();
  314. ss = Camera.main.GetComponentInParent<ScreenShake>();
  315. spirits = GetComponent<Spirits>();
  316. conductController = GetComponent<ConductController>();
  317. playerId = playerInput.playerIndex;
  318. transform.position = new Vector3(pos.x, pos.y, 0);
  319. switch (playerId)
  320. {
  321. case 0:
  322. PlayersInput.instance[0] = this;
  323. PlayersInput.instance[1] = this;
  324. SpiritSystem.isP1Out = true;
  325. SpiritSystem.isP1In = false;
  326. SpiritSystem.player1 = gameObject;
  327. SpiritSystem.p1Spirits = GetComponent<Spirits>();
  328. break;
  329. case 1:
  330. PlayersInput.instance[1] = this;
  331. SpiritSystem.isP2Out = true;
  332. SpiritSystem.isP2In = false;
  333. SpiritSystem.player2 = gameObject;
  334. SpiritSystem.p2Spirits = GetComponent<Spirits>();
  335. //切换为双人计算蓝量方式
  336. PlayerController p1 = PlayersInput.instance[0];
  337. mpReplySpeed = mpReplySpeed_2Players;
  338. p1.mpReplySpeed = mpReplySpeed_2Players;
  339. totalMp = totalMp_2Players;
  340. p1.totalMp = totalMp_2Players;
  341. if (mp > totalMp)
  342. {
  343. mp = totalMp;
  344. }
  345. if (p1.mp > totalMp)
  346. {
  347. p1.mp = totalMp;
  348. }
  349. uiMp.Show(mp, totalMp);
  350. p1.uiMp.Show(p1.mp, totalMp);
  351. break;
  352. default:
  353. break;
  354. }
  355. demonicDic = new Dictionary<int, List<Demonic>>();
  356. for (int i = 0; i < 5; i++)
  357. {
  358. demonicDic.Add(i, new List<Demonic>());
  359. }
  360. Init();
  361. spiritSystem = GameObject.Find("SpiritSystem").GetComponent<SpiritSystem>();
  362. fixedDeltaTime = Time.fixedDeltaTime;
  363. }
  364. private void Start()
  365. {
  366. slr = GameManager.instance.GetComponent<SoldierLevelRecord>();
  367. }
  368. override public void Update()
  369. {
  370. if (LBisHold)
  371. {
  372. isKeepBtnRush = true;
  373. }
  374. }
  375. void OnSprintingPress()
  376. {
  377. LBisHold = true;
  378. isClickBtnRush = true;
  379. isKeepBtnRush = true;
  380. }
  381. void OnSprintingRelease()
  382. {
  383. LBisHold = false;
  384. }
  385. //手柄按下LB
  386. [HideInInspector]
  387. public bool LBisHold;
  388. //读取手柄参数
  389. private void OnMove(InputValue value)
  390. {
  391. leftDir = value.Get<Vector2>();
  392. moveVec = value.Get<Vector2>();
  393. }
  394. void OnJump()
  395. {
  396. if (canJump)
  397. {
  398. isClickBtnJump = true;
  399. }
  400. }
  401. void OnSummon0()
  402. {
  403. if (nowConductButton == -1)
  404. {
  405. isClickBtnWest = true;
  406. nowConductButton = 0;
  407. conductTime = 0;
  408. }
  409. }
  410. void OnSummon0Up()
  411. {
  412. if (nowConductButton == 0)
  413. {
  414. isBtnWestUp = true;
  415. cacheConductId = nowConductButton;
  416. nowConductButton = -1;
  417. }
  418. }
  419. void OnSummon1()
  420. {
  421. if (nowConductButton == -1)
  422. {
  423. isClickBtnSouth = true;
  424. nowConductButton = 1;
  425. conductTime = 0;
  426. }
  427. }
  428. void OnSummon1Up()
  429. {
  430. if (nowConductButton == 1)
  431. {
  432. isBtnSouthUp = true;
  433. cacheConductId = nowConductButton;
  434. nowConductButton = -1;
  435. }
  436. }
  437. void OnSummon2()
  438. {
  439. if (nowConductButton == -1)
  440. {
  441. isClickBtnEast = true;
  442. nowConductButton = 2;
  443. conductTime = 0;
  444. }
  445. }
  446. void OnSummon2Up()
  447. {
  448. if (nowConductButton == 2)
  449. {
  450. isBtnEastUp = true;
  451. cacheConductId = nowConductButton;
  452. nowConductButton = -1;
  453. }
  454. }
  455. //选英灵 (手柄右扳机,键盘TAB)
  456. void OnChooseSpirit()
  457. {
  458. switch (playerId)
  459. {
  460. case 0:
  461. SpiritSystem.isP1CardChangeR = true;
  462. break;
  463. case 1:
  464. SpiritSystem.isP2CardChangeR = true;
  465. break;
  466. default:
  467. break;
  468. }
  469. }
  470. public void Jump()
  471. {
  472. SetUpSpeed(jumpSpeed);
  473. ani.Play("jump", 0, 0);
  474. }
  475. public void AirJump()
  476. {
  477. ChangeState(CharacterState.Rise);
  478. SetUpSpeed(airJumpSpeed);
  479. ani.Play("jump_air", 0, 0);
  480. }
  481. public void SetUpSpeed(float speed)
  482. {
  483. ChangeState(CharacterState.Rise);
  484. Vector3 velocity = rb.velocity;
  485. CheckTurn();
  486. velocity.y = speed;
  487. rb.velocity = velocity;
  488. //animalAni.SetInteger("state", (int)PlayerState.Rise);
  489. }
  490. public bool CheckSummon()
  491. {
  492. if (restSummonTime > 0)
  493. {
  494. return false;
  495. }
  496. if (state != CharacterState.Conduct && nowConductButton != -1 && conductTime > totalCacheSummonTime)
  497. {
  498. CheckTurn();
  499. if (conductCanRelease[nowConductButton])
  500. {
  501. ChangeState(CharacterState.Conduct);
  502. return true;
  503. }
  504. return false;
  505. }
  506. if (isBtnEastUp || isBtnWestUp || isBtnSouthUp)
  507. {
  508. if (cacheSummonTime >= 0 && conductTime <= totalCacheSummonTime)
  509. {
  510. CheckTurn();
  511. if (!CheckCanSummon(cacheSummonId))
  512. {
  513. return false;
  514. }
  515. Summon(cacheSummonId);
  516. return true;
  517. }
  518. }
  519. return false;
  520. }
  521. public bool CheckConduct()
  522. {
  523. if (isBtnEastUp || isBtnWestUp || isBtnSouthUp)
  524. {
  525. if (isReadyConduct)
  526. {
  527. conductController.Conduct(cacheConductId);
  528. }
  529. isReadyConduct = false;
  530. return true;
  531. }
  532. if (!isReadyConduct && nowConductButton != -1)
  533. {
  534. if (conductTime >= canConductTime[nowConductButton] * timeSlowingMultiplier)
  535. {
  536. isReadyConduct = true;
  537. if (!conductReadyTip.isShowing1 && !conductReadyTip.isShowingNoDemonic)
  538. {
  539. int boostNum = demonicDic[nowConductButton].Count;
  540. int dienum = (int)(boostNum * conductController.conversionRate[nowConductButton] + 0.5f);
  541. if (boostNum == 1)
  542. {
  543. dienum = 1;
  544. }
  545. if (dienum > 0)
  546. {
  547. conductReadyTip.Show(1);
  548. }
  549. else
  550. {
  551. conductReadyTip.Show(3, nowConductButton);
  552. }
  553. }
  554. }
  555. else if (conductTime >= (canConductTime[nowConductButton] - readyTipFxTime) * timeSlowingMultiplier)
  556. {
  557. if (!conductReadyTip.isShowing0 && !conductReadyTip.isShowingNoDemonic)
  558. {
  559. int boostNum = demonicDic[nowConductButton].Count;
  560. int dienum = (int)(boostNum * conductController.conversionRate[nowConductButton] + 0.5f);
  561. if (boostNum == 1)
  562. {
  563. dienum = 1;
  564. }
  565. if (dienum > 0)
  566. {
  567. conductReadyTip.Show(0);
  568. }
  569. else
  570. {
  571. conductReadyTip.Show(2, nowConductButton);
  572. }
  573. }
  574. }
  575. else
  576. {
  577. if (Time.timeScale == 1)
  578. {
  579. Time.timeScale = timeSlowingMultiplier;
  580. Time.fixedDeltaTime = fixedDeltaTime * Time.timeScale;
  581. int boostNum = demonicDic[nowConductButton].Count;
  582. int dienum = (int)(boostNum * conductController.conversionRate[nowConductButton] + 0.5f);
  583. if (boostNum == 1)
  584. {
  585. dienum = 1;
  586. }
  587. if (dienum == 0)
  588. {
  589. conductReadyTip.Show(2, nowConductButton);
  590. CannotConductFX(nowConductButton);
  591. }
  592. }
  593. conductReadyTip.Init();
  594. }
  595. }
  596. return false;
  597. }
  598. public void Conduct()
  599. {
  600. //switch (conductSkills[cacheConductId])
  601. //{
  602. // //巨人
  603. // case ConductSkills.AddAttack:
  604. // List<Demonic> newGiants = new List<Demonic>();
  605. // foreach (Demonic d in demonicDic[cacheConductId])
  606. // {
  607. // if (!d.isDie)
  608. // {
  609. // newGiants.Add(d);
  610. // if (d.attackController.addAttackEffect == null)
  611. // {
  612. // d.attackController.addAttackEffect = Instantiate(attackEffect, d.bodyTrans.position, new Quaternion(0, 0, 0, 0), d.bodyTrans);
  613. // }
  614. // d.attackController.addAttackEffect.transform.GetChild(0).gameObject.SetActive(true);
  615. // }
  616. // }
  617. // foreach (Demonic d in newGiants)
  618. // {
  619. // int damage = d.attackController.curDamage;
  620. // d.attackController.curDamage += (int)(addRate * boostNum * damage);
  621. // }
  622. // break;
  623. // //气功师
  624. // case ConductSkills.Mountain:
  625. // conductCanRelease[cacheConductId] = false;
  626. // GameObject curMountain = Instantiate(mountain, null);
  627. // Vector3 moffset = mountainOffset;
  628. // Vector3 sc = curMountain.transform.localScale;
  629. // sc.x = largeX * dienum;
  630. // curMountain.transform.localScale = sc;
  631. // if (bodyTrans.localScale.x < 0)
  632. // {
  633. // moffset.x = mountainOffset.x + sc.x / 2;
  634. // }
  635. // else
  636. // {
  637. // moffset.x = -mountainOffset.x - sc.x / 2;
  638. // }
  639. // Mountain MT = curMountain.GetComponent<Mountain>();
  640. // curMountain.transform.position = transform.position + moffset;
  641. // MT.pc = this;
  642. // MT.id = cacheConductId;
  643. // MT.demonicNum = boostNum;
  644. // break;
  645. // case ConductSkills.WavePower:
  646. // rb.constraints = RigidbodyConstraints.FreezeAll;
  647. // rb.useGravity = false;
  648. // conductCanRelease[cacheConductId] = false;
  649. // obj = Instantiate(wavePowerObj, transform);
  650. // obj.transform.position = transform.position + Vector3.up;
  651. // WavePowerSkill wps = obj.GetComponent<WavePowerSkill>();
  652. // wps.continueTime = wps.singleTime * dienum;
  653. // wps.longFX = (int)bodyTrans.localScale.x;
  654. // wps.damage = wavePowerDamage * boostNum;
  655. // wps.cacheID = cacheConductId;
  656. // wps.pc = this;
  657. // break;
  658. // case ConductSkills.SwordsControl:
  659. // conductCanRelease[cacheConductId] = false;
  660. // obj = Instantiate(flyingSwordsObj, transform);
  661. // obj.transform.position = transform.position + Vector3.up;
  662. // SwordsControl swordsControl = obj.GetComponentInChildren<SwordsControl>();
  663. // swordsControl.owner = this;
  664. // swordsControl.conductId = cacheConductId;
  665. // swordsControl.boostNum = boostNum;
  666. // break;
  667. // //弓箭手
  668. // case ConductSkills.AngryBullet:
  669. // conductCanRelease[cacheConductId] = false;
  670. // obj = Instantiate(angryBulletObj);
  671. // AngryBulletControl angryBulletControl = obj.GetComponent<AngryBulletControl>();
  672. // angryBulletControl.playerController = this;
  673. // angryBulletControl.cacheConductId = cacheConductId;
  674. // angryBulletControl.maxNum = boostNum * angryBulletNum;
  675. // break;
  676. // case ConductSkills.FlyingSwords:
  677. // obj = Instantiate(fanFlyingSwords);
  678. // FanFlyingSwords FFS = obj.GetComponent<FanFlyingSwords>();
  679. // FFS.owner = this;
  680. // FFS.angleRange = flyingSwordsAngleRange;
  681. // FFS.arrivalAngle = flyintSwordsArrivalAngle;
  682. // FFS.swordsNum = boostNum * flyingSwordsNum;
  683. // FFS.Biu();
  684. // break;
  685. //}
  686. }
  687. private int cannotConductfx;
  688. private void CannotConductFX(int id)
  689. {
  690. cannotConductfx = id;
  691. cannotConductFXs[id].SetActive(true);
  692. Invoke("CannotConductFXFade", 0.2f);
  693. }
  694. private void CannotConductFXFade()
  695. {
  696. cannotConductFXs[cannotConductfx].SetActive(false);
  697. }
  698. //角色处于可自由活动状态时的通用切换状态逻辑,如Idle、Run状态,以及别的状态结束时准备回到Idle状态前
  699. public bool CheckPlayerChangeState(CharacterState excludeState = CharacterState.None)
  700. {
  701. if (!foot.TrigGround)
  702. {
  703. if (excludeState != CharacterState.Summon)
  704. {
  705. if (CheckSummon())
  706. {
  707. return true;
  708. }
  709. }
  710. if ((btnRushPress || cacheRushTime > 0 || cacheRush) && mp >= rushCostMp)
  711. {
  712. if (excludeState != CharacterState.Rush)
  713. {
  714. restSummonTime = 0;
  715. summonTime = 0;
  716. cacheRush = false;
  717. ChangeState(CharacterState.Rush);
  718. return true;
  719. }
  720. }
  721. if (rb.velocity.y > 0)
  722. {
  723. if (excludeState != CharacterState.Rise && restSummonTime <= 0)
  724. {
  725. summonTime = 0;
  726. ChangeState(CharacterState.Rise);
  727. return true;
  728. }
  729. }
  730. else
  731. {
  732. if (excludeState != CharacterState.Fall && restSummonTime <= 0)
  733. {
  734. summonTime = 0;
  735. ChangeState(CharacterState.Fall);
  736. return true;
  737. }
  738. }
  739. }
  740. else
  741. {
  742. airJumped = 0;
  743. if (CheckSummon())
  744. {
  745. if (excludeState == CharacterState.Summon)
  746. {
  747. if (foot.TrigGround)
  748. {
  749. ani.Play("summon", 0, 0);
  750. }
  751. else
  752. {
  753. ani.Play("summon_air", 0, 0);
  754. }
  755. }
  756. return true;
  757. }
  758. if ((btnRushPress || cacheRushTime > 0 || cacheRush) && mp >= rushCostMp)
  759. {
  760. if (excludeState != CharacterState.Rush)
  761. {
  762. restSummonTime = 0;
  763. summonTime = 0;
  764. cacheRush = false;
  765. ChangeState(CharacterState.Rush);
  766. return true;
  767. }
  768. }
  769. if (btnJumpPress || cacheJumpTime > 0)
  770. {
  771. if (excludeState != CharacterState.Rise && restSummonTime <= 0)
  772. {
  773. summonTime = 0;
  774. Jump();
  775. ChangeState(CharacterState.Rise);
  776. return true;
  777. }
  778. }
  779. if (leftDir.y < -0.5)
  780. {
  781. Platform platform = foot.trigGroundList[0].GetComponent<Platform>();
  782. if (platform != null && platform.canDown)
  783. {
  784. foot.trigGroundList.Remove(platform.gameObject);
  785. }
  786. }
  787. if (canFly)
  788. {
  789. if (leftDir.x > 0.3f || leftDir.x < -0.3f || leftDir.y > 0.3f || leftDir.y < -0.3f)
  790. {
  791. if (excludeState != CharacterState.Run && restSummonTime <= 0)
  792. {
  793. summonTime = 0;
  794. ChangeState(CharacterState.Run);
  795. return true;
  796. }
  797. }
  798. else
  799. {
  800. if (excludeState != CharacterState.Idle && summonTime <= 0)
  801. {
  802. ChangeState(CharacterState.Idle);
  803. return true;
  804. }
  805. }
  806. }
  807. else
  808. {
  809. if (leftDir.x > 0.3f || leftDir.x < -0.3f)
  810. {
  811. if (excludeState != CharacterState.Run && restSummonTime <= 0)
  812. {
  813. summonTime = 0;
  814. ChangeState(CharacterState.Run);
  815. return true;
  816. }
  817. }
  818. else
  819. {
  820. if (excludeState != CharacterState.Idle && summonTime <= 0)
  821. {
  822. ChangeState(CharacterState.Idle);
  823. return true;
  824. }
  825. }
  826. }
  827. }
  828. return false;
  829. }
  830. public override Vector3 GetMoveDir()
  831. {
  832. return leftDir;
  833. }
  834. public void CachedPlayerInput()
  835. {
  836. if (btnRushPress)
  837. {
  838. cacheRushTime = totalCacheRushTime;
  839. }
  840. if (btnJumpPress)
  841. {
  842. cacheJumpTime = totalCacheJumpTime;
  843. }
  844. if (btnNorthPress)
  845. {
  846. cacheAttackTime = totalCacheAttackTime;
  847. }
  848. if (btnWestPress)
  849. {
  850. cacheSummonTime = totalCacheSummonTime;
  851. cacheSummonId = 0;
  852. }
  853. if (btnSouthPress)
  854. {
  855. cacheSummonTime = totalCacheSummonTime;
  856. cacheSummonId = 1;
  857. }
  858. if (btnEastPress)
  859. {
  860. cacheSummonTime = totalCacheSummonTime;
  861. cacheSummonId = 2;
  862. }
  863. //if (btnSpiritSummon)
  864. //{
  865. // cacheSummonTime = totalCacheSummonTime;
  866. // cacheSummonId = 3;
  867. //}
  868. //if (btnSpiritSummon1)
  869. //{
  870. // cacheSummonTime = totalCacheSummonTime;
  871. // cacheSummonId = 4;
  872. //}
  873. //if (btnSpiritSummon2)
  874. //{
  875. // cacheSummonTime = totalCacheSummonTime;
  876. // cacheSummonId = 5;
  877. //}
  878. //if (btnSpiritSummon3)
  879. //{
  880. // cacheSummonTime = totalCacheSummonTime;
  881. // cacheSummonId = 6;
  882. //}
  883. }
  884. public override void OnState()
  885. {
  886. base.OnState();
  887. if(state == CharacterState.None)
  888. {
  889. return;
  890. }
  891. cacheJumpTime -= Time.deltaTime;
  892. cacheSummonTime -= Time.deltaTime;
  893. canJumpTime -= Time.deltaTime;
  894. invincibleTime -= Time.deltaTime;
  895. summonTime -= Time.deltaTime;
  896. restSummonTime -= Time.deltaTime;
  897. rushTime -= Time.deltaTime;
  898. cacheRushTime -= Time.deltaTime;
  899. dieKeepTime -= Time.deltaTime;
  900. if (nowConductButton != -1)
  901. {
  902. conductTime += Time.deltaTime;
  903. }
  904. CachedPlayerInput();
  905. Vector3 velocity = rb.velocity;
  906. switch (state)
  907. {
  908. case CharacterState.Idle:
  909. if (CheckPlayerChangeState(CharacterState.Idle))
  910. {
  911. break;
  912. }
  913. rb.velocity = Vector3.right * velocityAddition;
  914. break;
  915. case CharacterState.Run:
  916. if (CheckPlayerChangeState(CharacterState.Run))
  917. {
  918. break;
  919. }
  920. CheckTurn();
  921. if (canFly)
  922. {
  923. rb.velocity = leftDir.normalized * moveSpeed;
  924. }
  925. else
  926. {
  927. if (leftDir.x > 0.3f)
  928. {
  929. rb.velocity = new Vector3(moveSpeed + velocityAddition, 0, 0);
  930. }
  931. else if (leftDir.x < -0.3f)
  932. {
  933. rb.velocity = new Vector3(-moveSpeed + velocityAddition, 0, 0);
  934. }
  935. }
  936. break;
  937. case CharacterState.Rise:
  938. if (CheckSummon())
  939. {
  940. break;
  941. }
  942. if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
  943. {
  944. ChangeState(CharacterState.Rush);
  945. break;
  946. }
  947. if (btnJumpPress || cacheJumpTime > 0)
  948. {
  949. if (airJumped < airJumpNumber && rb.velocity.y < canAirJumpSpeed)
  950. {
  951. airJumped++;
  952. AirJump();
  953. break;
  954. }
  955. }
  956. rb.velocity = AirMove(rb.velocity);
  957. if (rb.velocity.y <= 0)
  958. {
  959. ChangeState(CharacterState.Fall);
  960. break;
  961. }
  962. break;
  963. case CharacterState.Fall:
  964. if (CheckSummon())
  965. {
  966. break;
  967. }
  968. if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
  969. {
  970. ChangeState(CharacterState.Rush);
  971. break;
  972. }
  973. if (foot.TrigGround)
  974. {
  975. if (CheckPlayerChangeState(CharacterState.Fall))
  976. {
  977. break;
  978. }
  979. }
  980. if (btnJumpPress || cacheJumpTime > 0)
  981. {
  982. if (canJumpTime > 0)
  983. {
  984. AirJump();
  985. break;
  986. }
  987. else
  988. {
  989. if (airJumped < airJumpNumber)
  990. {
  991. airJumped++;
  992. AirJump();
  993. break;
  994. }
  995. }
  996. }
  997. rb.velocity = AirMove(rb.velocity);
  998. break;
  999. case CharacterState.Attack:
  1000. if (attackController.attackTime <= 0)
  1001. {
  1002. if (btnNorthKeep)
  1003. {
  1004. ChangeState(CharacterState.KeepAttack);
  1005. break;
  1006. }
  1007. if (CheckPlayerChangeState(CharacterState.Attack))
  1008. {
  1009. break;
  1010. }
  1011. }
  1012. break;
  1013. case CharacterState.KeepAttack:
  1014. if ((btnRushPress) && mp >= rushCostMp)
  1015. {
  1016. ChangeState(CharacterState.Rush);
  1017. break;
  1018. }
  1019. if (btnJumpPress && canJumpTime > 0)
  1020. {
  1021. AirJump();
  1022. break;
  1023. }
  1024. if (!btnNorthKeep)
  1025. {
  1026. if (CheckPlayerChangeState(CharacterState.KeepAttack))
  1027. {
  1028. break;
  1029. }
  1030. }
  1031. switch (attackState)
  1032. {
  1033. case PlayerAttackState.Idle:
  1034. if (bodyTrans.localScale.x > 0)
  1035. {
  1036. if (leftDir.x > 0.3f)
  1037. {
  1038. SetAttackState(PlayerAttackState.WalkBack);
  1039. velocity.x = attackMoveSpeed;
  1040. rb.velocity = velocity;
  1041. break;
  1042. }
  1043. else if (leftDir.x < -0.3f)
  1044. {
  1045. SetAttackState(PlayerAttackState.WalkForward);
  1046. velocity.x = -attackMoveSpeed;
  1047. rb.velocity = velocity;
  1048. break;
  1049. }
  1050. }
  1051. else
  1052. {
  1053. if (leftDir.x > 0.3f)
  1054. {
  1055. SetAttackState(PlayerAttackState.WalkForward);
  1056. velocity.x = attackMoveSpeed;
  1057. rb.velocity = velocity;
  1058. break;
  1059. }
  1060. else if (leftDir.x < -0.3f)
  1061. {
  1062. SetAttackState(PlayerAttackState.WalkBack);
  1063. velocity.x = -attackMoveSpeed;
  1064. rb.velocity = velocity;
  1065. break;
  1066. }
  1067. }
  1068. velocity.x = 0;
  1069. rb.velocity = velocity;
  1070. break;
  1071. case PlayerAttackState.WalkForward:
  1072. if (bodyTrans.localScale.x > 0)
  1073. {
  1074. if (leftDir.x > 0.3f)
  1075. {
  1076. SetAttackState(PlayerAttackState.WalkBack);
  1077. velocity.x = attackMoveSpeed;
  1078. rb.velocity = velocity;
  1079. break;
  1080. }
  1081. else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
  1082. {
  1083. SetAttackState(PlayerAttackState.Idle);
  1084. velocity.x = 0;
  1085. rb.velocity = velocity;
  1086. break;
  1087. }
  1088. else
  1089. {
  1090. velocity.x = -attackMoveSpeed;
  1091. rb.velocity = velocity;
  1092. }
  1093. }
  1094. else
  1095. {
  1096. if (leftDir.x < -0.3f)
  1097. {
  1098. SetAttackState(PlayerAttackState.WalkBack);
  1099. velocity.x = -attackMoveSpeed;
  1100. rb.velocity = velocity;
  1101. break;
  1102. }
  1103. else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
  1104. {
  1105. SetAttackState(PlayerAttackState.Idle);
  1106. velocity.x = 0;
  1107. rb.velocity = velocity;
  1108. break;
  1109. }
  1110. else
  1111. {
  1112. velocity.x = attackMoveSpeed;
  1113. rb.velocity = velocity;
  1114. }
  1115. }
  1116. break;
  1117. case PlayerAttackState.WalkBack:
  1118. if (bodyTrans.localScale.x > 0)
  1119. {
  1120. if (leftDir.x < -0.3f)
  1121. {
  1122. SetAttackState(PlayerAttackState.WalkForward);
  1123. velocity.x = -attackMoveSpeed;
  1124. rb.velocity = velocity;
  1125. break;
  1126. }
  1127. else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
  1128. {
  1129. SetAttackState(PlayerAttackState.Idle);
  1130. velocity.x = 0;
  1131. rb.velocity = velocity;
  1132. break;
  1133. }
  1134. else
  1135. {
  1136. velocity.x = attackMoveSpeed;
  1137. rb.velocity = velocity;
  1138. }
  1139. }
  1140. else
  1141. {
  1142. if (leftDir.x > 0.3f)
  1143. {
  1144. SetAttackState(PlayerAttackState.WalkForward);
  1145. velocity.x = attackMoveSpeed;
  1146. rb.velocity = velocity;
  1147. break;
  1148. }
  1149. else if (leftDir.x > -0.3f && leftDir.x > 0.3f)
  1150. {
  1151. SetAttackState(PlayerAttackState.Idle);
  1152. velocity.x = 0;
  1153. rb.velocity = velocity;
  1154. break;
  1155. }
  1156. else
  1157. {
  1158. velocity.x = -attackMoveSpeed;
  1159. rb.velocity = velocity;
  1160. }
  1161. }
  1162. break;
  1163. default:
  1164. break;
  1165. }
  1166. break;
  1167. case CharacterState.Summon:
  1168. if (leftDir.x > 0.3f || leftDir.x < -0.3f)
  1169. {
  1170. cacheDir = leftDir.x;
  1171. }
  1172. if (LBisHold)
  1173. {
  1174. cacheRush = true;
  1175. }
  1176. if (CheckPlayerChangeState(CharacterState.Summon))
  1177. {
  1178. break;
  1179. }
  1180. rb.velocity = Vector3.right * velocityAddition;
  1181. break;
  1182. case CharacterState.Rush:
  1183. if (rushTime <= 0)
  1184. {
  1185. if (btnRushKeep)
  1186. {
  1187. ChangeState(CharacterState.Sprint);
  1188. break;
  1189. }
  1190. if (CheckPlayerChangeState(CharacterState.Rush))
  1191. {
  1192. break;
  1193. }
  1194. }
  1195. rb.velocity = rushDir * rushSpeed;
  1196. break;
  1197. case CharacterState.Sprint:
  1198. if (!btnRushKeep)
  1199. {
  1200. if (CheckPlayerChangeState(CharacterState.Sprint))
  1201. {
  1202. break;
  1203. }
  1204. }
  1205. if (mp < sprintCostMp * Time.deltaTime)
  1206. {
  1207. if (CheckPlayerChangeState(CharacterState.Sprint))
  1208. {
  1209. break;
  1210. }
  1211. }
  1212. mp -= sprintCostMp * Time.deltaTime;
  1213. uiMp.Show(mp, totalMp);
  1214. rb.velocity = rushDir * rushSpeed;
  1215. break;
  1216. case CharacterState.Die:
  1217. if (dieKeepTime <= 0)
  1218. {
  1219. if (isRevive)
  1220. {
  1221. reviveTime += Time.deltaTime;
  1222. if (reviveTime >= totalReviveTime)
  1223. {
  1224. PlayerRevive();
  1225. }
  1226. }
  1227. else
  1228. {
  1229. PlayerDie();
  1230. }
  1231. }
  1232. break;
  1233. case CharacterState.Conduct:
  1234. if (CheckConduct())
  1235. {
  1236. ChangeState(CharacterState.Idle);
  1237. }
  1238. break;
  1239. case CharacterState.HitStun:
  1240. hitFeedbackSystem.HitStunUpdate();
  1241. break;
  1242. case CharacterState.SpecialStatus_Float:
  1243. attributeStatus.SpecialStateEffect(SpecialState.FloatState);
  1244. break;
  1245. case CharacterState.SpecialStatus_BlowUp:
  1246. attributeStatus.SpecialStateEffect(SpecialState.BlownUp);
  1247. break;
  1248. case CharacterState.SpecialStatus_ShotDown:
  1249. attributeStatus.SpecialStateEffect(SpecialState.ShotDown);
  1250. break;
  1251. case CharacterState.SpecialStatus_Weak:
  1252. attributeStatus.SpecialStateEffect(SpecialState.Weak);
  1253. break;
  1254. default:
  1255. break;
  1256. }
  1257. isClickBtnRush = false;
  1258. isKeepBtnRush = false;
  1259. isClickBtnJump = false;
  1260. isClickBtnSouth = false;
  1261. isClickBtnEast = false;
  1262. isClickBtnNorth = false;
  1263. isClickBtnWest = false;
  1264. isBtnSouthUp = false;
  1265. isBtnEastUp = false;
  1266. isBtnNorthUp = false;
  1267. isBtnWestUp = false;
  1268. isSpiritSummon = false;
  1269. isSpiritSummon1 = false;
  1270. isSpiritSummon2 = false;
  1271. isSpiritSummon3 = false;
  1272. if (foot.TrigGround)
  1273. {
  1274. canJumpTime = leaveGroundCanJumpTime;
  1275. }
  1276. //SearchTarget();
  1277. //attackTarget = targetCharacter;
  1278. if (isMpRepel)
  1279. {
  1280. if (mp < totalMp)
  1281. {
  1282. if (!isRapedReply)
  1283. {
  1284. mp += mpReplySpeed * Time.deltaTime;
  1285. }
  1286. else
  1287. {
  1288. mp += rapidReplySpeed * Time.deltaTime;
  1289. }
  1290. }
  1291. }
  1292. if (mp > totalMp)
  1293. {
  1294. mp = totalMp;
  1295. }
  1296. if (mp < 0)
  1297. {
  1298. mp = 0;
  1299. }
  1300. uiMp.Show(mp, totalMp);
  1301. }
  1302. public void PlayerDie()
  1303. {
  1304. switch (playerId)
  1305. {
  1306. case 0:
  1307. SpiritSystem.isP1In = true;
  1308. SpiritSystem.isP1Out = false;
  1309. break;
  1310. case 1:
  1311. SpiritSystem.isP2In = true;
  1312. SpiritSystem.isP2Out = false;
  1313. break;
  1314. default:
  1315. break;
  1316. }
  1317. foot.trigGroundList.Clear();
  1318. bodyTrans.gameObject.SetActive(false);
  1319. uiHp.transform.parent.gameObject.SetActive(false);
  1320. rb.constraints = RigidbodyConstraints.FreezeAll;
  1321. isRevive = true;
  1322. reviveTime = 0;
  1323. }
  1324. public void PlayerRevive()
  1325. {
  1326. isRevive = false;
  1327. bodyTrans.gameObject.SetActive(true);
  1328. uiHp.transform.parent.gameObject.SetActive(true);
  1329. rb.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotation;
  1330. transform.position = new Vector3(142 + 4 * playerId, 0, 0);
  1331. switch (playerId)
  1332. {
  1333. case 0:
  1334. SpiritSystem.isP1In = false;
  1335. SpiritSystem.isP1Out = true;
  1336. SpiritSystem.player1 = gameObject;
  1337. SpiritSystem.p1Spirits = GetComponent<Spirits>();
  1338. break;
  1339. case 1:
  1340. SpiritSystem.isP2In = false;
  1341. SpiritSystem.isP2Out = true;
  1342. SpiritSystem.player2 = gameObject;
  1343. SpiritSystem.p2Spirits = GetComponent<Spirits>();
  1344. break;
  1345. default:
  1346. break;
  1347. }
  1348. Init();
  1349. }
  1350. public void RapidReplyMp()
  1351. {
  1352. isRapedReply = true;
  1353. rapidReplyEffect.SetActive(true);
  1354. }
  1355. public void NormalReplyMp()
  1356. {
  1357. isRapedReply = false;
  1358. rapidReplyEffect.SetActive(false);
  1359. }
  1360. public override void ChangeState(CharacterState newState)
  1361. {
  1362. if (state == newState)
  1363. {
  1364. return;
  1365. }
  1366. Vector3 velocity = rb.velocity;
  1367. switch (state)
  1368. {
  1369. case CharacterState.Idle:
  1370. break;
  1371. case CharacterState.Run:
  1372. velocity.x = 0;
  1373. break;
  1374. case CharacterState.Rise:
  1375. bodyCollider.SetActive(true);
  1376. break;
  1377. case CharacterState.Fall:
  1378. break;
  1379. case CharacterState.Attack:
  1380. aniCollider.Play("NotAttack", 1, 0);
  1381. break;
  1382. case CharacterState.KeepAttack:
  1383. aniCollider.Play("NotAttack", 1, 0);
  1384. break;
  1385. case CharacterState.Summon:
  1386. rb.isKinematic = false;
  1387. if (cacheDir != 0)
  1388. {
  1389. if (cacheDir > 0.3f && bodyTrans.localScale.x > 0)
  1390. {
  1391. Turn();
  1392. }
  1393. else if (cacheDir < -0.3f && bodyTrans.localScale.x < 0)
  1394. {
  1395. Turn();
  1396. }
  1397. cacheDir = 0;
  1398. }
  1399. break;
  1400. case CharacterState.Rush:
  1401. invincibleTime = 0;
  1402. rb.useGravity = true;
  1403. velocity = Vector3.zero;
  1404. break;
  1405. case CharacterState.Sprint:
  1406. rb.useGravity = true;
  1407. velocity = Vector3.zero;
  1408. break;
  1409. case CharacterState.Die:
  1410. if (isRevive)
  1411. {
  1412. return;
  1413. }
  1414. isDie = false;
  1415. rb.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotation;
  1416. break;
  1417. case CharacterState.Conduct:
  1418. rb.isKinematic = false;
  1419. Time.timeScale = 1;
  1420. Time.fixedDeltaTime = fixedDeltaTime * Time.timeScale;
  1421. conductReadyTip.activeFalse();
  1422. break;
  1423. default:
  1424. break;
  1425. }
  1426. CharacterState oldState = state;
  1427. state = newState;
  1428. switch (newState)
  1429. {
  1430. case CharacterState.Idle:
  1431. aniCollider.Play("Idle", 0, 0);
  1432. if (oldState == CharacterState.Fall)
  1433. {
  1434. ani.Play("fall_end", 0, 0);
  1435. }
  1436. else
  1437. {
  1438. ani.Play("idle", 0, 0);
  1439. }
  1440. velocity = Vector3.right * velocityAddition;
  1441. //animalAni.SetInteger("state", (int)PlayerState.Idle);
  1442. break;
  1443. case CharacterState.Run:
  1444. aniCollider.Play("Run", 0, 0);
  1445. ani.Play("run_start", 0, 0);
  1446. //animalAni.SetInteger("state", (int)PlayerState.Walk);
  1447. break;
  1448. case CharacterState.Rise:
  1449. aniCollider.Play("Rise", 0, 0);
  1450. canJumpTime = 0;
  1451. break;
  1452. case CharacterState.Fall:
  1453. aniCollider.Play("Fall", 0, 0);
  1454. ani.Play("fall", 0, 0);
  1455. //animalAni.SetInteger("state", (int)PlayerState.Fall);
  1456. break;
  1457. case CharacterState.Attack:
  1458. attackController.attackTime = totalAttack_summonTime;
  1459. break;
  1460. case CharacterState.KeepAttack:
  1461. aniCollider.Play("Attack_summonKeep", 1, 0);
  1462. break;
  1463. case CharacterState.Summon:
  1464. aniCollider.Play("Summon", 0, 0);
  1465. if (foot.TrigGround)
  1466. {
  1467. ani.Play("summon", 0, 0);
  1468. }
  1469. else
  1470. {
  1471. ani.Play("summon_air", 0, 0);
  1472. }
  1473. velocity = Vector3.right * velocityAddition;
  1474. rb.isKinematic = true;
  1475. cacheDir = 0;
  1476. cacheRush = false;
  1477. break;
  1478. case CharacterState.Rush:
  1479. aniCollider.Play("Rush", 0, 0);
  1480. ani.Play("rush_loop", 0, 0);
  1481. rushTime = totalRushTime;
  1482. invincibleTime = rushInvincibleTime;
  1483. rb.useGravity = false;
  1484. if (bodyTrans.localScale.x > 0)
  1485. {
  1486. rushDir = Vector3.left;
  1487. }
  1488. else
  1489. {
  1490. rushDir = Vector3.right;
  1491. }
  1492. velocity = rushDir * rushSpeed;
  1493. mp -= rushCostMp;
  1494. uiMp.Show(mp, totalMp);
  1495. break;
  1496. case CharacterState.Sprint:
  1497. aniCollider.Play("Sprint", 0, 0);
  1498. rb.useGravity = false;
  1499. velocity = rushDir * rushSpeed;
  1500. break;
  1501. case CharacterState.Die:
  1502. rb.constraints = RigidbodyConstraints.FreezeAll;
  1503. aniCollider.Play("Die", 0, 0);
  1504. ani.Play("die", 0, 0);
  1505. isDie = true;
  1506. dieKeepTime = totalDieKeepTime;
  1507. break;
  1508. case CharacterState.Conduct:
  1509. conductTime = 0;
  1510. rb.velocity = Vector3.zero;
  1511. rb.isKinematic = true;
  1512. aniCollider.Play("Summon", 0, 0);
  1513. if (foot.TrigGround)
  1514. {
  1515. ani.Play("summon", 0, 0);
  1516. }
  1517. else
  1518. {
  1519. ani.Play("summon_air", 0, 0);
  1520. }
  1521. break;
  1522. default:
  1523. break;
  1524. }
  1525. rb.velocity = velocity;
  1526. }
  1527. public void CheckTurn()
  1528. {
  1529. if (leftDir.x > 0.3f && bodyTrans.localScale.x > 0)
  1530. {
  1531. if (state == CharacterState.Run)
  1532. {
  1533. ani.Play("run_start", 0, 0);
  1534. }
  1535. Turn();
  1536. }
  1537. else if (leftDir.x < -0.3f && bodyTrans.localScale.x < 0)
  1538. {
  1539. if (state == CharacterState.Run)
  1540. {
  1541. ani.Play("run_start", 0, 0);
  1542. }
  1543. Turn();
  1544. }
  1545. }
  1546. public Vector3 AirMove(Vector3 velocity)
  1547. {
  1548. CheckTurn();
  1549. if (canFly)
  1550. {
  1551. velocity = leftDir.normalized * flySpeed;
  1552. if (transform.position.y > playerMaxFlyHeight && velocity.y > 0)
  1553. {
  1554. velocity.y = 0;
  1555. }
  1556. }
  1557. else
  1558. {
  1559. if (leftDir.x > 0.3f)
  1560. {
  1561. velocity = new Vector3(moveSpeed, velocity.y, velocity.z);
  1562. }
  1563. else if (leftDir.x < -0.3f)
  1564. {
  1565. velocity = new Vector3(-moveSpeed, velocity.y, velocity.z);
  1566. }
  1567. else
  1568. {
  1569. velocity = new Vector3(0, velocity.y, velocity.z);
  1570. }
  1571. if (velocity.y > 0)
  1572. {
  1573. velocity += Vector3.up * extraRiseGravity * Time.deltaTime;
  1574. }
  1575. else
  1576. {
  1577. velocity += Vector3.up * extraFallGravity * Time.deltaTime;
  1578. }
  1579. }
  1580. return velocity;
  1581. }
  1582. public void Summon(int id)
  1583. {
  1584. if (id >= demonicPrefabs.Count)
  1585. {
  1586. Debug.LogError("未配置" + id + "号使魔");
  1587. return;
  1588. }
  1589. if (id >= demonicSummonPos.Count)
  1590. {
  1591. Debug.LogError("未配置" + id + "号使魔召唤位置");
  1592. return;
  1593. }
  1594. GameObject prefab;
  1595. prefab = demonicPrefabs[id];
  1596. if (!CheckCanSummon(id))
  1597. {
  1598. return;
  1599. }
  1600. ChangeState(CharacterState.Summon);
  1601. summonTime = totalSummonTime;
  1602. Demonic dem = prefab.GetComponent<Demonic>();
  1603. float costMp = dem.costMp;
  1604. for (int i = 0; i < 3; i++)
  1605. {
  1606. if (GameManager.curSoldiers[i] == dem.soldierType)
  1607. {
  1608. costMp += slr.seb[i].mp;
  1609. break;
  1610. }
  1611. }
  1612. mp -= costMp;
  1613. uiMp.Show(mp, totalMp);
  1614. GameObject demonicObj = PoolManager.Instantiate(prefab);
  1615. Demonic demonic = demonicObj.GetComponent<Demonic>();
  1616. onlySummonTime = demonic.summonTime;
  1617. invincibleTime = demonic.summonTime + addSummonInvincibleTime;
  1618. restSummonTime = onlySummonTime;
  1619. demonic.id = id;
  1620. demonic.playerID = playerId;
  1621. if (!demonicDic.ContainsKey(id))
  1622. {
  1623. demonicDic.Add(id, new List<Demonic>());
  1624. }
  1625. demonicDic[id].Add(demonic);
  1626. if (id <= 2)
  1627. {
  1628. demonicNums[id].text = demonicDic[id].Count.ToString();
  1629. }
  1630. demonicObj.transform.parent = null;
  1631. demonicObj.transform.localEulerAngles = Vector3.zero;
  1632. demonicObj.transform.localScale = new Vector3(1, 1, 1);
  1633. Vector3 offset = demonicSummonPos[id];
  1634. if (bodyTrans.localScale.x > 0)
  1635. {
  1636. demonicObj.transform.position = transform.position + offset;
  1637. if (demonic.bodyTrans.localScale.x < 0)
  1638. {
  1639. demonic.Turn();
  1640. }
  1641. }
  1642. else
  1643. {
  1644. demonicObj.transform.position = transform.position + new Vector3(-offset.x, offset.y, offset.z);
  1645. if (demonic.bodyTrans.localScale.x > 0)
  1646. {
  1647. demonic.Turn();
  1648. }
  1649. }
  1650. if (demonic.canFly)
  1651. {
  1652. demonic.flyHeight = demonic.transform.position.y;
  1653. }
  1654. demonic.player = this;
  1655. demonic.Init();
  1656. int order = prefab.GetComponent<Demonic>().baseSortingOrder + demonicDic[demonic.id].Count;
  1657. demonic.SetSortingOrder(order);
  1658. if (id != 4)
  1659. {
  1660. demonic.Attack_summon();
  1661. }
  1662. //id 3~6 为四个英灵
  1663. if (id >= 3 && id <= 6)
  1664. {
  1665. spirits.ultimateTimes[spirits.nowSpirit] -= 1;
  1666. }
  1667. spiritSystem.RefreshPlayerUI();
  1668. if (isInSoulTower)
  1669. {
  1670. ls.AddDenomic(demonic);
  1671. }
  1672. slr.SoldierAddLevelBuff(demonic);
  1673. }
  1674. public void OnDemonicRecycle(Demonic demonic)
  1675. {
  1676. if (!demonicDic.ContainsKey(demonic.id))
  1677. {
  1678. return;
  1679. }
  1680. demonicDic[demonic.id].Remove(demonic);
  1681. if (demonic.id <= 2)
  1682. {
  1683. demonicNums[demonic.id].text = demonicDic[demonic.id].Count.ToString();
  1684. }
  1685. for (int i = 0; i < demonicDic[demonic.id].Count; i++)
  1686. {
  1687. int order = demonicDic[demonic.id][i].baseSortingOrder + i;
  1688. demonicDic[demonic.id][i].SetSortingOrder(order);
  1689. }
  1690. }
  1691. public bool CheckCanSummon(int id)
  1692. {
  1693. GameObject prefab;
  1694. prefab = demonicPrefabs[id];
  1695. Demonic dem = prefab.GetComponent<Demonic>();
  1696. float costMp = dem.costMp;
  1697. for (int i = 0; i < 3; i++)
  1698. {
  1699. if (GameManager.curSoldiers[i] == dem.soldierType)
  1700. {
  1701. costMp += slr.seb[i].mp;
  1702. break;
  1703. }
  1704. }
  1705. if (id < 3)
  1706. {
  1707. costMp += addCostMp[id] * demonicDic[id].Count;
  1708. }
  1709. if (mp < costMp)
  1710. {
  1711. Debug.Log("mp不足召唤失败, 还得加个动画或者音效啥的");
  1712. return false;
  1713. }
  1714. return true;
  1715. }
  1716. public void Attack_summon()
  1717. {
  1718. attackController.Attack_summon();
  1719. if (leftDir.x > 0.3f)
  1720. {
  1721. if (bodyTrans.localScale.x > 0)
  1722. {
  1723. Turn();
  1724. }
  1725. SetAttackState(PlayerAttackState.WalkForward);
  1726. }
  1727. else if (leftDir.x < -0.3f)
  1728. {
  1729. if (bodyTrans.localScale.x < 0)
  1730. {
  1731. Turn();
  1732. }
  1733. SetAttackState(PlayerAttackState.WalkForward);
  1734. }
  1735. else
  1736. {
  1737. SetAttackState(PlayerAttackState.Idle);
  1738. }
  1739. }
  1740. public void SetAttackState(PlayerAttackState value)
  1741. {
  1742. attackState = value;
  1743. ani.SetInteger("attackState", (int)value);
  1744. aniCollider.Play("Attack_summonKeep", 1, 0);
  1745. }
  1746. /*
  1747. public void SearchTarget()
  1748. {
  1749. targetCharacter = searchTrigger.GetMinDisTarget(attackController.targetTypes, attackController.canHitFly);
  1750. }*/
  1751. public override void BeHit(int damage)
  1752. {
  1753. base.BeHit(damage);
  1754. //屏幕红闪+抖动
  1755. if (ss == null)
  1756. {
  1757. ss = Camera.main.GetComponentInParent<ScreenShake>();
  1758. }
  1759. ss.enabled = true;
  1760. if (isSustainedInjury || damage >= heavyDamage)
  1761. {
  1762. ss.ShakeScreen(1);
  1763. }
  1764. }
  1765. public override void BeHit(AttackInfo attackInfo, Character attackFrom)
  1766. {
  1767. if (conductController.HavePhoton(attackFrom, attackInfo.damage))
  1768. {
  1769. return;
  1770. }
  1771. base.BeHit(attackInfo, attackFrom);
  1772. //屏幕红闪+抖动
  1773. if (ss == null)
  1774. {
  1775. ss = Camera.main.GetComponentInParent<ScreenShake>();
  1776. }
  1777. ss.enabled = true;
  1778. if (isSustainedInjury || attackInfo.damage >= heavyDamage)
  1779. {
  1780. ss.ShakeScreen(1);
  1781. }
  1782. }
  1783. }