예제 #1
0
        private static void AppendAffix(this StringBuilder builder, Affix affix)
        {
            builder.AppendLine("   [AFFIX]");

            builder.AppendFormat("      <STRING>Name:{0}\r\n", affix.Name);
            builder.AppendFormat("      <STRING>File:{0}\r\n", affix.File);
            builder.AppendFormat("      <INTEGER>MinSpawnRange:{0}\r\n", affix.MinSpawnRange);
            builder.AppendFormat("      <INTEGER>MaxSpawnRange:{0}\r\n", affix.MaxSpawnRange);
            builder.AppendFormat("      <INTEGER>Weight:{0}\r\n", affix.Weight);
            builder.AppendFormat("      <INTEGER>DifficultiesAllowed:{0}\r\n", affix.DifficultiesAllowed);

            if (affix.UnitTypes.Count > 0)
            {
                builder.AppendLine("      [UNITTYPES]");
                foreach (var unitType in affix.UnitTypes)
                {
                    builder.AppendFormat("         <STRING>{0}\r\n", unitType);
                }
                builder.AppendLine("      [/UNITTYPES]");
            }

            if (affix.NotUnitTypes.Count > 0)
            {
                builder.AppendLine("      [NOTUNITTYPES]");
                foreach (var unitType in affix.NotUnitTypes)
                {
                    builder.AppendFormat("         <STRING>{0}\r\n", unitType);
                }
                builder.AppendLine("      [/NOTUNITTYPES]");
            }
            builder.AppendLine("   [/AFFIX]");
        }
예제 #2
0
        private void WriteAffix(Affix affix)
        {
            WriteString(affix.File);
            WriteString(affix.Name);

            _writer.Write(affix.MinSpawnRange);
            _writer.Write(affix.MaxSpawnRange);

            _writer.Write(affix.Weight);
            _writer.Write(affix.DifficultiesAllowed);

            _writer.Write((byte)affix.UnitTypes.Count);
            foreach (var unitType in affix.UnitTypes)
            {
                WriteString(unitType);
            }

            _writer.Write((byte)affix.NotUnitTypes.Count);
            foreach (var unitType in affix.NotUnitTypes)
            {
                WriteString(unitType);
            }
        }
예제 #3
0
        private static Affix ReadAffix(ref StringReader reader, ref int lineNumber)
        {
            Affix affix = new Affix();

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

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

                if (line == "[/AFFIX]")
                {
                    break;
                }
                else if (line.StartsWith("<STRING>Name:"))
                {
                    line = line.Replace("<STRING>Name:", "").Trim();

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

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

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

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

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

                    int difficultiesAllowed;
                    if (int.TryParse(line, out difficultiesAllowed))
                    {
                        affix.DifficultiesAllowed = difficultiesAllowed;
                        hasSet[5] = true;
                    }
                    else
                    {
                        throw new TxtConverterException(String.Format("DifficultiesAllowed must be a 32bit Integer. (Line: {0} | Current: {1})", lineNumber, line));
                    }
                }
                else if (line.StartsWith("[UNITTYPES]"))
                {
                    while ((line = reader.ReadLine()) != null)
                    {
                        lineNumber++;

                        if (line == "[/UNITTYPES]")
                        {
                            break;
                        }
                        else
                        {
                            affix.UnitTypes.Add(line.Replace("<STRING>", "").Trim());
                        }
                    }
                }
                else if (line.StartsWith("[NOTUNITTYPES]"))
                {
                    while ((line = reader.ReadLine()) != null)
                    {
                        lineNumber++;

                        if (line == "[/NOTUNITTYPES]")
                        {
                            break;
                        }
                        else
                        {
                            affix.NotUnitTypes.Add(line.Replace("<STRING>", "").Trim());
                        }
                    }
                }
				else if(line.StartsWith("//") || line.StartsWith("#"))
				{
					continue;
				}
                else
                {
                    throw new TxtConverterException(String.Format("Unknown unit property. (Line: {0})", lineNumber));
                }
            }

            Validate(hasSet, startLine);

            return affix;
        }
예제 #4
0
        private Affix ReadAffix()
        {
            Affix affix = new Affix();

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

            affix.MinSpawnRange = _reader.ReadInt32();
            affix.MaxSpawnRange = _reader.ReadInt32();

            affix.Weight = _reader.ReadInt32();
            affix.DifficultiesAllowed = _reader.ReadInt32();

            int unitTypeCount = _reader.ReadByte();
            for (int i = 0; i < unitTypeCount; i++)
            {
                affix.UnitTypes.Add(ReadString());
            }

            int notUnitTypeCount = _reader.ReadByte();
            for (int i = 0; i < notUnitTypeCount; i++)
            {
                affix.NotUnitTypes.Add(ReadString());
            }

            return affix;
        }