CapersProject/Assets/02.Scripts/Skill/Enemy/Boss/SandMole/MultiThrowSpikes.cs

99 lines
4.3 KiB
C#

using System;
using System.Collections;
using BlueWater.Interfaces;
using BlueWater.Maps;
using BlueWater.Players;
using BlueWater.Utility;
using UnityEngine;
namespace BlueWater.Enemies.Bosses.SandMole.Skills
{
public class MultiThrowSpikes : BaseSkill
{
private MultiThrowSpikesData _multiThrowSpikesData;
private SpineController _spineController;
private Collider _targetCollider;
private ICurrentDirection _currentDirection;
private Transform _particleInstantiateLocation;
protected override void BasicSetting()
{
_multiThrowSpikesData = (MultiThrowSpikesData)SkillData;
_spineController = SkillUser.GetComponent<SpineController>();
_targetCollider = SkillUser.GetComponent<ITarget>().Target;
_currentDirection = SkillUser.GetComponent<ICurrentDirection>();
_particleInstantiateLocation = MapManager.Instance.SandMoleMapController.ParticleInstanceLocation;
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 shootingStartTrack = _spineController.PlayAnimation(SandMoleAnimation.ShootingStart.ToString(), false);
if (shootingStartTrack == null)
{
EndSkill(0, actions[0]);
yield break;
}
yield return new WaitUntil(() => shootingStartTrack.IsComplete);
IsUsingSkill = true;
var startPosition = SkillUser.transform.position;
var waitForSeconds = new WaitForSeconds(_multiThrowSpikesData.SpikeInterval);
for (var i = 0; i < _multiThrowSpikesData.SpikeCount; i++)
{
if (!SkillUser || !_targetCollider)
{
EndSkill(SkillData.Cooldown, actions[0]);
yield break;
}
_spineController.PlayAnimation(SandMoleAnimation.ShootingIdle.ToString(), false);
var targetCenterPosition = _targetCollider.bounds.center;
startPosition.y = targetCenterPosition.y;
var targetVector = targetCenterPosition - startPosition;
var targetDirection = targetVector.normalized;
_currentDirection.CurrentDirection = targetDirection;
var rotation = Quaternion.LookRotation(targetDirection);
var projectile = Instantiate(_multiThrowSpikesData.SpikePrefab, startPosition, rotation,
_particleInstantiateLocation).GetComponent<ProjectileController>();
projectile.Initialize(_multiThrowSpikesData.Damage, _multiThrowSpikesData.TargetLayer);
projectile.SetPush(_multiThrowSpikesData.PushPower);
projectile.SetSlowMoveSpeed(_multiThrowSpikesData.SlowDuration, _multiThrowSpikesData.MoveSpeedCoefficient);
projectile.AddForce(projectile.transform.forward * _multiThrowSpikesData.ProjectileSpeed, ForceMode.Impulse);
yield return waitForSeconds;
}
var shootingEndTrack = _spineController.PlayAnimation(SandMoleAnimation.ShootingEnd.ToString(), true);
if (shootingEndTrack == null || !SkillUser)
{
EndSkill(0, actions[0]);
yield break;
}
yield return new WaitUntil(() => shootingEndTrack.IsComplete);
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));
}
}
}