PlayerController.cs 69 KB

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