PlayerController.cs 57 KB

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