SupaLidlGame/State/NPC/Doc/DocChooseAttackState.cs

79 lines
1.7 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-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;
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()
{
2023-07-19 01:25:02 -07:00
_possibleStates.Add(DartState);
_possibleStates.Add(SpikeState);
_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;
}
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
}
}