diff --git a/Resources/Enemies/Base_Fairy.tres b/Resources/Enemies/Base_Fairy.tres index 07b1c556..e6a22b60 100644 --- a/Resources/Enemies/Base_Fairy.tres +++ b/Resources/Enemies/Base_Fairy.tres @@ -52,4 +52,7 @@ PlayerDetectionRange = 90.0 ViewRange = 120.0 AlarmReactRange = 300.0 PlayerDisengageRange = 200.0 +StrafeSpeed = 25.0 +MaxStrafeDistance = 16.0 +MinStrafeDistance = 8.0 metadata/_custom_type_script = "uid://cd5o0ceb50jki" diff --git a/Resources/Enemies/Fairy_Guard.tres b/Resources/Enemies/Fairy_Guard.tres index 068de555..1f228430 100644 --- a/Resources/Enemies/Fairy_Guard.tres +++ b/Resources/Enemies/Fairy_Guard.tres @@ -52,4 +52,7 @@ PlayerDetectionRange = 90.0 ViewRange = 120.0 AlarmReactRange = 200.0 PlayerDisengageRange = 500.0 +StrafeSpeed = 25.0 +MaxStrafeDistance = 32.0 +MinStrafeDistance = 16.0 metadata/_custom_type_script = "uid://cd5o0ceb50jki" diff --git a/Resources/Enemies/Roaming_Susan.tres b/Resources/Enemies/Roaming_Susan.tres index 2dfa6bb8..16d76049 100644 --- a/Resources/Enemies/Roaming_Susan.tres +++ b/Resources/Enemies/Roaming_Susan.tres @@ -11,7 +11,12 @@ PrefabPath = &"res://Scenes/Actors/RoamingSusan.tscn" MaxHealth = 6.0 MovementSpeed = 20.0 Weapon = ExtResource("1_bpaea") -LootDrops = Array[Object]([]) +LootDrops = [] +PlayerDetectionRange = 90.0 +ViewRange = 120.0 AlarmReactRange = 200.0 PlayerDisengageRange = 500.0 +StrafeSpeed = 25.0 +MaxStrafeDistance = 16.0 +MinStrafeDistance = 8.0 metadata/_custom_type_script = "uid://cd5o0ceb50jki" diff --git a/Resources/Enemies/Thermathron.tres b/Resources/Enemies/Thermathron.tres index 6d20c332..eb34b4f3 100644 --- a/Resources/Enemies/Thermathron.tres +++ b/Resources/Enemies/Thermathron.tres @@ -1,6 +1,5 @@ -[gd_resource type="Resource" script_class="EnemyResource" load_steps=4 format=3 uid="uid://cfdvg162u65sr"] +[gd_resource type="Resource" script_class="EnemyResource" load_steps=3 format=3 uid="uid://cfdvg162u65sr"] -[ext_resource type="Script" uid="uid://cq65aed620ijo" path="res://Scripts/Resources/Loot/LootDrop.cs" id="1_f3huq"] [ext_resource type="Resource" uid="uid://cdfmedtgp2rcn" path="res://Resources/Weapons/EnemyWeapon.tres" id="7_filx8"] [ext_resource type="Script" uid="uid://cd5o0ceb50jki" path="res://Scripts/Resources/EnemyResource.cs" id="8_x8scf"] @@ -12,9 +11,12 @@ PrefabPath = &"res://Scenes/Actors/Thermathron.tscn" MaxHealth = 8.0 MovementSpeed = 38.0 Weapon = ExtResource("7_filx8") -LootDrops = Array[ExtResource("1_f3huq")]([]) +LootDrops = [] PlayerDetectionRange = 90.0 ViewRange = 120.0 AlarmReactRange = 200.0 PlayerDisengageRange = 500.0 +StrafeSpeed = 25.0 +MaxStrafeDistance = 0.0 +MinStrafeDistance = 0.0 metadata/_custom_type_script = "uid://cd5o0ceb50jki" diff --git a/Resources/Enemies/Turret360.tres b/Resources/Enemies/Turret360.tres index df75633e..416848bf 100644 --- a/Resources/Enemies/Turret360.tres +++ b/Resources/Enemies/Turret360.tres @@ -1,6 +1,5 @@ -[gd_resource type="Resource" script_class="EnemyResource" load_steps=4 format=3 uid="uid://ysd6wl2gmdhn"] +[gd_resource type="Resource" script_class="EnemyResource" load_steps=3 format=3 uid="uid://ysd6wl2gmdhn"] -[ext_resource type="Script" uid="uid://cq65aed620ijo" path="res://Scripts/Resources/Loot/LootDrop.cs" id="1_sma76"] [ext_resource type="Resource" uid="uid://dyaxm3st70sh6" path="res://Resources/Weapons/Enemy/TurretWeapon.tres" id="1_yap8t"] [ext_resource type="Script" uid="uid://cd5o0ceb50jki" path="res://Scripts/Resources/EnemyResource.cs" id="2_sma76"] @@ -12,9 +11,12 @@ PrefabPath = &"res://Scenes/Actors/Turret360.tscn" MaxHealth = 14.0 MovementSpeed = 0.0 Weapon = ExtResource("1_yap8t") -LootDrops = Array[ExtResource("1_sma76")]([]) +LootDrops = [] PlayerDetectionRange = 90.0 ViewRange = 120.0 AlarmReactRange = 200.0 PlayerDisengageRange = 500.0 +StrafeSpeed = 0.0 +MaxStrafeDistance = 0.0 +MinStrafeDistance = 0.0 metadata/_custom_type_script = "uid://cd5o0ceb50jki" diff --git a/Scenes/test.tscn b/Scenes/test.tscn index 530f62d9..72802326 100644 --- a/Scenes/test.tscn +++ b/Scenes/test.tscn @@ -652,7 +652,7 @@ IsEnabled = true Target = NodePath("../DebugTeleporter") [node name="DebugTeleporter" parent="Parallax2D/Factory Tilemaps/LevelProps" instance=ExtResource("30_8fdby")] -position = Vector2(-2002, -817) +position = Vector2(-429, 105) Invisible = true metadata/_edit_group_ = true diff --git a/Scripts/Components/FSM/Enemy/Alert.cs b/Scripts/Components/FSM/Enemy/Alert.cs index 83b66238..ec727d40 100644 --- a/Scripts/Components/FSM/Enemy/Alert.cs +++ b/Scripts/Components/FSM/Enemy/Alert.cs @@ -97,7 +97,7 @@ public partial class Alert : EnemyStateBase MoveTowardsPosition(PlayerDetection.LastKnownPlayerPosition.Value); } - NavigationModule.Move(); + NavigationModule.Move(StorageModule.EnemyData.MovementSpeed); StorageModule.FacingDirection = MainObject.Velocity.SnapToCardinal().Normalized(); } diff --git a/Scripts/Components/FSM/Enemy/EnemyStorageModule.cs b/Scripts/Components/FSM/Enemy/EnemyStorageModule.cs index 92827354..ae51be9c 100644 --- a/Scripts/Components/FSM/Enemy/EnemyStorageModule.cs +++ b/Scripts/Components/FSM/Enemy/EnemyStorageModule.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using Cirno.Scripts.Resources; using Cirno.Scripts.Resources.Loot; using Godot; using Godot.Collections; @@ -10,6 +11,8 @@ public partial class EnemyStorageModule : Node2D { [Export] public EnemyFSMProxy Root { get; private set; } + + public EnemyResource EnemyData => Root.EnemyResource; public Vector2 MovementDirection { get; set; } public Vector2 FacingDirection { get; set; } diff --git a/Scripts/Components/FSM/Enemy/NavigationMovementModule.cs b/Scripts/Components/FSM/Enemy/NavigationMovementModule.cs index 874f790a..5c4edbe8 100644 --- a/Scripts/Components/FSM/Enemy/NavigationMovementModule.cs +++ b/Scripts/Components/FSM/Enemy/NavigationMovementModule.cs @@ -25,7 +25,7 @@ public partial class NavigationMovementModule : Node2D _lastTargetPosition = target; } - public void Move() + public void Move(float movementSpeed) { if (!_lastTargetPosition.HasValue) { @@ -43,7 +43,7 @@ public partial class NavigationMovementModule : Node2D var nextPathPosition = _navigationAgent.GetNextPathPosition(); - var newVelocity = currentAgentPosition.DirectionTo(nextPathPosition) * StorageModule.MovementSpeed; + var newVelocity = currentAgentPosition.DirectionTo(nextPathPosition) * movementSpeed; if (_navigationAgent.AvoidanceEnabled) { diff --git a/Scripts/Components/FSM/Enemy/Shooting.cs b/Scripts/Components/FSM/Enemy/Shooting.cs index c6f52454..c3565fe5 100644 --- a/Scripts/Components/FSM/Enemy/Shooting.cs +++ b/Scripts/Components/FSM/Enemy/Shooting.cs @@ -20,14 +20,18 @@ public partial class Shooting : EnemyStateBase [Export] public NavigationMovementModule NavigationModule { get; private set; } - [Export] public float MaxStrafeDistance { get; private set; } = 64f; - [Export] public float MinStrafeDistance { get; private set; } = 16f; + // [Export] public float MaxStrafeDistance { get; private set; } = 64f; + // [Export] public float MinStrafeDistance { get; private set; } = 16f; [Export] public Weapon EquippedWeapon; private bool _isPlayerInRange = false; private Vector2? _currentStrafeTarget = null; + + private float _strafeSpeed => StorageModule.EnemyData.StrafeSpeed; + + private double _responseTimer = 0; public override void EnterState() { @@ -45,18 +49,8 @@ public partial class Shooting : EnemyStateBase EquippedWeapon.WeaponData = StorageModule.Root.EnemyResource.Weapon; _currentStrafeTarget = null; - // PlayerDetection.SetRange(StorageModule.Root.EnemyResource.PlayerDetectionRange); - // - // _isPlayerInRange = PlayerDetection.IsPlayerInRange(StorageModule.Root.EnemyResource.PlayerDetectionRange); - // - // PlayerDetection.PlayerInRange += PlayerDetectionOnPlayerInRange; - // - // PlayerDetection.PlayerOutOfRange += PlayerDetectionOnPlayerOutOfRange; - // - // DamageReceiver.ChangeState(true); - // - // DamageReceiver.HealthProvider.ResourceDepleted += HealthProviderOnResourceDepleted; - + + _responseTimer = 0; } private void HealthProviderOnResourceDepleted() @@ -93,10 +87,21 @@ public partial class Shooting : EnemyStateBase // SHOOT Shoot(); - // Check if a strafe position is needed - if (!_currentStrafeTarget.HasValue || NavigationModule.IsNavigationFinished()) + if (_strafeSpeed > 0) { - _currentStrafeTarget = CalculateStrafePosition(); + // Check if a strafe position is needed + if (!_currentStrafeTarget.HasValue || NavigationModule.IsNavigationFinished()) + { + if (_responseTimer < StorageModule.EnemyData.ResponseTime) + { + _responseTimer += delta; + } + else + { + _currentStrafeTarget = CalculateStrafePosition(); + _responseTimer = 0; + } + } } } else @@ -108,7 +113,7 @@ public partial class Shooting : EnemyStateBase if (_currentStrafeTarget.HasValue) { NavigationModule.SetTarget(_currentStrafeTarget.Value); - NavigationModule.Move(); + NavigationModule.Move(_strafeSpeed); } } @@ -129,7 +134,7 @@ public partial class Shooting : EnemyStateBase for (float factor = 1f; factor > 0.25f; factor *= 0.75f) { - float strafeDistance = Mathf.Lerp(MinStrafeDistance, MaxStrafeDistance, factor); + float strafeDistance = Mathf.Lerp(StorageModule.EnemyData.MinStrafeDistance, StorageModule.EnemyData.MaxStrafeDistance, factor); Vector2 newPos = enemyPos + (tryLeftFirst ? leftStrafe : rightStrafe) * strafeDistance; if (NavigationModule.IsNavigable(newPos) && PlayerDetection.HasLineOfSight(newPos, playerPos)) { @@ -139,7 +144,7 @@ public partial class Shooting : EnemyStateBase for (float factor = 1f; factor > 0.25f; factor *= 0.75f) { - float strafeDistance = Mathf.Lerp(MinStrafeDistance, MaxStrafeDistance, factor); + float strafeDistance = Mathf.Lerp(StorageModule.EnemyData.MinStrafeDistance, StorageModule.EnemyData.MaxStrafeDistance, factor); Vector2 newPos = enemyPos + (tryLeftFirst ? rightStrafe : leftStrafe) * strafeDistance; if (NavigationModule.IsNavigable(newPos) && PlayerDetection.HasLineOfSight(newPos, playerPos)) { diff --git a/Scripts/Resources/EnemyResource.cs b/Scripts/Resources/EnemyResource.cs index 1a835bf5..ac3c12a6 100644 --- a/Scripts/Resources/EnemyResource.cs +++ b/Scripts/Resources/EnemyResource.cs @@ -21,4 +21,13 @@ public partial class EnemyResource : Resource [Export] public float ViewRange { get; private set; } = 120f; [Export] public float AlarmReactRange { get; private set; } [Export] public float PlayerDisengageRange { get; private set; } + [Export] public float StrafeSpeed { get; private set; } = 25f; + [Export] public float MaxStrafeDistance { get; private set; } = 64f; + [Export] public float MinStrafeDistance { get; private set; } = 16f; + + /// + /// Time it takes for the enemy to change strafing direction + /// + [Export] public float ResponseTime { get; private set; } = 0.5f; + } \ No newline at end of file