| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866 |
- using System.Collections.Generic;
- using UnityEngine;
- using Spine.Unity;
- using Sirenix.OdinInspector;
- using UnityEngine.InputSystem;
- using TMPro;
- public enum PlayerAttackState
- {
- Idle = 0,
- WalkForward = 1,
- WalkBack = 2,
- }
- public class PlayerController : MoveCharacter
- {
- [Header("玩家属性")]
- public int playerId;
- public Vector2 pos;
- public bool canJump;
- public Animator aniCollider;
- [Header("玩家组件")]
- public UIHP uiMp;
- private Spirits spirits;
- public Collider soulCollector;
- public SkeletonMecanim skeletonMecanim;
- private SpiritSystem spiritSystem;
- private ScreenShake ss;
- private ConductController conductController;
- [Header("蓝耗")]
- public float mp;
- public float totalMp;
- public float totalMp_2Players; //双人模式下总蓝量
- public bool isMpRepel = true;
- public bool isRapedReply;
- public float mpReplySpeed;
- public float mpReplySpeed_2Players; //双人模式下蓝量回复速度
- public float rapidReplySpeed;
- public float lostMp;
- public float addMp = 10;
- public GameObject soul;
- public GameObject rapidReplyEffect;
- [Tooltip("场上每多一个同种类兵种,召唤兵种蓝耗+x")] public float[] addCostMp;
- [Header("移动属性")]
- public Vector2 moveVec; //玩家不动时移动数据
- [HideInInspector]
- public Vector2 leftDir;
- [Header("冲刺属性")]
- public float rushSpeed = 100;
- public float rushCostMp = 5;
- public Vector3 rushDir;
- public float rushInvincibleTime = 0.2f;
- [HideInInspector]
- public float rushTime;
- public float totalRushTime = 0.5f;
- [HideInInspector]
- public float cacheRushTime; //无法Rush时按下Rush键不会Rush,手感不好,缓存几帧,在这几帧内落地会立即Rush;
- public float totalCacheRushTime = 0.1f;
- public float sprintCostMp = 5;
- [Header("跳跃属性")]
- public float jumpSpeed = 10;
- public float airJumpSpeed = 10;
- public int airJumped;
- public int airJumpNumber = 1; //最大跳跃次数
- public float canAirJumpSpeed = 5;//y轴速度大于这个值时不能进行空中跳跃
- [HideInInspector]
- public float canJumpTime; //离开平台后仍然可以跳跃的时间,用于提升手感
- public float leaveGroundCanJumpTime = 0.1f;
- [HideInInspector]
- public float cacheJumpTime; //即将落地时按下跳跃键不会跳跃,手感不好,缓存几帧,在这几帧内落地会立即跳跃;
- public float totalCacheJumpTime = 0.1f;
- [Header("飞行属性")]
- public float flySpeed = 5;
- public float playerMaxFlyHeight;
- [Header("召唤属性")]
- public float totalSummonTime;
- [HideInInspector]
- public float summonTime;
- public float onlySummonTime;
- [HideInInspector]
- public float restSummonTime;
- private SoldierLevelRecord slr;
-
- [HideInInspector]
- public float cacheDir; //召唤的时候按左右召唤结束不会响应手感不好,缓存一下,召唤后摇期间有左右响应的话会转向
- [HideInInspector]
- public bool cacheRush; //召唤的时候按冲刺结束不会响应手感不好,缓存一下,召唤后摇期间按下冲刺的话会冲刺
- [HideInInspector]
- public float cacheSummonTime; //无法召唤时按下召唤键不会召唤,手感不好,缓存几帧,在这几帧内落地会立即召唤;
- [HideInInspector]
- public int cacheSummonId;
- [Header("召唤使魔")]
- public TextMeshProUGUI[] demonicNums;
- public GameObject[] cannotConductFXs;
- public List<GameObject> demonicPrefabs;
- public List<Vector3> demonicSummonPos;
- public Dictionary<int, List<Demonic>> demonicDic; //0:弓兵,1:胖子,2:棒子,3:融合后的弓兵,4:融合后的胖子,5:融合后的棒子
- [LabelText("动作结束后无敌帧时间")] public float addSummonInvincibleTime = 0.1f;
- [Header("攻击")]
- public PlayerAttackState attackState;
- public float attackMoveSpeed = 5f;
- [HideInInspector]
- public float cacheAttackTime; //无法攻击时按下攻击键不会攻击,手感不好,缓存几帧,在这几帧内落地会立即攻击;
- public float totalCacheAttackTime = 0.1f;
- [Header("复活")]
- public float reviveTime; //复活时间
- public float totalReviveTime;
- [Header("锁魂塔")]
- public GameObject curSoulTower;
- //指挥功能
- private float conductTime; //指挥按键长按时间
- private int nowConductButton = -1; //现在按下的指挥键(0.J/1.K/2.L/-1.无)
- private int cacheConductId;
- [Header("召唤相应时间")] [Tooltip("在此时间内松手为召唤")] public float totalCacheSummonTime;
- [Header("融魂相应时间")] [Tooltip("在此时间以外松手为融魂")] public float[] canConductTime;
- public bool[] conductCanRelease; //能否进入指挥技蓄力状态
- public ConductReadyTip conductReadyTip; //指挥技就绪
- private bool isReadyConduct;
- [Header("时间倍率")] [Tooltip("时间速度放慢到正常的几倍")] public float timeSlowingMultiplier;
- [DisplayOnly]public float fixedDeltaTime;
- public float readyTipFxTime;
- //攻击力
- [Header("增加攻击力特效")]
- public GameObject attackEffect;
- [Header("攻击力献祭比例")]
- public float addRate;
- //泰山压顶
- [Header("泰山压顶")]
- public GameObject mountain;
- public Vector3 mountainOffset;
- public float largeX;
- //气功波
- public GameObject wavePowerObj;
- [Header("气功波伤害基数")] public int wavePowerDamage;
- //御剑术
- public GameObject flyingSwordsObj;
- //怨气弹
- public GameObject angryBulletObj;
- [Header("怨气弹数量基数")] public int angryBulletNum;
- public bool btnJumpPress
- {
- get
- {
- //return Input.GetKeyDown(KeyCode.Space) || isClickBtnJump;
- return isClickBtnJump;
- }
- }
- [HideInInspector]
- public bool isClickBtnJump;
- public bool btnRushPress
- {
- get
- {
- //return Input.GetKeyDown(KeyCode.LeftShift) || isClickBtnRush;
- return isClickBtnRush;
- }
- }
- [HideInInspector]
- public bool isClickBtnRush;
- public bool btnRushKeep
- {
- get
- {
- //return Input.GetKey(KeyCode.LeftShift) || isKeepBtnRush;
- return LBisHold || isKeepBtnRush;
- }
- }
- [HideInInspector]
- public bool isKeepBtnRush;
- public bool btnEastPress
- {
- get
- {
- return isClickBtnEast;
- }
- }
- [HideInInspector]
- public bool isClickBtnEast;
- public bool btnEastUp
- {
- get
- {
- return isBtnEastUp;
- }
- }
- [HideInInspector]
- public bool isBtnEastUp;
- public bool btnSouthPress
- {
- get
- {
- //return Input.GetKeyDown(KeyCode.K) || isClickBtnSouth;
- return isClickBtnSouth;
- }
- }
- [HideInInspector]
- public bool isClickBtnSouth;
- public bool btnSouthUp
- {
- get
- {
- //return Input.GetKeyDown(KeyCode.K) || isClickBtnSouth;
- return isBtnSouthUp;
- }
- }
- [HideInInspector]
- public bool isBtnSouthUp;
- public bool btnWestPress
- {
- get
- {
- return isClickBtnWest;
- }
- }
- [HideInInspector]
- public bool isClickBtnWest;
- public bool btnWestUp
- {
- get
- {
- return isBtnWestUp;
- }
- }
- [HideInInspector]
- public bool isBtnWestUp;
- public bool btnNorthPress
- {
- get
- {
- return isClickBtnNorth;
- }
- }
- [HideInInspector]
- public bool isClickBtnNorth;
- public bool btnNorthUp
- {
- get
- {
- return isBtnNorthUp;
- }
- }
- [HideInInspector]
- public bool isBtnNorthUp;
- public bool btnSpiritSummon
- {
- get
- {
- //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
- return isSpiritSummon;
- }
- }
- [HideInInspector]
- public bool isSpiritSummon;
- public bool btnSpiritSummon1
- {
- get
- {
- //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
- return isSpiritSummon1;
- }
- }
- [HideInInspector]
- public bool isSpiritSummon1;
- public bool btnSpiritSummon2
- {
- get
- {
- //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
- return isSpiritSummon2;
- }
- }
- [HideInInspector]
- public bool isSpiritSummon2;
- public bool btnSpiritSummon3
- {
- get
- {
- //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
- return isSpiritSummon3;
- }
- }
- [HideInInspector]
- public bool isSpiritSummon3;
- public bool btnNorthKeep
- {
- get
- {
- //return Input.GetKey(KeyCode.I) || isKeepBtnNorth;
- return isKeepBtnNorth;
- }
- }
- [HideInInspector]
- public bool isKeepBtnNorth;
- public override void Init()
- {
- base.Init();
- uiHp = GameManager.instance.p1uiHP;
- uiMp = GameManager.instance.p1uiMP;
- uiMp.pc = this;
- mp = totalMp;
- uiMp.Show(mp, totalMp);
- demonicNums = new TextMeshProUGUI[3];
- for (int i = 0; i < 3; i++)
- {
- demonicNums[i] = GameManager.instance.demonicNum[i].GetComponentInChildren<TextMeshProUGUI>();
- }
- cannotConductFXs = new GameObject[3];
- for (int i = 0; i < 3; i++)
- {
- cannotConductFXs[i] = GameManager.instance.demonicNum[i].transform.GetChild(3).gameObject;
- }
- }
- public override void Awake()
- {
- base.Awake();
- PlayerInput playerInput = transform.GetComponent<PlayerInput>();
- ss = Camera.main.GetComponentInParent<ScreenShake>();
- spirits = GetComponent<Spirits>();
- conductController = GetComponent<ConductController>();
- playerId = playerInput.playerIndex;
- transform.position = new Vector3(pos.x, pos.y, 0);
- switch (playerId)
- {
- case 0:
- PlayersInput.instance[0] = this;
- PlayersInput.instance[1] = this;
- SpiritSystem.isP1Out = true;
- SpiritSystem.isP1In = false;
- SpiritSystem.player1 = gameObject;
- SpiritSystem.p1Spirits = GetComponent<Spirits>();
- break;
- case 1:
- PlayersInput.instance[1] = this;
- SpiritSystem.isP2Out = true;
- SpiritSystem.isP2In = false;
- SpiritSystem.player2 = gameObject;
- SpiritSystem.p2Spirits = GetComponent<Spirits>();
- //切换为双人计算蓝量方式
- PlayerController p1 = PlayersInput.instance[0];
- mpReplySpeed = mpReplySpeed_2Players;
- p1.mpReplySpeed = mpReplySpeed_2Players;
- totalMp = totalMp_2Players;
- p1.totalMp = totalMp_2Players;
- if (mp > totalMp)
- {
- mp = totalMp;
- }
- if (p1.mp > totalMp)
- {
- p1.mp = totalMp;
- }
- uiMp.Show(mp, totalMp);
- p1.uiMp.Show(p1.mp, totalMp);
- break;
- default:
- break;
- }
- demonicDic = new Dictionary<int, List<Demonic>>();
- for (int i = 0; i < 5; i++)
- {
- demonicDic.Add(i, new List<Demonic>());
- }
- Init();
- spiritSystem = GameObject.Find("SpiritSystem").GetComponent<SpiritSystem>();
- fixedDeltaTime = Time.fixedDeltaTime;
- }
- private void Start()
- {
- slr = GameManager.instance.GetComponent<SoldierLevelRecord>();
- }
- override public void Update()
- {
- if (LBisHold)
- {
- isKeepBtnRush = true;
- }
- }
- void OnSprintingPress()
- {
- LBisHold = true;
- isClickBtnRush = true;
- isKeepBtnRush = true;
- }
- void OnSprintingRelease()
- {
- LBisHold = false;
- }
- //手柄按下LB
- [HideInInspector]
- public bool LBisHold;
- //读取手柄参数
- private void OnMove(InputValue value)
- {
- leftDir = value.Get<Vector2>();
- moveVec = value.Get<Vector2>();
- }
- void OnJump()
- {
- if (canJump)
- {
- isClickBtnJump = true;
- }
- }
- void OnSummon0()
- {
- if (nowConductButton == -1)
- {
- isClickBtnWest = true;
- nowConductButton = 0;
- conductTime = 0;
- }
- }
- void OnSummon0Up()
- {
- if (nowConductButton == 0)
- {
- isBtnWestUp = true;
- cacheConductId = nowConductButton;
- nowConductButton = -1;
- }
- }
- void OnSummon1()
- {
- if (nowConductButton == -1)
- {
- isClickBtnSouth = true;
- nowConductButton = 1;
- conductTime = 0;
- }
- }
- void OnSummon1Up()
- {
- if (nowConductButton == 1)
- {
- isBtnSouthUp = true;
- cacheConductId = nowConductButton;
- nowConductButton = -1;
- }
- }
- void OnSummon2()
- {
- if (nowConductButton == -1)
- {
- isClickBtnEast = true;
- nowConductButton = 2;
- conductTime = 0;
- }
- }
- void OnSummon2Up()
- {
- if (nowConductButton == 2)
- {
- isBtnEastUp = true;
- cacheConductId = nowConductButton;
- nowConductButton = -1;
- }
- }
- //选英灵 (手柄右扳机,键盘TAB)
- void OnChooseSpirit()
- {
- switch (playerId)
- {
- case 0:
- SpiritSystem.isP1CardChangeR = true;
- break;
- case 1:
- SpiritSystem.isP2CardChangeR = true;
- break;
- default:
- break;
- }
- }
- public void Jump()
- {
- SetUpSpeed(jumpSpeed);
- ani.Play("jump", 0, 0);
- }
- public void AirJump()
- {
- ChangeState(CharacterState.Rise);
- SetUpSpeed(airJumpSpeed);
- ani.Play("jump_air", 0, 0);
- }
- public void SetUpSpeed(float speed)
- {
- ChangeState(CharacterState.Rise);
- Vector3 velocity = rb.velocity;
- CheckTurn();
- velocity.y = speed;
- rb.velocity = velocity;
- //animalAni.SetInteger("state", (int)PlayerState.Rise);
- }
- public bool CheckSummon()
- {
- if (restSummonTime > 0)
- {
- return false;
- }
- if (state != CharacterState.Conduct && nowConductButton != -1 && conductTime > totalCacheSummonTime)
- {
- CheckTurn();
- if (conductCanRelease[nowConductButton])
- {
- ChangeState(CharacterState.Conduct);
- return true;
- }
- return false;
- }
- if (isBtnEastUp || isBtnWestUp || isBtnSouthUp)
- {
- if (cacheSummonTime >= 0 && conductTime <= totalCacheSummonTime)
- {
- CheckTurn();
- if (!CheckCanSummon(cacheSummonId))
- {
- return false;
- }
- Summon(cacheSummonId);
- return true;
- }
- }
- return false;
- }
- public bool CheckConduct()
- {
- if (isBtnEastUp || isBtnWestUp || isBtnSouthUp)
- {
- if (isReadyConduct)
- {
- conductController.Conduct(cacheConductId);
- }
- isReadyConduct = false;
- return true;
- }
- if (!isReadyConduct && nowConductButton != -1)
- {
- if (conductTime >= canConductTime[nowConductButton] * timeSlowingMultiplier)
- {
- isReadyConduct = true;
- if (!conductReadyTip.isShowing1 && !conductReadyTip.isShowingNoDemonic)
- {
- int boostNum = demonicDic[nowConductButton].Count;
- int dienum = (int)(boostNum * conductController.conversionRate[nowConductButton] + 0.5f);
- if (boostNum == 1)
- {
- dienum = 1;
- }
- if (dienum > 0)
- {
- conductReadyTip.Show(1);
- }
- else
- {
- conductReadyTip.Show(3, nowConductButton);
- }
- }
- }
- else if (conductTime >= (canConductTime[nowConductButton] - readyTipFxTime) * timeSlowingMultiplier)
- {
- if (!conductReadyTip.isShowing0 && !conductReadyTip.isShowingNoDemonic)
- {
- int boostNum = demonicDic[nowConductButton].Count;
- int dienum = (int)(boostNum * conductController.conversionRate[nowConductButton] + 0.5f);
- if (boostNum == 1)
- {
- dienum = 1;
- }
- if (dienum > 0)
- {
- conductReadyTip.Show(0);
- }
- else
- {
- conductReadyTip.Show(2, nowConductButton);
- }
- }
- }
- else
- {
- if (Time.timeScale == 1)
- {
- Time.timeScale = timeSlowingMultiplier;
- Time.fixedDeltaTime = fixedDeltaTime * Time.timeScale;
- int boostNum = demonicDic[nowConductButton].Count;
- int dienum = (int)(boostNum * conductController.conversionRate[nowConductButton] + 0.5f);
- if (boostNum == 1)
- {
- dienum = 1;
- }
- if (dienum == 0)
- {
- conductReadyTip.Show(2, nowConductButton);
- CannotConductFX(nowConductButton);
- }
- }
- conductReadyTip.Init();
- }
- }
- return false;
- }
- public void Conduct()
- {
- //switch (conductSkills[cacheConductId])
- //{
- // //巨人
- // case ConductSkills.AddAttack:
- // List<Demonic> newGiants = new List<Demonic>();
- // foreach (Demonic d in demonicDic[cacheConductId])
- // {
- // if (!d.isDie)
- // {
- // newGiants.Add(d);
- // if (d.attackController.addAttackEffect == null)
- // {
- // d.attackController.addAttackEffect = Instantiate(attackEffect, d.bodyTrans.position, new Quaternion(0, 0, 0, 0), d.bodyTrans);
- // }
- // d.attackController.addAttackEffect.transform.GetChild(0).gameObject.SetActive(true);
- // }
- // }
- // foreach (Demonic d in newGiants)
- // {
- // int damage = d.attackController.curDamage;
- // d.attackController.curDamage += (int)(addRate * boostNum * damage);
- // }
- // break;
- // //气功师
- // case ConductSkills.Mountain:
- // conductCanRelease[cacheConductId] = false;
- // GameObject curMountain = Instantiate(mountain, null);
- // Vector3 moffset = mountainOffset;
- // Vector3 sc = curMountain.transform.localScale;
- // sc.x = largeX * dienum;
- // curMountain.transform.localScale = sc;
- // if (bodyTrans.localScale.x < 0)
- // {
- // moffset.x = mountainOffset.x + sc.x / 2;
- // }
- // else
- // {
- // moffset.x = -mountainOffset.x - sc.x / 2;
- // }
- // Mountain MT = curMountain.GetComponent<Mountain>();
- // curMountain.transform.position = transform.position + moffset;
- // MT.pc = this;
- // MT.id = cacheConductId;
- // MT.demonicNum = boostNum;
- // break;
- // case ConductSkills.WavePower:
- // rb.constraints = RigidbodyConstraints.FreezeAll;
- // rb.useGravity = false;
- // conductCanRelease[cacheConductId] = false;
- // obj = Instantiate(wavePowerObj, transform);
- // obj.transform.position = transform.position + Vector3.up;
- // WavePowerSkill wps = obj.GetComponent<WavePowerSkill>();
- // wps.continueTime = wps.singleTime * dienum;
- // wps.longFX = (int)bodyTrans.localScale.x;
- // wps.damage = wavePowerDamage * boostNum;
- // wps.cacheID = cacheConductId;
- // wps.pc = this;
- // break;
- // case ConductSkills.SwordsControl:
- // conductCanRelease[cacheConductId] = false;
- // obj = Instantiate(flyingSwordsObj, transform);
- // obj.transform.position = transform.position + Vector3.up;
- // SwordsControl swordsControl = obj.GetComponentInChildren<SwordsControl>();
- // swordsControl.owner = this;
- // swordsControl.conductId = cacheConductId;
- // swordsControl.boostNum = boostNum;
- // break;
- // //弓箭手
- // case ConductSkills.AngryBullet:
- // conductCanRelease[cacheConductId] = false;
- // obj = Instantiate(angryBulletObj);
- // AngryBulletControl angryBulletControl = obj.GetComponent<AngryBulletControl>();
- // angryBulletControl.playerController = this;
- // angryBulletControl.cacheConductId = cacheConductId;
- // angryBulletControl.maxNum = boostNum * angryBulletNum;
- // break;
- // case ConductSkills.FlyingSwords:
- // obj = Instantiate(fanFlyingSwords);
- // FanFlyingSwords FFS = obj.GetComponent<FanFlyingSwords>();
- // FFS.owner = this;
- // FFS.angleRange = flyingSwordsAngleRange;
- // FFS.arrivalAngle = flyintSwordsArrivalAngle;
- // FFS.swordsNum = boostNum * flyingSwordsNum;
- // FFS.Biu();
- // break;
- //}
- }
- private int cannotConductfx;
- private void CannotConductFX(int id)
- {
- cannotConductfx = id;
- cannotConductFXs[id].SetActive(true);
- Invoke("CannotConductFXFade", 0.2f);
- }
- private void CannotConductFXFade()
- {
- cannotConductFXs[cannotConductfx].SetActive(false);
- }
- //角色处于可自由活动状态时的通用切换状态逻辑,如Idle、Run状态,以及别的状态结束时准备回到Idle状态前
- public bool CheckPlayerChangeState(CharacterState excludeState = CharacterState.None)
- {
- if (!foot.TrigGround)
- {
- if (excludeState != CharacterState.Summon)
- {
- if (CheckSummon())
- {
- return true;
- }
- }
- if ((btnRushPress || cacheRushTime > 0 || cacheRush) && mp >= rushCostMp)
- {
- if (excludeState != CharacterState.Rush)
- {
- restSummonTime = 0;
- summonTime = 0;
- cacheRush = false;
- ChangeState(CharacterState.Rush);
- return true;
- }
- }
- if (rb.velocity.y > 0)
- {
- if (excludeState != CharacterState.Rise && restSummonTime <= 0)
- {
- summonTime = 0;
- ChangeState(CharacterState.Rise);
- return true;
- }
- }
- else
- {
- if (excludeState != CharacterState.Fall && restSummonTime <= 0)
- {
- summonTime = 0;
- ChangeState(CharacterState.Fall);
- return true;
- }
- }
- }
- else
- {
- airJumped = 0;
- if (CheckSummon())
- {
- if (excludeState == CharacterState.Summon)
- {
- if (foot.TrigGround)
- {
- ani.Play("summon", 0, 0);
- }
- else
- {
- ani.Play("summon_air", 0, 0);
- }
- }
- return true;
- }
- if ((btnRushPress || cacheRushTime > 0 || cacheRush) && mp >= rushCostMp)
- {
- if (excludeState != CharacterState.Rush)
- {
- restSummonTime = 0;
- summonTime = 0;
- cacheRush = false;
- ChangeState(CharacterState.Rush);
- return true;
- }
- }
- if (btnJumpPress || cacheJumpTime > 0)
- {
- if (excludeState != CharacterState.Rise && restSummonTime <= 0)
- {
- summonTime = 0;
- Jump();
- ChangeState(CharacterState.Rise);
- return true;
- }
- }
- if (leftDir.y < -0.5)
- {
- Platform platform = foot.trigGroundList[0].GetComponent<Platform>();
- if (platform != null && platform.canDown)
- {
- foot.trigGroundList.Remove(platform.gameObject);
- }
- }
- if (canFly)
- {
- if (leftDir.x > 0.3f || leftDir.x < -0.3f || leftDir.y > 0.3f || leftDir.y < -0.3f)
- {
- if (excludeState != CharacterState.Run && restSummonTime <= 0)
- {
- summonTime = 0;
- ChangeState(CharacterState.Run);
- return true;
- }
- }
- else
- {
- if (excludeState != CharacterState.Idle && summonTime <= 0)
- {
- ChangeState(CharacterState.Idle);
- return true;
- }
- }
- }
- else
- {
- if (leftDir.x > 0.3f || leftDir.x < -0.3f)
- {
- if (excludeState != CharacterState.Run && restSummonTime <= 0)
- {
- summonTime = 0;
- ChangeState(CharacterState.Run);
- return true;
- }
- }
- else
- {
- if (excludeState != CharacterState.Idle && summonTime <= 0)
- {
- ChangeState(CharacterState.Idle);
- return true;
- }
- }
- }
- }
- return false;
- }
- public override Vector3 GetMoveDir()
- {
- return leftDir;
- }
- public void CachedPlayerInput()
- {
- if (btnRushPress)
- {
- cacheRushTime = totalCacheRushTime;
- }
- if (btnJumpPress)
- {
- cacheJumpTime = totalCacheJumpTime;
- }
- if (btnNorthPress)
- {
- cacheAttackTime = totalCacheAttackTime;
- }
- if (btnWestPress)
- {
- cacheSummonTime = totalCacheSummonTime;
- cacheSummonId = 0;
- }
- if (btnSouthPress)
- {
- cacheSummonTime = totalCacheSummonTime;
- cacheSummonId = 1;
- }
- if (btnEastPress)
- {
- cacheSummonTime = totalCacheSummonTime;
- cacheSummonId = 2;
- }
- //if (btnSpiritSummon)
- //{
- // cacheSummonTime = totalCacheSummonTime;
- // cacheSummonId = 3;
- //}
- //if (btnSpiritSummon1)
- //{
- // cacheSummonTime = totalCacheSummonTime;
- // cacheSummonId = 4;
- //}
- //if (btnSpiritSummon2)
- //{
- // cacheSummonTime = totalCacheSummonTime;
- // cacheSummonId = 5;
- //}
- //if (btnSpiritSummon3)
- //{
- // cacheSummonTime = totalCacheSummonTime;
- // cacheSummonId = 6;
- //}
- }
- public override void OnState()
- {
- base.OnState();
- if(state == CharacterState.None)
- {
- return;
- }
- cacheJumpTime -= Time.deltaTime;
- cacheSummonTime -= Time.deltaTime;
- canJumpTime -= Time.deltaTime;
- invincibleTime -= Time.deltaTime;
- summonTime -= Time.deltaTime;
- restSummonTime -= Time.deltaTime;
- rushTime -= Time.deltaTime;
- cacheRushTime -= Time.deltaTime;
- dieKeepTime -= Time.deltaTime;
- if (nowConductButton != -1)
- {
- conductTime += Time.deltaTime;
- }
- CachedPlayerInput();
- Vector3 velocity = rb.velocity;
- switch (state)
- {
- case CharacterState.Idle:
- if (CheckPlayerChangeState(CharacterState.Idle))
- {
- break;
- }
- rb.velocity = Vector3.right * velocityAddition;
- break;
- case CharacterState.Run:
- if (CheckPlayerChangeState(CharacterState.Run))
- {
- break;
- }
- CheckTurn();
- if (canFly)
- {
- rb.velocity = leftDir.normalized * moveSpeed;
- }
- else
- {
- if (leftDir.x > 0.3f)
- {
- rb.velocity = new Vector3(moveSpeed + velocityAddition, 0, 0);
- }
- else if (leftDir.x < -0.3f)
- {
- rb.velocity = new Vector3(-moveSpeed + velocityAddition, 0, 0);
- }
- }
- break;
- case CharacterState.Rise:
- if (CheckSummon())
- {
- break;
- }
- if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
- {
- ChangeState(CharacterState.Rush);
- break;
- }
- if (btnJumpPress || cacheJumpTime > 0)
- {
- if (airJumped < airJumpNumber && rb.velocity.y < canAirJumpSpeed)
- {
- airJumped++;
- AirJump();
- break;
- }
- }
- rb.velocity = AirMove(rb.velocity);
- if (rb.velocity.y <= 0)
- {
- ChangeState(CharacterState.Fall);
- break;
- }
- break;
- case CharacterState.Fall:
- if (CheckSummon())
- {
- break;
- }
- if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
- {
- ChangeState(CharacterState.Rush);
- break;
- }
- if (foot.TrigGround)
- {
- if (CheckPlayerChangeState(CharacterState.Fall))
- {
- break;
- }
- }
- if (btnJumpPress || cacheJumpTime > 0)
- {
- if (canJumpTime > 0)
- {
- AirJump();
- break;
- }
- else
- {
- if (airJumped < airJumpNumber)
- {
- airJumped++;
- AirJump();
- break;
- }
- }
- }
- rb.velocity = AirMove(rb.velocity);
- break;
- case CharacterState.Attack:
- if (attackController.attackTime <= 0)
- {
- if (btnNorthKeep)
- {
- ChangeState(CharacterState.KeepAttack);
- break;
- }
- if (CheckPlayerChangeState(CharacterState.Attack))
- {
- break;
- }
- }
- break;
- case CharacterState.KeepAttack:
- if ((btnRushPress) && mp >= rushCostMp)
- {
- ChangeState(CharacterState.Rush);
- break;
- }
- if (btnJumpPress && canJumpTime > 0)
- {
- AirJump();
- break;
- }
- if (!btnNorthKeep)
- {
- if (CheckPlayerChangeState(CharacterState.KeepAttack))
- {
- break;
- }
- }
- switch (attackState)
- {
- case PlayerAttackState.Idle:
- if (bodyTrans.localScale.x > 0)
- {
- if (leftDir.x > 0.3f)
- {
- SetAttackState(PlayerAttackState.WalkBack);
- velocity.x = attackMoveSpeed;
- rb.velocity = velocity;
- break;
- }
- else if (leftDir.x < -0.3f)
- {
- SetAttackState(PlayerAttackState.WalkForward);
- velocity.x = -attackMoveSpeed;
- rb.velocity = velocity;
- break;
- }
- }
- else
- {
- if (leftDir.x > 0.3f)
- {
- SetAttackState(PlayerAttackState.WalkForward);
- velocity.x = attackMoveSpeed;
- rb.velocity = velocity;
- break;
- }
- else if (leftDir.x < -0.3f)
- {
- SetAttackState(PlayerAttackState.WalkBack);
- velocity.x = -attackMoveSpeed;
- rb.velocity = velocity;
- break;
- }
- }
- velocity.x = 0;
- rb.velocity = velocity;
- break;
- case PlayerAttackState.WalkForward:
- if (bodyTrans.localScale.x > 0)
- {
- if (leftDir.x > 0.3f)
- {
- SetAttackState(PlayerAttackState.WalkBack);
- velocity.x = attackMoveSpeed;
- rb.velocity = velocity;
- break;
- }
- else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
- {
- SetAttackState(PlayerAttackState.Idle);
- velocity.x = 0;
- rb.velocity = velocity;
- break;
- }
- else
- {
- velocity.x = -attackMoveSpeed;
- rb.velocity = velocity;
- }
- }
- else
- {
- if (leftDir.x < -0.3f)
- {
- SetAttackState(PlayerAttackState.WalkBack);
- velocity.x = -attackMoveSpeed;
- rb.velocity = velocity;
- break;
- }
- else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
- {
- SetAttackState(PlayerAttackState.Idle);
- velocity.x = 0;
- rb.velocity = velocity;
- break;
- }
- else
- {
- velocity.x = attackMoveSpeed;
- rb.velocity = velocity;
- }
- }
- break;
- case PlayerAttackState.WalkBack:
- if (bodyTrans.localScale.x > 0)
- {
- if (leftDir.x < -0.3f)
- {
- SetAttackState(PlayerAttackState.WalkForward);
- velocity.x = -attackMoveSpeed;
- rb.velocity = velocity;
- break;
- }
- else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
- {
- SetAttackState(PlayerAttackState.Idle);
- velocity.x = 0;
- rb.velocity = velocity;
- break;
- }
- else
- {
- velocity.x = attackMoveSpeed;
- rb.velocity = velocity;
- }
- }
- else
- {
- if (leftDir.x > 0.3f)
- {
- SetAttackState(PlayerAttackState.WalkForward);
- velocity.x = attackMoveSpeed;
- rb.velocity = velocity;
- break;
- }
- else if (leftDir.x > -0.3f && leftDir.x > 0.3f)
- {
- SetAttackState(PlayerAttackState.Idle);
- velocity.x = 0;
- rb.velocity = velocity;
- break;
- }
- else
- {
- velocity.x = -attackMoveSpeed;
- rb.velocity = velocity;
- }
- }
- break;
- default:
- break;
- }
- break;
- case CharacterState.Summon:
- if (leftDir.x > 0.3f || leftDir.x < -0.3f)
- {
- cacheDir = leftDir.x;
- }
- if (LBisHold)
- {
- cacheRush = true;
- }
- if (CheckPlayerChangeState(CharacterState.Summon))
- {
- break;
- }
- rb.velocity = Vector3.right * velocityAddition;
- break;
- case CharacterState.Rush:
- if (rushTime <= 0)
- {
- if (btnRushKeep)
- {
- ChangeState(CharacterState.Sprint);
- break;
- }
- if (CheckPlayerChangeState(CharacterState.Rush))
- {
- break;
- }
- }
- rb.velocity = rushDir * rushSpeed;
- break;
- case CharacterState.Sprint:
- if (!btnRushKeep)
- {
- if (CheckPlayerChangeState(CharacterState.Sprint))
- {
- break;
- }
- }
- if (mp < sprintCostMp * Time.deltaTime)
- {
- if (CheckPlayerChangeState(CharacterState.Sprint))
- {
- break;
- }
- }
- mp -= sprintCostMp * Time.deltaTime;
- uiMp.Show(mp, totalMp);
- rb.velocity = rushDir * rushSpeed;
- break;
- case CharacterState.Die:
- if (dieKeepTime <= 0)
- {
- if (isRevive)
- {
- reviveTime += Time.deltaTime;
- if (reviveTime >= totalReviveTime)
- {
- PlayerRevive();
- }
- }
- else
- {
- PlayerDie();
- }
- }
- break;
- case CharacterState.Conduct:
- if (CheckConduct())
- {
- ChangeState(CharacterState.Idle);
- }
- break;
- case CharacterState.HitStun:
- hitFeedbackSystem.HitStunUpdate();
- break;
- case CharacterState.SpecialStatus_Float:
- attributeStatus.SpecialStateEffect(SpecialState.FloatState);
- break;
- case CharacterState.SpecialStatus_BlowUp:
- attributeStatus.SpecialStateEffect(SpecialState.BlownUp);
- break;
- case CharacterState.SpecialStatus_ShotDown:
- attributeStatus.SpecialStateEffect(SpecialState.ShotDown);
- break;
- case CharacterState.SpecialStatus_Weak:
- attributeStatus.SpecialStateEffect(SpecialState.Weak);
- break;
- default:
- break;
- }
- isClickBtnRush = false;
- isKeepBtnRush = false;
- isClickBtnJump = false;
- isClickBtnSouth = false;
- isClickBtnEast = false;
- isClickBtnNorth = false;
- isClickBtnWest = false;
- isBtnSouthUp = false;
- isBtnEastUp = false;
- isBtnNorthUp = false;
- isBtnWestUp = false;
- isSpiritSummon = false;
- isSpiritSummon1 = false;
- isSpiritSummon2 = false;
- isSpiritSummon3 = false;
- if (foot.TrigGround)
- {
- canJumpTime = leaveGroundCanJumpTime;
- }
- //SearchTarget();
- //attackTarget = targetCharacter;
- if (isMpRepel)
- {
- if (mp < totalMp)
- {
- if (!isRapedReply)
- {
- mp += mpReplySpeed * Time.deltaTime;
- }
- else
- {
- mp += rapidReplySpeed * Time.deltaTime;
- }
- }
- }
- if (mp > totalMp)
- {
- mp = totalMp;
- }
- if (mp < 0)
- {
- mp = 0;
- }
- uiMp.Show(mp, totalMp);
- }
- public void PlayerDie()
- {
- switch (playerId)
- {
- case 0:
- SpiritSystem.isP1In = true;
- SpiritSystem.isP1Out = false;
- break;
- case 1:
- SpiritSystem.isP2In = true;
- SpiritSystem.isP2Out = false;
- break;
- default:
- break;
- }
- foot.trigGroundList.Clear();
- bodyTrans.gameObject.SetActive(false);
- uiHp.transform.parent.gameObject.SetActive(false);
- rb.constraints = RigidbodyConstraints.FreezeAll;
- isRevive = true;
- reviveTime = 0;
- }
- public void PlayerRevive()
- {
- isRevive = false;
- bodyTrans.gameObject.SetActive(true);
- uiHp.transform.parent.gameObject.SetActive(true);
- rb.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotation;
- transform.position = new Vector3(142 + 4 * playerId, 0, 0);
- switch (playerId)
- {
- case 0:
- SpiritSystem.isP1In = false;
- SpiritSystem.isP1Out = true;
- SpiritSystem.player1 = gameObject;
- SpiritSystem.p1Spirits = GetComponent<Spirits>();
- break;
- case 1:
- SpiritSystem.isP2In = false;
- SpiritSystem.isP2Out = true;
- SpiritSystem.player2 = gameObject;
- SpiritSystem.p2Spirits = GetComponent<Spirits>();
- break;
- default:
- break;
- }
- Init();
- }
- public void RapidReplyMp()
- {
- isRapedReply = true;
- rapidReplyEffect.SetActive(true);
- }
- public void NormalReplyMp()
- {
- isRapedReply = false;
- rapidReplyEffect.SetActive(false);
- }
- public override void ChangeState(CharacterState newState)
- {
- if (state == newState)
- {
- return;
- }
- Vector3 velocity = rb.velocity;
- switch (state)
- {
- case CharacterState.Idle:
- break;
- case CharacterState.Run:
- velocity.x = 0;
- break;
- case CharacterState.Rise:
- bodyCollider.SetActive(true);
- break;
- case CharacterState.Fall:
- break;
- case CharacterState.Attack:
- aniCollider.Play("NotAttack", 1, 0);
- break;
- case CharacterState.KeepAttack:
- aniCollider.Play("NotAttack", 1, 0);
- break;
- case CharacterState.Summon:
- rb.isKinematic = false;
- if (cacheDir != 0)
- {
- if (cacheDir > 0.3f && bodyTrans.localScale.x > 0)
- {
- Turn();
- }
- else if (cacheDir < -0.3f && bodyTrans.localScale.x < 0)
- {
- Turn();
- }
- cacheDir = 0;
- }
- break;
- case CharacterState.Rush:
- invincibleTime = 0;
- rb.useGravity = true;
- velocity = Vector3.zero;
- break;
- case CharacterState.Sprint:
- rb.useGravity = true;
- velocity = Vector3.zero;
- break;
- case CharacterState.Die:
- if (isRevive)
- {
- return;
- }
- isDie = false;
- rb.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotation;
- break;
- case CharacterState.Conduct:
- rb.isKinematic = false;
- Time.timeScale = 1;
- Time.fixedDeltaTime = fixedDeltaTime * Time.timeScale;
- conductReadyTip.activeFalse();
- break;
- default:
- break;
- }
- CharacterState oldState = state;
-
- state = newState;
- switch (newState)
- {
- case CharacterState.Idle:
- aniCollider.Play("Idle", 0, 0);
- if (oldState == CharacterState.Fall)
- {
- ani.Play("fall_end", 0, 0);
- }
- else
- {
- ani.Play("idle", 0, 0);
- }
- velocity = Vector3.right * velocityAddition;
- //animalAni.SetInteger("state", (int)PlayerState.Idle);
- break;
- case CharacterState.Run:
- aniCollider.Play("Run", 0, 0);
- ani.Play("run_start", 0, 0);
- //animalAni.SetInteger("state", (int)PlayerState.Walk);
- break;
- case CharacterState.Rise:
- aniCollider.Play("Rise", 0, 0);
- canJumpTime = 0;
- break;
- case CharacterState.Fall:
- aniCollider.Play("Fall", 0, 0);
- ani.Play("fall", 0, 0);
- //animalAni.SetInteger("state", (int)PlayerState.Fall);
- break;
- case CharacterState.Attack:
- attackController.attackTime = totalAttack_summonTime;
- break;
- case CharacterState.KeepAttack:
- aniCollider.Play("Attack_summonKeep", 1, 0);
- break;
- case CharacterState.Summon:
- aniCollider.Play("Summon", 0, 0);
- if (foot.TrigGround)
- {
- ani.Play("summon", 0, 0);
- }
- else
- {
- ani.Play("summon_air", 0, 0);
- }
- velocity = Vector3.right * velocityAddition;
- rb.isKinematic = true;
- cacheDir = 0;
- cacheRush = false;
- break;
- case CharacterState.Rush:
- aniCollider.Play("Rush", 0, 0);
- ani.Play("rush_loop", 0, 0);
- rushTime = totalRushTime;
- invincibleTime = rushInvincibleTime;
- rb.useGravity = false;
- if (bodyTrans.localScale.x > 0)
- {
- rushDir = Vector3.left;
- }
- else
- {
- rushDir = Vector3.right;
- }
- velocity = rushDir * rushSpeed;
- mp -= rushCostMp;
- uiMp.Show(mp, totalMp);
- break;
- case CharacterState.Sprint:
- aniCollider.Play("Sprint", 0, 0);
- rb.useGravity = false;
- velocity = rushDir * rushSpeed;
- break;
- case CharacterState.Die:
- rb.constraints = RigidbodyConstraints.FreezeAll;
- aniCollider.Play("Die", 0, 0);
- ani.Play("die", 0, 0);
- isDie = true;
- dieKeepTime = totalDieKeepTime;
- break;
- case CharacterState.Conduct:
- conductTime = 0;
- rb.velocity = Vector3.zero;
- rb.isKinematic = true;
- aniCollider.Play("Summon", 0, 0);
- if (foot.TrigGround)
- {
- ani.Play("summon", 0, 0);
- }
- else
- {
- ani.Play("summon_air", 0, 0);
- }
- break;
- default:
- break;
- }
- rb.velocity = velocity;
- }
- public void CheckTurn()
- {
- if (leftDir.x > 0.3f && bodyTrans.localScale.x > 0)
- {
- if (state == CharacterState.Run)
- {
- ani.Play("run_start", 0, 0);
- }
- Turn();
- }
- else if (leftDir.x < -0.3f && bodyTrans.localScale.x < 0)
- {
- if (state == CharacterState.Run)
- {
- ani.Play("run_start", 0, 0);
- }
- Turn();
- }
- }
- public Vector3 AirMove(Vector3 velocity)
- {
- CheckTurn();
- if (canFly)
- {
- velocity = leftDir.normalized * flySpeed;
- if (transform.position.y > playerMaxFlyHeight && velocity.y > 0)
- {
- velocity.y = 0;
- }
- }
- else
- {
- if (leftDir.x > 0.3f)
- {
- velocity = new Vector3(moveSpeed, velocity.y, velocity.z);
- }
- else if (leftDir.x < -0.3f)
- {
- velocity = new Vector3(-moveSpeed, velocity.y, velocity.z);
- }
- else
- {
- velocity = new Vector3(0, velocity.y, velocity.z);
- }
- if (velocity.y > 0)
- {
- velocity += Vector3.up * extraRiseGravity * Time.deltaTime;
- }
- else
- {
- velocity += Vector3.up * extraFallGravity * Time.deltaTime;
- }
- }
- return velocity;
- }
- public void Summon(int id)
- {
- if (id >= demonicPrefabs.Count)
- {
- Debug.LogError("未配置" + id + "号使魔");
- return;
- }
- if (id >= demonicSummonPos.Count)
- {
- Debug.LogError("未配置" + id + "号使魔召唤位置");
- return;
- }
- GameObject prefab;
- prefab = demonicPrefabs[id];
- if (!CheckCanSummon(id))
- {
- return;
- }
- ChangeState(CharacterState.Summon);
- summonTime = totalSummonTime;
- Demonic dem = prefab.GetComponent<Demonic>();
- float costMp = dem.costMp;
- for (int i = 0; i < 3; i++)
- {
- if (GameManager.curSoldiers[i] == dem.soldierType)
- {
- costMp += slr.seb[i].mp;
- break;
- }
- }
- mp -= costMp;
- uiMp.Show(mp, totalMp);
- GameObject demonicObj = PoolManager.Instantiate(prefab);
- Demonic demonic = demonicObj.GetComponent<Demonic>();
- onlySummonTime = demonic.summonTime;
- invincibleTime = demonic.summonTime + addSummonInvincibleTime;
- restSummonTime = onlySummonTime;
- demonic.id = id;
- demonic.playerID = playerId;
- if (!demonicDic.ContainsKey(id))
- {
- demonicDic.Add(id, new List<Demonic>());
- }
- demonicDic[id].Add(demonic);
- if (id <= 2)
- {
- demonicNums[id].text = demonicDic[id].Count.ToString();
- }
- demonicObj.transform.parent = null;
- demonicObj.transform.localEulerAngles = Vector3.zero;
- demonicObj.transform.localScale = new Vector3(1, 1, 1);
- Vector3 offset = demonicSummonPos[id];
- if (bodyTrans.localScale.x > 0)
- {
- demonicObj.transform.position = transform.position + offset;
- if (demonic.bodyTrans.localScale.x < 0)
- {
- demonic.Turn();
- }
- }
- else
- {
- demonicObj.transform.position = transform.position + new Vector3(-offset.x, offset.y, offset.z);
- if (demonic.bodyTrans.localScale.x > 0)
- {
- demonic.Turn();
- }
- }
- if (demonic.canFly)
- {
- demonic.flyHeight = demonic.transform.position.y;
- }
- demonic.player = this;
- demonic.Init();
- int order = prefab.GetComponent<Demonic>().baseSortingOrder + demonicDic[demonic.id].Count;
- demonic.SetSortingOrder(order);
- if (id != 4)
- {
- demonic.Attack_summon();
- }
- //id 3~6 为四个英灵
- if (id >= 3 && id <= 6)
- {
- spirits.ultimateTimes[spirits.nowSpirit] -= 1;
- }
- spiritSystem.RefreshPlayerUI();
- if (isInSoulTower)
- {
- ls.AddDenomic(demonic);
- }
- slr.SoldierAddLevelBuff(demonic);
- }
- public void OnDemonicRecycle(Demonic demonic)
- {
- if (!demonicDic.ContainsKey(demonic.id))
- {
- return;
- }
- demonicDic[demonic.id].Remove(demonic);
- if (demonic.id <= 2)
- {
- demonicNums[demonic.id].text = demonicDic[demonic.id].Count.ToString();
- }
- for (int i = 0; i < demonicDic[demonic.id].Count; i++)
- {
- int order = demonicDic[demonic.id][i].baseSortingOrder + i;
- demonicDic[demonic.id][i].SetSortingOrder(order);
- }
- }
- public bool CheckCanSummon(int id)
- {
- GameObject prefab;
- prefab = demonicPrefabs[id];
- Demonic dem = prefab.GetComponent<Demonic>();
- float costMp = dem.costMp;
- for (int i = 0; i < 3; i++)
- {
- if (GameManager.curSoldiers[i] == dem.soldierType)
- {
- costMp += slr.seb[i].mp;
- break;
- }
- }
- if (id < 3)
- {
- costMp += addCostMp[id] * demonicDic[id].Count;
- }
- if (mp < costMp)
- {
- Debug.Log("mp不足召唤失败, 还得加个动画或者音效啥的");
- return false;
- }
- return true;
- }
- public void Attack_summon()
- {
- attackController.Attack_summon();
- if (leftDir.x > 0.3f)
- {
- if (bodyTrans.localScale.x > 0)
- {
- Turn();
- }
- SetAttackState(PlayerAttackState.WalkForward);
- }
- else if (leftDir.x < -0.3f)
- {
- if (bodyTrans.localScale.x < 0)
- {
- Turn();
- }
- SetAttackState(PlayerAttackState.WalkForward);
- }
- else
- {
- SetAttackState(PlayerAttackState.Idle);
- }
- }
- public void SetAttackState(PlayerAttackState value)
- {
- attackState = value;
- ani.SetInteger("attackState", (int)value);
- aniCollider.Play("Attack_summonKeep", 1, 0);
- }
- /*
- public void SearchTarget()
- {
- targetCharacter = searchTrigger.GetMinDisTarget(attackController.targetTypes, attackController.canHitFly);
- }*/
- public override void BeHit(int damage)
- {
- base.BeHit(damage);
- //屏幕红闪+抖动
- if (ss == null)
- {
- ss = Camera.main.GetComponentInParent<ScreenShake>();
- }
- ss.enabled = true;
- if (isSustainedInjury || damage >= heavyDamage)
- {
- ss.ShakeScreen(1);
- }
- }
- public override void BeHit(AttackInfo attackInfo, Character attackFrom)
- {
- if (conductController.HavePhoton(attackFrom, attackInfo.damage))
- {
- return;
- }
- base.BeHit(attackInfo, attackFrom);
- //屏幕红闪+抖动
- if (ss == null)
- {
- ss = Camera.main.GetComponentInParent<ScreenShake>();
- }
- ss.enabled = true;
- if (isSustainedInjury || attackInfo.damage >= heavyDamage)
- {
- ss.ShakeScreen(1);
- }
- }
- }
|