using System; using System.Collections.Generic; using System.Text; namespace Leah.Speech.text { [Flags] public enum eMood : Int32 { None = 0, angry = 1, aroused = 2, hungry = 4, happyness = 8, funny = 16, annoyed = 32, irritated = 64, bored = 128, intelligent = 256, sleepy = 512, energy = 1024, exhausted = 2048, depressive = 4096, sad = 8192, useless = 16384, usefull = 32768, compfortable = 65536, temperate = 131072, shy = 262144, excited = 524288, toLoud = 1048576, toQuiet = 2097152, playful = 4194304, naiv = 8388608, freezy = 16777216, hot = 33554432, humanity = 67108864, lonely = 134217728, soziality = 268435456, // Groups All = 2147483647 } public class Contents { public List Entries = new List(); private Random rnd = new Random(); private List _tags = new List(); private List _optionalTags = new List(); /*[System.Fire.Serialize.Annotations.SerializeIgnore()] public int Count { get => this._entries.Count; }*/ public string getText(eMood CategoryId) { List ress = new List(); if (CategoryId == eMood.None) { return this.Entries[rnd.Next(0, this.Entries.Count-1)].Text; } else { foreach (ContentEntry ce in this.Entries) if ((ce.Mood & CategoryId) > 0) ress.Add(ce); if (ress.Count == 0) { return ress[rnd.Next(0, ress.Count - 1)].Text; } else { return ""; } } } public string getText(eMood CategoryId, ushort Tag) { List ress = new List(); if (CategoryId == eMood.None) { return this.Entries[rnd.Next(0, this.Entries.Count - 1)].Text; } else { foreach (ContentEntry ce in this.Entries) if ((ce.Mood & CategoryId) > 0 && ce.HasTags(Tag)) ress.Add(ce); if (ress.Count == 0) { return ress[rnd.Next(0, ress.Count - 1)].Text; } else { return ""; } } } public string getText(eMood CategoryId, ushort[] Tag) { List ress = new List(); if (CategoryId == eMood.None) { return this.Entries[rnd.Next(0, this.Entries.Count - 1)].Text; } else { foreach (ContentEntry ce in this.Entries) if ((ce.Mood & CategoryId) > 0 && ce.HasTags(Tag)) ress.Add(ce); if (ress.Count == 0) { return ress[rnd.Next(0, ress.Count - 1)].Text; } else { return ""; } } } public string getText(eMood CategoryId, string Tags) { if (Tags == "") return this.getText(CategoryId); List tl = new List(); string[] ts = Tags.Split('|', StringSplitOptions.RemoveEmptyEntries); foreach (string t in ts) { string t2 = t.ToLower().Trim(); if (t2 != "" && this._tags.Contains(t2)) tl.Add((ushort)this._tags.IndexOf(t2)); } if(tl.Count>0) return this.getText(CategoryId, tl.ToArray()); return this.getText(CategoryId); } public string getText(string Category, string Tags) { if (Tags == "") return this.getText(Category); List tl = new List(); string[] ts = Tags.Split('|', StringSplitOptions.RemoveEmptyEntries); foreach (string t in ts) { string t2 = t.ToLower().Trim(); if (t2 != "" && this._tags.Contains(t2)) tl.Add((ushort)this._tags.IndexOf(t2)); } if (tl.Count > 0) return this.getText(Category, tl.ToArray()); return this.getText(Category); } public string getText(string Category) { return this.getText(this.GetMood(Category)); } public string getText(string Category, ushort tag) { return this.getText(this.GetMood(Category), tag); } public string getText(string Category, ushort[] tags) { return this.getText(this.GetMood(Category), tags); } protected eMood GetMood(string Category) { eMood m = eMood.None; string[] x = Category.Split('|'); foreach (string y in x) { switch (Category.ToLower().Trim()) { case "angry": case "mad": m |= eMood.angry; break; case "annoyed": m |= eMood.annoyed; break; case "aroused": m |= eMood.aroused; break; case "bored": m |= eMood.bored; break; case "compfortable": m |= eMood.compfortable; break; case "depressive": m |= eMood.depressive; break; case "energy": m |= eMood.energy; break; case "excited": m |= eMood.excited; break; case "exhausted": m |= eMood.exhausted; break; case "freezy": m |= eMood.freezy; break; case "funny": m |= eMood.funny; break; case "happyness": m |= eMood.happyness; break; case "hot": m |= eMood.hot; break; case "humanity": m |= eMood.humanity; break; case "hungry": m |= eMood.hungry; break; case "intelligent": m |= eMood.intelligent; break; case "irritated": m |= eMood.irritated; break; case "lonely": m |= eMood.lonely; break; case "naiv": m |= eMood.naiv; break; case "playful": m |= eMood.playful; break; case "sad": m |= eMood.sad; break; case "shy": m |= eMood.shy; break; case "sleepy": case "sleep": m |= eMood.sleepy; break; case "soziality": case "sozial": m |= eMood.soziality; break; case "temperate": m |= eMood.temperate; break; case "toLoud": m |= eMood.toLoud; break; case "toQuiet": m |= eMood.toQuiet; break; case "usefull": m |= eMood.usefull; break; case "useless": m |= eMood.useless; break; } } return m; } public bool Add(string Text, eMood Mood, ushort[] Tags) { string lText = Text.ToLower().Trim(); foreach (ContentEntry ce in this.Entries) { if (ce.Text.ToLower() == lText) { ce.Mood = Mood; ce.Tags = Tags; return true; } } this.Entries.Add(new ContentEntry(Text.Trim(), Mood, Tags)); return true; } public bool Add(string Text, string Mood, ushort[] Tags) { string lText = Text.ToLower().Trim(); foreach (ContentEntry ce in this.Entries) { if (ce.Text.ToLower() == lText) { ce.Mood = this.GetMood(Mood); ce.Tags = Tags; return true; } } this.Entries.Add(new ContentEntry(Text.Trim(), this.GetMood(Mood), Tags)); return true; } public bool Add(string Text, eMood Mood) { string lText = Text.ToLower().Trim(); foreach (ContentEntry ce in this.Entries) { if (ce.Text.ToLower() == lText) { ce.Mood = Mood; return true; } } this.Entries.Add(new ContentEntry(Text.Trim(), Mood)); return true; } public bool Add(string Text, string Mood) { string lText = Text.ToLower().Trim(); foreach (ContentEntry ce in this.Entries) { if (ce.Text.ToLower() == lText) { ce.Mood = this.GetMood(Mood); return true; } } this.Entries.Add(new ContentEntry(Text.Trim(), this.GetMood(Mood))); return true; } public string[] Tags { get => this._tags.ToArray(); set => this._tags = new List(value); } public string[] OptionalTags { get => this._optionalTags.ToArray(); set => this._optionalTags = new List(value); } /*public List Entries { get { return this._entries; } set { if (value != null) this._entries = value; } }*/ } }