PlayerController.cs 58 KB

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