SupaLidlGame/State/NPC/Doc/DocChooseAttackState.cs

70 lines
1.6 KiB
C#
Raw Normal View History

2023-07-18 00:57:28 -07:00
using Godot;
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; }
[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;
private HashSet<NPCState> _possibleStates = new HashSet<NPCState>();
2023-07-18 00:57:28 -07:00
private int _consecutiveAttacks = 0;
public override void _Ready()
{
ResetStates();
2023-07-18 00:57:28 -07:00
base._Ready();
}
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;
}
if (_possibleStates.Count == 0)
{
ResetStates();
}
2023-07-18 00:57:28 -07:00
// choose random attack
var random = new System.Random();
int index = random.Next(_possibleStates.Count);
var state = _possibleStates.ElementAt(index);
_possibleStates.Remove(state);
return state;
2023-07-18 00:57:28 -07:00
}
}