PlayerController.cs 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960
  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 (isTransfiguration && !canTranSummon)
  539. {
  540. return true;
  541. }
  542. Summon(1);
  543. return true;
  544. }
  545. if (btnEastPress)
  546. {
  547. if (!isBaseBtnOut)
  548. {
  549. if (isTransfiguration && !canTranSummon)
  550. {
  551. return true;
  552. }
  553. Summon(2);
  554. }
  555. else
  556. {
  557. switch (playerId)
  558. {
  559. case 0:
  560. SpiritSystem.isBbtnDown1 = true;
  561. break;
  562. case 1:
  563. SpiritSystem.isBbtnDown2 = true;
  564. break;
  565. default:
  566. break;
  567. }
  568. }
  569. return true;
  570. }
  571. if (btnTransfiguratePress)
  572. {
  573. if (!isTransfiguration)
  574. {
  575. switch (playerId)
  576. {
  577. case 0:
  578. SpiritSystem.isSelect1 = true;
  579. break;
  580. case 1:
  581. SpiritSystem.isSelect2 = true;
  582. break;
  583. default:
  584. break;
  585. }
  586. if (spirits.currentSpirit != Spirits.SpiritType.None)
  587. {
  588. Transfiguration((int)spirits.currentSpirit + 3);
  589. }
  590. }
  591. else
  592. {
  593. isUltimate = true;
  594. keyTransfigurateRelease = false;
  595. }
  596. return true;
  597. }
  598. if (isSpiritSummon)
  599. {
  600. Transfiguration(3);
  601. return true;
  602. }
  603. if (isSpiritSummon1)
  604. {
  605. Transfiguration(4);
  606. return true;
  607. }
  608. if (isSpiritSummon2)
  609. {
  610. Transfiguration(5);
  611. return true;
  612. }
  613. if (isSpiritSummon3)
  614. {
  615. Transfiguration(6);
  616. return true;
  617. }
  618. return false;
  619. }
  620. //角色处于可自由活动状态时的通用切换状态逻辑,如Idle、Run状态,以及别的状态结束时准备回到Idle状态前
  621. public bool CheckPlayerChangeState(CharacterState excludeState = CharacterState.None)
  622. {
  623. if (!foot.TrigGround)
  624. {
  625. if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
  626. {
  627. if (excludeState != CharacterState.Rush)
  628. {
  629. ChangeState(CharacterState.Rush);
  630. return true;
  631. }
  632. }
  633. if (rb.velocity.y > 0)
  634. {
  635. if (excludeState != CharacterState.Rise)
  636. {
  637. ChangeState(CharacterState.Rise);
  638. return true;
  639. }
  640. }
  641. else
  642. {
  643. if (excludeState != CharacterState.Fall)
  644. {
  645. ChangeState(CharacterState.Fall);
  646. return true;
  647. }
  648. }
  649. }
  650. else
  651. {
  652. airJumped = 0;
  653. //if (btnNorthPress || cacheAttackTime > 0)
  654. //{
  655. // if (excludeState != CharacterState.Attack)
  656. // {
  657. // Attack1();
  658. // return true;
  659. // }
  660. //}
  661. if (eventTrigger.triggedRivet && (btnNorthPress || cachePullRopeTime > 0))
  662. {
  663. if (sprintLinkTrigger.linkedEnemy.Count > 0)
  664. {
  665. eventTrigger.triggedRivet.BindingRopes(sprintLinkTrigger.linkedEnemy);
  666. }
  667. //ChangeState(CharacterState.PullRope);
  668. }
  669. if (excludeState != CharacterState.Summon)
  670. {
  671. if (CheckSummon())
  672. {
  673. return true;
  674. }
  675. }
  676. if (excludeState != CharacterState.Transfiguration)
  677. {
  678. if (CheckSummon())
  679. {
  680. return true;
  681. }
  682. }
  683. if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
  684. {
  685. if (excludeState != CharacterState.Rush)
  686. {
  687. ChangeState(CharacterState.Rush);
  688. return true;
  689. }
  690. }
  691. if (btnJumpPress || cacheJumpTime > 0)
  692. {
  693. if (excludeState != CharacterState.Rise)
  694. {
  695. Jump();
  696. ChangeState(CharacterState.Rise);
  697. return true;
  698. }
  699. }
  700. if (canfly)
  701. {
  702. if (leftDir.x > 0.3f || leftDir.x < -0.3f || leftDir.y > 0.3f || leftDir.y < -0.3f)
  703. {
  704. if (excludeState != CharacterState.Run)
  705. {
  706. ChangeState(CharacterState.Run);
  707. return true;
  708. }
  709. }
  710. else
  711. {
  712. if (excludeState != CharacterState.Idle)
  713. {
  714. ChangeState(CharacterState.Idle);
  715. return true;
  716. }
  717. }
  718. }
  719. else
  720. {
  721. if (leftDir.x > 0.3f || leftDir.x < -0.3f)
  722. {
  723. if (excludeState != CharacterState.Run)
  724. {
  725. ChangeState(CharacterState.Run);
  726. return true;
  727. }
  728. }
  729. else
  730. {
  731. if (excludeState != CharacterState.Idle)
  732. {
  733. ChangeState(CharacterState.Idle);
  734. return true;
  735. }
  736. }
  737. }
  738. }
  739. return false;
  740. }
  741. public override Vector3 GetMoveDir()
  742. {
  743. return leftDir;
  744. }
  745. public void CachedPlayerInput()
  746. {
  747. if (btnRushPress)
  748. {
  749. cacheRushTime = totalCacheRushTime;
  750. }
  751. if (btnJumpPress)
  752. {
  753. cacheJumpTime = totalCacheJumpTime;
  754. }
  755. if (btnNorthPress)
  756. {
  757. cacheAttackTime = totalCacheAttackTime;
  758. }
  759. if (btnWestPress)
  760. {
  761. cacheSummonTime = totalCacheSummonTime;
  762. cacheSummonId = 0;
  763. }
  764. if (btnSouthPress)
  765. {
  766. cacheSummonTime = totalCacheSummonTime;
  767. cacheSummonId = 1;
  768. }
  769. if (btnEastPress)
  770. {
  771. cacheSummonTime = totalCacheSummonTime;
  772. cacheSummonId = 2;
  773. }
  774. if (btnSpiritSummon)
  775. {
  776. cacheSummonTime = totalCacheSummonTime;
  777. cacheSummonId = 3;
  778. }
  779. if (btnSpiritSummon1)
  780. {
  781. cacheSummonTime = totalCacheSummonTime;
  782. cacheSummonId = 4;
  783. }
  784. if (btnSpiritSummon2)
  785. {
  786. cacheSummonTime = totalCacheSummonTime;
  787. cacheSummonId = 5;
  788. }
  789. if (btnSpiritSummon3)
  790. {
  791. cacheSummonTime = totalCacheSummonTime;
  792. cacheSummonId = 6;
  793. }
  794. }
  795. public override void OnState()
  796. {
  797. base.OnState();
  798. hurtKeepTime -= Time.deltaTime;
  799. cacheJumpTime -= Time.deltaTime;
  800. cacheAttackTime -= Time.deltaTime;
  801. cacheSummonTime -= Time.deltaTime;
  802. canJumpTime -= Time.deltaTime;
  803. invincibleTime -= Time.deltaTime;
  804. attackTime -= Time.deltaTime;
  805. summonTime -= Time.deltaTime;
  806. rushTime -= Time.deltaTime;
  807. cacheRushTime -= Time.deltaTime;
  808. dieKeepTime -= Time.deltaTime;
  809. weakTime -= Time.deltaTime;
  810. Vector3 velocity = rb.velocity;
  811. switch (state)
  812. {
  813. case CharacterState.Idle:
  814. if (CheckPlayerChangeState(CharacterState.Idle))
  815. {
  816. break;
  817. }
  818. break;
  819. case CharacterState.Run:
  820. if (CheckPlayerChangeState(CharacterState.Run))
  821. {
  822. break;
  823. }
  824. CheckTurn();
  825. if (canfly)
  826. {
  827. rb.velocity = leftDir.normalized * moveSpeed;
  828. }
  829. else
  830. {
  831. if (leftDir.x > 0.3f)
  832. {
  833. rb.velocity = Vector3.right * moveSpeed;
  834. }
  835. else if (leftDir.x < -0.3f)
  836. {
  837. rb.velocity = Vector3.left * moveSpeed;
  838. }
  839. }
  840. break;
  841. case CharacterState.Rise:
  842. if (CheckSummon())
  843. {
  844. break;
  845. }
  846. if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
  847. {
  848. ChangeState(CharacterState.Rush);
  849. break;
  850. }
  851. if (rb.velocity.y <= 0)
  852. {
  853. ChangeState(CharacterState.Fall);
  854. break;
  855. }
  856. if (btnJumpPress || cacheJumpTime > 0)
  857. {
  858. if (airJumped == 0 && jumpNumber >= 2 && rb.velocity.y < airJumpSpeed)
  859. {
  860. airJumped = 1;
  861. AirJump();
  862. break;
  863. }
  864. if (airJumped == 1 && jumpNumber >= 3 && rb.velocity.y < airJumpSpeed)
  865. {
  866. airJumped = 2;
  867. AirJump();
  868. break;
  869. }
  870. isClickBtnJump = false;
  871. }
  872. CachedPlayerInput();
  873. rb.velocity = AirMove(rb.velocity);
  874. break;
  875. case CharacterState.Fall:
  876. if (CheckSummon())
  877. {
  878. break;
  879. }
  880. if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
  881. {
  882. ChangeState(CharacterState.Rush);
  883. break;
  884. }
  885. if (foot.TrigGround)
  886. {
  887. if (CheckPlayerChangeState())
  888. {
  889. break;
  890. }
  891. }
  892. //if (foot.canStepPlayers.Count > 0)
  893. //{
  894. // Jump(jumpSpeed / 2);
  895. // StepOther();
  896. // break;
  897. //}
  898. //if (foot.canStepEnemyList.Count > 0)
  899. //{
  900. // Jump(jumpSpeed / 2);
  901. // StepEnemy();
  902. // break;
  903. //}
  904. if (btnJumpPress || cacheJumpTime > 0)
  905. {
  906. if (canJumpTime > 0)
  907. {
  908. Jump();
  909. break;
  910. }
  911. else
  912. {
  913. switch (airJumped)
  914. {
  915. case 0:
  916. if(jumpNumber >= 2)
  917. {
  918. airJumped = 1;
  919. AirJump();
  920. }
  921. break;
  922. case 1:
  923. if(jumpNumber >= 3)
  924. {
  925. airJumped = 2;
  926. AirJump();
  927. }
  928. break;
  929. }
  930. }
  931. isClickBtnJump = false;
  932. }
  933. CachedPlayerInput();
  934. rb.velocity = AirMove(rb.velocity);
  935. break;
  936. case CharacterState.Hurt:
  937. if (hurtKeepTime <= 0 && rb.velocity.magnitude < hurtChangeVelocity)
  938. {
  939. if (CheckPlayerChangeState())
  940. {
  941. break;
  942. }
  943. }
  944. Vector3 vel = rb.velocity;
  945. if (!foot.TrigGround)
  946. {
  947. if (canfly)
  948. {
  949. vel.y = vel.y * (1 - decelerationRatio * Time.deltaTime);
  950. }
  951. else
  952. {
  953. vel += Vector3.up * extraFallGravity * Time.deltaTime;
  954. }
  955. }
  956. vel.x = vel.x * (1 - decelerationRatio * Time.deltaTime);
  957. rb.velocity = vel;
  958. CachedPlayerInput();
  959. break;
  960. case CharacterState.Coma:
  961. break;
  962. case CharacterState.Attack:
  963. if (attackTime <= 0)
  964. {
  965. if (btnNorthKeep)
  966. {
  967. ChangeState(CharacterState.KeepAttack);
  968. break;
  969. }
  970. if (CheckPlayerChangeState())
  971. {
  972. break;
  973. }
  974. }
  975. CachedPlayerInput();
  976. break;
  977. case CharacterState.KeepAttack:
  978. if ((btnRushPress) && mp >= rushCostMp)
  979. {
  980. ChangeState(CharacterState.Rush);
  981. break;
  982. }
  983. if (btnJumpPress && canJumpTime > 0)
  984. {
  985. Jump();
  986. break;
  987. }
  988. if (!btnNorthKeep)
  989. {
  990. if (CheckPlayerChangeState(CharacterState.Attack))
  991. {
  992. break;
  993. }
  994. }
  995. switch (attackState)
  996. {
  997. case PlayerAttackState.Idle:
  998. if (bodyTrans.localScale.x > 0)
  999. {
  1000. if (leftDir.x > 0.3f)
  1001. {
  1002. SetAttackState(PlayerAttackState.WalkBack);
  1003. velocity.x = attackMoveSpeed;
  1004. rb.velocity = velocity;
  1005. break;
  1006. }
  1007. else if (leftDir.x < -0.3f)
  1008. {
  1009. SetAttackState(PlayerAttackState.WalkForward);
  1010. velocity.x = -attackMoveSpeed;
  1011. rb.velocity = velocity;
  1012. break;
  1013. }
  1014. }
  1015. else
  1016. {
  1017. if (leftDir.x > 0.3f)
  1018. {
  1019. SetAttackState(PlayerAttackState.WalkForward);
  1020. velocity.x = attackMoveSpeed;
  1021. rb.velocity = velocity;
  1022. break;
  1023. }
  1024. else if (leftDir.x < -0.3f)
  1025. {
  1026. SetAttackState(PlayerAttackState.WalkBack);
  1027. velocity.x = -attackMoveSpeed;
  1028. rb.velocity = velocity;
  1029. break;
  1030. }
  1031. }
  1032. velocity.x = 0;
  1033. rb.velocity = velocity;
  1034. break;
  1035. case PlayerAttackState.WalkForward:
  1036. if (bodyTrans.localScale.x > 0)
  1037. {
  1038. if (leftDir.x > 0.3f)
  1039. {
  1040. SetAttackState(PlayerAttackState.WalkBack);
  1041. velocity.x = attackMoveSpeed;
  1042. rb.velocity = velocity;
  1043. break;
  1044. }
  1045. else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
  1046. {
  1047. SetAttackState(PlayerAttackState.Idle);
  1048. velocity.x = 0;
  1049. rb.velocity = velocity;
  1050. break;
  1051. }
  1052. else
  1053. {
  1054. velocity.x = -attackMoveSpeed;
  1055. rb.velocity = velocity;
  1056. }
  1057. }
  1058. else
  1059. {
  1060. if (leftDir.x < -0.3f)
  1061. {
  1062. SetAttackState(PlayerAttackState.WalkBack);
  1063. velocity.x = -attackMoveSpeed;
  1064. rb.velocity = velocity;
  1065. break;
  1066. }
  1067. else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
  1068. {
  1069. SetAttackState(PlayerAttackState.Idle);
  1070. velocity.x = 0;
  1071. rb.velocity = velocity;
  1072. break;
  1073. }
  1074. else
  1075. {
  1076. velocity.x = attackMoveSpeed;
  1077. rb.velocity = velocity;
  1078. }
  1079. }
  1080. break;
  1081. case PlayerAttackState.WalkBack:
  1082. if (bodyTrans.localScale.x > 0)
  1083. {
  1084. if (leftDir.x < -0.3f)
  1085. {
  1086. SetAttackState(PlayerAttackState.WalkForward);
  1087. velocity.x = -attackMoveSpeed;
  1088. rb.velocity = velocity;
  1089. break;
  1090. }
  1091. else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
  1092. {
  1093. SetAttackState(PlayerAttackState.Idle);
  1094. velocity.x = 0;
  1095. rb.velocity = velocity;
  1096. break;
  1097. }
  1098. else
  1099. {
  1100. velocity.x = attackMoveSpeed;
  1101. rb.velocity = velocity;
  1102. }
  1103. }
  1104. else
  1105. {
  1106. if (leftDir.x > 0.3f)
  1107. {
  1108. SetAttackState(PlayerAttackState.WalkForward);
  1109. velocity.x = attackMoveSpeed;
  1110. rb.velocity = velocity;
  1111. break;
  1112. }
  1113. else if (leftDir.x > -0.3f && leftDir.x > 0.3f)
  1114. {
  1115. SetAttackState(PlayerAttackState.Idle);
  1116. velocity.x = 0;
  1117. rb.velocity = velocity;
  1118. break;
  1119. }
  1120. else
  1121. {
  1122. velocity.x = -attackMoveSpeed;
  1123. rb.velocity = velocity;
  1124. }
  1125. }
  1126. break;
  1127. default:
  1128. break;
  1129. }
  1130. break;
  1131. case CharacterState.Summon:
  1132. if (summonTime <= 0)
  1133. {
  1134. if (CheckPlayerChangeState())
  1135. {
  1136. break;
  1137. }
  1138. }
  1139. break;
  1140. case CharacterState.Rush:
  1141. if (rushTime <= 0)
  1142. {
  1143. if (btnRushKeep)
  1144. {
  1145. ChangeState(CharacterState.Sprint);
  1146. break;
  1147. }
  1148. if (CheckPlayerChangeState())
  1149. {
  1150. break;
  1151. }
  1152. }
  1153. CachedPlayerInput();
  1154. //if (leftDir.magnitude < 0.3f)
  1155. //{
  1156. // if (bodyTrans.localScale.x > 0)
  1157. // {
  1158. // rushDir = Vector3.left;
  1159. // }
  1160. // else
  1161. // {
  1162. // rushDir = Vector3.right;
  1163. // }
  1164. //}
  1165. //else
  1166. //{
  1167. // rushDir = leftDir.normalized;
  1168. //}
  1169. rb.velocity = rushDir * rushSpeed;
  1170. break;
  1171. case CharacterState.Sprint:
  1172. if (!btnRushKeep)
  1173. {
  1174. if (CheckPlayerChangeState(CharacterState.Rush))
  1175. {
  1176. break;
  1177. }
  1178. }
  1179. if (mp < sprintCostMp * Time.deltaTime)
  1180. {
  1181. if (CheckPlayerChangeState(CharacterState.Rush))
  1182. {
  1183. break;
  1184. }
  1185. }
  1186. mp -= sprintCostMp * Time.deltaTime;
  1187. uiMp.Show(mp, totalMp);
  1188. CachedPlayerInput();
  1189. //CheckTurn();
  1190. //if (leftDir.magnitude < 0.3f)
  1191. //{
  1192. // if (bodyTrans.localScale.x > 0)
  1193. // {
  1194. // rushDir = Vector3.left;
  1195. // }
  1196. // else
  1197. // {
  1198. // rushDir = Vector3.right;
  1199. // }
  1200. //}
  1201. //else
  1202. //{
  1203. // rushDir = leftDir.normalized;
  1204. //}
  1205. rb.velocity = rushDir * rushSpeed;
  1206. break;
  1207. case CharacterState.Die:
  1208. if (dieKeepTime <= 0)
  1209. {
  1210. if (isRevive)
  1211. {
  1212. reviveTime += Time.deltaTime;
  1213. if(reviveTime >= totalReviveTime)
  1214. {
  1215. PlayerRevive();
  1216. }
  1217. }
  1218. else
  1219. {
  1220. PlayerDie();
  1221. }
  1222. }
  1223. break;
  1224. case CharacterState.Weak:
  1225. if (weakTime <= 0)
  1226. {
  1227. ChangeState(CharacterState.Idle);
  1228. break;
  1229. }
  1230. break;
  1231. case CharacterState.PullRope:
  1232. break;
  1233. default:
  1234. break;
  1235. }
  1236. if (!foot.TrigGround && !canfly)
  1237. {
  1238. if (rb.velocity.y > 0)
  1239. {
  1240. rb.velocity += Vector3.up * extraRiseGravity * Time.deltaTime;
  1241. }
  1242. else
  1243. {
  1244. rb.velocity += Vector3.up * extraFallGravity * Time.deltaTime;
  1245. }
  1246. }
  1247. isClickBtnRush = false;
  1248. isKeepBtnRush = false;
  1249. isClickBtnJump = false;
  1250. isClickBtnSouth = false;
  1251. isClickBtnEast = false;
  1252. isClickBtnNorth = false;
  1253. isClickBtnWest = false;
  1254. isSpiritSummon = false;
  1255. isSpiritSummon1 = false;
  1256. isSpiritSummon2 = false;
  1257. isSpiritSummon3 = false;
  1258. isClickBtnTransfigurate = false;
  1259. if (foot.TrigGround)
  1260. {
  1261. canJumpTime = leaveGroundCanJumpTime;
  1262. }
  1263. SearchTarget();
  1264. attackTarget = targetCharacter;
  1265. if (isMpRepel && floatState == 0)
  1266. {
  1267. if (mp < totalMp)
  1268. {
  1269. if (!isRapedReply)
  1270. {
  1271. mp += mpReplySpeed * Time.deltaTime;
  1272. }
  1273. else
  1274. {
  1275. mp += rapidReplySpeed * Time.deltaTime;
  1276. }
  1277. }
  1278. }
  1279. if (floatState != 0)
  1280. {
  1281. if (mp > 0)
  1282. {
  1283. lostMp += mpReplySpeed * Time.deltaTime;
  1284. mp -= mpReplySpeed * Time.deltaTime;
  1285. }
  1286. if (lostMp >= addMp)
  1287. {
  1288. Instantiate(soul, transform.position, new Quaternion(0, 0, 0, 0), null);
  1289. lostMp = 0;
  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. if (isTransfiguration)
  1318. {
  1319. isTransfiguration = false;
  1320. canfly = false;
  1321. canJump = true;
  1322. canMove = true;
  1323. rb.useGravity = true;
  1324. mecanim = playerMe;
  1325. ani = playerAni;
  1326. aniCollider = playerCol;
  1327. bodyTrans = playerTran;
  1328. beSearchTrigger = playerBst;
  1329. bulletPrefab = playerBullet;
  1330. searchTrigger = playerST;
  1331. foot = playerFoot;
  1332. spinee = playerSpinee;
  1333. mesh = playerMesh;
  1334. mats = playerMats;
  1335. soulCollector = playerSoulCollector;
  1336. outlineMats = playerOut;
  1337. spiritObj.transform.parent = null;
  1338. spiritObj.SetActive(false);
  1339. endChange = 0;
  1340. switch (playerId)
  1341. {
  1342. case 0:
  1343. SpiritSystem.isEndtran1 = true;
  1344. break;
  1345. case 1:
  1346. SpiritSystem.isEndtran2 = true;
  1347. break;
  1348. default:
  1349. break;
  1350. }
  1351. }
  1352. foot.trigGroundList.Clear();
  1353. bodyTrans.gameObject.SetActive(false);
  1354. uiHp.transform.parent.gameObject.SetActive(false);
  1355. rb.constraints = RigidbodyConstraints.FreezeAll;
  1356. isRevive = true;
  1357. reviveTime = 0;
  1358. }
  1359. public void PlayerRevive()
  1360. {
  1361. isRevive = false;
  1362. bodyTrans.gameObject.SetActive(true);
  1363. uiHp.transform.parent.gameObject.SetActive(true);
  1364. rb.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotation;
  1365. transform.position = new Vector3(142 + 4 * playerId, 0, 0);
  1366. switch (playerId)
  1367. {
  1368. case 0:
  1369. SpiritSystem.isP1In = false;
  1370. SpiritSystem.isP1Out = true;
  1371. SpiritSystem.player1 = gameObject;
  1372. SpiritSystem.p1Spirits = GetComponent<Spirits>();
  1373. break;
  1374. case 1:
  1375. SpiritSystem.isP2In = false;
  1376. SpiritSystem.isP2Out = true;
  1377. SpiritSystem.player2 = gameObject;
  1378. SpiritSystem.p2Spirits = GetComponent<Spirits>();
  1379. break;
  1380. default:
  1381. break;
  1382. }
  1383. Init();
  1384. }
  1385. public bool isMpRepel = true;
  1386. public float rapidReplySpeed;
  1387. public bool isRapedReply;
  1388. public void RapidReplyMp(float speed)
  1389. {
  1390. rapidReplySpeed = speed;
  1391. isRapedReply = true;
  1392. }
  1393. public void NormalReplyMp()
  1394. {
  1395. isRapedReply = false;
  1396. }
  1397. public override void ChangeState(CharacterState newState)
  1398. {
  1399. if (state == newState)
  1400. {
  1401. return;
  1402. }
  1403. Vector3 velocity = rb.velocity;
  1404. switch (state)
  1405. {
  1406. case CharacterState.Idle:
  1407. break;
  1408. case CharacterState.Run:
  1409. velocity.x = 0;
  1410. break;
  1411. case CharacterState.Rise:
  1412. bodyCollider.SetActive(true);
  1413. break;
  1414. case CharacterState.Fall:
  1415. break;
  1416. case CharacterState.Hurt:
  1417. break;
  1418. case CharacterState.Coma:
  1419. canMove = true;
  1420. foreach (GameObject i in HitCols)
  1421. {
  1422. i.SetActive(true);
  1423. }
  1424. break;
  1425. case CharacterState.Attack:
  1426. aniCollider.Play("NotAttack", 1, 0);
  1427. break;
  1428. case CharacterState.KeepAttack:
  1429. aniCollider.Play("NotAttack", 1, 0);
  1430. break;
  1431. case CharacterState.Summon:
  1432. rb.isKinematic = false;
  1433. break;
  1434. case CharacterState.Transfiguration:
  1435. rb.isKinematic = false;
  1436. break;
  1437. case CharacterState.Rush:
  1438. velocity = Vector3.zero;
  1439. break;
  1440. case CharacterState.Sprint:
  1441. velocity = Vector3.zero;
  1442. break;
  1443. case CharacterState.Die:
  1444. isDie = false;
  1445. break;
  1446. case CharacterState.Weak:
  1447. break;
  1448. default:
  1449. break;
  1450. }
  1451. CharacterState oldState = state;
  1452. state = newState;
  1453. switch (newState)
  1454. {
  1455. case CharacterState.Idle:
  1456. aniCollider.Play("Idle", 0, 0);
  1457. if (oldState == CharacterState.Fall)
  1458. {
  1459. ani.Play("fall_end", 0, 0);
  1460. }
  1461. else
  1462. {
  1463. ani.Play("idle", 0, 0);
  1464. }
  1465. velocity = Vector3.zero;
  1466. //animalAni.SetInteger("state", (int)PlayerState.Idle);
  1467. break;
  1468. case CharacterState.Run:
  1469. aniCollider.Play("Run", 0, 0);
  1470. ani.Play("run_start", 0, 0);
  1471. //animalAni.SetInteger("state", (int)PlayerState.Walk);
  1472. break;
  1473. case CharacterState.Rise:
  1474. aniCollider.Play("Rise", 0, 0);
  1475. canJumpTime = 0;
  1476. break;
  1477. case CharacterState.Fall:
  1478. aniCollider.Play("Fall", 0, 0);
  1479. ani.Play("fall", 0, 0);
  1480. //animalAni.SetInteger("state", (int)PlayerState.Fall);
  1481. break;
  1482. case CharacterState.Hurt:
  1483. aniCollider.Play("Hurt", 0, 0);
  1484. ani.Play("hitted", 0, 0);
  1485. invincibleTime = totalInvincibleTime;
  1486. hurtKeepTime = minHurtKeepTime;
  1487. //ani.Play("Invincible", 2, 0);
  1488. break;
  1489. case CharacterState.Coma:
  1490. //ani.Play("Coma", 0, 0);
  1491. ani.Play("idle", 0, 0);
  1492. aniCollider.Play("Idle", 0, 0);
  1493. rb.velocity = Vector3.zero;
  1494. foreach (GameObject i in HitCols)
  1495. {
  1496. i.SetActive(false);
  1497. }
  1498. break;
  1499. case CharacterState.Attack:
  1500. attackTime = totalAttack1Time;
  1501. break;
  1502. case CharacterState.KeepAttack:
  1503. aniCollider.Play("Attack1Keep", 1, 0);
  1504. break;
  1505. case CharacterState.Summon:
  1506. aniCollider.Play("Summon", 0, 0);
  1507. ani.Play("summon", 0, 0);
  1508. velocity = Vector3.zero;
  1509. rb.isKinematic = true;
  1510. break;
  1511. case CharacterState.Transfiguration:
  1512. isTransfiguration = true;
  1513. aniCollider.Play("Transfiguration", 0, 0);
  1514. ani.Play("transfiguration", 0, 0);
  1515. velocity = Vector3.zero;
  1516. rb.isKinematic = true;
  1517. break;
  1518. case CharacterState.Rush:
  1519. aniCollider.Play("Rush", 0, 0);
  1520. ani.Play("rush_loop", 0, 0);
  1521. rushTime = totalRushTime;
  1522. invincibleTime = rushInvincibleTime;
  1523. //if (leftDir.magnitude < 0.3f)
  1524. //{
  1525. // if (bodyTrans.localScale.x > 0)
  1526. // {
  1527. // rushDir = Vector3.left;
  1528. // }
  1529. // else
  1530. // {
  1531. // rushDir = Vector3.right;
  1532. // }
  1533. //}
  1534. //else
  1535. //{
  1536. // rushDir = leftDir.normalized;
  1537. //}
  1538. if (bodyTrans.localScale.x > 0)
  1539. {
  1540. rushDir = Vector3.left;
  1541. }
  1542. else
  1543. {
  1544. rushDir = Vector3.right;
  1545. }
  1546. velocity = rushDir * rushSpeed;
  1547. mp -= rushCostMp;
  1548. uiMp.Show(mp, totalMp);
  1549. break;
  1550. case CharacterState.Sprint:
  1551. aniCollider.Play("Sprint", 0, 0);
  1552. ani.Play("rush_loop", 0, 0);
  1553. velocity = rushDir * rushSpeed;
  1554. break;
  1555. case CharacterState.Die:
  1556. aniCollider.Play("Die", 0, 0);
  1557. ani.Play("die", 0, 0);
  1558. isDie = true;
  1559. dieKeepTime = totalDieKeepTime;
  1560. break;
  1561. case CharacterState.Weak:
  1562. aniCollider.Play("Weak", 0, 0);
  1563. ani.Play("weak", 0, 0);
  1564. velocity.y = weakUpSpeed;
  1565. weakTime = totalWeakTime;
  1566. break;
  1567. default:
  1568. break;
  1569. }
  1570. rb.velocity = velocity;
  1571. }
  1572. public void CheckTurn()
  1573. {
  1574. if (leftDir.x > 0.3f && bodyTrans.localScale.x > 0)
  1575. {
  1576. Turn();
  1577. }
  1578. else if (leftDir.x < -0.3f && bodyTrans.localScale.x < 0)
  1579. {
  1580. Turn();
  1581. }
  1582. }
  1583. public float maxFlyHeight;
  1584. public Vector3 AirMove(Vector3 velocity)
  1585. {
  1586. CheckTurn();
  1587. if (canfly)
  1588. {
  1589. velocity = leftDir.normalized * flySpeed;
  1590. if (transform.position.y > maxFlyHeight && velocity.y > 0)
  1591. {
  1592. velocity.y = 0;
  1593. }
  1594. }
  1595. else
  1596. {
  1597. if (leftDir.x > 0.3f)
  1598. {
  1599. velocity = new Vector3(moveSpeed, velocity.y, velocity.z);
  1600. }
  1601. else if (leftDir.x < -0.3f)
  1602. {
  1603. velocity = new Vector3(-moveSpeed, velocity.y, velocity.z);
  1604. }
  1605. else
  1606. {
  1607. velocity = new Vector3(0, velocity.y, velocity.z);
  1608. }
  1609. }
  1610. return velocity;
  1611. }
  1612. private Collider playerSoulCollector;
  1613. public void Transfiguration(int id) //变身
  1614. {
  1615. playerSoulCollector = soulCollector;
  1616. id = id - 3;
  1617. currentSpirit = id;
  1618. if (id >= changePrefabs.Count)
  1619. {
  1620. Debug.LogError("未配置" + id + "号变身");
  1621. return;
  1622. }
  1623. GameObject prefab = changePrefabs[id];
  1624. ChangeState(CharacterState.Transfiguration);
  1625. summonTime = prefab.GetComponent<Demonic>().totalSummonTime;
  1626. bodyTrans.gameObject.SetActive(false);
  1627. foot.trigGroundList.Clear();
  1628. spiritObj = PoolManager.Instantiate(prefab);
  1629. Demonic dem = spiritObj.GetComponent<Demonic>();
  1630. dem.id = id;
  1631. dem.playerID = playerId;
  1632. spiritObj.transform.parent = transform;
  1633. spiritObj.transform.localEulerAngles = Vector3.zero;
  1634. spiritObj.transform.localScale = new Vector3(1, 1, 1);
  1635. if (bodyTrans.localScale.x > 0)
  1636. {
  1637. spiritObj.transform.position = transform.position;
  1638. if (dem.bodyTrans.localScale.x < 0)
  1639. {
  1640. dem.Turn();
  1641. }
  1642. }
  1643. else
  1644. {
  1645. spiritObj.transform.position = transform.position;
  1646. if (dem.bodyTrans.localScale.x > 0)
  1647. {
  1648. dem.Turn();
  1649. }
  1650. }
  1651. mecanim = dem.mecanim;
  1652. ani = dem.ani;
  1653. aniCollider = dem.aniCollider;
  1654. bodyTrans = dem.bodyTrans;
  1655. beSearchTrigger = dem.beSearchTrigger;
  1656. bulletPrefab = dem.bulletPrefab;
  1657. searchTrigger = dem.searchTrigger;
  1658. foot = dem.foot;
  1659. spinee = dem.spinee;
  1660. mesh = dem.mesh;
  1661. mats = dem.mats;
  1662. soulCollector = dem.soulCollector;
  1663. outlineMats = dem.outlineMats;
  1664. if (dem.canFly)
  1665. {
  1666. canfly = true;
  1667. canJump = false;
  1668. rb.useGravity = false;
  1669. }
  1670. /* 法师出场释放浮空场
  1671. if (id == 3)
  1672. {
  1673. if ((int)spirits.currentSpirit == 0)
  1674. {
  1675. if (!spiritObj.GetComponent<Demonic>().hasEffect)
  1676. {
  1677. spiritObj.GetComponent<Demonic>().hasEffect = true;
  1678. Instantiate(spirits.floatEffect, spiritObj.transform.position, new Quaternion(0, 0, 0, 0), spiritObj.transform);
  1679. }
  1680. }
  1681. }
  1682. */
  1683. endChange = id + 3;
  1684. dem.hp = hp;
  1685. ChangeState(CharacterState.Idle);
  1686. }
  1687. public bool endTranSummon; //是否在结束变身后召唤英灵
  1688. public void EndTransfiguration(int id)
  1689. {
  1690. isTransfiguration = false;
  1691. canfly = false;
  1692. canJump = true;
  1693. canMove = true;
  1694. rb.useGravity = true;
  1695. mecanim = playerMe;
  1696. ani = playerAni;
  1697. aniCollider = playerCol;
  1698. bodyTrans = playerTran;
  1699. beSearchTrigger = playerBst;
  1700. bulletPrefab = playerBullet;
  1701. searchTrigger = playerST;
  1702. foot = playerFoot;
  1703. spinee = playerSpinee;
  1704. mesh = playerMesh;
  1705. mats = playerMats;
  1706. soulCollector = playerSoulCollector;
  1707. outlineMats = playerOut;
  1708. bodyTrans.gameObject.SetActive(true);
  1709. uiHp.gameObject.SetActive(true);
  1710. spiritObj.transform.parent = null;
  1711. spiritObj.SetActive(false);
  1712. if (endTranSummon)
  1713. {
  1714. Summon(endChange);
  1715. }
  1716. CheckPlayerChangeState();
  1717. endChange = 0;
  1718. switch (playerId)
  1719. {
  1720. case 0:
  1721. SpiritSystem.isEndtran1 = true;
  1722. break;
  1723. case 1:
  1724. SpiritSystem.isEndtran2 = true;
  1725. break;
  1726. default:
  1727. break;
  1728. }
  1729. }
  1730. public bool canArrowHitFloat; //可以让弓箭手攻击概率漂浮
  1731. public float probability; //攻击的漂浮概率
  1732. public float gainAbilityProbability; //弓箭手获得漂浮能力的概率
  1733. public int abilityTimes; //弓箭手释放漂浮能力的次数
  1734. private bool isFirst = true;
  1735. public void Summon(int id)
  1736. {
  1737. if (id >= demonicPrefabs.Count)
  1738. {
  1739. Debug.LogError("未配置" + id + "号使魔");
  1740. return;
  1741. }
  1742. if (id >= demonicSummonPos.Count)
  1743. {
  1744. Debug.LogError("未配置" + id + "号使魔召唤位置");
  1745. return;
  1746. }
  1747. GameObject prefab = demonicPrefabs[id];
  1748. if (!CheckCanSummon(id))
  1749. {
  1750. return;
  1751. }
  1752. ChangeState(CharacterState.Summon);
  1753. summonTime = prefab.GetComponent<Demonic>().totalSummonTime;
  1754. float costMp = prefab.GetComponent<Demonic>().costMp;
  1755. mp -= costMp;
  1756. uiMp.Show(mp, totalMp);
  1757. GameObject demonicObj = PoolManager.Instantiate(prefab);
  1758. Demonic demonic = demonicObj.GetComponent<Demonic>();
  1759. if (canArrowHitFloat && id == 0)
  1760. {
  1761. float k = UnityEngine.Random.Range(0, 100);
  1762. if (isFirst || k <= gainAbilityProbability)
  1763. {
  1764. isFirst = false;
  1765. demonic.attackToFloat = true;
  1766. demonic.floatProbability = probability;
  1767. demonic.floatTimes = abilityTimes;
  1768. }
  1769. }
  1770. if (id == 2)
  1771. {
  1772. demonic.criticalChance = criticalChance;
  1773. demonic.criticalMultiplier = criticalMultiplier;
  1774. }
  1775. demonic.id = id;
  1776. demonic.playerID = playerId;
  1777. if (!demonicDic.ContainsKey(id))
  1778. {
  1779. demonicDic.Add(id, new List<Demonic>());
  1780. }
  1781. demonicDic[id].Add(demonic);
  1782. demonicObj.transform.parent = null;
  1783. demonicObj.transform.localEulerAngles = Vector3.zero;
  1784. demonicObj.transform.localScale = new Vector3(1, 1, 1);
  1785. Vector3 offset = demonicSummonPos[id];
  1786. if (bodyTrans.localScale.x > 0)
  1787. {
  1788. demonicObj.transform.position = transform.position + offset;
  1789. if (demonic.bodyTrans.localScale.x < 0)
  1790. {
  1791. demonic.Turn();
  1792. }
  1793. }
  1794. else
  1795. {
  1796. demonicObj.transform.position = transform.position + new Vector3(-offset.x, offset.y, offset.z);
  1797. if (demonic.bodyTrans.localScale.x > 0)
  1798. {
  1799. demonic.Turn();
  1800. }
  1801. }
  1802. if (demonic.canFly)
  1803. {
  1804. demonic.flyHeight = demonic.transform.position.y;
  1805. }
  1806. if (id == 3)
  1807. {
  1808. if ((int)spirits.currentSpirit == 0)
  1809. {
  1810. if (!demonicObj.GetComponent<Demonic>().hasEffect)
  1811. {
  1812. demonicObj.GetComponent<Demonic>().hasEffect = true;
  1813. Instantiate(spirits.floatEffect, demonicObj.transform.position, new Quaternion(0, 0, 0, 0), demonicObj.transform);
  1814. }
  1815. }
  1816. }
  1817. demonic.player = this;
  1818. demonic.Init();
  1819. demonic.SetSortingOrder(demonic.sortingOrder + demonicId[id]);
  1820. demonicId[id]++;
  1821. demonic.Attack1();
  1822. }
  1823. public void OnDemonicRecycle(Demonic demonic)
  1824. {
  1825. if (!demonicDic.ContainsKey(demonic.id))
  1826. {
  1827. return;
  1828. }
  1829. demonicDic[demonic.id].Remove(demonic);
  1830. for (int i = 0; i < demonicDic[demonic.id].Count; i++)
  1831. {
  1832. demonicDic[demonic.id][i].SetSortingOrder(demonic.id * 1000 + i);
  1833. }
  1834. }
  1835. public bool CheckCanSummon(int id)
  1836. {
  1837. GameObject prefab = demonicPrefabs[id];
  1838. float costMp = prefab.GetComponent<Demonic>().costMp;
  1839. if (mp < costMp)
  1840. {
  1841. Debug.Log("mp不足召唤失败, 还得加个动画或者音效啥的");
  1842. return false;
  1843. }
  1844. return true;
  1845. }
  1846. public override void Attack1()
  1847. {
  1848. base.Attack1();
  1849. if (leftDir.x > 0.3f)
  1850. {
  1851. if (bodyTrans.localScale.x > 0)
  1852. {
  1853. Turn();
  1854. }
  1855. SetAttackState(PlayerAttackState.WalkForward);
  1856. }
  1857. else if (leftDir.x < -0.3f)
  1858. {
  1859. if (bodyTrans.localScale.x < 0)
  1860. {
  1861. Turn();
  1862. }
  1863. SetAttackState(PlayerAttackState.WalkForward);
  1864. }
  1865. else
  1866. {
  1867. SetAttackState(PlayerAttackState.Idle);
  1868. }
  1869. }
  1870. public void SetAttackState(PlayerAttackState value)
  1871. {
  1872. attackState = value;
  1873. ani.SetInteger("attackState", (int)value);
  1874. aniCollider.Play("Attack1Keep", 1, 0);
  1875. }
  1876. public void SearchTarget()
  1877. {
  1878. targetCharacter = searchTrigger.GetMinDisTarget(targetTypes, canHitFly);
  1879. }
  1880. }