PlayerController.cs 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782
  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. //攻击力
  131. [Header("增加攻击力特效")]
  132. public GameObject attackEffect;
  133. [Header("攻击力献祭比例")]
  134. public float addRate;
  135. //泰山压顶
  136. [Header("泰山压顶")]
  137. public GameObject mountain;
  138. public Vector3 mountainOffset;
  139. public float largeX;
  140. //气功波
  141. public GameObject wavePowerObj;
  142. [Header("气功波伤害基数")] public int wavePowerDamage;
  143. //御剑术
  144. public GameObject flyingSwordsObj;
  145. //怨气弹
  146. public GameObject angryBulletObj;
  147. [Header("怨气弹数量基数")] public int angryBulletNum;
  148. public bool btnJumpPress
  149. {
  150. get
  151. {
  152. //return Input.GetKeyDown(KeyCode.Space) || isClickBtnJump;
  153. return isClickBtnJump;
  154. }
  155. }
  156. [HideInInspector]
  157. public bool isClickBtnJump;
  158. public bool btnRushPress
  159. {
  160. get
  161. {
  162. //return Input.GetKeyDown(KeyCode.LeftShift) || isClickBtnRush;
  163. return isClickBtnRush;
  164. }
  165. }
  166. [HideInInspector]
  167. public bool isClickBtnRush;
  168. public bool btnRushKeep
  169. {
  170. get
  171. {
  172. //return Input.GetKey(KeyCode.LeftShift) || isKeepBtnRush;
  173. return LBisHold || isKeepBtnRush;
  174. }
  175. }
  176. [HideInInspector]
  177. public bool isKeepBtnRush;
  178. public bool btnEastPress
  179. {
  180. get
  181. {
  182. return isClickBtnEast;
  183. }
  184. }
  185. [HideInInspector]
  186. public bool isClickBtnEast;
  187. public bool btnEastUp
  188. {
  189. get
  190. {
  191. return isBtnEastUp;
  192. }
  193. }
  194. [HideInInspector]
  195. public bool isBtnEastUp;
  196. public bool btnSouthPress
  197. {
  198. get
  199. {
  200. //return Input.GetKeyDown(KeyCode.K) || isClickBtnSouth;
  201. return isClickBtnSouth;
  202. }
  203. }
  204. [HideInInspector]
  205. public bool isClickBtnSouth;
  206. public bool btnSouthUp
  207. {
  208. get
  209. {
  210. //return Input.GetKeyDown(KeyCode.K) || isClickBtnSouth;
  211. return isBtnSouthUp;
  212. }
  213. }
  214. [HideInInspector]
  215. public bool isBtnSouthUp;
  216. public bool btnWestPress
  217. {
  218. get
  219. {
  220. return isClickBtnWest;
  221. }
  222. }
  223. [HideInInspector]
  224. public bool isClickBtnWest;
  225. public bool btnWestUp
  226. {
  227. get
  228. {
  229. return isBtnWestUp;
  230. }
  231. }
  232. [HideInInspector]
  233. public bool isBtnWestUp;
  234. public bool btnNorthPress
  235. {
  236. get
  237. {
  238. return isClickBtnNorth;
  239. }
  240. }
  241. [HideInInspector]
  242. public bool isClickBtnNorth;
  243. public bool btnNorthUp
  244. {
  245. get
  246. {
  247. return isBtnNorthUp;
  248. }
  249. }
  250. [HideInInspector]
  251. public bool isBtnNorthUp;
  252. public bool btnTransClick
  253. {
  254. get
  255. {
  256. return isClickBtnTrans;
  257. }
  258. }
  259. [HideInInspector]
  260. public bool isClickBtnTrans;
  261. public override void Init()
  262. {
  263. base.Init();
  264. uiHp = gameManager.p1uiHP;
  265. uiMp = gameManager.p1uiMP;
  266. uiRush = gameManager.p1uiRush;
  267. uiMp.pc = this;
  268. mp = totalMp;
  269. rushChargeNums = rushChargeTotalNums;
  270. uiMp.Show(mp, totalMp);
  271. for(int i = 0; i < rushChargeTotalNums; i++)
  272. {
  273. if (uiRush.childCount <= i)
  274. {
  275. Transform rushUIchid = Instantiate(uiRush.GetChild(0),uiRush);
  276. rushUIchid.localPosition = uiRush.GetChild(0).transform.localPosition + Vector3.right * 50 * i;
  277. }
  278. UIController.ChangeImageFill(uiRush.GetChild(i).GetComponent<Image>(), 1);
  279. }
  280. demonicNums = new TextMeshProUGUI[3];
  281. for (int i = 0; i < 3; i++)
  282. {
  283. demonicNums[i] = gameManager.demonicNum[i].GetComponentInChildren<TextMeshProUGUI>();
  284. }
  285. cannotConductFXs = new GameObject[3];
  286. for (int i = 0; i < 3; i++)
  287. {
  288. cannotConductFXs[i] = gameManager.demonicNum[i].transform.GetChild(3).gameObject;
  289. }
  290. }
  291. public override void Awake()
  292. {
  293. gameManager = GameManager.instance;
  294. gameManager.player = this;
  295. base.Awake();
  296. PlayerInput playerInput = transform.GetComponent<PlayerInput>();
  297. ss = Camera.main.GetComponentInParent<ScreenShake>();
  298. spirits = GetComponent<Spirits>();
  299. conductController = GetComponent<ConductController>();
  300. playerId = playerInput.playerIndex;
  301. Vector3 towerPos = TowerMap.myTowers[0].transform.position;
  302. transform.position = new Vector3(towerPos.x + refreshPos.x, towerPos.y + refreshPos.y, 0);
  303. switch (playerId)
  304. {
  305. case 0:
  306. PlayersInput.instance[0] = this;
  307. PlayersInput.instance[1] = this;
  308. SpiritSystem.isP1Out = true;
  309. SpiritSystem.isP1In = false;
  310. SpiritSystem.player1 = gameObject;
  311. SpiritSystem.p1Spirits = GetComponent<Spirits>();
  312. break;
  313. case 1:
  314. PlayersInput.instance[1] = this;
  315. SpiritSystem.isP2Out = true;
  316. SpiritSystem.isP2In = false;
  317. SpiritSystem.player2 = gameObject;
  318. SpiritSystem.p2Spirits = GetComponent<Spirits>();
  319. //切换为双人计算蓝量方式
  320. PlayerController p1 = PlayersInput.instance[0];
  321. mpReplySpeed = mpReplySpeed_2Players;
  322. p1.mpReplySpeed = mpReplySpeed_2Players;
  323. totalMp = totalMp_2Players;
  324. p1.totalMp = totalMp_2Players;
  325. if (mp > totalMp)
  326. {
  327. mp = totalMp;
  328. }
  329. if (p1.mp > totalMp)
  330. {
  331. p1.mp = totalMp;
  332. }
  333. uiMp.Show(mp, totalMp);
  334. p1.uiMp.Show(p1.mp, totalMp);
  335. break;
  336. default:
  337. break;
  338. }
  339. demonicDic = new Dictionary<int, List<Demonic>>();
  340. for (int i = 0; i < 5; i++)
  341. {
  342. demonicDic.Add(i, new List<Demonic>());
  343. }
  344. for (int i = 0; i < 3; i++)
  345. {
  346. PoolManager.Preloading(demonicPrefabs[i],50);
  347. }
  348. Init();
  349. spiritSystem = GameObject.Find("SpiritSystem").GetComponent<SpiritSystem>();
  350. fixedDeltaTime = Time.fixedDeltaTime;
  351. }
  352. private void Start()
  353. {
  354. slr = gameManager.GetComponent<SoldierLevelRecord>();
  355. }
  356. override public void Update()
  357. {
  358. if (LBisHold)
  359. {
  360. isKeepBtnRush = true;
  361. }
  362. if (foot.TrigGround)
  363. {
  364. //playerFX.
  365. }
  366. }
  367. void OnSprintingPress()
  368. {
  369. LBisHold = true;
  370. isClickBtnRush = true;
  371. isKeepBtnRush = true;
  372. }
  373. void OnSprintingRelease()
  374. {
  375. LBisHold = false;
  376. }
  377. //手柄按下LB
  378. [HideInInspector]
  379. public bool LBisHold;
  380. //读取手柄参数
  381. private void OnMove(InputValue value)
  382. {
  383. leftDir = value.Get<Vector2>();
  384. moveVec = value.Get<Vector2>();
  385. }
  386. void OnJump()
  387. {
  388. if (canJump)
  389. {
  390. isClickBtnJump = true;
  391. }
  392. }
  393. void OnSummon0()
  394. {
  395. if (nowConductButton == -1)
  396. {
  397. isClickBtnWest = true;
  398. nowConductButton = 0;
  399. conductTime = 0;
  400. }
  401. }
  402. void OnSummon0Up()
  403. {
  404. if (nowConductButton == 0)
  405. {
  406. isBtnWestUp = true;
  407. cacheConductId = nowConductButton;
  408. nowConductButton = -1;
  409. }
  410. }
  411. void OnSummon1()
  412. {
  413. if (nowConductButton == -1)
  414. {
  415. isClickBtnSouth = true;
  416. nowConductButton = 1;
  417. conductTime = 0;
  418. }
  419. }
  420. void OnSummon1Up()
  421. {
  422. if (nowConductButton == 1)
  423. {
  424. isBtnSouthUp = true;
  425. cacheConductId = nowConductButton;
  426. nowConductButton = -1;
  427. }
  428. }
  429. void OnSummon2()
  430. {
  431. if (nowConductButton == -1)
  432. {
  433. isClickBtnEast = true;
  434. nowConductButton = 2;
  435. conductTime = 0;
  436. }
  437. }
  438. void OnSummon2Up()
  439. {
  440. if (nowConductButton == 2)
  441. {
  442. isBtnEastUp = true;
  443. cacheConductId = nowConductButton;
  444. nowConductButton = -1;
  445. }
  446. }
  447. //选英灵 (手柄右扳机,键盘TAB)
  448. void OnChooseSpirit()
  449. {
  450. switch (playerId)
  451. {
  452. case 0:
  453. SpiritSystem.isP1CardChangeR = true;
  454. break;
  455. case 1:
  456. SpiritSystem.isP2CardChangeR = true;
  457. break;
  458. default:
  459. break;
  460. }
  461. }
  462. void OnTransfigurate()
  463. {
  464. isClickBtnTrans = true;
  465. }
  466. public void Jump()
  467. {
  468. SetUpSpeed(jumpSpeed);
  469. ani.Play("jump", 0, 0);
  470. }
  471. public void AirJump()
  472. {
  473. ChangeState(CharacterState.Rise);
  474. SetUpSpeed(airJumpSpeed);
  475. ani.Play("jump_air", 0, 0);
  476. }
  477. public void SetUpSpeed(float speed)
  478. {
  479. ChangeState(CharacterState.Rise);
  480. Vector3 velocity = rb.velocity;
  481. CheckTurn();
  482. velocity.y = speed;
  483. rb.velocity = velocity;
  484. //animalAni.SetInteger("state", (int)PlayerState.Rise);
  485. }
  486. public bool CheckSummon()
  487. {
  488. if (restSummonTime > 0)
  489. {
  490. return false;
  491. }
  492. if (state != CharacterState.Conduct
  493. && nowConductButton != -1
  494. && conductController.conductSkills[nowConductButton] != ConductSkills.Null
  495. && conductTime > totalCacheSummonTime
  496. && conductController.cd[nowConductButton] <= 0)
  497. {
  498. CheckTurn();
  499. ChangeState(CharacterState.Conduct);
  500. return true;
  501. }
  502. if (btnEastUp || btnWestUp || btnSouthUp || btnTransClick || cacheSummonTime > 0)
  503. {
  504. if(conductTime <= totalCacheSummonTime)
  505. {
  506. CheckTurn();
  507. if (!CheckCanSummon(cacheSummonId))
  508. {
  509. return false;
  510. }
  511. Summon(cacheSummonId);
  512. cacheSummonTime = 0;
  513. return true;
  514. }
  515. }
  516. return false;
  517. }
  518. public bool CheckConduct()
  519. {
  520. if (isBtnWestUp || isBtnSouthUp || isBtnEastUp)
  521. {
  522. if (isReadyConduct)
  523. {
  524. cacheSummonTime = 0;
  525. conductController.Conduct(cacheConductId);
  526. }
  527. isReadyConduct = false;
  528. return true;
  529. }
  530. if (!isReadyConduct && nowConductButton != -1)
  531. {
  532. int boostNum = demonicDic[nowConductButton].Count;
  533. int dienum;
  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_summon[i].attackInfo;
  1522. attackInfo.damage += gameManager.damage;
  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)(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_summon[i].attackInfo;
  1537. attackInfo.damage += (int)(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.attributeStatus.resistances.armor += (int)(num * GameManager.instance.armorRate);
  1544. Debug.Log("地面兵的数量是:" + num + ",增加的防御为" + (int)(num * GameManager.instance.armorRate));
  1545. }
  1546. demonic.attributeStatus.resistances.armor = gameManager.armor;
  1547. demonic.attributeStatus.resistances.dodge = gameManager.dodge;
  1548. demonic.regeneration = gameManager.regeneration;
  1549. demonic.totalHp += gameManager.totalHp;
  1550. demonic.id = id;
  1551. demonic.playerID = playerId;
  1552. demonicObj.transform.parent = null;
  1553. demonicObj.transform.localEulerAngles = Vector3.zero;
  1554. demonicObj.transform.localScale = new Vector3(1, 1, 1);
  1555. Vector3 offset = demonicSummonPos[id];
  1556. //demonic.CheckTurn(-bodyTrans.localScale.x);
  1557. if (bodyTrans.localScale.x > 0)
  1558. {
  1559. if (demonic.bodyTrans.localScale.x < 0)
  1560. {
  1561. demonic.Turn();
  1562. }
  1563. }
  1564. else
  1565. {
  1566. if (demonic.bodyTrans.localScale.x > 0)
  1567. {
  1568. demonic.Turn();
  1569. }
  1570. }
  1571. demonicObj.transform.position = transform.position
  1572. + new Vector3(bodyTrans.localScale.x > 0 ? offset.x : -offset.x, offset.y, offset.z);
  1573. if (demonic.canFly)
  1574. {
  1575. demonic.flyHeight = demonic.transform.position.y;
  1576. }
  1577. demonic.player = this;
  1578. demonic.Init();
  1579. int order = demonicPrefabs[id].GetComponent<Demonic>().baseSortingOrder + demonicDic[demonic.id].Count;
  1580. demonic.SetSortingOrder(order);
  1581. return demonic;
  1582. }
  1583. public void OnDemonicRecycle(Demonic demonic)
  1584. {
  1585. if (!demonicDic.ContainsKey(demonic.id))
  1586. {
  1587. return;
  1588. }
  1589. demonicDic[demonic.id].Remove(demonic);
  1590. if (demonic.id <= 2)
  1591. {
  1592. demonicNums[demonic.id].text = demonicDic[demonic.id].Count.ToString();
  1593. }
  1594. for (int i = 0; i < demonicDic[demonic.id].Count; i++)
  1595. {
  1596. int order = demonicDic[demonic.id][i].baseSortingOrder + i;
  1597. demonicDic[demonic.id][i].SetSortingOrder(order);
  1598. }
  1599. }
  1600. public bool CheckCanSummon(int id)
  1601. {
  1602. if(id < 3) //使魔
  1603. {
  1604. GameObject prefab;
  1605. prefab = demonicPrefabs[id];
  1606. Demonic dem = prefab.GetComponent<Demonic>();
  1607. float costMp = dem.costMp;
  1608. for (int i = 0; i < 3; i++)
  1609. {
  1610. if (GameManager.curSoldiers[i] == dem.soldierType)
  1611. {
  1612. costMp += slr.seb[i].mp;
  1613. break;
  1614. }
  1615. }
  1616. costMp += addCostMp[id] * demonicDic[id].Count;
  1617. if (mp < costMp)
  1618. {
  1619. //Debug.Log("mp不足召唤失败, 还得加个动画或者音效啥的");
  1620. return false;
  1621. }
  1622. }
  1623. else
  1624. {
  1625. if(spirits.ultimateTimes[id -3 ] < spirits.summonCost)
  1626. {
  1627. return false;
  1628. }
  1629. }
  1630. return true;
  1631. }
  1632. public void SetAttackState(PlayerAttackState value)
  1633. {
  1634. attackState = value;
  1635. ani.SetInteger("attackState", (int)value);
  1636. aniCollider.Play("Attack_summonKeep", 1, 0);
  1637. }
  1638. /*
  1639. public void SearchTarget()
  1640. {
  1641. targetCharacter = searchTrigger.GetMinDisTarget(attackController.targetTypes, attackController.canHitFly);
  1642. }*/
  1643. public override void BeHit(int damage)
  1644. {
  1645. base.BeHit(damage);
  1646. //屏幕红闪+抖动
  1647. if (ss == null)
  1648. {
  1649. ss = Camera.main.GetComponentInParent<ScreenShake>();
  1650. }
  1651. ss.enabled = true;
  1652. if (isSustainedInjury || damage >= heavyDamage)
  1653. {
  1654. ss.ShakeScreen(1);
  1655. }
  1656. }
  1657. public override void BeHit(AttackController.AttackMethod attackMethod, Character attackFrom, int damage = -1)
  1658. {
  1659. Photosphere photosphere = conductController.photosphere;
  1660. if (photosphere)
  1661. {
  1662. if(damage == -1)
  1663. {
  1664. photosphere.hp -= attackMethod.attackInfo.damage;
  1665. }
  1666. else
  1667. {
  1668. photosphere.hp -= damage;
  1669. }
  1670. return;
  1671. }
  1672. base.BeHit(attackMethod, attackFrom);
  1673. //屏幕抖动
  1674. if (ss == null)
  1675. {
  1676. ss = Camera.main.GetComponentInParent<ScreenShake>();
  1677. }
  1678. ss.enabled = true;
  1679. if (isSustainedInjury || attackMethod.attackInfo.damage >= heavyDamage)
  1680. {
  1681. ss.ShakeScreen(1);
  1682. }
  1683. GameUI.instance.HurtMask((hp *1f)/totalHp);
  1684. }
  1685. }