Exemplo n.º 1
0
        public static void Load(XElement element, Submarine submarine)
        {
            Rectangle rect = Rectangle.Empty;

            if (element.Attribute("rect") != null)
            {
                string   rectString = ToolBox.GetAttributeString(element, "rect", "0,0,0,0");
                string[] rectValues = rectString.Split(',');

                rect = new Rectangle(
                    int.Parse(rectValues[0]),
                    int.Parse(rectValues[1]),
                    int.Parse(rectValues[2]),
                    int.Parse(rectValues[3]));
            }
            else
            {
                rect = new Rectangle(
                    int.Parse(element.Attribute("x").Value),
                    int.Parse(element.Attribute("y").Value),
                    int.Parse(element.Attribute("width").Value),
                    int.Parse(element.Attribute("height").Value));
            }

            Hull h = new Hull(MapEntityPrefab.list.Find(m => m.Name == "Hull"), rect, submarine);

            h.volume = ToolBox.GetAttributeFloat(element, "pressure", 0.0f);

            h.ID = (ushort)int.Parse(element.Attribute("ID").Value);
        }
Exemplo n.º 2
0
        //constructors & generation ----------------------------------------------------

        public Submarine(string filePath, string hash = "", bool tryLoad = true) : base(null)
        {
            this.filePath = filePath;
            try
            {
                name = System.IO.Path.GetFileNameWithoutExtension(filePath);
            }
            catch (Exception e)
            {
                DebugConsole.ThrowError("Error loading submarine " + filePath + "!", e);
            }

            if (hash != "")
            {
                this.hash = new Md5Hash(hash);
            }

            if (tryLoad)
            {
                XDocument doc = OpenFile(filePath);

                if (doc != null && doc.Root != null)
                {
                    Description = ToolBox.GetAttributeString(doc.Root, "description", "");
                    Enum.TryParse(ToolBox.GetAttributeString(doc.Root, "tags", ""), out tags);
                }
            }

            DockedTo = new List <Submarine>();


            ID = ushort.MaxValue;
            base.Remove();
        }
Exemplo n.º 3
0
        public SinglePlayerMode(XElement element)
            : this(GameModePreset.list.Find(gm => gm.Name == "Single Player"), null)
        {
            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "crew":
                    GameMain.GameSession.CrewManager = new CrewManager(subElement);
                    break;

                case "map":
                    Map = Map.Load(subElement);
                    break;
                }
            }

            //backwards compatibility with older save files
            if (Map == null)
            {
                string mapSeed = ToolBox.GetAttributeString(element, "mapseed", "a");

                GenerateMap(mapSeed);

                Map.SetLocation(ToolBox.GetAttributeInt(element, "currentlocation", 0));
            }

            savedOnStart = true;
        }
Exemplo n.º 4
0
        private void GenerateWallVertices(XElement rootElement)
        {
            List <Vector2> points = new List <Vector2>();

            var wallPrefabs =
                MapEntityPrefab.list.FindAll(mp => (mp is StructurePrefab) && ((StructurePrefab)mp).HasBody);

            foreach (XElement element in rootElement.Elements())
            {
                if (element.Name != "Structure")
                {
                    continue;
                }

                string name = ToolBox.GetAttributeString(element, "name", "");
                if (!wallPrefabs.Any(wp => wp.Name == name))
                {
                    continue;
                }

                var rect = ToolBox.GetAttributeVector4(element, "rect", Vector4.Zero);

                points.Add(new Vector2(rect.X, rect.Y));
                points.Add(new Vector2(rect.X + rect.Z, rect.Y));
                points.Add(new Vector2(rect.X, rect.Y - rect.W));
                points.Add(new Vector2(rect.X + rect.Z, rect.Y - rect.W));
            }

            wallVertices = MathUtils.GiftWrap(points);
        }
Exemplo n.º 5
0
        public MonsterEvent(XElement element)
            : base(element)
        {
            characterFile = ToolBox.GetAttributeString(element, "characterfile", "");

            minAmount = ToolBox.GetAttributeInt(element, "minamount", 1);
            maxAmount = Math.Max(ToolBox.GetAttributeInt(element, "maxamount", 1), minAmount);

            var spawnPosTypeStr = ToolBox.GetAttributeString(element, "spawntype", "");

            if (string.IsNullOrWhiteSpace(spawnPosTypeStr) ||
                !Enum.TryParse <Level.PositionType>(spawnPosTypeStr, true, out spawnPosType))
            {
                spawnPosType = Level.PositionType.MainPath;
            }

            spawnDeep = ToolBox.GetAttributeBool(element, "spawndeep", false);

            if (GameMain.NetworkMember != null)
            {
                List <string> monsterNames = GameMain.NetworkMember.monsterEnabled.Keys.ToList();
                string        tryKey       = monsterNames.Find(s => characterFile.ToLower().Contains(s.ToLower()));
                if (!string.IsNullOrWhiteSpace(tryKey))
                {
                    if (!GameMain.NetworkMember.monsterEnabled[tryKey])
                    {
                        disallowed = true;                                                 //spawn was disallowed by host
                    }
                }
            }
        }
Exemplo n.º 6
0
        public static List <string> GetRequiredFiles(XDocument fileListDoc)
        {
            List <string> requiredFiles = new List <string>();

            XElement fileList = fileListDoc.Root;

            if (fileList == null)
            {
                throw new Exception("Received list of new files was corrupted");
            }

            foreach (XElement file in fileList.Elements())
            {
                string filePath = ToolBox.GetAttributeString(file, "path", "");

                if (!File.Exists(filePath))
                {
                    requiredFiles.Add(filePath);
                    continue;
                }

                string md5 = ToolBox.GetAttributeString(file, "md5", "");

                if (GetFileMd5Hash(filePath) != md5)
                {
                    requiredFiles.Add(filePath);
                }
            }

            return(requiredFiles);
        }
Exemplo n.º 7
0
        public static Map Load(XElement element)
        {
            string mapSeed = ToolBox.GetAttributeString(element, "seed", "a");

            int size = ToolBox.GetAttributeInt(element, "size", 500);
            Map map = new Map(mapSeed, size);

            map.SetLocation(ToolBox.GetAttributeInt(element, "currentlocation", 0));

            string discoveredStr = ToolBox.GetAttributeString(element, "discovered", "");

            string[] discoveredStrs = discoveredStr.Split(',');
            for (int i = 0; i < discoveredStrs.Length; i++ )
            {
                int index = -1;
                if (int.TryParse(discoveredStrs[i], out index)) map.locations[index].Discovered = true;
            }
            
            string passedStr = ToolBox.GetAttributeString(element, "passed", "");
            string[] passedStrs = passedStr.Split(',');
            for (int i = 0; i < passedStrs.Length; i++)
            {
                int index = -1;
                if (int.TryParse(passedStrs[i], out index)) map.connections[index].Passed = true;
            }
            
            return map;
        }
Exemplo n.º 8
0
        public FixRequirement(XElement element)
        {
            name = ToolBox.GetAttributeString(element, "name", "");

            requiredSkills = new List <Skill>();
            requiredItems  = new List <string>();

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "skill":
                    string skillName = ToolBox.GetAttributeString(subElement, "name", "");
                    int    level     = ToolBox.GetAttributeInt(subElement, "level", 1);

                    requiredSkills.Add(new Skill(skillName, level));
                    break;

                case "item":
                    string itemName = ToolBox.GetAttributeString(subElement, "name", "");

                    requiredItems.Add(itemName);
                    break;
                }
            }
        }
Exemplo n.º 9
0
        public CharacterSound(XElement element)
        {
            Sound = Sound.Load(element.Attribute("file").Value);
            Range = ToolBox.GetAttributeFloat(element, "range", 1000.0f);

            Enum.TryParse <SoundType>(ToolBox.GetAttributeString(element, "state", "Idle"), true, out Type);
        }
Exemplo n.º 10
0
        public Attack(XElement element)
        {
            try
            {
                DamageType = (DamageType)Enum.Parse(typeof(DamageType), ToolBox.GetAttributeString(element, "damagetype", "None"), true);
            }
            catch
            {
                DamageType = DamageType.None;
            }

            damage          = ToolBox.GetAttributeFloat(element, "damage", 0.0f);
            structureDamage = ToolBox.GetAttributeFloat(element, "structuredamage", 0.0f);
            bleedingDamage  = ToolBox.GetAttributeFloat(element, "bleedingdamage", 0.0f);
            Stun            = ToolBox.GetAttributeFloat(element, "stun", 0.0f);

            SeverLimbsProbability = ToolBox.GetAttributeFloat(element, "severlimbsprobability", 0.0f);

            Force       = ToolBox.GetAttributeFloat(element, "force", 0.0f);
            TargetForce = ToolBox.GetAttributeFloat(element, "targetforce", 0.0f);
            Torque      = ToolBox.GetAttributeFloat(element, "torque", 0.0f);

            Range    = ToolBox.GetAttributeFloat(element, "range", 0.0f);
            Duration = ToolBox.GetAttributeFloat(element, "duration", 0.0f);

            priority = ToolBox.GetAttributeFloat(element, "priority", 1.0f);

            InitProjSpecific(element);

            string limbIndicesStr = ToolBox.GetAttributeString(element, "applyforceonlimbs", "");

            if (!string.IsNullOrWhiteSpace(limbIndicesStr))
            {
                ApplyForceOnLimbs = new List <int>();
                foreach (string limbIndexStr in limbIndicesStr.Split(','))
                {
                    int limbIndex;
                    if (int.TryParse(limbIndexStr, out limbIndex))
                    {
                        ApplyForceOnLimbs.Add(limbIndex);
                    }
                }
            }

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "statuseffect":
                    if (statusEffects == null)
                    {
                        statusEffects = new List <StatusEffect>();
                    }
                    statusEffects.Add(StatusEffect.Load(subElement));
                    break;
                }
            }
        }
Exemplo n.º 11
0
        public Sprite(XElement element, string path = "", string file = "")
        {
            if (file == "")
            {
                file = ToolBox.GetAttributeString(element, "texture", "");
            }

            if (file == "")
            {
                DebugConsole.ThrowError("Sprite " + element + " doesn't have a texture specified!");
                return;
            }

            if (!string.IsNullOrEmpty(path))
            {
                if (!path.EndsWith("/"))
                {
                    path += "/";
                }
            }

            this.file = path + file;

            texture = LoadTexture(this.file);

            if (texture == null)
            {
                return;
            }

            Vector4 sourceVector = ToolBox.GetAttributeVector4(element, "sourcerect", Vector4.Zero);

            if (sourceVector.Z == 0.0f)
            {
                sourceVector.Z = texture.Width;
            }
            if (sourceVector.W == 0.0f)
            {
                sourceVector.W = texture.Height;
            }

            sourceRect = new Rectangle(
                (int)sourceVector.X, (int)sourceVector.Y,
                (int)sourceVector.Z, (int)sourceVector.W);

            origin   = ToolBox.GetAttributeVector2(element, "origin", new Vector2(0.5f, 0.5f));
            origin.X = origin.X * sourceRect.Width;
            origin.Y = origin.Y * sourceRect.Height;

            size    = ToolBox.GetAttributeVector2(element, "size", Vector2.One);
            size.X *= sourceRect.Width;
            size.Y *= sourceRect.Height;

            Depth = ToolBox.GetAttributeFloat(element, "depth", 0.0f);

            list.Add(this);
        }
Exemplo n.º 12
0
        public ScriptedEvent(XElement element)
        {
            name        = ToolBox.GetAttributeString(element, "name", "");
            description = ToolBox.GetAttributeString(element, "description", "");

            difficulty = ToolBox.GetAttributeInt(element, "difficulty", 1);
            commonness = ToolBox.GetAttributeInt(element, "commonness", 1);

            MusicType = ToolBox.GetAttributeString(element, "musictype", "default");
        }
Exemplo n.º 13
0
        private Order(XElement orderElement)
        {
            Name      = ToolBox.GetAttributeString(orderElement, "name", "Name not found");
            DoingText = ToolBox.GetAttributeString(orderElement, "doingtext", "");

            string targetItemName = ToolBox.GetAttributeString(orderElement, "targetitemtype", "");

            if (!string.IsNullOrWhiteSpace(targetItemName))
            {
                try
                {
                    ItemComponentType = Type.GetType("Barotrauma.Items.Components." + targetItemName, true, true);
                }

                catch (Exception e)
                {
                    DebugConsole.ThrowError("Error in " + ConfigFile + ", item component type " + targetItemName + " not found", e);
                }
            }

            ItemName = ToolBox.GetAttributeString(orderElement, "targetitemname", "");

            Color = new Color(ToolBox.GetAttributeVector4(orderElement, "color", new Vector4(1.0f, 1.0f, 1.0f, 1.0f)));

            UseController = ToolBox.GetAttributeBool(orderElement, "usecontroller", false);

            string optionStr = ToolBox.GetAttributeString(orderElement, "options", "");

            if (string.IsNullOrWhiteSpace(optionStr))
            {
                Options = new string[0];
            }
            else
            {
                Options = optionStr.Split(',');

                for (int i = 0; i < Options.Length; i++)
                {
                    Options[i] = Options[i].Trim();
                }
            }



            foreach (XElement subElement in orderElement.Elements())
            {
                if (subElement.Name.ToString().ToLowerInvariant() != "sprite")
                {
                    continue;
                }
                SymbolSprite = new Sprite(subElement);
                break;
            }
        }
Exemplo n.º 14
0
        public Attack(XElement element)
        {
            try
            {
                DamageType = (DamageType)Enum.Parse(typeof(DamageType), ToolBox.GetAttributeString(element, "damagetype", "None"), true);
            }
            catch
            {
                DamageType = DamageType.None;
            }


            damage          = ToolBox.GetAttributeFloat(element, "damage", 0.0f);
            structureDamage = ToolBox.GetAttributeFloat(element, "structuredamage", 0.0f);
            bleedingDamage  = ToolBox.GetAttributeFloat(element, "bleedingdamage", 0.0f);

            Force       = ToolBox.GetAttributeFloat(element, "force", 0.0f);
            TargetForce = ToolBox.GetAttributeFloat(element, "targetforce", 0.0f);

            Torque = ToolBox.GetAttributeFloat(element, "torque", 0.0f);

            Stun = ToolBox.GetAttributeFloat(element, "stun", 0.0f);

            string soundPath = ToolBox.GetAttributeString(element, "sound", "");

            if (!string.IsNullOrWhiteSpace(soundPath))
            {
                sound = Sound.Load(soundPath);
            }

            Range = ToolBox.GetAttributeFloat(element, "range", 0.0f);

            Duration = ToolBox.GetAttributeFloat(element, "duration", 0.0f);

            priority = ToolBox.GetAttributeFloat(element, "priority", 1.0f);

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "particleemitter":
                    particleEmitterPrefab = new ParticleEmitterPrefab(subElement);
                    break;

                case "statuseffect":
                    if (statusEffects == null)
                    {
                        statusEffects = new List <StatusEffect>();
                    }
                    statusEffects.Add(StatusEffect.Load(subElement));
                    break;
                }
            }
        }
Exemplo n.º 15
0
        private void LoadHeadSprite()
        {
            XDocument doc = ToolBox.TryLoadXml(File);

            if (doc == null)
            {
                return;
            }

            XElement ragdollElement = doc.Root.Element("ragdoll");

            foreach (XElement limbElement in ragdollElement.Elements())
            {
                if (ToolBox.GetAttributeString(limbElement, "type", "").ToLowerInvariant() != "head")
                {
                    continue;
                }

                XElement spriteElement = limbElement.Element("sprite");

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

                spritePath = spritePath.Replace("[GENDER]", (this.gender == Gender.Female) ? "f" : "");
                spritePath = spritePath.Replace("[HEADID]", HeadSpriteId.ToString());

                string fileName = Path.GetFileNameWithoutExtension(spritePath);

                //go through the files in the directory to find a matching sprite
                var files = Directory.GetFiles(Path.GetDirectoryName(spritePath)).ToList();
                foreach (string file in files)
                {
                    string fileWithoutTags = Path.GetFileNameWithoutExtension(file);
                    fileWithoutTags = fileWithoutTags.Split('[', ']').First();

                    if (fileWithoutTags != fileName)
                    {
                        continue;
                    }

                    headSprite = new Sprite(spriteElement, "", file);

                    //extract the tags out of the filename
                    SpriteTags = file.Split('[', ']').Skip(1).ToList();
                    if (SpriteTags.Any())
                    {
                        SpriteTags.RemoveAt(SpriteTags.Count - 1);
                    }

                    break;
                }

                break;
            }
        }
Exemplo n.º 16
0
        private void LoadItemAsChild(XElement element, Item parent)
        {
            string itemName = ToolBox.GetAttributeString(element, "name", "");

            ItemPrefab itemPrefab = ItemPrefab.list.Find(ip => ip.Name == itemName) as ItemPrefab;

            if (itemPrefab == null)
            {
                DebugConsole.ThrowError("Couldn't spawn item for cargo mission: item prefab \"" + element.Name.ToString() + "\" not found");
                return;
            }

            WayPoint cargoSpawnPos = WayPoint.GetRandom(SpawnType.Cargo, null, Submarine.MainSub, true);

            if (cargoSpawnPos == null)
            {
                DebugConsole.ThrowError("Couldn't spawn items for cargo mission, cargo spawnpoint not found");
                return;
            }

            var cargoRoom = cargoSpawnPos.CurrentHull;

            if (cargoRoom == null)
            {
                DebugConsole.ThrowError("A waypoint marked as Cargo must be placed inside a room!");
                return;
            }

            Vector2 position = new Vector2(
                cargoSpawnPos.Position.X + Rand.Range(-20.0f, 20.0f, Rand.RandSync.Server),
                cargoRoom.Rect.Y - cargoRoom.Rect.Height + itemPrefab.Size.Y / 2);

            var item = new Item(itemPrefab, position, cargoRoom.Submarine);

            item.FindHull();


            items.Add(item);

            if (parent != null)
            {
                parent.Combine(item);
            }

            foreach (XElement subElement in element.Elements())
            {
                int amount = ToolBox.GetAttributeInt(subElement, "amount", 1);
                for (int i = 0; i < amount; i++)
                {
                    LoadItemAsChild(subElement, item);
                }
            }
        }
Exemplo n.º 17
0
        public static void Load(XElement element, Submarine submarine)
        {
            string rectString = ToolBox.GetAttributeString(element, "rect", "0,0,0,0");

            string[] rectValues = rectString.Split(',');

            Rectangle rect = new Rectangle(
                int.Parse(rectValues[0]),
                int.Parse(rectValues[1]),
                int.Parse(rectValues[2]),
                int.Parse(rectValues[3]));

            string name = element.Attribute("name").Value;

            Structure s = null;

            foreach (MapEntityPrefab ep in MapEntityPrefab.list)
            {
                if (ep.Name == name)
                {
                    s           = new Structure(rect, (StructurePrefab)ep, submarine);
                    s.Submarine = submarine;
                    s.ID        = (ushort)int.Parse(element.Attribute("ID").Value);
                    break;
                }
            }

            if (s == null)
            {
                DebugConsole.ThrowError("Structure prefab " + name + " not found.");
                return;
            }

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString())
                {
                case "section":
                    int index = ToolBox.GetAttributeInt(subElement, "i", -1);
                    if (index == -1)
                    {
                        continue;
                    }

                    s.sections[index].damage =
                        ToolBox.GetAttributeFloat(subElement, "damage", 0.0f);

                    s.sections[index].GapID = ToolBox.GetAttributeInt(subElement, "gap", -1);

                    break;
                }
            }
        }
Exemplo n.º 18
0
        public ArtifactEvent(XElement element)
            : base(element)
        {
            string itemName = ToolBox.GetAttributeString(element, "itemname", "");

            itemPrefab = ItemPrefab.list.Find(ip => ip.Name == itemName) as ItemPrefab;

            if (itemPrefab == null)
            {
                DebugConsole.ThrowError("Error in SalvageMission: couldn't find an item prefab with the name " + itemName);
            }
        }
Exemplo n.º 19
0
        private void InitializeJobItem(Character character, WayPoint spawnPoint, XElement itemElement, Item parentItem = null)
        {
            string itemName = ToolBox.GetAttributeString(itemElement, "name", "");

            ItemPrefab itemPrefab = ItemPrefab.list.Find(ip => ip.Name == itemName) as ItemPrefab;

            if (itemPrefab == null)
            {
                DebugConsole.ThrowError("Tried to spawn \"" + Name + "\" with the item \"" + itemName + "\". Matching item prefab not found.");
                return;
            }

            Item item = new Item(itemPrefab, character.Position, null);

            if (GameMain.Server != null && Entity.Spawner != null)
            {
                Entity.Spawner.CreateNetworkEvent(item, false);
            }

            if (ToolBox.GetAttributeBool(itemElement, "equip", false))
            {
                List <InvSlotType> allowedSlots = new List <InvSlotType>(item.AllowedSlots);
                allowedSlots.Remove(InvSlotType.Any);

                character.Inventory.TryPutItem(item, null, allowedSlots);
            }
            else
            {
                character.Inventory.TryPutItem(item, null, item.AllowedSlots);
            }

            if (item.Prefab.Name == "ID Card" && spawnPoint != null)
            {
                foreach (string s in spawnPoint.IdCardTags)
                {
                    item.AddTag(s);
                }
            }

            if (parentItem != null)
            {
                parentItem.Combine(item);
            }

            foreach (XElement childItemElement in itemElement.Elements())
            {
                InitializeJobItem(character, spawnPoint, childItemElement, item);
            }
        }
Exemplo n.º 20
0
        public static Submarine Load(XElement element, bool unloadPrevious)
        {
            if (unloadPrevious)
            {
                Unload();
            }

            //tryload -> false

            Submarine sub = new Submarine(ToolBox.GetAttributeString(element, "name", ""), "", false);

            sub.Load(unloadPrevious, element);

            return(sub);
        }
Exemplo n.º 21
0
        public static void LoadGame(string fileName)
        {
            string filePath = Path.Combine(SaveFolder, fileName + ".save");

            DecompressToDirectory(filePath, TempPath, null);

            XDocument doc = ToolBox.TryLoadXml(Path.Combine(TempPath, "gamesession.xml"));

            string    subPath     = Path.Combine(TempPath, ToolBox.GetAttributeString(doc.Root, "submarine", "")) + ".sub";
            Submarine selectedMap = new Submarine(subPath, "");// Submarine.Load();

            GameMain.GameSession = new GameSession(selectedMap, fileName, doc);

            //Directory.Delete(tempPath, true);
        }
Exemplo n.º 22
0
        public SkillPrefab(XElement element)
        {
            name = ToolBox.GetAttributeString(element, "name", "");

            var levelString = ToolBox.GetAttributeString(element, "level", "");

            if (levelString.Contains(","))
            {
                levelRange = ToolBox.ParseToVector2(levelString, false);
            }
            else
            {
                float skillLevel = float.Parse(levelString, System.Globalization.CultureInfo.InvariantCulture);
                levelRange = new Vector2(skillLevel, skillLevel);
            }
        }
Exemplo n.º 23
0
        public Explosion(XElement element)
        {
            attack = new Attack(element);

            force = ToolBox.GetAttributeFloat(element, "force", 0.0f);

            sparks    = ToolBox.GetAttributeBool(element, "sparks", true);
            shockwave = ToolBox.GetAttributeBool(element, "shockwave", true);
            flames    = ToolBox.GetAttributeBool(element, "flames", true);
            smoke     = ToolBox.GetAttributeBool(element, "smoke", true);

            decal     = ToolBox.GetAttributeString(element, "decal", "");
            decalSize = ToolBox.GetAttributeFloat(element, "decalSize", 1.0f);

            CameraShake = ToolBox.GetAttributeFloat(element, "camerashake", attack.Range * 0.1f);
        }
Exemplo n.º 24
0
        partial void InitProjSpecific(XElement element)
        {
            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "lightsource":
                    LightSource = new LightSource(subElement);
                    break;

                case "sound":
                    hitSound = Sound.Load(ToolBox.GetAttributeString(subElement, "file", ""));
                    break;
                }
            }
        }
Exemplo n.º 25
0
        public BackgroundSpritePrefab(XElement element)
        {
            string alignmentStr = ToolBox.GetAttributeString(element, "alignment", "");

            if (string.IsNullOrEmpty(alignmentStr) || !Enum.TryParse(alignmentStr, out Alignment))
            {
                Alignment = Alignment.Top | Alignment.Bottom | Alignment.Left | Alignment.Right;
            }

            Commonness = ToolBox.GetAttributeInt(element, "commonness", 1);

            SpawnOnWalls = ToolBox.GetAttributeBool(element, "spawnonwalls", true);

            Scale.X = ToolBox.GetAttributeFloat(element, "minsize", 1.0f);
            Scale.Y = ToolBox.GetAttributeFloat(element, "maxsize", 1.0f);

            DepthRange = ToolBox.GetAttributeVector2(element, "depthrange", new Vector2(0.0f, 1.0f));

            AlignWithSurface = ToolBox.GetAttributeBool(element, "alignwithsurface", false);

            RandomRotation   = ToolBox.GetAttributeVector2(element, "randomrotation", Vector2.Zero);
            RandomRotation.X = MathHelper.ToRadians(RandomRotation.X);
            RandomRotation.Y = MathHelper.ToRadians(RandomRotation.Y);

            SwingAmount = MathHelper.ToRadians(ToolBox.GetAttributeFloat(element, "swingamount", 0.0f));

            OverrideCommonness = new Dictionary <string, int>();

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "sprite":
                    Sprite = new Sprite(subElement);
                    break;

                case "overridecommonness":
                    string levelType = ToolBox.GetAttributeString(subElement, "leveltype", "");
                    if (!OverrideCommonness.ContainsKey(levelType))
                    {
                        OverrideCommonness.Add(levelType, ToolBox.GetAttributeInt(subElement, "commonness", 1));
                    }
                    break;
                }
            }
        }
Exemplo n.º 26
0
        public static void Load(XElement element, Submarine submarine)
        {
            Rectangle rect = Rectangle.Empty;

            if (element.Attribute("rect") != null)
            {
                string   rectString = ToolBox.GetAttributeString(element, "rect", "0,0,0,0");
                string[] rectValues = rectString.Split(',');

                rect = new Rectangle(
                    int.Parse(rectValues[0]),
                    int.Parse(rectValues[1]),
                    int.Parse(rectValues[2]),
                    int.Parse(rectValues[3]));
            }
            else
            {
                rect = new Rectangle(
                    int.Parse(element.Attribute("x").Value),
                    int.Parse(element.Attribute("y").Value),
                    int.Parse(element.Attribute("width").Value),
                    int.Parse(element.Attribute("height").Value));
            }

            bool isHorizontal = rect.Height > rect.Width;

            var horizontalAttribute = element.Attribute("horizontal");

            if (horizontalAttribute != null)
            {
                isHorizontal = horizontalAttribute.Value.ToString() == "true";
            }

            Gap g = new Gap(rect, isHorizontal, submarine);

            g.ID = (ushort)int.Parse(element.Attribute("ID").Value);

            g.linkedToID = new List <ushort>();
            //int i = 0;
            //while (element.Attribute("linkedto" + i) != null)
            //{
            //    g.linkedToID.Add(int.Parse(element.Attribute("linkedto" + i).Value));
            //    i += 1;
            //}
        }
Exemplo n.º 27
0
        private LocationType(XElement element)
        {
            name = element.Name.ToString();

            commonness   = ToolBox.GetAttributeInt(element, "commonness", 1);
            totalWeight += commonness;

            nameFormats = new List <string>();
            foreach (XAttribute nameFormat in element.Element("nameformats").Attributes())
            {
                nameFormats.Add(nameFormat.Value);
            }

            hireableJobs = new List <Tuple <JobPrefab, float> >();
            foreach (XElement subElement in element.Elements())
            {
                if (subElement.Name.ToString().ToLowerInvariant() != "hireable")
                {
                    continue;
                }

                string jobName = ToolBox.GetAttributeString(subElement, "name", "");

                JobPrefab jobPrefab = JobPrefab.List.Find(jp => jp.Name.ToLowerInvariant() == jobName.ToLowerInvariant());
                if (jobPrefab == null)
                {
                    DebugConsole.ThrowError("Invalid job name (" + jobName + ") in location type " + name);
                }

                float jobCommonness = ToolBox.GetAttributeFloat(subElement, "commonness", 1.0f);
                totalHireableWeight += jobCommonness;

                Tuple <JobPrefab, float> hireableJob = new Tuple <JobPrefab, float>(jobPrefab, jobCommonness);

                hireableJobs.Add(hireableJob);
            }

            string spritePath = ToolBox.GetAttributeString(element, "symbol", "Content/Map/beaconSymbol.png");

            symbolSprite = new Sprite(spritePath, new Vector2(0.5f, 0.5f));

            string backgroundPath = ToolBox.GetAttributeString(element, "background", "");

            backGround = new Sprite(backgroundPath, Vector2.Zero);
        }
Exemplo n.º 28
0
        public CharacterInfo(XElement element)
        {
            Name = ToolBox.GetAttributeString(element, "name", "unnamed");

            string genderStr = ToolBox.GetAttributeString(element, "gender", "male").ToLowerInvariant();

            gender = (genderStr == "m") ? Gender.Male : Gender.Female;

            File            = ToolBox.GetAttributeString(element, "file", "");
            Salary          = ToolBox.GetAttributeInt(element, "salary", 1000);
            headSpriteId    = ToolBox.GetAttributeInt(element, "headspriteid", 1);
            StartItemsGiven = ToolBox.GetAttributeBool(element, "startitemsgiven", false);

            int hullId = ToolBox.GetAttributeInt(element, "hull", -1);

            if (hullId > 0 && hullId <= ushort.MaxValue)
            {
                this.HullID = (ushort)hullId;
            }

            pickedItems = new List <ushort>();

            string pickedItemString = ToolBox.GetAttributeString(element, "items", "");

            if (!string.IsNullOrEmpty(pickedItemString))
            {
                string[] itemIds = pickedItemString.Split(',');
                foreach (string s in itemIds)
                {
                    pickedItems.Add((ushort)int.Parse(s));
                }
            }

            foreach (XElement subElement in element.Elements())
            {
                if (subElement.Name.ToString().ToLowerInvariant() != "job")
                {
                    continue;
                }

                Job = new Job(subElement);
                break;
            }
        }
Exemplo n.º 29
0
        public JobPrefab(XElement element)
        {
            Name = ToolBox.GetAttributeString(element, "name", "name not found");

            Description = ToolBox.GetAttributeString(element, "description", "");

            MinNumber = ToolBox.GetAttributeInt(element, "minnumber", 0);
            MaxNumber = ToolBox.GetAttributeInt(element, "maxnumber", 10);

            Commonness = ToolBox.GetAttributeInt(element, "commonness", 10);

            AllowAlways = ToolBox.GetAttributeBool(element, "allowalways", false);

            ItemNames = new List <string>();

            Skills = new List <SkillPrefab>();

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "items":
                    Items = subElement;
                    foreach (XElement itemElement in subElement.Elements())
                    {
                        string itemName = ToolBox.GetAttributeString(itemElement, "name", "");
                        if (!string.IsNullOrWhiteSpace(itemName))
                        {
                            ItemNames.Add(itemName);
                        }
                    }
                    break;

                case "skills":
                    foreach (XElement skillElement in subElement.Elements())
                    {
                        Skills.Add(new SkillPrefab(skillElement));
                    }
                    break;
                }
            }

            Skills.Sort((x, y) => y.LevelRange.X.CompareTo(x.LevelRange.X));
        }
Exemplo n.º 30
0
        partial void InitProjSpecific(XElement element)
        {
            string soundPath = ToolBox.GetAttributeString(element, "sound", "");

            if (!string.IsNullOrWhiteSpace(soundPath))
            {
                sound = Sound.Load(soundPath);
            }

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "particleemitter":
                    particleEmitterPrefab = new ParticleEmitterPrefab(subElement);
                    break;
                }
            }
        }