Ejemplo n.º 1
0
        void StartProgram()
        {
            service = new SpellService();
            Console.WriteLine("Введите текст для проверки орфографии:");
            string text = Console.ReadLine();

            Console.WriteLine();

            var spErrors = service.checkText(text, "ru, en", 0, "plain");

            if (spErrors.Length == 0)
            {
                Console.WriteLine("Ошибки не найдены");
            }
            else
            {
                foreach (SpellError er in spErrors)
                {
                    Console.WriteLine($"Ошибка в слове: {er.word}");
                    Console.WriteLine($"Позиция: {er.pos + 1}");
                    if (er.s != null)
                    {
                        Console.WriteLine("Возможные варианты: ");
                        foreach (string str in er.s)
                        {
                            Console.WriteLine(str);
                        }
                    }
                    Console.WriteLine();
                }
            }
            Console.ReadKey();
        }
        public ISpellStatBlock FindById(int Id)
        {
            SpellService spellService = new SpellService(ConnectionString);
            spell        tempSpell    = spellService.FindBy(Id);

            return(MapThisToSpellStatBlockObject(tempSpell));
        }
        public ISpellStatBlock GetSpellByName(string name)
        {
            SpellService spellService = new SpellService(ConnectionString);
            spell        tempSpell    = spellService.GetSpellByName(name);

            return(MapThisToSpellStatBlockObject(tempSpell));
        }
        public ActionResult Delete(int id)
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new SpellService(userId);

            service.Delete(id);
            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(int?id)
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new SpellService(userId);
            var model   = service.Edit((int)id);

            return(View(model));
        }
        // GET: Spell
        public ActionResult Index()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new SpellService(userId);
            var model   = service.GetSpells();

            return(View(model));
        }
Ejemplo n.º 7
0
        [TestCase("uber", false, "uber")] //we have documents about Uber the company, should not treat the name as typo
        public void Process(string input, bool expectedToCorrect, string expectedOutput)
        {
            var service       = new SpellService();
            var words         = input.Split(' ');
            var expectedWords = expectedOutput.Split(' ');

            bool corrected;
            var  correctedWords = service.CorrectSpelling(words, out corrected);

            Assert.That(corrected, Is.EqualTo(expectedToCorrect));
            Assert.That(correctedWords, Is.EquivalentTo(expectedWords));
        }
        public ActionResult Create(SpellCreate spell)
        {
            if (!ModelState.IsValid)
            {
                return(View(spell));
            }

            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new SpellService(userId);

            service.CreateSpell(spell);
            return(RedirectToAction("Index"));
        }
        public async Task ThrowArgumentException_WhenPassedInvalidId(string invalidId)
        {
            // Arrange
            Mock <IPandaScoreClient> pandaScoreClientMock = new Mock <IPandaScoreClient>();
            Mock <DataContext>       dataContextMock      = new Mock <DataContext>();

            // Act
            SpellService SUT = new SpellService(
                pandaScoreClientMock.Object,
                dataContextMock.Object);

            // Assert
            await Assert.ThrowsExceptionAsync <ArgumentException>(async() =>
                                                                  await SUT.FindAsync(invalidId));
        }
        public async Task ThrowArgumentNullException_WhenPassedNullAccessToken()
        {
            // Arrange
            Mock <IPandaScoreClient> pandaScoreClientMock = new Mock <IPandaScoreClient>();
            Mock <DataContext>       dataContextMock      = new Mock <DataContext>();

            // Act
            SpellService SUT = new SpellService(
                pandaScoreClientMock.Object,
                dataContextMock.Object);

            // Assert
            await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() =>
                                                                      await SUT.RebaseSpellsAsync(null));
        }
        public async Task FilterSpellsAsync_ShouldReturnSpells_WhenPassedValidParameters()
        {
            // Arrange
            var contextOptions = new DbContextOptionsBuilder <DataContext>()
                                 .UseInMemoryDatabase(databaseName: "FilterSpellsAsync_ShouldReturnSpells_WhenPassedValidParameters")
                                 .Options;

            string validSortOrder  = "name_asc";
            string validFilter     = "testSpell";
            int    validPageSize   = 10;
            int    validPageNumber = 1;

            string validName = "testSpell";

            Spell validSpell = new Spell
            {
                Id   = Guid.NewGuid(),
                Name = validName
            };

            IEnumerable <Spell> result = new List <Spell>();

            // Act
            using (DataContext actContext = new DataContext(contextOptions))
            {
                Mock <IPandaScoreClient> pandaScoreClientMock = new Mock <IPandaScoreClient>();

                await actContext.Spells.AddAsync(validSpell);

                await actContext.SaveChangesAsync();

                SpellService SUT = new SpellService(
                    pandaScoreClientMock.Object,
                    actContext);

                result = await SUT.FilterSpellsAsync(validSortOrder, validFilter, validPageNumber, validPageSize);
            }

            // Assert
            using (DataContext assertContext = new DataContext(contextOptions))
            {
                var spell = result.ToArray()[0];

                Assert.IsTrue(assertContext.Spells.Count().Equals(result.Count()));
                Assert.IsTrue(assertContext.Spells.Any(s => s.Name.Equals(spell.Name)));
            }
        }
        public async Task RebaseSpellsAsync_ShouldRepopulateSpellTable_WhenPassedValidParameters()
        {
            // Arrange
            var contextOptions = new DbContextOptionsBuilder <DataContext>()
                                 .UseInMemoryDatabase(databaseName: "RebaseSpellsAsync_ShouldRepopulateSpellTable_WhenPassedValidParameters")
                                 .Options;

            string validAccessToken    = string.Empty;
            string validCollectionName = "spells";
            int    validPageSize       = 100;

            Spell validSpell = new Spell
            {
                Id        = Guid.NewGuid(),
                Name      = "testTeam",
                DeletedOn = DateTime.UtcNow.AddHours(2),
                IsDeleted = true
            };

            IEnumerable <Spell> validSpellList = new List <Spell>()
            {
                validSpell
            };

            // Act
            using (DataContext actContext = new DataContext(contextOptions))
            {
                Mock <IPandaScoreClient> pandaScoreClientMock = new Mock <IPandaScoreClient>();

                pandaScoreClientMock
                .Setup(mock => mock.GetEntitiesParallel <Spell>(validAccessToken, validCollectionName, validPageSize))
                .Returns(Task.FromResult(validSpellList));

                SpellService SUT = new SpellService(
                    pandaScoreClientMock.Object,
                    actContext);

                await SUT.RebaseSpellsAsync(validAccessToken);
            }

            // Assert
            using (DataContext assertContext = new DataContext(contextOptions))
            {
                Assert.IsTrue(assertContext.Spells.Count() == 1);
                Assert.IsTrue(assertContext.Spells.Contains(validSpell));
            }
        }
Ejemplo n.º 13
0
        public async Task ThrowArgumentOutOfRangeException_WhenPassedInvalidPageSize(int invalidPageSize)
        {
            // Arrange
            Mock <IPandaScoreClient> pandaScoreClientMock = new Mock <IPandaScoreClient>();
            Mock <DataContext>       dataContextMock      = new Mock <DataContext>();

            string validSortOrder  = string.Empty;
            string validFilter     = string.Empty;
            int    validPageNumber = 1;

            SpellService SUT = new SpellService(
                pandaScoreClientMock.Object,
                dataContextMock.Object);

            // Act & Assert
            await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(
                () => SUT.FilterSpellsAsync(validSortOrder, validFilter, validPageNumber, invalidPageSize));
        }
Ejemplo n.º 14
0
    // Should move this to another class
    private void AddServices(GameObject gameObject)
    {
        var services = aiData.GetServices();

        // Give all Npc's persuasion
        PersuasionService.Create(gameObject);

        foreach (var service in services)
        {
            switch (service)
            {
            case Service.Barter:
                BarterService.Create(gameObject);
                break;

            case Service.Enchanting:
                EnchantingService.Create(gameObject);
                break;

            case Service.Repair:
                RepairService.Create(gameObject);
                break;

            case Service.Spellmaking:
                SpellmakingService.Create(gameObject);
                break;

            case Service.Spells:
                SpellService.Create(gameObject);
                break;

            case Service.Training:
                TrainingService.Create(gameObject);
                break;
            }
        }

        if (destinationData != null && destinationData.Count > 0)
        {
            TravelService.Create(gameObject);
        }
    }
        public async Task FindAsync_ShouldReturnSpell_WhenPassedValidParameters()
        {
            // Arrange
            var contextOptions = new DbContextOptionsBuilder <DataContext>()
                                 .UseInMemoryDatabase(databaseName: "FindAsync_ShouldReturnSpell_WhenPassedValidParameters")
                                 .Options;

            Guid validId = Guid.NewGuid();

            Spell validSpell = new Spell
            {
                Id   = validId,
                Name = "testSpell"
            };

            Spell result = null;

            // Act
            using (DataContext actContext = new DataContext(contextOptions))
            {
                Mock <IPandaScoreClient> pandaScoreClientMock = new Mock <IPandaScoreClient>();

                await actContext.Spells.AddAsync(validSpell);

                await actContext.SaveChangesAsync();

                SpellService SUT = new SpellService(
                    pandaScoreClientMock.Object,
                    actContext);

                result = await SUT.FindAsync(validId.ToString());
            }

            // Assert
            using (DataContext assertContext = new DataContext(contextOptions))
            {
                Assert.IsTrue(assertContext.Spells.Any(c => c.Id.Equals(result.Id)));
                Assert.IsTrue(assertContext.Spells.Any(c => c.Name.Equals(result.Name)));
            }
        }
Ejemplo n.º 16
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();
        }
Ejemplo n.º 17
0
 public SpellControl()
 {
     InitializeComponent();
     _spellService = new SpellService();
 }
Ejemplo n.º 18
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="T:Tibia.Spawns.MonsterXmlReader" /> class.
 /// </summary>
 /// <param name="spellService">The spell service.</param>
 public MonsterXmlReader(SpellService spellService)
 {
     _spellService = spellService;
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Diese Methode wird aufgerufen, wenn der ReconnectDatabaseCommand gestartet wird
        /// </summary>
        private void RebuildWeaponDatabaseExecute()
        {
            var dbService = ServiceLocator.Current.GetInstance <IDatabaseService>();
            var conn      = dbService.GetDbConnection();

            //Spells
            var spells = GetSpellsContent(conn);

            SpellService.WriteSpells(spells);



            var query  = "SELECT * FROM item_template";
            var cmd    = new MySqlCommand(query, conn.Connection);
            var result = new List <Item>();

            using (var reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    var itemClass     = reader.GetInt32("class");
                    var itemSubClass  = reader.GetInt32("subclass");
                    var inventoryType = reader.GetInt32("InventoryType");
                    var quality       = reader.GetInt32("Quality");
                    if (itemClass != 2 && itemClass != 4)
                    {
                        continue;
                    }
                    if (itemClass == 2 && (itemSubClass != 2 && itemSubClass != 3 && itemSubClass != 4 && itemSubClass != 7 && itemSubClass != 13 && itemSubClass != 15 && itemSubClass != 18))
                    {
                        continue;
                    }
                    if (itemClass == 4 && (inventoryType == 0 || inventoryType == 4 || inventoryType == 14 || inventoryType == 17 || inventoryType == 18 || inventoryType == 19 || inventoryType == 20 || inventoryType >= 23))
                    {
                        continue;
                    }
                    if (quality != 3 && quality != 4 && quality != 5)
                    {
                        continue;
                    }
                    var item = new Item
                    {
                        ItemIdent    = reader.GetInt32("entry"),
                        DisplayIdent = reader.GetInt32("displayid"),
                        Name         = reader.GetString("Name"),
                        Speed        = reader.GetInt32("delay"),
                        Quality      = (ItemConstants.Quality)quality,
                        WeaponClass  = itemClass != 2 ? 0 : (ItemConstants.WeaponClass)itemSubClass,
                        Type         = itemClass != 2 ? (ItemConstants.ItemType)inventoryType : (inventoryType == 15 || inventoryType == 26 ? ItemConstants.ItemType.Ranged : (ItemConstants.ItemType)inventoryType)
                    };

                    //DMG
                    if (item.IsWeapon())
                    {
                        item.DmgMin = reader.GetInt32("dmg_min1");
                        item.DmgMax = reader.GetInt32("dmg_max1");
                    }

                    GetStats(item, reader);
                    result.Add(item);
                }
            }
            GetSpells(result, spells);
            var items = ItemService.WriteItems(result);


            XmlSerializer <List <Item> > .ExportToXml(result, "Items");

            ItemService.ResetCache();
            dbService.ConnectionChange?.Invoke();
        }
Ejemplo n.º 20
0
 public Public(SpellService service)
 {
     m_service = service;
 }
Ejemplo n.º 21
0
 public Admin(SpellService service)
 {
     m_service = service;
 }
Ejemplo n.º 22
0
        private SpellService GetSpellService()
        {
            var svc = new SpellService();

            return(svc);
        }