PlayerController.cs 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Spine;
  5. using Spine.Unity;
  6. using UnityEngine.LowLevel;
  7. using UnityEngine.Playables;
  8. using System.ComponentModel;
  9. using Unity.VisualScripting;
  10. using System;
  11. using Base.Common;
  12. using cfg;
  13. using static UnityEngine.EventSystems.EventTrigger;
  14. using UnityEngine.InputSystem;
  15. using TMPro;
  16. [Serializable]
  17. public struct AttackInfo
  18. {
  19. public int damage;
  20. public Vector3 attackDir;
  21. public float force;
  22. public bool changeHurt;
  23. public float repelValue;
  24. }
  25. public enum PlayerAttackState
  26. {
  27. Idle = 0,
  28. WalkForward = 1,
  29. WalkBack = 2,
  30. }
  31. public class PlayerController : MoveCharacter
  32. {
  33. //public static PlayerController instance;
  34. public List<GameObject> changePrefabs;
  35. private GameObject spiritObj; //当前变身的对象
  36. public int endChange = 0;
  37. //public float changeTime; //变身时长
  38. //private float pastChangeTime;
  39. public List<GameObject> demonicPrefabs;
  40. public List<Vector3> demonicSummonPos;
  41. public Dictionary<int, List<Demonic>> demonicDic;
  42. public List<int> demonicId;
  43. public UIHP uiMp;
  44. public PlayerRope playerRope;
  45. public EventTrigger eventTrigger;
  46. public SprintLinkTrigger sprintLinkTrigger;
  47. public float jumpSpeed = 10;
  48. public float airJumpSpeed = 10;
  49. //public float moveAcc = 5f;
  50. //public float airMoveAcc = 3f;
  51. public float rushSpeed = 100;
  52. public float flySpeed = 5;
  53. public float mp;
  54. public float totalMp;
  55. public float mpReplySpeed = 1;
  56. public float rushCostMp = 5;
  57. public float sprintCostMp = 5;
  58. public float rushInvincibleTime = 0.2f;
  59. [HideInInspector]
  60. public float canJumpTime; //离开平台后仍然可以跳跃的时间,用于提升手感
  61. public float leaveGroundCanJumpTime = 0.1f;
  62. [HideInInspector]
  63. public float cacheJumpTime; //即将落地时按下跳跃键不会跳跃,手感不好,缓存几帧,在这几帧内落地会立即跳跃;
  64. public float totalCacheJumpTime = 0.1f;
  65. [HideInInspector]
  66. public float tandemJumpTime; //即将落地时按下跳跃键不会跳跃,手感不好,缓存几帧,在这几帧内落地会立即跳跃;
  67. public float totalTandemJumpTime = 0.1f;
  68. [HideInInspector]
  69. public float summonTime;
  70. [HideInInspector]
  71. public float cacheAttackTime; //无法攻击时按下攻击键不会攻击,手感不好,缓存几帧,在这几帧内落地会立即攻击;
  72. public float totalCacheAttackTime = 0.1f;
  73. [HideInInspector]
  74. public float cachePullRopeTime;
  75. public float totalCachePullRopeTime = 0.1f;
  76. [HideInInspector]
  77. public float cacheSummonTime; //无法召唤时按下召唤键不会召唤,手感不好,缓存几帧,在这几帧内落地会立即召唤;
  78. public float totalCacheSummonTime = 0.1f;
  79. [HideInInspector]
  80. public int cacheSummonId;
  81. [HideInInspector]
  82. public float rushTime;
  83. public float totalRushTime = 0.5f;
  84. [HideInInspector]
  85. public float cacheRushTime; //无法Rush时按下Rush键不会Rush,手感不好,缓存几帧,在这几帧内落地会立即Rush;
  86. public float totalCacheRushTime = 0.1f;
  87. public int airJumped;
  88. public int jumpNumber = 2; //最大跳跃次数
  89. public PlayerAttackState attackState;
  90. public float attackMoveSpeed = 5f;
  91. public Vector3 rushDir;
  92. private int currentSpirit; //当前将要召唤的英灵种类
  93. private Spirits spirits;
  94. public float lostMp;
  95. public GameObject soul;
  96. private float addMp = 10;
  97. public Collider soulCollector;
  98. public bool isTransfiguration = false; //已变身
  99. public Vector2 moveVec; //玩家不动时移动数据
  100. public float reviveTime; //复活时间
  101. public float totalReviveTime;
  102. public bool isBaseBtnOut = false;
  103. public bool btnJumpPress
  104. {
  105. get
  106. {
  107. //return Input.GetKeyDown(KeyCode.Space) || isClickBtnJump;
  108. return isClickBtnJump;
  109. }
  110. }
  111. [HideInInspector]
  112. public bool isClickBtnJump;
  113. public bool btnRushPress
  114. {
  115. get
  116. {
  117. //return Input.GetKeyDown(KeyCode.LeftShift) || isClickBtnRush;
  118. return isClickBtnRush;
  119. }
  120. }
  121. [HideInInspector]
  122. public bool isClickBtnRush;
  123. public bool btnRushKeep
  124. {
  125. get
  126. {
  127. //return Input.GetKey(KeyCode.LeftShift) || isKeepBtnRush;
  128. return LBisHold || isKeepBtnRush;
  129. }
  130. }
  131. [HideInInspector]
  132. public bool isKeepBtnRush;
  133. public bool btnSouthPress
  134. {
  135. get
  136. {
  137. //return Input.GetKeyDown(KeyCode.K) || isClickBtnSouth;
  138. return isClickBtnSouth;
  139. }
  140. }
  141. [HideInInspector]
  142. public bool isClickBtnSouth;
  143. public bool btnEastPress
  144. {
  145. get
  146. {
  147. //return Input.GetKeyDown(KeyCode.L) || isClickBtnEast;
  148. return isClickBtnEast;
  149. }
  150. }
  151. [HideInInspector]
  152. public bool isClickBtnEast;
  153. public bool btnTransfiguratePress
  154. {
  155. get
  156. {
  157. //return Input.GetKeyDown(KeyCode.L) || isClickBtnEast;
  158. return isClickBtnTransfigurate;
  159. }
  160. }
  161. [HideInInspector]
  162. public bool isClickBtnTransfigurate;
  163. public bool btnWestPress
  164. {
  165. get
  166. {
  167. //return Input.GetKeyDown(KeyCode.J) || isClickBtnWest;
  168. return isClickBtnWest;
  169. }
  170. }
  171. [HideInInspector]
  172. public bool isClickBtnWest;
  173. public bool btnNorthPress
  174. {
  175. get
  176. {
  177. //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
  178. return isClickBtnNorth;
  179. }
  180. }
  181. [HideInInspector]
  182. public bool isClickBtnNorth;
  183. public bool btnSpiritSummon
  184. {
  185. get
  186. {
  187. //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
  188. return isSpiritSummon;
  189. }
  190. }
  191. [HideInInspector]
  192. public bool isSpiritSummon;
  193. public bool btnSpiritSummon1
  194. {
  195. get
  196. {
  197. //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
  198. return isSpiritSummon1;
  199. }
  200. }
  201. [HideInInspector]
  202. public bool isSpiritSummon1;
  203. public bool btnSpiritSummon2
  204. {
  205. get
  206. {
  207. //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
  208. return isSpiritSummon2;
  209. }
  210. }
  211. [HideInInspector]
  212. public bool isSpiritSummon2;
  213. public bool btnSpiritSummon3
  214. {
  215. get
  216. {
  217. //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
  218. return isSpiritSummon3;
  219. }
  220. }
  221. [HideInInspector]
  222. public bool isSpiritSummon3;
  223. public bool btnNorthKeep
  224. {
  225. get
  226. {
  227. //return Input.GetKey(KeyCode.I) || isKeepBtnNorth;
  228. return isKeepBtnNorth;
  229. }
  230. }
  231. [HideInInspector]
  232. public bool isKeepBtnNorth;
  233. [HideInInspector]
  234. public Vector2 leftDir;
  235. public int playerId;
  236. public SkeletonMecanim skeletonMecanim;
  237. public SkeletonDataAsset[] playerSpine;
  238. public bool canJump;
  239. public bool canfly;
  240. //public Vector2 leftDir
  241. //{
  242. // get
  243. // {
  244. // int x = 0;
  245. // int y = 0;
  246. // if (Input.GetKey(KeyCode.A))
  247. // {
  248. // x--;
  249. // }
  250. // if (Input.GetKey(KeyCode.D))
  251. // {
  252. // x++;
  253. // }
  254. // if (Input.GetKey(KeyCode.S))
  255. // {
  256. // y--;
  257. // }
  258. // if (Input.GetKey(KeyCode.W))
  259. // {
  260. // y++;
  261. // }
  262. // return new Vector2(x, y);
  263. // }
  264. //}
  265. public override void Init()
  266. {
  267. base.Init();
  268. mp = totalMp;
  269. uiMp.Show(mp, totalMp);
  270. }
  271. private void Awake()
  272. {
  273. PlayerInput playerInput = transform.GetComponent<PlayerInput>();
  274. spirits = GetComponent<Spirits>();
  275. playerId = playerInput.playerIndex;
  276. transform.position = new Vector3(142 + 4 * playerId, 0, 0);
  277. playerRope.playerId = playerId;
  278. sprintLinkTrigger.playerID = playerId;
  279. if (PlayersInput.instance[1] == PlayersInput.instance[0])
  280. {
  281. PlayersInput.instance[1] = this;
  282. }
  283. PlayersInput.instance[playerId] = this;
  284. skeletonMecanim.skeletonDataAsset = playerSpine[playerId];
  285. switch (playerId)
  286. {
  287. case 0:
  288. SpiritSystem.isP1Out = true;
  289. SpiritSystem.isP1In = false;
  290. SpiritSystem.player1 = gameObject;
  291. SpiritSystem.p1Spirits = GetComponent<Spirits>();
  292. break;
  293. case 1:
  294. SpiritSystem.isP2Out = true;
  295. SpiritSystem.isP2In = false;
  296. SpiritSystem.player2 = gameObject;
  297. SpiritSystem.p2Spirits = GetComponent<Spirits>();
  298. break;
  299. default:
  300. break;
  301. }
  302. //else
  303. //{
  304. // DestroyImmediate(gameObject);
  305. // return;
  306. //}
  307. demonicDic = new Dictionary<int, List<Demonic>>();
  308. demonicId = new List<int>() { 0, 0, 0, 0, 0, 0, 0 };
  309. Init();
  310. }
  311. private void Update()
  312. {
  313. //if (Input.GetKeyDown(KeyCode.LeftShift))
  314. //{
  315. // isClickBtnRush = true;
  316. //}
  317. //if (Input.GetKey(KeyCode.LeftShift))
  318. //{
  319. // isKeepBtnRush = true;
  320. //}
  321. //if (Input.GetKeyDown(KeyCode.Space))
  322. //{
  323. // isClickBtnJump = true;
  324. //}
  325. //if (Input.GetKeyDown(KeyCode.J))
  326. //{
  327. // isClickBtnWest = true;
  328. //}
  329. //if (Input.GetKeyDown(KeyCode.K))
  330. //{
  331. // isClickBtnSouth = true;
  332. //}
  333. //if (Input.GetKeyDown(KeyCode.L))
  334. //{
  335. // isClickBtnEast = true;
  336. //}
  337. //if (Input.GetKeyDown(KeyCode.I))
  338. //{
  339. // isClickBtnNorth = true;
  340. //}
  341. if (LBisHold)
  342. {
  343. isKeepBtnRush = true;
  344. }
  345. if (floatState != 0)
  346. {
  347. CharacterFloat();
  348. }
  349. /* //到时间自动解除变身
  350. if (endChange != 0)
  351. {
  352. pastChangeTime += Time.deltaTime;
  353. if (pastChangeTime >= changeTime)
  354. {
  355. EndTransfiguration(endChange);
  356. endChange = 0;
  357. pastChangeTime = 0;
  358. }
  359. }
  360. */
  361. if (isTransfiguration)
  362. {
  363. bodyTrans.position = spiritObj.transform.position;
  364. }
  365. if (isInvisible)
  366. {
  367. invisibleTime -= Time.deltaTime;
  368. if (invisibleTime <= 0)
  369. {
  370. isInvisible = false;
  371. ChangeMat(1);
  372. }
  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. if (canMove)
  392. {
  393. leftDir = value.Get<Vector2>();
  394. }
  395. else
  396. {
  397. leftDir = Vector3.zero;
  398. moveVec = value.Get<Vector2>();
  399. }
  400. }
  401. void OnJump()
  402. {
  403. if (canJump && canMove)
  404. {
  405. isClickBtnJump = true;
  406. }
  407. }
  408. void OnSummon0()
  409. {
  410. if (!isFloat && canMove)
  411. {
  412. isClickBtnWest = true;
  413. }
  414. }
  415. void OnSummon0Up()
  416. {
  417. switch (playerId)
  418. {
  419. case 0:
  420. if (SpiritSystem.isXbtnDown1)
  421. {
  422. SpiritSystem.isXbtnDown1 = false;
  423. }
  424. break;
  425. case 1:
  426. if (SpiritSystem.isXbtnDown2)
  427. {
  428. SpiritSystem.isXbtnDown2 = false;
  429. }
  430. break;
  431. default:
  432. break;
  433. }
  434. }
  435. void OnSummon1()
  436. {
  437. if (!isFloat && canMove)
  438. {
  439. isClickBtnSouth = true;
  440. }
  441. }
  442. void OnSummon2()
  443. {
  444. if (!isFloat && canMove)
  445. {
  446. isClickBtnEast = true;
  447. }
  448. }
  449. public int[] needCorpses;
  450. void OnChooseSpirit() //选英灵
  451. {
  452. if (!isTransfiguration)
  453. {
  454. switch (playerId)
  455. {
  456. case 0:
  457. SpiritSystem.isP1CardChange = true;
  458. break;
  459. case 1:
  460. SpiritSystem.isP2CardChange = true;
  461. break;
  462. default:
  463. break;
  464. }
  465. }
  466. }
  467. public bool isUltimate; //英灵释放大招
  468. public bool keyTransfigurateRelease; //松开英灵释放大招键
  469. void OnTransfigurate() //变身
  470. {
  471. if (!isFloat && canMove)
  472. {
  473. isClickBtnTransfigurate = true;
  474. }
  475. }
  476. void OnTransfigurateUp() //松开变身键
  477. {
  478. if (isTransfiguration)
  479. {
  480. keyTransfigurateRelease = true;
  481. }
  482. }
  483. public void Jump()
  484. {
  485. SetUpSpeed(jumpSpeed);
  486. ani.Play("jump", 0, 0);
  487. }
  488. public void AirJump()
  489. {
  490. SetUpSpeed(airJumpSpeed);
  491. ani.Play("jump", 0, 0);
  492. }
  493. public void SetUpSpeed(float speed)
  494. {
  495. ChangeState(CharacterState.Rise);
  496. Vector3 velocity = rb.velocity;
  497. CheckTurn();
  498. velocity.y = speed;
  499. rb.velocity = velocity;
  500. //animalAni.SetInteger("state", (int)PlayerState.Rise);
  501. }
  502. public bool canTranSummon = true;
  503. public bool CheckSummon()
  504. {
  505. if (cacheSummonTime > 0)
  506. {
  507. Summon(cacheSummonId);
  508. return true;
  509. }
  510. if (btnWestPress)
  511. {
  512. if (!isBaseBtnOut)
  513. {
  514. if (isTransfiguration && !canTranSummon)
  515. {
  516. return true;
  517. }
  518. Summon(0);
  519. }
  520. else
  521. {
  522. switch (playerId)
  523. {
  524. case 0:
  525. SpiritSystem.isXbtnDown1 = true;
  526. break;
  527. case 1:
  528. SpiritSystem.isXbtnDown2 = true;
  529. break;
  530. default:
  531. break;
  532. }
  533. }
  534. return true;
  535. }
  536. if (btnSouthPress)
  537. {
  538. if (!isBaseBtnOut)
  539. {
  540. if (isTransfiguration && !canTranSummon)
  541. {
  542. return true;
  543. }
  544. Summon(1);
  545. }
  546. return true;
  547. }
  548. if (btnEastPress)
  549. {
  550. if (!isBaseBtnOut)
  551. {
  552. if (isTransfiguration && !canTranSummon)
  553. {
  554. return true;
  555. }
  556. Summon(2);
  557. }
  558. else
  559. {
  560. switch (playerId)
  561. {
  562. case 0:
  563. SpiritSystem.isBbtnDown1 = true;
  564. break;
  565. case 1:
  566. SpiritSystem.isBbtnDown2 = true;
  567. break;
  568. default:
  569. break;
  570. }
  571. }
  572. return true;
  573. }
  574. if (btnTransfiguratePress)
  575. {
  576. if (!isTransfiguration)
  577. {
  578. if (spirits.currentSpirit != Spirits.SpiritType.None)
  579. {
  580. switch (playerId)
  581. {
  582. case 0:
  583. SpiritSystem.isSelect1 = true;
  584. break;
  585. case 1:
  586. SpiritSystem.isSelect2 = true;
  587. break;
  588. default:
  589. break;
  590. }
  591. Transfiguration((int)spirits.currentSpirit + 3);
  592. }
  593. }
  594. else
  595. {
  596. isUltimate = true;
  597. keyTransfigurateRelease = false;
  598. }
  599. return true;
  600. }
  601. if (isSpiritSummon)
  602. {
  603. Transfiguration(3);
  604. return true;
  605. }
  606. if (isSpiritSummon1)
  607. {
  608. Transfiguration(4);
  609. return true;
  610. }
  611. if (isSpiritSummon2)
  612. {
  613. Transfiguration(5);
  614. return true;
  615. }
  616. if (isSpiritSummon3)
  617. {
  618. Transfiguration(6);
  619. return true;
  620. }
  621. return false;
  622. }
  623. //角色处于可自由活动状态时的通用切换状态逻辑,如Idle、Run状态,以及别的状态结束时准备回到Idle状态前
  624. public bool CheckPlayerChangeState(CharacterState excludeState = CharacterState.None)
  625. {
  626. if (!foot.TrigGround)
  627. {
  628. if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
  629. {
  630. if (excludeState != CharacterState.Rush)
  631. {
  632. ChangeState(CharacterState.Rush);
  633. return true;
  634. }
  635. }
  636. if (rb.velocity.y > 0)
  637. {
  638. if (excludeState != CharacterState.Rise)
  639. {
  640. ChangeState(CharacterState.Rise);
  641. return true;
  642. }
  643. }
  644. else
  645. {
  646. if (excludeState != CharacterState.Fall)
  647. {
  648. ChangeState(CharacterState.Fall);
  649. return true;
  650. }
  651. }
  652. }
  653. else
  654. {
  655. airJumped = 0;
  656. //if (btnNorthPress || cacheAttackTime > 0)
  657. //{
  658. // if (excludeState != CharacterState.Attack)
  659. // {
  660. // Attack1();
  661. // return true;
  662. // }
  663. //}
  664. if (eventTrigger.triggedRivet && (btnNorthPress || cachePullRopeTime > 0))
  665. {
  666. if (sprintLinkTrigger.linkedEnemy.Count > 0)
  667. {
  668. eventTrigger.triggedRivet.BindingRopes(sprintLinkTrigger.linkedEnemy);
  669. }
  670. //ChangeState(CharacterState.PullRope);
  671. }
  672. if (excludeState != CharacterState.Summon)
  673. {
  674. if (CheckSummon())
  675. {
  676. return true;
  677. }
  678. }
  679. if (excludeState != CharacterState.Transfiguration)
  680. {
  681. if (CheckSummon())
  682. {
  683. return true;
  684. }
  685. }
  686. if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
  687. {
  688. if (excludeState != CharacterState.Rush)
  689. {
  690. ChangeState(CharacterState.Rush);
  691. return true;
  692. }
  693. }
  694. if (btnJumpPress || cacheJumpTime > 0)
  695. {
  696. if (excludeState != CharacterState.Rise)
  697. {
  698. Jump();
  699. ChangeState(CharacterState.Rise);
  700. return true;
  701. }
  702. }
  703. if (canfly)
  704. {
  705. if (leftDir.x > 0.3f || leftDir.x < -0.3f || leftDir.y > 0.3f || leftDir.y < -0.3f)
  706. {
  707. if (excludeState != CharacterState.Run)
  708. {
  709. ChangeState(CharacterState.Run);
  710. return true;
  711. }
  712. }
  713. else
  714. {
  715. if (excludeState != CharacterState.Idle)
  716. {
  717. ChangeState(CharacterState.Idle);
  718. return true;
  719. }
  720. }
  721. }
  722. else
  723. {
  724. if (leftDir.x > 0.3f || leftDir.x < -0.3f)
  725. {
  726. if (excludeState != CharacterState.Run)
  727. {
  728. ChangeState(CharacterState.Run);
  729. return true;
  730. }
  731. }
  732. else
  733. {
  734. if (excludeState != CharacterState.Idle)
  735. {
  736. ChangeState(CharacterState.Idle);
  737. return true;
  738. }
  739. }
  740. }
  741. }
  742. return false;
  743. }
  744. public override Vector3 GetMoveDir()
  745. {
  746. return leftDir;
  747. }
  748. public void CachedPlayerInput()
  749. {
  750. if (btnRushPress)
  751. {
  752. cacheRushTime = totalCacheRushTime;
  753. }
  754. if (btnJumpPress)
  755. {
  756. cacheJumpTime = totalCacheJumpTime;
  757. }
  758. if (btnNorthPress)
  759. {
  760. cacheAttackTime = totalCacheAttackTime;
  761. }
  762. if (btnWestPress)
  763. {
  764. cacheSummonTime = totalCacheSummonTime;
  765. cacheSummonId = 0;
  766. }
  767. if (btnSouthPress)
  768. {
  769. cacheSummonTime = totalCacheSummonTime;
  770. cacheSummonId = 1;
  771. }
  772. if (btnEastPress)
  773. {
  774. cacheSummonTime = totalCacheSummonTime;
  775. cacheSummonId = 2;
  776. }
  777. if (btnSpiritSummon)
  778. {
  779. cacheSummonTime = totalCacheSummonTime;
  780. cacheSummonId = 3;
  781. }
  782. if (btnSpiritSummon1)
  783. {
  784. cacheSummonTime = totalCacheSummonTime;
  785. cacheSummonId = 4;
  786. }
  787. if (btnSpiritSummon2)
  788. {
  789. cacheSummonTime = totalCacheSummonTime;
  790. cacheSummonId = 5;
  791. }
  792. if (btnSpiritSummon3)
  793. {
  794. cacheSummonTime = totalCacheSummonTime;
  795. cacheSummonId = 6;
  796. }
  797. }
  798. public override void OnState()
  799. {
  800. base.OnState();
  801. //hurtKeepTime -= Time.deltaTime;
  802. cacheJumpTime -= Time.deltaTime;
  803. cacheAttackTime -= Time.deltaTime;
  804. cacheSummonTime -= Time.deltaTime;
  805. canJumpTime -= Time.deltaTime;
  806. invincibleTime -= Time.deltaTime;
  807. attackTime -= Time.deltaTime;
  808. summonTime -= Time.deltaTime;
  809. rushTime -= Time.deltaTime;
  810. cacheRushTime -= Time.deltaTime;
  811. dieKeepTime -= Time.deltaTime;
  812. weakTime -= Time.deltaTime;
  813. Vector3 velocity = rb.velocity;
  814. switch (state)
  815. {
  816. case CharacterState.Idle:
  817. if (CheckPlayerChangeState(CharacterState.Idle))
  818. {
  819. break;
  820. }
  821. rb.velocity = Vector3.right * velocityAddition;
  822. break;
  823. case CharacterState.Run:
  824. if (CheckPlayerChangeState(CharacterState.Run))
  825. {
  826. break;
  827. }
  828. CheckTurn();
  829. if (canfly)
  830. {
  831. rb.velocity = leftDir.normalized * moveSpeed;
  832. }
  833. else
  834. {
  835. if (leftDir.x > 0.3f)
  836. {
  837. rb.velocity = new Vector3(moveSpeed+velocityAddition,0,0);
  838. }
  839. else if (leftDir.x < -0.3f)
  840. {
  841. rb.velocity = new Vector3(-moveSpeed + velocityAddition,0,0);
  842. }
  843. }
  844. break;
  845. case CharacterState.Rise:
  846. if (CheckSummon())
  847. {
  848. break;
  849. }
  850. if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
  851. {
  852. ChangeState(CharacterState.Rush);
  853. break;
  854. }
  855. if (rb.velocity.y <= 0)
  856. {
  857. ChangeState(CharacterState.Fall);
  858. break;
  859. }
  860. if (btnJumpPress || cacheJumpTime > 0)
  861. {
  862. if (airJumped == 0 && jumpNumber >= 2 && rb.velocity.y < airJumpSpeed)
  863. {
  864. airJumped = 1;
  865. AirJump();
  866. break;
  867. }
  868. if (airJumped == 1 && jumpNumber >= 3 && rb.velocity.y < airJumpSpeed)
  869. {
  870. airJumped = 2;
  871. AirJump();
  872. break;
  873. }
  874. isClickBtnJump = false;
  875. }
  876. CachedPlayerInput();
  877. rb.velocity = AirMove(rb.velocity);
  878. break;
  879. case CharacterState.Fall:
  880. if (CheckSummon())
  881. {
  882. break;
  883. }
  884. if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
  885. {
  886. ChangeState(CharacterState.Rush);
  887. break;
  888. }
  889. if (foot.TrigGround)
  890. {
  891. if (CheckPlayerChangeState())
  892. {
  893. break;
  894. }
  895. }
  896. //if (foot.canStepPlayers.Count > 0)
  897. //{
  898. // Jump(jumpSpeed / 2);
  899. // StepOther();
  900. // break;
  901. //}
  902. //if (foot.canStepEnemyList.Count > 0)
  903. //{
  904. // Jump(jumpSpeed / 2);
  905. // StepEnemy();
  906. // break;
  907. //}
  908. if (btnJumpPress || cacheJumpTime > 0)
  909. {
  910. if (canJumpTime > 0)
  911. {
  912. Jump();
  913. break;
  914. }
  915. else
  916. {
  917. switch (airJumped)
  918. {
  919. case 0:
  920. if(jumpNumber >= 2)
  921. {
  922. airJumped = 1;
  923. AirJump();
  924. }
  925. break;
  926. case 1:
  927. if(jumpNumber >= 3)
  928. {
  929. airJumped = 2;
  930. AirJump();
  931. }
  932. break;
  933. }
  934. }
  935. isClickBtnJump = false;
  936. }
  937. CachedPlayerInput();
  938. rb.velocity = AirMove(rb.velocity);
  939. break;
  940. //case CharacterState.Hurt:
  941. // if (hurtKeepTime <= 0 && rb.velocity.magnitude < hurtChangeVelocity)
  942. // {
  943. // if (CheckPlayerChangeState())
  944. // {
  945. // break;
  946. // }
  947. // }
  948. // Vector3 vel = rb.velocity;
  949. // if (!foot.TrigGround)
  950. // {
  951. // if (canfly)
  952. // {
  953. // vel.y = vel.y * (1 - decelerationRatio * Time.deltaTime);
  954. // }
  955. // else
  956. // {
  957. // vel += Vector3.up * extraFallGravity * Time.deltaTime;
  958. // }
  959. // }
  960. // vel.x = vel.x * (1 - decelerationRatio * Time.deltaTime);
  961. // rb.velocity = vel;
  962. // CachedPlayerInput();
  963. // break;
  964. case CharacterState.Coma:
  965. break;
  966. case CharacterState.Attack:
  967. if (attackTime <= 0)
  968. {
  969. if (btnNorthKeep)
  970. {
  971. ChangeState(CharacterState.KeepAttack);
  972. break;
  973. }
  974. if (CheckPlayerChangeState())
  975. {
  976. break;
  977. }
  978. }
  979. CachedPlayerInput();
  980. break;
  981. case CharacterState.KeepAttack:
  982. if ((btnRushPress) && mp >= rushCostMp)
  983. {
  984. ChangeState(CharacterState.Rush);
  985. break;
  986. }
  987. if (btnJumpPress && canJumpTime > 0)
  988. {
  989. Jump();
  990. break;
  991. }
  992. if (!btnNorthKeep)
  993. {
  994. if (CheckPlayerChangeState(CharacterState.Attack))
  995. {
  996. break;
  997. }
  998. }
  999. switch (attackState)
  1000. {
  1001. case PlayerAttackState.Idle:
  1002. if (bodyTrans.localScale.x > 0)
  1003. {
  1004. if (leftDir.x > 0.3f)
  1005. {
  1006. SetAttackState(PlayerAttackState.WalkBack);
  1007. velocity.x = attackMoveSpeed;
  1008. rb.velocity = velocity;
  1009. break;
  1010. }
  1011. else if (leftDir.x < -0.3f)
  1012. {
  1013. SetAttackState(PlayerAttackState.WalkForward);
  1014. velocity.x = -attackMoveSpeed;
  1015. rb.velocity = velocity;
  1016. break;
  1017. }
  1018. }
  1019. else
  1020. {
  1021. if (leftDir.x > 0.3f)
  1022. {
  1023. SetAttackState(PlayerAttackState.WalkForward);
  1024. velocity.x = attackMoveSpeed;
  1025. rb.velocity = velocity;
  1026. break;
  1027. }
  1028. else if (leftDir.x < -0.3f)
  1029. {
  1030. SetAttackState(PlayerAttackState.WalkBack);
  1031. velocity.x = -attackMoveSpeed;
  1032. rb.velocity = velocity;
  1033. break;
  1034. }
  1035. }
  1036. velocity.x = 0;
  1037. rb.velocity = velocity;
  1038. break;
  1039. case PlayerAttackState.WalkForward:
  1040. if (bodyTrans.localScale.x > 0)
  1041. {
  1042. if (leftDir.x > 0.3f)
  1043. {
  1044. SetAttackState(PlayerAttackState.WalkBack);
  1045. velocity.x = attackMoveSpeed;
  1046. rb.velocity = velocity;
  1047. break;
  1048. }
  1049. else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
  1050. {
  1051. SetAttackState(PlayerAttackState.Idle);
  1052. velocity.x = 0;
  1053. rb.velocity = velocity;
  1054. break;
  1055. }
  1056. else
  1057. {
  1058. velocity.x = -attackMoveSpeed;
  1059. rb.velocity = velocity;
  1060. }
  1061. }
  1062. else
  1063. {
  1064. if (leftDir.x < -0.3f)
  1065. {
  1066. SetAttackState(PlayerAttackState.WalkBack);
  1067. velocity.x = -attackMoveSpeed;
  1068. rb.velocity = velocity;
  1069. break;
  1070. }
  1071. else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
  1072. {
  1073. SetAttackState(PlayerAttackState.Idle);
  1074. velocity.x = 0;
  1075. rb.velocity = velocity;
  1076. break;
  1077. }
  1078. else
  1079. {
  1080. velocity.x = attackMoveSpeed;
  1081. rb.velocity = velocity;
  1082. }
  1083. }
  1084. break;
  1085. case PlayerAttackState.WalkBack:
  1086. if (bodyTrans.localScale.x > 0)
  1087. {
  1088. if (leftDir.x < -0.3f)
  1089. {
  1090. SetAttackState(PlayerAttackState.WalkForward);
  1091. velocity.x = -attackMoveSpeed;
  1092. rb.velocity = velocity;
  1093. break;
  1094. }
  1095. else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
  1096. {
  1097. SetAttackState(PlayerAttackState.Idle);
  1098. velocity.x = 0;
  1099. rb.velocity = velocity;
  1100. break;
  1101. }
  1102. else
  1103. {
  1104. velocity.x = attackMoveSpeed;
  1105. rb.velocity = velocity;
  1106. }
  1107. }
  1108. else
  1109. {
  1110. if (leftDir.x > 0.3f)
  1111. {
  1112. SetAttackState(PlayerAttackState.WalkForward);
  1113. velocity.x = attackMoveSpeed;
  1114. rb.velocity = velocity;
  1115. break;
  1116. }
  1117. else if (leftDir.x > -0.3f && leftDir.x > 0.3f)
  1118. {
  1119. SetAttackState(PlayerAttackState.Idle);
  1120. velocity.x = 0;
  1121. rb.velocity = velocity;
  1122. break;
  1123. }
  1124. else
  1125. {
  1126. velocity.x = -attackMoveSpeed;
  1127. rb.velocity = velocity;
  1128. }
  1129. }
  1130. break;
  1131. default:
  1132. break;
  1133. }
  1134. break;
  1135. case CharacterState.Summon:
  1136. if (summonTime <= 0)
  1137. {
  1138. if (CheckPlayerChangeState())
  1139. {
  1140. break;
  1141. }
  1142. }
  1143. rb.velocity = Vector3.right * velocityAddition;
  1144. break;
  1145. case CharacterState.Rush:
  1146. if (rushTime <= 0)
  1147. {
  1148. if (btnRushKeep)
  1149. {
  1150. ChangeState(CharacterState.Sprint);
  1151. break;
  1152. }
  1153. if (CheckPlayerChangeState())
  1154. {
  1155. break;
  1156. }
  1157. }
  1158. CachedPlayerInput();
  1159. //if (leftDir.magnitude < 0.3f)
  1160. //{
  1161. // if (bodyTrans.localScale.x > 0)
  1162. // {
  1163. // rushDir = Vector3.left;
  1164. // }
  1165. // else
  1166. // {
  1167. // rushDir = Vector3.right;
  1168. // }
  1169. //}
  1170. //else
  1171. //{
  1172. // rushDir = leftDir.normalized;
  1173. //}
  1174. rb.velocity = rushDir * rushSpeed;
  1175. break;
  1176. case CharacterState.Sprint:
  1177. if (!btnRushKeep)
  1178. {
  1179. if (CheckPlayerChangeState(CharacterState.Rush))
  1180. {
  1181. break;
  1182. }
  1183. }
  1184. if (mp < sprintCostMp * Time.deltaTime)
  1185. {
  1186. if (CheckPlayerChangeState(CharacterState.Rush))
  1187. {
  1188. break;
  1189. }
  1190. }
  1191. mp -= sprintCostMp * Time.deltaTime;
  1192. uiMp.Show(mp, totalMp);
  1193. CachedPlayerInput();
  1194. //CheckTurn();
  1195. //if (leftDir.magnitude < 0.3f)
  1196. //{
  1197. // if (bodyTrans.localScale.x > 0)
  1198. // {
  1199. // rushDir = Vector3.left;
  1200. // }
  1201. // else
  1202. // {
  1203. // rushDir = Vector3.right;
  1204. // }
  1205. //}
  1206. //else
  1207. //{
  1208. // rushDir = leftDir.normalized;
  1209. //}
  1210. rb.velocity = rushDir * rushSpeed;
  1211. break;
  1212. case CharacterState.Die:
  1213. if (dieKeepTime <= 0)
  1214. {
  1215. if (isRevive)
  1216. {
  1217. reviveTime += Time.deltaTime;
  1218. if(reviveTime >= totalReviveTime)
  1219. {
  1220. PlayerRevive();
  1221. }
  1222. }
  1223. else
  1224. {
  1225. PlayerDie();
  1226. }
  1227. }
  1228. break;
  1229. case CharacterState.Weak:
  1230. if (rb.velocity.magnitude > 1)
  1231. {
  1232. if (ani.GetCurrentAnimatorClipInfo(0)[0].clip.name != "hitted")
  1233. {
  1234. ani.Play("hitted", 0, 0);
  1235. aniCollider.Play("Hurt", 0, 0);
  1236. }
  1237. Vector3 vel = rb.velocity;
  1238. if (!canfly)
  1239. {
  1240. if (foot.TrigGround && vel.y < 0)
  1241. {
  1242. vel.y = 0;
  1243. }
  1244. else
  1245. {
  1246. vel += Vector3.up * extraFallGravity * Time.deltaTime;
  1247. }
  1248. }
  1249. vel.y = vel.y * (1 - decelerationRatio * Time.deltaTime);
  1250. vel.x = vel.x * (1 - decelerationRatio * Time.deltaTime);
  1251. rb.velocity = vel;
  1252. }
  1253. else
  1254. {
  1255. if (ani.GetCurrentAnimatorClipInfo(0)[0].clip.name != "weak")
  1256. {
  1257. ani.Play("weak", 0, 0);
  1258. aniCollider.Play("Weak", 0, 0);
  1259. rb.velocity = Vector3.zero;
  1260. weakTime = totalWeakTime;
  1261. }
  1262. rb.velocity = new Vector3(velocityAddition, rb.velocity.y, 0);
  1263. }
  1264. if (weakTime <= 0)
  1265. {
  1266. ChangeState(CharacterState.Idle);
  1267. break;
  1268. }
  1269. break;
  1270. case CharacterState.PullRope:
  1271. break;
  1272. default:
  1273. break;
  1274. }
  1275. if (!foot.TrigGround && !canfly)
  1276. {
  1277. if (rb.velocity.y > 0)
  1278. {
  1279. rb.velocity += Vector3.up * extraRiseGravity * Time.deltaTime;
  1280. }
  1281. else
  1282. {
  1283. rb.velocity += Vector3.up * extraFallGravity * Time.deltaTime;
  1284. }
  1285. }
  1286. isClickBtnRush = false;
  1287. isKeepBtnRush = false;
  1288. isClickBtnJump = false;
  1289. isClickBtnSouth = false;
  1290. isClickBtnEast = false;
  1291. isClickBtnNorth = false;
  1292. isClickBtnWest = false;
  1293. isSpiritSummon = false;
  1294. isSpiritSummon1 = false;
  1295. isSpiritSummon2 = false;
  1296. isSpiritSummon3 = false;
  1297. isClickBtnTransfigurate = false;
  1298. if (foot.TrigGround)
  1299. {
  1300. canJumpTime = leaveGroundCanJumpTime;
  1301. }
  1302. SearchTarget();
  1303. attackTarget = targetCharacter;
  1304. if (isMpRepel && floatState == 0)
  1305. {
  1306. if (mp < totalMp)
  1307. {
  1308. if (!isRapedReply)
  1309. {
  1310. mp += mpReplySpeed * Time.deltaTime;
  1311. }
  1312. else
  1313. {
  1314. mp += rapidReplySpeed * Time.deltaTime;
  1315. }
  1316. }
  1317. }
  1318. if (floatState != 0)
  1319. {
  1320. if (mp > 0)
  1321. {
  1322. lostMp += mpReplySpeed * Time.deltaTime;
  1323. mp -= mpReplySpeed * Time.deltaTime;
  1324. }
  1325. if (lostMp >= addMp)
  1326. {
  1327. Instantiate(soul, transform.position, new Quaternion(0, 0, 0, 0), null);
  1328. lostMp = 0;
  1329. }
  1330. }
  1331. if (mp > totalMp)
  1332. {
  1333. mp = totalMp;
  1334. }
  1335. if (mp < 0)
  1336. {
  1337. mp = 0;
  1338. }
  1339. uiMp.Show(mp, totalMp);
  1340. }
  1341. public void PlayerDie()
  1342. {
  1343. switch (playerId)
  1344. {
  1345. case 0:
  1346. SpiritSystem.isP1In = true;
  1347. SpiritSystem.isP1Out = false;
  1348. break;
  1349. case 1:
  1350. SpiritSystem.isP2In = true;
  1351. SpiritSystem.isP2Out = false;
  1352. break;
  1353. default:
  1354. break;
  1355. }
  1356. foot.trigGroundList.Clear();
  1357. bodyTrans.gameObject.SetActive(false);
  1358. uiHp.transform.parent.gameObject.SetActive(false);
  1359. rb.constraints = RigidbodyConstraints.FreezeAll;
  1360. isRevive = true;
  1361. reviveTime = 0;
  1362. }
  1363. public void PlayerRevive()
  1364. {
  1365. isRevive = false;
  1366. isBaseBtnOut = false;
  1367. bodyTrans.gameObject.SetActive(true);
  1368. uiHp.transform.parent.gameObject.SetActive(true);
  1369. rb.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotation;
  1370. transform.position = new Vector3(142 + 4 * playerId, 0, 0);
  1371. switch (playerId)
  1372. {
  1373. case 0:
  1374. SpiritSystem.isP1In = false;
  1375. SpiritSystem.isP1Out = true;
  1376. SpiritSystem.player1 = gameObject;
  1377. SpiritSystem.p1Spirits = GetComponent<Spirits>();
  1378. break;
  1379. case 1:
  1380. SpiritSystem.isP2In = false;
  1381. SpiritSystem.isP2Out = true;
  1382. SpiritSystem.player2 = gameObject;
  1383. SpiritSystem.p2Spirits = GetComponent<Spirits>();
  1384. break;
  1385. default:
  1386. break;
  1387. }
  1388. Init();
  1389. }
  1390. public bool isMpRepel = true;
  1391. public float rapidReplySpeed;
  1392. public bool isRapedReply;
  1393. public GameObject rapidReplyEffect;
  1394. public void RapidReplyMp()
  1395. {
  1396. isRapedReply = true;
  1397. rapidReplyEffect.SetActive(true);
  1398. }
  1399. public void NormalReplyMp()
  1400. {
  1401. isRapedReply = false;
  1402. rapidReplyEffect.SetActive(false);
  1403. }
  1404. public override void ChangeState(CharacterState newState)
  1405. {
  1406. if (state == newState)
  1407. {
  1408. return;
  1409. }
  1410. Vector3 velocity = rb.velocity;
  1411. switch (state)
  1412. {
  1413. case CharacterState.Idle:
  1414. break;
  1415. case CharacterState.Run:
  1416. velocity.x = 0;
  1417. break;
  1418. case CharacterState.Rise:
  1419. bodyCollider.SetActive(true);
  1420. break;
  1421. case CharacterState.Fall:
  1422. break;
  1423. //case CharacterState.Hurt:
  1424. // break;
  1425. case CharacterState.Coma:
  1426. canMove = true;
  1427. foreach (GameObject i in HitCols)
  1428. {
  1429. i.SetActive(true);
  1430. }
  1431. break;
  1432. case CharacterState.Attack:
  1433. aniCollider.Play("NotAttack", 1, 0);
  1434. break;
  1435. case CharacterState.KeepAttack:
  1436. aniCollider.Play("NotAttack", 1, 0);
  1437. break;
  1438. case CharacterState.Summon:
  1439. rb.isKinematic = false;
  1440. break;
  1441. case CharacterState.Transfiguration:
  1442. rb.isKinematic = false;
  1443. break;
  1444. case CharacterState.Rush:
  1445. velocity = Vector3.zero;
  1446. break;
  1447. case CharacterState.Sprint:
  1448. velocity = Vector3.zero;
  1449. break;
  1450. case CharacterState.Die:
  1451. if(isRevive)
  1452. {
  1453. return;
  1454. }
  1455. isDie = false;
  1456. break;
  1457. case CharacterState.Weak:
  1458. beRepelValue = totalBeRepelValue;
  1459. break;
  1460. default:
  1461. break;
  1462. }
  1463. CharacterState oldState = state;
  1464. state = newState;
  1465. switch (newState)
  1466. {
  1467. case CharacterState.Idle:
  1468. aniCollider.Play("Idle", 0, 0);
  1469. if (oldState == CharacterState.Fall)
  1470. {
  1471. ani.Play("fall_end", 0, 0);
  1472. }
  1473. else
  1474. {
  1475. ani.Play("idle", 0, 0);
  1476. }
  1477. velocity = Vector3.right * velocityAddition;
  1478. //animalAni.SetInteger("state", (int)PlayerState.Idle);
  1479. break;
  1480. case CharacterState.Run:
  1481. aniCollider.Play("Run", 0, 0);
  1482. ani.Play("run_start", 0, 0);
  1483. //animalAni.SetInteger("state", (int)PlayerState.Walk);
  1484. break;
  1485. case CharacterState.Rise:
  1486. aniCollider.Play("Rise", 0, 0);
  1487. canJumpTime = 0;
  1488. break;
  1489. case CharacterState.Fall:
  1490. aniCollider.Play("Fall", 0, 0);
  1491. ani.Play("fall", 0, 0);
  1492. //animalAni.SetInteger("state", (int)PlayerState.Fall);
  1493. break;
  1494. //case CharacterState.Hurt:
  1495. // aniCollider.Play("Hurt", 0, 0);
  1496. // ani.Play("hitted", 0, 0);
  1497. // invincibleTime = totalInvincibleTime;
  1498. // hurtKeepTime = minHurtKeepTime;
  1499. // //ani.Play("Invincible", 2, 0);
  1500. // break;
  1501. case CharacterState.Coma:
  1502. //ani.Play("Coma", 0, 0);
  1503. ani.Play("idle", 0, 0);
  1504. aniCollider.Play("Idle", 0, 0);
  1505. rb.velocity = Vector3.zero;
  1506. foreach (GameObject i in HitCols)
  1507. {
  1508. i.SetActive(false);
  1509. }
  1510. break;
  1511. case CharacterState.Attack:
  1512. attackTime = totalAttack1Time;
  1513. break;
  1514. case CharacterState.KeepAttack:
  1515. aniCollider.Play("Attack1Keep", 1, 0);
  1516. break;
  1517. case CharacterState.Summon:
  1518. aniCollider.Play("Summon", 0, 0);
  1519. ani.Play("summon", 0, 0);
  1520. velocity = Vector3.right * velocityAddition;
  1521. rb.isKinematic = true;
  1522. break;
  1523. case CharacterState.Transfiguration:
  1524. isTransfiguration = true;
  1525. aniCollider.Play("Transfiguration", 0, 0);
  1526. ani.Play("transfiguration", 0, 0);
  1527. velocity = Vector3.zero;
  1528. rb.isKinematic = true;
  1529. break;
  1530. case CharacterState.Rush:
  1531. aniCollider.Play("Rush", 0, 0);
  1532. ani.Play("rush_loop", 0, 0);
  1533. rushTime = totalRushTime;
  1534. invincibleTime = rushInvincibleTime;
  1535. //if (leftDir.magnitude < 0.3f)
  1536. //{
  1537. // if (bodyTrans.localScale.x > 0)
  1538. // {
  1539. // rushDir = Vector3.left;
  1540. // }
  1541. // else
  1542. // {
  1543. // rushDir = Vector3.right;
  1544. // }
  1545. //}
  1546. //else
  1547. //{
  1548. // rushDir = leftDir.normalized;
  1549. //}
  1550. if (bodyTrans.localScale.x > 0)
  1551. {
  1552. rushDir = Vector3.left;
  1553. }
  1554. else
  1555. {
  1556. rushDir = Vector3.right;
  1557. }
  1558. velocity = rushDir * rushSpeed;
  1559. mp -= rushCostMp;
  1560. uiMp.Show(mp, totalMp);
  1561. break;
  1562. case CharacterState.Sprint:
  1563. aniCollider.Play("Sprint", 0, 0);
  1564. ani.Play("rush_loop", 0, 0);
  1565. velocity = rushDir * rushSpeed;
  1566. break;
  1567. case CharacterState.Die:
  1568. if (isTransfiguration)
  1569. {
  1570. EndTransfiguration(endChange);
  1571. }
  1572. else
  1573. {
  1574. aniCollider.Play("Die", 0, 0);
  1575. ani.Play("die", 0, 0);
  1576. isDie = true;
  1577. dieKeepTime = totalDieKeepTime;
  1578. }
  1579. break;
  1580. case CharacterState.Weak:
  1581. weakTime = totalWeakTime;
  1582. //hurtKeepTime = minHurtKeepTime;
  1583. break;
  1584. default:
  1585. break;
  1586. }
  1587. rb.velocity = velocity;
  1588. }
  1589. public void CheckTurn()
  1590. {
  1591. if (leftDir.x > 0.3f && bodyTrans.localScale.x > 0)
  1592. {
  1593. Turn();
  1594. }
  1595. else if (leftDir.x < -0.3f && bodyTrans.localScale.x < 0)
  1596. {
  1597. Turn();
  1598. }
  1599. }
  1600. public float maxFlyHeight;
  1601. public Vector3 AirMove(Vector3 velocity)
  1602. {
  1603. CheckTurn();
  1604. if (canfly)
  1605. {
  1606. velocity = leftDir.normalized * flySpeed;
  1607. if (transform.position.y > maxFlyHeight && velocity.y > 0)
  1608. {
  1609. velocity.y = 0;
  1610. }
  1611. }
  1612. else
  1613. {
  1614. if (leftDir.x > 0.3f)
  1615. {
  1616. velocity = new Vector3(moveSpeed, velocity.y, velocity.z);
  1617. }
  1618. else if (leftDir.x < -0.3f)
  1619. {
  1620. velocity = new Vector3(-moveSpeed, velocity.y, velocity.z);
  1621. }
  1622. else
  1623. {
  1624. velocity = new Vector3(0, velocity.y, velocity.z);
  1625. }
  1626. }
  1627. return velocity;
  1628. }
  1629. private Collider playerSoulCollector;
  1630. public void Transfiguration(int id) //变身
  1631. {
  1632. playerSoulCollector = soulCollector;
  1633. id = id - 3;
  1634. currentSpirit = id;
  1635. if (id >= changePrefabs.Count)
  1636. {
  1637. Debug.LogError("未配置" + id + "号变身");
  1638. return;
  1639. }
  1640. GameObject prefab = changePrefabs[id];
  1641. ChangeState(CharacterState.Transfiguration);
  1642. summonTime = prefab.GetComponent<Demonic>().totalSummonTime;
  1643. bodyTrans.gameObject.SetActive(false);
  1644. foot.trigGroundList.Clear();
  1645. spiritObj = PoolManager.Instantiate(prefab);
  1646. Demonic dem = spiritObj.GetComponent<Demonic>();
  1647. dem.id = id;
  1648. dem.playerID = playerId;
  1649. spiritObj.transform.parent = transform;
  1650. spiritObj.transform.localEulerAngles = Vector3.zero;
  1651. spiritObj.transform.localScale = new Vector3(1, 1, 1);
  1652. if (bodyTrans.localScale.x > 0)
  1653. {
  1654. spiritObj.transform.position = transform.position;
  1655. if (dem.bodyTrans.localScale.x < 0)
  1656. {
  1657. dem.Turn();
  1658. }
  1659. }
  1660. else
  1661. {
  1662. spiritObj.transform.position = transform.position;
  1663. if (dem.bodyTrans.localScale.x > 0)
  1664. {
  1665. dem.Turn();
  1666. }
  1667. }
  1668. mecanim = dem.mecanim;
  1669. ani = dem.ani;
  1670. aniCollider = dem.aniCollider;
  1671. bodyTrans = dem.bodyTrans;
  1672. beSearchTrigger = dem.beSearchTrigger;
  1673. bulletPrefab = dem.bulletPrefab;
  1674. searchTrigger = dem.searchTrigger;
  1675. foot = dem.foot;
  1676. spinee = dem.spinee;
  1677. mesh = dem.mesh;
  1678. mats = dem.mats;
  1679. soulCollector = dem.soulCollector;
  1680. outlineMats = dem.outlineMats;
  1681. if (dem.canFly)
  1682. {
  1683. canfly = true;
  1684. canJump = false;
  1685. rb.useGravity = false;
  1686. }
  1687. /* 法师出场释放浮空场
  1688. if (id == 3)
  1689. {
  1690. if ((int)spirits.currentSpirit == 0)
  1691. {
  1692. if (!spiritObj.GetComponent<Demonic>().hasEffect)
  1693. {
  1694. spiritObj.GetComponent<Demonic>().hasEffect = true;
  1695. Instantiate(spirits.floatEffect, spiritObj.transform.position, new Quaternion(0, 0, 0, 0), spiritObj.transform);
  1696. }
  1697. }
  1698. }
  1699. */
  1700. endChange = id + 3;
  1701. curHp = hp;
  1702. curTotalHp = totalHp;
  1703. switch (playerId)
  1704. {
  1705. case 0:
  1706. hp = SpiritSystem.tranHp1;
  1707. totalHp = SpiritSystem.tranHp1;
  1708. break;
  1709. case 1:
  1710. hp = SpiritSystem.tranHp2;
  1711. totalHp = SpiritSystem.tranHp2;
  1712. break;
  1713. default:
  1714. break;
  1715. }
  1716. uiHp.Show(hp, totalHp);
  1717. ChangeState(CharacterState.Idle);
  1718. }
  1719. private int curHp;
  1720. private int curTotalHp;
  1721. public bool endTranSummon; //是否在结束变身后召唤英灵
  1722. public void EndTransfiguration(int id)
  1723. {
  1724. isBaseBtnOut = false;
  1725. isTransfiguration = false;
  1726. canfly = false;
  1727. canJump = true;
  1728. canMove = true;
  1729. rb.useGravity = true;
  1730. mecanim = playerMe;
  1731. ani = playerAni;
  1732. aniCollider = playerCol;
  1733. bodyTrans = playerTran;
  1734. beSearchTrigger = playerBst;
  1735. bulletPrefab = playerBullet;
  1736. searchTrigger = playerST;
  1737. foot = playerFoot;
  1738. spinee = playerSpinee;
  1739. mesh = playerMesh;
  1740. mats = playerMats;
  1741. soulCollector = playerSoulCollector;
  1742. outlineMats = playerOut;
  1743. bodyTrans.gameObject.SetActive(true);
  1744. hp = curHp;
  1745. totalHp = curTotalHp;
  1746. uiHp.Show(hp, totalHp);
  1747. uiHp.gameObject.SetActive(true);
  1748. spiritObj.transform.parent = null;
  1749. spiritObj.SetActive(false);
  1750. if (endTranSummon)
  1751. {
  1752. Summon(endChange);
  1753. }
  1754. CheckPlayerChangeState();
  1755. endChange = 0;
  1756. switch (playerId)
  1757. {
  1758. case 0:
  1759. SpiritSystem.isEndtran1 = true;
  1760. break;
  1761. case 1:
  1762. SpiritSystem.isEndtran2 = true;
  1763. break;
  1764. default:
  1765. break;
  1766. }
  1767. }
  1768. public bool canArrowHitFloat; //可以让弓箭手攻击概率漂浮
  1769. public float probability; //攻击的漂浮概率
  1770. public float gainAbilityProbability; //弓箭手获得漂浮能力的概率
  1771. public int abilityTimes; //弓箭手释放漂浮能力的次数
  1772. private bool isFirst = true;
  1773. public void Summon(int id)
  1774. {
  1775. if (id >= demonicPrefabs.Count)
  1776. {
  1777. Debug.LogError("未配置" + id + "号使魔");
  1778. return;
  1779. }
  1780. if (id >= demonicSummonPos.Count)
  1781. {
  1782. Debug.LogError("未配置" + id + "号使魔召唤位置");
  1783. return;
  1784. }
  1785. GameObject prefab = demonicPrefabs[id];
  1786. if (!CheckCanSummon(id))
  1787. {
  1788. return;
  1789. }
  1790. ChangeState(CharacterState.Summon);
  1791. summonTime = prefab.GetComponent<Demonic>().totalSummonTime;
  1792. float costMp = prefab.GetComponent<Demonic>().costMp;
  1793. mp -= costMp;
  1794. uiMp.Show(mp, totalMp);
  1795. GameObject demonicObj = PoolManager.Instantiate(prefab);
  1796. Demonic demonic = demonicObj.GetComponent<Demonic>();
  1797. if (canArrowHitFloat && id == 0)
  1798. {
  1799. float k = UnityEngine.Random.Range(0, 100);
  1800. if (isFirst || k <= gainAbilityProbability)
  1801. {
  1802. isFirst = false;
  1803. demonic.attackToFloat = true;
  1804. demonic.floatProbability = probability;
  1805. demonic.floatTimes = abilityTimes;
  1806. }
  1807. }
  1808. if (id == 2)
  1809. {
  1810. demonic.criticalChance = criticalChance;
  1811. demonic.criticalMultiplier = criticalMultiplier;
  1812. }
  1813. demonic.id = id;
  1814. demonic.playerID = playerId;
  1815. if (!demonicDic.ContainsKey(id))
  1816. {
  1817. demonicDic.Add(id, new List<Demonic>());
  1818. }
  1819. demonicDic[id].Add(demonic);
  1820. demonicObj.transform.parent = null;
  1821. demonicObj.transform.localEulerAngles = Vector3.zero;
  1822. demonicObj.transform.localScale = new Vector3(1, 1, 1);
  1823. Vector3 offset = demonicSummonPos[id];
  1824. if (bodyTrans.localScale.x > 0)
  1825. {
  1826. demonicObj.transform.position = transform.position + offset;
  1827. if (demonic.bodyTrans.localScale.x < 0)
  1828. {
  1829. demonic.Turn();
  1830. }
  1831. }
  1832. else
  1833. {
  1834. demonicObj.transform.position = transform.position + new Vector3(-offset.x, offset.y, offset.z);
  1835. if (demonic.bodyTrans.localScale.x > 0)
  1836. {
  1837. demonic.Turn();
  1838. }
  1839. }
  1840. if (demonic.canFly)
  1841. {
  1842. demonic.flyHeight = demonic.transform.position.y;
  1843. }
  1844. if (id == 3)
  1845. {
  1846. if ((int)spirits.currentSpirit == 0)
  1847. {
  1848. if (!demonicObj.GetComponent<Demonic>().hasEffect)
  1849. {
  1850. demonicObj.GetComponent<Demonic>().hasEffect = true;
  1851. Instantiate(spirits.floatEffect, demonicObj.transform.position, new Quaternion(0, 0, 0, 0), demonicObj.transform);
  1852. }
  1853. }
  1854. }
  1855. demonic.player = this;
  1856. demonic.Init();
  1857. demonic.SetSortingOrder(demonic.sortingOrder + demonicId[id]);
  1858. demonicId[id]++;
  1859. demonic.Attack1();
  1860. }
  1861. public void OnDemonicRecycle(Demonic demonic)
  1862. {
  1863. if (!demonicDic.ContainsKey(demonic.id))
  1864. {
  1865. return;
  1866. }
  1867. demonicDic[demonic.id].Remove(demonic);
  1868. for (int i = 0; i < demonicDic[demonic.id].Count; i++)
  1869. {
  1870. demonicDic[demonic.id][i].SetSortingOrder(demonic.id * 1000 + i);
  1871. }
  1872. }
  1873. public bool CheckCanSummon(int id)
  1874. {
  1875. GameObject prefab = demonicPrefabs[id];
  1876. float costMp = prefab.GetComponent<Demonic>().costMp;
  1877. if (mp < costMp)
  1878. {
  1879. Debug.Log("mp不足召唤失败, 还得加个动画或者音效啥的");
  1880. return false;
  1881. }
  1882. return true;
  1883. }
  1884. public override void Attack1()
  1885. {
  1886. base.Attack1();
  1887. if (leftDir.x > 0.3f)
  1888. {
  1889. if (bodyTrans.localScale.x > 0)
  1890. {
  1891. Turn();
  1892. }
  1893. SetAttackState(PlayerAttackState.WalkForward);
  1894. }
  1895. else if (leftDir.x < -0.3f)
  1896. {
  1897. if (bodyTrans.localScale.x < 0)
  1898. {
  1899. Turn();
  1900. }
  1901. SetAttackState(PlayerAttackState.WalkForward);
  1902. }
  1903. else
  1904. {
  1905. SetAttackState(PlayerAttackState.Idle);
  1906. }
  1907. }
  1908. public void SetAttackState(PlayerAttackState value)
  1909. {
  1910. attackState = value;
  1911. ani.SetInteger("attackState", (int)value);
  1912. aniCollider.Play("Attack1Keep", 1, 0);
  1913. }
  1914. public void SearchTarget()
  1915. {
  1916. targetCharacter = searchTrigger.GetMinDisTarget(targetTypes, canHitFly);
  1917. }
  1918. }