using System; using DefaultNamespace; using UnityEditor; using UnityEngine; using Utils; using Random = UnityEngine.Random; public class GuardManager : MonoBehaviour, IDescribable { public string type; public string mod; public GameObject hat; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { if (mod == "SHORT") { transform.localScale = new Vector3(1f, 0.1f, 1f); } else if (mod == "HAT") { Instantiate(hat, transform); } } // 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 if (type == "JOKER") { return Random.value > 0.5? QuestionAnswer.YES : QuestionAnswer.NO; } throw new NotImplementedException(); } private QuestionAnswer GetHonestAnswer(string question) { //first get wether to think about another guard if (question[2] == '%') { if (question[0] == 'G') { 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 if (question[0] == 'G') { int index = int.Parse(question.Substring(1,1)); var guard = LevelLoader.Instance.Guards[index]; return guard.GetProperty(question.Substring(3)); } else { throw new NotImplementedException(); } } else { throw new NotImplementedException(); } } public string GetName() { return type; } public string GetDescription() { return "Describe " + type; } public string GetUnknownDescription() { if (mod == "SHORT") { return "the short guard"; } else if (mod == "HAT") { return "the guard with the hat"; } else { return "the plain guard"; } // add more modification here } public QuestionAnswer GetProperty(string property) { var answer = QuestionAnswer.NO_YES; if (property.StartsWith("hat")) { answer = mod == "HAT" ? QuestionAnswer.YES : QuestionAnswer.NO; } if (property.StartsWith("short")) { answer = mod == "SHORT" ? QuestionAnswer.YES : QuestionAnswer.NO; } if (property.EndsWith("!")) { //we want opposite, so switch return answer switch { QuestionAnswer.YES => QuestionAnswer.NO, QuestionAnswer.NO => QuestionAnswer.YES, QuestionAnswer.NO_YES => QuestionAnswer.NO_YES // i think? since we cannot confidently lie? }; } //else return base return answer; } }