Demonic.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  1. using Spine.Unity;
  2. using Spine;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using Sirenix.OdinInspector;
  7. public class Demonic : MoveCharacter
  8. {
  9. [FoldoutGroup("组件")] [DisplayOnly]public SearchState searchState;
  10. [FoldoutGroup("组件")] public BigSoldier bigSoldier;
  11. [FoldoutGroup("组件")] public AttackTrigger dragonTrigger;
  12. [FoldoutGroup("角色信息")] public string myName;
  13. [FoldoutGroup("条件")] [LabelText("释放起手式后死亡")] public bool summonEndToDie;
  14. [FoldoutGroup("条件")] [LabelText("体型是否会变化")] public bool canSizeChange;
  15. [FoldoutGroup("条件")] [LabelText("是否无视OnState")] public bool ignoresOnState;
  16. [Space(30)]
  17. [Title("Demonic属性")]
  18. public SoldierType soldierType; //当前士兵属于什么兵种
  19. public PlayerController player; //召唤师
  20. public int playerID;
  21. public int id;
  22. public float costMp = 10;
  23. public bool isBack = false; //往反方向走
  24. public int baseSortingOrder;
  25. public float runSpeed;
  26. private bool isFreeze; //冻结rb
  27. public DemoicTag demoicTags;
  28. public int ownDamageScale;
  29. [Header("锁魂塔")]
  30. public bool isReturnSoulTower;
  31. public Vector3 origSoulPos;
  32. public bool isRecorded;
  33. [Header("攻击")]
  34. private float pastAttackTime;
  35. private bool isConAttack; //连续攻击,不切idle动画
  36. [Header("八卦")]
  37. public float adsorbSpeed; //八卦吸附的速度
  38. [HideInInspector] public Vector3 adsorbTarget; //八卦胖子吸附时目标位置的X
  39. private float adsorbTime; //八卦吸附中的时间
  40. public GameObject effectPrefab; //八卦卦象效果
  41. [Header("掉落魂")]
  42. public int dropSoulMax = 3;
  43. public int dropSoulMin = 1;
  44. public float dropSoulAngle = 60f;
  45. private AttackController initAc;
  46. private int initRegeneration;
  47. private int initArmor;
  48. private int initDodge;
  49. private BuffController buffControl;
  50. public override void FixedUpdate()
  51. {
  52. if (ignoresOnState) return;
  53. OnSearchState();
  54. OnState();
  55. }
  56. public bool SearchTarget()
  57. {
  58. targetCharacter = searchTrigger.GetMinDisTarget(attackController.targetTypes, attackController.curAttackMethod.canHitFly,attackController.curAttackMethod.searchMode);
  59. if (targetCharacter != null)
  60. {
  61. return true;
  62. }
  63. else
  64. {
  65. return false;
  66. }
  67. }
  68. public void ChangeSearchState(SearchState newState)
  69. {
  70. switch (searchState)
  71. {
  72. case SearchState.NoTarget:
  73. break;
  74. case SearchState.InSearchScope:
  75. break;
  76. case SearchState.InAttackScope:
  77. break;
  78. default:
  79. break;
  80. }
  81. searchState = newState;
  82. switch (searchState)
  83. {
  84. case SearchState.NoTarget:
  85. targetCharacter = null;
  86. break;
  87. case SearchState.InSearchScope:
  88. break;
  89. case SearchState.InAttackScope:
  90. break;
  91. default:
  92. break;
  93. }
  94. }
  95. public void OnSearchState()
  96. {
  97. switch (searchState)
  98. {
  99. case SearchState.NoTarget:
  100. if (SearchTarget())
  101. {
  102. ChangeSearchState(SearchState.InSearchScope);
  103. break;
  104. }
  105. //向玩家基地移动
  106. break;
  107. case SearchState.InSearchScope:
  108. if (!SearchTarget())
  109. {
  110. targetCharacter = null;
  111. ChangeSearchState(SearchState.NoTarget);
  112. break;
  113. }
  114. attackDis = attackController.curAttackMethod.attackDistance + targetCharacter.beHitDistance;
  115. if (targetCharacter != null && Mathf.Abs(targetCharacter.transform.position.x - transform.position.x) <= attackDis)
  116. {
  117. ChangeSearchState(SearchState.InAttackScope);
  118. break;
  119. }
  120. break;
  121. case SearchState.InAttackScope:
  122. if (targetCharacter != null)
  123. {
  124. //判断是否在射程夹角内
  125. AttackController.AttackMethod am = attackController.curAttackMethod;
  126. if (am.attackType == AttackController.AttackType.Shoot
  127. && attackController.curAttackMethod.attackInfo.attackMethod_Type == AttackMethod_Type.Attack_March)
  128. {
  129. Vector3 dir = targetCharacter.beSearchTrigger.transform.position - transform.position;
  130. float angle = Vector3.Angle(dir, Vector3.left * bodyTrans.localScale.x);
  131. if ((dir.y > 0 && angle > am.maxUpAngle) || (dir.y < 0 && angle > am.maxDownAngle))
  132. {
  133. ChangeSearchState(SearchState.NoTarget);
  134. break;
  135. }
  136. }
  137. attackDis = attackController.curAttackMethod.attackDistance + targetCharacter.beHitDistance;
  138. if (!targetCharacter.gameObject.activeInHierarchy || targetCharacter.isDie
  139. || Mathf.Abs(targetCharacter.transform.position.x - transform.position.x) > attackDis)
  140. {
  141. ChangeSearchState(SearchState.NoTarget);
  142. }
  143. }
  144. else
  145. {
  146. ChangeSearchState(SearchState.NoTarget);
  147. }
  148. break;
  149. default:
  150. break;
  151. }
  152. }
  153. public override Vector3 GetMoveDir()
  154. {
  155. Vector3 moveDir = Vector3.zero;
  156. switch (searchState)
  157. {
  158. case SearchState.NoTarget:
  159. if (TowerMap.enemyTowers.Count == 0)
  160. {
  161. moveDir = Vector3.left;
  162. break;
  163. }
  164. float minDistance = Mathf.Infinity;
  165. int id = -1;
  166. for (int i = 0; i < TowerMap.enemyTowers.Count; i++)
  167. {
  168. EnemyTower enemyTower = TowerMap.enemyTowers[i].GetComponent<EnemyTower>();
  169. if (transform.position.y >
  170. enemyTower.transform.position.y + enemyTower.height)
  171. {
  172. continue;
  173. }
  174. float distance = Vector3.Distance(transform.position,
  175. TowerMap.enemyTowers[i].transform.position);
  176. if (distance < minDistance)
  177. {
  178. minDistance = distance;
  179. id = i;
  180. }
  181. }
  182. if (id == -1)
  183. {
  184. moveDir = Vector3.left;
  185. break;
  186. }
  187. if (bodyTrans.position.x > TowerMap.enemyTowers[id].transform.position.x)
  188. {
  189. moveDir = Vector3.left;
  190. }
  191. else
  192. {
  193. moveDir = Vector3.right;
  194. }
  195. break;
  196. case SearchState.InSearchScope:
  197. if (targetCharacter)
  198. {
  199. if (targetCharacter.transform.position.x - transform.position.x < 0)
  200. {
  201. moveDir = Vector3.left;
  202. }
  203. else
  204. {
  205. moveDir = Vector3.right;
  206. }
  207. }
  208. else
  209. {
  210. moveDir = Vector3.zero;
  211. }
  212. break;
  213. case SearchState.InAttackScope:
  214. if (targetCharacter)
  215. {
  216. if (targetCharacter.transform.position.x - transform.position.x < 0)
  217. {
  218. moveDir = Vector3.left;
  219. }
  220. else
  221. {
  222. moveDir = Vector3.right;
  223. }
  224. }
  225. else
  226. {
  227. moveDir = Vector3.zero;
  228. }
  229. break;
  230. default:
  231. break;
  232. }
  233. if (!isBack)
  234. {
  235. return moveDir;
  236. }
  237. return -moveDir;
  238. }
  239. public bool GetAttack()
  240. {
  241. if (searchState == SearchState.InAttackScope)
  242. {
  243. return true;
  244. }
  245. return false;
  246. }
  247. public override void OnState()
  248. {
  249. base.OnState();
  250. if (state == CharacterState.FramePause)
  251. {
  252. return;
  253. }
  254. //hurtKeepTime -= Time.deltaTime;
  255. dieKeepTime -= Time.deltaTime;
  256. invincibleTime -= Time.deltaTime;
  257. pastAttackTime += Time.deltaTime;
  258. Vector3 leftDir = GetMoveDir();
  259. bool isAttack = GetAttack();
  260. Vector3 velocity = rb.velocity;
  261. Quaternion targetQt = Quaternion.Euler(Vector3.zero);
  262. switch (state)
  263. {
  264. case CharacterState.Idle:
  265. if (isAdjustHeight == 1)
  266. {
  267. ChangeState(CharacterState.Rise);
  268. break;
  269. }
  270. if (isAttack)
  271. {
  272. if (pastAttackTime * (1 + GameManager.instance.attackSpeed/100f) >= attackController.attackInterval)
  273. {
  274. Attack_march();
  275. }
  276. }
  277. else
  278. {
  279. if (!foot.TrigGround && !canFly)
  280. {
  281. if (rb.velocity.y > 0)
  282. {
  283. ChangeState(CharacterState.Rise);
  284. break;
  285. }
  286. else
  287. {
  288. ChangeState(CharacterState.Fall);
  289. break;
  290. }
  291. }
  292. if (leftDir.x > 0.3f || leftDir.x < -0.3f)
  293. {
  294. ChangeState(CharacterState.Run);
  295. break;
  296. }
  297. velocity.x = velocityAddition;
  298. velocity.y = 0;
  299. if (!foot.haveGravity)
  300. {
  301. transform.position = new Vector3(transform.position.x, platformPosY, transform.position.z);
  302. targetQt = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, platformRotZ);
  303. }
  304. if (RotLerpTime < 1)
  305. {
  306. RotLerpTime += RotLerpSpeed * Time.deltaTime;
  307. transform.rotation = Quaternion.Lerp(transform.rotation, targetQt, RotLerpTime);
  308. }
  309. else
  310. {
  311. transform.rotation = targetQt;
  312. }
  313. rb.velocity = velocity;
  314. }
  315. break;
  316. case CharacterState.Run:
  317. if (isAttack)
  318. {
  319. if (pastAttackTime * (1 + GameManager.instance.attackSpeed / 100f) >= attackController.attackInterval)
  320. {
  321. Attack_march();
  322. }
  323. else
  324. {
  325. ChangeState(CharacterState.Idle);
  326. }
  327. }
  328. else
  329. {
  330. if (!foot.TrigGround && !canFly)
  331. {
  332. if (rb.velocity.y > 0)
  333. {
  334. ChangeState(CharacterState.Rise);
  335. break;
  336. }
  337. else
  338. {
  339. ChangeState(CharacterState.Fall);
  340. break;
  341. }
  342. }
  343. if (leftDir.x < 0.3f && leftDir.x > -0.3f)
  344. {
  345. ChangeState(CharacterState.Idle);
  346. break;
  347. }
  348. if (leftDir.x > 0.3f)
  349. {
  350. velocity.x = (moveSpeed + velocityAddition) * moveSpeedScale;
  351. if (bodyTrans.localScale.x > 0)
  352. {
  353. Turn();
  354. }
  355. }
  356. else if (leftDir.x < -0.3f)
  357. {
  358. velocity.x = (-moveSpeed + velocityAddition) * moveSpeedScale;
  359. if (bodyTrans.localScale.x < 0)
  360. {
  361. Turn();
  362. }
  363. }
  364. velocity.y = 0;
  365. if (!foot.haveGravity)
  366. {
  367. transform.position = new Vector3(transform.position.x, platformPosY, transform.position.z);
  368. targetQt = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, platformRotZ);
  369. }
  370. if (RotLerpTime < 1)
  371. {
  372. RotLerpTime += RotLerpSpeed * Time.deltaTime;
  373. transform.rotation = Quaternion.Lerp(transform.rotation, targetQt, RotLerpTime);
  374. }
  375. else
  376. {
  377. transform.rotation = targetQt;
  378. }
  379. rb.velocity = velocity;
  380. AdjustHeight();
  381. }
  382. break;
  383. case CharacterState.Rush:
  384. if (isAttack)
  385. {
  386. if (pastAttackTime * (1 + GameManager.instance.attackSpeed / 100f) >= attackController.attackInterval)
  387. {
  388. Attack_march();
  389. }
  390. else
  391. {
  392. ChangeState(CharacterState.Idle);
  393. }
  394. }
  395. else
  396. {
  397. if (!foot.TrigGround && !canFly)
  398. {
  399. if (rb.velocity.y > 0)
  400. {
  401. ChangeState(CharacterState.Rise);
  402. break;
  403. }
  404. else
  405. {
  406. ChangeState(CharacterState.Fall);
  407. break;
  408. }
  409. }
  410. if (leftDir.x < 0.3f && leftDir.x > -0.3f)
  411. {
  412. ChangeState(CharacterState.Idle);
  413. break;
  414. }
  415. if (leftDir.x > 0.3f)
  416. {
  417. //rb.velocity += Vector3.right * moveAcc * Time.deltaTime;
  418. rb.velocity = Vector3.right * runSpeed;
  419. //if (rb.velocity.x > maxMoveSpeed)
  420. //{
  421. // rb.velocity = new Vector3(maxMoveSpeed, rb.velocity.y, rb.velocity.z);
  422. //}
  423. if (bodyTrans.localScale.x > 0)
  424. {
  425. Turn();
  426. }
  427. }
  428. else if (leftDir.x < -0.3f)
  429. {
  430. //rb.velocity -= Vector3.right * moveAcc * Time.deltaTime;
  431. rb.velocity = Vector3.left * runSpeed;
  432. //if (rb.velocity.x < -maxMoveSpeed)
  433. //{
  434. // rb.velocity = new Vector3(-maxMoveSpeed, rb.velocity.y, rb.velocity.z);
  435. //}
  436. if (bodyTrans.localScale.x < 0)
  437. {
  438. Turn();
  439. }
  440. }
  441. }
  442. break;
  443. case CharacterState.Rise:
  444. if (isAdjustHeight == 1)
  445. {
  446. AdjustHeight();
  447. }
  448. else if(isAdjustHeight == 2)
  449. {
  450. ChangeState(CharacterState.Idle);
  451. isAdjustHeight = 0;
  452. }
  453. else
  454. {
  455. if (rb.velocity.y <= 0)
  456. {
  457. ChangeState(CharacterState.Fall);
  458. break;
  459. }
  460. rb.velocity += Vector3.up * extraRiseGravity * Time.deltaTime;
  461. }
  462. break;
  463. case CharacterState.Fall:
  464. if (foot.TrigGround || (canFly && !isDie))
  465. {
  466. if (isDie)
  467. {
  468. ChangeState(CharacterState.Die);
  469. break;
  470. }
  471. ChangeState(CharacterState.Idle);
  472. break;
  473. }
  474. if (canFly && isDie)
  475. {
  476. velocity.y += extraFallGravity * Time.deltaTime;
  477. rb.velocity = velocity;
  478. }
  479. else
  480. {
  481. velocity.y += extraFallGravity * Time.deltaTime;
  482. if (leftDir.x > 0.3f)
  483. {
  484. velocity.x = moveSpeed * moveSpeedScale;
  485. if (bodyTrans.localScale.x > 0)
  486. {
  487. Turn();
  488. }
  489. }
  490. else if (leftDir.x < -0.3f)
  491. {
  492. velocity.x = -moveSpeed * moveSpeedScale;
  493. if (bodyTrans.localScale.x < 0)
  494. {
  495. Turn();
  496. }
  497. }
  498. rb.velocity = velocity;
  499. }
  500. break;
  501. case CharacterState.Attack:
  502. attackController.JudgeTriggerOnOff();
  503. if (attackController.attackTime <= 0)
  504. {
  505. if (summonEndToDie)
  506. {
  507. ChangeState(CharacterState.Die);
  508. break;
  509. }
  510. if (isInSoulTower)
  511. {
  512. ChangeState(CharacterState.LockSoul);
  513. }
  514. else
  515. {
  516. isAttack = GetAttack();
  517. if (isAttack)
  518. {
  519. isConAttack = true;
  520. }
  521. ChangeState(CharacterState.Idle);
  522. }
  523. break;
  524. }
  525. if (!foot.haveGravity)
  526. {
  527. targetQt = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, platformRotZ);
  528. }
  529. if (RotLerpTime < 1)
  530. {
  531. RotLerpTime += RotLerpSpeed * Time.deltaTime;
  532. transform.rotation = Quaternion.Lerp(transform.rotation, targetQt, RotLerpTime);
  533. }
  534. else
  535. {
  536. transform.rotation = targetQt;
  537. }
  538. rb.velocity = new Vector3(velocityAddition, rb.velocity.y, rb.velocity.z);
  539. break;
  540. case CharacterState.Die:
  541. if (dieKeepTime <= 0)
  542. {
  543. gameObject.SetActive(false);
  544. break;
  545. }
  546. break;
  547. case CharacterState.LockSoul:
  548. if (!isReturnSoulTower)
  549. {
  550. if (targetCharacter != null && targetCharacter.gameObject.layer == 8 && targetCharacter.isInSoulTower)
  551. {
  552. ChangeState(CharacterState.Idle);
  553. }
  554. else
  555. {
  556. isReturnSoulTower = true;
  557. }
  558. }
  559. else
  560. {
  561. if (transform.position.x - origSoulPos.x >= 0.2f)
  562. {
  563. rb.velocity = Vector3.right * (-moveSpeed + velocityAddition) * moveSpeedScale;
  564. if (bodyTrans.localScale.x < 0)
  565. {
  566. Turn();
  567. }
  568. }
  569. else if (origSoulPos.x - transform.position.x >= 0.2f)
  570. {
  571. rb.velocity = Vector3.right * (moveSpeed + velocityAddition) * moveSpeedScale;
  572. if (bodyTrans.localScale.x > 0)
  573. {
  574. Turn();
  575. }
  576. }
  577. else
  578. {
  579. ani.CrossFade(AnimatorHash.ANIMATOR_idle, 0.2f);
  580. rb.velocity = Vector3.zero;
  581. transform.position = origSoulPos;
  582. isReturnSoulTower = false;
  583. targetCharacter = null;
  584. FaceToEneTower();
  585. }
  586. //锁魂塔内使魔返回原地过程中扫描到敌人时,停止返回并索敌攻击
  587. if (targetCharacter != null && targetCharacter.gameObject.layer == 8 && targetCharacter.isInSoulTower)
  588. {
  589. ChangeState(CharacterState.Idle);
  590. }
  591. }
  592. break;
  593. case CharacterState.HitStun:
  594. hitFeedbackSystem.HitStunUpdate();
  595. break;
  596. case CharacterState.SpecialStatus_Float:
  597. attributeStatus.SpecialStateEffect(SpecialState.FloatState);
  598. break;
  599. case CharacterState.SpecialStatus_BlowUp:
  600. attributeStatus.SpecialStateEffect(SpecialState.BlownUp);
  601. break;
  602. case CharacterState.SpecialStatus_ShotDown:
  603. attributeStatus.SpecialStateEffect(SpecialState.ShotDown);
  604. break;
  605. case CharacterState.SpecialStatus_Weak:
  606. attributeStatus.SpecialStateEffect(SpecialState.Weak);
  607. break;
  608. default:
  609. break;
  610. }
  611. }
  612. private void FaceToEneTower()
  613. {
  614. float dis = 1000000;
  615. GameObject to = null;
  616. foreach (GameObject g in TowerMap.enemyTowers)
  617. {
  618. float k = Vector3.Distance(g.transform.position, transform.position);
  619. if (k < dis)
  620. {
  621. dis = k;
  622. to = g;
  623. }
  624. }
  625. if (to != null && to.transform.position.x < transform.position.x)
  626. {
  627. if (bodyTrans.localScale.x < 0)
  628. {
  629. Turn();
  630. }
  631. }
  632. else
  633. {
  634. if (bodyTrans.localScale.x > 0)
  635. {
  636. Turn();
  637. }
  638. }
  639. }
  640. public override void ChangeState(CharacterState newState)
  641. {
  642. if (state == newState || newState == CharacterState.FramePause)
  643. {
  644. state = newState;
  645. return;
  646. }
  647. AnimatorStateInfo currentStateInfo = ani.GetCurrentAnimatorStateInfo(0);
  648. switch (state)
  649. {
  650. case CharacterState.Idle:
  651. //transform.rotation = Quaternion.Euler(Vector3.zero);
  652. break;
  653. case CharacterState.Run:
  654. //transform.rotation = Quaternion.Euler(Vector3.zero);
  655. rb.velocity = Vector3.zero;
  656. break;
  657. case CharacterState.Rush:
  658. rb.velocity = Vector3.zero;
  659. break;
  660. case CharacterState.Rise:
  661. if (!canFly)
  662. {
  663. bodyCollider.SetActive(true);
  664. }
  665. break;
  666. case CharacterState.Fall:
  667. rb.velocity = Vector3.zero;
  668. break;
  669. case CharacterState.Attack:
  670. if (isFreeze)
  671. {
  672. rb.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotation;
  673. }
  674. attackController.isAttackTriggerOn = false;
  675. attackController.curAttackMethod.attackTrigger.gameObject.SetActive(false);
  676. ani.speed = 1;
  677. break;
  678. case CharacterState.Die:
  679. isDie = false;
  680. break;
  681. case CharacterState.LockSoul:
  682. //isReturnSoulTower = true;
  683. break;
  684. case CharacterState.FramePause:
  685. state = hitFeedbackSystem.curCharacterState;
  686. ChangeState(newState);
  687. return;
  688. default:
  689. break;
  690. }
  691. //Debug.Log("士兵由" + state + "切换到" + newState);
  692. state = newState;
  693. switch (newState)
  694. {
  695. case CharacterState.Idle:
  696. if (!isConAttack || attackController.attackInterval > 0)
  697. {
  698. ani.CrossFade(AnimatorHash.ANIMATOR_idle, 1);
  699. }
  700. rb.velocity = Vector3.zero;
  701. isConAttack = false;
  702. //animalAni.SetInteger("state", (int)PlayerState.Idle);
  703. break;
  704. case CharacterState.Run:
  705. if(currentStateInfo.shortNameHash == AnimatorHash.ANIMATOR_weak)
  706. {
  707. ani.Play(AnimatorHash.ANIMATOR_walk, 0, 0);
  708. }
  709. else
  710. {
  711. ani.CrossFade(AnimatorHash.ANIMATOR_walk, 0.5f);
  712. }
  713. break;
  714. case CharacterState.Rush:
  715. ani.Play(AnimatorHash.ANIMATOR_rush, 0, 0);
  716. break;
  717. case CharacterState.Fall:
  718. ani.Play(AnimatorHash.ANIMATOR_fall, 0, 0);
  719. //animalAni.SetInteger("state", (int)PlayerState.Fall);
  720. break;
  721. case CharacterState.Attack:
  722. break;
  723. case CharacterState.Die:
  724. if (canFly)
  725. {
  726. if (isDie)
  727. {
  728. return;
  729. }
  730. rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionZ;
  731. rb.velocity = Vector3.zero;
  732. ChangeState(CharacterState.Fall);
  733. isDie = true;
  734. PlayersInput.instance[playerID].OnDemonicRecycle(this);
  735. //if (GameManager.instance.isGroundEnable && !canFly)
  736. //{
  737. // int randomInt = Random.Range(0, 100);
  738. // if (randomInt < GameManager.instance.groundProbability)
  739. // {
  740. // SoulDead soulDead = PoolManager.Instantiate(Resources.Load<GameObject>("Prefab/SoulDead"),transform.position).GetComponent<SoulDead>();
  741. // soulDead.Init(player, id);
  742. // soulDead.transform.position = transform.position;
  743. // }
  744. //}
  745. }
  746. else
  747. {
  748. isDie = true;
  749. ani.Play(AnimatorHash.ANIMATOR_die, 0, 0);
  750. dieKeepTime = totalDieKeepTime;
  751. PlayersInput.instance[playerID].OnDemonicRecycle(this);
  752. //if (GameManager.instance.isGroundEnable && !canFly)
  753. //{
  754. // int randomInt = Random.Range(0, 100);
  755. // if (randomInt < GameManager.instance.groundProbability)
  756. // {
  757. // SoulDead soulDead = PoolManager.Instantiate(Resources.Load<GameObject>("Prefab/SoulDead"), transform.position).GetComponent<SoulDead>();
  758. // soulDead.Init(player, id);
  759. // soulDead.transform.position = transform.position;
  760. // }
  761. //}
  762. }
  763. if (GameManager.instance.isSkyGroundIceEnable)
  764. {
  765. int randomInt = Random.Range(0, 100);
  766. if (randomInt < GameManager.instance.skyGroundProbability + (int)(GameManager.instance.skyGroundLabelEffectRatio * (GameManager.instance.myTreasuresTag[0] + GameManager.instance.myTreasuresTag[4])))
  767. {
  768. player.nextSummonNum++;
  769. GameUI.instance.summonNum.text = player.nextSummonNum.ToString();
  770. }
  771. }
  772. summonEndToDie = false;
  773. canSizeChange = false;
  774. bigSoldier.enabled = false;
  775. break;
  776. case CharacterState.LockSoul:
  777. rb.velocity = Vector3.zero;
  778. ani.Play(AnimatorHash.ANIMATOR_walk, 0, 0);
  779. //FaceToEneTower();
  780. break;
  781. default:
  782. break;
  783. }
  784. }
  785. public virtual void Attack_summon()
  786. {
  787. ani.speed = 1 * (1 + GameManager.instance.attackSpeed / 100f);
  788. if (needToAdjustFlyHeight && canFly)
  789. {
  790. flyHeight = Random.Range(minFlyHeight, maxFlyHeight);
  791. isAdjustHeight = 1;
  792. }
  793. if (!canFly)
  794. {
  795. rb.constraints = RigidbodyConstraints.FreezeAll;
  796. isFreeze = true;
  797. }
  798. CheckTurn(-PlayersInput.instance[playerID].bodyTrans.localScale.x);
  799. attackController.Attack_summon();
  800. invincibleTime = attackController.attackTime;
  801. attackTarget = targetCharacter;
  802. }
  803. public virtual void Attack_march()
  804. {
  805. ani.speed = 1 * (1 + GameManager.instance.attackSpeed / 100f);
  806. CheckTurn(GetMoveDir().x);
  807. attackController.Attack_march();
  808. if (attackController.attackMarchId + 1 < attackController.attackMethod_march.Length)
  809. {
  810. attackController.attackMarchId += 1;
  811. }
  812. else
  813. {
  814. attackController.attackMarchId = 0;
  815. }
  816. attackTarget = targetCharacter;
  817. pastAttackTime = 0;
  818. }
  819. public void DropSouls()
  820. {
  821. int dropSoulNum = Random.Range(dropSoulMin, dropSoulMax + 1);
  822. if (dropSoulNum > 1)
  823. {
  824. for (int i = 0; i < dropSoulNum; i++)
  825. {
  826. float angleInterval = dropSoulAngle / (float)(dropSoulNum - 1);
  827. float angle = 90 + ((float)i - (float)(dropSoulNum - 1) / 2) * angleInterval;
  828. angle = angle / 180 * Mathf.PI;
  829. GameObject soulObj = PoolManager.Instantiate(soulPrefab, transform.position);
  830. Vector3 dir = new Vector3(Mathf.Cos(angle), Mathf.Sin(angle), 0);
  831. Soul soul = soulObj.GetComponent<Soul>();
  832. soul.Burst(dir * soulStartSpeed);
  833. }
  834. }
  835. else
  836. {
  837. GameObject soulObj = PoolManager.Instantiate(soulPrefab, transform.position);
  838. Vector3 dir = Vector3.up;
  839. Soul soul = soulObj.GetComponent<Soul>();
  840. soul.Burst(dir * soulStartSpeed);
  841. }
  842. }
  843. public override void Init()
  844. {
  845. base.Init();
  846. attackController = initAc;
  847. regeneration = initRegeneration;
  848. attributeStatus.resistances.dodge = initDodge;
  849. attributeStatus.resistances.armor = initArmor;
  850. }
  851. public override void Awake()
  852. {
  853. base.Awake();
  854. initAc = attackController;
  855. initRegeneration = regeneration;
  856. initDodge = attributeStatus.resistances.dodge;
  857. initArmor = attributeStatus.resistances.armor;
  858. bc = GetComponent<BuffController>();
  859. }
  860. protected override void OnDisable()
  861. {
  862. base.OnDisable();
  863. ownDamageScale = 0;
  864. }
  865. /// <summary>
  866. /// 在子类具体实现,用于处理每种士兵单独的逻辑
  867. /// </summary>
  868. public virtual void AfterInit()
  869. {
  870. for (int i = 0; i < attackController.attackMethod_march.Length; i++)
  871. {
  872. AttackInfo attackInfo = attackController.attackMethod_march[i].attackInfo;
  873. attackInfo.damage = (int)(attackController.attackMethod_summon[i].attackInfo.damage/5f);
  874. if (attackInfo.damage < 1) attackInfo.damage = 1;
  875. }
  876. }
  877. }
  878. [System.Flags]
  879. public enum DemoicTag
  880. {
  881. None = 0,
  882. Sky = 1 << 0,
  883. Ground = 1 << 1,
  884. Remote = 1 << 2,
  885. Melee = 1 << 3,
  886. }