PlayerController.cs 64 KB

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