PlayerController.cs 73 KB

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