PlayerController.cs 69 KB

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