cirnogodot/Scripts/Chest.cs

53 lines
No EOL
1.1 KiB
C#

using Cirno.Scripts.Resources;
using Godot;
using Godot.Collections;
namespace Cirno.Scripts;
public partial class Chest : Interactable
{
[Export] public Array<LootItem> LootTable = new Array<LootItem>();
[Export] public ChestState State = ChestState.Closed;
private AnimatedSprite2D _sprite;
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);
}
_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;
}
}
public enum ChestState
{
Closed,
Open,
Destroyed
}