fCraft.Physics.LoadSettings C# (CSharp) Method

LoadSettings() public static method

public static LoadSettings ( System.Xml.Linq.XElement el, World world ) : void
el System.Xml.Linq.XElement
world World
return void
        public static void LoadSettings( XElement el, World world )
        {
            XAttribute temp;
            if ( ( temp = el.Attribute( "plantPhysics" ) ) != null ) {
                bool isPhy;
                if ( bool.TryParse( temp.Value, out isPhy ) ) {
                    world.EnablePlantPhysics( Player.Console, false );
                }
            }
            if ( ( temp = el.Attribute( "tntPhysics" ) ) != null ) {
                bool isPhy;
                if ( bool.TryParse( temp.Value, out isPhy ) ) {
                    world.EnableTNTPhysics( Player.Console, false );
                }
            }
            if ( ( temp = el.Attribute( "waterPhysics" ) ) != null ) {
                bool isPhy;
                if ( bool.TryParse( temp.Value, out isPhy ) ) {
                    world.EnableWaterPhysics( Player.Console, false );
                }
            }
        }

Usage Example

Example #1
0
        private static void LoadWorldListEntry([NotNull] XElement el)
        {
            if (el == null)
            {
                throw new ArgumentNullException("el");
            }
            XAttribute tempAttr;

            if ((tempAttr = el.Attribute("name")) == null)
            {
                Logger.Log(LogType.Error, "WorldManager: World tag with no name skipped.");
                return;
            }
            string worldName = tempAttr.Value;

            bool neverUnload = (el.Attribute("noUnload") != null);

            World world;

            try {
                world = AddWorld(null, worldName, null, neverUnload);
            } catch (WorldOpException ex) {
                Logger.Log(LogType.Error,
                           "WorldManager: Error adding world \"{0}\": {1}",
                           worldName, ex.Message);
                return;
            }

            if ((tempAttr = el.Attribute("hidden")) != null)
            {
                bool isHidden;
                if (Boolean.TryParse(tempAttr.Value, out isHidden))
                {
                    world.IsHidden = isHidden;
                }
                else
                {
                    Logger.Log(LogType.Warning,
                               "WorldManager: Could not parse \"hidden\" attribute of world \"{0}\", assuming NOT hidden.",
                               worldName);
                }
            }

            if ((tempAttr = el.Attribute("visitCount")) != null)
            {
                int vCount;
                if (Int32.TryParse(tempAttr.Value, out vCount))
                {
                    world.VisitCount = vCount;
                }
                else
                {
                    Logger.Log(LogType.Warning,
                               "WorldManager: Could not parse \"VisitCount\" attribute of world \"{0}\", assuming NO Visits.",
                               worldName);
                }
            }
            if (firstWorld == null)
            {
                firstWorld = world;
            }

            XElement tempEl = el.Element("Greeting");

            if (tempEl != null && !String.IsNullOrEmpty(tempEl.Value))
            {
                world.Greeting = tempEl.Value;
            }

            if ((tempEl = el.Element(AccessSecurityXmlTagName)) != null)
            {
                world.AccessSecurity = new SecurityController(tempEl, true);
            }
            else if ((tempEl = el.Element("accessSecurity")) != null)
            {
                world.AccessSecurity = new SecurityController(tempEl, true);
            }
            if ((tempEl = el.Element(BuildSecurityXmlTagName)) != null)
            {
                world.BuildSecurity = new SecurityController(tempEl, true);
            }
            else if ((tempEl = el.Element("buildSecurity")) != null)
            {
                world.BuildSecurity = new SecurityController(tempEl, true);
            }

            if ((tempAttr = el.Attribute("backup")) != null)
            {
                TimeSpan backupInterval;
                if (tempAttr.Value.ToTimeSpan(out backupInterval))
                {
                    world.BackupInterval = backupInterval;
                }
                else
                {
                    world.BackupInterval = WorldManager.DefaultBackupInterval;
                    Logger.Log(LogType.Warning,
                               "WorldManager: Could not parse \"backup\" attribute of world \"{0}\", assuming default ({1}).",
                               worldName,
                               world.BackupInterval.ToMiniString());
                }
            }
            else
            {
                world.BackupInterval = WorldManager.DefaultBackupInterval;
            }

            XElement blockEl = el.Element(BlockDB.XmlRootName);

            if (blockEl != null)
            {
                world.BlockDB.LoadSettings(blockEl);
            }

            XElement PhyEl = el.Element(Physics.XmlRootName);

            if (PhyEl != null)
            {
                Physics.LoadSettings(PhyEl, world);
            }

            XElement PhyEl2 = el.Element(Physics.XmlRootName2);

            if (PhyEl2 != null)
            {
                Physics.LoadOtherSettings(PhyEl2, world);
            }

            XElement RealmEl = el.Element(world.RealmXMLRootName);

            if (RealmEl != null)
            {
                world.LoadRealmState(RealmEl);
            }

            XElement envEl = el.Element(EnvironmentXmlTagName);

            if (envEl != null)
            {
                if ((tempAttr = envEl.Attribute("cloud")) != null)
                {
                    if (!Int32.TryParse(tempAttr.Value, out world.CloudColor))
                    {
                        world.CloudColor = -1;
                        Logger.Log(LogType.Warning,
                                   "WorldManager: Could not parse \"cloud\" attribute of Environment settings for world \"{0}\", assuming default (normal).",
                                   worldName);
                    }
                }
                if ((tempAttr = envEl.Attribute("terrain")) != null)
                {
                    world.Terrain = envEl.Attribute("terrain").Value;
                }

                if ((tempAttr = envEl.Attribute("fog")) != null)
                {
                    if (!Int32.TryParse(tempAttr.Value, out world.FogColor))
                    {
                        world.FogColor = -1;
                        Logger.Log(LogType.Warning,
                                   "WorldManager: Could not parse \"fog\" attribute of Environment settings for world \"{0}\", assuming default (normal).",
                                   worldName);
                    }
                }
                if ((tempAttr = envEl.Attribute("sky")) != null)
                {
                    if (!Int32.TryParse(tempAttr.Value, out world.SkyColor))
                    {
                        world.SkyColor = -1;
                        Logger.Log(LogType.Warning,
                                   "WorldManager: Could not parse \"sky\" attribute of Environment settings for world \"{0}\", assuming default (normal).",
                                   worldName);
                    }
                }
                if ((tempAttr = envEl.Attribute("level")) != null)
                {
                    if (!Int32.TryParse(tempAttr.Value, out world.EdgeLevel))
                    {
                        world.EdgeLevel = -1;
                        Logger.Log(LogType.Warning,
                                   "WorldManager: Could not parse \"level\" attribute of Environment settings for world \"{0}\", assuming default (normal).",
                                   worldName);
                    }
                }

                if ((tempAttr = envEl.Attribute("edge")) != null)
                {
                    Block block = Map.GetBlockByName(tempAttr.Value);
                    if (block == Block.Undefined)
                    {
                        world.EdgeBlock = Block.Water;
                        Logger.Log(LogType.Warning,
                                   "WorldManager: Could not parse \"edge\" attribute of Environment settings for world \"{0}\", assuming default (Water).",
                                   worldName);
                    }
                    else
                    {
                        if (Map.GetEdgeTexture(block) == null)
                        {
                            world.EdgeBlock = Block.Water;
                            Logger.Log(LogType.Warning,
                                       "WorldManager: Unacceptable blocktype given for \"edge\" attribute of Environment settings for world \"{0}\", assuming default (Water).",
                                       worldName);
                        }
                        else
                        {
                            world.EdgeBlock = block;
                        }
                    }
                }
            }

            foreach (XElement mainedRankEl in el.Elements(RankMainXmlTagName))
            {
                Rank rank = Rank.Parse(mainedRankEl.Value);
                if (rank != null)
                {
                    if (rank < world.AccessSecurity.MinRank)
                    {
                        world.AccessSecurity.MinRank = rank;
                        Logger.Log(LogType.Warning,
                                   "WorldManager: Lowered access MinRank of world {0} to allow it to be the main world for that rank.",
                                   rank.Name);
                    }
                    rank.MainWorld = world;
                }
            }

            CheckMapFile(world);
        }