cirnogodot/Scenes/Interactable.cs

56 lines
1.2 KiB
C#
Raw Normal View History

2024-06-09 18:19:57 +02:00
using Godot;
using System;
using System.Diagnostics;
using System.Linq;
2025-02-07 14:58:59 +01:00
using Cirno.Scripts;
2025-03-09 19:25:09 +01:00
using Cirno.Scripts.Interactables;
using Cirno.Scripts.Resources;
using Godot.Collections;
2024-06-09 18:19:57 +02:00
2025-03-09 19:25:09 +01:00
public partial class Interactable : Area2D, IInteractable
2024-06-09 18:19:57 +02:00
{
2025-03-02 15:37:14 +01:00
[Export] public Array<LootItem> Requirements = [];
2025-03-02 16:48:18 +01:00
//protected InventoryManager _inventoryManager;
2025-01-20 21:58:59 +01:00
public override void _Ready()
{
2025-03-02 16:48:18 +01:00
//_inventoryManager = this.GetInventoryManager();
//CallDeferred(MethodName.DeferredInitReferences);
2025-01-20 21:58:59 +01:00
}
2024-06-09 18:19:57 +02:00
2025-03-02 16:48:18 +01:00
// private void DeferredInitReferences()
// {
// _inventoryManager = InventoryManager.Instance;
// }
protected bool MeetsRequirements()
2024-06-09 18:19:57 +02:00
{
if (Requirements.Any())
2025-01-20 21:58:59 +01:00
{
2025-03-02 16:48:18 +01:00
if (InventoryManager.Instance.HasItems(Requirements.Select(x => x.ItemKey).ToList()))
{
GD.Print($"Requirements for activation of {this.Name} successfully met: {string.Join(",", Requirements.Select(x => x.Item))} ");
return true;
}
else
{
GD.Print($"Requirements for activation of {this.Name} not met: {string.Join(",", Requirements.Select(x => x.Item))} ");
return false;
}
2025-01-20 21:58:59 +01:00
}
return true;
}
2025-01-30 17:43:39 +01:00
public virtual bool Activate()
{
2025-01-30 17:43:39 +01:00
return true;
}
public virtual bool CanActivate()
{
return true;
2024-06-09 18:19:57 +02:00
}
}