Files
valheim/Assets/_Valheim/Scripts/Enemys/FishGiant.cs
2025-07-04 14:16:14 +08:00

227 lines
6.0 KiB
C#

using System.Collections.Generic;
using DarkTonic.MasterAudio;
using DragonLi.Core;
using DragonLi.Frame;
using Mirror;
using UnityEngine;
using Valheim;
public enum BossState
{
Sleep = 0,
WakeUp = 1,
Run2Stage = 4,
Idle = 2,
Flee=4,
Ghost = 3
}
public class FishGiant : Enemy
{
#if UNITY_EDITOR
[DisplayOnly]
#endif
[SyncVar]
public BossState bossState = BossState.Sleep;
public Move2Point move2Point;
public Transform headRig;
public Transform leftHandRig;
public Transform rightHandRig;
public ParticleSystem attackEffectL;
public ParticleSystem attackEffectR;
public ParticleSystem jumpAttackEffect;
// public MeshCollider meshCollider;
public BoxCollider meshCollider;
public BoxCollider JumpSkillRange;
[Header("声音")]
[SoundGroup] public string laughSound;
[SoundGroup] public string footLSound;
[SoundGroup] public string footRSound;
[SoundGroup] public string attackLSound;
[SoundGroup] public string attackRSound;
[SoundGroup] public string[] attackShoutSound;
[SoundGroup] public string jumpShoutSound;
[SoundGroup] public string jumpImpactSound;
[SoundGroup] public string deadSound;
[SoundGroup] public string deadFallDownSound;
public void OnSpawn(int id, int curLvl, BossState bossState, Vector3 wakeUpPoint)
{
//this.id = id;
// areaId = -1;
// this.lvl = curLvl;
// this.type = EnemyType.FishGiant;
// move2Point.targetPoint = wakeUpPoint;
// EnemyData enemyData = GameManager.Ins.EnemyDic[id];
// // modelHeight = enemyInfo.modelHeight;
// // speed = enemyInfo.Speed;
// atk = enemyData.Atk*lvl;
// health = enemyData.Hp*lvl;
// OriginHealth = enemyData.Hp*lvl;
// //rate = enemyInfo.Rate;
// atkArea = 2.5f;
// NavAgent.enabled = false;
// behaviorTree.enabled = true;
// behaviorTree.RegisterEvent("Move2Point", Move2Point);
// GameManager.Ins.CreateEnemyUI(this);
}
public override void Die(object info, Transform _sender)
{
PlayAudioVecRpc(deadSound, transform);
GameManager.Ins.EnemyList.Remove(this);
NavAgent.enabled = false;
GameManager.Ins.IsWin = true;
GameManager.Ins.ChangeGameBGM(Bgm.Win);
for (int i = 0; i < MRNetworkManager.Ins.roomSlots.Count; i++)
{
StartCoroutine(GameManager.Ins.BallFlyToTree(MRNetworkManager.Ins.roomSlots[i], 10, 0.5F, GameInit.Ins.FakeTree.position));
}
}
#region
public void FootLeft()
{
MasterAudio.PlaySound3DAtVector3(footLSound, transform.position);
}
public void FootRight()
{
MasterAudio.PlaySound3DAtVector3(footRSound, transform.position);
}
/// <summary>
/// 醒来
/// </summary>
public void WakeUp()
{
bossState = BossState.WakeUp;
}
/// <summary>
/// 大笑
/// </summary>
public void Laugh()
{
MasterAudio.PlaySound3DAtVector3(laughSound, transform.position);
}
/// <summary>
/// 攻击前喊叫
/// </summary>
public void Shout()
{
MasterAudio.PlaySound3DAtVector3(attackShoutSound[1], headRig.position);
}
/// <summary>
/// 右抓击
/// </summary>
public void AttackStartR()
{
attackEffectR.Play();
MasterAudio.PlaySound3DAtVector3(attackRSound, rightHandRig.position);
}
/// <summary>
/// 左抓击
/// </summary>
public void AttackStartL()
{
attackEffectL.Play();
MasterAudio.PlaySound3DAtVector3(attackLSound, leftHandRig.position);
}
/// <summary>
/// 开始起跳
/// </summary>
public void JumpAttack()
{
jumpAttackEffect.Play();
MasterAudio.PlaySound3DFollowTransform(jumpShoutSound, headRig);
}
/// <summary>
/// 跳跃攻击
/// </summary>
public void JumpSkill()
{
MasterAudio.PlaySound3DAtVector3(jumpImpactSound, transform.position);
if (isServer)
{
Debug.Log("跳跃攻击");
Bounds bounds = JumpSkillRange.bounds;
CountOnce(bounds);
}
}
/// <summary>
/// 跌倒
/// </summary>
public void FallDown()
{
MasterAudio.PlaySound3DAtVector3(deadFallDownSound, transform.position);
}
/// <summary>
/// 造成一次攻击
/// </summary>
public override void AttackOnce()
{
if (isServer)
{
Bounds bounds = meshCollider.bounds;
CountOnce(bounds);
}
}
#endregion
/// <summary>
/// 根据攻击盒计算一次伤害
/// </summary>
public void CountOnce(Bounds bounds)
{
Dictionary<int, Pet> pets = GameManager.Ins.PetList;
foreach (Pet pet in pets.Values)
{
if (pet.state != PetState.Trained)
{
continue;
}
if (bounds.Contains(pet.transform.position))
{
Debug.Log("宠物" + pet.id + "在范围内");
IDamagable damagable = pet.GetComponent<IDamagable>();
damagable.ApplyDamage(atk, null, null);
}
}
}
public void Move2Point()
{
move2Point.cb = () =>
{
Debug.Log("抵达终点");
move2Point.enabled = false;
RigidbodyComponent.isKinematic = true;
NavAgent.enabled = true;
AnimatorComponent.SetBool("Bellow", true);
MonoSingleton<CoroutineTaskManager>.Instance.WaitSecondTodo(() =>
{
AnimatorComponent.SetBool("Bellow", false);
MonoSingleton<CoroutineTaskManager>.Instance.WaitSecondTodo(() =>
{
Debug.Log("开始战斗");
bossState = BossState.Idle;
}, 0.1f);
}, 0.8f);
};
move2Point.enabled = true;
bossState = BossState.Run2Stage;
}
}