mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 08:35:34 +00:00
46 lines
No EOL
1 KiB
C#
46 lines
No EOL
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;
|
|
}
|
|
|
|
} |