PlayerController.cs 61 KB

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