Пример #1
0
        public Holdable(Item item, XElement element)
            : base(item, element)
        {
            body = item.body;

            Pusher = null;
            if (element.GetAttributeBool("blocksplayers", false))
            {
                Pusher = new PhysicsBody(item.body.width, item.body.height, item.body.radius, item.body.Density)
                {
                    BodyType            = FarseerPhysics.Dynamics.BodyType.Dynamic,
                    CollidesWith        = Physics.CollisionCharacter,
                    CollisionCategories = Physics.CollisionItemBlocking,
                    Enabled             = false
                };
                Pusher.FarseerBody.FixedRotation = false;
                Pusher.FarseerBody.GravityScale  = 0.0f;
            }

            handlePos       = new Vector2[2];
            scaledHandlePos = new Vector2[2];
            Vector2 previousValue = Vector2.Zero;

            for (int i = 1; i < 3; i++)
            {
                int    index         = i - 1;
                string attributeName = "handle" + i;
                var    attribute     = element.Attribute(attributeName);
                // If no value is defind for handle2, use the value of handle1.
                var value = attribute != null?ConvertUnits.ToSimUnits(XMLExtensions.ParseVector2(attribute.Value)) : previousValue;

                handlePos[index] = value;
                previousValue    = value;
            }

            canBePicked = true;

            if (attachable)
            {
                prevMsg           = DisplayMsg;
                prevPickKey       = PickKey;
                prevRequiredItems = new Dictionary <RelatedItem.RelationType, List <RelatedItem> >(requiredItems);

                if (item.Submarine != null)
                {
                    if (item.Submarine.Loading)
                    {
                        AttachToWall();
                        attached = false;
                    }
                    else //the submarine is not being loaded, which means we're either in the sub editor or the item has been spawned mid-round
                    {
                        if (Screen.Selected == GameMain.SubEditorScreen)
                        {
                            //in the sub editor, attach
                            AttachToWall();
                        }
                        else
                        {
                            //spawned mid-round, deattach
                            DeattachFromWall();
                        }
                    }
                }
            }
        }
Пример #2
0
 public override void Save(XElement element)
 {
     base.Save(element);
     for (int i = 0; i < deformRows.Count; i++)
     {
         element.Add(new XAttribute("row" + i, string.Join(" ", deformRows[i].Select(r => XMLExtensions.Vector2ToString(r)))));
     }
 }
Пример #3
0
        public CustomDeformation(XElement element) : base(element, new CustomDeformationParams(element))
        {
            phase = Rand.Range(0.0f, MathHelper.TwoPi);

            if (element == null)
            {
                deformRows.Add(new Vector2[] { Vector2.Zero, Vector2.Zero });
                deformRows.Add(new Vector2[] { Vector2.Zero, Vector2.Zero });
            }
            else
            {
                for (int i = 0; ; i++)
                {
                    string row = element.GetAttributeString("row" + i, "");
                    if (string.IsNullOrWhiteSpace(row))
                    {
                        break;
                    }

                    string[]  splitRow   = row.Split(' ');
                    Vector2[] rowVectors = new Vector2[splitRow.Length];
                    for (int j = 0; j < splitRow.Length; j++)
                    {
                        rowVectors[j] = XMLExtensions.ParseVector2(splitRow[j]);
                    }
                    deformRows.Add(rowVectors);
                }
            }

            if (deformRows.Count() == 0 || deformRows.First() == null || deformRows.First().Length == 0)
            {
                return;
            }

            var configDeformation = new Vector2[deformRows.First().Length, deformRows.Count];

            for (int x = 0; x < configDeformation.GetLength(0); x++)
            {
                for (int y = 0; y < configDeformation.GetLength(1); y++)
                {
                    configDeformation[x, y] = deformRows[y][x];
                }
            }

            //construct an array for the desired resolution,
            //interpolating values if the resolution configured in the xml is smaller
            //deformation = new Vector2[Resolution.X, Resolution.Y];
            float divX = 1.0f / Resolution.X, divY = 1.0f / Resolution.Y;

            for (int x = 0; x < Resolution.X; x++)
            {
                float normalizedX = x / (float)(Resolution.X - 1);
                for (int y = 0; y < Resolution.Y; y++)
                {
                    float normalizedY = y / (float)(Resolution.Y - 1);

                    Point indexTopLeft = new Point(
                        Math.Min((int)Math.Floor(normalizedX * (configDeformation.GetLength(0) - 1)), configDeformation.GetLength(0) - 1),
                        Math.Min((int)Math.Floor(normalizedY * (configDeformation.GetLength(1) - 1)), configDeformation.GetLength(1) - 1));
                    Point indexBottomRight = new Point(
                        Math.Min(indexTopLeft.X + 1, configDeformation.GetLength(0) - 1),
                        Math.Min(indexTopLeft.Y + 1, configDeformation.GetLength(1) - 1));

                    Vector2 deformTopLeft     = configDeformation[indexTopLeft.X, indexTopLeft.Y];
                    Vector2 deformTopRight    = configDeformation[indexBottomRight.X, indexTopLeft.Y];
                    Vector2 deformBottomLeft  = configDeformation[indexTopLeft.X, indexBottomRight.Y];
                    Vector2 deformBottomRight = configDeformation[indexBottomRight.X, indexBottomRight.Y];

                    Deformation[x, y] = Vector2.Lerp(
                        Vector2.Lerp(deformTopLeft, deformTopRight, (normalizedX % divX) / divX),
                        Vector2.Lerp(deformBottomLeft, deformBottomRight, (normalizedX % divX) / divX),
                        (normalizedY % divY) / divY);
                }
            }
        }
Пример #4
0
        public void LoadClientPermissions()
        {
            ClientPermissions.Clear();

            if (!File.Exists(ClientPermissionsFile))
            {
                if (File.Exists("Data/clientpermissions.txt"))
                {
                    LoadClientPermissionsOld("Data/clientpermissions.txt");
                }
                return;
            }

            XDocument doc = XMLExtensions.TryLoadXml(ClientPermissionsFile);

            if (doc == null)
            {
                return;
            }
            foreach (XElement clientElement in doc.Root.Elements())
            {
                string clientName     = clientElement.GetAttributeString("name", "");
                string clientEndPoint = clientElement.GetAttributeString("endpoint", null) ?? clientElement.GetAttributeString("ip", "");
                string steamIdStr     = clientElement.GetAttributeString("steamid", "");

                if (string.IsNullOrWhiteSpace(clientName))
                {
                    DebugConsole.ThrowError("Error in " + ClientPermissionsFile + " - all clients must have a name and an IP address.");
                    continue;
                }
                if (string.IsNullOrWhiteSpace(clientEndPoint) && string.IsNullOrWhiteSpace(steamIdStr))
                {
                    DebugConsole.ThrowError("Error in " + ClientPermissionsFile + " - all clients must have an IP address or a Steam ID.");
                    continue;
                }

                ClientPermissions           permissions       = Networking.ClientPermissions.None;
                List <DebugConsole.Command> permittedCommands = new List <DebugConsole.Command>();

                if (clientElement.Attribute("preset") == null)
                {
                    string permissionsStr = clientElement.GetAttributeString("permissions", "");
                    if (permissionsStr.ToLowerInvariant() == "all")
                    {
                        foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions)))
                        {
                            permissions |= permission;
                        }
                    }
                    else if (!Enum.TryParse(permissionsStr, out permissions))
                    {
                        DebugConsole.ThrowError("Error in " + ClientPermissionsFile + " - \"" + permissionsStr + "\" is not a valid client permission.");
                        continue;
                    }

                    if (permissions.HasFlag(Networking.ClientPermissions.ConsoleCommands))
                    {
                        foreach (XElement commandElement in clientElement.Elements())
                        {
                            if (commandElement.Name.ToString().ToLowerInvariant() != "command")
                            {
                                continue;
                            }

                            string commandName           = commandElement.GetAttributeString("name", "");
                            DebugConsole.Command command = DebugConsole.FindCommand(commandName);
                            if (command == null)
                            {
                                DebugConsole.ThrowError("Error in " + ClientPermissionsFile + " - \"" + commandName + "\" is not a valid console command.");
                                continue;
                            }

                            permittedCommands.Add(command);
                        }
                    }
                }
                else
                {
                    string           presetName = clientElement.GetAttributeString("preset", "");
                    PermissionPreset preset     = PermissionPreset.List.Find(p => p.Name == presetName);
                    if (preset == null)
                    {
                        DebugConsole.ThrowError("Failed to restore saved permissions to the client \"" + clientName + "\". Permission preset \"" + presetName + "\" not found.");
                        return;
                    }
                    else
                    {
                        permissions       = preset.Permissions;
                        permittedCommands = preset.PermittedCommands.ToList();
                    }
                }

                if (!string.IsNullOrEmpty(steamIdStr))
                {
                    if (ulong.TryParse(steamIdStr, out ulong steamID))
                    {
                        ClientPermissions.Add(new SavedClientPermission(clientName, steamID, permissions, permittedCommands));
                    }
                    else
                    {
                        DebugConsole.ThrowError("Error in " + ClientPermissionsFile + " - \"" + steamIdStr + "\" is not a valid Steam ID.");
                        continue;
                    }
                }
                else
                {
                    ClientPermissions.Add(new SavedClientPermission(clientName, clientEndPoint, permissions, permittedCommands));
                }
            }
        }
Пример #5
0
        private void LoadSettings()
        {
            XDocument doc = null;

            if (File.Exists(SettingsFile))
            {
                doc = XMLExtensions.TryLoadXml(SettingsFile);
            }

            if (doc == null || doc.Root == null)
            {
                doc = new XDocument(new XElement("serversettings"));
            }

            SerializableProperties = SerializableProperty.DeserializeProperties(this, doc.Root);

            AutoRestart = doc.Root.GetAttributeBool("autorestart", false);
#if CLIENT
            if (autoRestart)
            {
                GameMain.NetLobbyScreen.SetAutoRestart(autoRestart, AutoRestartInterval);
            }
#endif

            subSelectionMode = SelectionMode.Manual;
            Enum.TryParse(doc.Root.GetAttributeString("SubSelection", "Manual"), out subSelectionMode);
            Voting.AllowSubVoting = subSelectionMode == SelectionMode.Vote;

            modeSelectionMode = SelectionMode.Manual;
            Enum.TryParse(doc.Root.GetAttributeString("ModeSelection", "Manual"), out modeSelectionMode);
            Voting.AllowModeVoting = modeSelectionMode == SelectionMode.Vote;

            var traitorsEnabled = TraitorsEnabled;
            Enum.TryParse(doc.Root.GetAttributeString("TraitorsEnabled", "No"), out traitorsEnabled);
            TraitorsEnabled = traitorsEnabled;
            GameMain.NetLobbyScreen.SetTraitorsEnabled(traitorsEnabled);

            //"65-90", "97-122", "48-59" = upper and lower case english alphabet and numbers
            string[] allowedClientNameCharsStr = doc.Root.GetAttributeStringArray("AllowedClientNameChars", new string[] { "32-33", "65-90", "97-122", "48-59" });
            foreach (string allowedClientNameCharRange in allowedClientNameCharsStr)
            {
                string[] splitRange = allowedClientNameCharRange.Split('-');
                if (splitRange.Length == 0 || splitRange.Length > 2)
                {
                    DebugConsole.ThrowError("Error in server settings - " + allowedClientNameCharRange + " is not a valid range for characters allowed in client names.");
                    continue;
                }

                int min = -1;
                if (!int.TryParse(splitRange[0], out min))
                {
                    DebugConsole.ThrowError("Error in server settings - " + allowedClientNameCharRange + " is not a valid range for characters allowed in client names.");
                    continue;
                }
                int max = min;
                if (splitRange.Length == 2)
                {
                    if (!int.TryParse(splitRange[1], out max))
                    {
                        DebugConsole.ThrowError("Error in server settings - " + allowedClientNameCharRange + " is not a valid range for characters allowed in client names.");
                        continue;
                    }
                }

                if (min > -1 && max > -1)
                {
                    AllowedClientNameChars.Add(Pair <int, int> .Create(min, max));
                }
            }

            AllowedRandomMissionTypes = doc.Root.GetAttributeStringArray(
                "AllowedRandomMissionTypes",
                MissionPrefab.MissionTypes.ToArray()).ToList();

            if (GameMain.NetLobbyScreen != null
#if CLIENT
                && GameMain.NetLobbyScreen.ServerMessage != null
#endif
                )
            {
#if SERVER
                GameMain.NetLobbyScreen.ServerName       = doc.Root.GetAttributeString("name", "");
                GameMain.NetLobbyScreen.SelectedModeName = GameMode;
                GameMain.NetLobbyScreen.MissionTypeName  = MissionType;
#endif
                GameMain.NetLobbyScreen.ServerMessageText = doc.Root.GetAttributeString("ServerMessage", "");
            }

#if CLIENT
            showLogButton.Visible = SaveServerLogs;
#endif

            List <string> monsterNames = GameMain.Config.SelectedContentPackage.GetFilesOfType(ContentType.Character);
            for (int i = 0; i < monsterNames.Count; i++)
            {
                monsterNames[i] = Path.GetFileName(Path.GetDirectoryName(monsterNames[i]));
            }
            monsterEnabled = new Dictionary <string, bool>();
            foreach (string s in monsterNames)
            {
                if (!monsterEnabled.ContainsKey(s))
                {
                    monsterEnabled.Add(s, true);
                }
            }
            extraCargo = new Dictionary <ItemPrefab, int>();

            AutoBanTime    = doc.Root.GetAttributeFloat("autobantime", 60);
            MaxAutoBanTime = doc.Root.GetAttributeFloat("maxautobantime", 360);
        }
Пример #6
0
        private void LoadSettings()
        {
            XDocument doc = null;

            if (File.Exists(SettingsFile))
            {
                doc = XMLExtensions.TryLoadXml(SettingsFile);
            }

            if (doc == null || doc.Root == null)
            {
                doc = new XDocument(new XElement("serversettings"));
            }

            ObjectProperties = ObjectProperty.InitProperties(this, doc.Root);

            AutoRestart = doc.Root.GetAttributeBool("autorestart", false);
#if CLIENT
            if (autoRestart)
            {
                GameMain.NetLobbyScreen.SetAutoRestart(autoRestart, AutoRestartInterval);
            }
#endif

            subSelectionMode = SelectionMode.Manual;
            Enum.TryParse <SelectionMode>(doc.Root.GetAttributeString("SubSelection", "Manual"), out subSelectionMode);
            Voting.AllowSubVoting = subSelectionMode == SelectionMode.Vote;

            modeSelectionMode = SelectionMode.Manual;
            Enum.TryParse <SelectionMode>(doc.Root.GetAttributeString("ModeSelection", "Manual"), out modeSelectionMode);
            Voting.AllowModeVoting = modeSelectionMode == SelectionMode.Vote;

            var traitorsEnabled = TraitorsEnabled;
            Enum.TryParse <YesNoMaybe>(doc.Root.GetAttributeString("TraitorsEnabled", "No"), out traitorsEnabled);
            TraitorsEnabled = traitorsEnabled;
            GameMain.NetLobbyScreen.SetTraitorsEnabled(traitorsEnabled);

            if (GameMain.NetLobbyScreen != null
#if CLIENT
                && GameMain.NetLobbyScreen.ServerMessage != null
#endif
                )
            {
                GameMain.NetLobbyScreen.ServerMessageText = doc.Root.GetAttributeString("ServerMessage", "");
            }

#if CLIENT
            showLogButton.Visible = SaveServerLogs;
#endif

            List <string> monsterNames = Directory.GetDirectories("Content/Characters").ToList();
            for (int i = 0; i < monsterNames.Count; i++)
            {
                monsterNames[i] = monsterNames[i].Replace("Content/Characters", "").Replace("/", "").Replace("\\", "");
            }
            monsterEnabled = new Dictionary <string, bool>();
            foreach (string s in monsterNames)
            {
                monsterEnabled.Add(s, true);
            }
            extraCargo = new Dictionary <string, int>();
        }
Пример #7
0
        private void LoadSettings()
        {
            XDocument doc = null;

            if (File.Exists(SettingsFile))
            {
                doc = XMLExtensions.TryLoadXml(SettingsFile);
            }

            if (doc == null)
            {
                doc = new XDocument(new XElement("serversettings"));
            }

            SerializableProperties = SerializableProperty.DeserializeProperties(this, doc.Root);

            AutoRestart = doc.Root.GetAttributeBool("autorestart", false);

            Voting.AllowSubVoting  = SubSelectionMode == SelectionMode.Vote;
            Voting.AllowModeVoting = ModeSelectionMode == SelectionMode.Vote;

            selectedLevelDifficulty = doc.Root.GetAttributeFloat("LevelDifficulty", 20.0f);
            GameMain.NetLobbyScreen.SetLevelDifficulty(selectedLevelDifficulty);

            GameMain.NetLobbyScreen.SetTraitorsEnabled(traitorsEnabled);

            string[] defaultAllowedClientNameChars =
                new string[] {
                "32-33",
                "38-46",
                "48-57",
                "65-90",
                "91",
                "93",
                "95-122",
                "192-255",
                "384-591",
                "1024-1279",
                "19968-40959", "13312-19903", "131072-15043983", "15043985-173791", "173824-178207", "178208-183983", "63744-64255", "194560-195103" //CJK
            };

            string[] allowedClientNameCharsStr = doc.Root.GetAttributeStringArray("AllowedClientNameChars", defaultAllowedClientNameChars);
            if (doc.Root.GetAttributeString("AllowedClientNameChars", "") == "65-90,97-122,48-59")
            {
                allowedClientNameCharsStr = defaultAllowedClientNameChars;
            }

            foreach (string allowedClientNameCharRange in allowedClientNameCharsStr)
            {
                string[] splitRange = allowedClientNameCharRange.Split('-');
                if (splitRange.Length == 0 || splitRange.Length > 2)
                {
                    DebugConsole.ThrowError("Error in server settings - " + allowedClientNameCharRange + " is not a valid range for characters allowed in client names.");
                    continue;
                }

                int min = -1;
                if (!int.TryParse(splitRange[0], out min))
                {
                    DebugConsole.ThrowError("Error in server settings - " + allowedClientNameCharRange + " is not a valid range for characters allowed in client names.");
                    continue;
                }
                int max = min;
                if (splitRange.Length == 2)
                {
                    if (!int.TryParse(splitRange[1], out max))
                    {
                        DebugConsole.ThrowError("Error in server settings - " + allowedClientNameCharRange + " is not a valid range for characters allowed in client names.");
                        continue;
                    }
                }

                if (min > -1 && max > -1)
                {
                    AllowedClientNameChars.Add(new Pair <int, int>(min, max));
                }
            }

            AllowedRandomMissionTypes = new List <MissionType>();
            string[] allowedMissionTypeNames = doc.Root.GetAttributeStringArray(
                "AllowedRandomMissionTypes", Enum.GetValues(typeof(MissionType)).Cast <MissionType>().Select(m => m.ToString()).ToArray());
            foreach (string missionTypeName in allowedMissionTypeNames)
            {
                if (Enum.TryParse(missionTypeName, out MissionType missionType))
                {
                    if (missionType == Barotrauma.MissionType.None)
                    {
                        continue;
                    }
                    AllowedRandomMissionTypes.Add(missionType);
                }
            }

            ServerName        = doc.Root.GetAttributeString("name", "");
            ServerMessageText = doc.Root.GetAttributeString("ServerMessage", "");

            GameMain.NetLobbyScreen.SelectedModeIdentifier = GameModeIdentifier;
            GameMain.NetLobbyScreen.MissionTypeName        = MissionType;

            GameMain.NetLobbyScreen.SetBotSpawnMode(BotSpawnMode);
            GameMain.NetLobbyScreen.SetBotCount(BotCount);

            List <string> monsterNames = GameMain.Instance.GetFilesOfType(ContentType.Character).ToList();

            for (int i = 0; i < monsterNames.Count; i++)
            {
                monsterNames[i] = Path.GetFileName(Path.GetDirectoryName(monsterNames[i]));
            }
            MonsterEnabled = new Dictionary <string, bool>();
            foreach (string s in monsterNames)
            {
                if (!MonsterEnabled.ContainsKey(s))
                {
                    MonsterEnabled.Add(s, true);
                }
            }
        }
Пример #8
0
            public void ExtractAppearance(CharacterInfo characterInfo, string[] tags)
            {
                Gender disguisedGender              = Gender.None;
                Race   disguisedRace                = Race.None;
                int    disguisedHeadSpriteId        = -1;
                int    disguisedHairIndex           = -1;
                int    disguisedBeardIndex          = -1;
                int    disguisedMoustacheIndex      = -1;
                int    disguisedFaceAttachmentIndex = -1;
                Color  hairColor       = Color.Black;
                Color  facialHairColor = Color.Black;
                Color  skinColor       = Color.Black;

                foreach (string tag in tags)
                {
                    string[] s = tag.Split(':');

                    switch (s[0].ToLowerInvariant())
                    {
                    case "haircolor":
                        hairColor = XMLExtensions.ParseColor(s[1]);
                        break;

                    case "facialhaircolor":
                        facialHairColor = XMLExtensions.ParseColor(s[1]);
                        break;

                    case "skincolor":
                        skinColor = XMLExtensions.ParseColor(s[1]);
                        break;

                    case "gender":
                        Enum.TryParse(s[1], ignoreCase: true, out disguisedGender);
                        break;

                    case "race":
                        Enum.TryParse(s[1], ignoreCase: true, out disguisedRace);
                        break;

                    case "headspriteid":
                        int.TryParse(s[1], NumberStyles.Any, CultureInfo.InvariantCulture, out disguisedHeadSpriteId);
                        break;

                    case "hairindex":
                        disguisedHairIndex = int.Parse(s[1]);
                        break;

                    case "beardindex":
                        disguisedBeardIndex = int.Parse(s[1]);
                        break;

                    case "moustacheindex":
                        disguisedMoustacheIndex = int.Parse(s[1]);
                        break;

                    case "faceattachmentindex":
                        disguisedFaceAttachmentIndex = int.Parse(s[1]);
                        break;

                    case "sheetindex":
                        string[] vectorValues = s[1].Split(";");
                        SheetIndex = new Vector2(float.Parse(vectorValues[0]), float.Parse(vectorValues[1]));
                        break;
                    }
                }

                if ((characterInfo.HasGenders && disguisedGender == Gender.None) ||
                    (characterInfo.HasRaces && disguisedRace == Race.None) ||
                    disguisedHeadSpriteId <= 0)
                {
                    Portrait    = null;
                    Attachments = null;
                    return;
                }

                foreach (XElement limbElement in characterInfo.Ragdoll.MainElement.Elements())
                {
                    if (!limbElement.GetAttributeString("type", "").Equals("head", StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    XElement spriteElement = limbElement.Element("sprite");
                    if (spriteElement == null)
                    {
                        continue;
                    }

                    string spritePath = spriteElement.Attribute("texture").Value;

                    spritePath = spritePath.Replace("[GENDER]", disguisedGender.ToString().ToLowerInvariant());
                    spritePath = spritePath.Replace("[RACE]", disguisedRace.ToString().ToLowerInvariant());
                    spritePath = spritePath.Replace("[HEADID]", disguisedHeadSpriteId.ToString());

                    string fileName = Path.GetFileNameWithoutExtension(spritePath);

                    //go through the files in the directory to find a matching sprite
                    foreach (string file in Directory.GetFiles(Path.GetDirectoryName(spritePath)))
                    {
                        if (!file.EndsWith(".png", StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }
                        string fileWithoutTags = Path.GetFileNameWithoutExtension(file);
                        fileWithoutTags = fileWithoutTags.Split('[', ']').First();
                        if (fileWithoutTags != fileName)
                        {
                            continue;
                        }
                        Portrait = new Sprite(spriteElement, "", file)
                        {
                            RelativeOrigin = Vector2.Zero
                        };
                        break;
                    }

                    break;
                }

                if (characterInfo.Wearables != null)
                {
                    float baldnessChance = disguisedGender == Gender.Female ? 0.05f : 0.2f;

                    List <XElement> createElementList(WearableType wearableType, float emptyCommonness = 1.0f)
                    => CharacterInfo.AddEmpty(
                        characterInfo.FilterByTypeAndHeadID(
                            characterInfo.FilterElementsByGenderAndRace(characterInfo.Wearables, disguisedGender, disguisedRace),
                            wearableType, disguisedHeadSpriteId),
                        wearableType, emptyCommonness);

                    var disguisedHairs           = createElementList(WearableType.Hair, baldnessChance);
                    var disguisedBeards          = createElementList(WearableType.Beard);
                    var disguisedMoustaches      = createElementList(WearableType.Moustache);
                    var disguisedFaceAttachments = createElementList(WearableType.FaceAttachment);

                    XElement getElementFromList(List <XElement> list, int index)
                    => CharacterInfo.IsValidIndex(index, list)
                            ? list[index]
                            : characterInfo.GetRandomElement(list);

                    var disguisedHairElement           = getElementFromList(disguisedHairs, disguisedHairIndex);
                    var disguisedBeardElement          = getElementFromList(disguisedBeards, disguisedBeardIndex);
                    var disguisedMoustacheElement      = getElementFromList(disguisedMoustaches, disguisedMoustacheIndex);
                    var disguisedFaceAttachmentElement = getElementFromList(disguisedFaceAttachments, disguisedFaceAttachmentIndex);

                    Attachments = new List <WearableSprite>();

                    void loadAttachments(List <WearableSprite> attachments, XElement element, WearableType wearableType)
                    {
                        foreach (var s in element?.Elements("sprite") ?? Enumerable.Empty <XElement>())
                        {
                            attachments.Add(new WearableSprite(s, wearableType));
                        }
                    }

                    loadAttachments(Attachments, disguisedFaceAttachmentElement, WearableType.FaceAttachment);
                    loadAttachments(Attachments, disguisedBeardElement, WearableType.Beard);
                    loadAttachments(Attachments, disguisedMoustacheElement, WearableType.Moustache);
                    loadAttachments(Attachments, disguisedHairElement, WearableType.Hair);

                    loadAttachments(Attachments,
                                    characterInfo.OmitJobInPortraitClothing
                            ? JobPrefab.NoJobElement?.Element("PortraitClothing")
                            : JobPrefab?.ClothingElement,
                                    WearableType.JobIndicator);
                }

                HairColor       = hairColor;
                FacialHairColor = facialHairColor;
                SkinColor       = skinColor;
            }
        public void FromXmlNullStringTest()
        {
            Action act = () => XMLExtensions.FromXML <SerializableObjectFake>("");

            act.Should().Throw <ArgumentNullException>();
        }
Пример #10
0
        public void ToXmlNullObjectTest()
        {
            Action act = () => XMLExtensions.ToXML <SerializableObjectFake>(null);

            act.Should().Throw <ArgumentNullException>();
        }
        private void LoadSettings()
        {
            XDocument doc = null;

            if (File.Exists(SettingsFile))
            {
                doc = XMLExtensions.TryLoadXml(SettingsFile);
            }

            if (doc == null || doc.Root == null)
            {
                doc = new XDocument(new XElement("serversettings"));
            }

            SerializableProperties = SerializableProperty.DeserializeProperties(this, doc.Root);

            AutoRestart = doc.Root.GetAttributeBool("autorestart", false);
#if CLIENT
            if (autoRestart)
            {
                GameMain.NetLobbyScreen.SetAutoRestart(autoRestart, AutoRestartInterval);
            }
#endif

            subSelectionMode = SelectionMode.Manual;
            Enum.TryParse(doc.Root.GetAttributeString("SubSelection", "Manual"), out subSelectionMode);
            Voting.AllowSubVoting = subSelectionMode == SelectionMode.Vote;

            modeSelectionMode = SelectionMode.Manual;
            Enum.TryParse(doc.Root.GetAttributeString("ModeSelection", "Manual"), out modeSelectionMode);
            Voting.AllowModeVoting = modeSelectionMode == SelectionMode.Vote;

            var traitorsEnabled = TraitorsEnabled;
            Enum.TryParse(doc.Root.GetAttributeString("TraitorsEnabled", "No"), out traitorsEnabled);
            TraitorsEnabled = traitorsEnabled;
            GameMain.NetLobbyScreen.SetTraitorsEnabled(traitorsEnabled);

            AllowedRandomMissionTypes = doc.Root.GetAttributeStringArray(
                "AllowedRandomMissionTypes",
                MissionPrefab.MissionTypes.ToArray()).ToList();

            if (GameMain.NetLobbyScreen != null
#if CLIENT
                && GameMain.NetLobbyScreen.ServerMessage != null
#endif
                )
            {
#if SERVER
                GameMain.NetLobbyScreen.ServerName       = doc.Root.GetAttributeString("name", "");
                GameMain.NetLobbyScreen.SelectedModeName = GameMode;
                GameMain.NetLobbyScreen.MissionTypeName  = MissionType;
#endif
                GameMain.NetLobbyScreen.ServerMessageText = doc.Root.GetAttributeString("ServerMessage", "");
            }

#if CLIENT
            showLogButton.Visible = SaveServerLogs;
#endif

            List <string> monsterNames = GameMain.Config.SelectedContentPackage.GetFilesOfType(ContentType.Character);
            for (int i = 0; i < monsterNames.Count; i++)
            {
                monsterNames[i] = Path.GetFileName(Path.GetDirectoryName(monsterNames[i]));
            }
            monsterEnabled = new Dictionary <string, bool>();
            foreach (string s in monsterNames)
            {
                if (!monsterEnabled.ContainsKey(s))
                {
                    monsterEnabled.Add(s, true);
                }
            }
            extraCargo = new Dictionary <ItemPrefab, int>();

            AutoBanTime    = doc.Root.GetAttributeFloat("autobantime", 60);
            MaxAutoBanTime = doc.Root.GetAttributeFloat("maxautobantime", 360);
        }
Пример #12
0
        private void LoadSettings()
        {
            XDocument doc = null;

            if (File.Exists(SettingsFile))
            {
                doc = XMLExtensions.TryLoadXml(SettingsFile);
            }

            if (doc == null || doc.Root == null)
            {
                doc = new XDocument(new XElement("serversettings"));
            }

            SerializableProperties = SerializableProperty.DeserializeProperties(this, doc.Root);

            AutoRestart = doc.Root.GetAttributeBool("autorestart", false);

            Voting.AllowSubVoting  = SubSelectionMode == SelectionMode.Vote;
            Voting.AllowModeVoting = ModeSelectionMode == SelectionMode.Vote;

            selectedLevelDifficulty = doc.Root.GetAttributeFloat("LevelDifficulty", 20.0f);
            GameMain.NetLobbyScreen.SetLevelDifficulty(selectedLevelDifficulty);

            var traitorsEnabled = TraitorsEnabled;

            Enum.TryParse(doc.Root.GetAttributeString("TraitorsEnabled", "No"), out traitorsEnabled);
            TraitorsEnabled = traitorsEnabled;
            GameMain.NetLobbyScreen.SetTraitorsEnabled(traitorsEnabled);

            var botSpawnMode = BotSpawnMode.Fill;

            Enum.TryParse(doc.Root.GetAttributeString("BotSpawnMode", "Fill"), out botSpawnMode);
            BotSpawnMode = botSpawnMode;

            //"65-90", "97-122", "48-59" = upper and lower case english alphabet and numbers
            string[] allowedClientNameCharsStr = doc.Root.GetAttributeStringArray("AllowedClientNameChars", new string[] { "65-90", "97-122", "48-59" });
            foreach (string allowedClientNameCharRange in allowedClientNameCharsStr)
            {
                string[] splitRange = allowedClientNameCharRange.Split('-');
                if (splitRange.Length == 0 || splitRange.Length > 2)
                {
                    DebugConsole.ThrowError("Error in server settings - " + allowedClientNameCharRange + " is not a valid range for characters allowed in client names.");
                    continue;
                }

                int min = -1;
                if (!int.TryParse(splitRange[0], out min))
                {
                    DebugConsole.ThrowError("Error in server settings - " + allowedClientNameCharRange + " is not a valid range for characters allowed in client names.");
                    continue;
                }
                int max = min;
                if (splitRange.Length == 2)
                {
                    if (!int.TryParse(splitRange[1], out max))
                    {
                        DebugConsole.ThrowError("Error in server settings - " + allowedClientNameCharRange + " is not a valid range for characters allowed in client names.");
                        continue;
                    }
                }

                if (min > -1 && max > -1)
                {
                    AllowedClientNameChars.Add(new Pair <int, int>(min, max));
                }
            }

            AllowedRandomMissionTypes = new List <MissionType>();
            string[] allowedMissionTypeNames = doc.Root.GetAttributeStringArray(
                "AllowedRandomMissionTypes", Enum.GetValues(typeof(MissionType)).Cast <MissionType>().Select(m => m.ToString()).ToArray());
            foreach (string missionTypeName in allowedMissionTypeNames)
            {
                if (Enum.TryParse(missionTypeName, out MissionType missionType))
                {
                    if (missionType == Barotrauma.MissionType.None)
                    {
                        continue;
                    }
                    AllowedRandomMissionTypes.Add(missionType);
                }
            }

            ServerName        = doc.Root.GetAttributeString("name", "");
            ServerMessageText = doc.Root.GetAttributeString("ServerMessage", "");

            GameMain.NetLobbyScreen.SelectedModeIdentifier = GameModeIdentifier;
            GameMain.NetLobbyScreen.MissionTypeName        = MissionType;

            GameMain.NetLobbyScreen.SetBotSpawnMode(BotSpawnMode);
            GameMain.NetLobbyScreen.SetBotCount(BotCount);

            List <string> monsterNames = GameMain.Instance.GetFilesOfType(ContentType.Character).ToList();

            for (int i = 0; i < monsterNames.Count; i++)
            {
                monsterNames[i] = Path.GetFileName(Path.GetDirectoryName(monsterNames[i]));
            }
            MonsterEnabled = new Dictionary <string, bool>();
            foreach (string s in monsterNames)
            {
                if (!MonsterEnabled.ContainsKey(s))
                {
                    MonsterEnabled.Add(s, true);
                }
            }

            AutoBanTime    = doc.Root.GetAttributeFloat("autobantime", 60);
            MaxAutoBanTime = doc.Root.GetAttributeFloat("maxautobantime", 360);
        }