PlayerController.cs 58 KB

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