diff --git a/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs b/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs index f533803..128a0f6 100644 --- a/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs +++ b/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs @@ -305,6 +305,9 @@ private bool _processingBecomesStaticImage = false; + //击退外力 + private ExternalForce _repelForce; + // -------------------------------------------------------------------------------- //实例索引 @@ -1723,4 +1726,39 @@ Scale *= new Vector2(-1, 1); } } + + /// + /// 添加一个击退力 + /// + public void AddRepelForce(Vector2 velocity) + { + if (_repelForce == null) + { + _repelForce = new ExternalForce(ForceNames.Repel); + } + + //不在 MoveController 中 + if (_repelForce.MoveController == null) + { + _repelForce.Velocity = velocity; + MoveController.AddForce(_repelForce); + } + else + { + _repelForce.Velocity += velocity; + } + } + + /// + /// 获取击退力 + /// + public Vector2 GetRepelForce() + { + if (_repelForce == null || _repelForce.MoveController == null) + { + return Vector2.Zero; + } + + return _repelForce.Velocity; + } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/framework/activity/ExternalForce.cs b/DungeonShooting_Godot/src/framework/activity/ExternalForce.cs index fee637c..4f06156 100644 --- a/DungeonShooting_Godot/src/framework/activity/ExternalForce.cs +++ b/DungeonShooting_Godot/src/framework/activity/ExternalForce.cs @@ -7,6 +7,11 @@ public class ExternalForce { /// + /// 所在的移动控制器 + /// + public MoveController MoveController { get; set; } + + /// /// 当前力的名称 /// public string Name { get; } diff --git a/DungeonShooting_Godot/src/framework/activity/components/MoveController.cs b/DungeonShooting_Godot/src/framework/activity/components/MoveController.cs index 8c57a64..ef0f435 100644 --- a/DungeonShooting_Godot/src/framework/activity/components/MoveController.cs +++ b/DungeonShooting_Godot/src/framework/activity/components/MoveController.cs @@ -210,6 +210,7 @@ public T AddForce(T force) where T : ExternalForce { RemoveForce(force.Name); + force.MoveController = this; _forceList.Add(force); return force; } @@ -223,6 +224,7 @@ { if (_forceList[i].Name == name) { + _forceList[i].MoveController = null; _forceList.RemoveAt(i); return; } @@ -276,6 +278,11 @@ /// public void ClearForce() { + foreach (var force in _forceList) + { + force.MoveController = null; + } + _forceList.Clear(); } @@ -305,6 +312,7 @@ //自动销毁 if (CheckAutoDestroy(force)) { + force.MoveController = null; _forceList.Remove(force); externalForces[i] = null; } diff --git a/DungeonShooting_Godot/src/game/activity/ForceNames.cs b/DungeonShooting_Godot/src/game/activity/ForceNames.cs index ae60220..f732a84 100644 --- a/DungeonShooting_Godot/src/game/activity/ForceNames.cs +++ b/DungeonShooting_Godot/src/game/activity/ForceNames.cs @@ -8,4 +8,8 @@ /// 投抛外力 /// public const string Throw = "throw"; + /// + /// 击退外力 + /// + public const string Repel = "repel"; } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/activity/bullet/explode/Explode.cs b/DungeonShooting_Godot/src/game/activity/bullet/explode/Explode.cs index 60922d4..637b9b3 100644 --- a/DungeonShooting_Godot/src/game/activity/bullet/explode/Explode.cs +++ b/DungeonShooting_Godot/src/game/activity/bullet/explode/Explode.cs @@ -161,7 +161,7 @@ { var repelled = (_repelledRadius - len) / _repelledRadius * _maxRepelled; //o.MoveController.SetAllVelocity(Vector2.Zero); - o.MoveController.AddForce(Vector2.FromAngle(angle) * repelled); + o.AddRepelForce(Vector2.FromAngle(angle) * repelled); } } } diff --git a/DungeonShooting_Godot/src/game/activity/bullet/laser/Laser.cs b/DungeonShooting_Godot/src/game/activity/bullet/laser/Laser.cs index 3f9a230..f516e71 100644 --- a/DungeonShooting_Godot/src/game/activity/bullet/laser/Laser.cs +++ b/DungeonShooting_Godot/src/game/activity/bullet/laser/Laser.cs @@ -142,7 +142,7 @@ //击退 if (BulletData.Repel != 0) { - role.MoveController.AddForce(Vector2.FromAngle(Rotation) * BulletData.Repel); + role.AddRepelForce(Vector2.FromAngle(Rotation) * BulletData.Repel); } //造成伤害 role.CallDeferred(nameof(Role.Hurt), BulletData.TriggerRole.IsDestroyed ? null : BulletData.TriggerRole, BulletData.Harm, Rotation); diff --git a/DungeonShooting_Godot/src/game/activity/bullet/normal/Bullet.cs b/DungeonShooting_Godot/src/game/activity/bullet/normal/Bullet.cs index a516c2f..a444a13 100644 --- a/DungeonShooting_Godot/src/game/activity/bullet/normal/Bullet.cs +++ b/DungeonShooting_Godot/src/game/activity/bullet/normal/Bullet.cs @@ -141,7 +141,7 @@ { if (BulletData.Repel != 0) { - role.MoveController.AddForce(Velocity.Normalized() * BulletData.Repel); + role.AddRepelForce(Velocity.Normalized() * BulletData.Repel); } } diff --git a/DungeonShooting_Godot/src/game/activity/role/Role.cs b/DungeonShooting_Godot/src/game/activity/role/Role.cs index 9a5413b..b8acc1a 100644 --- a/DungeonShooting_Godot/src/game/activity/role/Role.cs +++ b/DungeonShooting_Godot/src/game/activity/role/Role.cs @@ -1259,7 +1259,7 @@ var repel = Utils.Random.RandomConfigRange(attr.MeleeAttackRepelRange); var position = role.GlobalPosition - MountPoint.GlobalPosition; var v2 = position.Normalized() * repel; - role.MoveController.AddForce(v2); + role.AddRepelForce(v2); } role.CallDeferred(nameof(Hurt), this, damage, (role.GetCenterPosition() - GlobalPosition).Angle()); diff --git a/DungeonShooting_Godot/src/game/activity/weapon/knife/Knife.cs b/DungeonShooting_Godot/src/game/activity/weapon/knife/Knife.cs index ca56de3..b465060 100644 --- a/DungeonShooting_Godot/src/game/activity/weapon/knife/Knife.cs +++ b/DungeonShooting_Godot/src/game/activity/weapon/knife/Knife.cs @@ -155,7 +155,7 @@ position = role.GlobalPosition - GlobalPosition; } var v2 = position.Normalized() * repel; - role.MoveController.AddForce(v2); + role.AddRepelForce(v2); } //造成伤害