Files
FutureMen/Assets/Scripts/Enemy/DropShip/DropShip.cs
2025-07-14 18:28:06 +08:00

359 lines
11 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using DragonLi.Core;
using DragonLi.Frame;
using UnityEngine;
public class DropShip : Enemy
{
public float oneAttackInterval;
public GameObject player;
public Transform[] enemyPos;
public Vector3 startPos;
public GameObject bigXl;//大招蓄力特效
public GameObject mzObj;//瞄准特效
public GameObject damagableObj;//受伤特效
public GameObject[] tailGas;//飞机尾气
private bool _isShow;
public override void Init()
{
base.Init();
_isShow = true;
bigXl.SetActive(false);
mzObj.SetActive(false);
damagableObj.SetActive(false);
player = GameManager.Ins.player;
foreach (var item in components)
{
item.Stop();
}
components[^1].boxCollider.enabled = false;
foreach (var item in tailGas)
{
item.SetActive(false);
}
bloodSlider.gameObject.SetActive(false);
enemyState = EnemyState.Show;
GameInit.Ins.PlayAudio("1.8",GameInit.Ins.self.transform,true);
}
public override void Attack()
{
base.Attack();
components[0].Play();
components[1].Play();
}
public override void StopAttack()
{
base.StopAttack();
foreach (var item in components)
{
item.Stop();
}
}
public override void OneAttackMode()
{
base.OneAttackMode();
components[0].Stop();
components[1].Stop();
if (components[2].isDead && components[3].isDead)
{
Fly();
}
else if(!components[2].isDead && components[3].isDead)
{
StartCoroutine(ShootOneAttackMode(2, Fly));
}
else if(components[2].isDead && !components[3].isDead)
{
StartCoroutine(ShootOneAttackMode(3, Fly));
}
else
{
StartCoroutine(ShootOneAttackMode(2));
StartCoroutine(ShootOneAttackMode(3, Fly));
}
}
public override void TwoAttackMode()
{
base.TwoAttackMode();
ShowEnemy();
}
public void ShowEnemy()
{
for (int i = 0; i < enemyPos.Length; i++)
{
Vector3 curEnemyPos=new Vector3(enemyPos[i].position.x,0,enemyPos[i].position.z);
GameManager.Ins.CreateCallEnemyEffect(curEnemyPos);
}
MonoSingleton<CoroutineTaskManager>.Instance.WaitSecondTodo(() =>
{
for (int i = 0; i < enemyPos.Length; i++)
{
Vector3 curEnemyPos=new Vector3(enemyPos[i].position.x,0,enemyPos[i].position.z);
GameManager.Ins.CreateEnemy(1,curEnemyPos,Vector3.zero,false);
}
},2f);
}
public override void ThreeAttackMode()
{
// base.ThreeAttackMode();
// components[^1].StopQteAttack();
}
private IEnumerator ShootOneAttackMode(int curIndex, Action cb = null)
{
// 一开始就把玩家位置记下来,避免中途玩家移动影响最终目标
Vector3 playerTarget = player.transform.position;
// 保持导弹发射高度(此处假设你希望在 y=0 平面)
playerTarget = new Vector3(playerTarget.x, 0f, playerTarget.z);
// 获取起点
Vector3 startPos = components[curIndex].showPos.position;
// 方向与总距离
Vector3 dir = (playerTarget - startPos).normalized;
float totalDist = Vector3.Distance(startPos, playerTarget);
// 要分几段发射用户想要“递进”n 次就填 n
int segmentCount = 4;
// 每段的长度
float step = totalDist / segmentCount;
for (int i = 1; i <= segmentCount; i++)
{
Vector3 targetPos;
if (i < segmentCount)
{
// 普通段落,按起点 + dir*i*step
targetPos = startPos + dir * (step * i);
}
else
{
// 最后一段,直接用预先算好的玩家位置
targetPos = playerTarget;
}
targetPos=new Vector3(targetPos.x, 0f, targetPos.z);
Debug.Log($"发射第 {i} 发导弹,目标点 = {targetPos}");
components[curIndex].EnemyShoot(targetPos);
GameInit.Ins.PlayAudio("2.3导弹发射",transform,false);
yield return new WaitForSeconds(oneAttackInterval);
}
// 全部发射完毕后回调
cb?.Invoke();
}
public override void Show()
{
base.Show();
isAttack = false;
isShield = true;
shieldObj.SetActive(true);
startPos = transform.position;
float endValue = 10;
if (GameInit.Ins.gamePlace == GamePlace.HangZhouLongHuTianJie)
endValue = 35f;
if(GameInit.Ins.gamePlace== GamePlace.Yangzhou_Hanjiang_TansuoZhongxin_wai)
endValue = 16f;
if(GameInit.Ins.gamePlace== GamePlace.Guangzhou_Panyv_Zhanting)
endValue = -7f;
if(GameInit.Ins.gamePlace== GamePlace.Anhui_Wuhu_Guanwei)
endValue = 13f;
if(GameInit.Ins.gamePlace== GamePlace.Zhejiang_Jinhua_KeJiGuan)
endValue = 17f;
if(GameInit.Ins.gamePlace== GamePlace.ShanDong_Langfang_QingzhouTaihuacheng)
endValue = 20f;
if(GameInit.Ins.gamePlace== GamePlace.Shandong_Jining_Shangchang_nei)
endValue = 7f;
if (GameInit.Ins.gamePlace == GamePlace.Company1Floor)
{
transform.DOMove(new Vector3(7f, transform.position.y, 12f), 4).OnComplete(() =>
{
isAttack = true;
foreach (var item in tailGas)
{
item.SetActive(true);
}
bloodSlider.gameObject.SetActive(true);
isShield = false;
shieldObj.SetActive(false);
_isShow = false;
});
}
if (GameInit.Ins.gamePlace == GamePlace.HangZhouLongHuTianJie||GameInit.Ins.gamePlace== GamePlace.Guangzhou_Panyv_Zhanting )
{
transform.DOMoveX(endValue, 4).OnComplete(() =>
{
isAttack = true;
foreach (var item in tailGas)
{
item.SetActive(true);
}
bloodSlider.gameObject.SetActive(true);
isShield = false;
shieldObj.SetActive(false);
_isShow = false;
});
}
if (GameInit.Ins.gamePlace == GamePlace.Hubei_Xiangyang_Kejiguan)
{
transform.DOMove(new Vector3(-8.12f,transform.position.y,-3.71f), 4).OnComplete(() =>
{
isAttack = true;
foreach (var item in tailGas)
{
item.SetActive(true);
}
bloodSlider.gameObject.SetActive(true);
isShield = false;
shieldObj.SetActive(false);
_isShow = false;
});
}
else
{
transform.DOMoveZ(endValue, 4).OnComplete(() =>
{
isAttack = true;
foreach (var item in tailGas)
{
item.SetActive(true);
}
bloodSlider.gameObject.SetActive(true);
isShield = false;
shieldObj.SetActive(false);
_isShow = false;
});
}
}
public override void Show2()
{
base.Show2();
isAttack = false;
//shieldObj.SetActive(true);
//isShield = true;
if (GameInit.Ins.gamePlace == GamePlace.HangZhouLongHuTianJie)
{
transform.DOMove(transform.position + new Vector3(-15, -2, 0), 3).OnComplete(() =>
{
isAttack = true;
});
}
else
{
transform.DOMove(transform.position + new Vector3(0, -2, 0), 3).OnComplete(() =>
{
isAttack = true;
});
}
}
public void Fly()
{
isShield = true;
AnimatorComponent.SetBool("fly",true);
GameInit.Ins.PlayAudio("2.11冲刺",transform,false);
foreach (var item in tailGas)
{
item.SetActive(false);
}
MonoSingleton<CoroutineTaskManager>.Instance.WaitSecondTodo(() =>
{
isShield=false;
StopFly();
},3f);
}
public void StopFly()
{
foreach (var item in tailGas)
{
item.SetActive(true);
}
AnimatorComponent.SetBool("fly",false);
userSillIng = false;
}
public override void Dead()
{
var pos=transform.position;
if (GameInit.Ins.gamePlace == GamePlace.ShanDong_Langfang_QingzhouTaihuacheng)
pos = new Vector3(16.6f, 0, 16.2f);
if(!isDead)
GameManager.Ins.CurLevelWin(pos);
base.Dead();
}
public override void StartQteAttack()
{
bigXl.SetActive(true);
mzObj.SetActive(true);
components[^1].StatQteAttack();
shieldObj.SetActive(false);
isShield = false;
}
public override void BossQteAttack()
{
base.BossQteAttack();
components[^1].QteAttack();
StopQteAttack();
}
public override void StopQteAttack()
{
base.StopQteAttack();
bigXl.SetActive(false);
mzObj.SetActive(false);
components[^1].StopQteAttack();
shieldObj.SetActive(false);
isShield = false;
}
public override void ChangeHp(float value, object info, Transform _sender)
{
base.ChangeHp(value, info, _sender);
damagableObj.SetActive(health/maxHealth<=0.5f);
}
private float enemyTime=45f;
private float curEnemyTime;
public override void Update()
{
base.Update();
if (_isShow) return;
// 平滑朝向玩家
Vector3 targetDir = GameManager.Ins.player.transform.position - transform.position;
targetDir.y = 0f;
if (targetDir != Vector3.zero)
{
Quaternion targetRotation = Quaternion.LookRotation(targetDir);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 2f);
}
curEnemyTime-=Time.deltaTime;
if (curEnemyTime <= 0)
{
if (GameManager.Ins.GetCurEnemyListCount() <= 8)
{
ShowEnemy();
}
curEnemyTime = enemyTime;
}
}
}