Пример #1
0
        /// <summary>
        ///     Starts this instance.
        /// </summary>
        /// <returns>The task.</returns>
        public virtual async Task Start()
        {
            Logger.LogStart(">> Loading vocations");
            VocationXmlReader       vocationXmlReader = new VocationXmlReader();
            IEnumerable <IVocation> vocations         = await vocationXmlReader.LoadAsync(Settings.Default.Vocations_Xml);

            _vocationService = new VocationService(vocations);
            Logger.LogDone();

            Logger.LogStart(">> Loading items");
            ItemReader          itemReader = new ItemReader();
            IEnumerable <IItem> items      = await itemReader.LoadAsync(Settings.Default.Items_Otb);

            _itemService = new ItemService(items);
            ItemXmlReader itemXmlReader = new ItemXmlReader(_itemService);
            await itemXmlReader.LoadAsync(Settings.Default.Items_Xml);

            Logger.LogDone();

            Logger.LogStart(">> Loading spells");
            SpellXmlReader       spellXmlReader = new SpellXmlReader();
            IEnumerable <ISpell> spells         = await spellXmlReader.LoadAsync(Settings.Default.Spells_Xml);

            _spellService = new SpellService(spells);
            Logger.LogDone();

            Logger.LogStart(">> Loading monsters");
            MonsterXmlReader       monsterXmlReader = new MonsterXmlReader(_spellService);
            IEnumerable <IMonster> monsters         = await monsterXmlReader.LoadAsync(Settings.Default.Monsters_Xml);

            _monsterService = new MonsterService(monsters);
            Logger.LogDone();

            Logger.LogStart(">> Loading npcs");
            NpcXmlReader       npcXmlReader = new NpcXmlReader();
            IEnumerable <INpc> npcs         = await npcXmlReader.LoadAsync(Settings.Default.Npcs_Xml);

            _npcService = new NpcService(npcs);
            Logger.LogDone();

            Logger.LogStart(">> Loading map");
            MapReader mapReader = new MapReader(_itemService);
            WorldMap  map       = await mapReader.LoadAsync(Settings.Default.Map_Otb);

            Logger.LogDone();

            Logger.LogStart(">> Loading outfits");
            DrkOutfitReader       outfitReader = new DrkOutfitReader();
            IEnumerable <IOutfit> outfits      = await outfitReader.LoadAsync(Settings.Default.Outfits_Xml);

            _outfitService = new OutfitService(outfits);
            Logger.LogDone();

            Logger.LogStart(">> Loading mounts");
            DrkMountReader       mountReader = new DrkMountReader();
            IEnumerable <IMount> mounts      = await mountReader.LoadAsync(Settings.Default.Mounts_Xml);

            _mountService = new MountService(mounts);
            Logger.LogDone();

            Logger.LogStart(">> Loading channels");
            // TODO: Channels are broken. They should be handled by a category like ChannelType (e.g.: Public, Private, Guild, Party, etc.), then each category has an ID
            // TODO: Eventually loading channels this away should be replaced.
            // TODO Alternatively, we could move the specific implementation of LocalChannel to a scripting language (like Lua)
            // TODO: This could be also converted into a more modular approach (like a CS-Script)
            IDictionary <ChannelType, IChannel> channels = new Dictionary <ChannelType, IChannel>();

            channels.Add(ChannelType.Local, new LocalChannel());
            channels.Add(ChannelType.Loot, new LootChannel());
            channels.Add(ChannelType.Advertising, new AdvertisingChannel());
            channels.Add(ChannelType.AdvertisingRookgaard, new AdvertisingRookgaardChannel());
            channels.Add(ChannelType.English, new EnglishChannel());
            channels.Add(ChannelType.Help, new HelpChannel());
            channels.Add(ChannelType.World, new WorldChannel());
            Logger.LogDone();

            Logger.LogStart(">> Initializing town services");
            _townService = new TownService(map.Towns.Values);
            Logger.LogDone();

            Logger.LogStart(">> Initializing tile services");
            _tileService = new TileService(map.Tiles.Values);
            Logger.LogDone();

            // TODO: Remove this after project is complete
            InitializeTest();

            Logger.LogStart(">> Initializing repositories");
            _accountsRepository = new Repository <IAccount, uint>();

            // TODO: Remove this when repositories are implemented
            _accountsRepository.Create(_characterSpawn.Account);
            Logger.LogDone();

            Logger.LogStart(">> Initializing spawn services");
            SpawnXmlReader            spawnXmlReader = new SpawnXmlReader(_monsterService, _npcService);
            ICollection <SpawnSource> spawnSources   = (await spawnXmlReader.LoadAsync(Settings.Default.Spawns_Xml)).ToList();

            _creatureSpawnService = new CreatureSpawnService(spawnSources);
            RegisterSpawns(spawnSources);
            // TODO: Remove this when player repositories are implemented;
            _creatureSpawnService.RegisterCreature(_characterSpawn);
            Logger.LogDone();

            Logger.LogStart(">> Initializing communication services");
            _chatService    = new ChatService(_accountsRepository.GetAll(), channels);
            _commandService = new CommandService();
            _commandService.Register(new TeleportCommand(_townService, _creatureSpawnService));
            _commandService.Register(new TownListCommand(_townService));
            _commandService.Register(new PositionInfoCommand());
            _commandService.Register(new ChangeSexCommand());
            _commandService.Register(new BroadcastCommand(_creatureSpawnService));
            Logger.LogDone();

            Logger.LogStart(">> Initializing game server");
            _gameConnections = new List <GameConnection>();
            _gameListener    = new TcpListener(IPAddress.Any, Settings.Default.Network_Port_GameServer);
            _gameListener.Start();
            _gameListener.BeginAcceptSocket(OnGameMessageReceived, _gameListener);
            Logger.LogDone();

            Logger.LogStart(">> Initializing login server");
            _loginConnections = new List <LoginConnection>();
            _loginListener    = new TcpListener(IPAddress.Any, Settings.Default.Network_Port_LoginServer);
            _loginListener.Start();
            _loginListener.BeginAcceptSocket(OnLoginMessageReceived, _loginListener);
            Logger.LogDone();

            _onlineTimer = new Stopwatch();
        }