2023-07-13 23:46:58 -07:00
|
|
|
using Godot;
|
2023-08-03 16:17:34 -07:00
|
|
|
using SupaLidlGame.Extensions;
|
2023-07-13 23:46:58 -07:00
|
|
|
|
|
|
|
namespace SupaLidlGame.State.NPC.Doc;
|
|
|
|
|
|
|
|
public partial class DocTelegraphState : NPCState
|
|
|
|
{
|
|
|
|
[Export]
|
|
|
|
public AnimationPlayer TelegraphAnimationPlayer { get; set; }
|
|
|
|
|
|
|
|
[Export]
|
2023-07-18 00:57:28 -07:00
|
|
|
public DocChooseAttackState AttackState { get; set; }
|
2023-07-13 23:46:58 -07:00
|
|
|
|
|
|
|
[Export]
|
|
|
|
public double Duration { get; set; } = 1;
|
|
|
|
|
|
|
|
private double _currentDuration = 1;
|
|
|
|
|
|
|
|
public override NPCState Enter(IState<NPCState> previousState)
|
|
|
|
{
|
2023-07-23 23:39:20 -07:00
|
|
|
// TODO: clean this up
|
|
|
|
if (!(NPC as Characters.Doc).IsActive)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-07-13 23:46:58 -07:00
|
|
|
_currentDuration = Duration;
|
|
|
|
TelegraphAnimationPlayer.Play("enter_in");
|
2023-07-24 21:29:14 -07:00
|
|
|
NPC.ShouldMove = true;
|
2023-07-23 23:39:20 -07:00
|
|
|
|
2023-08-03 16:17:34 -07:00
|
|
|
var player = this.GetWorld().CurrentPlayer;
|
2023-07-23 23:39:20 -07:00
|
|
|
Vector2 randVec;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
float randX = GD.RandRange(-112, 112);
|
|
|
|
float randY = GD.RandRange(-112, 112);
|
|
|
|
randVec = new Vector2(randX, randY);
|
|
|
|
}
|
2023-07-24 21:29:14 -07:00
|
|
|
while (randVec.DistanceSquaredTo(player.GlobalPosition) < 9216);
|
|
|
|
// can not teleport within 96 units of the player
|
2023-07-23 23:39:20 -07:00
|
|
|
|
|
|
|
NPC.GlobalPosition = randVec;
|
2023-07-13 23:46:58 -07:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Exit(IState<NPCState> nextState)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public override NPCState Process(double delta)
|
|
|
|
{
|
|
|
|
if ((_currentDuration -= delta) <= 0)
|
|
|
|
{
|
|
|
|
return AttackState;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|