113 lines
2.3 KiB
C#
113 lines
2.3 KiB
C#
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using Godot;
|
|
using Godot.Bridge;
|
|
using Godot.Collections;
|
|
using Godot.NativeInterop;
|
|
|
|
[ScriptPath("res://Scripts/Entities/NPC.cs")]
|
|
public partial class NPC : Entity, Interacteable
|
|
{
|
|
[Export(PropertyHint.None, "")]
|
|
public Array<SaveFile.Flags> spawn;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public Array<SaveFile.Flags> despawn;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public int[] neededVar;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public IDs neededCapture = IDs.None;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public Area2D radius;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public IBehaviour[] behaviours;
|
|
|
|
public IBehaviour current;
|
|
|
|
private bool playerIn;
|
|
|
|
public override void _EnterTree()
|
|
{
|
|
if ((spawn != null && spawn.Count != 0 && !SaveFile.HasFlags(spawn)) || (despawn != null && despawn.Count != 0 && SaveFile.HasFlags(despawn)) || (neededCapture != IDs.None && !SaveFile.current.apprehended.Contains(neededCapture)))
|
|
{
|
|
QueueFree();
|
|
return;
|
|
}
|
|
base._EnterTree();
|
|
IBehaviour[] array = behaviours;
|
|
if (array != null && array.Length != 0)
|
|
{
|
|
for (int i = 0; i < behaviours.Length; i++)
|
|
{
|
|
behaviours[i].parent = this;
|
|
}
|
|
}
|
|
Room.current.entities.Add(this);
|
|
if (radius != null)
|
|
{
|
|
radius.Monitorable = false;
|
|
radius.BodyEntered += OnTriggerEnter;
|
|
radius.BodyExited += OnTriggerExit;
|
|
}
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
base._Process(delta);
|
|
if (!TextSystem.instance.Visible && (Main.inEvent == null || Main.inEvent.done) && !IsQueuedForDeletion())
|
|
{
|
|
if (current == null)
|
|
{
|
|
GetNext(IBehaviour.Triggers.Always);
|
|
}
|
|
else
|
|
{
|
|
current.Do();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Interact()
|
|
{
|
|
GetNext(IBehaviour.Triggers.Interact);
|
|
}
|
|
|
|
private void GetNext(IBehaviour.Triggers trigger)
|
|
{
|
|
if (behaviours == null || behaviours.Length == 0)
|
|
{
|
|
if (trigger == IBehaviour.Triggers.Interact)
|
|
{
|
|
Player.instance.canInput = true;
|
|
}
|
|
return;
|
|
}
|
|
for (int num = behaviours.Length - 1; num >= 0; num--)
|
|
{
|
|
if (behaviours[num].trigger == trigger && SaveFile.CanDo(behaviours[num].needs, behaviours[num].limit))
|
|
{
|
|
current = behaviours[num];
|
|
behaviours[num].Do();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnTriggerEnter(Node other)
|
|
{
|
|
if (other is Player)
|
|
{
|
|
GetNext(IBehaviour.Triggers.Range);
|
|
}
|
|
}
|
|
|
|
private void OnTriggerExit(Node other)
|
|
{
|
|
}
|
|
|
|
}
|