PlayerController.cs 69 KB

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