PlayerController.cs 62 KB

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