mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:35:34 +00:00
66 lines
No EOL
1.8 KiB
C#
66 lines
No EOL
1.8 KiB
C#
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");
|
|
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>("AnimatedSprite2D");
|
|
|
|
|
|
}
|
|
|
|
public override bool CanActivate()
|
|
{
|
|
return State == ChestState.Closed;
|
|
}
|
|
} |