Beispiel #1
0
        private static void AppendUnit(this StringBuilder builder, Unit unit)
        {
            builder.AppendLine("      [UNIT]");

            builder.AppendFormat("         <INTEGER64>GUID:{0}\r\n", unit.GUID);
            builder.AppendFormat("         <STRING>Name:{0}\r\n", unit.Name);
            builder.AppendFormat("         <STRING>File:{0}\r\n", unit.File);
            builder.AppendFormat("         <STRING>UnitType:{0}\r\n", unit.Type);
            builder.AppendFormat("         <BINARY>Unknown:{0:X2}\r\n", unit.Unknown);
            builder.AppendFormat("         <INTEGER>Level:{0}\r\n", unit.Level);
            builder.AppendFormat("         <INTEGER>MinLevel:{0}\r\n", unit.MinLevel);
            builder.AppendFormat("         <INTEGER>MaxLevel:{0}\r\n", unit.MaxLevel);
            builder.AppendFormat("         <INTEGER>Rarity:{0}\r\n", unit.Rarity);
            builder.AppendFormat("         <INTEGER>RarityHC:{0}\r\n", unit.RarityHC);

            builder.AppendLine("      [/UNIT]");
        }
Beispiel #2
0
        private static Unit ReadUnit(ref StringReader reader, ref int lineNumber)
        {
            Unit unit = new Unit();

            string line;
            int startLine = lineNumber;
            bool[] hasSet = new bool[10];

            while ((line = reader.ReadLine()) != null)
            {
                lineNumber++;

                if (line == "[/UNIT]")
                {
                    break;
                }
                else if (line.StartsWith("<INTEGER64>GUID:"))
                {
                    line = line.Replace("<INTEGER64>GUID:", "").Trim();

                    long guid;
                    if (long.TryParse(line, out guid))
                    {
                        unit.GUID = guid;
                        hasSet[0] = true;
                    }
                    else
                    {
                        throw new TxtConverterException(String.Format("GUID must be a 64bit Integer. (Line: {0} | Current: {1})", lineNumber, line));
                    }
                }
                else if (line.StartsWith("<STRING>Name:"))
                {
                    line = line.Replace("<STRING>Name:", "").Trim();

                    unit.Name = line;
                    hasSet[1] = true;
                }
                else if (line.StartsWith("<STRING>File:"))
                {
                    line = line.Replace("<STRING>File:", "").Trim();

                    unit.File = line;
                    hasSet[2] = true;
                }
                else if (line.StartsWith("<STRING>UnitType:"))
                {
                    line = line.Replace("<STRING>UnitType:", "").Trim();

                    unit.Type = line;
                    hasSet[3] = true;
                }
                else if (line.StartsWith("<BINARY>Unknown:"))
                {
                    line = line.Replace("<BINARY>Unknown:", "").Trim();

                    if(line.Length != 2)
                    {
                        throw new TxtConverterException(String.Format("Unknown must be a single hex byte. (Line: {0} | Current: {1})", lineNumber, line));
                    }

                    byte unknown;
                    if(byte.TryParse(line, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out unknown))
                    {
                        unit.Unknown = unknown;
                        hasSet[4] = true;
                    }else{
                        throw new TxtConverterException(String.Format("Unknown is not a valid hex byte! (Line: {0} | Current: {1})", lineNumber, line));
                    }
                }
                else if (line.StartsWith("<INTEGER>Level:"))
                {
                    line = line.Replace("<INTEGER>Level:", "").Trim();

                    int level;
                    if (int.TryParse(line, out level))
                    {
                        unit.Level = level;
                        hasSet[5] = true;
                    }
                    else
                    {
                        throw new TxtConverterException(String.Format("Level must be a 32bit Integer. (Line: {0} | Current: {1})", lineNumber, line));
                    }
                }
                else if (line.StartsWith("<INTEGER>MinLevel:"))
                {
                    
                    line = line.Replace("<INTEGER>MinLevel:", "").Trim();

                    int level;
                    if (int.TryParse(line, out level))
                    {
                        unit.MinLevel = level;
                        hasSet[6] = true;
                    }
                    else
                    {
                        throw new TxtConverterException(String.Format("MinLevel must be a 32bit Integer. (Line: {0} | Current: {1})", lineNumber, line));
                    }
                }
                else if (line.StartsWith("<INTEGER>MaxLevel:"))
                {
                    
                    line = line.Replace("<INTEGER>MaxLevel:", "").Trim();

                    int level;
                    if (int.TryParse(line, out level))
                    {
                        unit.MaxLevel = level;
                        hasSet[7] = true;
                    }
                    else
                    {
                        throw new TxtConverterException(String.Format("MaxLevel must be a 32bit Integer. (Line: {0} | Current: {1})", lineNumber, line));
                    }
                }
                else if (line.StartsWith("<INTEGER>Rarity:"))
                {
                    
                    line = line.Replace("<INTEGER>Rarity:", "").Trim();

                    int rarity;
                    if (int.TryParse(line, out rarity))
                    {
                        unit.Rarity = rarity;
                        hasSet[8] = true;
                    }
                    else
                    {
                        throw new TxtConverterException(String.Format("Rarity must be a 32bit Integer. (Line: {0} | Current: {1})", lineNumber, line));
                    }
                }
                else if (line.StartsWith("<INTEGER>RarityHC:"))
                {
                    
                    line = line.Replace("<INTEGER>RarityHC:", "").Trim();

                    int rarity;
                    if (int.TryParse(line, out rarity))
                    {
                        unit.RarityHC = rarity;
                        hasSet[9] = true;
                    }
                    else
                    {
                        throw new TxtConverterException(String.Format("RarityHC must be a 32bit Integer. (Line: {0} | Current: {1})", lineNumber, line));
                    }
                }
				else if(line.StartsWith("//") || line.StartsWith("#"))
				{
					continue;
				}
                else
                {
                    throw new TxtConverterException(String.Format("Unknown unit property. (Line: {0})", lineNumber));
                }
            }

            Validate(hasSet, startLine);

            return unit;
        }
Beispiel #3
0
        private void WriteUnit(Unit unit)
        {
            _writer.Write(unit.GUID);

            WriteString(unit.Name);

            WriteString(unit.File);

            _writer.Write(unit.Unknown);

            _writer.Write(unit.Level);
            _writer.Write(unit.MinLevel);
            _writer.Write(unit.MaxLevel);

            _writer.Write(unit.Rarity);
            _writer.Write(unit.RarityHC);

            WriteString(unit.Type);
        }
Beispiel #4
0
        private Unit ReadUnit()
        {
            Unit unit = new Unit();

            unit.GUID = _reader.ReadInt64();

            unit.Name = ReadString();
            unit.File = ReadString();

            unit.Unknown = _reader.ReadByte();

            unit.Level = _reader.ReadInt32();
            unit.MinLevel = _reader.ReadInt32();
            unit.MaxLevel = _reader.ReadInt32();

            unit.Rarity = _reader.ReadInt32();
            unit.RarityHC = _reader.ReadInt32();

            unit.Type = ReadString();

            return unit;
        }