Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="World"/> class.
        /// </summary>
        /// <param name="parent">Server this world is part of.</param>
        /// <exception cref="ArgumentNullException"><paramref name="parent" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">The unarmed weapon ID is not a valid item template ID.</exception>
        public World(Server parent)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }

            _respawnTaskList = new RespawnTaskList(this);

            // Store the parent
            _server = parent;

            // Create some objects
            _guildMemberPerformer = new GuildMemberPerformer(DbController, FindUser);

            // Create the unarmed weapon
            var unarmedWeaponID       = ServerSettings.Default.UnarmedItemTemplateID;
            var unarmedWeaponTemplate = _itemTemplateManager[unarmedWeaponID];

            if (unarmedWeaponTemplate == null)
            {
                const string errmsg = "Unable to create unarmed weapon - couldn't find item template with ID `{0}`.";
                if (log.IsFatalEnabled)
                {
                    log.FatalFormat(errmsg, unarmedWeaponID);
                }
                throw new ArgumentException(string.Format(errmsg, unarmedWeaponID));
            }

            _unarmedWeapon = new ItemEntity(unarmedWeaponTemplate, 1);

            // Load the maps
            var mapFiles = MapBase.GetMapFiles(ContentPaths.Build);

            _maps = new DArray <Map>(mapFiles.Count() + 10);
            foreach (var mapFile in mapFiles)
            {
                MapID mapID;
                if (!MapBase.TryGetIndexFromPath(mapFile, out mapID))
                {
                    const string errmsg = "Failed to get the ID of map file `{0}`.";
                    if (log.IsFatalEnabled)
                    {
                        log.FatalFormat(errmsg, mapFile);
                    }
                    throw new ArgumentException(string.Format(errmsg, mapFile));
                }

                var m = new Map(mapID, this);
                _maps[(int)mapID] = m;
                m.Load();
            }

            // Trim down the maps array under the assumption we won't be adding more maps
            _maps.Trim();

            // Add some event hooks
            BanningManager.Instance.AccountBanned -= BanningManager_AccountBanned;
            BanningManager.Instance.AccountBanned += BanningManager_AccountBanned;
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="World"/> class.
        /// </summary>
        /// <param name="parent">Server this world is part of.</param>
        /// <exception cref="ArgumentNullException"><paramref name="parent" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">The unarmed weapon ID is not a valid item template ID.</exception>
        public World(Server parent)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }

            _respawnTaskList = new RespawnTaskList(this);

            // Store the parent
            _server = parent;

            // Create some objects
            _guildMemberPerformer = new GuildMemberPerformer(DbController, FindUser);

            // Create the unarmed weapon
            var unarmedWeaponID       = ServerSettings.Default.UnarmedItemTemplateID;
            var unarmedWeaponTemplate = _itemTemplateManager[unarmedWeaponID];

            if (unarmedWeaponTemplate == null)
            {
                const string errmsg = "Unable to create unarmed weapon - couldn't find item template with ID `{0}`.";
                if (log.IsFatalEnabled)
                {
                    log.FatalFormat(errmsg, unarmedWeaponID);
                }
                throw new ArgumentException(string.Format(errmsg, unarmedWeaponID));
            }

            _unarmedWeapon = new ItemEntity(unarmedWeaponTemplate, 1);

            // Create the maps
            var mapFiles = MapBase.GetMapFiles(ContentPaths.Build);

            _maps = mapFiles.LoadIntoIndexedArray(x => (int)x.ID, x =>
            {
                MapID mapID;
                if (!MapBase.TryGetIndexFromPath(x, out mapID))
                {
                    const string errmsg = "Failed to get the ID of map file `{0}`.";
                    if (log.IsFatalEnabled)
                    {
                        log.FatalFormat(errmsg, x);
                    }
                    throw new ArgumentException(string.Format(errmsg, x));
                }

                return(new Map(mapID, this));
            });

            // Load maps in parallel
            Parallel.ForEach(_maps, map =>
            {
                if (map != null)
                {
                    map.Load();
                }
            });

            // Add some event hooks
            BanningManager.Instance.AccountBanned -= BanningManager_AccountBanned;
            BanningManager.Instance.AccountBanned += BanningManager_AccountBanned;
        }