Throw item
This commit is contained in:
@@ -13,6 +13,8 @@ public interface IGame : IProvide<IGameRepo>, IProvide<IGameEventDepot>, 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<PackedScene>("res://src/items/thrown/ThrownItem.tscn");
|
||||
var thrown = thrownScene.Instantiate<ThrownItem>();
|
||||
thrown.ThrownItemStats = item.Info;
|
||||
AddChild(thrown);
|
||||
thrown.Throw();
|
||||
}
|
||||
|
||||
private void OnEnemyDefeated(Vector3 vector, EnemyStatResource resource)
|
||||
{
|
||||
var restorativeScene = GD.Load<PackedScene>("res://src/items/restorative/Restorative.tscn");
|
||||
|
||||
@@ -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--;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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<PackedScene>("res://src/items/thrown/ThrownItem.tscn");
|
||||
var throwable = throwableScene.Instantiate<ThrownItem>();
|
||||
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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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="."]
|
||||
|
||||
Reference in New Issue
Block a user