From e115d5863c2be274a91adbe3a43d7eb9c9f509e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=9D=8Exl?= <1911159016@qq.com> Date: Mon, 8 Apr 2024 13:57:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E6=97=B6=E4=BF=AE=E6=94=B9=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E9=98=B5=E8=90=A5,=E7=9B=AE=E5=89=8D=E8=BF=98?= =?UTF-8?q?=E6=9C=89=E7=82=B9=E5=B0=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Test1/inlet/Start2/Preinstall.json | 2 +- .../src/game/activity/role/ai/AiRole.cs | 1 + .../activity/role/ai/state/AiAttackState.cs | 6 +++++ .../activity/role/ai/state/AiSurroundState.cs | 6 +++++ .../src/game/activity/role/enemy/Enemy.cs | 27 ++++++++++++------- .../src/game/activity/role/player/Player.cs | 9 +++++++ 6 files changed, 40 insertions(+), 11 deletions(-) diff --git a/DungeonShooting_Godot/resource/map/tileMaps/Test1/inlet/Start2/Preinstall.json b/DungeonShooting_Godot/resource/map/tileMaps/Test1/inlet/Start2/Preinstall.json index 763ac16c..553b233b 100644 --- a/DungeonShooting_Godot/resource/map/tileMaps/Test1/inlet/Start2/Preinstall.json +++ b/DungeonShooting_Godot/resource/map/tileMaps/Test1/inlet/Start2/Preinstall.json @@ -1 +1 @@ -[{"Name":"Preinstall1","Weight":100,"Remark":"","AutoFill":true,"WaveList":[[{"Position":{"X":0,"Y":0},"Size":{"X":0,"Y":0},"SpecialMarkType":1,"DelayTime":0,"MarkList":[]},{"Position":{"X":53,"Y":31},"Size":{"X":16,"Y":16},"SpecialMarkType":0,"DelayTime":0,"MarkList":[{"Id":"enemy0001","Weight":100,"Attr":{"Face":"0","Weapon":"weapon0003","CurrAmmon":"12","ResidueAmmo":"12"},"Altitude":0,"VerticalSpeed":5.551115E-14}]}]]}] \ No newline at end of file +[{"Name":"Preinstall1","Weight":100,"Remark":"","AutoFill":true,"WaveList":[[{"Position":{"X":0,"Y":0},"Size":{"X":0,"Y":0},"SpecialMarkType":1,"DelayTime":0,"MarkList":[]},{"Position":{"X":53,"Y":31},"Size":{"X":16,"Y":16},"SpecialMarkType":0,"DelayTime":0,"MarkList":[{"Id":"enemy0001","Weight":100,"Attr":{"Face":"0","Weapon":"weapon0003","CurrAmmon":"12","ResidueAmmo":"12"},"Altitude":0,"VerticalSpeed":5.551115E-14}]},{"Position":{"X":84,"Y":8},"Size":{"X":16,"Y":16},"SpecialMarkType":0,"DelayTime":0,"MarkList":[{"Id":"enemy0001","Weight":100,"Attr":{"Face":"0","Weapon":"weapon0002","CurrAmmon":"7","ResidueAmmo":"7"},"Altitude":0,"VerticalSpeed":5.551115E-14}]}]]}] \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/activity/role/ai/AiRole.cs b/DungeonShooting_Godot/src/game/activity/role/ai/AiRole.cs index a459fe4d..de6b899f 100644 --- a/DungeonShooting_Godot/src/game/activity/role/ai/AiRole.cs +++ b/DungeonShooting_Godot/src/game/activity/role/ai/AiRole.cs @@ -122,6 +122,7 @@ public abstract partial class AiRole : Role { if (AttackTarget == null || AttackTarget.IsDestroyed || !IsEnemy(AttackTarget)) { + AttackTarget = null; foreach (var role in World.Role_InstanceList) { if (role.AffiliationArea == AffiliationArea && IsEnemy(role)) diff --git a/DungeonShooting_Godot/src/game/activity/role/ai/state/AiAttackState.cs b/DungeonShooting_Godot/src/game/activity/role/ai/state/AiAttackState.cs index 12acf2e5..8fcb08d3 100644 --- a/DungeonShooting_Godot/src/game/activity/role/ai/state/AiAttackState.cs +++ b/DungeonShooting_Godot/src/game/activity/role/ai/state/AiAttackState.cs @@ -83,6 +83,12 @@ public class AiAttackState : StateBase public override void Process(float delta) { + if (Master.LookTarget == null || Master.LookTarget.IsDestroyed || (Master.LookTarget is Role role && !Master.IsEnemy(role))) //更改攻击状态 + { + ChangeState(AIStateEnum.AiNormal); + return; + } + //更新标记位置 Master.UpdateMarkTargetPosition(); diff --git a/DungeonShooting_Godot/src/game/activity/role/ai/state/AiSurroundState.cs b/DungeonShooting_Godot/src/game/activity/role/ai/state/AiSurroundState.cs index 94afce73..46497e13 100644 --- a/DungeonShooting_Godot/src/game/activity/role/ai/state/AiSurroundState.cs +++ b/DungeonShooting_Godot/src/game/activity/role/ai/state/AiSurroundState.cs @@ -43,6 +43,12 @@ public class AiSurroundState : StateBase public override void Process(float delta) { + if (Master.LookTarget == null) + { + ChangeState(AIStateEnum.AiNormal); + return; + } + //先检查弹药是否打光 if (Master.IsAllWeaponTotalAmmoEmpty()) { diff --git a/DungeonShooting_Godot/src/game/activity/role/enemy/Enemy.cs b/DungeonShooting_Godot/src/game/activity/role/enemy/Enemy.cs index 9db906b9..1f8dd9f9 100644 --- a/DungeonShooting_Godot/src/game/activity/role/enemy/Enemy.cs +++ b/DungeonShooting_Godot/src/game/activity/role/enemy/Enemy.cs @@ -128,20 +128,27 @@ public partial class Enemy : AiRole //看向目标 if (LookTarget != null && MountLookTarget) { - var pos = LookTarget.Position; - LookPosition = pos; - //脸的朝向 - var gPos = Position; - if (pos.X > gPos.X && Face == FaceDirection.Left) + if (LookTarget.IsDestroyed) { - Face = FaceDirection.Right; + LookTarget = null; } - else if (pos.X < gPos.X && Face == FaceDirection.Right) + else { - Face = FaceDirection.Left; + var pos = LookTarget.Position; + LookPosition = pos; + //脸的朝向 + var gPos = Position; + if (pos.X > gPos.X && Face == FaceDirection.Left) + { + Face = FaceDirection.Right; + } + else if (pos.X < gPos.X && Face == FaceDirection.Right) + { + Face = FaceDirection.Left; + } + //枪口跟随目标 + MountPoint.SetLookAt(pos); } - //枪口跟随目标 - MountPoint.SetLookAt(pos); } if (RoleState.CanPickUpWeapon) diff --git a/DungeonShooting_Godot/src/game/activity/role/player/Player.cs b/DungeonShooting_Godot/src/game/activity/role/player/Player.cs index 0bc007ce..ca2e85fc 100644 --- a/DungeonShooting_Godot/src/game/activity/role/player/Player.cs +++ b/DungeonShooting_Godot/src/game/activity/role/player/Player.cs @@ -203,6 +203,15 @@ public partial class Player : Role else if (InputManager.UseActiveProp) //使用道具 { UseActiveProp(); + + foreach (var role in World.Role_InstanceList) + { + if (IsEnemy(role)) + { + role.Camp = Camp; + break; + } + } } else if (InputManager.ExchangeProp) //切换道具 {