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-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()
|
|
|
|
{
|
|
|
|
//_possibleStates.Add(DartState);
|
|
|
|
//_possibleStates.Add(SpikeState);
|
|
|
|
_possibleStates.Add(UnwantedFrequencyState);
|
|
|
|
}
|
|
|
|
|
2023-07-18 00:57:28 -07:00
|
|
|
public override NPCState Enter(IState<NPCState> previous)
|
|
|
|
{
|
|
|
|
if (previous is not DocTelegraphState)
|
|
|
|
{
|
|
|
|
_consecutiveAttacks++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_consecutiveAttacks = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_consecutiveAttacks > Doc.Intensity)
|
|
|
|
{
|
|
|
|
_consecutiveAttacks = 0;
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|