PlayerController.cs 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871
  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 || wallTrigger.TrigWall)
  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. case CharacterState.SpecialStatus_BlowUp:
  1263. mecanim.transform.localPosition = Vector3.zero;
  1264. mecanim.transform.localRotation = Quaternion.Euler(0, 0, 0);
  1265. break;
  1266. default:
  1267. break;
  1268. }
  1269. CharacterState oldState = state;
  1270. state = newState;
  1271. switch (newState)
  1272. {
  1273. case CharacterState.Idle:
  1274. aniCollider.Play("Idle", 0, 0);
  1275. if (oldState == CharacterState.Fall)
  1276. {
  1277. ani.Play("fall_end", 0, 0);
  1278. }
  1279. else
  1280. {
  1281. ani.Play("idle", 0, 0);
  1282. }
  1283. velocity = Vector3.right * velocityAddition;
  1284. //animalAni.SetInteger("state", (int)PlayerState.Idle);
  1285. break;
  1286. case CharacterState.Run:
  1287. aniCollider.Play("Run", 0, 0);
  1288. ani.Play("run_start", 0, 0);
  1289. //animalAni.SetInteger("state", (int)PlayerState.Walk);
  1290. break;
  1291. case CharacterState.Rise:
  1292. //bodyCollider.SetActive(false);
  1293. aniCollider.Play("Rise", 0, 0);
  1294. canJumpTime = 0;
  1295. break;
  1296. case CharacterState.Fall:
  1297. aniCollider.Play("Fall", 0, 0);
  1298. ani.Play("fall", 0, 0);
  1299. //animalAni.SetInteger("state", (int)PlayerState.Fall);
  1300. break;
  1301. case CharacterState.KeepAttack:
  1302. aniCollider.Play("Attack_summonKeep", 1, 0);
  1303. break;
  1304. case CharacterState.Summon:
  1305. aniCollider.Play("Summon", 0, 0);
  1306. if (foot.TrigGround)
  1307. {
  1308. ani.Play("summon", 0, 0);
  1309. }
  1310. else
  1311. {
  1312. ani.Play("summon_air", 0, 0);
  1313. }
  1314. velocity = Vector3.right * velocityAddition;
  1315. rb.isKinematic = true;
  1316. cacheDir = 0;
  1317. cacheRush = false;
  1318. break;
  1319. case CharacterState.Rush:
  1320. if (GameManager.instance.isWindEnable || GameManager.instance.isThunderEnable) bodyTrigger.gameObject.SetActive(true);
  1321. aniCollider.Play("Rush", 0, 0);
  1322. ani.Play("rush_loop", 0, 0);
  1323. rushTime = totalRushTime;
  1324. invincibleTime = rushInvincibleTime;
  1325. rb.useGravity = false;
  1326. if (bodyTrans.localScale.x > 0)
  1327. {
  1328. rushDir = Vector3.left;
  1329. }
  1330. else
  1331. {
  1332. rushDir = Vector3.right;
  1333. }
  1334. velocity = rushDir * rushSpeed;
  1335. //mp -= rushCostMp;
  1336. rushChargeNums--;
  1337. UIController.ChangeImageFill(uiRush.GetChild(rushChargeNums).GetComponent<Image>(), rushChargeTime, rushChargeAddTime);
  1338. if (rushChargeNums != rushChargeTotalNums - 1)
  1339. {
  1340. UIController.ChangeImageFill(uiRush.GetChild(rushChargeNums + 1).GetComponent<Image>(), 0);
  1341. }
  1342. uiMp.Show(mp, totalMp);
  1343. break;
  1344. case CharacterState.Sprint:
  1345. if(GameManager.instance.isWindEnable || GameManager.instance.isThunderEnable) bodyTrigger.gameObject.SetActive(true);
  1346. aniCollider.Play("Sprint", 0, 0);
  1347. rb.useGravity = false;
  1348. velocity = rushDir * rushSpeed;
  1349. break;
  1350. case CharacterState.Die:
  1351. rb.constraints = RigidbodyConstraints.FreezeAll;
  1352. aniCollider.Play("Die", 0, 0);
  1353. ani.Play("die", 0, 0);
  1354. isDie = true;
  1355. dieKeepTime = totalDieKeepTime;
  1356. break;
  1357. case CharacterState.Conduct:
  1358. conductTime = 0;
  1359. rb.velocity = Vector3.zero;
  1360. rb.isKinematic = true;
  1361. aniCollider.Play("Summon", 0, 0);
  1362. if (foot.TrigGround)
  1363. {
  1364. ani.Play("summon", 0, 0);
  1365. }
  1366. else
  1367. {
  1368. ani.Play("summon_air", 0, 0);
  1369. }
  1370. break;
  1371. default:
  1372. break;
  1373. }
  1374. rb.velocity = velocity;
  1375. }
  1376. public void CheckTurn()
  1377. {
  1378. if (leftDir.x > 0.3f && bodyTrans.localScale.x > 0)
  1379. {
  1380. if (state == CharacterState.Run)
  1381. {
  1382. ani.Play("run_start", 0, 0);
  1383. }
  1384. Turn();
  1385. }
  1386. else if (leftDir.x < -0.3f && bodyTrans.localScale.x < 0)
  1387. {
  1388. if (state == CharacterState.Run)
  1389. {
  1390. ani.Play("run_start", 0, 0);
  1391. }
  1392. Turn();
  1393. }
  1394. }
  1395. public Vector3 AirMove(Vector3 velocity)
  1396. {
  1397. CheckTurn();
  1398. if (canFly)
  1399. {
  1400. velocity = leftDir.normalized * flySpeed;
  1401. if (transform.position.y > playerMaxFlyHeight && velocity.y > 0)
  1402. {
  1403. velocity.y = 0;
  1404. }
  1405. }
  1406. else
  1407. {
  1408. if (leftDir.x > 0.3f)
  1409. {
  1410. velocity = new Vector3(moveSpeed, velocity.y, velocity.z);
  1411. }
  1412. else if (leftDir.x < -0.3f)
  1413. {
  1414. velocity = new Vector3(-moveSpeed, velocity.y, velocity.z);
  1415. }
  1416. else
  1417. {
  1418. velocity = new Vector3(0, velocity.y, velocity.z);
  1419. }
  1420. if (velocity.y > 0)
  1421. {
  1422. velocity += Vector3.up * extraRiseGravity * Time.deltaTime;
  1423. }
  1424. else
  1425. {
  1426. velocity += Vector3.up * extraFallGravity * Time.deltaTime;
  1427. }
  1428. }
  1429. return velocity;
  1430. }
  1431. public void Summon(int id)
  1432. {
  1433. //ChangeState(CharacterState.Summon);
  1434. //summonTime = totalSummonTime;
  1435. Demonic dem = demonicPrefabs[id].GetComponent<Demonic>();
  1436. float costMp = dem.costMp;
  1437. for (int i = 0; i < 3; i++)
  1438. {
  1439. if (GameManager.curSoldiers[i] == dem.soldierType)
  1440. {
  1441. costMp += slr.seb[i].mp;
  1442. break;
  1443. }
  1444. }
  1445. mp -= costMp;
  1446. uiMp.Show(mp, totalMp);
  1447. StartCoroutine(SummonDemoic(id));
  1448. //for (int i = 0; i < nextSummonNum; i++)
  1449. //{
  1450. // Demonic demonic = CreateDemonic(id);
  1451. // if (demonic.canFly)
  1452. // {
  1453. // if (i > 0) demonic.transform.position += new Vector3(Random.Range(-2, 2), Random.Range(-2, 2), 0);
  1454. // }
  1455. // else
  1456. // {
  1457. // if (i > 0) demonic.transform.position += new Vector3(Random.Range(-2, 2), Random.Range(0f, 0.5f), 0);
  1458. // }
  1459. // int attackSummonId = nowAttackSummonID;
  1460. // if (lastSoldier != demonic.soldierType)
  1461. // {
  1462. // attackSummonId = 0;
  1463. // }
  1464. // demonic.attackController.attackSummonId = attackSummonId;
  1465. // onlySummonTime = demonic.attackController.summonTime[attackSummonId];
  1466. // invincibleTime = onlySummonTime + addSummonInvincibleTime;
  1467. // restSummonTime = onlySummonTime;
  1468. // demonic.Attack_summon();
  1469. // lastSoldier = demonic.soldierType;
  1470. // attackSummonId++;
  1471. // if (attackSummonId >= demonic.attackController.attackMethod_summon.Length)
  1472. // {
  1473. // attackSummonId = 0;
  1474. // AttackSummonChangeTime = 0;
  1475. // }
  1476. // else
  1477. // {
  1478. // AttackSummonChangeTime = AttackSummonChangeTotalTime;
  1479. // }
  1480. // nowAttackSummonID = attackSummonId;
  1481. // //id 3~6 为四个英灵
  1482. // if (id >= 3)
  1483. // {
  1484. // spirits.ultimateTimes[id - 3] -= spirits.summonCost;
  1485. // }
  1486. // spiritSystem.RefreshPlayerUI();
  1487. // if (isInSoulTower)
  1488. // {
  1489. // ls.AddDenomic(demonic);
  1490. // }
  1491. //}
  1492. //nextSummonNum = 1;
  1493. //GameUI.instance.summonNum.text = nextSummonNum.ToString();
  1494. }
  1495. IEnumerator<WaitForSeconds> SummonDemoic(int id)
  1496. {
  1497. int count = 0;
  1498. int num = nextSummonNum;
  1499. nextSummonNum = 1;
  1500. GameUI.instance.summonNum.text = nextSummonNum.ToString();
  1501. while (count < num)
  1502. {
  1503. ChangeState(CharacterState.Summon);
  1504. summonTime = totalSummonTime;
  1505. Demonic demonic = CreateDemonic(id);
  1506. if (demonic.canFly)
  1507. {
  1508. if (count > 0) demonic.transform.position += new Vector3(Random.Range(-2, 2), Random.Range(-2, 2), 0);
  1509. }
  1510. else
  1511. {
  1512. if (count > 0) demonic.transform.position += new Vector3(Random.Range(-2, 2), Random.Range(0f, 0.5f), 0);
  1513. }
  1514. int attackSummonId = nowAttackSummonID;
  1515. if (lastSoldier != demonic.soldierType)
  1516. {
  1517. attackSummonId = 0;
  1518. }
  1519. demonic.attackController.attackSummonId = attackSummonId;
  1520. onlySummonTime = demonic.attackController.summonTime[attackSummonId];
  1521. //invincibleTime = onlySummonTime + addSummonInvincibleTime;
  1522. restSummonTime = onlySummonTime;
  1523. demonic.Attack_summon();
  1524. lastSoldier = demonic.soldierType;
  1525. attackSummonId++;
  1526. if (attackSummonId >= demonic.attackController.attackMethod_summon.Length)
  1527. {
  1528. attackSummonId = 0;
  1529. AttackSummonChangeTime = 0;
  1530. }
  1531. else
  1532. {
  1533. AttackSummonChangeTime = AttackSummonChangeTotalTime;
  1534. }
  1535. nowAttackSummonID = attackSummonId;
  1536. //id 3~6 为四个英灵
  1537. if (id >= 3)
  1538. {
  1539. spirits.ultimateTimes[id - 3] -= spirits.summonCost;
  1540. }
  1541. spiritSystem.RefreshPlayerUI();
  1542. if (isInSoulTower)
  1543. {
  1544. ls.AddDenomic(demonic);
  1545. }
  1546. count++;
  1547. yield return new WaitForSeconds(0.1f);
  1548. }
  1549. yield return null;
  1550. }
  1551. public Demonic CreateDemonic(int id)
  1552. {
  1553. Demonic demonic = InitDemonic(id);
  1554. if (GameManager.instance.isWoodEnable)
  1555. {
  1556. int randomInt = Random.Range(0, 100);
  1557. if (randomInt < GameManager.instance.woodProbability + GameManager.instance.myTreasuresTag[7] * GameManager.instance.woodLabelEffectRatio)
  1558. {
  1559. PoolManager.Instantiate(Resources.Load<GameObject>("Prefab/SoulFlower"), demonic.transform.position + Vector3.up * 2, Quaternion.identity, demonic.transform).GetComponent<SoulFlower>().Init(true);
  1560. }
  1561. }
  1562. if (!demonicDic.ContainsKey(id))
  1563. {
  1564. demonicDic.Add(id, new List<Demonic>());
  1565. }
  1566. demonicDic[id].Add(demonic);
  1567. if (id <= 2)
  1568. {
  1569. demonicNums[id].text = demonicDic[id].Count.ToString();
  1570. }
  1571. return demonic;
  1572. }
  1573. public Demonic InitDemonic(int id)
  1574. {
  1575. GameObject demonicObj = PoolManager.Instantiate(demonicPrefabs[id]);
  1576. Demonic demonic = demonicObj.GetComponent<Demonic>();
  1577. demonic.id = id;
  1578. demonic.Init();
  1579. slr.SoldierAddLevelBuff(demonic);
  1580. AttackController attackController = demonic.attackController;
  1581. for (int i = 0; i < attackController.attackMethod_summon.Length; i++)
  1582. {
  1583. AttackInfo attackInfo = attackController.attackMethod_summon[i].attackInfo;
  1584. attackInfo.damage += gameManager.damage;
  1585. attackInfo.criticalChance = gameManager.criticalChance;
  1586. attackInfo.lifesteal = gameManager.lifesteal;
  1587. }
  1588. for (int i = 0; i < attackController.attackMethod_march.Length; i++)
  1589. {
  1590. AttackInfo attackInfo = attackController.attackMethod_march[i].attackInfo;
  1591. attackInfo.damage += (int)(gameManager.damage * gameManager.damageRate);
  1592. attackInfo.criticalChance = gameManager.criticalChance;
  1593. attackInfo.lifesteal = gameManager.lifesteal;
  1594. }
  1595. if (GameManager.instance.isSkyEnable)
  1596. {
  1597. for (int i = 0; i < attackController.attackMethod_summon.Length; i++)
  1598. {
  1599. AttackInfo attackInfo = attackController.attackMethod_summon[i].attackInfo;
  1600. attackInfo.damage += (int)(attackInfo.damage * demonicDic[0].Count * (GameManager.instance.attackRate + GameManager.instance.myTreasuresTag[0] * GameManager.instance.skyLabelEffectRatio));
  1601. //Debug.Log("飞行兵的数量是:" + demonicDic[0].Count + ",增加的起手式伤害为" + (int)(attackInfo.damage * demonicDic[0].Count * GameManager.instance.attackRate));
  1602. }
  1603. for (int i = 0; i < attackController.attackMethod_march.Length; i++)
  1604. {
  1605. AttackInfo attackInfo = attackController.attackMethod_march[i].attackInfo;
  1606. attackInfo.damage += (int)(attackInfo.damage * demonicDic[0].Count * (GameManager.instance.attackRate * GameManager.instance.myTreasuresTag[0] * GameManager.instance.skyLabelEffectRatio));
  1607. //Debug.Log("飞行兵的数量是:" + demonicDic[0].Count + ",增加的行军式伤害为" + (int)(attackInfo.damage * demonicDic[0].Count * GameManager.instance.attackRate));
  1608. }
  1609. }
  1610. if (GameManager.instance.isGroundEnable)
  1611. {
  1612. int num = demonicDic[1].Count + demonicDic[2].Count;
  1613. //Debug.Log("地面兵的数量是:" + num + ",增加的血量为" + (int)(demonic.totalHp * num * GameManager.instance.hpRate));
  1614. demonic.totalHp += (int)(demonic.totalHp * num * (GameManager.instance.hpRate + GameManager.instance.myTreasuresTag[4] * GameManager.instance.groundLabelEffectRatio));
  1615. demonic.hp = demonic.totalHp;
  1616. demonic.uiHp.Show(demonic.hp, demonic.totalHp);
  1617. }
  1618. demonic.attributeStatus.resistances.armor = gameManager.armor;
  1619. demonic.attributeStatus.resistances.dodge = gameManager.dodge;
  1620. demonic.regeneration = gameManager.regeneration;
  1621. demonic.totalHp += gameManager.totalHp;
  1622. demonic.playerID = playerId;
  1623. demonicObj.transform.parent = null;
  1624. demonicObj.transform.localEulerAngles = Vector3.zero;
  1625. Vector3 offset = demonicSummonPos[id];
  1626. //demonic.CheckTurn(-bodyTrans.localScale.x);
  1627. if (bodyTrans.localScale.x > 0)
  1628. {
  1629. if (demonic.bodyTrans.localScale.x < 0)
  1630. {
  1631. demonic.Turn();
  1632. }
  1633. }
  1634. else
  1635. {
  1636. if (demonic.bodyTrans.localScale.x > 0)
  1637. {
  1638. demonic.Turn();
  1639. }
  1640. }
  1641. demonicObj.transform.position = transform.position
  1642. + new Vector3(bodyTrans.localScale.x > 0 ? offset.x : -offset.x, offset.y, offset.z);
  1643. if (demonic.canFly)
  1644. {
  1645. demonic.flyHeight = demonic.transform.position.y;
  1646. }
  1647. GameManager.instance.demonicAttributes[demonic.id].AddOwnAttributes(demonic);
  1648. demonic.player = this;
  1649. int order = demonicPrefabs[id].GetComponent<Demonic>().baseSortingOrder + demonicDic[demonic.id].Count;
  1650. demonic.SetSortingOrder(order);
  1651. demonic.AfterInit();
  1652. return demonic;
  1653. }
  1654. public void OnDemonicRecycle(Demonic demonic)
  1655. {
  1656. if (!demonicDic.ContainsKey(demonic.id))
  1657. {
  1658. return;
  1659. }
  1660. demonicDic[demonic.id].Remove(demonic);
  1661. if (demonic.id <= 2)
  1662. {
  1663. demonicNums[demonic.id].text = demonicDic[demonic.id].Count.ToString();
  1664. }
  1665. for (int i = 0; i < demonicDic[demonic.id].Count; i++)
  1666. {
  1667. int order = demonicDic[demonic.id][i].baseSortingOrder + i;
  1668. demonicDic[demonic.id][i].SetSortingOrder(order);
  1669. }
  1670. }
  1671. public bool CheckCanSummon(int id)
  1672. {
  1673. if(id < 3) //使魔
  1674. {
  1675. GameObject prefab;
  1676. prefab = demonicPrefabs[id];
  1677. Demonic dem = prefab.GetComponent<Demonic>();
  1678. float costMp = dem.costMp;
  1679. for (int i = 0; i < 3; i++)
  1680. {
  1681. if (GameManager.curSoldiers[i] == dem.soldierType)
  1682. {
  1683. costMp += slr.seb[i].mp;
  1684. break;
  1685. }
  1686. }
  1687. costMp += addCostMp[id] * demonicDic[id].Count;
  1688. if (mp < costMp)
  1689. {
  1690. //Debug.Log("mp不足召唤失败, 还得加个动画或者音效啥的");
  1691. return false;
  1692. }
  1693. }
  1694. else
  1695. {
  1696. if(spirits.ultimateTimes[id -3 ] < spirits.summonCost)
  1697. {
  1698. return false;
  1699. }
  1700. }
  1701. return true;
  1702. }
  1703. public void SetAttackState(PlayerAttackState value)
  1704. {
  1705. attackState = value;
  1706. ani.SetInteger("attackState", (int)value);
  1707. aniCollider.Play("Attack_summonKeep", 1, 0);
  1708. }
  1709. /*
  1710. public void SearchTarget()
  1711. {
  1712. targetCharacter = searchTrigger.GetMinDisTarget(attackController.targetTypes, attackController.canHitFly);
  1713. }*/
  1714. public override void BeHit(int damage)
  1715. {
  1716. base.BeHit(damage);
  1717. //屏幕红闪+抖动
  1718. if (ss == null)
  1719. {
  1720. ss = Camera.main.GetComponentInParent<ScreenShake>();
  1721. }
  1722. ss.enabled = true;
  1723. if (isSustainedInjury || damage >= heavyDamage)
  1724. {
  1725. ss.ShakeScreen(1);
  1726. }
  1727. }
  1728. public override void BeHit(AttackController.AttackMethod attackMethod, Character attackFrom, int damage = -1)
  1729. {
  1730. List<Photosphere> photospheres = conductController.photospheres;
  1731. if (photospheres.Count > 0)
  1732. {
  1733. Photosphere photosphere = photospheres[photospheres.Count - 1];
  1734. if (damage == -1)
  1735. {
  1736. photosphere.hp -= attackMethod.attackInfo.damage;
  1737. }
  1738. else
  1739. {
  1740. photosphere.hp -= damage;
  1741. }
  1742. return;
  1743. }
  1744. if (invincibleTime > 0)
  1745. {
  1746. return;
  1747. }
  1748. base.BeHit(attackMethod, attackFrom, damage);
  1749. //屏幕抖动
  1750. if (ss == null)
  1751. {
  1752. ss = Camera.main.GetComponentInParent<ScreenShake>();
  1753. }
  1754. ss.enabled = true;
  1755. if (isSustainedInjury || attackMethod.attackInfo.damage >= heavyDamage)
  1756. {
  1757. ss.ShakeScreen(1);
  1758. }
  1759. GameUI.instance.HurtMask((hp *1f)/totalHp);
  1760. }
  1761. }
  1762. public class DeadDemonicInformation
  1763. {
  1764. public int id;
  1765. public DeadDemonicInformation(int _id)
  1766. {
  1767. id = _id;
  1768. }
  1769. }