Traveller/scripts/stateMachine/StateProcessor/ChaseStateProcessor.cs
Cold-Mint 61618c13a9
AI characters can set default weapons. The AI will try to attack and kill the enemy now. Fixed an issue where bubbles would not display properly.
AI角色支持设置默认武器。AI会尝试攻击并杀死敌人了。修复气泡不能正常显示的问题。
2024-07-10 23:23:04 +08:00

57 lines
1.9 KiB
C#

using ColdMint.scripts.character;
using ColdMint.scripts.debug;
using Godot;
namespace ColdMint.scripts.stateMachine.StateProcessor;
/// <summary>
/// <para>Chasing state processor</para>
/// <para>追击状态处理器</para>
/// </summary>
public class ChaseStateProcessor : StateProcessorTemplate
{
protected override void OnExecute(StateContext context, Node owner)
{
if (owner is not AiCharacter aiCharacter)
{
return;
}
//Get the first enemy to enter the reconnaissance range.
//获取第一次进入侦察范围的敌人。
var enemy = aiCharacter.GetFirstEnemyInScoutArea();
if (enemy == null)
{
//No more enemies. Return to previous status.
//没有敌人了,返回上一个状态。
aiCharacter.HidePlaint();
aiCharacter.HideQuery();
aiCharacter.SetTargetPosition(aiCharacter.GlobalPosition);
LogCat.Log("chase_no_enemy", label: LogCat.LogLabel.ChaseStateProcessor);
context.CurrentState = context.PreviousState;
}
else
{
var canAttackEnemy = aiCharacter.GetFirstEnemyInAttackArea();
if (canAttackEnemy == null)
{
aiCharacter.HidePlaint();
aiCharacter.DispladyQuery();
}
else
{
//TODO:转到攻击状态。
aiCharacter.HideQuery();
aiCharacter.DispladyPlaint();
aiCharacter.UseItem(enemy.GlobalPosition);
}
//Set the position of the enemy entering the range to the position we are going to.
//将进入范围的敌人位置设置为我们要前往的位置。
aiCharacter.SetTargetPosition(enemy.GlobalPosition);
aiCharacter.AimTheCurrentItemAtAPoint(enemy.GlobalPosition);
}
}
public override State State => State.Chase;
}