Chest contents in trenchbroom

This commit is contained in:
Marco 2025-06-27 09:08:00 +02:00
commit 4cc7a0c004
7 changed files with 509 additions and 452 deletions

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

View file

@ -19,7 +19,9 @@ classname = "actor_chest_1"
description = "Chest Type 1"
func_godot_internal = false
base_classes = Array[Resource]([ExtResource("1_6p0lm")])
class_properties = {}
class_properties = {
"items": ""
}
class_property_descriptions = {}
auto_apply_to_matching_node_properties = false
meta_properties = {

View file

@ -1,19 +1,33 @@
using Cirno.Scripts.Interactables;
using System.Linq;
using Cirno.Scripts.Interactables;
using Cirno.Scripts.Resources;
using Godot;
using Godot.Collections;
namespace Cirno.Scripts.Components.Actors._3D;
[Tool]
public partial class Chest3D : Interactable3D
{
[Export] public Array<LootItem> LootTable = [];
[Export] public Array<StringName> LootKeys = [];
[Export] public ChestState State = ChestState.Closed;
[Signal] public delegate void OpenChestEventHandler();
[Signal] public delegate void CloseChestEventHandler();
public void _func_godot_apply_properties(Dictionary<string, string> props)
{
if (props.TryGetValue("items", out var items) && !string.IsNullOrWhiteSpace(items))
{
var itemsArray = items.Split(',');
LootKeys = new Array<StringName>(itemsArray.Select(x => new StringName(x)));
}
//TargetFunc = props["targetfunc"];
//TargetName = props["targetname"];
}
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
{
GD.Print("Attempting to open chest");
@ -23,6 +37,11 @@ public partial class Chest3D : Interactable3D
{
InventoryManager.Instance.AddItem(item);
}
foreach (var key in LootKeys)
{
InventoryManager.Instance.AddItem(key);
}
EmitSignalOpenChest();
//_sprite.Play("Opening");

View file

@ -115,6 +115,18 @@ public partial class InventoryManager : Node
return dbItem != null;
}
public bool AddItem(string itemKey)
{
var i = FindItemInDb(itemKey);
if (i is null)
{
GD.Print($"{itemKey} not found in DB");
return false;
}
return AddItem(i);
}
public bool AddItem(LootItem item)
{
//var item = new LootItem() { Item = type, Amount = amount };