2023-07-18 00:57:28 -07:00
|
|
|
using Godot;
|
2023-07-19 00:17:25 -07:00
|
|
|
using System.Linq;
|
2023-07-18 00:57:28 -07:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace SupaLidlGame.State.NPC.Doc;
|
|
|
|
|
|
|
|
public partial class DocChooseAttackState : NPCState
|
|
|
|
{
|
|
|
|
[Export]
|
|
|
|
public DocShungiteDartState DartState { get; set; }
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
public DocShungiteSpikeState SpikeState { get; set; }
|
|
|
|
|
2023-07-19 00:17:25 -07:00
|
|
|
[Export]
|
|
|
|
public DocUnwantedFrequencyState UnwantedFrequencyState { get; set; }
|
|
|
|
|
2023-07-23 23:39:20 -07:00
|
|
|
[Export]
|
|
|
|
public DocLanceState LanceState { get; set; }
|
|
|
|
|
2023-07-18 00:57:28 -07:00
|
|
|
[Export]
|
|
|
|
public DocExitState ExitState { get; set; }
|
|
|
|
|
|
|
|
public Characters.Doc Doc => NPC as Characters.Doc;
|
|
|
|
|
2023-07-19 00:17:25 -07:00
|
|
|
private HashSet<NPCState> _possibleStates = new HashSet<NPCState>();
|
2023-07-18 00:57:28 -07:00
|
|
|
|
|
|
|
private int _consecutiveAttacks = 0;
|
|
|
|
|
|
|
|
public override void _Ready()
|
|
|
|
{
|
2023-07-19 00:17:25 -07:00
|
|
|
ResetStates();
|
2023-07-18 00:57:28 -07:00
|
|
|
base._Ready();
|
|
|
|
}
|
|
|
|
|
2023-07-19 00:17:25 -07:00
|
|
|
private void ResetStates()
|
|
|
|
{
|
2023-07-19 01:25:02 -07:00
|
|
|
_possibleStates.Add(DartState);
|
|
|
|
_possibleStates.Add(SpikeState);
|
2023-07-19 00:17:25 -07:00
|
|
|
_possibleStates.Add(UnwantedFrequencyState);
|
|
|
|
}
|
|
|
|
|
2023-07-18 00:57:28 -07:00
|
|
|
public override NPCState Enter(IState<NPCState> previous)
|
|
|
|
{
|
2023-07-23 23:39:20 -07:00
|
|
|
if (Doc.Intensity == 3)
|
|
|
|
{
|
|
|
|
return LanceState;
|
|
|
|
}
|
|
|
|
|
2023-07-18 00:57:28 -07:00
|
|
|
if (previous is not DocTelegraphState)
|
|
|
|
{
|
|
|
|
_consecutiveAttacks++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-07-22 20:23:48 -07:00
|
|
|
_consecutiveAttacks = 1;
|
2023-07-18 00:57:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_consecutiveAttacks > Doc.Intensity)
|
|
|
|
{
|
2023-07-22 20:23:48 -07:00
|
|
|
_consecutiveAttacks = 1;
|
|
|
|
ResetStates();
|
2023-07-18 00:57:28 -07:00
|
|
|
return ExitState;
|
|
|
|
}
|
|
|
|
|
2023-07-19 00:17:25 -07:00
|
|
|
if (_possibleStates.Count == 0)
|
|
|
|
{
|
|
|
|
ResetStates();
|
|
|
|
}
|
|
|
|
|
2023-07-18 00:57:28 -07:00
|
|
|
// choose random attack
|
|
|
|
var random = new System.Random();
|
2023-07-19 00:17:25 -07:00
|
|
|
int index = random.Next(_possibleStates.Count);
|
|
|
|
var state = _possibleStates.ElementAt(index);
|
|
|
|
_possibleStates.Remove(state);
|
|
|
|
return state;
|
2023-07-18 00:57:28 -07:00
|
|
|
}
|
|
|
|
}
|