PlayerController.cs 60 KB

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