diff --git a/DungeonShooting_Godot/src/framework/ui/grid/UiGrid.cs b/DungeonShooting_Godot/src/framework/ui/grid/UiGrid.cs index 09b87da..925b4e2 100644 --- a/DungeonShooting_Godot/src/framework/ui/grid/UiGrid.cs +++ b/DungeonShooting_Godot/src/framework/ui/grid/UiGrid.cs @@ -4,6 +4,12 @@ using System.Collections.Generic; using Godot; +/// +/// Ui网格组件 +/// +/// 原生Godot类型 +/// Ui节点类型 +/// 传给Cell的数据类型 public partial class UiGrid : GridContainer, IDestroy where TNodeType : Node where TUiNodeType : IUiNode { public bool IsDestroyed { get; private set; } diff --git a/DungeonShooting_Godot/src/game/activity/prop/Prop.cs b/DungeonShooting_Godot/src/game/activity/prop/Prop.cs index 5962d3b..deff9c5 100644 --- a/DungeonShooting_Godot/src/game/activity/prop/Prop.cs +++ b/DungeonShooting_Godot/src/game/activity/prop/Prop.cs @@ -4,5 +4,49 @@ /// public abstract partial class Prop : ActivityObject { + /// + /// 道具的拥有者 + /// + public Role Master { get; private set; } + /// + /// 当被动被道具被拾起时调用 + /// + /// 拾起该道具的角色 + protected abstract void OnPickUp(Role master); + + /// + /// 当被动道具被移除时调用 + /// + /// 移除该道具的角色 + protected abstract void OnRemove(Role master); + + + /// + /// 如果道具放入了角色背包中, 则每帧调用 + /// + public virtual void PackProcess(float delta) + { + + } + + public override void Interactive(ActivityObject master) + { + if (master is Role role) + { + Pickup(); + Master = role; + role.PushProp(this); + OnPickUp(role); + } + } + + public override CheckInteractiveResult CheckInteractive(ActivityObject master) + { + if (master is Player) + { + return new CheckInteractiveResult(this, true, ResourcePath.resource_sprite_ui_icon_icon_pickup_png); + } + return base.CheckInteractive(master); + } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/activity/prop/active/Active.cs b/DungeonShooting_Godot/src/game/activity/prop/active/Active.cs new file mode 100644 index 0000000..6747581 --- /dev/null +++ b/DungeonShooting_Godot/src/game/activity/prop/active/Active.cs @@ -0,0 +1,27 @@ + +/// +/// 主动使用道具 +/// +public abstract partial class Active : Prop +{ + /// + /// 是否可以使用 + /// + public bool CanUse { get; set; } + + /// + /// 当道具被使用时调用 + /// + protected abstract void OnUse(); + + /// + /// 触发使用道具 + /// + public void Use() + { + if (CanUse) + { + OnUse(); + } + } +} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/activity/prop/buff/Buff.cs b/DungeonShooting_Godot/src/game/activity/prop/buff/Buff.cs index 1afa4d7..d862b85 100644 --- a/DungeonShooting_Godot/src/game/activity/prop/buff/Buff.cs +++ b/DungeonShooting_Godot/src/game/activity/prop/buff/Buff.cs @@ -1,43 +1,8 @@  /// -/// 增益被动道具 +/// 被动增益道具 /// public abstract partial class Buff : Prop { - /// - /// buff的拥有者 - /// - public Role Master { get; private set; } - - /// - /// 当被动被道具被拾起时调用 - /// - /// 拾起该buff的角色 - protected abstract void OnPickUp(Role master); - /// - /// 当被动道具被移除时调用 - /// - /// 移除该buff的角色 - protected abstract void OnRemove(Role master); - - public override void Interactive(ActivityObject master) - { - if (master is Role role) - { - Pickup(); - Master = role; - role.PushProp(this); - OnPickUp(role); - } - } - - public override CheckInteractiveResult CheckInteractive(ActivityObject master) - { - if (master is Player) - { - return new CheckInteractiveResult(this, true, ResourcePath.resource_sprite_ui_icon_icon_pickup_png); - } - return base.CheckInteractive(master); - } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/activity/role/Player.cs b/DungeonShooting_Godot/src/game/activity/role/Player.cs index 24d432b..3411aec 100644 --- a/DungeonShooting_Godot/src/game/activity/role/Player.cs +++ b/DungeonShooting_Godot/src/game/activity/role/Player.cs @@ -147,7 +147,7 @@ //扔掉武器 var weapon = Holster.ActiveWeapon; base.ThrowWeapon(); - EventManager.EmitEvent(EventEnum.OnPlayerThrowWeapon, weapon); + EventManager.EmitEvent(EventEnum.OnPlayerRemoveWeapon, weapon); } public override void ThrowWeapon(int index) @@ -155,7 +155,7 @@ //扔掉武器 var weapon = Holster.GetWeapon(index); base.ThrowWeapon(index); - EventManager.EmitEvent(EventEnum.OnPlayerThrowWeapon, weapon); + EventManager.EmitEvent(EventEnum.OnPlayerRemoveWeapon, weapon); } protected override int OnHandlerHurt(int damage) diff --git a/DungeonShooting_Godot/src/game/activity/role/Role.cs b/DungeonShooting_Godot/src/game/activity/role/Role.cs index 5bc0694..4a2129b 100644 --- a/DungeonShooting_Godot/src/game/activity/role/Role.cs +++ b/DungeonShooting_Godot/src/game/activity/role/Role.cs @@ -402,6 +402,13 @@ _shieldRecoveryTimer = 0; } } + + //道具调用更新 + var props = PropsPack.ToArray(); + foreach (var prop in props) + { + prop.PackProcess(delta); + } } /// @@ -649,7 +656,7 @@ // GameApplication.Instance.Node3D.GetRoot().AddChild(blood); } OnHit(damage, !flag); - + //受伤特效 PlayHitAnimation(); @@ -759,15 +766,28 @@ /// /// 添加道具 /// - /// - public void PushProp(Buff buff) + public void PushProp(Prop prop) { - if (PropsPack.Contains(buff)) + if (PropsPack.Contains(prop)) { GD.PrintErr("道具已经在包裹中了!"); return; } - PropsPack.Add(buff); - EventManager.EmitEvent(EventEnum.OnPlayerPickUpProp, buff); + PropsPack.Add(prop); + EventManager.EmitEvent(EventEnum.OnPlayerPickUpProp, prop); + } + + /// + /// 移除道具 + /// + public bool RemoveProp(Prop prop) + { + if (PropsPack.Remove(prop)) + { + EventManager.EmitEvent(EventEnum.OnPlayerRemoveProp, prop); + return true; + } + GD.PrintErr("当前道具不在角色包裹中!"); + return false; } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/event/EventEnum.cs b/DungeonShooting_Godot/src/game/event/EventEnum.cs index 75274c6..839aa4f 100644 --- a/DungeonShooting_Godot/src/game/event/EventEnum.cs +++ b/DungeonShooting_Godot/src/game/event/EventEnum.cs @@ -43,7 +43,7 @@ /// /// 玩家丢弃武器, 参数为 /// - OnPlayerThrowWeapon, + OnPlayerRemoveWeapon, /// /// 玩家拾起道具, 参数为 /// @@ -51,7 +51,7 @@ /// /// 玩家丢弃道具, 参数为 /// - OnPlayerThrowProp, + OnPlayerRemoveProp, /// /// 当玩家进入地牢时调用, 没有参数