PlayerController.cs 54 KB

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