PlayerController.cs 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008
  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. if(newState == CharacterState.Weak)
  1411. {
  1412. return;
  1413. }
  1414. Vector3 velocity = rb.velocity;
  1415. switch (state)
  1416. {
  1417. case CharacterState.Idle:
  1418. break;
  1419. case CharacterState.Run:
  1420. velocity.x = 0;
  1421. break;
  1422. case CharacterState.Rise:
  1423. bodyCollider.SetActive(true);
  1424. break;
  1425. case CharacterState.Fall:
  1426. break;
  1427. //case CharacterState.Hurt:
  1428. // break;
  1429. case CharacterState.Coma:
  1430. canMove = true;
  1431. foreach (GameObject i in HitCols)
  1432. {
  1433. i.SetActive(true);
  1434. }
  1435. break;
  1436. case CharacterState.Attack:
  1437. aniCollider.Play("NotAttack", 1, 0);
  1438. break;
  1439. case CharacterState.KeepAttack:
  1440. aniCollider.Play("NotAttack", 1, 0);
  1441. break;
  1442. case CharacterState.Summon:
  1443. rb.isKinematic = false;
  1444. break;
  1445. case CharacterState.Transfiguration:
  1446. rb.isKinematic = false;
  1447. break;
  1448. case CharacterState.Rush:
  1449. velocity = Vector3.zero;
  1450. break;
  1451. case CharacterState.Sprint:
  1452. velocity = Vector3.zero;
  1453. break;
  1454. case CharacterState.Die:
  1455. if(isRevive)
  1456. {
  1457. return;
  1458. }
  1459. isDie = false;
  1460. break;
  1461. case CharacterState.Weak:
  1462. beRepelValue = totalBeRepelValue;
  1463. break;
  1464. default:
  1465. break;
  1466. }
  1467. CharacterState oldState = state;
  1468. state = newState;
  1469. switch (newState)
  1470. {
  1471. case CharacterState.Idle:
  1472. aniCollider.Play("Idle", 0, 0);
  1473. if (oldState == CharacterState.Fall)
  1474. {
  1475. ani.Play("fall_end", 0, 0);
  1476. }
  1477. else
  1478. {
  1479. ani.Play("idle", 0, 0);
  1480. }
  1481. velocity = Vector3.right * velocityAddition;
  1482. //animalAni.SetInteger("state", (int)PlayerState.Idle);
  1483. break;
  1484. case CharacterState.Run:
  1485. aniCollider.Play("Run", 0, 0);
  1486. ani.Play("run_start", 0, 0);
  1487. //animalAni.SetInteger("state", (int)PlayerState.Walk);
  1488. break;
  1489. case CharacterState.Rise:
  1490. aniCollider.Play("Rise", 0, 0);
  1491. canJumpTime = 0;
  1492. break;
  1493. case CharacterState.Fall:
  1494. aniCollider.Play("Fall", 0, 0);
  1495. ani.Play("fall", 0, 0);
  1496. //animalAni.SetInteger("state", (int)PlayerState.Fall);
  1497. break;
  1498. //case CharacterState.Hurt:
  1499. // aniCollider.Play("Hurt", 0, 0);
  1500. // ani.Play("hitted", 0, 0);
  1501. // invincibleTime = totalInvincibleTime;
  1502. // hurtKeepTime = minHurtKeepTime;
  1503. // //ani.Play("Invincible", 2, 0);
  1504. // break;
  1505. case CharacterState.Coma:
  1506. //ani.Play("Coma", 0, 0);
  1507. ani.Play("idle", 0, 0);
  1508. aniCollider.Play("Idle", 0, 0);
  1509. rb.velocity = Vector3.zero;
  1510. foreach (GameObject i in HitCols)
  1511. {
  1512. i.SetActive(false);
  1513. }
  1514. break;
  1515. case CharacterState.Attack:
  1516. attackTime = totalAttack1Time;
  1517. break;
  1518. case CharacterState.KeepAttack:
  1519. aniCollider.Play("Attack1Keep", 1, 0);
  1520. break;
  1521. case CharacterState.Summon:
  1522. aniCollider.Play("Summon", 0, 0);
  1523. ani.Play("summon", 0, 0);
  1524. velocity = Vector3.right * velocityAddition;
  1525. rb.isKinematic = true;
  1526. break;
  1527. case CharacterState.Transfiguration:
  1528. isTransfiguration = true;
  1529. aniCollider.Play("Transfiguration", 0, 0);
  1530. ani.Play("transfiguration", 0, 0);
  1531. velocity = Vector3.zero;
  1532. rb.isKinematic = true;
  1533. break;
  1534. case CharacterState.Rush:
  1535. aniCollider.Play("Rush", 0, 0);
  1536. ani.Play("rush_loop", 0, 0);
  1537. rushTime = totalRushTime;
  1538. invincibleTime = rushInvincibleTime;
  1539. //if (leftDir.magnitude < 0.3f)
  1540. //{
  1541. // if (bodyTrans.localScale.x > 0)
  1542. // {
  1543. // rushDir = Vector3.left;
  1544. // }
  1545. // else
  1546. // {
  1547. // rushDir = Vector3.right;
  1548. // }
  1549. //}
  1550. //else
  1551. //{
  1552. // rushDir = leftDir.normalized;
  1553. //}
  1554. if (bodyTrans.localScale.x > 0)
  1555. {
  1556. rushDir = Vector3.left;
  1557. }
  1558. else
  1559. {
  1560. rushDir = Vector3.right;
  1561. }
  1562. velocity = rushDir * rushSpeed;
  1563. mp -= rushCostMp;
  1564. uiMp.Show(mp, totalMp);
  1565. break;
  1566. case CharacterState.Sprint:
  1567. aniCollider.Play("Sprint", 0, 0);
  1568. ani.Play("rush_loop", 0, 0);
  1569. velocity = rushDir * rushSpeed;
  1570. break;
  1571. case CharacterState.Die:
  1572. if (isTransfiguration)
  1573. {
  1574. EndTransfiguration(endChange);
  1575. }
  1576. else
  1577. {
  1578. aniCollider.Play("Die", 0, 0);
  1579. ani.Play("die", 0, 0);
  1580. isDie = true;
  1581. dieKeepTime = totalDieKeepTime;
  1582. }
  1583. break;
  1584. case CharacterState.Weak:
  1585. weakTime = totalWeakTime;
  1586. //hurtKeepTime = minHurtKeepTime;
  1587. break;
  1588. default:
  1589. break;
  1590. }
  1591. rb.velocity = velocity;
  1592. }
  1593. public void CheckTurn()
  1594. {
  1595. if (leftDir.x > 0.3f && bodyTrans.localScale.x > 0)
  1596. {
  1597. Turn();
  1598. }
  1599. else if (leftDir.x < -0.3f && bodyTrans.localScale.x < 0)
  1600. {
  1601. Turn();
  1602. }
  1603. }
  1604. public float maxFlyHeight;
  1605. public Vector3 AirMove(Vector3 velocity)
  1606. {
  1607. CheckTurn();
  1608. if (canfly)
  1609. {
  1610. velocity = leftDir.normalized * flySpeed;
  1611. if (transform.position.y > maxFlyHeight && velocity.y > 0)
  1612. {
  1613. velocity.y = 0;
  1614. }
  1615. }
  1616. else
  1617. {
  1618. if (leftDir.x > 0.3f)
  1619. {
  1620. velocity = new Vector3(moveSpeed, velocity.y, velocity.z);
  1621. }
  1622. else if (leftDir.x < -0.3f)
  1623. {
  1624. velocity = new Vector3(-moveSpeed, velocity.y, velocity.z);
  1625. }
  1626. else
  1627. {
  1628. velocity = new Vector3(0, velocity.y, velocity.z);
  1629. }
  1630. }
  1631. return velocity;
  1632. }
  1633. private Collider playerSoulCollector;
  1634. public void Transfiguration(int id) //变身
  1635. {
  1636. playerSoulCollector = soulCollector;
  1637. id = id - 3;
  1638. currentSpirit = id;
  1639. if (id >= changePrefabs.Count)
  1640. {
  1641. Debug.LogError("未配置" + id + "号变身");
  1642. return;
  1643. }
  1644. GameObject prefab = changePrefabs[id];
  1645. ChangeState(CharacterState.Transfiguration);
  1646. summonTime = prefab.GetComponent<Demonic>().totalSummonTime;
  1647. bodyTrans.gameObject.SetActive(false);
  1648. foot.trigGroundList.Clear();
  1649. spiritObj = PoolManager.Instantiate(prefab);
  1650. Demonic dem = spiritObj.GetComponent<Demonic>();
  1651. dem.id = id;
  1652. dem.playerID = playerId;
  1653. spiritObj.transform.parent = transform;
  1654. spiritObj.transform.localEulerAngles = Vector3.zero;
  1655. spiritObj.transform.localScale = new Vector3(1, 1, 1);
  1656. if (bodyTrans.localScale.x > 0)
  1657. {
  1658. spiritObj.transform.position = transform.position;
  1659. if (dem.bodyTrans.localScale.x < 0)
  1660. {
  1661. dem.Turn();
  1662. }
  1663. }
  1664. else
  1665. {
  1666. spiritObj.transform.position = transform.position;
  1667. if (dem.bodyTrans.localScale.x > 0)
  1668. {
  1669. dem.Turn();
  1670. }
  1671. }
  1672. mecanim = dem.mecanim;
  1673. ani = dem.ani;
  1674. aniCollider = dem.aniCollider;
  1675. bodyTrans = dem.bodyTrans;
  1676. beSearchTrigger = dem.beSearchTrigger;
  1677. bulletPrefab = dem.bulletPrefab;
  1678. searchTrigger = dem.searchTrigger;
  1679. foot = dem.foot;
  1680. spinee = dem.spinee;
  1681. mesh = dem.mesh;
  1682. mats = dem.mats;
  1683. soulCollector = dem.soulCollector;
  1684. outlineMats = dem.outlineMats;
  1685. if (dem.canFly)
  1686. {
  1687. canfly = true;
  1688. canJump = false;
  1689. rb.useGravity = false;
  1690. }
  1691. /* 法师出场释放浮空场
  1692. if (id == 3)
  1693. {
  1694. if ((int)spirits.currentSpirit == 0)
  1695. {
  1696. if (!spiritObj.GetComponent<Demonic>().hasEffect)
  1697. {
  1698. spiritObj.GetComponent<Demonic>().hasEffect = true;
  1699. Instantiate(spirits.floatEffect, spiritObj.transform.position, new Quaternion(0, 0, 0, 0), spiritObj.transform);
  1700. }
  1701. }
  1702. }
  1703. */
  1704. endChange = id + 3;
  1705. curHp = hp;
  1706. curTotalHp = totalHp;
  1707. switch (playerId)
  1708. {
  1709. case 0:
  1710. hp = SpiritSystem.tranHp1;
  1711. totalHp = SpiritSystem.tranHp1;
  1712. break;
  1713. case 1:
  1714. hp = SpiritSystem.tranHp2;
  1715. totalHp = SpiritSystem.tranHp2;
  1716. break;
  1717. default:
  1718. break;
  1719. }
  1720. uiHp.Show(hp, totalHp);
  1721. ChangeState(CharacterState.Idle);
  1722. }
  1723. private int curHp;
  1724. private int curTotalHp;
  1725. public bool endTranSummon; //是否在结束变身后召唤英灵
  1726. public void EndTransfiguration(int id)
  1727. {
  1728. isBaseBtnOut = false;
  1729. isTransfiguration = false;
  1730. canfly = false;
  1731. canJump = true;
  1732. canMove = true;
  1733. rb.useGravity = true;
  1734. mecanim = playerMe;
  1735. ani = playerAni;
  1736. aniCollider = playerCol;
  1737. bodyTrans = playerTran;
  1738. beSearchTrigger = playerBst;
  1739. bulletPrefab = playerBullet;
  1740. searchTrigger = playerST;
  1741. foot = playerFoot;
  1742. spinee = playerSpinee;
  1743. mesh = playerMesh;
  1744. mats = playerMats;
  1745. soulCollector = playerSoulCollector;
  1746. outlineMats = playerOut;
  1747. bodyTrans.gameObject.SetActive(true);
  1748. hp = curHp;
  1749. totalHp = curTotalHp;
  1750. uiHp.Show(hp, totalHp);
  1751. uiHp.gameObject.SetActive(true);
  1752. spiritObj.transform.parent = null;
  1753. spiritObj.SetActive(false);
  1754. if (endTranSummon)
  1755. {
  1756. Summon(endChange);
  1757. }
  1758. CheckPlayerChangeState();
  1759. endChange = 0;
  1760. switch (playerId)
  1761. {
  1762. case 0:
  1763. SpiritSystem.isEndtran1 = true;
  1764. break;
  1765. case 1:
  1766. SpiritSystem.isEndtran2 = true;
  1767. break;
  1768. default:
  1769. break;
  1770. }
  1771. }
  1772. public bool canArrowHitFloat; //可以让弓箭手攻击概率漂浮
  1773. public float probability; //攻击的漂浮概率
  1774. public float gainAbilityProbability; //弓箭手获得漂浮能力的概率
  1775. public int abilityTimes; //弓箭手释放漂浮能力的次数
  1776. private bool isFirst = true;
  1777. public void Summon(int id)
  1778. {
  1779. if (id >= demonicPrefabs.Count)
  1780. {
  1781. Debug.LogError("未配置" + id + "号使魔");
  1782. return;
  1783. }
  1784. if (id >= demonicSummonPos.Count)
  1785. {
  1786. Debug.LogError("未配置" + id + "号使魔召唤位置");
  1787. return;
  1788. }
  1789. GameObject prefab = demonicPrefabs[id];
  1790. if (!CheckCanSummon(id))
  1791. {
  1792. return;
  1793. }
  1794. ChangeState(CharacterState.Summon);
  1795. summonTime = prefab.GetComponent<Demonic>().totalSummonTime;
  1796. float costMp = prefab.GetComponent<Demonic>().costMp;
  1797. mp -= costMp;
  1798. uiMp.Show(mp, totalMp);
  1799. GameObject demonicObj = PoolManager.Instantiate(prefab);
  1800. Demonic demonic = demonicObj.GetComponent<Demonic>();
  1801. if (canArrowHitFloat && id == 0)
  1802. {
  1803. float k = UnityEngine.Random.Range(0, 100);
  1804. if (isFirst || k <= gainAbilityProbability)
  1805. {
  1806. isFirst = false;
  1807. demonic.attackToFloat = true;
  1808. demonic.floatProbability = probability;
  1809. demonic.floatTimes = abilityTimes;
  1810. }
  1811. }
  1812. if (id == 2)
  1813. {
  1814. demonic.criticalChance = criticalChance;
  1815. demonic.criticalMultiplier = criticalMultiplier;
  1816. }
  1817. demonic.id = id;
  1818. demonic.playerID = playerId;
  1819. if (!demonicDic.ContainsKey(id))
  1820. {
  1821. demonicDic.Add(id, new List<Demonic>());
  1822. }
  1823. demonicDic[id].Add(demonic);
  1824. demonicObj.transform.parent = null;
  1825. demonicObj.transform.localEulerAngles = Vector3.zero;
  1826. demonicObj.transform.localScale = new Vector3(1, 1, 1);
  1827. Vector3 offset = demonicSummonPos[id];
  1828. if (bodyTrans.localScale.x > 0)
  1829. {
  1830. demonicObj.transform.position = transform.position + offset;
  1831. if (demonic.bodyTrans.localScale.x < 0)
  1832. {
  1833. demonic.Turn();
  1834. }
  1835. }
  1836. else
  1837. {
  1838. demonicObj.transform.position = transform.position + new Vector3(-offset.x, offset.y, offset.z);
  1839. if (demonic.bodyTrans.localScale.x > 0)
  1840. {
  1841. demonic.Turn();
  1842. }
  1843. }
  1844. if (demonic.canFly)
  1845. {
  1846. demonic.flyHeight = demonic.transform.position.y;
  1847. }
  1848. if (id == 3)
  1849. {
  1850. if ((int)spirits.currentSpirit == 0)
  1851. {
  1852. if (!demonicObj.GetComponent<Demonic>().hasEffect)
  1853. {
  1854. demonicObj.GetComponent<Demonic>().hasEffect = true;
  1855. Instantiate(spirits.floatEffect, demonicObj.transform.position, new Quaternion(0, 0, 0, 0), demonicObj.transform);
  1856. }
  1857. }
  1858. }
  1859. demonic.player = this;
  1860. demonic.Init();
  1861. demonic.SetSortingOrder(demonic.sortingOrder + demonicId[id]);
  1862. demonicId[id]++;
  1863. demonic.Attack1();
  1864. }
  1865. public void OnDemonicRecycle(Demonic demonic)
  1866. {
  1867. if (!demonicDic.ContainsKey(demonic.id))
  1868. {
  1869. return;
  1870. }
  1871. demonicDic[demonic.id].Remove(demonic);
  1872. for (int i = 0; i < demonicDic[demonic.id].Count; i++)
  1873. {
  1874. demonicDic[demonic.id][i].SetSortingOrder(demonic.id * 1000 + i);
  1875. }
  1876. }
  1877. public bool CheckCanSummon(int id)
  1878. {
  1879. GameObject prefab = demonicPrefabs[id];
  1880. float costMp = prefab.GetComponent<Demonic>().costMp;
  1881. if (mp < costMp)
  1882. {
  1883. Debug.Log("mp不足召唤失败, 还得加个动画或者音效啥的");
  1884. return false;
  1885. }
  1886. return true;
  1887. }
  1888. public override void Attack1()
  1889. {
  1890. base.Attack1();
  1891. if (leftDir.x > 0.3f)
  1892. {
  1893. if (bodyTrans.localScale.x > 0)
  1894. {
  1895. Turn();
  1896. }
  1897. SetAttackState(PlayerAttackState.WalkForward);
  1898. }
  1899. else if (leftDir.x < -0.3f)
  1900. {
  1901. if (bodyTrans.localScale.x < 0)
  1902. {
  1903. Turn();
  1904. }
  1905. SetAttackState(PlayerAttackState.WalkForward);
  1906. }
  1907. else
  1908. {
  1909. SetAttackState(PlayerAttackState.Idle);
  1910. }
  1911. }
  1912. public void SetAttackState(PlayerAttackState value)
  1913. {
  1914. attackState = value;
  1915. ani.SetInteger("attackState", (int)value);
  1916. aniCollider.Play("Attack1Keep", 1, 0);
  1917. }
  1918. public void SearchTarget()
  1919. {
  1920. targetCharacter = searchTrigger.GetMinDisTarget(targetTypes, canHitFly);
  1921. }
  1922. }