Beispiel #1
0
        public static void InitializeWeatherData(string filename)
        {
            using (var proxy = new TextReaderProxy(new StreamReader(filename)))
            {
                while (!proxy.EndOfStream)
                {
                    var line  = proxy.ReadLine().TrimEnd('~');
                    var words = line.Split(',');

                    var hemisphere = EnumerationExtensions.GetEnum <HemisphereTypes>(words[0]
                                                                                     .EqualsIgnoreCase("north") ? 0 : 1);
                    var season  = EnumerationExtensions.GetEnum <SeasonTypes>(words[1]);
                    var climate = EnumerationExtensions.GetEnum <ClimateTypes>(words[2]);

                    var data = new WeatherRangeData(hemisphere, season, climate);

                    // 3/4 = Temperature Lo/HI
                    // 5/6 = Pressure Lo/HI
                    // 7/8 = CloudCover Lo/Hi
                    // 9/10 = Humidity Lo/Hi
                    // 11/12 = Precipitation Lo/HI
                    // 13/14 = Energy Lo/HI
                    // 15/16 = WindSpeed X Lo/HI
                    // 17/18 = WindSpeed Y Lo/HI

                    WeatherConstants.WeatherData.Add(data);
                }
            }
        }
Beispiel #2
0
        public static void load_helps(TextReaderProxy proxy)
        {
            do
            {
                var help = new HelpData
                {
                    Level   = proxy.ReadNumber(),
                    Keyword = proxy.ReadToEndOfLine()
                };

                if (help.Keyword.StartsWith("#$"))
                {
                    break;
                }

                help.Text = proxy.ReadString(new[] { '~' });

                if (help.Keyword.EqualsIgnoreCase("greeting"))
                {
                    HelpGreeting = help.Text;
                }

                add_help(help);
            } while (!proxy.EndOfStream);
        }
        public void ReadNumber_ReturnsValidValue()
        {
            TextReaderProxy proxy = new TextReaderProxy(new StringReader("100 words"));

            var result = proxy.ReadNumber();

            result.Should().Be(100);
        }
        public void ReadNextWord_ReturnsValidString()
        {
            TextReaderProxy proxy = new TextReaderProxy(new StringReader("first word"));

            var result = proxy.ReadNextWord();

            result.Should().Be("first");
        }
        public void ReadNextLetter_ThrowsExceptionAtEndOfStream()
        {
            TextReaderProxy proxy = new TextReaderProxy(new StringReader(""));

            Action act = () => proxy.ReadNextLetter();

            act.Should().Throw <IOException>();
        }
        public void ReadNextLetter_ReturnsValidChar()
        {
            TextReaderProxy proxy = new TextReaderProxy(new StringReader("a word"));

            var result = proxy.ReadNextLetter();

            result.Should().Be('a');
        }
        public void Load()
        {
            var dirProxy = new DirectoryProxy();
            var files    = dirProxy.GetFiles(Directory);

            var validLines = new List <string> {
                "level", "roomrange", "mobrange", "objrange"
            };

            foreach (var file in files.Where(x => !x.Equals(".")))
            {
                using (var proxy = new TextReaderProxy(new StreamReader(Directory + file)))
                {
                    IEnumerable <string> lines = proxy.ReadIntoList();

                    int low = 0, hi = 0, rlow = 0, rhi = 0, mlow, mhi, olow, ohi;
                    var badFile = false;

                    foreach (var line in lines)
                    {
                        string[] words;
                        switch (line.ToLower())
                        {
                        case "level":
                            if (low < LevelConstants.ImmortalLevel)
                            {
                                LogManager.Instance.Bug("God file {0} with level {1} < {2}", file, low,
                                                        LevelConstants.ImmortalLevel);
                                badFile = true;
                            }
                            break;

                        case "roomrange":
                            words = line.Split();
                            rlow  = low = words[1].ToInt32();
                            rhi   = hi = words[2].ToInt32();
                            break;

                        case "mobrange":
                            words = line.Split();
                            rlow  = low = words[1].ToInt32();
                            rhi   = hi = words[2].ToInt32();
                            break;

                        case "objrange":
                            words = line.Split();
                            rlow  = low = words[1].ToInt32();
                            rhi   = hi = words[2].ToInt32();
                            break;
                        }
                    }

                    if (rlow > 0 && rhi > 0 && !badFile)
                    {
                    }
                }
            }
        }
        public void ReadBitvectorWithSpacesReturnsValidObject(string stringToRead, int valueToCheck, bool expectedValue)
        {
            TextReaderProxy proxy = new TextReaderProxy(new StringReader("2 & 4 & 8~"));

            ExtendedBitvector result = proxy.ReadBitvector();

            Assert.That(result, Is.Not.Null);
            Assert.That(result.IsSet((int)valueToCheck), Is.EqualTo(expectedValue));
        }
Beispiel #9
0
        private static void SendFileToBuffer(CharacterInstance ch, SystemFileTypes fileType)
        {
            string path = SystemConstants.GetSystemFile(fileType);

            using (TextReaderProxy proxy = new TextReaderProxy(new StreamReader(path)))
            {
                string buffer = proxy.ReadToEnd();
                comm.write_to_buffer(ch.Descriptor, buffer, buffer.Length);
            }
        }
Beispiel #10
0
        private static void SendFileToBuffer(this PlayerInstance ch, SystemFileTypes fileType)
        {
            var path = SystemConstants.GetSystemFile(fileType);

            using (var proxy = new TextReaderProxy(new StreamReader(path)))
            {
                var buffer = proxy.ReadToEnd();
                ch.Descriptor.WriteToBuffer(buffer, buffer.Length);
            }
        }
        public void ReadIntoList_ReturnsValidList()
        {
            TextReaderProxy proxy =
                new TextReaderProxy(new StringReader("#common\r\n~\r\nabcdefghijklmnopqrstuvwxyz~\r\n~\n\r"));

            List <string> results = proxy.ReadIntoList();

            results.Should().NotBeNull();
            results.Count.Should().Be(4);
            results[0].Should().Be("#common");
            results[3].Should().Be("~");
        }
Beispiel #12
0
        public override void Load()
        {
            if (Character == null)
            {
                return;
            }

            using (var proxy = new TextReaderProxy(new StreamReader(Filename)))
            {
                /*List<TextSection> sections = proxy.ReadSections(new[] { "#COMMENT" }, new[] { "*" }, null, null);
                 * if (sections.Count > 0 && Character.Comments == null)
                 *  Character.Comments = new List<NoteData>();
                 *
                 * foreach (TextSection section in sections)
                 * {
                 *  bool inText = false;
                 *  NoteData newNote = new NoteData();
                 *  foreach (string line in section.Lines)
                 *  {
                 *      if (inText)
                 *      {
                 *          if (line.EndsWith("~"))
                 *              inText = false;
                 *          newNote.Text += line.TrimHash();
                 *      }
                 *
                 *      Tuple<string, string> tuple = line.FirstArgument();
                 *      switch (tuple.Item1.ToLower())
                 *      {
                 *          case "sender":
                 *              newNote.Sender = tuple.Item2.TrimHash();
                 *              break;
                 *          case "date":
                 *              newNote.DateSent = tuple.Item2.TrimHash();
                 *              break;
                 *          case "to":
                 *              newNote.RecipientList = tuple.Item2.TrimHash();
                 *              break;
                 *          case "subject":
                 *              newNote.Subject = tuple.Item2.TrimHash();
                 *              break;
                 *          case "text":
                 *              inText = true;
                 *              break;
                 *      }
                 *  }
                 *
                 *  Character.Comments.Add(newNote);
                 * }*/
            }
        }
Beispiel #13
0
        public static void LoadSystemDirectoriesFromDataFile(string path)
        {
            using (var proxy = new TextReaderProxy(new StreamReader(path + "\\SystemDirectories.txt")))
            {
                while (!proxy.EndOfStream)
                {
                    var line  = proxy.ReadLine().TrimEnd('~');
                    var words = line.Split(',');

                    var dirType = EnumerationExtensions.GetEnum <SystemDirectoryTypes>(words[0]);
                    SystemDirectories.Add(dirType, path + "\\" + words[1]);
                }
            }
        }
        public static void InitializeWeatherMessages(string filename)
        {
            using (var proxy = new TextReaderProxy(new StreamReader(filename)))
            {
                IEnumerable <TextSection> sections = proxy.ReadSections(new[] { "#" }, null, null, "#END");
                foreach (var section in sections)
                {
                    var lines = new List <string>();
                    section.Lines.ToList().ForEach(x => lines.Add(x.TrimEnd('~')));

                    WeatherMessages.Add(EnumerationExtensions.GetEnum <PrecipitationTypes>(section.Header), lines);
                }
            }
        }
Beispiel #15
0
        public void LoadMap(SystemFileTypes fileType, IEnumerable <string> map)
        {
            var path = SystemConstants.GetSystemFile(fileType);

            using (var proxy = new TextReaderProxy(new StreamReader(path)))
            {
                IEnumerable <string> lines = proxy.ReadIntoList();
                if (!lines.Any())
                {
                    throw new InvalidDataException($"Missing data for {fileType}");
                }

                map.ToList().AddRange(lines);
            }
        }
        public void ReadSections_HasInvalidSectionParameters()
        {
            TextReaderProxy proxy =
                new TextReaderProxy(new StringReader("#common\r\n~\r\nabcdefghijklmnopqrstuvwxyz~\r\n~\n\r#uncommon\r\n~\r\nabcdefghijklmnopqrstuvwxyz~\r\n~\n\r#end\n\r"));

            List <TextSection> results = proxy.ReadSections(new List <string> {
                "#"
            }, new List <string> {
                "*"
            },
                                                            new List <string> {
                "#"
            }, "#end");

            results.Count.Should().Be(0);
        }
Beispiel #17
0
        public static void LoadSystemFilesFromDataFile(string path)
        {
            using (var proxy = new TextReaderProxy(new StreamReader(path + "\\SystemFiles.txt")))
            {
                while (!proxy.EndOfStream)
                {
                    var line  = proxy.ReadLine().TrimEnd('~');
                    var words = line.Split(',');

                    var fileType           = EnumerationExtensions.GetEnum <SystemFileTypes>(words[0]);
                    var useSystemDirectory = Convert.ToBoolean(BooleanConstants.ContainsIgnoreCase(words[2]));

                    SystemFiles.Add(fileType, new KeyValuePair <string, bool>(words[1], useSystemDirectory));
                }
            }
        }
        public void ReadSections_ReturnsValidList()
        {
            TextReaderProxy proxy =
                new TextReaderProxy(new StringReader("#common\r\n~\r\nabcdefghijklmnopqrstuvwxyz~\r\n~\n\r#uncommon\r\n~\r\nabcdefghijklmnopqrstuvwxyz~\r\n~\n\r#end\n\r"));

            List <TextSection> results = proxy.ReadSections(new List <string> {
                "#"
            }, new List <string> {
                "*"
            }, null, "#end");

            results.Should().NotBeNull();
            results.Count.Should().Be(2);
            results[0].Header.Should().Be("common");
            results[0].Lines.Count.Should().Be(3);
        }
        public void ReadEndOfLine_DoesntReadNextLine()
        {
            TextReaderProxy proxy =
                new TextReaderProxy(new StringReader("This is a test\n\rwith two lines."));

            var result1 = proxy.ReadNextLetter();

            result1.Should().Be('T');

            var result2 = proxy.ReadToEndOfLine(true);

            result2.Should().Be("his is a test");

            var result3 = proxy.ReadLine();

            result3.Should().Be("with two lines.");
        }
        public void ReadSections_HasFooter()
        {
            TextReaderProxy proxy =
                new TextReaderProxy(new StringReader("#common\r\n~\r\nabcdefghijklmnopqrstuvwxyz~\r\n~\r\n^end_common\n\r#uncommon\r\n~\r\nabcdefghijklmnopqrstuvwxyz~\r\n~\n\r^end_uncommon\r\n#end\n\r"));

            List <TextSection> results = proxy.ReadSections(new List <string> {
                "#"
            }, new List <string> {
                "*"
            },
                                                            new List <string> {
                "^"
            }, "#end");

            results.Should().NotBeNull();
            results[0].Footer.Should().Be("end_common");
        }
Beispiel #21
0
        public TimeInfoData LoadTimeInfo()
        {
            using (var proxy = new TextReaderProxy(new StreamReader(Filename)))
            {
                var timeInfo = new TimeInfoData();

                IEnumerable <string> lines = proxy.ReadIntoList();
                foreach (var line in lines.Where(x => !x.StartsWith("*")))
                {
                    if (line.StartsWithIgnoreCase("#time"))
                    {
                        timeInfo.Load(lines);
                        break;
                    }
                    if (line.EqualsIgnoreCase("end"))
                    {
                        break;
                    }
                }

                return(timeInfo);
            }
        }
        public override AreaData LoadArea(AreaData area)
        {
            using (var proxy = new TextReaderProxy(new StreamReader(FilePath)))
            {
                var word    = string.Empty;
                var newArea = area;
                newArea.Age     = 15;
                newArea.Author  = "unknown";
                newArea.Version = 0;

                do
                {
                    var c = proxy.ReadNextLetter();
                    if (c != '#')
                    {
                        LogManager.Instance.Bug("LoadArea: # not found in area file %s", AreaName);
                        throw new InitializationException("# not found in area file");
                    }

                    word = proxy.ReadNextWord();
                    if (word.StartsWith("$"))
                    {
                        break;
                    }

                    switch (word.ToUpper())
                    {
                    case "AREA":
                        // area =load_area(proxy, areaVersion);
                        break;

                    case "AUTHOR":
                        area.Author = proxy.ReadToEndOfLine();
                        break;

                    case "FLAGS":
                        area.Flags          = proxy.ReadNumber();
                        area.ResetFrequency = proxy.ReadNumber();
                        area.Age            = area.ResetFrequency;
                        break;

                    case "RANGES":
                        area.HighSoftRange = LevelConstants.MaxLevel;
                        area.HighHardRange = LevelConstants.MaxLevel;
                        break;

                    case "ECONOMY":
                        area.HighEconomy = proxy.ReadNumber();
                        area.LowEconomy  = proxy.ReadNumber();
                        break;

                    case "RESETMSG":
                        area.ResetMessage = proxy.ReadToEndOfLine();
                        break;

                    case "HELPS":
                        // load_helps(proxy);
                        break;

                    case "MOBILES":
                        // load_mobiles(area, proxy);
                        break;

                    case "OBJECTS":
                        // load_objects(area, proxy);
                        break;

                    case "RESETS":
                        // load_resets(area, proxy);
                        break;

                    case "ROOMS":
                        // load_rooms(area, proxy);
                        break;

                    case "SHOPS":
                        // load_shops(proxy);
                        break;

                    case "REPAIRS":
                        // load_repairs(proxy);
                        break;

                    case "SPECIALS":
                        // load_specials(proxy);
                        break;

                    case "CLIMATE":
                        // load_climate(area, proxy);
                        break;

                    case "NEIGHBOR":
                        // load_neighbor(area, proxy);
                        break;

                    case "VERSION":
                        area.Version = proxy.ReadNumber();
                        break;

                    case "SPELLLIMIT":
                        area.SpellLimit = proxy.ReadNumber();
                        break;

                    default:
                        LogManager.Instance.Bug("LoadArea: Area %s: bad section name %s", AreaName, word);
                        if (BootDb)
                        {
                            throw new InitializationException("Area {0} had a bad section name {1}", AreaName, word);
                        }
                        return(null);
                    }
                } while (!proxy.EndOfStream && !word.StartsWith("$"));

                return(newArea);
            }
        }
Beispiel #23
0
 public static void fread_command(TextReaderProxy proxy)
 {
     // TODO
 }
Beispiel #24
0
 public static void fread_social(TextReaderProxy proxy)
 {
     // TODO
 }