diff --git a/DungeonShooting_Godot/excel/BulletBase.xlsx b/DungeonShooting_Godot/excel/BulletBase.xlsx index 093a10d..65ac36d 100644 --- a/DungeonShooting_Godot/excel/BulletBase.xlsx +++ b/DungeonShooting_Godot/excel/BulletBase.xlsx Binary files differ diff --git a/DungeonShooting_Godot/resource/config/BulletBase.json b/DungeonShooting_Godot/resource/config/BulletBase.json index 8a23d51..de64482 100644 --- a/DungeonShooting_Godot/resource/config/BulletBase.json +++ b/DungeonShooting_Godot/resource/config/BulletBase.json @@ -321,7 +321,7 @@ "Type": 1, "Prefab": "bullet0009", "HarmRange": [ - 12 + 15 ], "RepelRange": [ 55 @@ -356,7 +356,7 @@ "Type": 2, "Prefab": "res://prefab/bullet/laser/Laser0001.tscn", "HarmRange": [ - 5 + 7 ], "RepelRange": [ 35 diff --git a/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs b/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs index c4df8c2..50a975c 100644 --- a/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs +++ b/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs @@ -161,12 +161,6 @@ private float _verticalSpeed; /// - /// 投抛状态下物体碰撞器大小, 如果 (x, y) 都小于 0, 则默认使用 AnimatedSprite 的默认动画第一帧的大小 - /// - [Export] - public Vector2 ThrowCollisionSize { get; set; } = new Vector2(-1, -1); - - /// /// 是否启用垂直方向上的运动模拟, 默认开启, 如果禁用, 那么下落和投抛效果, 同样 Throw() 函数也将失效 /// public bool EnableVerticalMotion { get; set; } = true; @@ -303,9 +297,6 @@ //下坠是否已经结束 private bool _isFallOver = true; - //下坠状态碰撞器形状 - private RectangleShape2D _throwRectangleShape; - //投抛移动速率 private ExternalForce _throwForce; @@ -322,8 +313,12 @@ //击退外力 private ExternalForce _repelForce; + //绑定销毁物体集合 private HashSet _destroySet; + //挂载的物体集合 + private HashSet _mountObjects; + // -------------------------------------------------------------------------------- //实例索引 @@ -714,17 +709,6 @@ /// 旋转速度 public void Throw(float altitude, float verticalSpeed, Vector2 velocity, float rotateSpeed) { - var parent = GetParent(); - if (parent == null) - { - GameApplication.Instance.World.YSortLayer.AddChild(this); - } - else if (parent != GameApplication.Instance.World.YSortLayer) - { - parent.RemoveChild(this); - GameApplication.Instance.World.YSortLayer.AddChild(this); - } - Altitude = altitude; //Position = Position + new Vector2(0, altitude); VerticalSpeed = verticalSpeed; @@ -1396,6 +1380,16 @@ { return; } + + if (_mountObjects != null) + { + foreach (var item in _mountObjects) + { + item.OnUnmount(this); + } + + _mountObjects = null; + } IsDestroyed = true; if (AffiliationArea != null) @@ -1418,7 +1412,7 @@ } _components.Clear(); - + if (_destroySet != null) { foreach (var destroy in _destroySet) @@ -1459,10 +1453,9 @@ { this.AddToActivityRoot(RoomLayerEnum.YSortLayer); } - else if (parent == GameApplication.Instance.World.NormalLayer) + else if (parent != GameApplication.Instance.World.YSortLayer) { - parent.RemoveChild(this); - this.AddToActivityRoot(RoomLayerEnum.YSortLayer); + Reparent(GameApplication.Instance.World.YSortLayer); } CalcThrowAnimatedPosition(); @@ -1495,12 +1488,6 @@ _fallData.OriginCollisionMask = CollisionMask; _fallData.OriginCollisionLayer = CollisionLayer; - if (_throwRectangleShape == null) - { - _throwRectangleShape = new RectangleShape2D(); - } - - Collision.Shape = _throwRectangleShape; Collision.Position = Vector2.Zero; Collision.Rotation = 0; Collision.Scale = Vector2.One; @@ -1565,15 +1552,6 @@ _firstFall = true; _hasResilienceVerticalSpeed = false; _resilienceVerticalSpeed = 0; - - if (ThrowCollisionSize.X < 0 && ThrowCollisionSize.Y < 0) - { - _throwRectangleShape.Size = GetDefaultTexture().GetSize(); - } - else - { - _throwRectangleShape.Size = ThrowCollisionSize; - } Throw(); } @@ -1893,4 +1871,36 @@ _destroySet.Remove(destroy); } + + /// + /// 绑定挂载对象, 绑定的物体会在当前物体销毁时触发扔出 + /// + public void BindMountObject(IMountItem target) + { + if (_mountObjects == null) + { + _mountObjects = new HashSet(); + } + + if (_mountObjects.Add(target)) + { + target.OnMount(this); + } + } + + /// + /// 移除绑定挂载对象 + /// + public void RemoveMountObject(IMountItem target) + { + if (_mountObjects == null) + { + return; + } + + if (_mountObjects.Remove(target)) + { + target.OnUnmount(this); + } + } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/framework/activity/components/MoveController.cs b/DungeonShooting_Godot/src/framework/activity/components/MoveController.cs index 0f69a21..0f51b39 100644 --- a/DungeonShooting_Godot/src/framework/activity/components/MoveController.cs +++ b/DungeonShooting_Godot/src/framework/activity/components/MoveController.cs @@ -386,7 +386,7 @@ //调用反弹函数 Master.OnBounce(rotation); - if (Enable) + if (Enable && !Master.IsDestroyed) { if (Master.ActivityMaterial.RotationType == 1) //跟着反弹角度 { diff --git a/DungeonShooting_Godot/src/framework/activity/mount/IMountItem.cs b/DungeonShooting_Godot/src/framework/activity/mount/IMountItem.cs new file mode 100644 index 0000000..bf2c397 --- /dev/null +++ b/DungeonShooting_Godot/src/framework/activity/mount/IMountItem.cs @@ -0,0 +1,16 @@ + +/// +/// 可被 ActivityObject 挂载的物体 +/// +public interface IMountItem +{ + /// + /// 挂载到 ActivityObject 时调用 + /// + void OnMount(ActivityObject target); + + /// + /// 从 ActivityObject 卸载时调用 + /// + void OnUnmount(ActivityObject target); +} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/activity/bullet/normal/Arrow.cs b/DungeonShooting_Godot/src/game/activity/bullet/normal/Arrow.cs index 49d2a2c..3cd7b23 100644 --- a/DungeonShooting_Godot/src/game/activity/bullet/normal/Arrow.cs +++ b/DungeonShooting_Godot/src/game/activity/bullet/normal/Arrow.cs @@ -2,7 +2,7 @@ using Godot; [Tool] -public partial class Arrow : Bullet +public partial class Arrow : Bullet, IMountItem { [Export, ExportFillNode] public AnimatedSprite2D HalfSprite { get; set; } @@ -27,18 +27,27 @@ public override void LogicalFinish() { - MoveController.Enable = false; - CollisionArea.Monitoring = false; - CollisionArea.Monitorable = false; - Collision.Disabled = true; + SetEnableMovement(false); } private void OnBindTarget(ActivityObject activityObject) { Altitude = -activityObject.ToLocal(GlobalPosition).Y; - Reparent(activityObject); - activityObject.BindDestroyObject(this); + activityObject.BindMountObject(this); AnimatedSprite.Play(AnimatorNames.HalfEnd); HalfSprite.Visible = true; } + + public void OnMount(ActivityObject target) + { + Reparent(target); + } + + public void OnUnmount(ActivityObject target) + { + SetEnableMovement(true); + MoveController.ClearForce(); + MoveController.BasisVelocity = Vector2.Zero; + Throw(10, 60, new Vector2(20, 0), 0); + } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/activity/bullet/normal/Bullet.cs b/DungeonShooting_Godot/src/game/activity/bullet/normal/Bullet.cs index 8744f60..58d13ff 100644 --- a/DungeonShooting_Godot/src/game/activity/bullet/normal/Bullet.cs +++ b/DungeonShooting_Godot/src/game/activity/bullet/normal/Bullet.cs @@ -371,4 +371,15 @@ OnLeavePoolEvent(); } } + + /// + /// 设置是否启用移动逻辑 + /// + public void SetEnableMovement(bool v) + { + MoveController.Enable = v; + CollisionArea.Monitoring = v; + CollisionArea.Monitorable = v; + Collision.Disabled = !v; + } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs b/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs index f7a38b1..15b54fc 100644 --- a/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs +++ b/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs @@ -337,15 +337,6 @@ CurrAmmo = Attribute.AmmoCapacity; //剩余弹药量 ResidueAmmo = Mathf.Min(Attribute.StandbyAmmoCapacity + CurrAmmo, Attribute.MaxAmmoCapacity) - CurrAmmo; - - if (Collision.Shape is RectangleShape2D rectangleShape) - { - ThrowCollisionSize = rectangleShape.Size; - } - else - { - ThrowCollisionSize = new Vector2(-1, -1); - } } ///