59 lines
1.5 KiB
C#
59 lines
1.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.InteropServices;
|
|
using Ktyl.Util;
|
|
using UnityEngine;
|
|
|
|
[CreateAssetMenu(menuName = "KernelPanic/Artefacts/Artefact System")]
|
|
public class ArtefactSystem : ScriptableObject
|
|
{
|
|
[SerializeField] private DialogueSystem _dialogue;
|
|
[SerializeField] private ArtefactInventory _inventory;
|
|
[SerializeField] private SerialInt _nearbyArtefactId;
|
|
|
|
private readonly List<Artefact> _artefacts = new List<Artefact>();
|
|
|
|
public Artefact GetNearbyArtefact()
|
|
{
|
|
return _nearbyArtefactId == -1 ? null : GetArtefact(_nearbyArtefactId);
|
|
}
|
|
|
|
private Artefact GetArtefact(int id)
|
|
{
|
|
for (int i = 0; i < _artefacts.Count; i++)
|
|
{
|
|
if (_artefacts[i].artefactID == id) return _artefacts[i];
|
|
}
|
|
|
|
Debug.LogError($"no registered artefact with id {id}");
|
|
return null;
|
|
}
|
|
|
|
public void RegisterArtefact(Artefact artefact)
|
|
{
|
|
if (_artefacts.Contains(artefact))
|
|
{
|
|
// Debug.LogError($"{artefact} already registered", this);
|
|
return;
|
|
}
|
|
|
|
_artefacts.Add(artefact);
|
|
}
|
|
|
|
public void FindArtefact(Artefact artefact)
|
|
{
|
|
_inventory.addA(artefact);
|
|
|
|
if (artefact.OnFound)
|
|
{
|
|
artefact.OnFound.Raise();
|
|
}
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
_artefacts.Clear();
|
|
}
|
|
}
|