private void ProcessSegment(PlayerObject player, NPCPage page, NPCSegment segment, uint objectID) { player.NPCObjectID = objectID; player.NPCScriptID = ScriptID; player.NPCSuccess.Add(segment, segment.Check(player)); player.NPCPage = page; }
private NPCSegment ParseSegment(NPCPage page, IEnumerable <string> scriptLines) { List <string> checks = new List <string>(), acts = new List <string>(), say = new List <string>(), buttons = new List <string>(), elseSay = new List <string>(), elseActs = new List <string>(), elseButtons = new List <string>(), gotoButtons = new List <string>(); List <string> lines = scriptLines.ToList(); List <string> currentSay = say, currentButtons = buttons; Regex regex = new Regex(@"<.*?/(\@.*?)>"); for (int i = 0; i < lines.Count; i++) { if (string.IsNullOrEmpty(lines[i])) { continue; } if (lines[i].StartsWith(";")) { continue; } if (lines[i].StartsWith("#")) { string[] action = lines[i].Remove(0, 1).ToUpper().Trim().Split(' '); switch (action[0]) { case "IF": currentSay = checks; currentButtons = null; continue; case "SAY": currentSay = say; currentButtons = buttons; continue; case "ACT": currentSay = acts; currentButtons = gotoButtons; continue; case "ELSESAY": currentSay = elseSay; currentButtons = elseButtons; continue; case "ELSEACT": currentSay = elseActs; currentButtons = gotoButtons; continue; default: throw new NotImplementedException(); } } if (lines[i].StartsWith("[") && lines[i].EndsWith("]")) { break; } if (currentButtons != null) { Match match = regex.Match(lines[i]); while (match.Success) { string argu = match.Groups[1].Captures[0].Value; currentButtons.Add(string.Format("[{0}]", argu)); match = match.NextMatch(); } //Check if line has a goto command var parts = lines[i].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Count() > 1) { switch (parts[0].ToUpper()) { case "GOTO": case "GROUPGOTO": gotoButtons.Add(string.Format("[{0}]", parts[1].ToUpper())); break; case "TIMERECALL": case "DELAYGOTO": case "TIMERECALLGROUP": if (parts.Length > 2) { gotoButtons.Add(string.Format("[{0}]", parts[2].ToUpper())); } break; } } } currentSay.Add(lines[i].TrimEnd()); } NPCSegment segment = new NPCSegment(page, say, buttons, elseSay, elseButtons, gotoButtons); for (int i = 0; i < checks.Count; i++) { segment.ParseCheck(checks[i]); } for (int i = 0; i < acts.Count; i++) { segment.ParseAct(segment.ActList, acts[i]); } for (int i = 0; i < elseActs.Count; i++) { segment.ParseAct(segment.ElseActList, elseActs[i]); } currentButtons = new List <string>(); currentButtons.AddRange(buttons); currentButtons.AddRange(elseButtons); currentButtons.AddRange(gotoButtons); return(segment); }
private NPCPage ParsePage(IList <string> scriptLines, string sectionName) { bool nextPage = false, nextSection = false; List <string> lines = scriptLines.Where(x => !string.IsNullOrEmpty(x)).ToList(); NPCPage Page = new NPCPage(sectionName); //Cleans arguments out of search page name string tempSectionName = Page.ArgumentParse(sectionName); //parse all individual pages in a script, defined by sectionName for (int i = 0; i < lines.Count; i++) { string line = lines[i]; if (line.StartsWith(";")) { continue; } if (!lines[i].ToUpper().StartsWith(tempSectionName.ToUpper())) { continue; } List <string> segmentLines = new List <string>(); nextPage = false; //Found a page, now process that page and split it into segments for (int j = i + 1; j < lines.Count; j++) { string nextLine = lines[j]; if (j < lines.Count - 1) { nextLine = lines[j + 1]; } else { nextLine = ""; } if (nextLine.StartsWith("[") && nextLine.EndsWith("]")) { nextPage = true; } else if (nextLine.StartsWith("#IF")) { nextSection = true; } if (nextSection || nextPage) { segmentLines.Add(lines[j]); //end of segment, so need to parse it and put into the segment list within the page if (segmentLines.Count > 0) { NPCSegment segment = ParseSegment(Page, segmentLines); List <string> currentButtons = new List <string>(); currentButtons.AddRange(segment.Buttons); currentButtons.AddRange(segment.ElseButtons); currentButtons.AddRange(segment.GotoButtons); Page.Buttons.AddRange(currentButtons); Page.SegmentList.Add(segment); segmentLines.Clear(); nextSection = false; } if (nextPage) { break; } continue; } segmentLines.Add(lines[j]); } //bottom of script reached, add all lines found to new segment if (segmentLines.Count > 0) { NPCSegment segment = ParseSegment(Page, segmentLines); List <string> currentButtons = new List <string>(); currentButtons.AddRange(segment.Buttons); currentButtons.AddRange(segment.ElseButtons); currentButtons.AddRange(segment.GotoButtons); Page.Buttons.AddRange(currentButtons); Page.SegmentList.Add(segment); segmentLines.Clear(); } return(Page); } return(Page); }
private void ProcessSegment(NPCPage page, NPCSegment segment) { segment.Check(); }
private void ProcessSegment(MonsterObject monster, NPCPage page, NPCSegment segment) { segment.Check(monster); }
private void ProcessSegment(PlayerObject player, NPCPage page, NPCSegment segment) { player.NPCID = ObjectID; player.NPCSuccess = segment.Check(player); player.NPCPage = page; }
private NPCSegment ParseSegment(NPCPage page, IEnumerable<string> scriptLines) { List<string> checks = new List<string>(), acts = new List<string>(), say = new List<string>(), buttons = new List<string>(), elseSay = new List<string>(), elseActs = new List<string>(), elseButtons = new List<string>(), gotoButtons = new List<string>(); List<string> lines = scriptLines.ToList(); List<string> currentSay = say, currentButtons = buttons; for (int i = 0; i < lines.Count; i++) { if (string.IsNullOrEmpty(lines[i])) continue; if (lines[i].StartsWith("#")) { string[] action = lines[i].Remove(0, 1).ToUpper().Trim().Split(' '); switch (action[0]) { case "IF": currentSay = checks; currentButtons = null; continue; case "SAY": currentSay = say; currentButtons = buttons; continue; case "ACT": currentSay = acts; currentButtons = gotoButtons; continue; case "ELSESAY": currentSay = elseSay; currentButtons = elseButtons; continue; case "ELSEACT": currentSay = elseActs; currentButtons = gotoButtons; continue; default: throw new NotImplementedException(); } } if (lines[i].StartsWith("[") && lines[i].EndsWith("]")) break; if (currentButtons != null) { Match match = Regex.Match(lines[i]); while (match.Success) { string argu = match.Groups[1].Captures[0].Value; currentButtons.Add(string.Format("[{0}]", argu));//ToUpper() match = match.NextMatch(); } //Check if line has a goto command var parts = lines[i].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Count() > 1) switch (parts[0].ToUpper()) { case "GOTO": case "GROUPGOTO": gotoButtons.Add(string.Format("[{0}]", parts[1].ToUpper())); break; case "TIMERECALL": if (parts.Length > 2) gotoButtons.Add(string.Format("[{0}]", parts[2].ToUpper())); break; case "TIMERECALLGROUP": if (parts.Length > 2) gotoButtons.Add(string.Format("[{0}]", parts[2].ToUpper())); break; case "DELAYGOTO": gotoButtons.Add(string.Format("[{0}]", parts[2].ToUpper())); break; } } currentSay.Add(lines[i].TrimEnd()); } NPCSegment segment = new NPCSegment(page, say, buttons, elseSay, elseButtons, gotoButtons); for (int i = 0; i < checks.Count; i++) segment.ParseCheck(checks[i]); for (int i = 0; i < acts.Count; i++) segment.ParseAct(segment.ActList, acts[i]); for (int i = 0; i < elseActs.Count; i++) segment.ParseAct(segment.ElseActList, elseActs[i]); currentButtons = new List<string>(); currentButtons.AddRange(buttons); currentButtons.AddRange(elseButtons); currentButtons.AddRange(gotoButtons); return segment; }
private void ProcessSegment(MonsterObject Monster, NPCPage page, NPCSegment segment) { segment.Check(Monster); }