SupaLidlGame/State/NPC/Doc/DocShungiteSpikeState.cs

91 lines
2.4 KiB
C#
Raw Normal View History

2023-07-17 20:03:38 -07:00
using Godot;
using SupaLidlGame.Entities;
namespace SupaLidlGame.State.NPC.Doc;
public partial class DocShungiteSpikeState : DocShungiteDartState
2023-07-17 20:03:38 -07:00
{
protected int _currentAttacks = 0;
2023-07-17 20:03:38 -07:00
2023-07-18 00:57:28 -07:00
public override NPCState Enter(IState<NPCState> previous)
{
2023-07-23 23:39:20 -07:00
Doc.CanAttack = false;
2023-07-21 02:54:13 -07:00
if (this is not DocUnwantedFrequencyState)
{
2023-07-22 20:23:48 -07:00
Doc.TelegraphAnimation.Play("shungite_spike");
2023-07-21 02:54:13 -07:00
}
_currentAttacks = 0;
_currentAttackDuration = 1;
2023-07-24 00:43:21 -07:00
Doc.ShouldMove = false;
Doc.CanAttack = false;
2023-07-18 00:57:28 -07:00
return base.Enter(previous);
}
2023-07-21 02:54:13 -07:00
public override void Exit(IState<NPCState> nextState)
{
2023-07-24 00:43:21 -07:00
Doc.ShouldMove = true;
Doc.CanAttack = true;
2023-07-22 20:23:48 -07:00
//Doc.TelegraphAnimation.Stop();
//Doc.TelegraphAnimation.Stop();
2023-07-21 02:54:13 -07:00
}
2023-07-17 20:03:38 -07:00
protected override Projectile SpawnProjectile(
Vector2 position,
Vector2 direction)
{
2023-07-22 20:23:48 -07:00
Doc.TelegraphAnimation.Play("shungite_spike");
2023-07-18 00:57:28 -07:00
var projectile = base.SpawnProjectile(position, direction)
as ShungiteSpike;
projectile.GlobalRotation = 0;
projectile.Delay = 0;
2023-07-21 02:54:13 -07:00
projectile.Hitbox.Faction = Doc.Faction;
if (projectile.Hurtbox is not null)
{
projectile.Hurtbox.Faction = Doc.Faction;
}
2023-07-17 20:03:38 -07:00
return projectile;
}
protected override void Attack()
{
2023-07-31 01:12:47 -07:00
var player = NPC.FindBestTarget();
2023-07-17 20:03:38 -07:00
var playerPos = player.GlobalPosition;
var docPos = NPC.GlobalPosition;
var projectile = SpawnProjectile(docPos, Vector2.Zero) as ShungiteSpike;
var projectileSpeed = projectile.Speed = 96;
// predict to player's position
var targetPos = Utils.Physics.PredictNewPosition(
docPos,
projectileSpeed,
playerPos,
player.Velocity,
out float time);
projectile.Direction = projectile.GlobalPosition.DirectionTo(targetPos);
projectile.FreezeTime = time + 0.25; // freeze when it reaches target
_currentAttackDuration = 1;
_currentAttacks++;
2023-07-18 00:57:28 -07:00
}
public override NPCState Process(double delta)
{
2023-07-23 23:39:20 -07:00
if (Doc.StunTime > 0)
{
return null;
}
2023-07-24 21:29:14 -07:00
if ((_currentAttackDuration -= delta) <= 0 || Doc.Intensity > 2)
2023-07-18 00:57:28 -07:00
{
Attack();
2023-07-18 00:57:28 -07:00
}
if (_currentAttacks >= Doc.Intensity)
2023-07-18 00:57:28 -07:00
{
return ChooseAttackState;
2023-07-18 00:57:28 -07:00
}
return null;
2023-07-17 20:03:38 -07:00
}
}