PlayerController.cs 72 KB

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