PlayerController.cs 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using Spine.Unity;
  4. using Sirenix.OdinInspector;
  5. using UnityEngine.InputSystem;
  6. using TMPro;
  7. public enum PlayerAttackState
  8. {
  9. Idle = 0,
  10. WalkForward = 1,
  11. WalkBack = 2,
  12. }
  13. public class PlayerController : MoveCharacter
  14. {
  15. [Header("玩家属性")]
  16. public int playerId;
  17. public Vector2 pos;
  18. public bool canJump;
  19. public Animator aniCollider;
  20. [Header("玩家组件")]
  21. public UIHP uiMp;
  22. private Spirits spirits;
  23. public Collider soulCollector;
  24. public SkeletonMecanim skeletonMecanim;
  25. private SpiritSystem spiritSystem;
  26. private ScreenShake ss;
  27. private ConductController conductController;
  28. [Header("蓝耗")]
  29. public float mp;
  30. public float totalMp;
  31. public float totalMp_2Players; //双人模式下总蓝量
  32. public bool isMpRepel = true;
  33. public bool isRapedReply;
  34. public float mpReplySpeed;
  35. public float mpReplySpeed_2Players; //双人模式下蓝量回复速度
  36. public float rapidReplySpeed;
  37. public float lostMp;
  38. public float addMp = 10;
  39. public GameObject soul;
  40. public GameObject rapidReplyEffect;
  41. [Tooltip("场上每多一个同种类兵种,召唤兵种蓝耗+x")] public float[] addCostMp;
  42. [Header("移动属性")]
  43. public Vector2 moveVec; //玩家不动时移动数据
  44. [HideInInspector]
  45. public Vector2 leftDir;
  46. [Header("冲刺属性")]
  47. public float rushSpeed = 100;
  48. public float rushCostMp = 5;
  49. public Vector3 rushDir;
  50. public float rushInvincibleTime = 0.2f;
  51. [HideInInspector]
  52. public float rushTime;
  53. public float totalRushTime = 0.5f;
  54. [HideInInspector]
  55. public float cacheRushTime; //无法Rush时按下Rush键不会Rush,手感不好,缓存几帧,在这几帧内落地会立即Rush;
  56. public float totalCacheRushTime = 0.1f;
  57. public float sprintCostMp = 5;
  58. [Header("跳跃属性")]
  59. public float jumpSpeed = 10;
  60. public float airJumpSpeed = 10;
  61. public int airJumped;
  62. public int airJumpNumber = 1; //最大跳跃次数
  63. public float canAirJumpSpeed = 5;//y轴速度大于这个值时不能进行空中跳跃
  64. [HideInInspector]
  65. public float canJumpTime; //离开平台后仍然可以跳跃的时间,用于提升手感
  66. public float leaveGroundCanJumpTime = 0.1f;
  67. [HideInInspector]
  68. public float cacheJumpTime; //即将落地时按下跳跃键不会跳跃,手感不好,缓存几帧,在这几帧内落地会立即跳跃;
  69. public float totalCacheJumpTime = 0.1f;
  70. [Header("飞行属性")]
  71. public float flySpeed = 5;
  72. public float playerMaxFlyHeight;
  73. [Header("召唤属性")]
  74. public float totalSummonTime;
  75. [HideInInspector]
  76. public float summonTime;
  77. public float onlySummonTime;
  78. [HideInInspector]
  79. public float restSummonTime;
  80. private SoldierLevelRecord slr;
  81. [HideInInspector]
  82. public float cacheDir; //召唤的时候按左右召唤结束不会响应手感不好,缓存一下,召唤后摇期间有左右响应的话会转向
  83. [HideInInspector]
  84. public bool cacheRush; //召唤的时候按冲刺结束不会响应手感不好,缓存一下,召唤后摇期间按下冲刺的话会冲刺
  85. [HideInInspector]
  86. public float cacheSummonTime; //无法召唤时按下召唤键不会召唤,手感不好,缓存几帧,在这几帧内落地会立即召唤;
  87. [HideInInspector]
  88. public int cacheSummonId;
  89. [Header("召唤使魔")]
  90. public TextMeshProUGUI[] demonicNums;
  91. public GameObject[] cannotConductFXs;
  92. public List<GameObject> demonicPrefabs;
  93. public List<Vector3> demonicSummonPos;
  94. public Dictionary<int, List<Demonic>> demonicDic; //0:弓兵,1:胖子,2:棒子,3:融合后的弓兵,4:融合后的胖子,5:融合后的棒子
  95. [Header("攻击")]
  96. public PlayerAttackState attackState;
  97. public float attackMoveSpeed = 5f;
  98. [HideInInspector]
  99. public float cacheAttackTime; //无法攻击时按下攻击键不会攻击,手感不好,缓存几帧,在这几帧内落地会立即攻击;
  100. public float totalCacheAttackTime = 0.1f;
  101. [Header("复活")]
  102. public float reviveTime; //复活时间
  103. public float totalReviveTime;
  104. [Header("锁魂塔")]
  105. public GameObject curSoulTower;
  106. //指挥功能
  107. private float conductTime; //指挥按键长按时间
  108. private int nowConductButton = -1; //现在按下的指挥键(0.J/1.K/2.L/-1.无)
  109. private int cacheConductId;
  110. [Header("召唤相应时间")] [Tooltip("在此时间内松手为召唤")] public float totalCacheSummonTime;
  111. [Header("融魂相应时间")] [Tooltip("在此时间以外松手为融魂")] public float[] canConductTime;
  112. public bool[] conductCanRelease; //能否进入指挥技蓄力状态
  113. public ConductReadyTip conductReadyTip; //指挥技就绪
  114. private bool isReadyConduct;
  115. [Header("时间倍率")] [Tooltip("时间速度放慢到正常的几倍")] public float timeSlowingMultiplier;
  116. [DisplayOnly]public float fixedDeltaTime;
  117. public float readyTipFxTime;
  118. //攻击力
  119. [Header("增加攻击力特效")]
  120. public GameObject attackEffect;
  121. [Header("攻击力献祭比例")]
  122. public float addRate;
  123. //泰山压顶
  124. [Header("泰山压顶")]
  125. public GameObject mountain;
  126. public Vector3 mountainOffset;
  127. public float largeX;
  128. //气功波
  129. public GameObject wavePowerObj;
  130. [Header("气功波伤害基数")] public int wavePowerDamage;
  131. //御剑术
  132. public GameObject flyingSwordsObj;
  133. //怨气弹
  134. public GameObject angryBulletObj;
  135. [Header("怨气弹数量基数")] public int angryBulletNum;
  136. public bool btnJumpPress
  137. {
  138. get
  139. {
  140. //return Input.GetKeyDown(KeyCode.Space) || isClickBtnJump;
  141. return isClickBtnJump;
  142. }
  143. }
  144. [HideInInspector]
  145. public bool isClickBtnJump;
  146. public bool btnRushPress
  147. {
  148. get
  149. {
  150. //return Input.GetKeyDown(KeyCode.LeftShift) || isClickBtnRush;
  151. return isClickBtnRush;
  152. }
  153. }
  154. [HideInInspector]
  155. public bool isClickBtnRush;
  156. public bool btnRushKeep
  157. {
  158. get
  159. {
  160. //return Input.GetKey(KeyCode.LeftShift) || isKeepBtnRush;
  161. return LBisHold || isKeepBtnRush;
  162. }
  163. }
  164. [HideInInspector]
  165. public bool isKeepBtnRush;
  166. public bool btnEastPress
  167. {
  168. get
  169. {
  170. return isClickBtnEast;
  171. }
  172. }
  173. [HideInInspector]
  174. public bool isClickBtnEast;
  175. public bool btnEastUp
  176. {
  177. get
  178. {
  179. return isBtnEastUp;
  180. }
  181. }
  182. [HideInInspector]
  183. public bool isBtnEastUp;
  184. public bool btnSouthPress
  185. {
  186. get
  187. {
  188. //return Input.GetKeyDown(KeyCode.K) || isClickBtnSouth;
  189. return isClickBtnSouth;
  190. }
  191. }
  192. [HideInInspector]
  193. public bool isClickBtnSouth;
  194. public bool btnSouthUp
  195. {
  196. get
  197. {
  198. //return Input.GetKeyDown(KeyCode.K) || isClickBtnSouth;
  199. return isBtnSouthUp;
  200. }
  201. }
  202. [HideInInspector]
  203. public bool isBtnSouthUp;
  204. public bool btnWestPress
  205. {
  206. get
  207. {
  208. return isClickBtnWest;
  209. }
  210. }
  211. [HideInInspector]
  212. public bool isClickBtnWest;
  213. public bool btnWestUp
  214. {
  215. get
  216. {
  217. return isBtnWestUp;
  218. }
  219. }
  220. [HideInInspector]
  221. public bool isBtnWestUp;
  222. public bool btnNorthPress
  223. {
  224. get
  225. {
  226. return isClickBtnNorth;
  227. }
  228. }
  229. [HideInInspector]
  230. public bool isClickBtnNorth;
  231. public bool btnNorthUp
  232. {
  233. get
  234. {
  235. return isBtnNorthUp;
  236. }
  237. }
  238. [HideInInspector]
  239. public bool isBtnNorthUp;
  240. public bool btnSpiritSummon
  241. {
  242. get
  243. {
  244. //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
  245. return isSpiritSummon;
  246. }
  247. }
  248. [HideInInspector]
  249. public bool isSpiritSummon;
  250. public bool btnSpiritSummon1
  251. {
  252. get
  253. {
  254. //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
  255. return isSpiritSummon1;
  256. }
  257. }
  258. [HideInInspector]
  259. public bool isSpiritSummon1;
  260. public bool btnSpiritSummon2
  261. {
  262. get
  263. {
  264. //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
  265. return isSpiritSummon2;
  266. }
  267. }
  268. [HideInInspector]
  269. public bool isSpiritSummon2;
  270. public bool btnSpiritSummon3
  271. {
  272. get
  273. {
  274. //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
  275. return isSpiritSummon3;
  276. }
  277. }
  278. [HideInInspector]
  279. public bool isSpiritSummon3;
  280. public bool btnNorthKeep
  281. {
  282. get
  283. {
  284. //return Input.GetKey(KeyCode.I) || isKeepBtnNorth;
  285. return isKeepBtnNorth;
  286. }
  287. }
  288. [HideInInspector]
  289. public bool isKeepBtnNorth;
  290. public override void Init()
  291. {
  292. base.Init();
  293. uiHp = GameManager.instance.p1uiHP;
  294. uiMp = GameManager.instance.p1uiMP;
  295. uiMp.pc = this;
  296. mp = totalMp;
  297. uiMp.Show(mp, totalMp);
  298. demonicNums = new TextMeshProUGUI[3];
  299. for (int i = 0; i < 3; i++)
  300. {
  301. demonicNums[i] = GameManager.instance.demonicNum[i].GetComponentInChildren<TextMeshProUGUI>();
  302. }
  303. cannotConductFXs = new GameObject[3];
  304. for (int i = 0; i < 3; i++)
  305. {
  306. cannotConductFXs[i] = GameManager.instance.demonicNum[i].transform.GetChild(3).gameObject;
  307. }
  308. }
  309. public override void Awake()
  310. {
  311. base.Awake();
  312. PlayerInput playerInput = transform.GetComponent<PlayerInput>();
  313. ss = Camera.main.GetComponentInParent<ScreenShake>();
  314. spirits = GetComponent<Spirits>();
  315. conductController = GetComponent<ConductController>();
  316. playerId = playerInput.playerIndex;
  317. transform.position = new Vector3(pos.x, pos.y, 0);
  318. switch (playerId)
  319. {
  320. case 0:
  321. PlayersInput.instance[0] = this;
  322. PlayersInput.instance[1] = this;
  323. SpiritSystem.isP1Out = true;
  324. SpiritSystem.isP1In = false;
  325. SpiritSystem.player1 = gameObject;
  326. SpiritSystem.p1Spirits = GetComponent<Spirits>();
  327. break;
  328. case 1:
  329. PlayersInput.instance[1] = this;
  330. SpiritSystem.isP2Out = true;
  331. SpiritSystem.isP2In = false;
  332. SpiritSystem.player2 = gameObject;
  333. SpiritSystem.p2Spirits = GetComponent<Spirits>();
  334. //切换为双人计算蓝量方式
  335. PlayerController p1 = PlayersInput.instance[0];
  336. mpReplySpeed = mpReplySpeed_2Players;
  337. p1.mpReplySpeed = mpReplySpeed_2Players;
  338. totalMp = totalMp_2Players;
  339. p1.totalMp = totalMp_2Players;
  340. if (mp > totalMp)
  341. {
  342. mp = totalMp;
  343. }
  344. if (p1.mp > totalMp)
  345. {
  346. p1.mp = totalMp;
  347. }
  348. uiMp.Show(mp, totalMp);
  349. p1.uiMp.Show(p1.mp, totalMp);
  350. break;
  351. default:
  352. break;
  353. }
  354. demonicDic = new Dictionary<int, List<Demonic>>();
  355. for (int i = 0; i < 5; i++)
  356. {
  357. demonicDic.Add(i, new List<Demonic>());
  358. }
  359. Init();
  360. spiritSystem = GameObject.Find("SpiritSystem").GetComponent<SpiritSystem>();
  361. fixedDeltaTime = Time.fixedDeltaTime;
  362. }
  363. private void Start()
  364. {
  365. slr = GameManager.instance.GetComponent<SoldierLevelRecord>();
  366. }
  367. override public void Update()
  368. {
  369. if (LBisHold)
  370. {
  371. isKeepBtnRush = true;
  372. }
  373. }
  374. void OnSprintingPress()
  375. {
  376. LBisHold = true;
  377. isClickBtnRush = true;
  378. isKeepBtnRush = true;
  379. }
  380. void OnSprintingRelease()
  381. {
  382. LBisHold = false;
  383. }
  384. //手柄按下LB
  385. [HideInInspector]
  386. public bool LBisHold;
  387. //读取手柄参数
  388. private void OnMove(InputValue value)
  389. {
  390. leftDir = value.Get<Vector2>();
  391. moveVec = value.Get<Vector2>();
  392. }
  393. void OnJump()
  394. {
  395. if (canJump)
  396. {
  397. isClickBtnJump = true;
  398. }
  399. }
  400. void OnSummon0()
  401. {
  402. if (nowConductButton == -1)
  403. {
  404. isClickBtnWest = true;
  405. nowConductButton = 0;
  406. conductTime = 0;
  407. }
  408. }
  409. void OnSummon0Up()
  410. {
  411. if (nowConductButton == 0)
  412. {
  413. isBtnWestUp = true;
  414. cacheConductId = nowConductButton;
  415. nowConductButton = -1;
  416. }
  417. }
  418. void OnSummon1()
  419. {
  420. if (nowConductButton == -1)
  421. {
  422. isClickBtnSouth = true;
  423. nowConductButton = 1;
  424. conductTime = 0;
  425. }
  426. }
  427. void OnSummon1Up()
  428. {
  429. if (nowConductButton == 1)
  430. {
  431. isBtnSouthUp = true;
  432. cacheConductId = nowConductButton;
  433. nowConductButton = -1;
  434. }
  435. }
  436. void OnSummon2()
  437. {
  438. if (nowConductButton == -1)
  439. {
  440. isClickBtnEast = true;
  441. nowConductButton = 2;
  442. conductTime = 0;
  443. }
  444. }
  445. void OnSummon2Up()
  446. {
  447. if (nowConductButton == 2)
  448. {
  449. isBtnEastUp = true;
  450. cacheConductId = nowConductButton;
  451. nowConductButton = -1;
  452. }
  453. }
  454. //选英灵 (手柄右扳机,键盘TAB)
  455. void OnChooseSpirit()
  456. {
  457. switch (playerId)
  458. {
  459. case 0:
  460. SpiritSystem.isP1CardChangeR = true;
  461. break;
  462. case 1:
  463. SpiritSystem.isP2CardChangeR = true;
  464. break;
  465. default:
  466. break;
  467. }
  468. }
  469. public void Jump()
  470. {
  471. SetUpSpeed(jumpSpeed);
  472. ani.Play("jump", 0, 0);
  473. }
  474. public void AirJump()
  475. {
  476. ChangeState(CharacterState.Rise);
  477. SetUpSpeed(airJumpSpeed);
  478. ani.Play("jump_air", 0, 0);
  479. }
  480. public void SetUpSpeed(float speed)
  481. {
  482. ChangeState(CharacterState.Rise);
  483. Vector3 velocity = rb.velocity;
  484. CheckTurn();
  485. velocity.y = speed;
  486. rb.velocity = velocity;
  487. //animalAni.SetInteger("state", (int)PlayerState.Rise);
  488. }
  489. public bool CheckSummon()
  490. {
  491. if (restSummonTime > 0)
  492. {
  493. return false;
  494. }
  495. if (state != CharacterState.Conduct && nowConductButton != -1 && conductTime > totalCacheSummonTime)
  496. {
  497. CheckTurn();
  498. if (conductCanRelease[nowConductButton])
  499. {
  500. ChangeState(CharacterState.Conduct);
  501. return true;
  502. }
  503. return false;
  504. }
  505. if (isBtnEastUp || isBtnWestUp || isBtnSouthUp)
  506. {
  507. if (cacheSummonTime >= 0 && conductTime <= totalCacheSummonTime)
  508. {
  509. CheckTurn();
  510. if (!CheckCanSummon(cacheSummonId))
  511. {
  512. return false;
  513. }
  514. Summon(cacheSummonId);
  515. return true;
  516. }
  517. }
  518. return false;
  519. }
  520. public bool CheckConduct()
  521. {
  522. if (isBtnEastUp || isBtnWestUp || isBtnSouthUp)
  523. {
  524. if (isReadyConduct)
  525. {
  526. conductController.Conduct(cacheConductId);
  527. }
  528. isReadyConduct = false;
  529. return true;
  530. }
  531. if (!isReadyConduct && nowConductButton != -1)
  532. {
  533. if (conductTime >= canConductTime[nowConductButton] * timeSlowingMultiplier)
  534. {
  535. isReadyConduct = true;
  536. if (!conductReadyTip.isShowing1 && !conductReadyTip.isShowingNoDemonic)
  537. {
  538. int boostNum = demonicDic[nowConductButton].Count;
  539. int dienum = (int)(boostNum * conductController.conversionRate[nowConductButton] + 0.5f);
  540. if (boostNum == 1)
  541. {
  542. dienum = 1;
  543. }
  544. if (dienum > 0)
  545. {
  546. conductReadyTip.Show(1);
  547. }
  548. else
  549. {
  550. conductReadyTip.Show(3, nowConductButton);
  551. }
  552. }
  553. }
  554. else if (conductTime >= (canConductTime[nowConductButton] - readyTipFxTime) * timeSlowingMultiplier)
  555. {
  556. if (!conductReadyTip.isShowing0 && !conductReadyTip.isShowingNoDemonic)
  557. {
  558. int boostNum = demonicDic[nowConductButton].Count;
  559. int dienum = (int)(boostNum * conductController.conversionRate[nowConductButton] + 0.5f);
  560. if (boostNum == 1)
  561. {
  562. dienum = 1;
  563. }
  564. if (dienum > 0)
  565. {
  566. conductReadyTip.Show(0);
  567. }
  568. else
  569. {
  570. conductReadyTip.Show(2, nowConductButton);
  571. }
  572. }
  573. }
  574. else
  575. {
  576. if (Time.timeScale == 1)
  577. {
  578. Time.timeScale = timeSlowingMultiplier;
  579. Time.fixedDeltaTime = fixedDeltaTime * Time.timeScale;
  580. int boostNum = demonicDic[nowConductButton].Count;
  581. int dienum = (int)(boostNum * conductController.conversionRate[nowConductButton] + 0.5f);
  582. if (boostNum == 1)
  583. {
  584. dienum = 1;
  585. }
  586. if (dienum == 0)
  587. {
  588. conductReadyTip.Show(2, nowConductButton);
  589. CannotConductFX(nowConductButton);
  590. }
  591. }
  592. conductReadyTip.Init();
  593. }
  594. }
  595. return false;
  596. }
  597. public void Conduct()
  598. {
  599. //switch (conductSkills[cacheConductId])
  600. //{
  601. // //巨人
  602. // case ConductSkills.AddAttack:
  603. // List<Demonic> newGiants = new List<Demonic>();
  604. // foreach (Demonic d in demonicDic[cacheConductId])
  605. // {
  606. // if (!d.isDie)
  607. // {
  608. // newGiants.Add(d);
  609. // if (d.attackController.addAttackEffect == null)
  610. // {
  611. // d.attackController.addAttackEffect = Instantiate(attackEffect, d.bodyTrans.position, new Quaternion(0, 0, 0, 0), d.bodyTrans);
  612. // }
  613. // d.attackController.addAttackEffect.transform.GetChild(0).gameObject.SetActive(true);
  614. // }
  615. // }
  616. // foreach (Demonic d in newGiants)
  617. // {
  618. // int damage = d.attackController.curDamage;
  619. // d.attackController.curDamage += (int)(addRate * boostNum * damage);
  620. // }
  621. // break;
  622. // //气功师
  623. // case ConductSkills.Mountain:
  624. // conductCanRelease[cacheConductId] = false;
  625. // GameObject curMountain = Instantiate(mountain, null);
  626. // Vector3 moffset = mountainOffset;
  627. // Vector3 sc = curMountain.transform.localScale;
  628. // sc.x = largeX * dienum;
  629. // curMountain.transform.localScale = sc;
  630. // if (bodyTrans.localScale.x < 0)
  631. // {
  632. // moffset.x = mountainOffset.x + sc.x / 2;
  633. // }
  634. // else
  635. // {
  636. // moffset.x = -mountainOffset.x - sc.x / 2;
  637. // }
  638. // Mountain MT = curMountain.GetComponent<Mountain>();
  639. // curMountain.transform.position = transform.position + moffset;
  640. // MT.pc = this;
  641. // MT.id = cacheConductId;
  642. // MT.demonicNum = boostNum;
  643. // break;
  644. // case ConductSkills.WavePower:
  645. // rb.constraints = RigidbodyConstraints.FreezeAll;
  646. // rb.useGravity = false;
  647. // conductCanRelease[cacheConductId] = false;
  648. // obj = Instantiate(wavePowerObj, transform);
  649. // obj.transform.position = transform.position + Vector3.up;
  650. // WavePowerSkill wps = obj.GetComponent<WavePowerSkill>();
  651. // wps.continueTime = wps.singleTime * dienum;
  652. // wps.longFX = (int)bodyTrans.localScale.x;
  653. // wps.damage = wavePowerDamage * boostNum;
  654. // wps.cacheID = cacheConductId;
  655. // wps.pc = this;
  656. // break;
  657. // case ConductSkills.SwordsControl:
  658. // conductCanRelease[cacheConductId] = false;
  659. // obj = Instantiate(flyingSwordsObj, transform);
  660. // obj.transform.position = transform.position + Vector3.up;
  661. // SwordsControl swordsControl = obj.GetComponentInChildren<SwordsControl>();
  662. // swordsControl.owner = this;
  663. // swordsControl.conductId = cacheConductId;
  664. // swordsControl.boostNum = boostNum;
  665. // break;
  666. // //弓箭手
  667. // case ConductSkills.AngryBullet:
  668. // conductCanRelease[cacheConductId] = false;
  669. // obj = Instantiate(angryBulletObj);
  670. // AngryBulletControl angryBulletControl = obj.GetComponent<AngryBulletControl>();
  671. // angryBulletControl.playerController = this;
  672. // angryBulletControl.cacheConductId = cacheConductId;
  673. // angryBulletControl.maxNum = boostNum * angryBulletNum;
  674. // break;
  675. // case ConductSkills.FlyingSwords:
  676. // obj = Instantiate(fanFlyingSwords);
  677. // FanFlyingSwords FFS = obj.GetComponent<FanFlyingSwords>();
  678. // FFS.owner = this;
  679. // FFS.angleRange = flyingSwordsAngleRange;
  680. // FFS.arrivalAngle = flyintSwordsArrivalAngle;
  681. // FFS.swordsNum = boostNum * flyingSwordsNum;
  682. // FFS.Biu();
  683. // break;
  684. //}
  685. }
  686. private int cannotConductfx;
  687. private void CannotConductFX(int id)
  688. {
  689. cannotConductfx = id;
  690. cannotConductFXs[id].SetActive(true);
  691. Invoke("CannotConductFXFade", 0.2f);
  692. }
  693. private void CannotConductFXFade()
  694. {
  695. cannotConductFXs[cannotConductfx].SetActive(false);
  696. }
  697. //角色处于可自由活动状态时的通用切换状态逻辑,如Idle、Run状态,以及别的状态结束时准备回到Idle状态前
  698. public bool CheckPlayerChangeState(CharacterState excludeState = CharacterState.None)
  699. {
  700. if (!foot.TrigGround)
  701. {
  702. if (excludeState != CharacterState.Summon)
  703. {
  704. if (CheckSummon())
  705. {
  706. return true;
  707. }
  708. }
  709. if ((btnRushPress || cacheRushTime > 0 || cacheRush) && mp >= rushCostMp)
  710. {
  711. if (excludeState != CharacterState.Rush)
  712. {
  713. restSummonTime = 0;
  714. summonTime = 0;
  715. cacheRush = false;
  716. ChangeState(CharacterState.Rush);
  717. return true;
  718. }
  719. }
  720. if (rb.velocity.y > 0)
  721. {
  722. if (excludeState != CharacterState.Rise && restSummonTime <= 0)
  723. {
  724. summonTime = 0;
  725. ChangeState(CharacterState.Rise);
  726. return true;
  727. }
  728. }
  729. else
  730. {
  731. if (excludeState != CharacterState.Fall && restSummonTime <= 0)
  732. {
  733. summonTime = 0;
  734. ChangeState(CharacterState.Fall);
  735. return true;
  736. }
  737. }
  738. }
  739. else
  740. {
  741. airJumped = 0;
  742. if (CheckSummon())
  743. {
  744. if (excludeState == CharacterState.Summon)
  745. {
  746. if (foot.TrigGround)
  747. {
  748. ani.Play("summon", 0, 0);
  749. }
  750. else
  751. {
  752. ani.Play("summon_air", 0, 0);
  753. }
  754. }
  755. return true;
  756. }
  757. if ((btnRushPress || cacheRushTime > 0 || cacheRush) && mp >= rushCostMp)
  758. {
  759. if (excludeState != CharacterState.Rush)
  760. {
  761. restSummonTime = 0;
  762. summonTime = 0;
  763. cacheRush = false;
  764. ChangeState(CharacterState.Rush);
  765. return true;
  766. }
  767. }
  768. if (btnJumpPress || cacheJumpTime > 0)
  769. {
  770. if (excludeState != CharacterState.Rise && restSummonTime <= 0)
  771. {
  772. summonTime = 0;
  773. Jump();
  774. ChangeState(CharacterState.Rise);
  775. return true;
  776. }
  777. }
  778. if (leftDir.y < -0.5)
  779. {
  780. Platform platform = foot.trigGroundList[0].GetComponent<Platform>();
  781. if (platform != null && platform.canDown)
  782. {
  783. foot.trigGroundList.Remove(platform.gameObject);
  784. }
  785. }
  786. if (canFly)
  787. {
  788. if (leftDir.x > 0.3f || leftDir.x < -0.3f || leftDir.y > 0.3f || leftDir.y < -0.3f)
  789. {
  790. if (excludeState != CharacterState.Run && restSummonTime <= 0)
  791. {
  792. summonTime = 0;
  793. ChangeState(CharacterState.Run);
  794. return true;
  795. }
  796. }
  797. else
  798. {
  799. if (excludeState != CharacterState.Idle && summonTime <= 0)
  800. {
  801. ChangeState(CharacterState.Idle);
  802. return true;
  803. }
  804. }
  805. }
  806. else
  807. {
  808. if (leftDir.x > 0.3f || leftDir.x < -0.3f)
  809. {
  810. if (excludeState != CharacterState.Run && restSummonTime <= 0)
  811. {
  812. summonTime = 0;
  813. ChangeState(CharacterState.Run);
  814. return true;
  815. }
  816. }
  817. else
  818. {
  819. if (excludeState != CharacterState.Idle && summonTime <= 0)
  820. {
  821. ChangeState(CharacterState.Idle);
  822. return true;
  823. }
  824. }
  825. }
  826. }
  827. return false;
  828. }
  829. public override Vector3 GetMoveDir()
  830. {
  831. return leftDir;
  832. }
  833. public void CachedPlayerInput()
  834. {
  835. if (btnRushPress)
  836. {
  837. cacheRushTime = totalCacheRushTime;
  838. }
  839. if (btnJumpPress)
  840. {
  841. cacheJumpTime = totalCacheJumpTime;
  842. }
  843. if (btnNorthPress)
  844. {
  845. cacheAttackTime = totalCacheAttackTime;
  846. }
  847. if (btnWestPress)
  848. {
  849. cacheSummonTime = totalCacheSummonTime;
  850. cacheSummonId = 0;
  851. }
  852. if (btnSouthPress)
  853. {
  854. cacheSummonTime = totalCacheSummonTime;
  855. cacheSummonId = 1;
  856. }
  857. if (btnEastPress)
  858. {
  859. cacheSummonTime = totalCacheSummonTime;
  860. cacheSummonId = 2;
  861. }
  862. //if (btnSpiritSummon)
  863. //{
  864. // cacheSummonTime = totalCacheSummonTime;
  865. // cacheSummonId = 3;
  866. //}
  867. //if (btnSpiritSummon1)
  868. //{
  869. // cacheSummonTime = totalCacheSummonTime;
  870. // cacheSummonId = 4;
  871. //}
  872. //if (btnSpiritSummon2)
  873. //{
  874. // cacheSummonTime = totalCacheSummonTime;
  875. // cacheSummonId = 5;
  876. //}
  877. //if (btnSpiritSummon3)
  878. //{
  879. // cacheSummonTime = totalCacheSummonTime;
  880. // cacheSummonId = 6;
  881. //}
  882. }
  883. public override void OnState()
  884. {
  885. base.OnState();
  886. if(state == CharacterState.None)
  887. {
  888. return;
  889. }
  890. cacheJumpTime -= Time.deltaTime;
  891. cacheSummonTime -= Time.deltaTime;
  892. canJumpTime -= Time.deltaTime;
  893. invincibleTime -= Time.deltaTime;
  894. summonTime -= Time.deltaTime;
  895. restSummonTime -= Time.deltaTime;
  896. rushTime -= Time.deltaTime;
  897. cacheRushTime -= Time.deltaTime;
  898. dieKeepTime -= Time.deltaTime;
  899. if (nowConductButton != -1)
  900. {
  901. conductTime += Time.deltaTime;
  902. }
  903. CachedPlayerInput();
  904. Vector3 velocity = rb.velocity;
  905. switch (state)
  906. {
  907. case CharacterState.Idle:
  908. if (CheckPlayerChangeState(CharacterState.Idle))
  909. {
  910. break;
  911. }
  912. rb.velocity = Vector3.right * velocityAddition;
  913. break;
  914. case CharacterState.Run:
  915. if (CheckPlayerChangeState(CharacterState.Run))
  916. {
  917. break;
  918. }
  919. CheckTurn();
  920. if (canFly)
  921. {
  922. rb.velocity = leftDir.normalized * moveSpeed;
  923. }
  924. else
  925. {
  926. if (leftDir.x > 0.3f)
  927. {
  928. rb.velocity = new Vector3(moveSpeed + velocityAddition, 0, 0);
  929. }
  930. else if (leftDir.x < -0.3f)
  931. {
  932. rb.velocity = new Vector3(-moveSpeed + velocityAddition, 0, 0);
  933. }
  934. }
  935. break;
  936. case CharacterState.Rise:
  937. if (CheckSummon())
  938. {
  939. break;
  940. }
  941. if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
  942. {
  943. ChangeState(CharacterState.Rush);
  944. break;
  945. }
  946. if (btnJumpPress || cacheJumpTime > 0)
  947. {
  948. if (airJumped < airJumpNumber && rb.velocity.y < canAirJumpSpeed)
  949. {
  950. airJumped++;
  951. AirJump();
  952. break;
  953. }
  954. }
  955. rb.velocity = AirMove(rb.velocity);
  956. if (rb.velocity.y <= 0)
  957. {
  958. ChangeState(CharacterState.Fall);
  959. break;
  960. }
  961. break;
  962. case CharacterState.Fall:
  963. if (CheckSummon())
  964. {
  965. break;
  966. }
  967. if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
  968. {
  969. ChangeState(CharacterState.Rush);
  970. break;
  971. }
  972. if (foot.TrigGround)
  973. {
  974. if (CheckPlayerChangeState(CharacterState.Fall))
  975. {
  976. break;
  977. }
  978. }
  979. if (btnJumpPress || cacheJumpTime > 0)
  980. {
  981. if (canJumpTime > 0)
  982. {
  983. AirJump();
  984. break;
  985. }
  986. else
  987. {
  988. if (airJumped < airJumpNumber)
  989. {
  990. airJumped++;
  991. AirJump();
  992. break;
  993. }
  994. }
  995. }
  996. rb.velocity = AirMove(rb.velocity);
  997. break;
  998. case CharacterState.Attack:
  999. if (attackController.attackTime <= 0)
  1000. {
  1001. if (btnNorthKeep)
  1002. {
  1003. ChangeState(CharacterState.KeepAttack);
  1004. break;
  1005. }
  1006. if (CheckPlayerChangeState(CharacterState.Attack))
  1007. {
  1008. break;
  1009. }
  1010. }
  1011. break;
  1012. case CharacterState.KeepAttack:
  1013. if ((btnRushPress) && mp >= rushCostMp)
  1014. {
  1015. ChangeState(CharacterState.Rush);
  1016. break;
  1017. }
  1018. if (btnJumpPress && canJumpTime > 0)
  1019. {
  1020. AirJump();
  1021. break;
  1022. }
  1023. if (!btnNorthKeep)
  1024. {
  1025. if (CheckPlayerChangeState(CharacterState.KeepAttack))
  1026. {
  1027. break;
  1028. }
  1029. }
  1030. switch (attackState)
  1031. {
  1032. case PlayerAttackState.Idle:
  1033. if (bodyTrans.localScale.x > 0)
  1034. {
  1035. if (leftDir.x > 0.3f)
  1036. {
  1037. SetAttackState(PlayerAttackState.WalkBack);
  1038. velocity.x = attackMoveSpeed;
  1039. rb.velocity = velocity;
  1040. break;
  1041. }
  1042. else if (leftDir.x < -0.3f)
  1043. {
  1044. SetAttackState(PlayerAttackState.WalkForward);
  1045. velocity.x = -attackMoveSpeed;
  1046. rb.velocity = velocity;
  1047. break;
  1048. }
  1049. }
  1050. else
  1051. {
  1052. if (leftDir.x > 0.3f)
  1053. {
  1054. SetAttackState(PlayerAttackState.WalkForward);
  1055. velocity.x = attackMoveSpeed;
  1056. rb.velocity = velocity;
  1057. break;
  1058. }
  1059. else if (leftDir.x < -0.3f)
  1060. {
  1061. SetAttackState(PlayerAttackState.WalkBack);
  1062. velocity.x = -attackMoveSpeed;
  1063. rb.velocity = velocity;
  1064. break;
  1065. }
  1066. }
  1067. velocity.x = 0;
  1068. rb.velocity = velocity;
  1069. break;
  1070. case PlayerAttackState.WalkForward:
  1071. if (bodyTrans.localScale.x > 0)
  1072. {
  1073. if (leftDir.x > 0.3f)
  1074. {
  1075. SetAttackState(PlayerAttackState.WalkBack);
  1076. velocity.x = attackMoveSpeed;
  1077. rb.velocity = velocity;
  1078. break;
  1079. }
  1080. else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
  1081. {
  1082. SetAttackState(PlayerAttackState.Idle);
  1083. velocity.x = 0;
  1084. rb.velocity = velocity;
  1085. break;
  1086. }
  1087. else
  1088. {
  1089. velocity.x = -attackMoveSpeed;
  1090. rb.velocity = velocity;
  1091. }
  1092. }
  1093. else
  1094. {
  1095. if (leftDir.x < -0.3f)
  1096. {
  1097. SetAttackState(PlayerAttackState.WalkBack);
  1098. velocity.x = -attackMoveSpeed;
  1099. rb.velocity = velocity;
  1100. break;
  1101. }
  1102. else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
  1103. {
  1104. SetAttackState(PlayerAttackState.Idle);
  1105. velocity.x = 0;
  1106. rb.velocity = velocity;
  1107. break;
  1108. }
  1109. else
  1110. {
  1111. velocity.x = attackMoveSpeed;
  1112. rb.velocity = velocity;
  1113. }
  1114. }
  1115. break;
  1116. case PlayerAttackState.WalkBack:
  1117. if (bodyTrans.localScale.x > 0)
  1118. {
  1119. if (leftDir.x < -0.3f)
  1120. {
  1121. SetAttackState(PlayerAttackState.WalkForward);
  1122. velocity.x = -attackMoveSpeed;
  1123. rb.velocity = velocity;
  1124. break;
  1125. }
  1126. else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
  1127. {
  1128. SetAttackState(PlayerAttackState.Idle);
  1129. velocity.x = 0;
  1130. rb.velocity = velocity;
  1131. break;
  1132. }
  1133. else
  1134. {
  1135. velocity.x = attackMoveSpeed;
  1136. rb.velocity = velocity;
  1137. }
  1138. }
  1139. else
  1140. {
  1141. if (leftDir.x > 0.3f)
  1142. {
  1143. SetAttackState(PlayerAttackState.WalkForward);
  1144. velocity.x = attackMoveSpeed;
  1145. rb.velocity = velocity;
  1146. break;
  1147. }
  1148. else if (leftDir.x > -0.3f && leftDir.x > 0.3f)
  1149. {
  1150. SetAttackState(PlayerAttackState.Idle);
  1151. velocity.x = 0;
  1152. rb.velocity = velocity;
  1153. break;
  1154. }
  1155. else
  1156. {
  1157. velocity.x = -attackMoveSpeed;
  1158. rb.velocity = velocity;
  1159. }
  1160. }
  1161. break;
  1162. default:
  1163. break;
  1164. }
  1165. break;
  1166. case CharacterState.Summon:
  1167. if (leftDir.x > 0.3f || leftDir.x < -0.3f)
  1168. {
  1169. cacheDir = leftDir.x;
  1170. }
  1171. if (LBisHold)
  1172. {
  1173. cacheRush = true;
  1174. }
  1175. if (CheckPlayerChangeState(CharacterState.Summon))
  1176. {
  1177. break;
  1178. }
  1179. rb.velocity = Vector3.right * velocityAddition;
  1180. break;
  1181. case CharacterState.Rush:
  1182. if (rushTime <= 0)
  1183. {
  1184. if (btnRushKeep)
  1185. {
  1186. ChangeState(CharacterState.Sprint);
  1187. break;
  1188. }
  1189. if (CheckPlayerChangeState(CharacterState.Rush))
  1190. {
  1191. break;
  1192. }
  1193. }
  1194. rb.velocity = rushDir * rushSpeed;
  1195. break;
  1196. case CharacterState.Sprint:
  1197. if (!btnRushKeep)
  1198. {
  1199. if (CheckPlayerChangeState(CharacterState.Sprint))
  1200. {
  1201. break;
  1202. }
  1203. }
  1204. if (mp < sprintCostMp * Time.deltaTime)
  1205. {
  1206. if (CheckPlayerChangeState(CharacterState.Sprint))
  1207. {
  1208. break;
  1209. }
  1210. }
  1211. mp -= sprintCostMp * Time.deltaTime;
  1212. uiMp.Show(mp, totalMp);
  1213. rb.velocity = rushDir * rushSpeed;
  1214. break;
  1215. case CharacterState.Die:
  1216. if (dieKeepTime <= 0)
  1217. {
  1218. if (isRevive)
  1219. {
  1220. reviveTime += Time.deltaTime;
  1221. if (reviveTime >= totalReviveTime)
  1222. {
  1223. PlayerRevive();
  1224. }
  1225. }
  1226. else
  1227. {
  1228. PlayerDie();
  1229. }
  1230. }
  1231. break;
  1232. case CharacterState.Conduct:
  1233. if (CheckConduct())
  1234. {
  1235. ChangeState(CharacterState.Idle);
  1236. }
  1237. break;
  1238. case CharacterState.HitStun:
  1239. hitFeedbackSystem.HitStunUpdate();
  1240. break;
  1241. case CharacterState.SpecialStatus_Float:
  1242. attributeStatus.SpecialStateEffect(SpecialState.FloatState);
  1243. break;
  1244. case CharacterState.SpecialStatus_BlowUp:
  1245. attributeStatus.SpecialStateEffect(SpecialState.BlownUp);
  1246. break;
  1247. case CharacterState.SpecialStatus_ShotDown:
  1248. attributeStatus.SpecialStateEffect(SpecialState.ShotDown);
  1249. break;
  1250. case CharacterState.SpecialStatus_Weak:
  1251. attributeStatus.SpecialStateEffect(SpecialState.Weak);
  1252. break;
  1253. default:
  1254. break;
  1255. }
  1256. isClickBtnRush = false;
  1257. isKeepBtnRush = false;
  1258. isClickBtnJump = false;
  1259. isClickBtnSouth = false;
  1260. isClickBtnEast = false;
  1261. isClickBtnNorth = false;
  1262. isClickBtnWest = false;
  1263. isBtnSouthUp = false;
  1264. isBtnEastUp = false;
  1265. isBtnNorthUp = false;
  1266. isBtnWestUp = false;
  1267. isSpiritSummon = false;
  1268. isSpiritSummon1 = false;
  1269. isSpiritSummon2 = false;
  1270. isSpiritSummon3 = false;
  1271. if (foot.TrigGround)
  1272. {
  1273. canJumpTime = leaveGroundCanJumpTime;
  1274. }
  1275. //SearchTarget();
  1276. //attackTarget = targetCharacter;
  1277. if (isMpRepel)
  1278. {
  1279. if (mp < totalMp)
  1280. {
  1281. if (!isRapedReply)
  1282. {
  1283. mp += mpReplySpeed * Time.deltaTime;
  1284. }
  1285. else
  1286. {
  1287. mp += rapidReplySpeed * Time.deltaTime;
  1288. }
  1289. }
  1290. }
  1291. if (mp > totalMp)
  1292. {
  1293. mp = totalMp;
  1294. }
  1295. if (mp < 0)
  1296. {
  1297. mp = 0;
  1298. }
  1299. uiMp.Show(mp, totalMp);
  1300. }
  1301. public void PlayerDie()
  1302. {
  1303. switch (playerId)
  1304. {
  1305. case 0:
  1306. SpiritSystem.isP1In = true;
  1307. SpiritSystem.isP1Out = false;
  1308. break;
  1309. case 1:
  1310. SpiritSystem.isP2In = true;
  1311. SpiritSystem.isP2Out = false;
  1312. break;
  1313. default:
  1314. break;
  1315. }
  1316. foot.trigGroundList.Clear();
  1317. bodyTrans.gameObject.SetActive(false);
  1318. uiHp.transform.parent.gameObject.SetActive(false);
  1319. rb.constraints = RigidbodyConstraints.FreezeAll;
  1320. isRevive = true;
  1321. reviveTime = 0;
  1322. }
  1323. public void PlayerRevive()
  1324. {
  1325. isRevive = false;
  1326. bodyTrans.gameObject.SetActive(true);
  1327. uiHp.transform.parent.gameObject.SetActive(true);
  1328. rb.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotation;
  1329. transform.position = new Vector3(142 + 4 * playerId, 0, 0);
  1330. switch (playerId)
  1331. {
  1332. case 0:
  1333. SpiritSystem.isP1In = false;
  1334. SpiritSystem.isP1Out = true;
  1335. SpiritSystem.player1 = gameObject;
  1336. SpiritSystem.p1Spirits = GetComponent<Spirits>();
  1337. break;
  1338. case 1:
  1339. SpiritSystem.isP2In = false;
  1340. SpiritSystem.isP2Out = true;
  1341. SpiritSystem.player2 = gameObject;
  1342. SpiritSystem.p2Spirits = GetComponent<Spirits>();
  1343. break;
  1344. default:
  1345. break;
  1346. }
  1347. Init();
  1348. }
  1349. public void RapidReplyMp()
  1350. {
  1351. isRapedReply = true;
  1352. rapidReplyEffect.SetActive(true);
  1353. }
  1354. public void NormalReplyMp()
  1355. {
  1356. isRapedReply = false;
  1357. rapidReplyEffect.SetActive(false);
  1358. }
  1359. public override void ChangeState(CharacterState newState)
  1360. {
  1361. if (state == newState)
  1362. {
  1363. return;
  1364. }
  1365. Vector3 velocity = rb.velocity;
  1366. switch (state)
  1367. {
  1368. case CharacterState.Idle:
  1369. break;
  1370. case CharacterState.Run:
  1371. velocity.x = 0;
  1372. break;
  1373. case CharacterState.Rise:
  1374. bodyCollider.SetActive(true);
  1375. break;
  1376. case CharacterState.Fall:
  1377. break;
  1378. case CharacterState.Attack:
  1379. aniCollider.Play("NotAttack", 1, 0);
  1380. break;
  1381. case CharacterState.KeepAttack:
  1382. aniCollider.Play("NotAttack", 1, 0);
  1383. break;
  1384. case CharacterState.Summon:
  1385. rb.isKinematic = false;
  1386. if (cacheDir != 0)
  1387. {
  1388. if (cacheDir > 0.3f && bodyTrans.localScale.x > 0)
  1389. {
  1390. Turn();
  1391. }
  1392. else if (cacheDir < -0.3f && bodyTrans.localScale.x < 0)
  1393. {
  1394. Turn();
  1395. }
  1396. cacheDir = 0;
  1397. }
  1398. break;
  1399. case CharacterState.Rush:
  1400. invincibleTime = 0;
  1401. rb.useGravity = true;
  1402. velocity = Vector3.zero;
  1403. break;
  1404. case CharacterState.Sprint:
  1405. rb.useGravity = true;
  1406. velocity = Vector3.zero;
  1407. break;
  1408. case CharacterState.Die:
  1409. if (isRevive)
  1410. {
  1411. return;
  1412. }
  1413. isDie = false;
  1414. rb.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotation;
  1415. break;
  1416. case CharacterState.Conduct:
  1417. rb.isKinematic = false;
  1418. Time.timeScale = 1;
  1419. Time.fixedDeltaTime = fixedDeltaTime * Time.timeScale;
  1420. conductReadyTip.activeFalse();
  1421. break;
  1422. default:
  1423. break;
  1424. }
  1425. CharacterState oldState = state;
  1426. state = newState;
  1427. switch (newState)
  1428. {
  1429. case CharacterState.Idle:
  1430. aniCollider.Play("Idle", 0, 0);
  1431. if (oldState == CharacterState.Fall)
  1432. {
  1433. ani.Play("fall_end", 0, 0);
  1434. }
  1435. else
  1436. {
  1437. ani.Play("idle", 0, 0);
  1438. }
  1439. velocity = Vector3.right * velocityAddition;
  1440. //animalAni.SetInteger("state", (int)PlayerState.Idle);
  1441. break;
  1442. case CharacterState.Run:
  1443. aniCollider.Play("Run", 0, 0);
  1444. ani.Play("run_start", 0, 0);
  1445. //animalAni.SetInteger("state", (int)PlayerState.Walk);
  1446. break;
  1447. case CharacterState.Rise:
  1448. aniCollider.Play("Rise", 0, 0);
  1449. canJumpTime = 0;
  1450. break;
  1451. case CharacterState.Fall:
  1452. aniCollider.Play("Fall", 0, 0);
  1453. ani.Play("fall", 0, 0);
  1454. //animalAni.SetInteger("state", (int)PlayerState.Fall);
  1455. break;
  1456. case CharacterState.Attack:
  1457. attackController.attackTime = totalAttack_summonTime;
  1458. break;
  1459. case CharacterState.KeepAttack:
  1460. aniCollider.Play("Attack_summonKeep", 1, 0);
  1461. break;
  1462. case CharacterState.Summon:
  1463. aniCollider.Play("Summon", 0, 0);
  1464. if (foot.TrigGround)
  1465. {
  1466. ani.Play("summon", 0, 0);
  1467. }
  1468. else
  1469. {
  1470. ani.Play("summon_air", 0, 0);
  1471. }
  1472. velocity = Vector3.right * velocityAddition;
  1473. rb.isKinematic = true;
  1474. cacheDir = 0;
  1475. cacheRush = false;
  1476. break;
  1477. case CharacterState.Rush:
  1478. aniCollider.Play("Rush", 0, 0);
  1479. ani.Play("rush_loop", 0, 0);
  1480. rushTime = totalRushTime;
  1481. invincibleTime = rushInvincibleTime;
  1482. rb.useGravity = false;
  1483. if (bodyTrans.localScale.x > 0)
  1484. {
  1485. rushDir = Vector3.left;
  1486. }
  1487. else
  1488. {
  1489. rushDir = Vector3.right;
  1490. }
  1491. velocity = rushDir * rushSpeed;
  1492. mp -= rushCostMp;
  1493. uiMp.Show(mp, totalMp);
  1494. break;
  1495. case CharacterState.Sprint:
  1496. aniCollider.Play("Sprint", 0, 0);
  1497. rb.useGravity = false;
  1498. velocity = rushDir * rushSpeed;
  1499. break;
  1500. case CharacterState.Die:
  1501. rb.constraints = RigidbodyConstraints.FreezeAll;
  1502. aniCollider.Play("Die", 0, 0);
  1503. ani.Play("die", 0, 0);
  1504. isDie = true;
  1505. dieKeepTime = totalDieKeepTime;
  1506. break;
  1507. case CharacterState.Conduct:
  1508. conductTime = 0;
  1509. rb.velocity = Vector3.zero;
  1510. rb.isKinematic = true;
  1511. aniCollider.Play("Summon", 0, 0);
  1512. if (foot.TrigGround)
  1513. {
  1514. ani.Play("summon", 0, 0);
  1515. }
  1516. else
  1517. {
  1518. ani.Play("summon_air", 0, 0);
  1519. }
  1520. break;
  1521. default:
  1522. break;
  1523. }
  1524. rb.velocity = velocity;
  1525. }
  1526. public void CheckTurn()
  1527. {
  1528. if (leftDir.x > 0.3f && bodyTrans.localScale.x > 0)
  1529. {
  1530. if (state == CharacterState.Run)
  1531. {
  1532. ani.Play("run_start", 0, 0);
  1533. }
  1534. Turn();
  1535. }
  1536. else if (leftDir.x < -0.3f && bodyTrans.localScale.x < 0)
  1537. {
  1538. if (state == CharacterState.Run)
  1539. {
  1540. ani.Play("run_start", 0, 0);
  1541. }
  1542. Turn();
  1543. }
  1544. }
  1545. public Vector3 AirMove(Vector3 velocity)
  1546. {
  1547. CheckTurn();
  1548. if (canFly)
  1549. {
  1550. velocity = leftDir.normalized * flySpeed;
  1551. if (transform.position.y > playerMaxFlyHeight && velocity.y > 0)
  1552. {
  1553. velocity.y = 0;
  1554. }
  1555. }
  1556. else
  1557. {
  1558. if (leftDir.x > 0.3f)
  1559. {
  1560. velocity = new Vector3(moveSpeed, velocity.y, velocity.z);
  1561. }
  1562. else if (leftDir.x < -0.3f)
  1563. {
  1564. velocity = new Vector3(-moveSpeed, velocity.y, velocity.z);
  1565. }
  1566. else
  1567. {
  1568. velocity = new Vector3(0, velocity.y, velocity.z);
  1569. }
  1570. if (velocity.y > 0)
  1571. {
  1572. velocity += Vector3.up * extraRiseGravity * Time.deltaTime;
  1573. }
  1574. else
  1575. {
  1576. velocity += Vector3.up * extraFallGravity * Time.deltaTime;
  1577. }
  1578. }
  1579. return velocity;
  1580. }
  1581. public void Summon(int id)
  1582. {
  1583. if (id >= demonicPrefabs.Count)
  1584. {
  1585. Debug.LogError("未配置" + id + "号使魔");
  1586. return;
  1587. }
  1588. if (id >= demonicSummonPos.Count)
  1589. {
  1590. Debug.LogError("未配置" + id + "号使魔召唤位置");
  1591. return;
  1592. }
  1593. GameObject prefab;
  1594. prefab = demonicPrefabs[id];
  1595. if (!CheckCanSummon(id))
  1596. {
  1597. return;
  1598. }
  1599. ChangeState(CharacterState.Summon);
  1600. summonTime = totalSummonTime;
  1601. Demonic dem = prefab.GetComponent<Demonic>();
  1602. float costMp = dem.costMp;
  1603. for (int i = 0; i < 3; i++)
  1604. {
  1605. if (GameManager.curSoldiers[i] == dem.soldierType)
  1606. {
  1607. costMp += slr.seb[i].mp;
  1608. break;
  1609. }
  1610. }
  1611. mp -= costMp;
  1612. uiMp.Show(mp, totalMp);
  1613. GameObject demonicObj = PoolManager.Instantiate(prefab);
  1614. Demonic demonic = demonicObj.GetComponent<Demonic>();
  1615. onlySummonTime = demonic.summonTime;
  1616. restSummonTime = onlySummonTime;
  1617. demonic.id = id;
  1618. demonic.playerID = playerId;
  1619. if (!demonicDic.ContainsKey(id))
  1620. {
  1621. demonicDic.Add(id, new List<Demonic>());
  1622. }
  1623. demonicDic[id].Add(demonic);
  1624. if (id <= 2)
  1625. {
  1626. demonicNums[id].text = demonicDic[id].Count.ToString();
  1627. }
  1628. demonicObj.transform.parent = null;
  1629. demonicObj.transform.localEulerAngles = Vector3.zero;
  1630. demonicObj.transform.localScale = new Vector3(1, 1, 1);
  1631. Vector3 offset = demonicSummonPos[id];
  1632. if (bodyTrans.localScale.x > 0)
  1633. {
  1634. demonicObj.transform.position = transform.position + offset;
  1635. if (demonic.bodyTrans.localScale.x < 0)
  1636. {
  1637. demonic.Turn();
  1638. }
  1639. }
  1640. else
  1641. {
  1642. demonicObj.transform.position = transform.position + new Vector3(-offset.x, offset.y, offset.z);
  1643. if (demonic.bodyTrans.localScale.x > 0)
  1644. {
  1645. demonic.Turn();
  1646. }
  1647. }
  1648. if (demonic.canFly)
  1649. {
  1650. demonic.flyHeight = demonic.transform.position.y;
  1651. }
  1652. demonic.player = this;
  1653. demonic.Init();
  1654. int order = prefab.GetComponent<Demonic>().baseSortingOrder + demonicDic[demonic.id].Count;
  1655. demonic.SetSortingOrder(order);
  1656. if (id != 4)
  1657. {
  1658. demonic.Attack_summon();
  1659. }
  1660. //id 3~6 为四个英灵
  1661. if (id >= 3 && id <= 6)
  1662. {
  1663. spirits.ultimateTimes[spirits.nowSpirit] -= 1;
  1664. }
  1665. spiritSystem.RefreshPlayerUI();
  1666. if (isInSoulTower)
  1667. {
  1668. ls.AddDenomic(demonic);
  1669. }
  1670. slr.SoldierAddLevelBuff(demonic);
  1671. }
  1672. public void OnDemonicRecycle(Demonic demonic)
  1673. {
  1674. if (!demonicDic.ContainsKey(demonic.id))
  1675. {
  1676. return;
  1677. }
  1678. demonicDic[demonic.id].Remove(demonic);
  1679. if (demonic.id <= 2)
  1680. {
  1681. demonicNums[demonic.id].text = demonicDic[demonic.id].Count.ToString();
  1682. }
  1683. for (int i = 0; i < demonicDic[demonic.id].Count; i++)
  1684. {
  1685. int order = demonicDic[demonic.id][i].baseSortingOrder + i;
  1686. demonicDic[demonic.id][i].SetSortingOrder(order);
  1687. }
  1688. }
  1689. public bool CheckCanSummon(int id)
  1690. {
  1691. GameObject prefab;
  1692. prefab = demonicPrefabs[id];
  1693. Demonic dem = prefab.GetComponent<Demonic>();
  1694. float costMp = dem.costMp;
  1695. for (int i = 0; i < 3; i++)
  1696. {
  1697. if (GameManager.curSoldiers[i] == dem.soldierType)
  1698. {
  1699. costMp += slr.seb[i].mp;
  1700. break;
  1701. }
  1702. }
  1703. if (id < 3)
  1704. {
  1705. costMp += addCostMp[id] * demonicDic[id].Count;
  1706. }
  1707. if (mp < costMp)
  1708. {
  1709. Debug.Log("mp不足召唤失败, 还得加个动画或者音效啥的");
  1710. return false;
  1711. }
  1712. return true;
  1713. }
  1714. public void Attack_summon()
  1715. {
  1716. attackController.Attack_summon();
  1717. if (leftDir.x > 0.3f)
  1718. {
  1719. if (bodyTrans.localScale.x > 0)
  1720. {
  1721. Turn();
  1722. }
  1723. SetAttackState(PlayerAttackState.WalkForward);
  1724. }
  1725. else if (leftDir.x < -0.3f)
  1726. {
  1727. if (bodyTrans.localScale.x < 0)
  1728. {
  1729. Turn();
  1730. }
  1731. SetAttackState(PlayerAttackState.WalkForward);
  1732. }
  1733. else
  1734. {
  1735. SetAttackState(PlayerAttackState.Idle);
  1736. }
  1737. }
  1738. public void SetAttackState(PlayerAttackState value)
  1739. {
  1740. attackState = value;
  1741. ani.SetInteger("attackState", (int)value);
  1742. aniCollider.Play("Attack_summonKeep", 1, 0);
  1743. }
  1744. /*
  1745. public void SearchTarget()
  1746. {
  1747. targetCharacter = searchTrigger.GetMinDisTarget(attackController.targetTypes, attackController.canHitFly);
  1748. }*/
  1749. public override void BeHit(int damage)
  1750. {
  1751. base.BeHit(damage);
  1752. //屏幕红闪+抖动
  1753. if (ss == null)
  1754. {
  1755. ss = Camera.main.GetComponentInParent<ScreenShake>();
  1756. }
  1757. ss.enabled = true;
  1758. if (isSustainedInjury || damage >= heavyDamage)
  1759. {
  1760. ss.ShakeScreen(1);
  1761. }
  1762. }
  1763. public override void BeHit(AttackInfo attackInfo, Character attackFrom)
  1764. {
  1765. if (conductController.HavePhoton(attackFrom, attackInfo.damage))
  1766. {
  1767. return;
  1768. }
  1769. base.BeHit(attackInfo, attackFrom);
  1770. //屏幕红闪+抖动
  1771. if (ss == null)
  1772. {
  1773. ss = Camera.main.GetComponentInParent<ScreenShake>();
  1774. }
  1775. ss.enabled = true;
  1776. if (isSustainedInjury || attackInfo.damage >= heavyDamage)
  1777. {
  1778. ss.ShakeScreen(1);
  1779. }
  1780. }
  1781. }