实时修改角色阵营,目前还有点小问题

This commit is contained in:
小李xl 2024-04-08 13:57:24 +08:00
parent c805f60898
commit e115d5863c
6 changed files with 40 additions and 11 deletions

View File

@ -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}]}]]}] [{"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}]}]]}]

View File

@ -122,6 +122,7 @@ public abstract partial class AiRole : Role
{ {
if (AttackTarget == null || AttackTarget.IsDestroyed || !IsEnemy(AttackTarget)) if (AttackTarget == null || AttackTarget.IsDestroyed || !IsEnemy(AttackTarget))
{ {
AttackTarget = null;
foreach (var role in World.Role_InstanceList) foreach (var role in World.Role_InstanceList)
{ {
if (role.AffiliationArea == AffiliationArea && IsEnemy(role)) if (role.AffiliationArea == AffiliationArea && IsEnemy(role))

View File

@ -83,6 +83,12 @@ public class AiAttackState : StateBase<AiRole, AIStateEnum>
public override void Process(float delta) 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(); Master.UpdateMarkTargetPosition();

View File

@ -43,6 +43,12 @@ public class AiSurroundState : StateBase<AiRole, AIStateEnum>
public override void Process(float delta) public override void Process(float delta)
{ {
if (Master.LookTarget == null)
{
ChangeState(AIStateEnum.AiNormal);
return;
}
//先检查弹药是否打光 //先检查弹药是否打光
if (Master.IsAllWeaponTotalAmmoEmpty()) if (Master.IsAllWeaponTotalAmmoEmpty())
{ {

View File

@ -128,20 +128,27 @@ public partial class Enemy : AiRole
//看向目标 //看向目标
if (LookTarget != null && MountLookTarget) if (LookTarget != null && MountLookTarget)
{ {
var pos = LookTarget.Position; if (LookTarget.IsDestroyed)
LookPosition = pos;
//脸的朝向
var gPos = Position;
if (pos.X > gPos.X && Face == FaceDirection.Left)
{ {
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) if (RoleState.CanPickUpWeapon)

View File

@ -203,6 +203,15 @@ public partial class Player : Role
else if (InputManager.UseActiveProp) //使用道具 else if (InputManager.UseActiveProp) //使用道具
{ {
UseActiveProp(); UseActiveProp();
foreach (var role in World.Role_InstanceList)
{
if (IsEnemy(role))
{
role.Camp = Camp;
break;
}
}
} }
else if (InputManager.ExchangeProp) //切换道具 else if (InputManager.ExchangeProp) //切换道具
{ {