Enemy.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  1. using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical;
  2. using Sirenix.OdinInspector;
  3. using Spine;
  4. using Spine.Unity;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using TMPro;
  8. using Unity.VisualScripting;
  9. using UnityEngine;
  10. public enum EnemyTag
  11. {
  12. Common,
  13. Backline,
  14. Tank
  15. }
  16. public enum SearchState
  17. {
  18. NoTarget = 0, //搜索范围内没有目标
  19. InSearchScope = 1, //在搜索范围内发现目标,但不在攻击范围内
  20. InAttackScope = 2, //目标在攻击范围内
  21. }
  22. public class Enemy : MoveCharacter
  23. {
  24. [Space(30)]
  25. [Title("Enemy属性")]
  26. [LabelText("击杀提供的经验值")]
  27. public int exp;
  28. public EnemyTag tag;
  29. [LabelText("死亡特效")]
  30. public GameObject dieEffect;
  31. public string name;
  32. public int baseSortingOrder;
  33. int sortingOrder = 0;
  34. public bool isBack = false; //往反方向走
  35. public float jumpSpeed = 10;
  36. public float maxMoveSpeed, minMoveSpeed;
  37. public float runSpeed;
  38. [Header("击飞、屏幕反弹")]
  39. public bool isBeBlownUp; //被击飞
  40. public bool isBeReboundedX; //X方向被反弹
  41. public bool isBeReboundedY; //Y方向被反弹
  42. private bool hasBeReboundedX;
  43. private bool hasBeReboundedY;
  44. public float reboundXSpeed;
  45. public float reboundYSpeed;
  46. public int wallDamage;
  47. [Header("敌方英灵")]
  48. public Spirits.SpiritType type;
  49. [Header("敌方单位组件")]
  50. public SearchState searchState;
  51. [Header("攻击")]
  52. public float attackRatio;
  53. protected int curAttackID;
  54. public int len;
  55. protected float pastAttackTime;
  56. protected bool isConAttack; //连续攻击,不切idle动画
  57. [Header("掉落魂")]
  58. public int dropSoulMax = 3;
  59. public int dropSoulMin = 1;
  60. public int dropProbability = 100;
  61. public float dropSoulAngle = 60f;
  62. public override void Awake()
  63. {
  64. base.Awake();
  65. }
  66. protected virtual void Start()
  67. {
  68. len = attackController.attackMethod_march.Length;
  69. }
  70. protected virtual void OnEnable()
  71. {
  72. Init();
  73. }
  74. protected override void OnDisable()
  75. {
  76. base.OnDisable();
  77. EnemyCreater.instance.OnEnemyRecycle(this);
  78. }
  79. public override void Init()
  80. {
  81. base.Init();
  82. moveSpeed = Random.Range(minMoveSpeed, maxMoveSpeed);
  83. spinee.transform.rotation = Quaternion.identity;
  84. ChangeSearchState(SearchState.NoTarget);
  85. attributeStatus.curSpecialStates = SpecialState.Null;
  86. attributeStatus.attributeTime = 0;
  87. curAttackID = 0;
  88. attackController.curAttackMethod = attackController.attackMethod_march[0];
  89. }
  90. public override void FixedUpdate()
  91. {
  92. OnSearchState();
  93. OnState();
  94. }
  95. public override Vector3 GetMoveDir()
  96. {
  97. Vector3 moveDir = Vector3.zero;
  98. switch (searchState)
  99. {
  100. case SearchState.NoTarget:
  101. if (TowerMap.myTowers.Count == 0)
  102. {
  103. moveDir = Vector3.right;
  104. break;
  105. }
  106. float minDistance = Mathf.Infinity;
  107. int id = -1;
  108. for (int i = 0; i < TowerMap.myTowers.Count; i++)
  109. {
  110. Tower myTower = TowerMap.myTowers[i].GetComponent<Tower>();
  111. if (transform.position.y >
  112. myTower.transform.position.y + myTower.height)
  113. {
  114. continue;
  115. }
  116. float distance = Vector3.Distance(transform.position,
  117. TowerMap.myTowers[i].transform.position);
  118. if (distance < minDistance)
  119. {
  120. minDistance = distance;
  121. id = i;
  122. }
  123. }
  124. if (id == -1)
  125. {
  126. moveDir = Vector3.right;
  127. break;
  128. }
  129. if (bodyTrans.position.x > TowerMap.myTowers[id].transform.position.x)
  130. {
  131. moveDir = Vector3.left;
  132. }
  133. else
  134. {
  135. moveDir = Vector3.right;
  136. }
  137. break;
  138. case SearchState.InSearchScope:
  139. if (targetCharacter)
  140. {
  141. if (targetCharacter.transform.position.x - transform.position.x < -1)
  142. {
  143. moveDir = Vector3.left;
  144. }
  145. else if(targetCharacter.transform.position.x - transform.position.x >1)
  146. {
  147. moveDir = Vector3.right;
  148. }
  149. else
  150. {
  151. moveDir = bodyTrans.localScale.x > 0 ? Vector3.left : Vector3.right;
  152. }
  153. }
  154. else
  155. {
  156. moveDir = Vector3.zero;
  157. }
  158. break;
  159. case SearchState.InAttackScope:
  160. if (targetCharacter)
  161. {
  162. if (targetCharacter.transform.position.x - transform.position.x < 0)
  163. {
  164. moveDir = Vector3.left;
  165. }
  166. else
  167. {
  168. moveDir = Vector3.right;
  169. }
  170. }
  171. else
  172. {
  173. moveDir = Vector3.zero;
  174. }
  175. break;
  176. default:
  177. break;
  178. }
  179. if (!isBack)
  180. {
  181. return moveDir;
  182. }
  183. return -moveDir;
  184. }
  185. public virtual bool GetAttack()
  186. {
  187. if (searchState == SearchState.InAttackScope)
  188. {
  189. return true;
  190. }
  191. return false;
  192. }
  193. public bool GetJump()
  194. {
  195. return false;
  196. }
  197. public override void OnState()
  198. {
  199. base.OnState();
  200. if (state == CharacterState.FramePause)
  201. {
  202. return;
  203. }
  204. //hurtKeepTime -= Time.deltaTime;
  205. invincibleTime -= Time.deltaTime;
  206. pastAttackTime += Time.deltaTime;
  207. Vector3 leftDir = GetMoveDir();
  208. bool isAttack = GetAttack();
  209. Vector3 velocity = rb.velocity;
  210. Quaternion targetQt = Quaternion.Euler(Vector3.zero);
  211. switch (state)
  212. {
  213. case CharacterState.Idle:
  214. if (isAdjustHeight == 1)
  215. {
  216. ChangeState(CharacterState.Rise);
  217. break;
  218. }
  219. else if (isAttack)
  220. {
  221. if (pastAttackTime >= attackController.attackInterval)
  222. {
  223. Attack_march();
  224. }
  225. }
  226. else
  227. {
  228. if (!foot.TrigGround && !canFly)
  229. {
  230. if (rb.velocity.y > 0)
  231. {
  232. ChangeState(CharacterState.Rise);
  233. break;
  234. }
  235. else
  236. {
  237. ChangeState(CharacterState.Fall);
  238. break;
  239. }
  240. }
  241. if (leftDir.x > 0.3f || leftDir.x < -0.3f)
  242. {
  243. ChangeState(CharacterState.Run);
  244. break;
  245. }
  246. velocity.y = 0;
  247. if (!foot.haveGravity)
  248. {
  249. transform.position = new Vector3(transform.position.x, platformPosY, transform.position.z);
  250. targetQt = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, platformRotZ);
  251. }
  252. if (RotLerpTime < 1)
  253. {
  254. RotLerpTime += RotLerpSpeed * Time.deltaTime;
  255. transform.rotation = Quaternion.Lerp(transform.rotation, targetQt, RotLerpTime);
  256. }
  257. else
  258. {
  259. transform.rotation = targetQt;
  260. }
  261. rb.velocity = velocity * moveSpeedScale;
  262. }
  263. break;
  264. case CharacterState.Run:
  265. if (isAttack)
  266. {
  267. if (pastAttackTime >= attackController.attackInterval)
  268. {
  269. Attack_march();
  270. }
  271. else
  272. {
  273. ChangeState(CharacterState.Idle);
  274. }
  275. }
  276. else
  277. {
  278. if (!foot.TrigGround && !canFly)
  279. {
  280. if (rb.velocity.y > 0)
  281. {
  282. ChangeState(CharacterState.Rise);
  283. break;
  284. }
  285. else
  286. {
  287. ChangeState(CharacterState.Fall);
  288. break;
  289. }
  290. }
  291. if (leftDir.x < 0.3f && leftDir.x > -0.3f)
  292. {
  293. ChangeState(CharacterState.Idle);
  294. break;
  295. }
  296. if (leftDir.x > 0.3f)
  297. {
  298. velocity.x = moveSpeed;
  299. if (bodyTrans.localScale.x > 0)
  300. {
  301. Turn();
  302. }
  303. }
  304. else if (leftDir.x < -0.3f)
  305. {
  306. velocity.x = -moveSpeed;
  307. if (bodyTrans.localScale.x < 0)
  308. {
  309. Turn();
  310. }
  311. }
  312. velocity.y = 0;
  313. if (!foot.haveGravity)
  314. {
  315. transform.position = new Vector3(transform.position.x, platformPosY, transform.position.z);
  316. targetQt = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, platformRotZ);
  317. }
  318. if (RotLerpTime < 1)
  319. {
  320. RotLerpTime += RotLerpSpeed * Time.deltaTime;
  321. transform.rotation = Quaternion.Lerp(transform.rotation, targetQt, RotLerpTime);
  322. }
  323. else
  324. {
  325. transform.rotation = targetQt;
  326. }
  327. rb.velocity = velocity * moveSpeedScale;
  328. AdjustHeight();
  329. }
  330. break;
  331. case CharacterState.Rush:
  332. if (isAttack)
  333. {
  334. if (pastAttackTime >= attackController.attackInterval)
  335. {
  336. Attack_march();
  337. }
  338. else
  339. {
  340. ChangeState(CharacterState.Idle);
  341. }
  342. }
  343. else
  344. {
  345. if (!foot.TrigGround && !canFly)
  346. {
  347. if (rb.velocity.y > 0)
  348. {
  349. ChangeState(CharacterState.Rise);
  350. break;
  351. }
  352. else
  353. {
  354. ChangeState(CharacterState.Attack);
  355. break;
  356. }
  357. }
  358. if (leftDir.x < 0.3f && leftDir.x > -0.3f)
  359. {
  360. ChangeState(CharacterState.Idle);
  361. break;
  362. }
  363. if (leftDir.x > 0.3f)
  364. {
  365. //rb.velocity += Vector3.right * moveAcc * Time.deltaTime;
  366. rb.velocity = Vector3.right * runSpeed * moveSpeedScale;
  367. //if (rb.velocity.x > maxMoveSpeed)
  368. //{
  369. // rb.velocity = new Vector3(maxMoveSpeed, rb.velocity.y, rb.velocity.z);
  370. //}
  371. if (bodyTrans.localScale.x > 0)
  372. {
  373. Turn();
  374. }
  375. }
  376. else if (leftDir.x < -0.3f)
  377. {
  378. //rb.velocity -= Vector3.right * moveAcc * Time.deltaTime;
  379. rb.velocity = Vector3.left * runSpeed * moveSpeedScale;
  380. //if (rb.velocity.x < -maxMoveSpeed)
  381. //{
  382. // rb.velocity = new Vector3(-maxMoveSpeed, rb.velocity.y, rb.velocity.z);
  383. //}
  384. if (bodyTrans.localScale.x < 0)
  385. {
  386. Turn();
  387. }
  388. }
  389. //AdjustHeight();
  390. }
  391. break;
  392. case CharacterState.Rise:
  393. if (isAdjustHeight == 1)
  394. {
  395. AdjustHeight();
  396. if (!foot.haveGravity)
  397. {
  398. targetQt = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, platformRotZ);
  399. }
  400. if (RotLerpTime < 1)
  401. {
  402. RotLerpTime += RotLerpSpeed * Time.deltaTime;
  403. transform.rotation = Quaternion.Lerp(transform.rotation, targetQt, RotLerpTime);
  404. }
  405. else
  406. {
  407. transform.rotation = targetQt;
  408. }
  409. }
  410. else if (isAdjustHeight == 2)
  411. {
  412. ChangeState(CharacterState.Idle);
  413. isAdjustHeight = 0;
  414. }
  415. else
  416. {
  417. if (rb.velocity.y <= 0)
  418. {
  419. ChangeState(CharacterState.Fall);
  420. break;
  421. }
  422. rb.velocity += Vector3.up * extraRiseGravity * Time.deltaTime * moveSpeedScale;
  423. }
  424. break;
  425. case CharacterState.Fall:
  426. if (foot.TrigGround || canFly)
  427. {
  428. ChangeState(CharacterState.Idle);
  429. break;
  430. }
  431. velocity.y += extraFallGravity * Time.deltaTime;
  432. if (leftDir.x > 0.3f)
  433. {
  434. velocity.x = moveSpeed;
  435. if (bodyTrans.localScale.x > 0)
  436. {
  437. Turn();
  438. }
  439. }
  440. else if (leftDir.x < -0.3f)
  441. {
  442. velocity.x = -moveSpeed;
  443. if (bodyTrans.localScale.x < 0)
  444. {
  445. Turn();
  446. }
  447. }
  448. rb.velocity = velocity * moveSpeedScale;
  449. break;
  450. case CharacterState.Attack:
  451. attackController.JudgeTriggerOnOff();
  452. if (attackController.attackTime <= 0)
  453. {
  454. isAttack = GetAttack();
  455. if (isAttack)
  456. {
  457. isConAttack = true;
  458. }
  459. ChangeState(CharacterState.Idle);
  460. break;
  461. }
  462. if (!foot.haveGravity)
  463. {
  464. targetQt = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, platformRotZ);
  465. }
  466. if (RotLerpTime < 1)
  467. {
  468. RotLerpTime += RotLerpSpeed * Time.deltaTime;
  469. transform.rotation = Quaternion.Lerp(transform.rotation, targetQt, RotLerpTime);
  470. }
  471. else
  472. {
  473. transform.rotation = targetQt;
  474. }
  475. break;
  476. case CharacterState.Die:
  477. //if (killer != null && killer.GetComponent<Demonic>())
  478. //{
  479. // SoldierType st = killer.GetComponent<Demonic>().soldierType;
  480. // SoldierEXP.expInstance.AddEXP(st, (int)(exp * LevelSelect.EXPRatio + 0.5f));
  481. //}
  482. //if (dieEffect)
  483. //{
  484. // PoolManager.Instantiate(dieEffect, transform.position);
  485. //}
  486. //GameManager gameManager = GameManager.instance;
  487. //if (gameManager.gameType == GameType.GameEnd)
  488. //{
  489. // GameObject fx = PoolManager.Instantiate(gameManager.dropGoldFX);
  490. // fx.transform.position = transform.position;
  491. // GameObject injuryNum = PoolManager.Instantiate(gameManager.dropGoldText);
  492. // injuryNum.transform.position = new Vector3(
  493. // transform.position.x + injuryNumPos_march.x + Random.Range(-injuryNumRandom_march.x / 2f, injuryNumRandom_march.x / 2f),
  494. // transform.position.y + injuryNumPos_march.y + Random.Range(-injuryNumRandom_march.y / 2f, injuryNumRandom_march.y / 2f),
  495. // transform.position.z);
  496. // TextMeshProUGUI text = injuryNum.GetComponentInChildren<TextMeshProUGUI>();
  497. // text.text = $"+{gameManager.enemyGoldDrop}";
  498. //}
  499. gameObject.SetActive(false);
  500. //dieKeepTime -= Time.deltaTime;
  501. //if (dieKeepTime <= 0)
  502. //{
  503. // if (killer!=null && killer.GetComponent<Demonic>())
  504. // {
  505. // SoldierType st = killer.GetComponent<Demonic>().soldierType;
  506. // SoldierEXP.expInstance.AddEXP(st, (int)(exp * LevelSelect.EXPRatio + 0.5f));
  507. // }
  508. // if (dieEffect)
  509. // {
  510. // PoolManager.Instantiate(dieEffect, transform.position);
  511. // }
  512. // GameManager gameManager = GameManager.instance;
  513. // if (gameManager.gameType == GameType.GameEnd)
  514. // {
  515. // GameObject fx = PoolManager.Instantiate(gameManager.dropGoldFX);
  516. // fx.transform.position = transform.position;
  517. // GameObject injuryNum = PoolManager.Instantiate(gameManager.dropGoldText);
  518. // injuryNum.transform.position = new Vector3(
  519. // transform.position.x + injuryNumPos_march.x + Random.Range(-injuryNumRandom_march.x / 2f, injuryNumRandom_march.x / 2f),
  520. // transform.position.y + injuryNumPos_march.y + Random.Range(-injuryNumRandom_march.y / 2f, injuryNumRandom_march.y / 2f),
  521. // transform.position.z);
  522. // TextMeshProUGUI text = injuryNum.GetComponentInChildren<TextMeshProUGUI>();
  523. // text.text = $"+{gameManager.enemyGoldDrop}";
  524. // }
  525. // gameObject.SetActive(false);
  526. // break;
  527. //}
  528. break;
  529. case CharacterState.HitStun:
  530. hitFeedbackSystem.HitStunUpdate();
  531. break;
  532. case CharacterState.SpecialStatus_Float:
  533. attributeStatus.SpecialStateEffect(SpecialState.FloatState);
  534. break;
  535. case CharacterState.SpecialStatus_BlowUp:
  536. attributeStatus.SpecialStateEffect(SpecialState.BlownUp);
  537. break;
  538. case CharacterState.SpecialStatus_ShotDown:
  539. attributeStatus.SpecialStateEffect(SpecialState.ShotDown);
  540. break;
  541. case CharacterState.SpecialStatus_Weak:
  542. attributeStatus.SpecialStateEffect(SpecialState.Weak);
  543. break;
  544. default:
  545. break;
  546. }
  547. }
  548. public override void ChangeState(CharacterState newState)
  549. {
  550. if (state == newState || newState == CharacterState.FramePause)
  551. {
  552. state = newState;
  553. return;
  554. }
  555. //Debug.Log("从" + state + "转向" + newState);
  556. switch (state)
  557. {
  558. case CharacterState.Idle:
  559. //transform.rotation = Quaternion.Euler(Vector3.zero);
  560. break;
  561. case CharacterState.Run:
  562. rb.velocity = Vector3.zero;
  563. //transform.rotation = Quaternion.Euler(Vector3.zero);
  564. break;
  565. case CharacterState.Rush:
  566. rb.velocity = Vector3.zero;
  567. break;
  568. case CharacterState.Rise:
  569. if (!canFly)
  570. {
  571. bodyCollider.SetActive(true);
  572. }
  573. break;
  574. case CharacterState.Fall:
  575. rb.velocity = Vector3.zero;
  576. break;
  577. //case CharacterState.Hurt:
  578. // break;
  579. case CharacterState.Attack:
  580. attackController.isAttackTriggerOn = false;
  581. attackController.curAttackMethod.attackTrigger.gameObject.SetActive(false);
  582. break;
  583. case CharacterState.Die:
  584. isDie = false;
  585. break;
  586. case CharacterState.FramePause:
  587. state = hitFeedbackSystem.curCharacterState;
  588. ChangeState(newState);
  589. return;
  590. default:
  591. break;
  592. }
  593. CharacterState oldState = state;
  594. state = newState;
  595. switch (newState)
  596. {
  597. case CharacterState.Idle:
  598. if (!isConAttack || attackController.attackInterval > 0)
  599. {
  600. ani.Play(AnimatorHash.ANIMATOR_idle, 0, 0);
  601. }
  602. rb.velocity = Vector3.zero;
  603. break;
  604. case CharacterState.Run:
  605. ani.Play(AnimatorHash.ANIMATOR_walk, 0, 0);
  606. break;
  607. case CharacterState.Rush:
  608. ani.Play(AnimatorHash.ANIMATOR_rush, 0, 0);
  609. break;
  610. case CharacterState.Fall:
  611. ani.Play(AnimatorHash.ANIMATOR_fall, 0, 0);
  612. break;
  613. case CharacterState.Attack:
  614. break;
  615. case CharacterState.Rise:
  616. ani.Play(AnimatorHash.ANIMATOR_jump, 0, 0);
  617. nowCanFly = canFly;
  618. break;
  619. case CharacterState.Die:
  620. ani.Play(AnimatorHash.ANIMATOR_die, 0, 0);
  621. isDie = true;
  622. dieKeepTime = totalDieKeepTime;
  623. if(GameManager.instance.gameType != GameType.GameEnd)
  624. {
  625. DropSouls();
  626. }
  627. if (killer != null && killer.GetComponent<Demonic>())
  628. {
  629. SoldierType st = killer.GetComponent<Demonic>().soldierType;
  630. SoldierEXP.expInstance.AddEXP(st, (int)(exp * LevelSelect.EXPRatio + 0.5f));
  631. }
  632. if (dieEffect)
  633. {
  634. PoolManager.Instantiate(dieEffect, transform.position);
  635. }
  636. GameManager gameManager = GameManager.instance;
  637. if (gameManager.gameType == GameType.GameEnd)
  638. {
  639. GameObject fx = PoolManager.Instantiate(gameManager.dropGoldFX);
  640. fx.transform.position = transform.position;
  641. GameObject injuryNum = PoolManager.Instantiate(gameManager.dropGoldText);
  642. injuryNum.transform.position = new Vector3(
  643. transform.position.x + injuryNumPos_march.x + Random.Range(-injuryNumRandom_march.x / 2f, injuryNumRandom_march.x / 2f),
  644. transform.position.y + injuryNumPos_march.y + Random.Range(-injuryNumRandom_march.y / 2f, injuryNumRandom_march.y / 2f),
  645. transform.position.z);
  646. TextMeshProUGUI text = injuryNum.GetComponentInChildren<TextMeshProUGUI>();
  647. text.text = $"+{gameManager.enemyGoldDrop}";
  648. }
  649. if (GameManager.instance.isRockEnable)
  650. {
  651. int randomInt = Random.Range(0, 100);
  652. if (randomInt < GameManager.instance.rockProbability + GameManager.instance.myTreasuresTag[3] * GameManager.instance.rockLabelEffectRatio)
  653. {
  654. StoneStatue stoneStatue = PoolManager.Instantiate(Resources.Load<GameObject>("Prefab/StoneStatue"), transform.position).GetComponentInChildren<StoneStatue>();
  655. GameManager.instance.player.rebornSkills.Add(stoneStatue);
  656. if(tag == EnemyTag.Tank)
  657. {
  658. stoneStatue.bulletCount = 6;
  659. stoneStatue.transform.parent.localScale = Vector3.one * 1.5f;
  660. }
  661. else
  662. {
  663. stoneStatue.bulletCount = 3;
  664. stoneStatue.transform.parent.localScale = Vector3.one * 0.8f;
  665. }
  666. }
  667. }
  668. //if (GameManager.instance.isWoodEnable)
  669. //{
  670. // int randomInt = Random.Range(0, 100);
  671. // if (randomInt < GameManager.instance.woodProbability + GameManager.instance.myTreasuresTag[7] * GameManager.instance.woodLabelEffectRatio)
  672. // {
  673. // PoolManager.Instantiate(Resources.Load<GameObject>("Prefab/SoulFlower"), transform.position).GetComponent<SoulFlower>().Init(false);
  674. // }
  675. //}
  676. break;
  677. default:
  678. break;
  679. }
  680. }
  681. public void DropSouls()
  682. {
  683. int dropSoulNum = Random.Range(dropSoulMin, dropSoulMax + 1);
  684. if (dropSoulNum > 1)
  685. {
  686. for (int i = 0; i < dropSoulNum; i++)
  687. {
  688. float angleInterval = dropSoulAngle / (float)(dropSoulNum - 1);
  689. float angle = 90 + ((float)i - (float)(dropSoulNum - 1) / 2) * angleInterval;
  690. angle = angle / 180 * Mathf.PI;
  691. GameObject soulObj = PoolManager.Instantiate(soulPrefab, transform.position);
  692. Vector3 dir = new Vector3(Mathf.Cos(angle), Mathf.Sin(angle), 0);
  693. Soul soul = soulObj.GetComponent<Soul>();
  694. soul.Burst(dir * soulStartSpeed);
  695. soul.type = type;
  696. }
  697. }
  698. else
  699. {
  700. int randomInt = Random.Range(0, 100);
  701. if (randomInt >= dropProbability)
  702. {
  703. return;
  704. }
  705. GameObject soulObj = PoolManager.Instantiate(soulPrefab, transform.position);
  706. Vector3 dir = Vector3.up;
  707. Soul soul = soulObj.GetComponent<Soul>();
  708. soul.Burst(dir * soulStartSpeed);
  709. soul.type = type;
  710. }
  711. }
  712. public void Jump()
  713. {
  714. SetUpSpeed(jumpSpeed);
  715. ani.Play(AnimatorHash.ANIMATOR_jump, 0, 0);
  716. }
  717. public void SetUpSpeed(float speed)
  718. {
  719. ChangeState(CharacterState.Rise);
  720. Vector3 velocity = rb.velocity;
  721. Vector3 leftDir = GetMoveDir();
  722. if (leftDir.x > 0.3f)
  723. {
  724. if (bodyTrans.localScale.x > 0)
  725. {
  726. Turn();
  727. }
  728. }
  729. else if (leftDir.x < -0.3f)
  730. {
  731. if (bodyTrans.localScale.x < 0)
  732. {
  733. Turn();
  734. }
  735. }
  736. velocity.y = speed;
  737. rb.velocity = velocity * moveSpeedScale;
  738. //animalAni.SetInteger("state", (int)PlayerState.Rise);
  739. }
  740. public virtual void ChangeSearchState(SearchState newState)
  741. {
  742. switch (searchState)
  743. {
  744. case SearchState.NoTarget:
  745. break;
  746. case SearchState.InSearchScope:
  747. break;
  748. case SearchState.InAttackScope:
  749. break;
  750. default:
  751. break;
  752. }
  753. searchState = newState;
  754. switch (searchState)
  755. {
  756. case SearchState.NoTarget:
  757. Character character0 = PlayersInput.instance[0];
  758. if (character0 && character0.attackController.beTargetCharacter.Exists(t => t == this))
  759. {
  760. character0.attackController.beTargetCharacter.Remove(this);
  761. }
  762. targetCharacter = null;
  763. break;
  764. case SearchState.InSearchScope:
  765. break;
  766. case SearchState.InAttackScope:
  767. break;
  768. default:
  769. break;
  770. }
  771. }
  772. public bool SearchTarget()
  773. {
  774. targetCharacter = searchTrigger.GetMinDisTarget(attackController.targetTypes, attackController.curAttackMethod.canHitFly, attackController.curAttackMethod.searchMode);
  775. if (targetCharacter != null)
  776. {
  777. Character character0 = PlayersInput.instance[0];
  778. Character character1 = PlayersInput.instance[1];
  779. if (targetCharacter == character0
  780. && !character0.attackController.beTargetCharacter.Exists(t => t == this))
  781. {
  782. character0.attackController.beTargetCharacter.Add(this);
  783. }
  784. if (targetCharacter == character1
  785. && !character1.attackController.beTargetCharacter.Exists(t => t == this))
  786. {
  787. character1.attackController.beTargetCharacter.Add(this);
  788. }
  789. return true;
  790. }
  791. else
  792. {
  793. return false;
  794. }
  795. }
  796. public virtual void OnSearchState()
  797. {
  798. switch (searchState)
  799. {
  800. case SearchState.NoTarget:
  801. if (SearchTarget())
  802. {
  803. ChangeSearchState(SearchState.InSearchScope);
  804. break;
  805. }
  806. //向玩家基地移动
  807. break;
  808. case SearchState.InSearchScope:
  809. if (!SearchTarget())
  810. {
  811. targetCharacter = null;
  812. ChangeSearchState(SearchState.NoTarget);
  813. break;
  814. }
  815. attackDis = attackController.curAttackMethod.attackDistance + targetCharacter.beHitDistance;
  816. if (targetCharacter != null && Mathf.Abs(targetCharacter.transform.position.x - transform.position.x) <= attackDis)
  817. {
  818. ChangeSearchState(SearchState.InAttackScope);
  819. break;
  820. }
  821. break;
  822. case SearchState.InAttackScope:
  823. if (targetCharacter != null)
  824. {
  825. //判断是否在射程夹角内
  826. AttackController.AttackMethod am = attackController.curAttackMethod;
  827. if (am.attackType == AttackController.AttackType.Shoot
  828. && attackController.curAttackMethod.attackInfo.attackMethod_Type == AttackMethod_Type.Attack_March)
  829. {
  830. Vector3 dir = targetCharacter.beSearchTrigger.transform.position - transform.position;
  831. float angle = Vector3.Angle(dir, Vector3.left * bodyTrans.localScale.x);
  832. if ((dir.y > 0 && angle > am.maxUpAngle) || (dir.y < 0 && angle > am.maxDownAngle))
  833. {
  834. ChangeSearchState(SearchState.NoTarget);
  835. }
  836. }
  837. attackDis = attackController.curAttackMethod.attackDistance + targetCharacter.beHitDistance;
  838. if (!targetCharacter.gameObject.activeInHierarchy || targetCharacter.isDie
  839. || Mathf.Abs(targetCharacter.transform.position.x - transform.position.x) > attackDis)
  840. {
  841. ChangeSearchState(SearchState.NoTarget);
  842. }
  843. }
  844. else
  845. {
  846. ChangeSearchState(SearchState.NoTarget);
  847. }
  848. break;
  849. default:
  850. break;
  851. }
  852. }
  853. public void Attack_summon()
  854. {
  855. CheckTurn(GetMoveDir().x);
  856. attackController.Attack_summon();
  857. attackTarget = targetCharacter;
  858. }
  859. public virtual void Attack_march()
  860. {
  861. CheckTurn(GetMoveDir().x);
  862. attackController.Attack_march();
  863. if (curAttackID + 1 < len)
  864. {
  865. curAttackID += 1;
  866. }
  867. else if (attackController.curAttackMethod.attackInfo.attackMethod_Type == AttackMethod_Type.Attack_Summon)
  868. {
  869. curAttackID = 1;
  870. }
  871. else
  872. {
  873. curAttackID = 0;
  874. }
  875. attackTarget = targetCharacter;
  876. pastAttackTime = 0;
  877. }
  878. public void ChosePlayer()
  879. {
  880. float distance0 = Mathf.Infinity;
  881. float distance1 = Mathf.Infinity;
  882. PlayerController player0 = PlayersInput.instance[0];
  883. PlayerController player1 = PlayersInput.instance[1];
  884. if (player0 != null && !player0.isRevive)
  885. {
  886. distance0 = Mathf.Abs(player0.transform.position.x
  887. - transform.position.x);
  888. }
  889. if (player1 != null && !player1.isRevive)
  890. {
  891. distance1 = Mathf.Abs(player1.transform.position.x
  892. - transform.position.x);
  893. }
  894. if (distance0 == Mathf.Infinity && distance1 == Mathf.Infinity)
  895. {
  896. targetCharacter = null;
  897. return;
  898. }
  899. if (distance0 <= distance1)
  900. {
  901. targetCharacter = player0;
  902. if (!player0.attackController.beTargetCharacter.Exists(t => t == this))
  903. {
  904. player0.attackController.beTargetCharacter.Add(this);
  905. }
  906. }
  907. else
  908. {
  909. targetCharacter = player1;
  910. if (!player1.attackController.beTargetCharacter.Exists(t => t == this))
  911. {
  912. player1.attackController.beTargetCharacter.Add(this);
  913. }
  914. }
  915. }
  916. public override void BeHit(int damage)
  917. {
  918. base.BeHit(damage);
  919. }
  920. public override void BeHit(AttackController.AttackMethod attackMethod, Character attackFrom, int damage = -1)
  921. {
  922. base.BeHit(attackMethod, attackFrom, damage);
  923. }
  924. }