Add the ability to ask questions ABOUT the guards

This commit is contained in:
WillJeynes
2026-08-25 14:57:05 +01:00
parent 514ba1f26f
commit cf651447d3
18 changed files with 769 additions and 29 deletions
+35 -13
View File
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using DefaultNamespace;
using JetBrains.Annotations;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using TMPro;
using UnityEngine;
using UnityEngine.Rendering;
@@ -85,16 +86,29 @@ public class DialogManager : Singleton<DialogManager>
//special keywords
if (kvp.Key == "DOORS")
{
for (int i = 0; i < LevelLoader.Instance.Doors.Count; i++)
foreach (var man in LevelLoader.Instance.Doors)
{
PopulateSingleQuestionOption(new KeyValuePair<string, JToken>("door " + (i+1), kvp.Value));
PopulateSingleQuestionOption(new KeyValuePair<string, JToken>(man.GetUnknownDescription(), kvp.Value));
}
}
else if (kvp.Key == "GUARDS")
else if (kvp.Key.StartsWith("GUARDS"))
{
for (int i = 0; i < LevelLoader.Instance.Guards.Count; i++)
foreach (var man in LevelLoader.Instance.Guards)
{
PopulateSingleQuestionOption(new KeyValuePair<string, JToken>("guard " + (i+1), kvp.Value));
string postfix = "";
if (man == currentGuard)
{
if (kvp.Key.EndsWith("YOU"))
{
postfix = " (you)";
}
else
{
//this lowkey breaks most puzzes cause double negative makes all tell truth
continue;
}
}
PopulateSingleQuestionOption(new KeyValuePair<string, JToken>(man.GetUnknownDescription() + postfix, kvp.Value));
}
}
else if (kvp.Key == "QUESTION")
@@ -178,7 +192,7 @@ public class DialogManager : Singleton<DialogManager>
FullQuestion = FullQuestionPrefixes.Pop() + FullQuestion;
}
Debug.LogError(FullQuestion);
Debug.Log(FullQuestion);
string q = "";
string r = "";
@@ -189,22 +203,30 @@ public class DialogManager : Singleton<DialogManager>
q += item;
r = item + " " + r;
if (item.StartsWith("guard "))
int ig = LevelLoader.Instance.Guards.FindIndex(
guard => item.StartsWith(guard.GetUnknownDescription())
);
if (ig >= 0)
{
FullQuestion = FullQuestion.ReplaceLast("GS", "G" + (int.Parse(item[^1].ToString())-1));
FullQuestion = FullQuestion.ReplaceLast("GS", "G" + ig);
}
if (item.StartsWith("door "))
int id = LevelLoader.Instance.Doors.FindIndex(
door => item.StartsWith(door.GetUnknownDescription())
);
if (id >= 0)
{
FullQuestion = FullQuestion.ReplaceLast("DS", "D" + (int.Parse(item[^1].ToString())-1));
FullQuestion = FullQuestion.ReplaceLast("DS", "D" + id);
}
}
Debug.LogError(q);
Debug.LogError(FullQuestion);
Debug.Log(FullQuestion);
//now get a response from the guard being questioned
var response = currentGuard.Answer(FullQuestion);
Debug.Log(response);
r = r.Replace("NOREC_", "");
+23 -1
View File
@@ -1,3 +1,4 @@
using System;
using DefaultNamespace;
using UnityEditor;
using UnityEngine;
@@ -6,10 +7,22 @@ using Utils;
public class DoorManager : MonoBehaviour, IDescribable
{
public string type;
public string mod;
public Material blueMaterial;
public Material redMaterial;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
if (mod == "BLUE")
{
this.GetComponent<Renderer>().material = blueMaterial;
}
else if (mod == "RED")
{
this.GetComponent<Renderer>().material = redMaterial;
}
}
// Update is called once per frame
@@ -64,4 +77,13 @@ public class DoorManager : MonoBehaviour, IDescribable
{
return "Describe " + type;
}
public string GetUnknownDescription()
{
if (mod == "RED" || mod == "BLUE")
{
return $"the {mod} door";
} // add more modification here
throw new NotImplementedException();
}
}
+59 -3
View File
@@ -7,10 +7,21 @@ using Utils;
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
@@ -64,8 +75,6 @@ public class GuardManager : MonoBehaviour, IDescribable
{
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));
@@ -84,6 +93,12 @@ public class GuardManager : MonoBehaviour, IDescribable
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();
@@ -104,4 +119,45 @@ public class GuardManager : MonoBehaviour, IDescribable
{
return "Describe " + type;
}
public string GetUnknownDescription()
{
if (mod == "SHORT")
{
return "the short guard";
}
else if (mod == "HAT")
{
return "the guard with the hat";
}// add more modification here
throw new NotImplementedException();
}
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;
}
}
+2
View File
@@ -40,6 +40,7 @@ public class LevelLoader : Singleton<LevelLoader>
var manager = doorinstance.GetComponent<DoorManager>();
manager.type = data.doors[i].action;
manager.mod = data.doorsmods.GetRandomAndRemove();
Doors.Add(manager);
}
@@ -53,6 +54,7 @@ public class LevelLoader : Singleton<LevelLoader>
var manager = guardinstance.GetComponent<GuardManager>();
manager.type = data.guards[i].action;
manager.mod = data.guardsmods.GetRandomAndRemove();
Guards.Add(manager);
}
+2
View File
@@ -39,7 +39,9 @@ public class SpeechManager : Singleton<SpeechManager>
{
StopCoroutine(ccoroutine);
mainText.text = fulltext;
Status = fulltext.Length > 30 ? "DONELONG" : "DONE";
fulltext = null;
}
else if (textBuffer.Count > 0)
{
+2
View File
@@ -7,6 +7,8 @@ namespace Utils
{
public List<DoorData> doors;
public List<GuardData> guards;
public List<string> guardsmods;
public List<string> doorsmods;
}
[System.Serializable]
+13
View File
@@ -14,5 +14,18 @@ namespace Utils
(list[i], list[j]) = (list[j], list[i]);
}
}
public static T GetRandomAndRemove<T>(this List<T> list)
{
if (list.Count == 0)
return default;
int index = Random.Range(0, list.Count);
T item = list[index];
list.RemoveAt(index);
return item;
}
}
}