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; public string puzzle; private Light focusLight; public int isfocussed; // 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); } focusLight = transform.FindChildRecursive("FocusLight").GetComponent(); } // Update is called once per frame void Update() { if (isfocussed == 2 && focusLight.intensity < 200) { focusLight.intensity += Time.deltaTime * 100; } else if (isfocussed == 1 && focusLight.intensity < 100) { focusLight.intensity += Time.deltaTime * 100; } else if (isfocussed == 0 && focusLight.intensity > 30) { focusLight.intensity -= Time.deltaTime * 100; } } 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 if (question == "RANDOM") { return Random.value > 0.5? QuestionAnswer.YES : QuestionAnswer.NO; } else { throw new NotImplementedException(); } } public string GetName() { return type; } public string GetDescribeName() { if (!string.IsNullOrEmpty(mod)) { return mod; } else { return "plain guard"; } } 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 if (mod == "#LEFTHORSE") { return "the left horse"; } else if (mod == "#RIGHTHORSE") { return "the right horse"; } 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.StartsWith("truth")) { answer = type == "TRUTHER" ? QuestionAnswer.YES : QuestionAnswer.NO; } if (property.StartsWith("horse")) { answer = QuestionAnswer.YES; } 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; } }