diff --git a/DungeonShooting_Godot/resource/map/tileMaps/testGroup/inlet/Room1.tscn b/DungeonShooting_Godot/resource/map/tileMaps/testGroup/inlet/Room1.tscn index 5a05f49..937eee3 100644 --- a/DungeonShooting_Godot/resource/map/tileMaps/testGroup/inlet/Room1.tscn +++ b/DungeonShooting_Godot/resource/map/tileMaps/testGroup/inlet/Room1.tscn @@ -99,3 +99,10 @@ Type = 9 ItemExpression = "5000" WaveNumber = 3 + +[node name="ActivityMark19" type="Node2D" parent="."] +position = Vector2(106, 31) +script = ExtResource("3_m4jrh") +Type = 9 +ItemExpression = "5000" +WaveNumber = 3 diff --git a/DungeonShooting_Godot/src/framework/activity/CheckInteractiveResult.cs b/DungeonShooting_Godot/src/framework/activity/CheckInteractiveResult.cs index de50959..99b1296 100644 --- a/DungeonShooting_Godot/src/framework/activity/CheckInteractiveResult.cs +++ b/DungeonShooting_Godot/src/framework/activity/CheckInteractiveResult.cs @@ -29,7 +29,7 @@ /// /// 是否可以互动 /// - public bool CanInteractive; + public bool CanInteractive = false; /// /// 互动提示类型 /// diff --git a/DungeonShooting_Godot/src/game/activity/package/Package.cs b/DungeonShooting_Godot/src/game/activity/package/Package.cs index a8d72e3..a4bd76f 100644 --- a/DungeonShooting_Godot/src/game/activity/package/Package.cs +++ b/DungeonShooting_Godot/src/game/activity/package/Package.cs @@ -1,6 +1,9 @@ using System; using System.Collections.Generic; +/// +/// 物体背包类 +/// public class Package : IDestroy where T : ActivityObject, IPackageItem { public bool IsDestroyed { get; private set; } @@ -30,11 +33,10 @@ /// public T[] ItemSlot { get; private set; } - public Package(Role master) + public Package(Role master, int capacity) { Master = master; - //默认容量4 - SetCapacity(4); + SetCapacity(capacity); } /// @@ -405,6 +407,50 @@ return -1; } + + /// + /// 返回指定 id 的物体在背包中的索引, 如果不在背包中, 则返回 -1 + /// + public int IndexOfByItemId(string itemId) + { + if (ItemSlot == null) + { + return -1; + } + + for (var i = 0; i < ItemSlot.Length; i++) + { + var packageItem = ItemSlot[i]; + if (packageItem != null && packageItem.ItemConfig.Id == itemId) + { + return i; + } + } + + return -1; + } + + /// + /// 获取背包中指定 id 的物体, 如果有多个相同 id 的物体, 则返回第一个匹配的物体 + /// + public T GetItemById(string itemId) + { + if (ItemSlot == null) + { + return null; + } + + for (var i = 0; i < ItemSlot.Length; i++) + { + var packageItem = ItemSlot[i]; + if (packageItem != null && packageItem.ItemConfig.Id == itemId) + { + return packageItem; + } + } + + return null; + } public void Destroy() { diff --git a/DungeonShooting_Godot/src/game/activity/prop/Prop.cs b/DungeonShooting_Godot/src/game/activity/prop/Prop.cs index ef1879d..88c3aa2 100644 --- a/DungeonShooting_Godot/src/game/activity/prop/Prop.cs +++ b/DungeonShooting_Godot/src/game/activity/prop/Prop.cs @@ -28,13 +28,47 @@ { } + + public virtual void OnRemoveItem() + { + + } + + public virtual void OnPickUpItem() + { + + } + + public virtual void OnActiveItem() + { + + } + + public virtual void OnConcealItem() + { + + } + + public virtual void OnOverflowItem() + { + + } + + /// + /// 执行将当前道具放入角色背包的操作 + /// + protected void PushToRole(Role role) + { + Pickup(); + role.PushProp(this); + OnPickUp(role); + } + public override void Interactive(ActivityObject master) { if (master is Role role) { - Pickup(); - role.PushProp(this); - OnPickUp(role); + PushToRole(role); } } @@ -46,29 +80,5 @@ } return base.CheckInteractive(master); } - - public void OnRemoveItem() - { - - } - public void OnPickUpItem() - { - - } - - public void OnActiveItem() - { - - } - - public void OnConcealItem() - { - - } - - public void OnOverflowItem() - { - - } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/activity/prop/active/ActiveProp.cs b/DungeonShooting_Godot/src/game/activity/prop/active/ActiveProp.cs index a2be35f..6f3acb3 100644 --- a/DungeonShooting_Godot/src/game/activity/prop/active/ActiveProp.cs +++ b/DungeonShooting_Godot/src/game/activity/prop/active/ActiveProp.cs @@ -7,6 +7,11 @@ public abstract partial class ActiveProp : Prop { /// + /// 道具是否可以叠加 + /// + public bool Superposition { get; set; } = false; + + /// /// 道具可使用次数 /// public int Count @@ -131,9 +136,18 @@ protected virtual void OnCooldownFinish() { } - + + protected override void ProcessOver(float delta) + { + CheckAutoDestroy(); + } + public override void PackProcess(float delta) { + if (CheckAutoDestroy()) + { + return; + } //冷却 if (_cooldownTimer > 0) { @@ -154,6 +168,22 @@ } } + //检测是否达到自动销毁的条件 + private bool CheckAutoDestroy() + { + if (Count == 0 && AutoDestroy) //用光了, 自动销毁 + { + if (Master != null) + { + Master.RemoveProp(this); + } + Destroy(); + return true; + } + + return false; + } + /// /// 检测是否可以使用当前道具 /// @@ -181,11 +211,6 @@ //冷却计时器 _cooldownTimer = CooldownTime; - if (Count == 0 && AutoDestroy) //用光了, 自动销毁 - { - Master.RemoveProp(this); - Destroy(); - } } } @@ -201,4 +226,82 @@ return (CooldownTime - _cooldownTimer) / CooldownTime; } + + public override void Interactive(ActivityObject master) + { + if (master is Player player) + { + //查找相同类型的物体 + ActiveProp item; + if (Superposition && (item = player.ActivePropsPack.GetItemById(ItemConfig.Id)) != null) //走叠加逻辑 + { + if (item.Count < item.MaxCount) //可以叠加 + { + if (item.Count + Count > item.MaxCount) + { + Count -= item.MaxCount - item.Count; + item.Count = item.MaxCount; + } + else + { + item.Count += Count; + Count = 0; + } + } + else //该道具不能拾起 + { + return; + } + } + else //正常拾起 + { + if (player.ActivePropsPack.HasVacancy()) //还有空位 + { + PushToRole(player); + } + else //没有空位了 + { + //替换手中的道具 + + } + } + + return; + } + + base.Interactive(master); + } + + public override CheckInteractiveResult CheckInteractive(ActivityObject master) + { + if (master is Player player) + { + //查找相同类型的物体 + ActiveProp item; + if (Superposition && (item = player.ActivePropsPack.GetItemById(ItemConfig.Id)) != null) //走叠加逻辑 + { + if (item.Count < item.MaxCount) //可以叠加 + { + return new CheckInteractiveResult(this, true, CheckInteractiveResult.InteractiveType.Bullet); + } + else //该道具不能拾起 + { + return new CheckInteractiveResult(this); + } + } + else //正常拾起 + { + if (player.ActivePropsPack.HasVacancy()) //还有空位 + { + return new CheckInteractiveResult(this, true, CheckInteractiveResult.InteractiveType.PickUp); + } + else //没有空位了 + { + //替换手中的道具 + return new CheckInteractiveResult(this, true, CheckInteractiveResult.InteractiveType.Replace); + } + } + } + return base.CheckInteractive(master); + } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/activity/prop/active/ActiveProp5000.cs b/DungeonShooting_Godot/src/game/activity/prop/active/ActiveProp5000.cs index 74bf050..55f185a 100644 --- a/DungeonShooting_Godot/src/game/activity/prop/active/ActiveProp5000.cs +++ b/DungeonShooting_Godot/src/game/activity/prop/active/ActiveProp5000.cs @@ -11,6 +11,7 @@ { AutoDestroy = true; MaxCount = 20; + Superposition = true; } public override bool OnCheckUse() diff --git a/DungeonShooting_Godot/src/game/activity/role/Role.cs b/DungeonShooting_Godot/src/game/activity/role/Role.cs index fa9867e..4b6242c 100644 --- a/DungeonShooting_Godot/src/game/activity/role/Role.cs +++ b/DungeonShooting_Godot/src/game/activity/role/Role.cs @@ -311,8 +311,8 @@ public override void OnInit() { - ActivePropsPack = new Package(this); - WeaponPack = new Package(this); + ActivePropsPack = new Package(this, 1); + WeaponPack = new Package(this, 4); _startScale = Scale; MountPoint.Master = this; @@ -434,7 +434,10 @@ var buffProps = BuffPropPack.ToArray(); foreach (var prop in buffProps) { - prop.PackProcess(delta); + if (!prop.IsDestroyed) + { + prop.PackProcess(delta); + } } } @@ -442,7 +445,7 @@ var props = (Prop[])ActivePropsPack.ItemSlot.Clone(); foreach (var prop in props) { - if (prop != null) + if (prop != null && !prop.IsDestroyed) { prop.PackProcess(delta); } diff --git a/DungeonShooting_Godot/src/game/ui/roomUI/ActivePropBar.cs b/DungeonShooting_Godot/src/game/ui/roomUI/ActivePropBar.cs index 4db890e..c037150 100644 --- a/DungeonShooting_Godot/src/game/ui/roomUI/ActivePropBar.cs +++ b/DungeonShooting_Godot/src/game/ui/roomUI/ActivePropBar.cs @@ -135,8 +135,7 @@ public void SetChargeProgressVisible(bool visible) { var ninePatchRect = _activePropBar.L_ChargeProgressBar.Instance; - var sprite = _activePropBar.L_CooldownProgress.Instance; - sprite.Visible = visible; + _activePropBar.L_ChargeProgress.Instance.Visible = visible; if (ninePatchRect.Visible == visible && _initCooldown) { return; @@ -144,8 +143,8 @@ _initCooldown = true; + var sprite = _activePropBar.L_CooldownProgress.Instance; ninePatchRect.Visible = visible; - _activePropBar.L_ChargeProgress.Instance.Visible = visible; //调整冷却蒙板大小 if (visible) {