From 84ee313ce5e93a84c823eeef24e8313c0cfa5346 Mon Sep 17 00:00:00 2001 From: Zenny Date: Sun, 22 Sep 2024 14:40:53 -0700 Subject: [PATCH] Throw item --- src/game/Game.cs | 11 +++++++++++ src/inventory_menu/InventoryMenu.cs | 20 +++++++++++--------- src/items/InventoryItem.cs | 6 ------ src/items/accessory/Accessory.cs | 2 +- src/items/armor/Armor.cs | 2 +- src/items/consumable/ConsumableItem.cs | 2 +- src/items/throwable/ThrowableItem.cs | 12 +----------- src/items/thrown/ThrownItem.cs | 2 +- src/items/thrown/ThrownItem.tscn | 7 +++---- 9 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/game/Game.cs b/src/game/Game.cs index 749e4050..d141375d 100644 --- a/src/game/Game.cs +++ b/src/game/Game.cs @@ -13,6 +13,8 @@ public interface IGame : IProvide, IProvide, IProvid public IPlayer Player { get; } public void DropItem(IInventoryItem item); + + public void ThrowItem(IInventoryItem item); } [Meta(typeof(IAutoNode))] @@ -143,6 +145,15 @@ public partial class Game : Node3D, IGame dropped.Drop(); } + public void ThrowItem(IInventoryItem item) + { + var thrownScene = GD.Load("res://src/items/thrown/ThrownItem.tscn"); + var thrown = thrownScene.Instantiate(); + thrown.ThrownItemStats = item.Info; + AddChild(thrown); + thrown.Throw(); + } + private void OnEnemyDefeated(Vector3 vector, EnemyStatResource resource) { var restorativeScene = GD.Load("res://src/items/restorative/Restorative.tscn"); diff --git a/src/inventory_menu/InventoryMenu.cs b/src/inventory_menu/InventoryMenu.cs index 1b48ef7f..37e0273b 100644 --- a/src/inventory_menu/InventoryMenu.cs +++ b/src/inventory_menu/InventoryMenu.cs @@ -237,6 +237,9 @@ public partial class InventoryMenu : Control, IInventoryMenu { foreach (var item in ItemSlots) ItemsPage.RemoveChildEx(item); + + ItemDescriptionTitle.Text = string.Empty; + ItemEffectLabel.Text = string.Empty; } private void PopulatePlayerInfo() @@ -408,23 +411,22 @@ public partial class InventoryMenu : Control, IInventoryMenu { var currentItem = ItemSlots[_currentIndex].Item; - if (currentItem is IThrowableItem throwable) - { - throwable.Throw(); + Game.ThrowItem(currentItem); + GameRepo.PlayerData.Inventory.Remove(currentItem); - if (_currentIndex >= ItemSlots.Length - 1) - _currentIndex--; - if (_currentIndex <= 0) - _currentIndex = 0; + if (_currentIndex >= ItemSlots.Length - 1) + _currentIndex--; + if (_currentIndex <= 0) + _currentIndex = 0; - EmitSignal(SignalName.ClosedMenu); - } + EmitSignal(SignalName.ClosedMenu); } private async void DropButtonPressed() { var currentItem = ItemSlots[_currentIndex].Item; Game.DropItem(currentItem); + GameRepo.PlayerData.Inventory.Remove(currentItem); if (_currentIndex >= ItemSlots.Length - 1) _currentIndex--; diff --git a/src/items/InventoryItem.cs b/src/items/InventoryItem.cs index 686a726d..2020893b 100644 --- a/src/items/InventoryItem.cs +++ b/src/items/InventoryItem.cs @@ -1,5 +1,4 @@ using Chickensoft.GodotNodeInterfaces; -using Godot; using System; namespace GameJamDungeon @@ -15,9 +14,4 @@ namespace GameJamDungeon { public void Use(); } - - public interface IThrowableItem : IInventoryItem - { - public void Throw(); - } } diff --git a/src/items/accessory/Accessory.cs b/src/items/accessory/Accessory.cs index 9ae4e811..6b4c6942 100644 --- a/src/items/accessory/Accessory.cs +++ b/src/items/accessory/Accessory.cs @@ -5,7 +5,7 @@ using Godot; using System; [Meta(typeof(IAutoNode))] -public partial class Accessory : Node3D, IEquipableItem, IThrowableItem +public partial class Accessory : Node3D, IEquipableItem { public override void _Notification(int what) => this.Notify(what); diff --git a/src/items/armor/Armor.cs b/src/items/armor/Armor.cs index eacc9c0b..10a57e90 100644 --- a/src/items/armor/Armor.cs +++ b/src/items/armor/Armor.cs @@ -5,7 +5,7 @@ using Godot; using System; [Meta(typeof(IAutoNode))] -public partial class Armor : Node3D, IEquipableItem, IThrowableItem +public partial class Armor : Node3D, IEquipableItem { public override void _Notification(int what) => this.Notify(what); diff --git a/src/items/consumable/ConsumableItem.cs b/src/items/consumable/ConsumableItem.cs index cf22e865..972d6c04 100644 --- a/src/items/consumable/ConsumableItem.cs +++ b/src/items/consumable/ConsumableItem.cs @@ -5,7 +5,7 @@ using Godot; using System; [Meta(typeof(IAutoNode))] -public partial class ConsumableItem : Node3D, IUsableItem, IThrowableItem +public partial class ConsumableItem : Node3D, IUsableItem { public override void _Notification(int what) => this.Notify(what); diff --git a/src/items/throwable/ThrowableItem.cs b/src/items/throwable/ThrowableItem.cs index 6450abd7..7f1755e4 100644 --- a/src/items/throwable/ThrowableItem.cs +++ b/src/items/throwable/ThrowableItem.cs @@ -5,7 +5,7 @@ using Godot; using System; [Meta(typeof(IAutoNode))] -public partial class ThrowableItem : Node3D, IThrowableItem +public partial class ThrowableItem : Node3D, IInventoryItem { public override void _Notification(int what) => this.Notify(what); @@ -32,16 +32,6 @@ public partial class ThrowableItem : Node3D, IThrowableItem Pickup.BodyEntered += OnEntered; } - public void Throw() - { - var throwableScene = GD.Load("res://src/items/thrown/ThrownItem.tscn"); - var throwable = throwableScene.Instantiate(); - throwable.ThrownItemStats = ThrowableItemInfo; - Game.AddChild(throwable); - throwable.Throw(); - GameRepo.PlayerData.Inventory.Remove(this); - } - public void OnEntered(Node3D body) { var isAdded = GameRepo.PlayerData.Inventory.TryAdd(this); diff --git a/src/items/thrown/ThrownItem.cs b/src/items/thrown/ThrownItem.cs index a8477258..1287825e 100644 --- a/src/items/thrown/ThrownItem.cs +++ b/src/items/thrown/ThrownItem.cs @@ -17,7 +17,7 @@ public partial class ThrownItem : RigidBody3D public void OnResolved() { BodyEntered += ThrownItem_BodyEntered; - GlobalPosition = Game.Player.GlobalPosition + Vector3.Up; + GlobalPosition = Game.Player.GlobalPosition + new Vector3(0, 1.5f, 0); Sprite.Texture = ThrownItemStats.Texture; AddCollisionExceptionWith((Node)Game.Player); } diff --git a/src/items/thrown/ThrownItem.tscn b/src/items/thrown/ThrownItem.tscn index d8d779c5..d968d7e4 100644 --- a/src/items/thrown/ThrownItem.tscn +++ b/src/items/thrown/ThrownItem.tscn @@ -4,19 +4,18 @@ [ext_resource type="Texture2D" uid="uid://mi70lolgtf3n" path="res://src/items/throwable/textures/GEOMANCER-DICE.png" id="2_alcjn"] [sub_resource type="BoxShape3D" id="BoxShape3D_s4ym5"] -size = Vector3(0.288967, 0.302734, 0.28064) +size = Vector3(1.43084, 1.23022, 1.52861) [node name="Hitbox" type="RigidBody3D"] collision_layer = 17 collision_mask = 16 -mass = 0.001 -gravity_scale = 0.0 +gravity_scale = 0.25 contact_monitor = true max_contacts_reported = 1 script = ExtResource("1_wlplc") [node name="CollisionShape3D" type="CollisionShape3D" parent="."] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00739601, 0.0986328, 0.137878) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0274667, 0.116821, 0.118644) shape = SubResource("BoxShape3D_s4ym5") [node name="Sprite" type="Sprite3D" parent="."]