Files
the-peoples-messenger/Assets/Scripts/GuardManager.cs
T
2026-08-25 12:37:13 +01:00

108 lines
2.6 KiB
C#

using System;
using DefaultNamespace;
using UnityEditor;
using UnityEngine;
using Utils;
public class GuardManager : MonoBehaviour, IDescribable
{
public string type;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnDrawGizmos()
{
#if UNITY_EDITOR
Handles.Label(
transform.position + Vector3.up * 0f,
type
);
#endif
}
public QuestionAnswer Answer(string question)
{
//first get actual answer
var origAnswer = GetHonestAnswer(question);
if (type == "TRUTHER")
{
//if tell truth just return it
return origAnswer;
}
else if (type == "LIAR")
{
//if tell lies invert it
return origAnswer switch
{
QuestionAnswer.YES => QuestionAnswer.NO,
QuestionAnswer.NO => QuestionAnswer.YES,
QuestionAnswer.NO_YES => QuestionAnswer.NO_YES // i think? since we cannot confidently lie?
};
}
else
{//add joker at some point
throw new NotImplementedException();
}
}
private QuestionAnswer GetHonestAnswer(string question)
{
//first get wether to think about another guard
if (question[2] == '%')
{
if (question[0] == 'G')
{
Debug.Log(question);
Debug.Log(question.Substring(1,1));
int index = int.Parse(question.Substring(1,1));
var guard = LevelLoader.Instance.Guards[index];
return guard.Answer(question.Substring(3));
}
else
{
throw new NotImplementedException();
}
}
//if not get a property
else if (question[2] == '#')
{
if (question[0] == 'D')
{
int index = int.Parse(question.Substring(1,1));
var door = LevelLoader.Instance.Doors[index];
return door.GetProperty(question.Substring(3));
}
else
{
throw new NotImplementedException();
}
}
else
{
throw new NotImplementedException();
}
}
public string GetName()
{
return type;
}
public string GetDescription()
{
return "Describe " + type;
}
}