public string GetNextStoryBoard() { string s = ""; if (OpenedMap != null) { if (OpenedMap.EndIndex >= state) { if (state > Count - 1) { return(s); } FirstEngaged = false; if (Storyboard.GetKey(state).Name == "RelationTrigger") { RelationTrigger rt = (RelationTrigger)Storyboard.GetKey(state); rt.Activate(); return(""); } return(String.Format("{0} - {1}", Storyboard.GetKey(state).Name, Storyboard.GetValue(state))); } else { int index = Conditions.FindIndex(y => y == OpenedMap); OpenedMap = null; state = 0; Conditions[index].Exists = false; Engaged = false; } } return(s); }
public Story ReadFromFile(string file) { Story s = new Story(); StreamReader sr = new StreamReader(file); s.p = p; while (!sr.EndOfStream) { string line = sr.ReadLine(); if (line.Trim() == "" || line == null) { continue; } else if (IsEnemy(line)) { string[] data = GetDataFromRow(line, "enemy"); Enemy e = new Enemy(data[0], int.Parse(data[1]), int.Parse(data[2]), bool.Parse(data[3]), int.Parse(data[4]), int.Parse(data[5]), double.Parse(data[6])); s.AddEnemy(e); } else if (IsCharacter(line)) { string[] data = GetDataFromRow(line, "character"); Character n = new Character(data[0], data[1] == "M" ? Gender.MALE : data[1] == "F" ? Gender.FEMALE : Gender.OTHER); s.AddNPC(n); } else if (IsMapCondition(line)) { string[] data = GetConditonData(line); if (HasNoEntity(data)) { bool bracket = true; int startIndex = s.Count; int count = 0; Narrator n = null; Narrator v = s.narrator; MapCondition mc = null; if (s.narrator.LocX > 0) { n = new Narrator(); n.LocX = int.Parse(data[0]); n.LocY = int.Parse(data[1]); } else { v.LocX = int.Parse(data[0]); v.LocY = int.Parse(data[1]); } while (bracket) { string read = sr.ReadLine(); if (read == "map_cond_end") { bracket = false; } else { string[] story = read.Split('-'); if (story[0] == "player") { s.AddStoryBoard(s.p, story[1]); count++; } else if (story[0] == "narr") { s.AddStoryBoard(s.narrator, story[1]); count++; } } } mc = new MapCondition(n ?? v, startIndex, startIndex + count - 1); s.AddMapCondition(mc); } else { string[] charac = data[0].Split(':'); Enemy e = null; Enemy x = null; Character n = null; Character p = null; int lever = -1; if (charac[0] == "enemy") { lever = 0; e = s.GetEnemyByName(charac[1]); if (e.LocX != 0) { x = (Enemy)e.Clone(); x.LocX = int.Parse(data[1]); x.LocY = int.Parse(data[2]); } else { e.LocX = int.Parse(data[1]); e.LocY = int.Parse(data[2]); } } else if (charac[0] == "character") { lever = 1; n = s.GetNpcByName(charac[1]); if (n.LocX != 0) { p = (Character)n.Clone(); p.LocX = int.Parse(data[1]); p.LocY = int.Parse(data[2]); } else { n.LocX = int.Parse(data[1]); n.LocY = int.Parse(data[2]); } } int startIndex = s.Count; bool bracket = true; int count = 0; while (bracket) { string read = sr.ReadLine(); if (read == "map_cond_end") { bracket = false; } else if (read == "engage_battle()") { Battle b = new Battle((Player)s.p, x ?? e); s.AddStoryBoard(b, "Battle"); } else if (read.Contains("relate")) { string cutted = read.Replace("relate", ""); cutted = cutted.Replace("(", ""); cutted = cutted.Replace(")", ""); cutted = cutted.Trim(); string[] data_rel = cutted.Split(','); RelationTrigger rt = new RelationTrigger (data_rel[0] == "F" ? RelationType.FRIENDSHIP : RelationType.ROMANCE, int.Parse(data_rel[1]), n); s.AddStoryBoard(rt, ""); count++; } else { string[] story = read.Split('-'); if (story[0] == "player") { Regex t = new Regex("%[target]*%"); if (t.IsMatch(story[1])) { switch (lever) { case 0: ITalk target = x ?? e; story[1] = Regex.Replace(story[1], "%[target]*%", target.Name); break; case 1: ITalk target2 = p ?? n; story[1] = Regex.Replace(story[1], "%[target]*%", target2.Name); break; } } s.AddStoryBoard(s.p, story[1]); count++; } else if (story[0] == "target") { s.AddStoryBoard(p ?? n, story[1]); count++; } else { s.AddStoryBoard(x ?? e, story[1]); count++; } } } MapCondition mc = null; switch (lever) { case 0: mc = new MapCondition(x ?? e, startIndex, startIndex + count - 1); s.AddMapCondition(mc); break; case 1: mc = new MapCondition(p ?? n, startIndex, startIndex + count - 1); s.AddMapCondition(mc); break; } } } } sr.Close(); s.FormatText(); return(s); }