2021-03-05 14:26:15 +01:00
|
|
|
using System;
|
2021-02-23 14:05:42 +01:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2021-03-05 14:26:15 +01:00
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
using Ktyl.Util;
|
2021-02-23 14:05:42 +01:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
[CreateAssetMenu(menuName = "KernelPanic/Artefacts/Artefact System")]
|
|
|
|
public class ArtefactSystem : ScriptableObject
|
|
|
|
{
|
|
|
|
[SerializeField] private DialogueSystem _dialogue;
|
|
|
|
[SerializeField] private ArtefactInventory _inventory;
|
2021-03-05 14:26:15 +01:00
|
|
|
[SerializeField] private SerialInt _nearbyArtefactId;
|
|
|
|
|
|
|
|
private readonly List<Artefact> _artefacts = new List<Artefact>();
|
2021-04-27 01:57:07 +02:00
|
|
|
|
2021-03-05 14:26:15 +01:00
|
|
|
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))
|
|
|
|
{
|
2021-04-27 01:57:07 +02:00
|
|
|
// Debug.LogError($"{artefact} already registered", this);
|
2021-03-05 14:26:15 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_artefacts.Add(artefact);
|
|
|
|
}
|
2021-02-23 14:05:42 +01:00
|
|
|
|
|
|
|
public void FindArtefact(Artefact artefact)
|
|
|
|
{
|
|
|
|
_inventory.addA(artefact);
|
2021-04-16 20:30:49 +02:00
|
|
|
|
|
|
|
if (artefact.OnFound)
|
|
|
|
{
|
|
|
|
artefact.OnFound.Raise();
|
|
|
|
}
|
2021-02-23 14:05:42 +01:00
|
|
|
}
|
2021-03-05 14:26:15 +01:00
|
|
|
|
|
|
|
private void OnDisable()
|
|
|
|
{
|
|
|
|
_artefacts.Clear();
|
|
|
|
}
|
2021-02-23 14:05:42 +01:00
|
|
|
}
|