Demonic.cs 31 KB

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