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 LootTable = []; [Export] public Array LootKeys = []; [Export] public ChestState State = ChestState.Closed; [Signal] public delegate void OpenChestEventHandler(); [Signal] public delegate void CloseChestEventHandler(); public void _func_godot_apply_properties(Dictionary props) { if (props.TryGetValue("items", out var items) && !string.IsNullOrWhiteSpace(items)) { var itemsArray = items.Split(','); LootKeys = new Array(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"); if (State != ChestState.Closed) return false; if (!MeetsRequirements()) return false; foreach (var item in LootTable) { InventoryManager.Instance.AddItem(item); } foreach (var key in LootKeys) { InventoryManager.Instance.AddItem(key); } EmitSignalOpenChest(); //_sprite.Play("Opening"); State = ChestState.Open; return true; } public override void _Ready() { base._Ready(); //_sprite = GetNode("AnimatedSprite2D"); } public override bool CanActivate() { return State == ChestState.Closed; } }