diff options
Diffstat (limited to 'Valheim_v202102/Valheim/assembly_valheim/DreamTexts.cs')
-rw-r--r-- | Valheim_v202102/Valheim/assembly_valheim/DreamTexts.cs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/Valheim_v202102/Valheim/assembly_valheim/DreamTexts.cs b/Valheim_v202102/Valheim/assembly_valheim/DreamTexts.cs new file mode 100644 index 0000000..4c2b44d --- /dev/null +++ b/Valheim_v202102/Valheim/assembly_valheim/DreamTexts.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +public class DreamTexts : MonoBehaviour +{ + [Serializable] + public class DreamText + { + public string m_text = "Fluffy sheep"; + + public float m_chanceToDream = 0.1f; + + public List<string> m_trueKeys = new List<string>(); + + public List<string> m_falseKeys = new List<string>(); + } + + public List<DreamText> m_texts = new List<DreamText>(); + + public DreamText GetRandomDreamText() + { + List<DreamText> list = new List<DreamText>(); + foreach (DreamText text in m_texts) + { + if (HaveGlobalKeys(text)) + { + list.Add(text); + } + } + if (list.Count == 0) + { + return null; + } + DreamText dreamText = list[UnityEngine.Random.Range(0, list.Count)]; + if (UnityEngine.Random.value <= dreamText.m_chanceToDream) + { + return dreamText; + } + return null; + } + + private bool HaveGlobalKeys(DreamText dream) + { + foreach (string trueKey in dream.m_trueKeys) + { + if (!ZoneSystem.instance.GetGlobalKey(trueKey)) + { + return false; + } + } + foreach (string falseKey in dream.m_falseKeys) + { + if (ZoneSystem.instance.GetGlobalKey(falseKey)) + { + return false; + } + } + return true; + } +} |