diff --git a/prefab/entitys/BlackenedAboriginalWarrior.tscn b/prefab/entitys/BlackenedAboriginalWarrior.tscn index 43d9ec7..40f0c81 100644 --- a/prefab/entitys/BlackenedAboriginalWarrior.tscn +++ b/prefab/entitys/BlackenedAboriginalWarrior.tscn @@ -24,10 +24,10 @@ animations = [{ }] [sub_resource type="CircleShape2D" id="CircleShape2D_c61vr"] -radius = 153.0 +radius = 220.0 [sub_resource type="CircleShape2D" id="CircleShape2D_fowd5"] -radius = 172.29 +radius = 300.0 [node name="BlackenedAboriginalWarrior" type="CharacterBody2D"] collision_layer = 64 diff --git a/scripts/stateMachine/PatrolStateMachine.cs b/scripts/stateMachine/PatrolStateMachine.cs index 7929438..6fd9044 100644 --- a/scripts/stateMachine/PatrolStateMachine.cs +++ b/scripts/stateMachine/PatrolStateMachine.cs @@ -14,11 +14,8 @@ public class PatrolStateMachine : StateMachineTemplate { Points = [ - new Godot.Vector2(100, 0), - new Godot.Vector2(-100, 0), - new Godot.Vector2(50, 0), - new Godot.Vector2(-50, 0), - new Godot.Vector2(0, 0) + new Godot.Vector2(Config.CellSize * 3, 0), + new Godot.Vector2(-Config.CellSize * 3, 0), ] }; RegisterProcessor(patrolStateProcessor); @@ -28,5 +25,7 @@ public class PatrolStateMachine : StateMachineTemplate RegisterProcessor(lookForWeaponProcessor); var fleeProcessor = new FleeProcessor(); RegisterProcessor(fleeProcessor); + var attackStateProcessor = new AttackStateProcessor(); + RegisterProcessor(attackStateProcessor); } } \ No newline at end of file diff --git a/scripts/stateMachine/StateProcessor/AttackStateProcessor.cs b/scripts/stateMachine/StateProcessor/AttackStateProcessor.cs new file mode 100644 index 0000000..234f519 --- /dev/null +++ b/scripts/stateMachine/StateProcessor/AttackStateProcessor.cs @@ -0,0 +1,79 @@ +using System; +using ColdMint.scripts.character; +using Godot; + +namespace ColdMint.scripts.stateMachine.StateProcessor; + +/// +/// AttackStateProcessor +/// 攻击状态处理器 +/// +public class AttackStateProcessor : StateProcessorTemplate +{ + + /// + /// Consecutive attacks + /// 连续攻击次数 + /// + private int _consecutiveAttacks; + + /// + /// Max number of consecutive attacks + /// 最大连续攻击次数 + /// + /// + ///When this value is reached, the attack needs to be paused for a period of time. + ///到达此值后需要暂停一段时间攻击。 + /// + public int MaxConsecutiveAttacks = 3; + + /// + /// How long to pause after the maximum number of attacks is reached + /// 到达最大攻击次数后停顿多长时间 + /// + public TimeSpan PauseTimeSpan = TimeSpan.FromSeconds(3); + + /// + /// Time of next attack + /// 下次攻击时间 + /// + 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; +} \ No newline at end of file diff --git a/scripts/stateMachine/StateProcessor/ChaseStateProcessor.cs b/scripts/stateMachine/StateProcessor/ChaseStateProcessor.cs index 7419f69..9ea0091 100644 --- a/scripts/stateMachine/StateProcessor/ChaseStateProcessor.cs +++ b/scripts/stateMachine/StateProcessor/ChaseStateProcessor.cs @@ -40,10 +40,7 @@ public class ChaseStateProcessor : StateProcessorTemplate } else { - //TODO:转到攻击状态。 - aiCharacter.HideQuery(); - aiCharacter.DispladyPlaint(); - aiCharacter.UseItem(enemy.GlobalPosition); + context.CurrentState = State.Attack; } //Set the position of the enemy entering the range to the position we are going to.