PlayerController.cs 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Spine;
  5. using Spine.Unity;
  6. using UnityEngine.LowLevel;
  7. using UnityEngine.Playables;
  8. using System.ComponentModel;
  9. using Unity.VisualScripting;
  10. using System;
  11. using Base.Common;
  12. using cfg;
  13. using static UnityEngine.EventSystems.EventTrigger;
  14. using UnityEngine.InputSystem;
  15. using TMPro;
  16. [Serializable]
  17. public struct AttackInfo
  18. {
  19. public int damage;
  20. public Vector3 attackDir;
  21. public float force;
  22. public bool changeHurt;
  23. public float repelValue;
  24. }
  25. public enum PlayerAttackState
  26. {
  27. Idle = 0,
  28. WalkForward = 1,
  29. WalkBack = 2,
  30. }
  31. public class PlayerController : MoveCharacter
  32. {
  33. [Header("玩家属性")]
  34. public int playerId;
  35. public bool canJump;
  36. public bool endTranSummon; //是否在结束变身后召唤英灵
  37. [Header("变身英灵")]
  38. public bool isUltimate; //英灵释放大招
  39. public bool keyTransfigurateRelease; //松开英灵释放大招键
  40. public List<GameObject> changePrefabs;
  41. public int[] needCorpses;
  42. private GameObject spiritObj; //当前变身的对象
  43. public int endChange = 0; //结束变身后召唤的英灵
  44. public Vector2 rightDir;
  45. [Header("玩家组件")]
  46. public UIHP uiMp;
  47. public PlayerRope playerRope;
  48. public EventTrigger eventTrigger;
  49. public SprintLinkTrigger sprintLinkTrigger;
  50. private Spirits spirits;
  51. public Collider soulCollector;
  52. public SkeletonMecanim skeletonMecanim;
  53. public SkeletonDataAsset[] playerSpine;
  54. private SpiritSystem spiritSystem;
  55. [Header("血量")]
  56. private int curHp;
  57. private int curTotalHp;
  58. [Header("蓝耗")]
  59. public float mp;
  60. public float totalMp;
  61. public float totalMp_2Players; //双人模式下总蓝量
  62. public bool isMpRepel = true;
  63. public bool isRapedReply;
  64. public float mpReplySpeed;
  65. public float mpReplySpeed_2Players; //双人模式下蓝量回复速度
  66. public float rapidReplySpeed;
  67. public float lostMp;
  68. private float addMp = 10;
  69. public GameObject soul;
  70. public GameObject rapidReplyEffect;
  71. [Tooltip("场上每多一个同种类兵种,召唤兵种蓝耗+x")]public float[] addCostMp;
  72. [Header("移动属性")]
  73. public Vector2 moveVec; //玩家不动时移动数据
  74. [HideInInspector]
  75. public Vector2 leftDir;
  76. [Header("冲刺属性")]
  77. public float rushSpeed = 100;
  78. public float rushCostMp = 5;
  79. public Vector3 rushDir;
  80. public float rushInvincibleTime = 0.2f;
  81. [HideInInspector]
  82. public float rushTime;
  83. public float totalRushTime = 0.5f;
  84. [HideInInspector]
  85. public float cacheRushTime; //无法Rush时按下Rush键不会Rush,手感不好,缓存几帧,在这几帧内落地会立即Rush;
  86. public float totalCacheRushTime = 0.1f;
  87. [Header("链条属性")]
  88. public float sprintCostMp = 5;
  89. [HideInInspector]
  90. public float cachePullRopeTime;
  91. public float totalCachePullRopeTime = 0.1f;
  92. [Header("跳跃属性")]
  93. public float jumpSpeed = 10;
  94. public float airJumpSpeed = 10;
  95. public int airJumped;
  96. public int airJumpNumber = 1; //最大跳跃次数
  97. public float canAirJumpSpeed = 5;//y轴速度大于这个值时不能进行空中跳跃
  98. [HideInInspector]
  99. public float canJumpTime; //离开平台后仍然可以跳跃的时间,用于提升手感
  100. public float leaveGroundCanJumpTime = 0.1f;
  101. [HideInInspector]
  102. public float cacheJumpTime; //即将落地时按下跳跃键不会跳跃,手感不好,缓存几帧,在这几帧内落地会立即跳跃;
  103. public float totalCacheJumpTime = 0.1f;
  104. [Header("飞行属性")]
  105. public float flySpeed = 5;
  106. public float maxFlyHeight;
  107. [Header("召唤属性")]
  108. [HideInInspector]
  109. public float cacheDir; //召唤的时候按左右召唤结束不会响应手感不好,缓存一下,召唤后摇期间有左右响应的话会转向
  110. [HideInInspector]
  111. public bool cacheRush; //召唤的时候按冲刺结束不会响应手感不好,缓存一下,召唤后摇期间按下冲刺的话会冲刺
  112. [HideInInspector]
  113. public float summonTime;
  114. [HideInInspector]
  115. public float cacheSummonTime; //无法召唤时按下召唤键不会召唤,手感不好,缓存几帧,在这几帧内落地会立即召唤;
  116. [HideInInspector]
  117. public int cacheSummonId;
  118. [Header("召唤使魔")]
  119. public TextMeshProUGUI[] demonicNums;
  120. public GameObject[] cannotConductFXs;
  121. public List<GameObject> demonicPrefabs;
  122. public List<Vector3> demonicSummonPos;
  123. public Dictionary<int, List<Demonic>> demonicDic;
  124. private List<Demonic> arrows = new List<Demonic>();
  125. private List<Demonic> giants = new List<Demonic>();
  126. private List<Demonic> swords = new List<Demonic>();
  127. [Header("攻击")]
  128. public PlayerAttackState attackState;
  129. public float attackMoveSpeed = 5f;
  130. [HideInInspector]
  131. public float cacheAttackTime; //无法攻击时按下攻击键不会攻击,手感不好,缓存几帧,在这几帧内落地会立即攻击;
  132. public float totalCacheAttackTime = 0.1f;
  133. [Header("复活")]
  134. public float reviveTime; //复活时间
  135. public float totalReviveTime;
  136. [Header("玩家是否在基地")]
  137. public bool isBaseBtnOut = false;
  138. [Header("八卦")]
  139. public ChooseYinYang chooseYinYang;
  140. [Header("锁魂塔")]
  141. public GameObject curSoulTower;
  142. //指挥功能
  143. private float conductTime; //指挥按键长按时间
  144. private int nowConductButton = -1; //现在按下的指挥键(0.J/1.K/2.L/-1.无)
  145. private int cacheConductId;
  146. [Header("召唤相应时间")] [Tooltip("在此时间内松手为召唤")] public float totalCacheSummonTime;
  147. [Header("融魂相应时间")] [Tooltip("在此时间以外松手为融魂")] public float[] canConductTime;
  148. [Header("融魂技")] [Tooltip("选择相应的融魂技能")] public ConductSkills[] conductSkills;
  149. public bool[] conductCanRelease; //能否进入指挥技蓄力状态
  150. public ConductReadyTip conductReadyTip; //指挥技就绪
  151. private bool isReadyConduct;
  152. [Header("时间倍率")] [Tooltip("时间速度放慢到正常的几倍")] public float timeSlowingMultiplier;
  153. public float readyTipFxTime;
  154. [Header("转换率")] public float[] conversionRate;
  155. //大胖子
  156. [Header("融合临时血量基数")] public int temptHp;
  157. [Header("融合血量持续时间")]public float temptTime;
  158. public GameObject[] bigGiant;
  159. public float[] stageSize;
  160. public int[] giantDieNum;
  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(142 + 4 * playerId, 0, 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. private float TranSize(int dieNum)
  738. {
  739. for (int i = stageSize.Length - 1; i >= 0; i--)
  740. {
  741. if (dieNum >= giantDieNum[i])
  742. {
  743. if (i == stageSize.Length - 1)
  744. {
  745. return stageSize[i];
  746. }
  747. float size = stageSize[i] + (stageSize[i + 1] - stageSize[i]) / (giantDieNum[i + 1] - giantDieNum[i]) * (dieNum - giantDieNum[i]);
  748. return size;
  749. }
  750. }
  751. return 1;
  752. }
  753. public void Conduct()
  754. {
  755. int boostNum = demonicDic[cacheConductId].Count;
  756. int dienum = Mathf.RoundToInt(boostNum * conversionRate[cacheConductId]);
  757. if (dienum == 0 && boostNum >= 1)
  758. {
  759. dienum = 1;
  760. }
  761. if (dienum > 0)
  762. {
  763. GameObject obj;
  764. List<int> dieId = new List<int>();
  765. List<Demonic> dieDemonic = new List<Demonic>();
  766. while(dieId.Count<dienum)
  767. {
  768. int id = UnityEngine.Random.Range(0, boostNum);
  769. if(!dieId.Exists(t=> t == id))
  770. {
  771. dieId.Add(id);
  772. dieDemonic.Add(demonicDic[cacheConductId][id]);
  773. }
  774. }
  775. foreach (Demonic d in dieDemonic)
  776. {
  777. d.ChangeState(CharacterState.Die);
  778. }
  779. switch (conductSkills[cacheConductId])
  780. {
  781. //胖子
  782. case ConductSkills.Giant:
  783. GameObject demonicObj = PoolManager.Instantiate(bigGiant[cacheConductId]);
  784. Demonic demonic = demonicObj.GetComponent<Demonic>();
  785. demonic.id = cacheConductId;
  786. demonicDic[demonic.id].Add(demonic);
  787. demonicNums[demonic.id].text = demonicDic[demonic.id].Count.ToString();
  788. int tempthp = boostNum * temptHp;
  789. demonic.playerID = playerId;
  790. demonicObj.transform.parent = null;
  791. demonicObj.transform.localEulerAngles = Vector3.zero;
  792. demonicObj.transform.localScale = new Vector3(1, 1, 1) * TranSize(boostNum);
  793. Vector3 offset = demonicSummonPos[0] * 2;
  794. if (bodyTrans.localScale.x > 0)
  795. {
  796. demonicObj.transform.position = transform.position + offset;
  797. if (demonic.bodyTrans.localScale.x < 0)
  798. {
  799. demonic.Turn();
  800. }
  801. }
  802. else
  803. {
  804. demonicObj.transform.position = transform.position + new Vector3(-offset.x, offset.y, offset.z);
  805. if (demonic.bodyTrans.localScale.x > 0)
  806. {
  807. demonic.Turn();
  808. }
  809. }
  810. demonic.player = this;
  811. demonic.totalHp = (int)(TranSize(boostNum) * demonic.totalHp);
  812. demonic.Init();
  813. int order = demonic.baseSortingOrder + demonicDic[demonic.id].Count;
  814. demonic.SetSortingOrder(order);
  815. if (isInSoulTower)
  816. {
  817. ls.AddDenomic(demonic);
  818. }
  819. demonic.GetTemptHP(tempthp, temptTime);
  820. break;
  821. case ConductSkills.Photosphere:
  822. conductCanRelease[cacheConductId] = false;
  823. obj = Instantiate(photosphereObj, transform);
  824. obj.transform.position = transform.position + Vector3.up;
  825. Photosphere photosphere = obj.GetComponent<Photosphere>();
  826. photosphere.owner = this;
  827. photosphere.conductId = cacheConductId;
  828. photosphere.hp = boostNum * photosphereHp;
  829. break;
  830. case ConductSkills.AddAttack:
  831. List<Demonic> newGiants = new List<Demonic>();
  832. foreach (Demonic d in demonicDic[cacheConductId])
  833. {
  834. if (!d.isDie)
  835. {
  836. newGiants.Add(d);
  837. if (d.addAttackEffect == null)
  838. {
  839. d.addAttackEffect = Instantiate(attackEffect, d.bodyTrans.position, new Quaternion(0, 0, 0, 0), d.bodyTrans);
  840. }
  841. d.addAttackEffect.transform.GetChild(0).gameObject.SetActive(true);
  842. }
  843. }
  844. giants = newGiants;
  845. foreach (Demonic d in giants)
  846. {
  847. int[] damages = d.curDamage2;
  848. for (int i = 0; i < damages.Length; i++)
  849. {
  850. damages[i] += (int)(addRate * boostNum * damages[i]);
  851. }
  852. d.curDamage2 = damages;
  853. }
  854. break;
  855. //气功师
  856. case ConductSkills.Mountain:
  857. conductCanRelease[cacheConductId] = false;
  858. GameObject curMountain = Instantiate(mountain, null);
  859. Vector3 moffset = mountainOffset;
  860. Vector3 sc = curMountain.transform.localScale;
  861. sc.x = largeX * dienum;
  862. curMountain.transform.localScale = sc;
  863. if (bodyTrans.localScale.x < 0)
  864. {
  865. moffset.x = mountainOffset.x + sc.x / 2;
  866. }
  867. else
  868. {
  869. moffset.x = -mountainOffset.x - sc.x / 2;
  870. }
  871. Mountain MT = curMountain.GetComponent<Mountain>();
  872. curMountain.transform.position = transform.position + moffset;
  873. MT.pc = this;
  874. MT.id = cacheConductId;
  875. MT.demonicNum = boostNum;
  876. break;
  877. case ConductSkills.WavePower:
  878. canMove = false;
  879. rb.constraints = RigidbodyConstraints.FreezeAll;
  880. rb.useGravity = false;
  881. conductCanRelease[cacheConductId] = false;
  882. obj = Instantiate(wavePowerObj, transform);
  883. obj.transform.position = transform.position + Vector3.up;
  884. WavePowerSkill wps = obj.GetComponent<WavePowerSkill>();
  885. wps.continueTime = wps.singleTime * dienum;
  886. wps.longFX = (int)bodyTrans.localScale.x;
  887. wps.damage = wavePowerDamage * boostNum;
  888. wps.cacheID = cacheConductId;
  889. wps.pc = this;
  890. break;
  891. case ConductSkills.SwordsControl:
  892. conductCanRelease[cacheConductId] = false;
  893. obj = Instantiate(flyingSwordsObj, transform);
  894. obj.transform.position = transform.position + Vector3.up;
  895. SwordsControl swordsControl = obj.GetComponentInChildren<SwordsControl>();
  896. swordsControl.owner = this;
  897. swordsControl.conductId = cacheConductId;
  898. swordsControl.boostNum = boostNum;
  899. break;
  900. //弓箭手
  901. case ConductSkills.AngryBullet:
  902. conductCanRelease[cacheConductId] = false;
  903. obj = Instantiate(angryBulletObj);
  904. AngryBulletControl angryBulletControl = obj.GetComponent<AngryBulletControl>();
  905. angryBulletControl.playerController = this;
  906. angryBulletControl.cacheConductId = cacheConductId;
  907. angryBulletControl.maxNum = boostNum * angryBulletNum;
  908. break;
  909. case ConductSkills.FlyingSwords:
  910. obj = Instantiate(fanFlyingSwords);
  911. FanFlyingSwords FFS = obj.GetComponent<FanFlyingSwords>();
  912. FFS.owner = this;
  913. FFS.angleRange = flyingSwordsAngleRange;
  914. FFS.arrivalAngle = flyintSwordsArrivalAngle;
  915. FFS.swordsNum = boostNum * flyingSwordsNum;
  916. FFS.Biu();
  917. break;
  918. }
  919. }
  920. else
  921. {
  922. print("使魔不足");
  923. }
  924. }
  925. private int cannotConductfx;
  926. private void CannotConductFX(int id)
  927. {
  928. cannotConductfx = id;
  929. cannotConductFXs[id].SetActive(true);
  930. Invoke("CannotConductFXFade", 0.2f);
  931. }
  932. private void CannotConductFXFade()
  933. {
  934. cannotConductFXs[cannotConductfx].SetActive(false);
  935. }
  936. //角色处于可自由活动状态时的通用切换状态逻辑,如Idle、Run状态,以及别的状态结束时准备回到Idle状态前
  937. public bool CheckPlayerChangeState(CharacterState excludeState = CharacterState.None)
  938. {
  939. if (!foot.TrigGround)
  940. {
  941. //if(excludeState != CharacterState.Summon)
  942. //{
  943. // if (CheckSummon())
  944. // {
  945. // return true;
  946. // }
  947. //}
  948. if (excludeState != CharacterState.Summon || excludeState != CharacterState.Conduct)
  949. {
  950. if (CheckSummon())
  951. {
  952. return true;
  953. }
  954. }
  955. if ((btnRushPress || cacheRushTime > 0 || cacheRush) && mp >= rushCostMp)
  956. {
  957. if (excludeState != CharacterState.Rush)
  958. {
  959. cacheRush = false;
  960. ChangeState(CharacterState.Rush);
  961. return true;
  962. }
  963. }
  964. if (rb.velocity.y > 0)
  965. {
  966. if (excludeState != CharacterState.Rise)
  967. {
  968. ChangeState(CharacterState.Rise);
  969. return true;
  970. }
  971. }
  972. else
  973. {
  974. if (excludeState != CharacterState.Fall)
  975. {
  976. ChangeState(CharacterState.Fall);
  977. return true;
  978. }
  979. }
  980. }
  981. else
  982. {
  983. airJumped = 0;
  984. //if (btnNorthPress || cacheAttackTime > 0)
  985. //{
  986. // if (excludeState != CharacterState.Attack)
  987. // {
  988. // Attack_summon();
  989. // return true;
  990. // }
  991. //}
  992. if (eventTrigger.triggedRivet && (btnNorthPress || cachePullRopeTime > 0))
  993. {
  994. if (sprintLinkTrigger.linkedEnemy.Count > 0)
  995. {
  996. eventTrigger.triggedRivet.BindingRopes(sprintLinkTrigger.linkedEnemy);
  997. }
  998. //ChangeState(CharacterState.PullRope);
  999. }
  1000. if (excludeState != CharacterState.Summon || excludeState != CharacterState.Conduct)
  1001. {
  1002. if (CheckSummon())
  1003. {
  1004. return true;
  1005. }
  1006. }
  1007. if ((btnRushPress || cacheRushTime > 0 || cacheRush) && mp >= rushCostMp )
  1008. {
  1009. if (excludeState != CharacterState.Rush)
  1010. {
  1011. cacheRush = false;
  1012. ChangeState(CharacterState.Rush);
  1013. return true;
  1014. }
  1015. }
  1016. if (btnJumpPress || cacheJumpTime > 0)
  1017. {
  1018. if (excludeState != CharacterState.Rise)
  1019. {
  1020. Jump();
  1021. ChangeState(CharacterState.Rise);
  1022. return true;
  1023. }
  1024. }
  1025. if (leftDir.y < -0.5)
  1026. {
  1027. Platform platform = foot.trigGroundList[0].GetComponent<Platform>();
  1028. if (platform != null && platform.canDown)
  1029. {
  1030. foot.trigGroundList.Remove(platform.gameObject);
  1031. }
  1032. }
  1033. if (canFly)
  1034. {
  1035. if (leftDir.x > 0.3f || leftDir.x < -0.3f || leftDir.y > 0.3f || leftDir.y < -0.3f)
  1036. {
  1037. if (excludeState != CharacterState.Run)
  1038. {
  1039. ChangeState(CharacterState.Run);
  1040. return true;
  1041. }
  1042. }
  1043. else
  1044. {
  1045. if (excludeState != CharacterState.Idle)
  1046. {
  1047. ChangeState(CharacterState.Idle);
  1048. return true;
  1049. }
  1050. }
  1051. }
  1052. else
  1053. {
  1054. if (leftDir.x > 0.3f || leftDir.x < -0.3f)
  1055. {
  1056. if (excludeState != CharacterState.Run)
  1057. {
  1058. ChangeState(CharacterState.Run);
  1059. return true;
  1060. }
  1061. }
  1062. else
  1063. {
  1064. if (excludeState != CharacterState.Idle)
  1065. {
  1066. ChangeState(CharacterState.Idle);
  1067. return true;
  1068. }
  1069. }
  1070. }
  1071. }
  1072. return false;
  1073. }
  1074. public override Vector3 GetMoveDir()
  1075. {
  1076. return leftDir;
  1077. }
  1078. public void CachedPlayerInput()
  1079. {
  1080. if (btnRushPress)
  1081. {
  1082. cacheRushTime = totalCacheRushTime;
  1083. }
  1084. if (btnJumpPress)
  1085. {
  1086. cacheJumpTime = totalCacheJumpTime;
  1087. }
  1088. if (btnNorthPress)
  1089. {
  1090. cacheAttackTime = totalCacheAttackTime;
  1091. }
  1092. if (btnWestPress)
  1093. {
  1094. cacheSummonTime = totalCacheSummonTime;
  1095. cacheSummonId = 0;
  1096. }
  1097. if (btnSouthPress)
  1098. {
  1099. cacheSummonTime = totalCacheSummonTime;
  1100. cacheSummonId = 1;
  1101. }
  1102. if (btnEastPress)
  1103. {
  1104. cacheSummonTime = totalCacheSummonTime;
  1105. cacheSummonId = 2;
  1106. }
  1107. //if (btnSpiritSummon)
  1108. //{
  1109. // cacheSummonTime = totalCacheSummonTime;
  1110. // cacheSummonId = 3;
  1111. //}
  1112. //if (btnSpiritSummon1)
  1113. //{
  1114. // cacheSummonTime = totalCacheSummonTime;
  1115. // cacheSummonId = 4;
  1116. //}
  1117. //if (btnSpiritSummon2)
  1118. //{
  1119. // cacheSummonTime = totalCacheSummonTime;
  1120. // cacheSummonId = 5;
  1121. //}
  1122. //if (btnSpiritSummon3)
  1123. //{
  1124. // cacheSummonTime = totalCacheSummonTime;
  1125. // cacheSummonId = 6;
  1126. //}
  1127. }
  1128. public override void OnState()
  1129. {
  1130. base.OnState();
  1131. cacheJumpTime -= Time.deltaTime;
  1132. cacheAttackTime -= Time.deltaTime;
  1133. cacheSummonTime -= Time.deltaTime;
  1134. canJumpTime -= Time.deltaTime;
  1135. invincibleTime -= Time.deltaTime;
  1136. attackTime -= Time.deltaTime;
  1137. summonTime -= Time.deltaTime;
  1138. rushTime -= Time.deltaTime;
  1139. cacheRushTime -= Time.deltaTime;
  1140. dieKeepTime -= Time.deltaTime;
  1141. weakTime -= Time.deltaTime;
  1142. beRepelValue += Time.deltaTime;
  1143. if (nowConductButton != -1)
  1144. {
  1145. conductTime += Time.deltaTime;
  1146. }
  1147. CachedPlayerInput();
  1148. Vector3 velocity = rb.velocity;
  1149. switch (state)
  1150. {
  1151. case CharacterState.Idle:
  1152. if (CheckPlayerChangeState(CharacterState.Idle))
  1153. {
  1154. break;
  1155. }
  1156. rb.velocity = Vector3.right * velocityAddition;
  1157. break;
  1158. case CharacterState.Run:
  1159. if (CheckPlayerChangeState(CharacterState.Run))
  1160. {
  1161. break;
  1162. }
  1163. CheckTurn();
  1164. if (canFly)
  1165. {
  1166. rb.velocity = leftDir.normalized * moveSpeed;
  1167. }
  1168. else
  1169. {
  1170. if (leftDir.x > 0.3f)
  1171. {
  1172. rb.velocity = new Vector3(moveSpeed + velocityAddition, 0, 0);
  1173. }
  1174. else if (leftDir.x < -0.3f)
  1175. {
  1176. rb.velocity = new Vector3(-moveSpeed + velocityAddition, 0, 0);
  1177. }
  1178. }
  1179. break;
  1180. case CharacterState.Rise:
  1181. if (CheckSummon())
  1182. {
  1183. break;
  1184. }
  1185. if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
  1186. {
  1187. ChangeState(CharacterState.Rush);
  1188. break;
  1189. }
  1190. if (btnJumpPress || cacheJumpTime > 0)
  1191. {
  1192. if (airJumped < airJumpNumber && rb.velocity.y < canAirJumpSpeed)
  1193. {
  1194. airJumped++;
  1195. AirJump();
  1196. break;
  1197. }
  1198. }
  1199. rb.velocity = AirMove(rb.velocity);
  1200. if (rb.velocity.y <= 0)
  1201. {
  1202. ChangeState(CharacterState.Fall);
  1203. break;
  1204. }
  1205. break;
  1206. case CharacterState.Fall:
  1207. if (CheckSummon())
  1208. {
  1209. break;
  1210. }
  1211. if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
  1212. {
  1213. ChangeState(CharacterState.Rush);
  1214. break;
  1215. }
  1216. if (foot.TrigGround)
  1217. {
  1218. if (CheckPlayerChangeState())
  1219. {
  1220. break;
  1221. }
  1222. }
  1223. //if (foot.canStepPlayers.Count > 0)
  1224. //{
  1225. // Jump(jumpSpeed / 2);
  1226. // StepOther();
  1227. // break;
  1228. //}
  1229. //if (foot.canStepEnemyList.Count > 0)
  1230. //{
  1231. // Jump(jumpSpeed / 2);
  1232. // StepEnemy();
  1233. // break;
  1234. //}
  1235. if (btnJumpPress || cacheJumpTime > 0)
  1236. {
  1237. if (canJumpTime > 0)
  1238. {
  1239. Jump();
  1240. break;
  1241. }
  1242. else
  1243. {
  1244. if (airJumped < airJumpNumber)
  1245. {
  1246. airJumped++;
  1247. AirJump();
  1248. break;
  1249. }
  1250. }
  1251. }
  1252. rb.velocity = AirMove(rb.velocity);
  1253. break;
  1254. //case CharacterState.Hurt:
  1255. // if (hurtKeepTime <= 0 && rb.velocity.magnitude < hurtChangeVelocity)
  1256. // {
  1257. // if (CheckPlayerChangeState())
  1258. // {
  1259. // break;
  1260. // }
  1261. // }
  1262. // Vector3 vel = rb.velocity;
  1263. // if (!foot.TrigGround)
  1264. // {
  1265. // if (canfly)
  1266. // {
  1267. // vel.y = vel.y * (1 - decelerationRatio * Time.deltaTime);
  1268. // }
  1269. // else
  1270. // {
  1271. // vel += Vector3.up * extraFallGravity * Time.deltaTime;
  1272. // }
  1273. // }
  1274. // vel.x = vel.x * (1 - decelerationRatio * Time.deltaTime);
  1275. // rb.velocity = vel;
  1276. // CachedPlayerInput();
  1277. // break;
  1278. case CharacterState.Coma:
  1279. break;
  1280. case CharacterState.Attack:
  1281. if (attackTime <= 0)
  1282. {
  1283. if (btnNorthKeep)
  1284. {
  1285. ChangeState(CharacterState.KeepAttack);
  1286. break;
  1287. }
  1288. if (CheckPlayerChangeState())
  1289. {
  1290. break;
  1291. }
  1292. }
  1293. break;
  1294. case CharacterState.KeepAttack:
  1295. if ((btnRushPress) && mp >= rushCostMp)
  1296. {
  1297. ChangeState(CharacterState.Rush);
  1298. break;
  1299. }
  1300. if (btnJumpPress && canJumpTime > 0)
  1301. {
  1302. Jump();
  1303. break;
  1304. }
  1305. if (!btnNorthKeep)
  1306. {
  1307. if (CheckPlayerChangeState(CharacterState.Attack))
  1308. {
  1309. break;
  1310. }
  1311. }
  1312. switch (attackState)
  1313. {
  1314. case PlayerAttackState.Idle:
  1315. if (bodyTrans.localScale.x > 0)
  1316. {
  1317. if (leftDir.x > 0.3f)
  1318. {
  1319. SetAttackState(PlayerAttackState.WalkBack);
  1320. velocity.x = attackMoveSpeed;
  1321. rb.velocity = velocity;
  1322. break;
  1323. }
  1324. else if (leftDir.x < -0.3f)
  1325. {
  1326. SetAttackState(PlayerAttackState.WalkForward);
  1327. velocity.x = -attackMoveSpeed;
  1328. rb.velocity = velocity;
  1329. break;
  1330. }
  1331. }
  1332. else
  1333. {
  1334. if (leftDir.x > 0.3f)
  1335. {
  1336. SetAttackState(PlayerAttackState.WalkForward);
  1337. velocity.x = attackMoveSpeed;
  1338. rb.velocity = velocity;
  1339. break;
  1340. }
  1341. else if (leftDir.x < -0.3f)
  1342. {
  1343. SetAttackState(PlayerAttackState.WalkBack);
  1344. velocity.x = -attackMoveSpeed;
  1345. rb.velocity = velocity;
  1346. break;
  1347. }
  1348. }
  1349. velocity.x = 0;
  1350. rb.velocity = velocity;
  1351. break;
  1352. case PlayerAttackState.WalkForward:
  1353. if (bodyTrans.localScale.x > 0)
  1354. {
  1355. if (leftDir.x > 0.3f)
  1356. {
  1357. SetAttackState(PlayerAttackState.WalkBack);
  1358. velocity.x = attackMoveSpeed;
  1359. rb.velocity = velocity;
  1360. break;
  1361. }
  1362. else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
  1363. {
  1364. SetAttackState(PlayerAttackState.Idle);
  1365. velocity.x = 0;
  1366. rb.velocity = velocity;
  1367. break;
  1368. }
  1369. else
  1370. {
  1371. velocity.x = -attackMoveSpeed;
  1372. rb.velocity = velocity;
  1373. }
  1374. }
  1375. else
  1376. {
  1377. if (leftDir.x < -0.3f)
  1378. {
  1379. SetAttackState(PlayerAttackState.WalkBack);
  1380. velocity.x = -attackMoveSpeed;
  1381. rb.velocity = velocity;
  1382. break;
  1383. }
  1384. else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
  1385. {
  1386. SetAttackState(PlayerAttackState.Idle);
  1387. velocity.x = 0;
  1388. rb.velocity = velocity;
  1389. break;
  1390. }
  1391. else
  1392. {
  1393. velocity.x = attackMoveSpeed;
  1394. rb.velocity = velocity;
  1395. }
  1396. }
  1397. break;
  1398. case PlayerAttackState.WalkBack:
  1399. if (bodyTrans.localScale.x > 0)
  1400. {
  1401. if (leftDir.x < -0.3f)
  1402. {
  1403. SetAttackState(PlayerAttackState.WalkForward);
  1404. velocity.x = -attackMoveSpeed;
  1405. rb.velocity = velocity;
  1406. break;
  1407. }
  1408. else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
  1409. {
  1410. SetAttackState(PlayerAttackState.Idle);
  1411. velocity.x = 0;
  1412. rb.velocity = velocity;
  1413. break;
  1414. }
  1415. else
  1416. {
  1417. velocity.x = attackMoveSpeed;
  1418. rb.velocity = velocity;
  1419. }
  1420. }
  1421. else
  1422. {
  1423. if (leftDir.x > 0.3f)
  1424. {
  1425. SetAttackState(PlayerAttackState.WalkForward);
  1426. velocity.x = attackMoveSpeed;
  1427. rb.velocity = velocity;
  1428. break;
  1429. }
  1430. else if (leftDir.x > -0.3f && leftDir.x > 0.3f)
  1431. {
  1432. SetAttackState(PlayerAttackState.Idle);
  1433. velocity.x = 0;
  1434. rb.velocity = velocity;
  1435. break;
  1436. }
  1437. else
  1438. {
  1439. velocity.x = -attackMoveSpeed;
  1440. rb.velocity = velocity;
  1441. }
  1442. }
  1443. break;
  1444. default:
  1445. break;
  1446. }
  1447. break;
  1448. case CharacterState.Summon:
  1449. if (leftDir.x > 0.3f || leftDir.x < -0.3f)
  1450. {
  1451. cacheDir = leftDir.x;
  1452. }
  1453. if (LBisHold)
  1454. {
  1455. cacheRush = true;
  1456. }
  1457. if (summonTime <= 0 || btnTransfiguratePress)
  1458. {
  1459. if (CheckPlayerChangeState())
  1460. {
  1461. break;
  1462. }
  1463. }
  1464. rb.velocity = Vector3.right * velocityAddition;
  1465. break;
  1466. case CharacterState.Rush:
  1467. if (rushTime <= 0)
  1468. {
  1469. if (btnRushKeep)
  1470. {
  1471. ChangeState(CharacterState.Sprint);
  1472. break;
  1473. }
  1474. if (CheckPlayerChangeState())
  1475. {
  1476. break;
  1477. }
  1478. }
  1479. //if (leftDir.magnitude < 0.3f)
  1480. //{
  1481. // if (bodyTrans.localScale.x > 0)
  1482. // {
  1483. // rushDir = Vector3.left;
  1484. // }
  1485. // else
  1486. // {
  1487. // rushDir = Vector3.right;
  1488. // }
  1489. //}
  1490. //else
  1491. //{
  1492. // rushDir = leftDir.normalized;
  1493. //}
  1494. rb.velocity = rushDir * rushSpeed;
  1495. break;
  1496. case CharacterState.Sprint:
  1497. if (!btnRushKeep)
  1498. {
  1499. if (CheckPlayerChangeState(CharacterState.Rush))
  1500. {
  1501. break;
  1502. }
  1503. }
  1504. if (mp < sprintCostMp * Time.deltaTime)
  1505. {
  1506. if (CheckPlayerChangeState(CharacterState.Rush))
  1507. {
  1508. break;
  1509. }
  1510. }
  1511. mp -= sprintCostMp * Time.deltaTime;
  1512. uiMp.Show(mp, totalMp);
  1513. //CheckTurn();
  1514. //if (leftDir.magnitude < 0.3f)
  1515. //{
  1516. // if (bodyTrans.localScale.x > 0)
  1517. // {
  1518. // rushDir = Vector3.left;
  1519. // }
  1520. // else
  1521. // {
  1522. // rushDir = Vector3.right;
  1523. // }
  1524. //}
  1525. //else
  1526. //{
  1527. // rushDir = leftDir.normalized;
  1528. //}
  1529. rb.velocity = rushDir * rushSpeed;
  1530. break;
  1531. case CharacterState.Die:
  1532. if (dieKeepTime <= 0)
  1533. {
  1534. if (isRevive)
  1535. {
  1536. reviveTime += Time.deltaTime;
  1537. if (reviveTime >= totalReviveTime)
  1538. {
  1539. PlayerRevive();
  1540. }
  1541. }
  1542. else
  1543. {
  1544. PlayerDie();
  1545. }
  1546. }
  1547. break;
  1548. case CharacterState.Weak:
  1549. if (rb.velocity.magnitude > 1)
  1550. {
  1551. if (ani.GetCurrentAnimatorClipInfo(0)[0].clip.name != "hitted")
  1552. {
  1553. ani.Play("hitted", 0, 0);
  1554. aniCollider.Play("Hurt", 0, 0);
  1555. }
  1556. Vector3 vel = rb.velocity;
  1557. if (!canFly)
  1558. {
  1559. if (foot.TrigGround && vel.y < 0)
  1560. {
  1561. vel.y = 0;
  1562. }
  1563. else
  1564. {
  1565. vel += Vector3.up * extraFallGravity * Time.deltaTime;
  1566. }
  1567. }
  1568. vel.y = vel.y * (1 - decelerationRatio * Time.deltaTime);
  1569. vel.x = vel.x * (1 - decelerationRatio * Time.deltaTime);
  1570. rb.velocity = vel;
  1571. }
  1572. else
  1573. {
  1574. if (ani.GetCurrentAnimatorClipInfo(0)[0].clip.name != "weak")
  1575. {
  1576. ani.Play("weak", 0, 0);
  1577. aniCollider.Play("Weak", 0, 0);
  1578. rb.velocity = Vector3.zero;
  1579. weakTime = totalWeakTime;
  1580. }
  1581. rb.velocity = new Vector3(velocityAddition, rb.velocity.y, 0);
  1582. }
  1583. if (weakTime <= 0)
  1584. {
  1585. ChangeState(CharacterState.Idle);
  1586. break;
  1587. }
  1588. break;
  1589. case CharacterState.PullRope:
  1590. break;
  1591. case CharacterState.Conduct:
  1592. if (CheckConduct())
  1593. {
  1594. ChangeState(CharacterState.Idle);
  1595. }
  1596. break;
  1597. default:
  1598. break;
  1599. }
  1600. if (!foot.TrigGround && !canFly)
  1601. {
  1602. if (rb.velocity.y > 0)
  1603. {
  1604. rb.velocity += Vector3.up * extraRiseGravity * Time.deltaTime;
  1605. }
  1606. else
  1607. {
  1608. rb.velocity += Vector3.up * extraFallGravity * Time.deltaTime;
  1609. }
  1610. }
  1611. isClickBtnRush = false;
  1612. isKeepBtnRush = false;
  1613. isClickBtnJump = false;
  1614. isClickBtnSouth = false;
  1615. isClickBtnEast = false;
  1616. isClickBtnNorth = false;
  1617. isClickBtnWest = false;
  1618. isBtnSouthUp = false;
  1619. isBtnEastUp = false;
  1620. isBtnNorthUp = false;
  1621. isBtnWestUp = false;
  1622. isSpiritSummon = false;
  1623. isSpiritSummon1 = false;
  1624. isSpiritSummon2 = false;
  1625. isSpiritSummon3 = false;
  1626. isClickBtnTransfigurate = false;
  1627. keyTransfigurateRelease = false;
  1628. if (foot.TrigGround)
  1629. {
  1630. canJumpTime = leaveGroundCanJumpTime;
  1631. }
  1632. SearchTarget();
  1633. attackTarget = targetCharacter;
  1634. if (isMpRepel && floatState == 0)
  1635. {
  1636. if (mp < totalMp)
  1637. {
  1638. if (!isRapedReply)
  1639. {
  1640. mp += mpReplySpeed * Time.deltaTime;
  1641. }
  1642. else
  1643. {
  1644. mp += rapidReplySpeed * Time.deltaTime;
  1645. }
  1646. }
  1647. }
  1648. if (floatState != 0)
  1649. {
  1650. if (mp > 0)
  1651. {
  1652. lostMp += mpReplySpeed * Time.deltaTime;
  1653. mp -= mpReplySpeed * Time.deltaTime;
  1654. }
  1655. if (lostMp >= addMp)
  1656. {
  1657. Instantiate(soul, transform.position, new Quaternion(0, 0, 0, 0), null);
  1658. lostMp = 0;
  1659. }
  1660. }
  1661. if (mp > totalMp)
  1662. {
  1663. mp = totalMp;
  1664. }
  1665. if (mp < 0)
  1666. {
  1667. mp = 0;
  1668. }
  1669. uiMp.Show(mp, totalMp);
  1670. }
  1671. public void PlayerDie()
  1672. {
  1673. switch (playerId)
  1674. {
  1675. case 0:
  1676. SpiritSystem.isP1In = true;
  1677. SpiritSystem.isP1Out = false;
  1678. break;
  1679. case 1:
  1680. SpiritSystem.isP2In = true;
  1681. SpiritSystem.isP2Out = false;
  1682. break;
  1683. default:
  1684. break;
  1685. }
  1686. foot.trigGroundList.Clear();
  1687. bodyTrans.gameObject.SetActive(false);
  1688. uiHp.transform.parent.gameObject.SetActive(false);
  1689. rb.constraints = RigidbodyConstraints.FreezeAll;
  1690. isRevive = true;
  1691. reviveTime = 0;
  1692. }
  1693. public void PlayerRevive()
  1694. {
  1695. isRevive = false;
  1696. isBaseBtnOut = false;
  1697. bodyTrans.gameObject.SetActive(true);
  1698. uiHp.transform.parent.gameObject.SetActive(true);
  1699. rb.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotation;
  1700. transform.position = new Vector3(142 + 4 * playerId, 0, 0);
  1701. switch (playerId)
  1702. {
  1703. case 0:
  1704. SpiritSystem.isP1In = false;
  1705. SpiritSystem.isP1Out = true;
  1706. SpiritSystem.player1 = gameObject;
  1707. SpiritSystem.p1Spirits = GetComponent<Spirits>();
  1708. break;
  1709. case 1:
  1710. SpiritSystem.isP2In = false;
  1711. SpiritSystem.isP2Out = true;
  1712. SpiritSystem.player2 = gameObject;
  1713. SpiritSystem.p2Spirits = GetComponent<Spirits>();
  1714. break;
  1715. default:
  1716. break;
  1717. }
  1718. Init();
  1719. }
  1720. public void RapidReplyMp()
  1721. {
  1722. isRapedReply = true;
  1723. rapidReplyEffect.SetActive(true);
  1724. }
  1725. public void NormalReplyMp()
  1726. {
  1727. isRapedReply = false;
  1728. rapidReplyEffect.SetActive(false);
  1729. }
  1730. public override void ChangeState(CharacterState newState)
  1731. {
  1732. if (state == newState)
  1733. {
  1734. return;
  1735. }
  1736. if (newState == CharacterState.Weak)
  1737. {
  1738. return;
  1739. }
  1740. Vector3 velocity = rb.velocity;
  1741. switch (state)
  1742. {
  1743. case CharacterState.Idle:
  1744. break;
  1745. case CharacterState.Run:
  1746. velocity.x = 0;
  1747. break;
  1748. case CharacterState.Rise:
  1749. bodyCollider.SetActive(true);
  1750. break;
  1751. case CharacterState.Fall:
  1752. break;
  1753. //case CharacterState.Hurt:
  1754. // break;
  1755. case CharacterState.Coma:
  1756. canMove = true;
  1757. break;
  1758. case CharacterState.Attack:
  1759. aniCollider.Play("NotAttack", 1, 0);
  1760. break;
  1761. case CharacterState.KeepAttack:
  1762. aniCollider.Play("NotAttack", 1, 0);
  1763. break;
  1764. case CharacterState.Summon:
  1765. rb.isKinematic = false;
  1766. if (cacheDir != 0)
  1767. {
  1768. if (cacheDir > 0.3f && bodyTrans.localScale.x > 0)
  1769. {
  1770. Turn();
  1771. }
  1772. else if (cacheDir < -0.3f && bodyTrans.localScale.x < 0)
  1773. {
  1774. Turn();
  1775. }
  1776. cacheDir = 0;
  1777. }
  1778. break;
  1779. case CharacterState.Transfiguration:
  1780. rb.isKinematic = false;
  1781. break;
  1782. case CharacterState.Rush:
  1783. velocity = Vector3.zero;
  1784. break;
  1785. case CharacterState.Sprint:
  1786. velocity = Vector3.zero;
  1787. break;
  1788. case CharacterState.Die:
  1789. if (isRevive)
  1790. {
  1791. return;
  1792. }
  1793. isDie = false;
  1794. break;
  1795. case CharacterState.Weak:
  1796. beRepelValue = totalBeRepelValue;
  1797. newTotalWeakTime = totalWeakTime;
  1798. break;
  1799. case CharacterState.Conduct:
  1800. rb.isKinematic = false;
  1801. Time.timeScale = 1;
  1802. conductReadyTip.activeFalse();
  1803. break;
  1804. default:
  1805. break;
  1806. }
  1807. CharacterState oldState = state;
  1808. state = newState;
  1809. switch (newState)
  1810. {
  1811. case CharacterState.Idle:
  1812. aniCollider.Play("Idle", 0, 0);
  1813. if (oldState == CharacterState.Fall)
  1814. {
  1815. ani.Play("fall_end", 0, 0);
  1816. }
  1817. else
  1818. {
  1819. ani.Play("idle", 0, 0);
  1820. }
  1821. velocity = Vector3.right * velocityAddition;
  1822. //animalAni.SetInteger("state", (int)PlayerState.Idle);
  1823. break;
  1824. case CharacterState.Run:
  1825. aniCollider.Play("Run", 0, 0);
  1826. ani.Play("run_start", 0, 0);
  1827. //animalAni.SetInteger("state", (int)PlayerState.Walk);
  1828. break;
  1829. case CharacterState.Rise:
  1830. aniCollider.Play("Rise", 0, 0);
  1831. canJumpTime = 0;
  1832. break;
  1833. case CharacterState.Fall:
  1834. aniCollider.Play("Fall", 0, 0);
  1835. ani.Play("fall", 0, 0);
  1836. //animalAni.SetInteger("state", (int)PlayerState.Fall);
  1837. break;
  1838. //case CharacterState.Hurt:
  1839. // aniCollider.Play("Hurt", 0, 0);
  1840. // ani.Play("hitted", 0, 0);
  1841. // invincibleTime = totalInvincibleTime;
  1842. // hurtKeepTime = minHurtKeepTime;
  1843. // //ani.Play("Invincible", 2, 0);
  1844. // break;
  1845. case CharacterState.Coma:
  1846. //ani.Play("Coma", 0, 0);
  1847. ani.Play("idle", 0, 0);
  1848. aniCollider.Play("Idle", 0, 0);
  1849. rb.velocity = Vector3.zero;
  1850. break;
  1851. case CharacterState.Attack:
  1852. attackTime = totalAttack_summonTime;
  1853. break;
  1854. case CharacterState.KeepAttack:
  1855. aniCollider.Play("Attack_summonKeep", 1, 0);
  1856. break;
  1857. case CharacterState.Summon:
  1858. aniCollider.Play("Summon", 0, 0);
  1859. ani.Play("summon", 0, 0);
  1860. velocity = Vector3.right * velocityAddition;
  1861. rb.isKinematic = true;
  1862. cacheDir = 0;
  1863. cacheRush = false;
  1864. break;
  1865. case CharacterState.Transfiguration:
  1866. aniCollider.Play("Transfiguration", 0, 0);
  1867. ani.Play("transfiguration", 0, 0);
  1868. velocity = Vector3.zero;
  1869. rb.isKinematic = true;
  1870. break;
  1871. case CharacterState.Rush:
  1872. aniCollider.Play("Rush", 0, 0);
  1873. ani.Play("rush_loop", 0, 0);
  1874. rushTime = totalRushTime;
  1875. invincibleTime = rushInvincibleTime;
  1876. //if (leftDir.magnitude < 0.3f)
  1877. //{
  1878. // if (bodyTrans.localScale.x > 0)
  1879. // {
  1880. // rushDir = Vector3.left;
  1881. // }
  1882. // else
  1883. // {
  1884. // rushDir = Vector3.right;
  1885. // }
  1886. //}
  1887. //else
  1888. //{
  1889. // rushDir = leftDir.normalized;
  1890. //}
  1891. if (bodyTrans.localScale.x > 0)
  1892. {
  1893. rushDir = Vector3.left;
  1894. }
  1895. else
  1896. {
  1897. rushDir = Vector3.right;
  1898. }
  1899. velocity = rushDir * rushSpeed;
  1900. mp -= rushCostMp;
  1901. uiMp.Show(mp, totalMp);
  1902. break;
  1903. case CharacterState.Sprint:
  1904. aniCollider.Play("Sprint", 0, 0);
  1905. ani.Play("rush_loop", 0, 0);
  1906. velocity = rushDir * rushSpeed;
  1907. break;
  1908. case CharacterState.Die:
  1909. aniCollider.Play("Die", 0, 0);
  1910. ani.Play("die", 0, 0);
  1911. isDie = true;
  1912. dieKeepTime = totalDieKeepTime;
  1913. break;
  1914. case CharacterState.Weak:
  1915. weakTime = newTotalWeakTime;
  1916. //hurtKeepTime = minHurtKeepTime;
  1917. break;
  1918. case CharacterState.Conduct:
  1919. rb.velocity = Vector3.zero;
  1920. rb.isKinematic = true;
  1921. aniCollider.Play("Summon", 0, 0);
  1922. ani.Play("summon", 0, 0);
  1923. break;
  1924. default:
  1925. break;
  1926. }
  1927. rb.velocity = velocity;
  1928. }
  1929. public void CheckTurn()
  1930. {
  1931. if (leftDir.x > 0.3f && bodyTrans.localScale.x > 0)
  1932. {
  1933. Turn();
  1934. }
  1935. else if (leftDir.x < -0.3f && bodyTrans.localScale.x < 0)
  1936. {
  1937. Turn();
  1938. }
  1939. }
  1940. public Vector3 AirMove(Vector3 velocity)
  1941. {
  1942. CheckTurn();
  1943. if (canFly)
  1944. {
  1945. velocity = leftDir.normalized * flySpeed;
  1946. if (transform.position.y > maxFlyHeight && velocity.y > 0)
  1947. {
  1948. velocity.y = 0;
  1949. }
  1950. }
  1951. else
  1952. {
  1953. if (leftDir.x > 0.3f)
  1954. {
  1955. velocity = new Vector3(moveSpeed, velocity.y, velocity.z);
  1956. }
  1957. else if (leftDir.x < -0.3f)
  1958. {
  1959. velocity = new Vector3(-moveSpeed, velocity.y, velocity.z);
  1960. }
  1961. else
  1962. {
  1963. velocity = new Vector3(0, velocity.y, velocity.z);
  1964. }
  1965. }
  1966. return velocity;
  1967. }
  1968. public void Transfiguration(int id) //变身
  1969. {
  1970. id = id - 3;
  1971. if (id >= changePrefabs.Count)
  1972. {
  1973. Debug.LogError("未配置" + id + "号变身");
  1974. return;
  1975. }
  1976. GameObject prefab = changePrefabs[id];
  1977. ChangeState(CharacterState.Transfiguration);
  1978. summonTime = prefab.GetComponent<Demonic>().totalSummonTime;
  1979. bodyTrans.gameObject.SetActive(false);
  1980. foot.trigGroundList.Clear();
  1981. spiritObj = PoolManager.Instantiate(prefab);
  1982. Demonic dem = spiritObj.GetComponent<Demonic>();
  1983. dem.id = id;
  1984. dem.playerID = playerId;
  1985. spiritObj.transform.parent = transform;
  1986. spiritObj.transform.localEulerAngles = Vector3.zero;
  1987. spiritObj.transform.localScale = new Vector3(1, 1, 1);
  1988. if (bodyTrans.localScale.x > 0)
  1989. {
  1990. spiritObj.transform.position = transform.position;
  1991. if (dem.bodyTrans.localScale.x < 0)
  1992. {
  1993. dem.Turn();
  1994. }
  1995. }
  1996. else
  1997. {
  1998. spiritObj.transform.position = transform.position;
  1999. if (dem.bodyTrans.localScale.x > 0)
  2000. {
  2001. dem.Turn();
  2002. }
  2003. }
  2004. mecanim = dem.mecanim;
  2005. ani = dem.ani;
  2006. aniCollider = dem.aniCollider;
  2007. bodyTrans = dem.bodyTrans;
  2008. beSearchTrigger = dem.beSearchTrigger;
  2009. bulletPrefab = dem.bulletPrefab;
  2010. searchTrigger = dem.searchTrigger;
  2011. foot = dem.foot;
  2012. spinee = dem.spinee;
  2013. mesh = dem.mesh;
  2014. mats = dem.mats;
  2015. soulCollector = dem.soulCollector;
  2016. outlineMats = dem.outlineMats;
  2017. if (dem.canFly)
  2018. {
  2019. canFly = true;
  2020. canJump = false;
  2021. rb.useGravity = false;
  2022. }
  2023. /* 法师出场释放浮空场
  2024. if (id == 3)
  2025. {
  2026. if ((int)spirits.currentSpirit == 0)
  2027. {
  2028. if (!spiritObj.GetComponent<Demonic>().hasEffect)
  2029. {
  2030. spiritObj.GetComponent<Demonic>().hasEffect = true;
  2031. Instantiate(spirits.floatEffect, spiritObj.transform.position, new Quaternion(0, 0, 0, 0), spiritObj.transform);
  2032. }
  2033. }
  2034. }
  2035. */
  2036. endChange = id + 3;
  2037. curHp = hp;
  2038. curTotalHp = totalHp;
  2039. uiHp.Show(hp, totalHp);
  2040. ChangeState(CharacterState.Idle);
  2041. }
  2042. public void Summon(int id)
  2043. {
  2044. if (id >= demonicPrefabs.Count)
  2045. {
  2046. Debug.LogError("未配置" + id + "号使魔");
  2047. return;
  2048. }
  2049. if (id >= demonicSummonPos.Count)
  2050. {
  2051. Debug.LogError("未配置" + id + "号使魔召唤位置");
  2052. return;
  2053. }
  2054. GameObject prefab;
  2055. if (id == 1)
  2056. {
  2057. prefab = chooseYinYang.SelectPrefab(playerId);
  2058. }
  2059. else
  2060. {
  2061. prefab = demonicPrefabs[id];
  2062. }
  2063. if (!CheckCanSummon(id))
  2064. {
  2065. return;
  2066. }
  2067. ChangeState(CharacterState.Summon);
  2068. summonTime = prefab.GetComponent<Demonic>().totalSummonTime;
  2069. float costMp = prefab.GetComponent<Demonic>().costMp;
  2070. mp -= costMp;
  2071. uiMp.Show(mp, totalMp);
  2072. GameObject demonicObj = PoolManager.Instantiate(prefab);
  2073. Demonic demonic = demonicObj.GetComponent<Demonic>();
  2074. demonic.id = id;
  2075. demonic.playerID = playerId;
  2076. if (!demonicDic.ContainsKey(id))
  2077. {
  2078. demonicDic.Add(id, new List<Demonic>());
  2079. }
  2080. demonicDic[id].Add(demonic);
  2081. if (id <= 2)
  2082. {
  2083. demonicNums[id].text = demonicDic[id].Count.ToString();
  2084. }
  2085. demonicObj.transform.parent = null;
  2086. demonicObj.transform.localEulerAngles = Vector3.zero;
  2087. demonicObj.transform.localScale = new Vector3(1, 1, 1);
  2088. Vector3 offset = demonicSummonPos[id];
  2089. if (bodyTrans.localScale.x > 0)
  2090. {
  2091. demonicObj.transform.position = transform.position + offset;
  2092. if (demonic.bodyTrans.localScale.x < 0)
  2093. {
  2094. demonic.Turn();
  2095. }
  2096. }
  2097. else
  2098. {
  2099. demonicObj.transform.position = transform.position + new Vector3(-offset.x, offset.y, offset.z);
  2100. if (demonic.bodyTrans.localScale.x > 0)
  2101. {
  2102. demonic.Turn();
  2103. }
  2104. }
  2105. if (demonic.canFly)
  2106. {
  2107. demonic.flyHeight = demonic.transform.position.y;
  2108. }
  2109. demonic.player = this;
  2110. demonic.Init();
  2111. int order = prefab.GetComponent<Demonic>().baseSortingOrder + demonicDic[demonic.id].Count;
  2112. demonic.SetSortingOrder(order);
  2113. if (id != 4)
  2114. {
  2115. demonic.Attack_summon();
  2116. }
  2117. //id 3~6 为四个英灵
  2118. if (id >= 3 && id <= 6)
  2119. {
  2120. spirits.ultimateTimes[spirits.nowSpirit] -= 1;
  2121. }
  2122. spiritSystem.RefreshPlayerUI();
  2123. if (isInSoulTower)
  2124. {
  2125. ls.AddDenomic(demonic);
  2126. }
  2127. }
  2128. public void OnDemonicRecycle(Demonic demonic)
  2129. {
  2130. if (!demonicDic.ContainsKey(demonic.id))
  2131. {
  2132. return;
  2133. }
  2134. demonicDic[demonic.id].Remove(demonic);
  2135. if (demonic.id <= 2)
  2136. {
  2137. demonicNums[demonic.id].text = demonicDic[demonic.id].Count.ToString();
  2138. }
  2139. for (int i = 0; i < demonicDic[demonic.id].Count; i++)
  2140. {
  2141. int order = demonicDic[demonic.id][i].baseSortingOrder + i;
  2142. demonicDic[demonic.id][i].SetSortingOrder(order);
  2143. }
  2144. }
  2145. public bool CheckCanSummon(int id)
  2146. {
  2147. GameObject prefab;
  2148. if (id == 1)
  2149. {
  2150. prefab = chooseYinYang.SelectPrefab(playerId);
  2151. }
  2152. else
  2153. {
  2154. prefab = demonicPrefabs[id];
  2155. }
  2156. float costMp = prefab.GetComponent<Demonic>().costMp;
  2157. if (id < 3)
  2158. {
  2159. costMp += addCostMp[id] * demonicDic[id].Count;
  2160. }
  2161. if (mp < costMp)
  2162. {
  2163. Debug.Log("mp不足召唤失败, 还得加个动画或者音效啥的");
  2164. return false;
  2165. }
  2166. return true;
  2167. }
  2168. public override void Attack_summon()
  2169. {
  2170. base.Attack_summon();
  2171. if (leftDir.x > 0.3f)
  2172. {
  2173. if (bodyTrans.localScale.x > 0)
  2174. {
  2175. Turn();
  2176. }
  2177. SetAttackState(PlayerAttackState.WalkForward);
  2178. }
  2179. else if (leftDir.x < -0.3f)
  2180. {
  2181. if (bodyTrans.localScale.x < 0)
  2182. {
  2183. Turn();
  2184. }
  2185. SetAttackState(PlayerAttackState.WalkForward);
  2186. }
  2187. else
  2188. {
  2189. SetAttackState(PlayerAttackState.Idle);
  2190. }
  2191. }
  2192. public void SetAttackState(PlayerAttackState value)
  2193. {
  2194. attackState = value;
  2195. ani.SetInteger("attackState", (int)value);
  2196. aniCollider.Play("Attack_summonKeep", 1, 0);
  2197. }
  2198. public void SearchTarget()
  2199. {
  2200. targetCharacter = searchTrigger.GetMinDisTarget(targetTypes, canHitFly);
  2201. }
  2202. public void ChangeSpirit()
  2203. {
  2204. if ((playerId == 0 && SpiritSystem.canP1CardChange) || (playerId == 1 && SpiritSystem.canP2CardChange))
  2205. {
  2206. if (rightDir.x >= 0.5)
  2207. {
  2208. switch (playerId)
  2209. {
  2210. case 0:
  2211. SpiritSystem.P1CardChangeTime = 0;
  2212. SpiritSystem.canP1CardChange = false;
  2213. SpiritSystem.isP1CardChangeR = true;
  2214. break;
  2215. case 1:
  2216. SpiritSystem.P2CardChangeTime = 0;
  2217. SpiritSystem.canP2CardChange = false;
  2218. SpiritSystem.isP2CardChangeR = true;
  2219. break;
  2220. default:
  2221. break;
  2222. }
  2223. }
  2224. else if (rightDir.x <= -0.5)
  2225. {
  2226. switch (playerId)
  2227. {
  2228. case 0:
  2229. SpiritSystem.P1CardChangeTime = 0;
  2230. SpiritSystem.canP1CardChange = false;
  2231. SpiritSystem.isP1CardChangeL = true;
  2232. break;
  2233. case 1:
  2234. SpiritSystem.P2CardChangeTime = 0;
  2235. SpiritSystem.canP2CardChange = false;
  2236. SpiritSystem.isP2CardChangeL = true;
  2237. break;
  2238. default:
  2239. break;
  2240. }
  2241. }
  2242. }
  2243. }
  2244. }