mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
73 lines
No EOL
2.1 KiB
C#
73 lines
No EOL
2.1 KiB
C#
using System.Linq;
|
|
using Cirno.Scripts.Misc;
|
|
using Cirno.Scripts.Resources;
|
|
using Godot;
|
|
using Godot.Collections;
|
|
|
|
namespace Cirno.Scripts.Interactables;
|
|
|
|
[Tool]
|
|
public partial class Interactable3D : Area3D, IInteractable
|
|
{
|
|
[Export] public Array<LootItem> Requirements = [];
|
|
[Export] public Array<StringName> RequirementKeys = [];
|
|
|
|
public virtual bool Activate(ActivationType activationType = ActivationType.Toggle)
|
|
{
|
|
return MeetsRequirements();
|
|
}
|
|
|
|
protected virtual bool MeetsRequirements()
|
|
{
|
|
if (Requirements.Count != 0)
|
|
{
|
|
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;
|
|
}
|
|
|
|
}
|
|
|
|
if (RequirementKeys.Count != 0)
|
|
{
|
|
if (InventoryManager.Instance.HasItems(RequirementKeys.Select(x => x.ToString()).ToList()))
|
|
{
|
|
GD.Print($"Requirements for activation of {this.Name} successfully met: {string.Join(",", RequirementKeys.Select(x => x))} ");
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
GD.Print($"Requirements for activation of {this.Name} not met: {string.Join(",", RequirementKeys.Select(x => x))} ");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public virtual bool CanActivate()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public Vector2 GetGlobalPosition2D()
|
|
{
|
|
return new Vector2(this.GlobalPosition.X, this.GlobalPosition.Z);
|
|
}
|
|
|
|
public Vector2 GetScreenPosition()
|
|
{
|
|
if (CameraController3D.Instance is null)
|
|
{
|
|
return this.GetGlobalPosition2D();
|
|
}
|
|
|
|
return CameraController3D.Instance.UnprojectPosition(this.GlobalPosition);
|
|
}
|
|
} |