2023-07-17 20:18:42 -07:00
|
|
|
using Godot;
|
|
|
|
using GodotUtilities;
|
|
|
|
using SupaLidlGame.Entities;
|
|
|
|
|
|
|
|
namespace SupaLidlGame.State.NPC.Doc;
|
|
|
|
|
|
|
|
public partial class DocShungiteDartState : DocAttackState
|
|
|
|
{
|
|
|
|
[Export]
|
|
|
|
public override double Duration { get; set; }
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
public override double AttackDuration { get; set; }
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
public override PackedScene Projectile { get; set; }
|
|
|
|
|
|
|
|
[Export]
|
2023-07-18 00:57:28 -07:00
|
|
|
public override DocChooseAttackState ChooseAttackState { get; set; }
|
2023-07-17 20:18:42 -07:00
|
|
|
|
2023-07-18 00:57:28 -07:00
|
|
|
[Export]
|
|
|
|
public Characters.Doc Doc { get; set; }
|
2023-07-17 20:18:42 -07:00
|
|
|
|
2023-07-24 00:43:21 -07:00
|
|
|
public override NPCState Enter(IState<NPCState> nextState)
|
2023-07-17 20:18:42 -07:00
|
|
|
{
|
2023-07-24 00:43:21 -07:00
|
|
|
Doc.CanAttack = true;
|
|
|
|
Doc.ShouldMove = true;
|
|
|
|
return base.Enter(nextState);
|
2023-07-17 20:18:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual Projectile SpawnProjectile(
|
|
|
|
Vector2 position,
|
|
|
|
Vector2 direction)
|
|
|
|
{
|
|
|
|
var projectile = _map.SpawnEntity<Projectile>(Projectile);
|
|
|
|
projectile.Hitbox.Faction = NPC.Faction;
|
|
|
|
projectile.GlobalPosition = position;
|
|
|
|
projectile.Direction = direction;
|
|
|
|
projectile.GlobalRotation = direction.Angle();
|
2023-07-18 00:57:28 -07:00
|
|
|
projectile.Delay = 1.0 / Doc.Intensity;
|
2023-07-17 20:18:42 -07:00
|
|
|
return projectile;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Attack()
|
|
|
|
{
|
|
|
|
var player = _world.CurrentPlayer;
|
|
|
|
var playerPos = player.GlobalPosition;
|
2023-07-19 00:17:25 -07:00
|
|
|
// global position is (from npc to player) * 2 = (2 * npc) - player
|
|
|
|
//projectile.GlobalPosition = 2 * NPC.GlobalPosition - playerPos;
|
2023-07-17 20:18:42 -07:00
|
|
|
Vector2 position1 = 2 * NPC.GlobalPosition - playerPos;
|
|
|
|
Vector2 position2 = 2 * playerPos - NPC.GlobalPosition;
|
|
|
|
Vector2 direction1 = position1.DirectionTo(playerPos);
|
|
|
|
Vector2 direction2 = -direction1;
|
|
|
|
SpawnProjectile(position1, direction1);
|
|
|
|
SpawnProjectile(position2, direction2);
|
2023-07-18 00:57:28 -07:00
|
|
|
_currentAttackDuration = AttackDuration / Doc.Intensity;
|
2023-07-17 20:18:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public override NPCState Process(double delta)
|
|
|
|
{
|
2023-07-23 23:39:20 -07:00
|
|
|
if (Doc.StunTime > 0)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-07-17 20:18:42 -07:00
|
|
|
if ((_currentDuration -= delta) <= 0)
|
|
|
|
{
|
2023-07-18 00:57:28 -07:00
|
|
|
return ChooseAttackState;
|
2023-07-17 20:18:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((_currentAttackDuration -= delta) <= 0)
|
|
|
|
{
|
|
|
|
Attack();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|