Exemplo n.º 1
0
        public StatusWriter(StatusForm statusForm)
        {
            var scoreHealthRegex = new Regex(@"^You have (\d*)\((\d*)\) hit(, (\d*)\((\d*)\) (saidin|saidar|dark power))? and (-?\d*)\((\d*)\) movement points.$", RegexOptions.Compiled);

            var enemyColors = new Regex(@"\*\\x1B\[3(6|5|1)m([^ ]*)\\x1B\[0m\*", RegexOptions.Compiled);

            Store.ParsedOutput.Subscribe((outputs) => {
                foreach (var output in outputs)
                {
                    if (output.Type == ParsedOutputType.Raw)
                    {
                        foreach (var line in output.Lines)
                        {
                            if (scoreHealthRegex.IsMatch(line))
                            {
                                statusForm.WriteToOutput(line + "\n", MudColors.ForegroundColor);
                            }
                            if (enemyColors.IsMatch(line))
                            {
                                // todo: this is inefficient
                                statusForm.WriteToOutput(FormatDecodedText.Format(ControlCharacterEncoder.Decode(line + "\n")));
                            }
                        }
                    }
                    else if (output.Type == ParsedOutputType.Status)
                    {
                        statusForm.WriteToOutput(output.Lines[0] + "\n", MudColors.ForegroundColor);
                    }
                    else if (output.Type == ParsedOutputType.Room)
                    {
                        foreach (var line in output.Creatures)
                        {
                            if (enemyColors.IsMatch(line))
                            {
                                // todo: this is inefficient
                                statusForm.WriteToOutput(FormatDecodedText.Format(ControlCharacterEncoder.Decode(line + "\n")));
                            }
                        }
                    }
                }
            });
        }
Exemplo n.º 2
0
        public NarrsWriter(MudClientForm form)
        {
            _form = form;

            Store.ParsedOutput.Subscribe((outputs) => {
                foreach (var output in outputs)
                {
                    if (output.Type != ParsedOutputType.Raw)
                    {
                        continue;
                    }
                    foreach (var line in output.Lines)
                    {
                        // todo: also include my narrates in here
                        // todo: should match on colour and also with a regex instead of doing this
                        if (line.Contains(" narrates '") ||
                            line.Contains(" tells you '") ||
                            line.Contains(" says '") ||
                            line.Contains(" speaks from the ") ||
                            line.Contains(" bellows '") ||
                            line.Contains(" hisses '") ||
                            line.Contains(" chats '") ||
                            line == "You are hungry." ||
                            line == "You are thirsty.")
                        {
                            if (line == "You are hungry." || line == "You are thirsty.")
                            {
                                SystemSounds.Beep.Play();
                            }


                            // todo: decoding & then converting to rich text will be needlessly wasteful
                            _form.WriteToNarrs(FormatDecodedText.Format(ControlCharacterEncoder.Decode(line + "\n")));
                        }
                    }
                }
            });
        }
Exemplo n.º 3
0
        public ParsedOutputWriter(MudClientForm form)
        {
            Store.TcpSend.Subscribe((message) => {
                // output = output + "\n"; // seems to be the most like zMud
                form.WriteToOutput(" " + message + " ", MudColors.CommandColor);
            });

            Store.ClientInfo.Subscribe((message) => {
                form.WriteToOutput("\n" + message + "\n", MudColors.ClientInfoColor);
            });


            Store.ParsedOutput.Subscribe((parsedOutputs) => {
                foreach (var p in parsedOutputs)
                {
                    switch (p.Type)
                    {
                    case ParsedOutputType.Raw:
                        // todo: dont unsplit things, dont decode things ~ waste of time & effort
                        // probably copy paste a custom version of .FormatOutput

                        /*var lines = p.Lines;
                         * for (int i = 0; i < p.Lines.Length; i++) {
                         *  if (!string.IsNullOrWhiteSpace(p.Lines[i])) {
                         *      lines[i] = p.LineMetadata[i].Type.ToString().PadRight(15)[..15] + " " + p.Lines[i];
                         *  }
                         * }*/

                        var formattedOutput = FormatDecodedText.Format(ControlCharacterEncoder.Decode(string.Join("\n", p.Lines) + "\n"));
                        form.WriteToOutput(formattedOutput);

                        if (!form.ContainsFocus)
                        {
                            WindowFlasher.Flash(form);
                        }
                        break;

                    case ParsedOutputType.Room:
                        // todo: there's a break between rooms even if it was a dline

                        form.WriteToOutput("\n" + p.Title, MudColors.RoomTitle);
                        // form.WriteToOutput(string.Join("\n", p.Description) + "\n", MudColors.ForegroundColor);
                        form.WriteToOutput(p.Exits + "\n", MudColors.RoomExits);
                        if (p.Tracks.Length > 0)
                        {
                            form.WriteToOutput(string.Join("\n", p.Tracks) + "\n", MudColors.Tracks);
                        }
                        if (p.Items.Length > 0)
                        {
                            form.WriteToOutput(string.Join("\n", p.Items) + "\n", MudColors.ItemsOnFloor);
                        }
                        if (p.Creatures.Length > 0)
                        {
                            // Todo: does this work correctly? also it's inefficient
                            form.WriteToOutput(FormatDecodedText.Format(ControlCharacterEncoder.Decode("\\x1B[33m" + string.Join("\n", p.Creatures) + "\n")));
                        }

                        break;

                    case ParsedOutputType.Status:
                        form.WriteToOutput(p.Lines[0] + " ", MudColors.ForegroundColor);
                        break;

                    default:
                        throw new Exception("Unhandled parsed output type");
                    }
                }
            });
        }