PlayerController.cs 68 KB

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