738 lines
25 KiB
C#
738 lines
25 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using DG.Tweening;
|
||
using DragonLi.Core;
|
||
using DragonLi.Frame;
|
||
using UnityEngine;
|
||
|
||
public class MachineDragon : Enemy
|
||
{
|
||
public GameObject player;
|
||
public Transform[] enemyPos;
|
||
|
||
public GameObject bigXl; // 大招蓄力特效
|
||
public GameObject mzObj; // 瞄准特效
|
||
public GameObject damagableObj; // 受伤特效
|
||
|
||
public GameObject attack2Pre;
|
||
|
||
private bool _startAttack;
|
||
private bool _isAttacking;
|
||
private bool _isShow;
|
||
|
||
public int attackMode;
|
||
|
||
public override void Init()
|
||
{
|
||
base.Init();
|
||
|
||
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;
|
||
bloodSlider.gameObject.SetActive(false);
|
||
enemyState = EnemyState.Show;
|
||
attackMode = 0;
|
||
}
|
||
|
||
public override void StopAttack()
|
||
{
|
||
base.StopAttack();
|
||
attackMode = 0;
|
||
components[0].Stop();
|
||
components[1].Stop();
|
||
StopAllCoroutines();
|
||
_isAttacking = false;
|
||
}
|
||
|
||
public override void ChangeHp(float value, object info, Transform _sender)
|
||
{
|
||
base.ChangeHp(value, info, _sender);
|
||
damagableObj.SetActive(health / maxHealth <= 0.5f);
|
||
}
|
||
|
||
public override void Show()
|
||
{
|
||
base.Show();
|
||
isAttack = false;
|
||
isShield = true;
|
||
_isShow = true;
|
||
AnimatorComponent.SetFloat("speedf", 1);
|
||
GameInit.Ins.PlayAudio("2.24走动",transform,false);
|
||
float endValue = 10;
|
||
if (GameInit.Ins.gamePlace == GamePlace.HangZhouLongHuTianJie)
|
||
endValue = 20.5f;
|
||
if (GameInit.Ins.gamePlace == GamePlace.Yangzhou_Hanjiang_Tansuozhongxin)
|
||
endValue = -6.5f;
|
||
if(GameInit.Ins.gamePlace== GamePlace.Yangzhou_Hanjiang_TansuoZhongxin_wai||GameInit.Ins.gamePlace ==GamePlace.Zhejiang_Jinhua_KeJiGuan)
|
||
endValue = -1f;
|
||
if (GameInit.Ins.gamePlace == GamePlace.Guangzhou_Panyv_Zhanting)
|
||
endValue = 3f;
|
||
if (GameInit.Ins.gamePlace == GamePlace.Anhui_Wuhu_Guanwei)
|
||
endValue = 0f;
|
||
if (GameInit.Ins.gamePlace == GamePlace.ShanDong_Langfang_QingzhouTaihuacheng)
|
||
endValue = 6.3f;
|
||
if (GameInit.Ins.gamePlace == GamePlace.Company1Floor)
|
||
endValue = 7f;
|
||
if (GameInit.Ins.gamePlace == GamePlace.Yangzhou_Hanjiang_TansuoZhongxin_wai
|
||
|| GameInit.Ins.gamePlace == GamePlace.Zhejiang_Jinhua_KeJiGuan
|
||
|| GameInit.Ins.gamePlace == GamePlace.Anhui_Wuhu_Guanwei
|
||
|| GameInit.Ins.gamePlace == GamePlace.ShanDong_Langfang_QingzhouTaihuacheng
|
||
)
|
||
{
|
||
transform.DOMoveX(endValue, 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if (GameInit.Ins.gamePlace == GamePlace.Shandong_Jining_Shangchang)
|
||
{
|
||
transform.DOMove(new Vector3(12.12f, transform.position.y, 4.6f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if (GameInit.Ins.gamePlace == GamePlace.Jilin_Tonghua_Liuhe)
|
||
{
|
||
transform.DOMove(new Vector3(-5.33f,transform.position.y,3.1f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if (GameInit.Ins.gamePlace == GamePlace.Shandong_Jinan_Huaiyin_ShengfutongShangmao)
|
||
{
|
||
transform.DOMove(new Vector3(-0.05f,transform.position.y,4.6f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if (GameInit.Ins.gamePlace == GamePlace.Shandong_Jinan_Huaiyin_ShengfutongShangmao_wai)
|
||
{
|
||
transform.DOMove(new Vector3(-1.72f,transform.position.y,2.3f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if (GameInit.Ins.gamePlace == GamePlace.Hunan_Jishou_Qianzhou_Tianhong)
|
||
{
|
||
transform.DOMove(new Vector3(-1.14f,transform.position.y,0.98f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Shandong_Jining_Shangchang_nei)
|
||
{
|
||
transform.DOMove(new Vector3(-5.26f,transform.position.y,2.2f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Zhejiang_Shaoxing_Shengzhou_WuyueGuangchang)
|
||
{
|
||
transform.DOMove(new Vector3(-4.64f,transform.position.y,0.93f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Hubei_Xiangyang_Kejiguan)
|
||
{
|
||
transform.DOMove(new Vector3(-2.36f,0,9.09f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Henan_Xinzheng_Shuanghudadao_Longhujinyicheng)
|
||
{
|
||
transform.DOMove(new Vector3(-2.2f,0,3.92f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Nanjing_Qixia_Yaohuamen_Jindiguangchang)
|
||
{
|
||
transform.DOMove(new Vector3(7.12f,0,5.41f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Nanjing_Qixia_Yaohuamen_Jindiguangchang_nei)
|
||
{
|
||
transform.DOMove(new Vector3(0.06f,0,3.43f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Anshan_Suzhou_Yueshan_Guchengshangyejie)
|
||
{
|
||
transform.DOMove(new Vector3(-4.46f,0,4.07f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Gansu_Longnan_Shicheng_Dongsheng)
|
||
{
|
||
transform.DOMove(new Vector3(0f,0,17.9f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Shandong_Heze_Yuncheng_Gefuli)
|
||
{
|
||
transform.DOMove(new Vector3(-12.33f,transform.position.y,1.27f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Wulanhaote_Ouya_Shangchang)
|
||
{
|
||
transform.DOMove(new Vector3(-0.57f,0f,10f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Wulanhaote_Wanda_Shangchang)
|
||
{
|
||
transform.DOMove(new Vector3(-9.1f,0f,12.11f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Hunan_Hengyang_Zhuhui_Dongzhoudao)
|
||
{
|
||
transform.DOMove(new Vector3(8.73f,0f,4.19f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Hunan_Hengyang_Zhuhui_Dongzhoudao_nei
|
||
|| GameInit.Ins.gamePlace == GamePlace.Jiangsu_Xvzhou_Fengxian_Wuyueguangchang
|
||
|| GameInit.Ins.gamePlace == GamePlace.Jiangsu_Xvzhou_Guolou_Oulebao_2
|
||
|| GameInit.Ins.gamePlace == GamePlace.Chongqing_Yuzhong_Hongyadong_Xiakexing_shiwan
|
||
)
|
||
{
|
||
transform.DOMove(new Vector3(-0.16f,0f,5.51f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Yunnan_Lincang_Linxiang_Hengji)
|
||
{
|
||
transform.DOMove(new Vector3(-0.69f,0f,3.19f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Yunnan_Lincang_Linxiang_Hengji_Dixia)
|
||
{
|
||
transform.DOMove(new Vector3(-0.29f,0f,25.41f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Yunnan_Mile_Jinchen_Shidaiguangchang)
|
||
{
|
||
transform.DOMove(new Vector3(-0.58f,0f,5.52f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Guangxi_Guilin_Gongcheng_Shijixincheng)
|
||
{
|
||
transform.DOMove(new Vector3(-4.45f,0f,10.66f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Guangdong_Shenzhen_Guangming_Wanda)
|
||
{
|
||
transform.DOMove(new Vector3(-5.43f,0f,2.01f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Xinjiang_Yili_Yining_Wanrong)
|
||
{
|
||
transform.DOMove(new Vector3(-3.87f,0f,0.79f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Liaoning_AnShan_Lishan_Dayuecheng)
|
||
{
|
||
transform.DOMove(new Vector3(-5.05f,0f,2.15f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Hebei_Tangshan_Qianan_Tianyuangu)
|
||
{
|
||
transform.DOMove(new Vector3(0f,0f,8.5f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Zhejiang_Hangzhou_Linping_Yintaicheng)
|
||
{
|
||
transform.DOMove(new Vector3(1.86f,0f,4.41f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Gansu_Jinchang_Jinchuan_Shijiguangchang)
|
||
{
|
||
transform.DOMove(new Vector3(3.33f,0f,5.38f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Gansu_Jinchang_Jinchuan_Shijiguangchang_Shiwai)
|
||
{
|
||
transform.DOMove(new Vector3(-2.65f,0f,0.74f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Henan_Xinxiang_Wandaguangchang)
|
||
{
|
||
transform.DOMove(new Vector3(4.38f,0f,-16.91f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Henan_Xinxiang_Wandaguangchang_Shinei)
|
||
{
|
||
transform.DOMove(new Vector3(-0.098f,0f,2.89f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Zhejiang_Hangzhou_Linping_Yintaicheng_Shinei)
|
||
{
|
||
transform.DOMove(new Vector3(1.73f,0f,6.01f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Guangdong_Guangzhou_Yanghaiyan)
|
||
{
|
||
transform.DOMove(new Vector3(-1.14f,0f,-1.45f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Guangdong_Guangzhou_Yanghaiyan_Lihu)
|
||
{
|
||
transform.DOMove(new Vector3(-0.46f,0f,-1.4f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Nanjing_Pukou_Longhutianjie)
|
||
{
|
||
transform.DOMove(new Vector3(-3.49f,0f,2.27f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Jiangsu_Xvzhou_Guolou_Oulebao || GameInit.Ins.gamePlace == GamePlace.Jiangsu_Xvzhou_Suning_Guangchang_1)
|
||
{
|
||
transform.DOMove(new Vector3(-0.47f,0f,3.92f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Jiangsu_Xvzhou_Suning_Guangchang)
|
||
{
|
||
transform.DOMove(new Vector3(-5.37f,0f,1.94f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Shanxi_Baoji_Meixian_TianlongShangcheng)
|
||
{
|
||
transform.DOMove(new Vector3(4.96f,0f,3.21f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if(GameInit.Ins.gamePlace == GamePlace.Hunan_Changde_Lixian_WandaGuangchang)
|
||
{
|
||
transform.DOMove(new Vector3(-4.63f,0f,3.09f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if (GameInit.Ins.gamePlace == GamePlace.Jilin_Changchun_Beihu_WyueGuangchang)
|
||
{
|
||
transform.DOMove(new Vector3(-1.92f, 0f, 6f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if (GameInit.Ins.gamePlace == GamePlace.Chongqing_Yuzhong_Hongyadong_Xiakexing)
|
||
{
|
||
transform.DOMove(new Vector3(2.65f, 0f, 28.18f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if (GameInit.Ins.gamePlace == GamePlace.Anhui_Suzhou_Yueshan_Guchengshangyejie_2)
|
||
{
|
||
transform.DOMove(new Vector3(-3.93f, 0f, 1.52f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if (GameInit.Ins.gamePlace == GamePlace.Ningxia_Yinchuan_Jinfeng_XinhualianGuangchang)
|
||
{
|
||
transform.DOMove(new Vector3(5.88f, 0f, -1.08f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if (GameInit.Ins.gamePlace == GamePlace.Hunan_Zhuzhou_Wanda_Shennongcheng_Chaowanshe)
|
||
{
|
||
transform.DOMove(new Vector3(4.93f, 0f,0.89f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if (GameInit.Ins.gamePlace == GamePlace.Company1FloorShiwai)
|
||
{
|
||
transform.DOMove(new Vector3(-4.48f, 0f, 21.35f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if (GameInit.Ins.gamePlace == GamePlace.Anhui_Suzhou_Yueshan_Guchengshangyejie_Shinei)
|
||
{
|
||
transform.DOMove(new Vector3(0.33f, 0f, 4.08f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if (GameInit.Ins.gamePlace == GamePlace.Hebei_Hengshui_Taocheng_WandaGuangchang)
|
||
{
|
||
transform.DOMove(new Vector3(-5.5f, 0f, 3.34f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if (GameInit.Ins.gamePlace == GamePlace.Shandong_Jining_Shangchang_3)
|
||
{
|
||
transform.DOMove(new Vector3(-0.2f, 0f, 3.77f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if (GameInit.Ins.gamePlace == GamePlace.Zhejiang_Wenzhou_Cangnan_Yintaicheng)
|
||
{
|
||
transform.DOMove(new Vector3(-0.73f, 0f, 6.83f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if (GameInit.Ins.gamePlace == GamePlace.Shandong_Weifang_Linqu_WandaGuangchang)
|
||
{
|
||
transform.DOMove(new Vector3(-7.35f, 0f,-4.37f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
else if (GameInit.Ins.gamePlace == GamePlace.Jilin_Changchun_Chaoyang_OuyaMaichang)
|
||
{
|
||
transform.DOMove(new Vector3(1.63f, 0f,5.07f), 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
|
||
|
||
else
|
||
{
|
||
transform.DOMoveZ(endValue, 4).OnComplete(() =>
|
||
{
|
||
Both();
|
||
});
|
||
}
|
||
}
|
||
|
||
public void Both()
|
||
{
|
||
AnimatorComponent.SetFloat("speedf", 0);
|
||
AnimatorComponent.SetBool("isBoth", true);
|
||
GameInit.Ins.PlayAudio("2.29咆哮",transform,true);
|
||
GameInit.Ins.PlayAudio("1.12",GameInit.Ins.self.transform,true);
|
||
MonoSingleton<CoroutineTaskManager>.Instance.WaitSecondTodo(() =>
|
||
{
|
||
AnimatorComponent.SetBool("isBoth", false);
|
||
isAttack = true;
|
||
bloodSlider.gameObject.SetActive(true);
|
||
isShield = false;
|
||
MonoSingleton<CoroutineTaskManager>.Instance.WaitSecondTodo(() =>
|
||
{
|
||
_isShow = false;
|
||
}, 1f);
|
||
}, 1f);
|
||
}
|
||
|
||
public override void Attack()
|
||
{
|
||
base.Attack();
|
||
if (!_isAttacking)
|
||
{
|
||
attackMode = 1;
|
||
_isAttacking = true;
|
||
components[0].Play();
|
||
components[1].Play();
|
||
}
|
||
}
|
||
|
||
public override void OneAttackMode()
|
||
{
|
||
base.OneAttackMode();
|
||
if (!isDashing)
|
||
{
|
||
StartCoroutine(DashRoutine());
|
||
}
|
||
}
|
||
|
||
public float dashSpeed = 10f; // 冲刺速度
|
||
public float overshootDistance = 2f; // 超过玩家的距离
|
||
private float hitRadius = 2f; // 检测玩家的半径
|
||
private bool isDashing = false;
|
||
private bool hasHitPlayer = false;
|
||
|
||
// 修改后的 DashRoutine:先冲到 endPos,再返回 startPos
|
||
private IEnumerator DashRoutine()
|
||
{
|
||
isDashing = true;
|
||
attack2Pre.SetActive(true);
|
||
attackMode = 2;
|
||
|
||
// 记录起始位置
|
||
Vector3 startPos = transform.position;
|
||
Vector3 playerPos = player.transform.position.ReflectVectorXOZ();
|
||
Vector3 dashDirection = (playerPos - startPos).normalized;
|
||
Vector3 endPos = playerPos + dashDirection * overshootDistance;
|
||
GameInit.Ins.PlayAudio("2.30冲刺",transform,false);
|
||
// —— 第一阶段:从 startPos 冲向 endPos ——
|
||
hasHitPlayer = false;
|
||
while (Vector3.Distance(transform.position, endPos) > 0.1f)
|
||
{
|
||
transform.position = Vector3.MoveTowards(transform.position, endPos, dashSpeed * Time.deltaTime);
|
||
transform.forward = Vector3.Lerp(transform.forward, dashDirection, Time.deltaTime * 10f);
|
||
|
||
if (!hasHitPlayer)
|
||
{
|
||
// 这里用 attack2Pre 作为碰撞检测中心,也可以直接用 transform.position
|
||
Collider[] hits = Physics.OverlapSphere(attack2Pre.transform.position, hitRadius, LayerMask.GetMask("Player"));
|
||
foreach (var hit in hits)
|
||
{
|
||
if (hit.CompareTag("Player"))
|
||
{
|
||
Debug.LogError("第一阶段:撞到了玩家,造成了伤害");
|
||
hit.GetComponent<IDamagable>()?.ApplyDamage(3000, null, attack2Pre.transform);
|
||
hasHitPlayer = true;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
yield return null;
|
||
}
|
||
|
||
transform.position = endPos;
|
||
hasHitPlayer = false; // 重置,允许第二阶段再撞一次
|
||
|
||
// —— 第二阶段:从 endPos 冲回 startPos ——
|
||
Vector3 returnDirection = (startPos - endPos).normalized;
|
||
GameInit.Ins.PlayAudio("2.30冲刺",transform,true);
|
||
while (Vector3.Distance(transform.position, startPos) > 0.1f)
|
||
{
|
||
transform.position = Vector3.MoveTowards(transform.position, startPos, dashSpeed * Time.deltaTime);
|
||
transform.forward = Vector3.Lerp(transform.forward, returnDirection, Time.deltaTime * 10f);
|
||
|
||
if (!hasHitPlayer)
|
||
{
|
||
Collider[] hits = Physics.OverlapSphere(attack2Pre.transform.position, hitRadius, LayerMask.GetMask("Player"));
|
||
foreach (var hit in hits)
|
||
{
|
||
if (hit.CompareTag("Player"))
|
||
{
|
||
Debug.LogError("第二阶段:撞到了玩家,造成了伤害");
|
||
hit.GetComponent<IDamagable>()?.ApplyDamage(3000, null, attack2Pre.transform);
|
||
hasHitPlayer = true;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
yield return null;
|
||
}
|
||
|
||
// 确保精确回到起点
|
||
transform.position = startPos;
|
||
|
||
attackMode = 0;
|
||
isDashing = false;
|
||
userSillIng = false;
|
||
}
|
||
|
||
IEnumerator ToTarget( Transform target )
|
||
{
|
||
// 记录起始位置
|
||
Vector3 startPos = transform.position;
|
||
Vector3 playerPos = target.position.ReflectVectorXOZ();
|
||
Vector3 dashDirection = (playerPos - startPos).normalized;
|
||
Vector3 endPos = playerPos + dashDirection * overshootDistance;
|
||
while (Vector3.Distance(transform.position, endPos) > 0.1f)
|
||
{
|
||
transform.position = Vector3.MoveTowards(transform.position, endPos, dashSpeed * Time.deltaTime);
|
||
transform.forward = Vector3.Lerp(transform.forward, dashDirection, Time.deltaTime * 10f);
|
||
yield return null;
|
||
}
|
||
//到达目标点后执行的方法
|
||
}
|
||
|
||
public override void Show2()
|
||
{
|
||
base.Show2();
|
||
StopAllCoroutines();
|
||
attackMode = 3;
|
||
}
|
||
|
||
public override void TwoAttackMode()
|
||
{
|
||
base.TwoAttackMode();
|
||
ShowEnemy();
|
||
}
|
||
|
||
public void ShowEnemy()
|
||
{
|
||
if (GameInit.Ins.gamePlace == GamePlace.Jiangsu_Xvzhou_Guolou_Oulebao)
|
||
{
|
||
// 在江苏徐州鼓楼欧乐堡地点,生成在以固定点为中心的4×4矩形范围内
|
||
Vector3 centerPos = new Vector3(0f, 0f, 2.5f); // 从Show方法中提取的欧乐堡中心点坐标
|
||
float width = 4f; // 矩形宽度
|
||
float length = 4f; // 矩形长度
|
||
int enemyCount = enemyPos.Length;
|
||
|
||
for (int i = 0; i < enemyCount; i++)
|
||
{
|
||
// 在4×4矩形范围内随机生成位置
|
||
float randomX = Random.Range(-width / 2, width / 2);
|
||
float randomZ = Random.Range(-length / 2, length / 2);
|
||
Vector3 randomPos = centerPos + new Vector3(randomX, 0, randomZ);
|
||
|
||
GameManager.Ins.CreateCallEnemyEffect(randomPos);
|
||
}
|
||
|
||
MonoSingleton<CoroutineTaskManager>.Instance.WaitSecondTodo(() =>
|
||
{
|
||
for (int i = 0; i < enemyCount; i++)
|
||
{
|
||
float randomX = Random.Range(-width / 2, width / 2);
|
||
float randomZ = Random.Range(-length / 2, length / 2);
|
||
Vector3 randomPos = centerPos + new Vector3(randomX, 0, randomZ);
|
||
|
||
GameManager.Ins.CreateEnemy(6, randomPos, Vector3.zero, false);
|
||
}
|
||
}, 2f);
|
||
}
|
||
else
|
||
{
|
||
// 其他地点保持原有逻辑
|
||
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(6, curEnemyPos, Vector3.zero, false);
|
||
}
|
||
}, 2f);
|
||
}
|
||
}
|
||
|
||
public override void StartQteAttack()
|
||
{
|
||
components[^1].StatQteAttack();
|
||
attackMode = 4;
|
||
MonoSingleton<CoroutineTaskManager>.Instance.WaitSecondTodo(() =>
|
||
{
|
||
bigXl.SetActive(true);
|
||
mzObj.SetActive(true);
|
||
}, 2f);
|
||
}
|
||
|
||
public override void BossQteAttack()
|
||
{
|
||
base.BossQteAttack();
|
||
AnimatorComponent.SetBool("isCastEnd", true);
|
||
components[^1].QteAttack();
|
||
attackMode = 0;
|
||
bigXl.SetActive(false);
|
||
mzObj.SetActive(false);
|
||
}
|
||
|
||
public override void StopQteAttack()
|
||
{
|
||
base.StopQteAttack();
|
||
bigXl.SetActive(false);
|
||
mzObj.SetActive(false);
|
||
components[^1].StopQteAttack();
|
||
shieldObj.SetActive(false);
|
||
isShield = false;
|
||
attackMode = 0;
|
||
}
|
||
|
||
private float enemyTime=90f;
|
||
private float curEnemyTime;
|
||
public override void Update()
|
||
{
|
||
base.Update();
|
||
AnimatorComponent.SetInteger("attackMode", attackMode);
|
||
if (_isShow) return;
|
||
|
||
attack2Pre.SetActive(attackMode == 2);
|
||
if (isDashing) 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()<=5)
|
||
ShowEnemy();
|
||
curEnemyTime = enemyTime;
|
||
}
|
||
}
|
||
|
||
public override void Dead()
|
||
{
|
||
if(!isDead)
|
||
GameManager.Ins.CurLevelWin(transform.position.ReflectVectorXOZ());
|
||
base.Dead();
|
||
GameInit.Ins.PlayAudio("1.13",GameInit.Ins.self.transform,true);
|
||
}
|
||
}
|