Give the enemy pause after the attack.
使敌人攻击后有所停顿。
This commit is contained in:
parent
35dc2ee1b9
commit
9416993849
|
@ -24,10 +24,10 @@ animations = [{
|
||||||
}]
|
}]
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_c61vr"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_c61vr"]
|
||||||
radius = 153.0
|
radius = 220.0
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_fowd5"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_fowd5"]
|
||||||
radius = 172.29
|
radius = 300.0
|
||||||
|
|
||||||
[node name="BlackenedAboriginalWarrior" type="CharacterBody2D"]
|
[node name="BlackenedAboriginalWarrior" type="CharacterBody2D"]
|
||||||
collision_layer = 64
|
collision_layer = 64
|
||||||
|
|
|
@ -14,11 +14,8 @@ public class PatrolStateMachine : StateMachineTemplate
|
||||||
{
|
{
|
||||||
Points =
|
Points =
|
||||||
[
|
[
|
||||||
new Godot.Vector2(100, 0),
|
new Godot.Vector2(Config.CellSize * 3, 0),
|
||||||
new Godot.Vector2(-100, 0),
|
new Godot.Vector2(-Config.CellSize * 3, 0),
|
||||||
new Godot.Vector2(50, 0),
|
|
||||||
new Godot.Vector2(-50, 0),
|
|
||||||
new Godot.Vector2(0, 0)
|
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
RegisterProcessor(patrolStateProcessor);
|
RegisterProcessor(patrolStateProcessor);
|
||||||
|
@ -28,5 +25,7 @@ public class PatrolStateMachine : StateMachineTemplate
|
||||||
RegisterProcessor(lookForWeaponProcessor);
|
RegisterProcessor(lookForWeaponProcessor);
|
||||||
var fleeProcessor = new FleeProcessor();
|
var fleeProcessor = new FleeProcessor();
|
||||||
RegisterProcessor(fleeProcessor);
|
RegisterProcessor(fleeProcessor);
|
||||||
|
var attackStateProcessor = new AttackStateProcessor();
|
||||||
|
RegisterProcessor(attackStateProcessor);
|
||||||
}
|
}
|
||||||
}
|
}
|
79
scripts/stateMachine/StateProcessor/AttackStateProcessor.cs
Normal file
79
scripts/stateMachine/StateProcessor/AttackStateProcessor.cs
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
using System;
|
||||||
|
using ColdMint.scripts.character;
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace ColdMint.scripts.stateMachine.StateProcessor;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>AttackStateProcessor</para>
|
||||||
|
/// <para>攻击状态处理器</para>
|
||||||
|
/// </summary>
|
||||||
|
public class AttackStateProcessor : StateProcessorTemplate
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>Consecutive attacks</para>
|
||||||
|
/// <para>连续攻击次数</para>
|
||||||
|
/// </summary>
|
||||||
|
private int _consecutiveAttacks;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>Max number of consecutive attacks</para>
|
||||||
|
/// <para>最大连续攻击次数</para>
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
///<para>When this value is reached, the attack needs to be paused for a period of time.</para>
|
||||||
|
///<para>到达此值后需要暂停一段时间攻击。</para>
|
||||||
|
/// </remarks>
|
||||||
|
public int MaxConsecutiveAttacks = 3;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>How long to pause after the maximum number of attacks is reached</para>
|
||||||
|
/// <para>到达最大攻击次数后停顿多长时间</para>
|
||||||
|
/// </summary>
|
||||||
|
public TimeSpan PauseTimeSpan = TimeSpan.FromSeconds(3);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>Time of next attack</para>
|
||||||
|
/// <para>下次攻击时间</para>
|
||||||
|
/// </summary>
|
||||||
|
private DateTime _nextAttackTime = DateTime.Now;
|
||||||
|
protected override void OnExecute(StateContext context, Node owner)
|
||||||
|
{
|
||||||
|
var now = DateTime.Now;
|
||||||
|
if (now < _nextAttackTime)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (owner is not AiCharacter aiCharacter)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var enemy = aiCharacter.GetFirstEnemyInScoutArea();
|
||||||
|
if (enemy == null)
|
||||||
|
{
|
||||||
|
context.CurrentState = context.PreviousState;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var canAttackEnemy = aiCharacter.GetFirstEnemyInAttackArea();
|
||||||
|
if (canAttackEnemy == null)
|
||||||
|
{
|
||||||
|
context.CurrentState = context.PreviousState;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
aiCharacter.DispladyPlaint();
|
||||||
|
aiCharacter.HideQuery();
|
||||||
|
if (aiCharacter.UseItem(enemy.GlobalPosition))
|
||||||
|
{
|
||||||
|
_consecutiveAttacks++;
|
||||||
|
if (_consecutiveAttacks >= MaxConsecutiveAttacks)
|
||||||
|
{
|
||||||
|
_consecutiveAttacks = 0;
|
||||||
|
_nextAttackTime = now + PauseTimeSpan;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
aiCharacter.AimTheCurrentItemAtAPoint(enemy.GlobalPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override State State => State.Attack;
|
||||||
|
}
|
|
@ -40,10 +40,7 @@ public class ChaseStateProcessor : StateProcessorTemplate
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//TODO:转到攻击状态。
|
context.CurrentState = State.Attack;
|
||||||
aiCharacter.HideQuery();
|
|
||||||
aiCharacter.DispladyPlaint();
|
|
||||||
aiCharacter.UseItem(enemy.GlobalPosition);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Set the position of the enemy entering the range to the position we are going to.
|
//Set the position of the enemy entering the range to the position we are going to.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user