134 lines
2.4 KiB
C#
134 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using Godot;
|
|
using Godot.Bridge;
|
|
using Godot.Collections;
|
|
using Godot.NativeInterop;
|
|
|
|
[ScriptPath("res://Scripts/Check.cs")]
|
|
public partial class Check : Area2D, Interacteable
|
|
{
|
|
[Signal]
|
|
public delegate void OnTriggerEventHandler();
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private string diag;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public Array<SaveFile.Flags> neededFlags;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public Array<SaveFile.Flags> limitFlags;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public SaveFile.Flags setFlag = SaveFile.Flags.None;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public bool callEvent;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public bool playerTouch;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public bool once;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public bool destroyOnLoad;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Node2D lookAt;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Vector2 moveAtEnd;
|
|
|
|
public bool touched;
|
|
|
|
|
|
public override void _EnterTree()
|
|
{
|
|
if (destroyOnLoad && !SaveFile.CanDo(neededFlags, limitFlags))
|
|
{
|
|
QueueFree();
|
|
}
|
|
else
|
|
{
|
|
base.BodyEntered += OnTriggerEnter;
|
|
}
|
|
}
|
|
|
|
public bool CanDo()
|
|
{
|
|
if (!TextSystem.instance.Visible && SaveFile.CanDo(neededFlags, limitFlags))
|
|
{
|
|
return playerTouch == touched;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public virtual void Interact()
|
|
{
|
|
if (!callEvent && (diag == null || diag.Length == 0))
|
|
{
|
|
Player.instance.canInput = true;
|
|
return;
|
|
}
|
|
if (CanDo())
|
|
{
|
|
if (setFlag != SaveFile.Flags.None)
|
|
{
|
|
SaveFile.AddFlag(setFlag);
|
|
}
|
|
if (callEvent)
|
|
{
|
|
if (HasMeta("Blocker"))
|
|
{
|
|
Main.inEvent = Coroutine.Start(CommonEvents.Blocker(diag, lookAt.GlobalPosition));
|
|
}
|
|
else if (GetSignalConnectionList(SignalName.OnTrigger).Count <= 1 && diag.Length > 1)
|
|
{
|
|
CommonEvents.DoEvent(diag);
|
|
}
|
|
else
|
|
{
|
|
EmitSignal(SignalName.OnTrigger);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
TextSystem.GetText(diag);
|
|
SaveFile.AddFlag(setFlag);
|
|
}
|
|
CallDeferred("StopMove");
|
|
}
|
|
else
|
|
{
|
|
Player.instance.canInput = true;
|
|
}
|
|
touched = false;
|
|
if (once)
|
|
{
|
|
QueueFree();
|
|
}
|
|
}
|
|
|
|
private void StopMove()
|
|
{
|
|
Party.StopMoving();
|
|
if (lookAt != null && !HasMeta("Blocker"))
|
|
{
|
|
Party.LookAt(lookAt.GlobalPosition);
|
|
}
|
|
}
|
|
|
|
private void OnTriggerEnter(Node other)
|
|
{
|
|
if (playerTouch && other == Player.instance?.controlling)
|
|
{
|
|
touched = true;
|
|
Interact();
|
|
}
|
|
}
|
|
|
|
}
|