Add more floors, light refactoring
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
namespace GameJamDungeon;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace GameJamDungeon;
|
||||
|
||||
public interface IEquipableItem : IInventoryItem
|
||||
{
|
||||
public void Equip();
|
||||
|
||||
public void Unequip();
|
||||
public ImmutableList<ItemTag> ItemTags { get; }
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Chickensoft.Collections;
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Collections;
|
||||
using Chickensoft.GodotNodeInterfaces;
|
||||
using Godot;
|
||||
using System;
|
||||
@@ -31,24 +32,18 @@ public interface IInventory : INode
|
||||
event Inventory.InventoryAtCapacityEventHandler InventoryAtCapacity;
|
||||
|
||||
event Inventory.PickedUpItemEventHandler PickedUpItem;
|
||||
|
||||
event Inventory.AccessoryUnequippedEventHandler AccessoryUnequipped;
|
||||
|
||||
event Inventory.RaiseStatRequestEventHandler RaiseStatRequest;
|
||||
}
|
||||
|
||||
public partial class Inventory : Node, IInventory
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
// TODO: Constants class with export
|
||||
private const int _maxInventorySize = 20;
|
||||
|
||||
[Signal]
|
||||
public delegate void InventoryAtCapacityEventHandler(string rejectedItemName);
|
||||
[Signal]
|
||||
public delegate void AccessoryUnequippedEventHandler(Accessory unequippedAccessory);
|
||||
[Signal]
|
||||
public delegate void RaiseStatRequestEventHandler(ConsumableItemStats consumableItemStats);
|
||||
[Signal]
|
||||
public delegate void PickedUpItemEventHandler(string pickedUpItemName);
|
||||
|
||||
public Inventory()
|
||||
@@ -56,6 +51,27 @@ public partial class Inventory : Node, IInventory
|
||||
Items = [];
|
||||
}
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
EquippedWeapon.Changed += EquippedWeapon_Changed;
|
||||
EquippedArmor.Changed += EquippedArmor_Changed;
|
||||
EquippedAccessory.Changed += EquippedAccessory_Changed;
|
||||
}
|
||||
|
||||
private void EquippedAccessory_Changed(Accessory obj)
|
||||
{
|
||||
}
|
||||
|
||||
private void EquippedArmor_Changed(Armor obj)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private void EquippedWeapon_Changed(Weapon obj)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<IInventoryItem> Items { get; private set; }
|
||||
|
||||
public IAutoProp<Weapon> EquippedWeapon => _equippedWeapon;
|
||||
@@ -96,21 +112,17 @@ public partial class Inventory : Node, IInventory
|
||||
|
||||
public void Unequip(IEquipableItem equipable)
|
||||
{
|
||||
if (equipable is Weapon weapon)
|
||||
{
|
||||
if (equipable is Weapon)
|
||||
_equippedWeapon.OnNext(new Weapon());
|
||||
if (weapon.WeaponTags.Contains(WeaponTag.BreaksOnChange))
|
||||
Items.Remove(weapon);
|
||||
}
|
||||
else if (equipable is Armor armor)
|
||||
else if (equipable is Armor)
|
||||
_equippedArmor.OnNext(new Armor());
|
||||
else if (equipable is Accessory accessory)
|
||||
{
|
||||
EmitSignal(SignalName.AccessoryUnequipped, _equippedAccessory.Value);
|
||||
else if (equipable is Accessory)
|
||||
_equippedAccessory.OnNext(new Accessory());
|
||||
}
|
||||
else
|
||||
throw new NotImplementedException("Item type is not supported.");
|
||||
|
||||
if (equipable.ItemTags.Contains(ItemTag.BreaksOnChange))
|
||||
Remove(equipable);
|
||||
}
|
||||
|
||||
public bool IsEquipped(IEquipableItem equipable)
|
||||
|
||||
@@ -26,4 +26,7 @@ public partial class InventoryItemStats : Resource
|
||||
|
||||
[Export(PropertyHint.Range, "0, 999, 1")]
|
||||
public int ThrowDamage { get; set; } = 5;
|
||||
|
||||
[Export]
|
||||
public Godot.Collections.Array<ItemTag> ItemTags { get; set; } = new Godot.Collections.Array<ItemTag>();
|
||||
}
|
||||
@@ -43,6 +43,8 @@ public partial class Accessory : Node3D, IEquipableItem
|
||||
|
||||
public ImmutableList<AccessoryTag> AccessoryTags => [.. _accessoryStats.AccessoryTags];
|
||||
|
||||
public ImmutableList<ItemTag> ItemTags => [.. _accessoryStats.ItemTags];
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
Pickup.BodyEntered += OnEntered;
|
||||
@@ -54,16 +56,6 @@ public partial class Accessory : Node3D, IEquipableItem
|
||||
_accessoryStats = (AccessoryStats)inventoryItemStats;
|
||||
}
|
||||
|
||||
public void Equip()
|
||||
{
|
||||
GameEventDepot.OnEquippedAccessory(this);
|
||||
}
|
||||
|
||||
public void Unequip()
|
||||
{
|
||||
GameEventDepot.OnUnequippedAccessory();
|
||||
}
|
||||
|
||||
public void Throw()
|
||||
{
|
||||
Player.Inventory.Remove(this);
|
||||
|
||||
@@ -2,6 +2,7 @@ using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace GameJamDungeon;
|
||||
|
||||
@@ -10,8 +11,6 @@ public partial class Armor : Node3D, IEquipableItem
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Dependency] public IGameEventDepot GameEventDepot => this.DependOn<IGameEventDepot>();
|
||||
|
||||
[Dependency] public IPlayer Player => this.DependOn<IPlayer>();
|
||||
|
||||
[Export] private ArmorStats _armorStats { get; set; } = new ArmorStats();
|
||||
@@ -36,6 +35,8 @@ public partial class Armor : Node3D, IEquipableItem
|
||||
|
||||
public int Defense => _armorStats.Defense;
|
||||
|
||||
public ImmutableList<ItemTag> ItemTags => [.. _armorStats.ItemTags];
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
Pickup.BodyEntered += OnEntered;
|
||||
@@ -47,16 +48,6 @@ public partial class Armor : Node3D, IEquipableItem
|
||||
_armorStats = (ArmorStats)inventoryItemStats;
|
||||
}
|
||||
|
||||
public void Equip()
|
||||
{
|
||||
GameEventDepot.OnEquippedArmor(this);
|
||||
}
|
||||
|
||||
public void Unequip()
|
||||
{
|
||||
GameEventDepot.OnUnequippedArmor();
|
||||
}
|
||||
|
||||
public void Throw()
|
||||
{
|
||||
Player.Inventory.Remove(this);
|
||||
|
||||
@@ -10,9 +10,6 @@ public partial class ConsumableItem : Node3D, IUsableItem
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Signal]
|
||||
public delegate void RaiseStatRequestEventHandler(ConsumableItemStats consumableItemStats);
|
||||
|
||||
[Dependency] public IGame Game => this.DependOn<IGame>();
|
||||
|
||||
[Dependency] public IPlayer Player => this.DependOn<IPlayer>();
|
||||
@@ -40,15 +37,15 @@ public partial class ConsumableItem : Node3D, IUsableItem
|
||||
|
||||
public void Use()
|
||||
{
|
||||
if (_consumableItemStats.RaiseHPAmount > 0)
|
||||
Game.RaiseHP(_consumableItemStats.RaiseHPAmount);
|
||||
if (_consumableItemStats.RaiseVTAmount > 0)
|
||||
Game.RaiseVT(_consumableItemStats.RaiseVTAmount);
|
||||
if (Player.Stats.CurrentHP.Value == Player.Stats.MaximumHP.Value && _consumableItemStats.RaiseHPAmount > 0)
|
||||
Player.RaiseHP(_consumableItemStats.RaiseHPAmount);
|
||||
if (Player.Stats.CurrentVT.Value == Player.Stats.MaximumVT.Value && _consumableItemStats.RaiseVTAmount > 0)
|
||||
Player.RaiseVT(_consumableItemStats.RaiseVTAmount);
|
||||
|
||||
if (_consumableItemStats.HealHPAmount > 0 && Player.Stats.CurrentHP.Value != Player.Stats.MaximumHP.Value)
|
||||
Game.HealHP(_consumableItemStats.HealHPAmount);
|
||||
Player.HealHP(_consumableItemStats.HealHPAmount);
|
||||
if (_consumableItemStats.HealVTAmount > 0 && Player.Stats.CurrentVT.Value != Player.Stats.MaximumVT.Value)
|
||||
Game.HealVT(_consumableItemStats.HealVTAmount);
|
||||
Player.HealVT(_consumableItemStats.HealVTAmount);
|
||||
}
|
||||
|
||||
public void SetItemStats(InventoryItemStats inventoryItemStats)
|
||||
|
||||
@@ -32,11 +32,11 @@ public partial class DroppedItem : RigidBody3D, IDroppedItem
|
||||
|
||||
public async void Drop()
|
||||
{
|
||||
AddCollisionExceptionWith((Node)Game.Player);
|
||||
AddCollisionExceptionWith((Node)Player);
|
||||
GlobalPosition = Player.CurrentPosition + Vector3.Up;
|
||||
ApplyCentralImpulse(-Player.CurrentBasis.Z.Normalized() * 5.0f);
|
||||
await ToSignal(GetTree().CreateTimer(1.5), "timeout");
|
||||
RemoveCollisionExceptionWith((Node)Game.Player);
|
||||
RemoveCollisionExceptionWith((Node)Player);
|
||||
}
|
||||
|
||||
public void RescueItem()
|
||||
|
||||
@@ -63,9 +63,9 @@ public partial class ThrowableItem : Node3D, IUsableItem
|
||||
public void Use()
|
||||
{
|
||||
if (_throwableItemStats.HealHPAmount > 0)
|
||||
Game.HealHP(_throwableItemStats.HealHPAmount);
|
||||
Player.HealHP(_throwableItemStats.HealHPAmount);
|
||||
if (_throwableItemStats.HealVTAmount > 0)
|
||||
Game.HealVT(_throwableItemStats.HealVTAmount);
|
||||
Player.HealVT(_throwableItemStats.HealVTAmount);
|
||||
|
||||
if (_throwableItemStats.UsableItemTags.Contains(UsableItemTag.DoubleEXP))
|
||||
Game.DoubleEXP(TimeSpan.FromSeconds(30));
|
||||
|
||||
@@ -45,6 +45,8 @@ public partial class Weapon : Node3D, IInventoryItem, IEquipableItem
|
||||
|
||||
public ImmutableList<WeaponTag> WeaponTags => [.. _weaponStats.WeaponTags];
|
||||
|
||||
public ImmutableList<ItemTag> ItemTags => [.. _weaponStats.ItemTags];
|
||||
|
||||
public ElementType WeaponElement => _weaponStats.WeaponElement;
|
||||
|
||||
public double ElementalDamageBonus => _weaponStats.ElementalDamageBonus;
|
||||
@@ -62,16 +64,6 @@ public partial class Weapon : Node3D, IInventoryItem, IEquipableItem
|
||||
Sprite.Texture = texture;
|
||||
}
|
||||
|
||||
public void Equip()
|
||||
{
|
||||
EmitSignal(SignalName.EquippedItem, this);
|
||||
}
|
||||
|
||||
public void Unequip()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Throw()
|
||||
{
|
||||
Player.Inventory.Remove(this);
|
||||
|
||||
Reference in New Issue
Block a user