cirnogodot/Scripts/Chest.cs

46 lines
1 KiB
C#
Raw Normal View History

using Cirno.Scripts.Resources;
using Godot;
using Godot.Collections;
2025-01-28 14:05:38 +01:00
namespace Cirno.Scripts;
public partial class Chest : Interactable
2025-01-28 14:05:38 +01:00
{
[Export] public Array<LootItem> LootTable = new Array<LootItem>();
2025-01-30 17:43:39 +01:00
[Export] public ChestState State = ChestState.Closed;
private AnimatedSprite2D _sprite;
2025-01-28 14:05:38 +01:00
2025-03-09 21:58:25 +01:00
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
2025-01-28 14:05:38 +01:00
{
2025-01-30 17:43:39 +01:00
GD.Print("Attempting to open chest");
if (State != ChestState.Closed) return false;
if (!MeetsRequirements()) return false;
foreach (var item in LootTable)
{
2025-03-02 16:48:18 +01:00
InventoryManager.Instance.AddItem(item);
}
2025-01-30 17:43:39 +01:00
_sprite.Play("Opening");
State = ChestState.Open;
return true;
2025-01-28 14:05:38 +01:00
}
public override void _Ready()
2025-01-28 14:05:38 +01:00
{
base._Ready();
2025-01-30 17:43:39 +01:00
_sprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
}
public override bool CanActivate()
{
return State == ChestState.Closed;
2025-01-28 14:05:38 +01:00
}
2025-01-28 14:05:38 +01:00
}