fix enemies sharing inventories

This also fixes an issue where enemies do not have weapons as their
shared inventory is full and therefore can not equip any item.
pull/3/head
John Montagu, the 4th Earl of Sandvich 2023-05-28 12:07:19 -07:00
parent 39d4069aa1
commit 423c3e3b17
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
3 changed files with 24 additions and 16 deletions

View File

@ -12,6 +12,7 @@
[ext_resource type="AudioStream" uid="uid://njun3e6v4854" path="res://Assets/Sounds/hurt.wav" id="10_n1e64"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_ms3xg"]
resource_local_to_scene = true
shader = ExtResource("1_fx1w5")
shader_parameter/color = Quaternion(1, 1, 1, 1)
shader_parameter/intensity = 0.0
@ -49,6 +50,7 @@ atlas = ExtResource("3_ocaae")
region = Rect2(168, 0, 24, 24)
[sub_resource type="SpriteFrames" id="SpriteFrames_6pejo"]
resource_local_to_scene = true
animations = [{
"frames": [{
"duration": 1.0,
@ -177,7 +179,6 @@ shape = SubResource("RectangleShape2D_8lxmf")
[node name="Inventory" type="Node2D" parent="."]
y_sort_enabled = true
script = ExtResource("7_43gq8")
Items = [null]
[node name="Sword" parent="Inventory" instance=ExtResource("8_s3c8r")]
Knockback = 100.0

View File

@ -203,6 +203,7 @@ horizontal_alignment = 1
y_sort_enabled = true
position = Vector2(0, 4)
script = ExtResource("7_xyenu")
Items = Array[Node2D]([])
InventoryMap = {
"equip_1": 0,
"equip_2": 1

View File

@ -9,7 +9,7 @@ namespace SupaLidlGame.Items
public Character Character { get; private set; }
[Export]
public Array<Item> Items { get; private set; } = new Array<Item>();
public Array<Item> Items { get; private set; }
[Export]
public Dictionary<string, int> InventoryMap { get; set; }
@ -43,6 +43,26 @@ namespace SupaLidlGame.Items
InventoryMap.Add("equip_3", 2);
}
public override void _Ready()
{
if (Items is null)
{
// instantiating a new array will prevent characters from
// sharing inventories
Items = new Array<Item>();
}
Character = GetParent<Character>();
foreach (Node child in GetChildren())
{
if (child is Item item)
{
GD.Print("Adding item " + item.Name);
AddItem(item);
}
}
base._Ready();
}
private bool EquipItem(Item item, ref Item slot)
{
if (item is not null)
@ -122,19 +142,5 @@ namespace SupaLidlGame.Items
var e = SelectedItem = item;
throw new System.NotImplementedException();
}
public override void _Ready()
{
Character = GetParent<Character>();
foreach (Node child in GetChildren())
{
if (child is Item item)
{
GD.Print("Adding item " + item.Name);
AddItem(item);
}
}
base._Ready();
}
}
}