Fix up item usage
This commit is contained in:
@@ -5,16 +5,17 @@ using Chickensoft.Serialization;
|
||||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
public interface IInventory : INode
|
||||
{
|
||||
public List<InventoryItem> Items { get; }
|
||||
public List<IInventoryItem> Items { get; }
|
||||
|
||||
public bool TryAdd(InventoryItem inventoryItem);
|
||||
public bool TryAdd(IInventoryItem inventoryItem);
|
||||
|
||||
public void Remove(InventoryItem inventoryItem);
|
||||
public void Remove(IInventoryItem inventoryItem);
|
||||
|
||||
public void Sort();
|
||||
}
|
||||
@@ -33,9 +34,9 @@ public partial class Inventory : Node, IInventory
|
||||
}
|
||||
|
||||
[Save("inventory_items")]
|
||||
public List<InventoryItem> Items { get; private set; }
|
||||
public List<IInventoryItem> Items { get; private set; }
|
||||
|
||||
public bool TryAdd(InventoryItem inventoryItem)
|
||||
public bool TryAdd(IInventoryItem inventoryItem)
|
||||
{
|
||||
if (Items.Count >= _maxInventorySize)
|
||||
return false;
|
||||
@@ -44,15 +45,15 @@ public partial class Inventory : Node, IInventory
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Remove(InventoryItem inventoryItem) => Items.Remove(inventoryItem);
|
||||
public void Remove(IInventoryItem inventoryItem) => Items.Remove(inventoryItem);
|
||||
|
||||
|
||||
public void Sort()
|
||||
{
|
||||
var equippedWeapon = Items.OfType<Weapon>().Where(x => x.IsEquipped);
|
||||
var equippedArmor = Items.OfType<Armor>().Where(x => x.IsEquipped);
|
||||
var equippedAccessory = Items.OfType<Accessory>().Where(x => x.IsEquipped);
|
||||
var equippedItems = new List<InventoryItem>();
|
||||
var equippedWeapon = Items.OfType<Weapon>().Where(x => x.IsEquipped).Cast<IInventoryItem>();
|
||||
var equippedArmor = Items.OfType<Armor>().Where(x => x.IsEquipped).Cast<IInventoryItem>();
|
||||
var equippedAccessory = Items.OfType<Accessory>().Where(x => x.IsEquipped).Cast<IInventoryItem>();
|
||||
var equippedItems = new List<IInventoryItem>();
|
||||
equippedItems.AddRange(equippedWeapon);
|
||||
equippedItems.AddRange(equippedArmor);
|
||||
equippedItems.AddRange(equippedAccessory);
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
using Chickensoft.Serialization;
|
||||
using Godot;
|
||||
using System;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
[Meta]
|
||||
public abstract partial class InventoryItem : Node3D
|
||||
public abstract partial class InventoryItem : Node3D, IInventoryItem
|
||||
{
|
||||
[Save("inventory_item_id")]
|
||||
public Guid ID => Guid.NewGuid();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Chickensoft.GodotNodeInterfaces;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
@@ -23,12 +24,12 @@ public partial class DroppedItem : RigidBody3D, IDroppedItem
|
||||
|
||||
[Node] private Area3D Pickup { get; set; } = default!;
|
||||
|
||||
public InventoryItem Item { get; set; }
|
||||
public IInventoryItem Item { get; set; }
|
||||
|
||||
public void OnResolved()
|
||||
{
|
||||
ContactMonitor = true;
|
||||
Sprite.Texture = Item.ItemStats.Texture;
|
||||
Sprite.Texture = ((InventoryItem)Item).ItemStats.Texture;
|
||||
}
|
||||
|
||||
public async void Drop()
|
||||
|
||||
@@ -3,6 +3,7 @@ using Chickensoft.Introspection;
|
||||
using Zennysoft.Game.Ma.src.items;
|
||||
using Godot;
|
||||
using Zennysoft.Game.Ma.Implementation;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
@@ -15,7 +16,7 @@ public partial class ThrownItem : RigidBody3D
|
||||
|
||||
[Dependency] public IGame Game => this.DependOn<IGame>();
|
||||
|
||||
public InventoryItem ItemThatIsThrown;
|
||||
public IInventoryItem ItemThatIsThrown;
|
||||
|
||||
private EffectService _effectService;
|
||||
|
||||
@@ -25,7 +26,7 @@ public partial class ThrownItem : RigidBody3D
|
||||
{
|
||||
BodyEntered += ThrownItem_BodyEntered;
|
||||
GlobalPosition = Player.CurrentPosition;
|
||||
Sprite.Texture = ItemThatIsThrown.ItemStats.Texture;
|
||||
Sprite.Texture = ((InventoryItem)ItemThatIsThrown).ItemStats.Texture;
|
||||
AddCollisionExceptionWith((Node)Player);
|
||||
}
|
||||
|
||||
@@ -39,7 +40,7 @@ public partial class ThrownItem : RigidBody3D
|
||||
public void Throw(EffectService effectService)
|
||||
{
|
||||
_effectService = effectService;
|
||||
ApplyCentralImpulse(-Player.CurrentBasis.Z.Normalized() * ItemThatIsThrown.ThrowSpeed);
|
||||
ApplyCentralImpulse(-Player.CurrentBasis.Z.Normalized() * ((InventoryItem)ItemThatIsThrown).ThrowSpeed);
|
||||
}
|
||||
|
||||
public void RescueItem()
|
||||
@@ -100,6 +101,6 @@ public partial class ThrownItem : RigidBody3D
|
||||
}
|
||||
}
|
||||
else
|
||||
enemy.TakeDamage(ItemThatIsThrown.ThrowDamage);
|
||||
enemy.TakeDamage(((InventoryItem)ItemThatIsThrown).ThrowDamage);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user