Ejemplo n.º 1
0
Archivo: NPC.cs Proyecto: Bia10/ArcNET
        private static Tuple <BasicStatType, int> GetBasicStat(string paramValue)
        {
            Tuple <BasicStatType, int> basicStatTuple = null;
            var trimmedStats = paramValue.TrimStart();
            var statAndValue = trimmedStats.Split(" ", 2);
            var statType     = statAndValue[0].Trim();

            if (!((IList)Enum.GetNames(typeof(BasicStatType))).Contains(statType))
            {
                ConsoleExtensions.Log($"unrecognized Entity.BasicStatType param:|{statType}|", "warn");
            }

            var statValue = statAndValue[1].Trim();

            //ConsoleExtensions.Log($"statType:|{statType}| value:|{statValue}|", "warn");

            foreach (var basicStatType in (BasicStatType[])Enum.GetValues(typeof(BasicStatType)))
            {
                var enumValueName = Enum.GetName(typeof(BasicStatType), basicStatType);
                if (!enumValueName.Equals(statType))
                {
                    //ConsoleExtensions.Log($"Failed to match enumValueName:|{enumValueName}| vs statType:|{statType}|", "warn");
                    continue;
                }
                basicStatTuple = new Tuple <BasicStatType, int>(basicStatType, int.Parse(statValue));
            }

            return(basicStatTuple);
        }
Ejemplo n.º 2
0
        public static GameObjectHeader Read(this BinaryReader reader)
        {
            var header = new GameObjectHeader
            {
                Version = reader.ReadInt32()
            };

            if (header.Version != 0x77)
            {
                throw new InvalidDataException("Unknown object file version: " + header.Version);
            }

            header.ProtoId        = reader.ReadGameObjectGuid(true);
            header.ObjectId       = reader.ReadGameObjectGuid(true);
            header.GameObjectType = (Enums.ObjectType)reader.ReadUInt32();

            if (!header.ProtoId.IsProto())
            {
                header.PropCollectionItems = reader.ReadInt16();
            }

            var bitmapLength = (int)Enum.Parse(typeof(Enums.ObjectFieldBitmap), header.GameObjectType.ToString());

            header.Bitmap = new BitArray(reader.ReadBytes(bitmapLength));

            ConsoleExtensions.Log($"Parsed GameOjb headerVersion: {header.Version} "
                                  + $"\n ProtoId: {header.ProtoId}"
                                  + $"\n ObjectId: {header.ObjectId}"
                                  + $"\n GameObjectType: {header.GameObjectType}"
                                  + $"\n bitmapLength: {bitmapLength}"
                                  + $"\n Bitmap: {header.Bitmap}", "warn");
            return(header);
        }
Ejemplo n.º 3
0
        public FacadeWalk Read()
        {
            var obj = new FacadeWalk
            {
                Marker = MarshallingExtensions.ByteArrayToStructure <FacWalkMarker>(_reader)
            };
            //ConsoleExtensions.Log($"Parsed file marker: {obj.Marker.fileMarker}", "success");

            const string markerConst  = "FacWalk V101 ";
            var          markerActual = obj.Marker.fileMarker;

            if (markerActual != markerConst)
            {
                ConsoleExtensions.Log("Filetype or version mismatch!", "error");
                ConsoleExtensions.Log($"Expected: {markerConst}", "error");
                ConsoleExtensions.Log($"Parsed: {markerActual}", "error");
                return(null);
            }

            obj.Header  = MarshallingExtensions.ByteArrayToStructure <FacWalkHeader>(_reader);
            obj.Entries = new FacWalkEntry[obj.Header.entryCount];
#if DEBUG
            //ConsoleExtensions.Log($"Parsed Header: {obj.Header}", "success");
            //ConsoleExtensions.Log($"Parsing {obj.Header.entryCount} entries", "info");
#endif
            for (var i = 0; i < obj.Header.entryCount; i++)
            {
                obj.Entries[i] = MarshallingExtensions.ByteArrayToStructure <FacWalkEntry>(_reader);
                //AnsiConsole.WriteLine($"Parsing entry: {obj.Entries[i]} index:{i}");
            }

            return(obj);
        }
Ejemplo n.º 4
0
        public void Print()
        {
            var osMajorVersion = OperatingSystem.Version.Major;
            var osMinorVersion = OperatingSystem.Version.Minor;
            var osBuildVersion = OperatingSystem.Version.Build;

            ConsoleExtensions.Log($"Major: {osMajorVersion} " +
                                  $"Minor: {osMinorVersion} " +
                                  $"OsBuildVersion: {osBuildVersion}", "info");

            DisplaySettings.PrintCurrentDisplaySettings();
        }
Ejemplo n.º 5
0
        public void PrintCurrentDisplaySettings()
        {
            if (!DevMode.dmDeviceName.Valid())
            {
                throw new InvalidOperationException("Display device name is not valid! " +
                                                    $"DeviceName: {DevMode.dmDeviceName}");
            }

            foreach (var field in typeof(DeviceMode).GetFields())
            {
                ConsoleExtensions.Log($"{field.Name} {field.GetValue(DevMode)}", "info");
            }
        }
Ejemplo n.º 6
0
        private static DeviceMode GetCurrentDisplaySettings()
        {
            DeviceMode devMode = default;

            devMode.dmSize = (ushort)Marshal.SizeOf(devMode);

            if (NativeMethods.EnumDisplaySettings(null, DisplayModeNumber.CurrentSettings.ToInt(), ref devMode))
            {
                return(devMode);
            }

            ConsoleExtensions.Log("Failed to obtain current display settings!", "error");
            return(new DeviceMode());
        }
Ejemplo n.º 7
0
        private static string GetHighResDir()
        {
            var pathToArcDir     = AnsiConsole.Ask <string>("[green]Insert path to Arcanum dir[/]:");
            var pathToHighResDir = Path.Combine(pathToArcDir + "\\HighRes");

            while (!Directory.Exists(pathToHighResDir))
            {
                ConsoleExtensions.Log("HighRes dir not found!", "error");
                pathToArcDir     = AnsiConsole.Ask <string>("[green]Insert path to Arcanum dir again[/]:");
                pathToHighResDir = Path.Combine(pathToArcDir + "\\HighRes");
            }

            return(pathToHighResDir);
        }
Ejemplo n.º 8
0
        public Sector ReadSector()
        {
            var sector = new Sector();

            ReadLights(_reader, sector.Lights);
            ReadTiles(_reader, sector.Tiles);
            SkipRoofList(_reader);

            var placeholder = _reader.ReadInt32();

            ConsoleExtensions.Log(placeholder.ToString("X4"), "info");
            ConsoleExtensions.Log(_reader.BaseStream.Position.ToString("X4"), "info");

            if (placeholder < 0xAA0000 || placeholder > 0xAA0004)
            {
                throw new InvalidDataException("Invalid placeholder value read from sector.");
            }
            // All of these seems to be old Arcanum leftovers
            if (placeholder >= 0xAA0001)
            {
                ReadTileScripts(_reader, sector);
            }
            if (placeholder >= 0xAA0002)
            {
                ReadSectorScripts(_reader, sector);
            }
            if (placeholder >= 0xAA0003)
            {
                _reader.ReadInt32();   // Townmap Info
                _reader.ReadInt32();   // Aptitude Adjustment
                _reader.ReadInt32();   // Light Scheme
                _reader.ReadBytes(12); // Sound List
            }
            if (placeholder >= 0xAA0004)
            {
                _reader.ReadBytes(512);
            }
            ReadObjects(_reader, sector);

            if (_reader.BaseStream.Position + 4 != _reader.BaseStream.Length)
            {
                throw new Exception();
            }

            return(sector);
        }
Ejemplo n.º 9
0
        private static ObjFCritterFlags2 ParseObjFCritterFlags2(string paramValue)
        {
            var flag        = (ObjFCritterFlags2)0;
            var trimmedFlag = paramValue.TrimStart().TrimEnd();

            if (!((IList)Enum.GetNames(typeof(ObjFCritterFlags2))).Contains(trimmedFlag))
            {
                ConsoleExtensions.Log($"Unrecognized ObjFCritterFlags2 param:|{trimmedFlag}|", "warn");
            }

            foreach (var critterFlag2 in (ObjFCritterFlags2[])Enum.GetValues(typeof(ObjFCritterFlags2)))
            {
                if (!Enum.GetName(typeof(ObjFCritterFlags2), critterFlag2).Equals(trimmedFlag))
                {
                    continue;
                }
                //ConsoleExtensions.Log($"Recognized ObjFCritterFlags2 param:|{trimmedFlag}|", "success");
                flag = critterFlag2;
            }
            return(flag);
        }
Ejemplo n.º 10
0
        private static ObjFNpcFlags ParseObjFNpcFlags(string paramValue)
        {
            var flag        = (ObjFNpcFlags)0;
            var trimmedFlag = paramValue.TrimStart().TrimEnd();

            if (!((IList)Enum.GetNames(typeof(ObjFNpcFlags))).Contains(trimmedFlag))
            {
                ConsoleExtensions.Log($"Unrecognized ObjFNpcFlags param:|{trimmedFlag}|", "warn");
            }

            foreach (var npcFlag in (ObjFNpcFlags[])Enum.GetValues(typeof(ObjFNpcFlags)))
            {
                if (!Enum.GetName(typeof(ObjFNpcFlags), npcFlag).Equals(trimmedFlag))
                {
                    continue;
                }
                //ConsoleExtensions.Log($"Recognized ObjFNpcFlags param:|{trimmedFlag}|", "success");
                flag = npcFlag;
            }
            return(flag);
        }
Ejemplo n.º 11
0
        private static string[] Parse(string input)
        {
            //failures to conform to pattern:
            input = input switch
            {
                "2028 door light wood" => "{2028}{door-light-wood}",
                "2029 door heavy wood" => "{2029}{door-heavy-wood}",
                "2030 door metal gate" => "{2030}{door-metal-gate}",
                "2031 door metal" => "{2031}{door-metal}",
                "2032 door glass" => "{2032}{door-glass}",
                "2033 door stone" => "{2033}{door-stone}",
                "2034 door rock cave in" => "{2034}{door-rock-cave-in}",
                "2035 window house standard" => "{2035}{window-house-standard}",
                "2036 window store front" => "{2036}{window-store-front}",
                "2037 window curtains only" => "{2037}{window-curtains-only}",
                "2038 window jail bars" => "{2038}{window-jail-bars}",
                "2039 window wooden shutters" => "{2039}{window-wooden-shutters}",
                "2040 window metal shutters" => "{2040}{window-metal-shutters}",
                "2041 window stained glass" => "{2041}{window-stained-glass}",
                "2042 window boarded up" => "{2042}{window-boarded-up}",
                _ => input
            };

            var regex = new Regex(Pattern);

            if (Regex.Matches(input, Pattern).Count == 0)
            {
                ConsoleExtensions.Log($"Input: |{input}| failed to match pattern: {Pattern}!", "error");
            }
            var matches = Regex.Matches(input, Pattern);

            var output = new string[matches.Count];

            for (var i = 0; i < matches.Count; i++)
            {
                output[i] = regex.Replace(matches[i].Value, Substitution);
            }

            return(output);
        }
Ejemplo n.º 12
0
        public static void CloneHighResPatch(string resultLocation)
        {
            const string repo = "https://github.com/ArcNET-Modding/HighResPatch.git";

            ConsoleExtensions.Log($"Cloning repo: {repo} into: \n {resultLocation}", "info");
            Repository.Clone(repo, resultLocation);
            var files = Directory.EnumerateFiles(resultLocation, "*.*", SearchOption.AllDirectories).ToList();

            if (files.Count == 0)
            {
                return;
            }

            ConsoleExtensions.Log($"Cloned {files.Count} files", "success");
            var highResPath = Path.Combine(resultLocation, "HighRes");

            new DirectoryInfo(highResPath).CopyTo(resultLocation);

            var foldersToDelete = new DirectoryInfo(highResPath);

            ConsoleExtensions.Log($"Removing empty folder: {foldersToDelete}", "info");
            foldersToDelete.ExistsDelete();
        }
Ejemplo n.º 13
0
        private static void Main()
        {
            const string digitStr      = "316574541894516";
            const string digitStrfalse = "31s65745g41894s516";

            ConsoleExtensions.Log($"digitonly? {ConsoleExtensions.YesNo(digitStr.IsDigitsOnly())}", "info");
            ConsoleExtensions.Log($"digitonlyFalse? {ConsoleExtensions.YesNo(digitStrfalse.IsDigitsOnly())}", "info");

            AnsiConsole.Render(ConsoleExtensions.DirectorySummary("C:\\Games\\RimWorld"));

            var choices = new[] { "qwerty", "fooobaar", "123467", "@^@#^&" };

            foreach (var(choice, index) in choices.WithIndex())
            {
                ConsoleExtensions.Log($"Choice: {choice} Index: {index}", "info");
            }

            AnsiConsole.Prompt(ConsoleExtensions.GenerateChoiceMenu(choices));

            const string numbers  = "12345";
            const string numbers2 = "13264.97";
            var          intNumb  = numbers.To <int>();
            var          longNumb = numbers.To <long>();
            var          deciNumb = numbers2.To <decimal>();
            var          floatNum = numbers2.To <float>();

            ConsoleExtensions.Log($"Type: {numbers.GetType()} Value: {numbers}", "info");
            ConsoleExtensions.Log($"Type: {intNumb.GetType()} Value: {intNumb}", "info");
            ConsoleExtensions.Log($"Type: {longNumb.GetType()} Value: {longNumb}", "info");
            ConsoleExtensions.Log($"Type: {deciNumb.GetType()} Value: {deciNumb}", "info");
            ConsoleExtensions.Log($"Type: {floatNum.GetType()} Value: {floatNum}", "info");

            const Lang lang    = Lang.Fr;
            var        langInt = lang.ToInt();

            ConsoleExtensions.Log($"langInt: {langInt}", "info");
            var enumCount = lang.CountMembers();

            ConsoleExtensions.Log($"enumCount: {enumCount}", "info");
            var enumDesc = lang.GetDescription();

            ConsoleExtensions.Log($"enumDesc: {enumDesc}", "info");

            const string endsWithDigits = "b54891stastassgfdahblab545lafgijfsdgisdogi ... 12 ... 1234 dfhgsdffhgsdf 14 56";
            var          endsDigits     = endsWithDigits.EndsWithDigits(4);

            ConsoleExtensions.Log($"endsDigits: {ConsoleExtensions.YesNo(endsDigits)}", "info");
            var endDigitStr = endsWithDigits.GetDigitsFromEnd(4);

            ConsoleExtensions.Log($"endDigitStr: {endDigitStr}", "info");
            ConsoleExtensions.Log($"head: {endsWithDigits.Head(5)} tail: {endsWithDigits.Tail(5)}", "info");

            const string rn = "blblbl" + "\r\n" + "56748946";

            ConsoleExtensions.Log($"rn: {rn}", "info");
            ConsoleExtensions.Log($"rn.RemoveLineBreaks(): {rn.RemoveLineBreaks()}", "info");

            const string firsToUpper = "red green";

            ConsoleExtensions.Log($"firsToUpper: {firsToUpper}", "info");
            ConsoleExtensions.Log($"firsToUpper.FirstCharToUpper(): {firsToUpper.FirstCharToUpper()}", "info");

            const string url = "https://www.youtube.com/";

            ConsoleExtensions.Log($"url: {url.ReplaceForbiddenFilenameChars("_")}", "info");

            var x = "fooo".GetValueFromEnumDescription <describedEnum>();

            ConsoleExtensions.Log($"enum value: {x}", "info");

            var          indicesSTr = "ZArray<ZPair<long,long> > aPotionDiscountRate;";
            const string pattern    = " >";
            List <int>   indices    = new();

            indices.AddRange(indicesSTr.AllIndicesOf(pattern));

            foreach (var n in indices)
            {
                ConsoleExtensions.Log($"Pattern: {pattern} found at: {n}", "info");
                indicesSTr = indicesSTr.ReplaceAt(n, 1);
            }

            ConsoleExtensions.Log($"Replaced: {indicesSTr}", "info");

            const string testStr1  = "short nir";
            const string testStr2  = "short int";
            const string testStr3  = "short n";
            var          testList1 = new List <string> {
                testStr1
            };
            var testList2 = new List <string> {
                testStr2
            };

            ConsoleExtensions.Log($"CharHashEqual: {testStr1.CharHashEqualTo(testStr2)}", "info");
            ConsoleExtensions.Log($"StrHashEqual: {testList1.StrHashEqualTo(testList2)}", "info");
            ConsoleExtensions.Log($"StringsEqual: {testStr1.StringEqualTo(testStr2)}", "info");
            ConsoleExtensions.Log($"StrictlyCharEqual: {testStr1.StrictlyCharEqualTo(testStr2)}", "info");
            ConsoleExtensions.Log($"HeadSizeOfStrB: {testStr1.HeadSizeOfStrB(testStr3)}", "info");

            const string testStr4 = "ZArray<ZPair<long, long>> aPotionDiscountRate;";
            var          split    = testStr4.SplitIfNotPrecededByChar(" ", ',');

            ConsoleExtensions.Log($"Split0 {split[0]} Split1 {split[1]}", "info");

            const string testStr5 = "ščřěžěřžžč";
            var          encoded  = testStr5.EncodeToBytes();
            var          decoder  = testStr5.DecodeToBytes();

            var xx = string.Concat(encoded.Select(b => b.ToString("X2")));
            var nn = string.Concat(decoder.Select(b => b.ToString("X2")));

            ConsoleExtensions.Log($"encoded: {xx} decoded: {nn}", "info", true);
        }
Ejemplo n.º 14
0
        private static void Main()
        {
            Terminal.RenderLogo();

            var choice = Terminal.GetMainMenuChoice();

            ConsoleExtensions.Log($"Selected choice: {choice}", "info");
            switch (choice)
            {
            case "Extract game data":
                ConsoleExtensions.Log($"Choice: {choice} is currently unsupported!", "error");
                break;

            case "Parse extracted game data":
                Parser.ParseExtractedData();
                break;

            case "Install High-Res patch":
                var pathToHighResDir = GetHighResDir();
                var files            = Directory.EnumerateFiles(
                    pathToHighResDir, "*.*", SearchOption.AllDirectories).ToList();

                if (files.Count == 0)
                {
                    ConsoleExtensions.Log("HighResFolder empty proceeding to clone latest version", "info");
                    GitHub.CloneHighResPatch(pathToHighResDir);
                }

                var configPath = Path.Combine(pathToHighResDir + "\\config.ini");
                if (!File.Exists(configPath))
                {
                    throw new InvalidOperationException($"Config file not found at path: {configPath}");
                }

                ConsoleExtensions.Log("Gathering environment info", "info");
                var envInfo = new EnvironmentInfo();
                envInfo.Print();

                ConsoleExtensions.Log("Auto-config according to environment info", "info");
                HighResConfig.AutoConfigure(envInfo);

                ConsoleExtensions.Log("Summary of config.ini:", "info");
                AnsiConsole.Render(Terminal.ConfigTable());

                if (AnsiConsole.Confirm("Would you like to change config?"))
                {
                    AnsiConsole.WriteException(new NotImplementedException());
                    return;
                }

                HighResConfig.Write(configPath);
                LaunchWeidu(CmdArgs.Weidu.InstallHighResPatch, pathToHighResDir);
                break;

            case "Uninstall High-Res patch":
                LaunchWeidu(CmdArgs.Weidu.UninstallHighResPatch);
                break;

            default:
                ConsoleExtensions.Log($"Choice: {choice} is currently unsupported!", "error");
                break;
            }
        }
Ejemplo n.º 15
0
        public static GameObject GetGameObject(this BinaryReader reader)
        {
            var gameObject          = new GameObject();
            var prototypeGameObject = new GameObject();

            gameObject.Header = GameObjectHeaderReader.Read(reader);

            if (!gameObject.Header.IsPrototype())
            {
                prototypeGameObject = GameObjectManager.ObjectList.Find(x =>
                                                                        x.Header.ObjectId.GetId().CompareTo(gameObject.Header.ProtoId.GetId()) == 0);
            }

            const string pathToTypes        = "ArcNET.DataTypes.GameObjects.Types.";
            var          gameObjectObjType  = Type.GetType(pathToTypes + gameObject.Header.GameObjectType);
            const string pathToCustomReader = "ArcNET.DataTypes.BinaryReaderExtensions";
            var          binaryReader       = Type.GetType(pathToCustomReader);

            gameObject.Obj = Activator.CreateInstance(gameObjectObjType ?? throw new InvalidOperationException());

            var props = from p in gameObjectObjType.GetProperties()
                        where p.CanWrite
                        orderby p.PropertyOrder()
                        select p;

            var propertyArray = props.ToArray();

            foreach (var propertyInfo in propertyArray)
            {
                if (binaryReader == null)
                {
                    throw new InvalidOperationException("binaryReader is null");
                }

                var readMethod = binaryReader.GetMethod(propertyInfo.PropertyType.Name.Contains("Tuple")
                    ? "ReadArray"
                    : "Read" + propertyInfo.PropertyType.Name);

                if (readMethod is not null && readMethod.IsGenericMethod)
                {
                    if (propertyInfo.PropertyType.FullName != null)
                    {
                        var genericTypeName = propertyInfo.PropertyType.FullName
                                              .Replace("System.Tuple`2[[", "").Split(new[] { ',' })[0]
                                              .Replace("[]", "");
                        readMethod = readMethod.MakeGenericMethod(Type.GetType(genericTypeName) ?? throw new InvalidOperationException());
                    }
                }

                var parameters = new List <object>()
                {
                    reader
                };
                var bit = (int)Enum.Parse(typeof(Enums.ObjectField), propertyInfo.Name);

                foreach (var param in parameters)
                {
                    ConsoleExtensions.Log($"Parameters: {param} Bit: {bit}", "debug");
                }

                if (gameObject.Header.Bitmap.Get(bit, gameObject.Header.IsPrototype()))
                {
                    if (readMethod is null)
                    {
                        continue;
                    }
                    try
                    {
                        propertyInfo.SetValue(gameObject.Obj, readMethod.Invoke(binaryReader, parameters.ToArray()));
                    }
                    catch (Exception e)
                    {
                        AnsiConsole.WriteException(e);
                        throw;
                    }
                }
                else
                {
                    if (prototypeGameObject == null || prototypeGameObject.Header.GameObjectType.ToString()
                        != gameObjectObjType.ToString())
                    {
                        continue;
                    }

                    var tempType     = prototypeGameObject.Obj.GetType();
                    var tempProperty = tempType.GetProperty(propertyInfo.Name);
                    var tempObj      = tempProperty?.GetValue(prototypeGameObject.Obj);

                    propertyInfo.SetValue(gameObject.Obj, tempObj);
                }
            }

            var artIds = props
                         .Where(item =>
                                item.PropertyType.ToString() == "ArcNET.DataTypes.Common.ArtId" &&
                                item.GetValue(gameObject.Obj) != null).Select(item => ((ArtId)item.GetValue(gameObject.Obj))?.Path);

            foreach (var artId in artIds)
            {
                ArtId.ArtIds.Add(artId);
            }

            return(gameObject);
        }
Ejemplo n.º 16
0
        public void Parse(string type)
        {
            var mobStringList = new List <string>();

            while (true)
            {
                var curLine = _reader.ReadLine();

                if (!string.IsNullOrWhiteSpace(curLine))
                {
                    var lines      = curLine.Split(":", 2);
                    var paramName  = lines[0];
                    var paramValue = lines[1];

                    switch (paramName)
                    {
                    case "Description" when paramValue.Contains(@"\\"):
                        mobStringList.Add(curLine);

                        break;

                    case "Description":
                        mobStringList.Add(curLine);
                        break;

                    case "Internal Name" or "internal name":
                        mobStringList.Add(curLine);
                        break;

                    case "Level":
                        mobStringList.Add(curLine);
                        break;

                    case "Art Number and Palette":
                        mobStringList.Add(curLine);
                        break;

                    case "Scale":
                        mobStringList.Add(curLine);
                        break;

                    case "Alignment":
                        mobStringList.Add(curLine);
                        break;

                    case "Object Flag":
                        mobStringList.Add(curLine);
                        break;

                    case "Critter Flag":
                        mobStringList.Add(curLine);
                        break;

                    case "Critter2 Flag":
                        mobStringList.Add(curLine);
                        break;

                    case "NPC Flag":
                        mobStringList.Add(curLine);
                        break;

                    case "Blit Flag":
                        mobStringList.Add(curLine);
                        break;

                    case "Spell Flag":
                        mobStringList.Add(curLine);
                        break;

                    case "Hit Chart":
                        mobStringList.Add(curLine);
                        break;

                    case "Basic Stat" or "basic stat":
                        mobStringList.Add(curLine);
                        break;

                    case "Spell" or "spell":
                        mobStringList.Add(curLine);
                        break;

                    case "Script":
                        mobStringList.Add(curLine);
                        break;

                    case "Faction":
                        mobStringList.Add(curLine);
                        break;

                    case "AI Packet":
                        mobStringList.Add(curLine);
                        break;

                    case "Material":
                        mobStringList.Add(curLine);
                        break;

                    case "Hit Points":
                        mobStringList.Add(curLine);
                        break;

                    case "Fatigue":
                        mobStringList.Add(curLine);
                        break;

                    case "Damage Resistance" or "damage resistance":
                        mobStringList.Add(curLine);
                        break;

                    case "Fire Resistance":
                        mobStringList.Add(curLine);
                        break;

                    case "Electrical Resistance":
                        mobStringList.Add(curLine);
                        break;

                    case "Poison Resistance":
                        mobStringList.Add(curLine);
                        break;

                    case "Magic Resistance":
                        mobStringList.Add(curLine);
                        break;

                    case "Normal Damage":
                        mobStringList.Add(curLine);
                        break;

                    case "Fatigue Damage":
                        mobStringList.Add(curLine);
                        break;

                    case "Poison Damage":
                        mobStringList.Add(curLine);
                        break;

                    case "Electrical Damage":
                        mobStringList.Add(curLine);
                        break;

                    case "Fire Damage":
                        mobStringList.Add(curLine);
                        break;

                    case "Sound Bank" or "sound bank":
                        mobStringList.Add(curLine);
                        break;

                    case "Portrait":
                        mobStringList.Add(curLine);
                        break;

                    case "Retail Price Multiplier":
                        mobStringList.Add(curLine);
                        break;

                    case "Social Class":
                        mobStringList.Add(curLine);
                        break;

                    case "Category":
                        mobStringList.Add(curLine);
                        break;

                    case "Auto Level Scheme":
                        mobStringList.Add(curLine);
                        break;

                    case "Inventory Source":
                        mobStringList.Add(curLine);
                        break;

                    default:
                        ConsoleExtensions.Log($"unrecognized entity param:|{paramName}|", "warn");
                        break;
                    }
                }

                if (string.IsNullOrWhiteSpace(curLine))
                {
                    //assuming end of one mob block...
                    switch (type)
                    {
                    case "Monster":
                    {
                        var currentMob = Monster.GetFromText(mobStringList);
                        GameObjectManager.Monsters.Add(currentMob);
                        break;
                    }

                    case "NPC":
                    {
                        var currentNpc = NPC.GetFromText(mobStringList);
                        GameObjectManager.NPCs.Add(currentNpc);
                        break;
                    }

                    case "Unique":
                    {
                        var currentUnique = Unique.GetFromText(mobStringList);
                        GameObjectManager.Uniques.Add(currentUnique);
                        break;
                    }
                    }

                    mobStringList.Clear();
                }

                if (curLine == null)
                {
                    break;
                }
            }
        }
Ejemplo n.º 17
0
        private static Tuple <BasicStatType, int> GetBasicStat(string paramValue)
        {
            Tuple <BasicStatType, int> basicStatTuple = null;
            var trimmedStats = paramValue.TrimStart();

            //skip junk
            if (trimmedStats.Equals("Strength 13") || trimmedStats.Equals("Dexterity 15") ||
                trimmedStats.Equals("Dexterity 14"))
            {
                return(null);
            }

            var separator = "\t\t";

            if (trimmedStats.Contains("Gender") || trimmedStats.Contains("Race"))
            {
                separator = " ";
            }
            if (trimmedStats.Contains("tech points") || trimmedStats.Contains("magick points"))
            {
                var whitespaceIndexes = GetWhitespaceIndexes(trimmedStats);
                if (whitespaceIndexes.Count >= 2)
                {
                    trimmedStats = trimmedStats.Remove(whitespaceIndexes.First(), 1);
                    //ConsoleExtensions.Log($"trimmedStats after removal:|{trimmedStats}|", "warn");
                }
                separator = " ";
            }
            if (trimmedStats.Contains("Constitution") || trimmedStats.Contains("Intelligence"))
            {
                separator = "\t";
            }

            var statAndValue = trimmedStats.Split(separator, 2);
            var statType     = statAndValue[0].Trim();

            statType = statType switch
            {
                "magickpoints" => "MagickPoints",
                "techpoints" => "TechPoints",
                _ => statType
            };

            if (!((IList)Enum.GetNames(typeof(BasicStatType))).Contains(statType))
            {
                ConsoleExtensions.Log($"unrecognized Entity.BasicStatType param:|{statType}|", "warn");
            }

            var statValue = statAndValue[1].Trim();

            //ConsoleExtensions.Log($"statType:|{statType}| value:|{statValue}|", "warn");

            foreach (var basicStatType in (BasicStatType[])Enum.GetValues(typeof(BasicStatType)))
            {
                var enumValueName = Enum.GetName(typeof(BasicStatType), basicStatType);
                if (!enumValueName.Equals(statType))
                {
                    //ConsoleExtensions.Log($"Failed to match enumValueName:|{enumValueName}| vs statType:|{statType}|", "warn");
                    continue;
                }
                basicStatTuple = new Tuple <BasicStatType, int>(basicStatType, int.Parse(statValue));
            }

            return(basicStatTuple);
        }