Ejemplo n.º 1
0
        /// <summary>
        /// Loads the data from file.
        /// </summary>
        /// <param name="contentPath">The content path to load the data from.</param>
        void Load(ContentPaths contentPath)
        {
            _npcChatDialogs.Clear();

            var filePath = GetFilePath(contentPath);

            if (!File.Exists(filePath))
            {
                _npcChatDialogs.Trim();
                return;
            }

            var reader = GenericValueReader.CreateFromFile(filePath, _rootNodeName);
            var items  = reader.ReadManyNodes(_chatDialogsNodeName, CreateDialog);

            for (var i = 0; i < items.Length; i++)
            {
                if (items[i] != null)
                {
                    _npcChatDialogs[i] = items[i];
                }
            }

            _npcChatDialogs.Trim();
        }
Ejemplo n.º 2
0
        static void TrimTestSub(bool trackFree)
        {
            const int size = 1000;

            var objs = new object[size];

            for (var i = 0; i < size / 2; i++)
            {
                if ((i % 3) == 0)
                {
                    objs[i] = i.ToString();
                }
            }

            var d = new DArray <object>(size, trackFree);

            for (var i = 0; i < size; i++)
            {
                if (objs[i] != null)
                {
                    d[i] = objs[i];
                }
            }

            d.Trim();

            // Make sure our data has not changed
            for (var i = 0; i < size; i++)
            {
                if (objs[i] != null)
                {
                    Assert.AreSame(objs[i], d[i], "TrackFree = " + trackFree);
                }
            }

            // Make sure the null slots are still null
            for (var i = 0; i < d.Length; i++)
            {
                Assert.AreSame(objs[i], d[i], "TrackFree = " + trackFree);
            }

            // Make sure that inserts first fill up the gaps, THEN expand
            var startLen = d.Length;
            var gaps     = startLen - d.Count;

            for (var i = 0; i < gaps; i++)
            {
                d.Insert(new object());
            }

            Assert.AreEqual(startLen, d.Length, "TrackFree = " + trackFree);

            // Make sure we start expanding now
            for (var i = 0; i < 10; i++)
            {
                var before = d.Length;
                d.Insert(new object());
                Assert.AreEqual(before + 1, d.Length, "TrackFree = " + trackFree);
            }
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
0
        public static void Load(ContentPaths contentPath, IContentManager cm)
        {
            if (IsLoaded)
            {
                return;
            }

            _isLoaded = true;

            var path = GetGrhDataFilePath(contentPath);

            if (cm == null)
            {
                throw new ArgumentNullException("cm");
            }

            if (!File.Exists(path))
            {
                throw new FileNotFoundException("GrhData data file not found.", path);
            }

            _isLoading = true;

            try
            {
                // Create the GrhData DArray
                if (_grhDatas == null)
                {
                    _grhDatas = new DArray <GrhData>(256);
                }
                else
                {
                    _grhDatas.Clear();
                }

                _catDic.Clear();

                _grhDatas.ItemAdded -= AddHandler;
                _grhDatas.ItemAdded += AddHandler;

                _grhDatas.ItemRemoved -= RemoveHandler;
                _grhDatas.ItemRemoved += RemoveHandler;

                // Read and add the GrhDatas in order by their type
                var reader = GenericValueReader.CreateFromFile(path, _rootNodeName);

                LoadGrhDatas(reader, _nonAnimatedGrhDatasNodeName, x => StationaryGrhData.Read(x, cm));
                LoadGrhDatas(reader, _animatedGrhDatasNodeName, AnimatedGrhData.Read);
                LoadGrhDatas(reader, _autoAnimatedGrhDatasNodeName, x => AutomaticAnimatedGrhData.Read(x, cm));

                // Trim down the GrhData array, mainly for the client since it will never add/remove any GrhDatas
                // while in the Client, and the Client is what counts, baby!
                _grhDatas.Trim();
            }
            finally
            {
                _isLoading = false;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Loads all of the items.
        /// </summary>
        void LoadAll()
        {
            var ids = GetIDs();

            foreach (var id in ids)
            {
                var item = LoadItem(id);
                var i    = IDToInt(id);
                _items.Insert(i, item);

                if (log.IsDebugEnabled)
                {
                    log.DebugFormat("Loaded item `{0}` at index `{1}`.", item, i);
                }
            }

            _items.Trim();
        }
Ejemplo n.º 6
0
        static void TrimTestSub(bool trackFree)
        {
            const int size = 1000;

            var objs = new object[size];
            for (var i = 0; i < size / 2; i++)
            {
                if ((i % 3) == 0)
                    objs[i] = i.ToString();
            }

            var d = new DArray<object>(size, trackFree);
            for (var i = 0; i < size; i++)
            {
                if (objs[i] != null)
                    d[i] = objs[i];
            }

            d.Trim();

            // Make sure our data has not changed
            for (var i = 0; i < size; i++)
            {
                if (objs[i] != null)
                    Assert.AreSame(objs[i], d[i], "TrackFree = " + trackFree);
            }

            // Make sure the null slots are still null
            for (var i = 0; i < d.Length; i++)
            {
                Assert.AreSame(objs[i], d[i], "TrackFree = " + trackFree);
            }

            // Make sure that inserts first fill up the gaps, THEN expand
            var startLen = d.Length;
            var gaps = startLen - d.Count;
            for (var i = 0; i < gaps; i++)
            {
                d.Insert(new object());
            }

            Assert.AreEqual(startLen, d.Length, "TrackFree = " + trackFree);

            // Make sure we start expanding now
            for (var i = 0; i < 10; i++)
            {
                var before = d.Length;
                d.Insert(new object());
                Assert.AreEqual(before + 1, d.Length, "TrackFree = " + trackFree);
            }
        }