cirnogodot/Scenes/Interactable.cs

73 lines
1.6 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;
2025-06-13 17:46:44 +02:00
using Cirno.Scripts.Misc;
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-03-23 17:08:04 +01:00
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-13 13:29:13 +01:00
if (InventoryManager.Instance.HasItems(Requirements.Select(x => x.ItemKey.ToString()).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-03-09 21:58:25 +01:00
public virtual bool Activate(ActivationType activationType = ActivationType.Toggle)
{
2025-01-30 17:43:39 +01:00
return true;
}
public virtual bool CanActivate()
{
return true;
2024-06-09 18:19:57 +02:00
}
2025-06-13 17:46:44 +02:00
public Vector2 GetScreenPosition()
{
if (CameraController.Instance is null)
{
return this.GlobalPosition;
}
return this.GlobalPosition - CameraController.Instance.GlobalPosition +
(GetViewport().GetVisibleRect().Size / 2);
}
public Vector2 GetGlobalPosition2D()
{
return GetGlobalPosition();
}
2024-06-09 18:19:57 +02:00
}