PlayerController.cs 55 KB

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