252 lines
6.5 KiB
C#
252 lines
6.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using DefaultNamespace;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using Utils;
|
|
using Utils.Utils;
|
|
using Random = UnityEngine.Random;
|
|
|
|
public class GuardManager : MonoBehaviour, IDescribable
|
|
{
|
|
public string type;
|
|
|
|
public string mod;
|
|
|
|
|
|
public string puzzle;
|
|
|
|
|
|
private Light focusLight;
|
|
public int isfocussed;
|
|
|
|
[SerializeField]
|
|
private List<GameEntry<Material>> GuardMaterials;
|
|
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
if (mod == "BLUE")
|
|
{
|
|
GetComponentInChildren<Renderer>().material = GuardMaterials.ByKey("OTHER");
|
|
}
|
|
else if (mod == "HAT")
|
|
{
|
|
GetComponentInChildren<Renderer>().material = GuardMaterials.ByKey("HAT");
|
|
}
|
|
else if (mod == "JOKER")
|
|
{
|
|
GetComponentInChildren<Renderer>().material = GuardMaterials.ByKey("JOKER");
|
|
}
|
|
|
|
focusLight = transform.FindChildRecursive("FocusLight").GetComponent<Light>();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (focusLight != null)
|
|
{
|
|
if (isfocussed == 2 && focusLight.intensity < 250)
|
|
{
|
|
focusLight.intensity += Time.deltaTime * 100;
|
|
}
|
|
else if (isfocussed == 1 && focusLight.intensity < 150)
|
|
{
|
|
focusLight.intensity += Time.deltaTime * 100;
|
|
}
|
|
else if (isfocussed == 0 && focusLight.intensity > 100)
|
|
{
|
|
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()
|
|
{
|
|
if (type == "TRUTHER")
|
|
{
|
|
return "Veritas";
|
|
}
|
|
else if (type == "LIAR")
|
|
{
|
|
return "Vesper";
|
|
}
|
|
else
|
|
{
|
|
return "Jester";
|
|
}
|
|
}
|
|
|
|
public string GetDescribeName()
|
|
{
|
|
return GetUnknownDescription().CapitalizeFirstLetter();
|
|
}
|
|
|
|
public string GetDescription()
|
|
{
|
|
if (type == "TRUTHER")
|
|
{
|
|
return "Sworn by oath to always tell the truth, at all costs.";
|
|
}
|
|
else if (type == "LIAR")
|
|
{
|
|
return "Cursed to always tell the opposite of the truth, no matter his real intentions.";
|
|
}
|
|
else
|
|
{
|
|
return "Things are slow in the King's chamber, comes down here for laughs.";
|
|
}
|
|
}
|
|
|
|
public string GetUnknownDescription()
|
|
{
|
|
if (mod == "BLUE")
|
|
{
|
|
return "the blue 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 red 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;
|
|
}
|
|
}
|