125 lines
5.2 KiB
C#
125 lines
5.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using BlueWater.Audios;
|
|
using BlueWater.Interfaces;
|
|
using BlueWater.Maps;
|
|
using BlueWater.Players;
|
|
using BlueWater.Utility;
|
|
using UnityEngine;
|
|
|
|
namespace BlueWater.Enemies.Bosses.SandMole.Skills
|
|
{
|
|
public class SpikeBarrage : BaseSkill
|
|
{
|
|
private SpikeBarrageData _spikeBarrageData;
|
|
private SpineController _spineController;
|
|
private AiMovement _aiMovement;
|
|
private Rigidbody _userRigidbody;
|
|
private CapsuleCollider _userCollider;
|
|
private BoxCollider _userHitBox;
|
|
private Collider _targetCollider;
|
|
private SandMoleMapController _sandMoleMapController;
|
|
private Transform _particleInstantiateLocation;
|
|
private Transform _centerSpawnTransform;
|
|
|
|
protected override void BasicSetting()
|
|
{
|
|
_spikeBarrageData = (SpikeBarrageData)SkillData;
|
|
_spineController = SkillUser.GetComponent<SpineController>();
|
|
_aiMovement = SkillUser.GetComponent<AiMovement>();
|
|
_userRigidbody = SkillUser.GetComponent<Rigidbody>();
|
|
_userCollider = SkillUser.GetComponent<CapsuleCollider>();
|
|
_userHitBox = SkillUser.GetComponentInChildren<BoxCollider>();
|
|
_targetCollider = SkillUser.GetComponent<ITarget>().Target;
|
|
_sandMoleMapController = MapManager.Instance.SandMoleMapController;
|
|
_particleInstantiateLocation = _sandMoleMapController.ParticleInstanceLocation;
|
|
_centerSpawnTransform = _sandMoleMapController.CenterSpawnTransform;
|
|
|
|
base.BasicSetting();
|
|
}
|
|
|
|
public override void ActivateSkill(params Action[] actions)
|
|
{
|
|
Utils.StartUniqueCoroutine(this, ref SkillCoroutineInstance, SkillCoroutine(actions));
|
|
}
|
|
|
|
private IEnumerator SkillCoroutine(params Action[] actions)
|
|
{
|
|
EnableSkill = false;
|
|
_spineController.SetSkin(SandMoleSkin.Idle.ToString());
|
|
var digInTrack = _spineController.PlayAnimation(SandMoleAnimation.DigIn.ToString(), false);
|
|
if (digInTrack == null || !SkillUser)
|
|
{
|
|
EndSkill(0, actions[0]);
|
|
yield break;
|
|
}
|
|
|
|
AudioManager.Instance.PlaySfx("SandMoleDigIn");
|
|
yield return new WaitUntil(() => digInTrack.IsComplete);
|
|
|
|
_userHitBox.enabled = false;
|
|
_aiMovement.Teleport(_centerSpawnTransform.position);
|
|
|
|
yield return new WaitForSeconds(1f);
|
|
|
|
_userHitBox.enabled = true;
|
|
var digOutTrack = _spineController.PlayAnimation(SandMoleAnimation.DigOut.ToString(), false);
|
|
if (digOutTrack == null || !SkillUser)
|
|
{
|
|
EndSkill(0, actions[0]);
|
|
yield break;
|
|
}
|
|
|
|
yield return new WaitUntil(() => digOutTrack.IsComplete);
|
|
|
|
var spinReady2Track = _spineController.PlayAnimation(SandMoleAnimation.SpinReady2.ToString(), false);
|
|
if (spinReady2Track == null)
|
|
{
|
|
EndSkill(0, actions[0]);
|
|
yield break;
|
|
}
|
|
|
|
yield return new WaitUntil(() => spinReady2Track.IsComplete);
|
|
|
|
_spineController.SetSkin(SandMoleSkin.Spin.ToString());
|
|
var spinTrack = _spineController.PlayAnimation(SandMoleAnimation.Spin.ToString(), true);
|
|
if (spinTrack == null || !SkillUser)
|
|
{
|
|
EndSkill(0, actions[0]);
|
|
yield break;
|
|
}
|
|
|
|
var startAngle = _spikeBarrageData.StartAngle;
|
|
var angleStep = _spikeBarrageData.AngleStep;
|
|
var spikeSpawnPosition = _userCollider.bounds.center;
|
|
spikeSpawnPosition.y = _targetCollider.bounds.center.y;
|
|
var spikeInterval = new WaitForSeconds(_spikeBarrageData.SpikeInterval);
|
|
for (var i = 0; i < _spikeBarrageData.SpikeCount; i++)
|
|
{
|
|
var currentAngle = startAngle + angleStep * i;
|
|
var rotation = Quaternion.Euler(0f, currentAngle, 0f);
|
|
var spike = Instantiate(_spikeBarrageData.SpikePrefab, spikeSpawnPosition, rotation,
|
|
_particleInstantiateLocation).GetComponent<ProjectileController>();
|
|
spike.Initialize(_spikeBarrageData.Damage, _spikeBarrageData.TargetLayer);
|
|
spike.SetPush(_spikeBarrageData.PushPower);
|
|
spike.SetSlowMoveSpeed(_spikeBarrageData.SlowDuration, _spikeBarrageData.MoveSpeedCoefficient);
|
|
spike.AddForce(spike.transform.forward * _spikeBarrageData.ProjectileSpeed, ForceMode.Impulse);
|
|
|
|
yield return spikeInterval;
|
|
}
|
|
|
|
EndSkill(SkillData.Cooldown, actions[0]);
|
|
}
|
|
|
|
private void EndSkill(float cooldown, Action action)
|
|
{
|
|
Utils.EndUniqueCoroutine(this, ref SkillCoroutineInstance);
|
|
|
|
_spineController.SetSkin(SandMoleSkin.Normal.ToString());
|
|
_spineController.PlayAnimation(SandMoleAnimation.Idle.ToString(), true);
|
|
action?.Invoke();
|
|
|
|
Utils.StartUniqueCoroutine(this, ref CooldownCoroutineInstance,Utils.CoolDownCoroutine(cooldown, EndCooldown));
|
|
}
|
|
}
|
|
} |