Ejemplo n.º 1
0
        public async Task OnGameStart()
        {
            //When we start the loading screen for the game
            //To know what world we should load we should
            //To know that we need information about the character session.
            CharacterSessionEnterResponse characterSessionData = await CharacterService.TryEnterSession(LocalCharacterData.CharacterId)
                                                                 .ConfigureAwaitFalse();

            if (!characterSessionData.isSuccessful)
            {
                if (Logger.IsErrorEnabled)
                {
                    Logger.Error($"Failed to query Character Session Data: {characterSessionData.ResultCode}:{(int)characterSessionData.ResultCode}");
                }

                //If we already have a claim we should repeat.
                if (characterSessionData.ResultCode == CharacterSessionEnterResponseCode.AccountAlreadyHasCharacterSession)
                {
                    //Retry 5 times while not successful.
                    for (int i = 0; i < 5 && !characterSessionData.isSuccessful; i++)
                    {
                        characterSessionData = await CharacterService.TryEnterSession(LocalCharacterData.CharacterId)
                                               .ConfigureAwaitFalse();

                        await Task.Delay(1500)
                        .ConfigureAwaitFalseVoid();
                    }

                    //If not succesful after the retry.
                    if (!characterSessionData.isSuccessful)
                    {
                        await LoadCharacterSelection();

                        return;
                    }
                }
                else
                {
                    await LoadCharacterSelection();
                }
            }

            if (Logger.IsInfoEnabled)
            {
                Logger.Info($"About to broadcasting {nameof(OnCharacterSessionDataChanged)} with Zone: {characterSessionData.ZoneId}");
            }

            OnCharacterSessionDataChanged?.Invoke(this, new CharacterSessionDataChangedEventArgs(characterSessionData.ZoneId));
        }
Ejemplo n.º 2
0
 public CommandHandler(
     DiscordSocketClient client,
     CommandService commands,
     ExperienceService expService,
     CharacterService charService,
     IServiceProvider services,
     IConfiguration config)
 {
     _client      = client;
     _commands    = commands;
     _expService  = expService;
     _charService = charService;
     _services    = services;
     _config      = config;
 }
Ejemplo n.º 3
0
        public IHttpActionResult Delete(int id)
        {
            if (User.IsInRole("SuperAdmin"))
            {
                var service = new CharacterService(Guid.Parse(User.Identity.GetUserId()));

                if (!service.DeleteCharacter(id))
                {
                    return(InternalServerError());
                }

                return(Ok());
            }
            return(BadRequest());
        }
        private async void TopCountChangedAsync()
        {
            Mouse.OverrideCursor = Cursors.Wait;
            Task <Character[]> task = CharacterService.GetTopXXCharacterAsync(CountValue);

            Character[] characters = await task;
            if (task.IsCompleted)
            {
                if (characters != null)
                {
                    Mouse.OverrideCursor = Cursors.Arrow;
                    ListCharacters       = characters;
                }
            }
        }
Ejemplo n.º 5
0
        public async Task RegisterCharacter_Should_Create_New_Dungeon_Character_Entity_In_Database()
        {
            using var context = await GetDatabase();

            var mapper           = this.GetMapper();
            var characterService = new CharacterService(context, mapper);
            var dungeonService   = new DungeonService(context, characterService, mapper);

            await dungeonService.RegisterCharacterAsync("1", "1");

            var expected = 1;
            var actual   = context.DungeonCharacter.Count();

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CharacterCommands"/> class.
 /// </summary>
 /// <param name="database">A database context from the context pool.</param>
 /// <param name="contentService">The content service.</param>
 /// <param name="discordService">The Discord integration service.</param>
 /// <param name="feedbackService">The feedback service.</param>
 /// <param name="characterService">The character service.</param>
 public CharacterCommands
 (
     GlobalInfoContext database,
     ContentService contentService,
     DiscordService discordService,
     UserFeedbackService feedbackService,
     CharacterService characterService
 )
 {
     this.Database   = database;
     this.Content    = contentService;
     this.Discord    = discordService;
     this.Feedback   = feedbackService;
     this.Characters = characterService;
 }
        public async void Task_GetStoriesById_Return_NotFoundResult()
        {
            //Arrange
            var dbContext = DataContextMocker.GetDataContext(nameof(Task_GetStoriesById_Return_NotFoundResult));
            CharacterService characterService = new CharacterService(dbContext);
            var controller = new CharacterController(characterService);

            var characterId = 2;

            //Act
            var data = await controller.GetStoriesById(characterId);

            //Assert
            Assert.IsType <NotFoundObjectResult>(data);
        }
Ejemplo n.º 8
0
        public async Task CreateAsync_ShouldReturnResponseNewValidCharacter()
        {
            _houseService.Setup(x => x.GetHouseAsync(It.IsAny <string>())).ReturnsAsync(Response <HouseModel> .Create(HouseFake()));
            _characterFactory.Setup(x => x.CreateAsync(It.IsAny <CreateCharacterDto>(), It.IsAny <HouseModel>()))
            .ReturnsAsync(Response <CharacterModel> .Create(CharacterFake()));

            var response = await CharacterService.CreateAsync(CreateCharacterDtoFake());

            response.Should().NotBeNull();
            response.HasError.Should().BeFalse();
            response.Messages.Should().BeEmpty();
            response.Data.HasValue.Should().BeTrue();
            response.Data.Value.Should().BeOfType(typeof(CharacterModel));
            response.Data.Value.Name.Should().Be(CharacterFake().Name);
        }
        public async void Task_GetCharacterById_Return_BadRequestResult()
        {
            //Arrange
            var dbContext = DataContextMocker.GetDataContext(nameof(Task_GetCharacterById_Return_BadRequestResult));
            CharacterService characterService = new CharacterService(dbContext);
            var controller = new CharacterController(characterService);

            int?characterId = null;

            //Act
            var data = await controller.GetCharacterById(characterId);

            //Assert
            Assert.IsType <BadRequestObjectResult>(data);
        }
        private async void GetSearchResultsAsync()
        {
            Mouse.OverrideCursor = Cursors.Wait;
            Task <Character[]> task = CharacterService.GetCharactersContainingStringAsync(SearchedText);

            Character[] characters = await task;
            if (task.IsCompleted)
            {
                if (characters != null)
                {
                    Mouse.OverrideCursor = Cursors.Arrow;
                    ResultCharacters     = characters;
                }
            }
        }
        public async void Task_GetEventsIdById_Return_OkResult()
        {
            //Arrange
            var dbContext = DataContextMocker.GetDataContext(nameof(Task_GetEventsIdById_Return_OkResult));
            CharacterService characterService = new CharacterService(dbContext);
            var controller = new CharacterController(characterService);

            var characterId = 1011334;

            //Act
            var data = await controller.GetEventsById(characterId);

            //Assert
            Assert.IsType <OkObjectResult>(data);
        }
        public async Task RegisterCharacterAsync_Should_Register_Character_To_Given_Raid()
        {
            var context = await this.GetDatabase();

            var mapper           = this.GetMapper();
            var characterService = new CharacterService(context, mapper);
            var raidService      = new RaidService(context, characterService, mapper);

            await raidService.RegisterCharacterAsync("1", "1");

            var expected = 1;
            var actual   = context.Raids.First(r => r.Id == "1").RegisteredCharacters.Count();

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 13
0
        public ActionResult ActiveToggle(Guid Id)
        {
            CharacterService cs = new CharacterService(FILENAME, User.Identity.Name);

            try
            {
                Character c = cs.GetCharacter(Id);
                cs.EditCharacter(c.Id, c.Name, c.Faction.ToString(), c.Race.ToString(), c.Class.ToString(), c.Level, !c.Active);
            }
            catch (Exception e)
            {
            }

            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 14
0
        public async Task DeleteAsyncWhenIdNotExists()
        {
            var id = Guid.NewGuid();

            var characterRepository = Substitute.For <ICharacterRepository>();

            characterRepository.GetAsync(id).Returns((Character)null);

            var characterService = new CharacterService(characterRepository);
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await characterService.DeleteAsync(id);
            });

            await characterRepository.Received().GetAsync(id);
        }
        public static CharacterManager Create()
        {
            IUserIO io = new UserIO();

            ICharacterRepository repo;
            IItemRepository itemRepo;
            ICharacterService service;

            repo = GetNewCharacterRepository();
            itemRepo = GetNewItemRepository();
            service = new CharacterService(repo, itemRepo);

            CharacterManager manager = new CharacterManager(io, service);

            return manager;
        }
        public async Task AddProgressToRaid_Should_Not_Increase_When_Killed_Bosses_Equal_TotalBosses()
        {
            using var context = await this.GetDatabase();

            var mapper           = this.GetMapper();
            var characterService = new CharacterService(context, mapper);
            var raidService      = new RaidService(context, characterService, mapper);
            var guildService     = new GuildService(null, context, raidService, characterService, mapper);

            await guildService.AddProgressToRaidAsync("TestRaid2");

            var expected = 10;
            var actual   = context.RaidDestinations.First(ch => ch.Id == "2").KilledBosses;

            Assert.Equal(expected, actual);
        }
        public async Task DemoteRank_Should_Decrease_Rank_Correctly()
        {
            using var context = await this.GetDatabase();

            var mapper           = this.GetMapper();
            var characterService = new CharacterService(context, mapper);
            var raidService      = new RaidService(context, characterService, mapper);
            var guildService     = new GuildService(null, context, raidService, characterService, mapper);

            await guildService.DemoteRankAsync("2");

            var expected = "1";
            var actual   = context.Characters.First(ch => ch.Id == "2").RankId;

            Assert.Equal(expected, actual);
        }
        public ActionResult Create(CharacterCreate character)
        {
            if (!ModelState.IsValid)
            {
                return(View(character));
            }

            var characterId = Guid.Parse(User.Identity.GetUserId());
            var service     = new CharacterService(characterId);

            service.CreateCharacter(character);

            var modCalc = new CharacterService(character);

            modCalc.CalculateModifiers(character);
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 19
0
        public IHttpActionResult GetAll()
        {
            CharacterService service;

            try
            {
                service = new CharacterService(Guid.Parse(User.Identity.GetUserId()));
            }
            catch
            {
                Guid fakeId = new Guid();
                service = new CharacterService(fakeId);
            }
            var characters = service.GetCharacters();

            return(Ok(characters));
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TransformationCommands"/> class.
 /// </summary>
 /// <param name="feedback">The feedback service.</param>
 /// <param name="characters">The character service.</param>
 /// <param name="transformation">The transformation service.</param>
 /// <param name="interactivity">The interactivity service.</param>
 /// <param name="users">The user service.</param>
 /// <param name="content">The content service.</param>
 public TransformationCommands
 (
     [NotNull] UserFeedbackService feedback,
     [NotNull] CharacterService characters,
     [NotNull] TransformationService transformation,
     [NotNull] InteractivityService interactivity,
     [NotNull] UserService users,
     [NotNull] ContentService content
 )
 {
     _feedback       = feedback;
     _characters     = characters;
     _transformation = transformation;
     _interactivity  = interactivity;
     _users          = users;
     _content        = content;
 }
        public async Task CreateAsync_Should_Throw_If_Not_Valid_InputData(string destination, string leaderId)
        {
            var context = await this.GetDatabase();

            var mapper           = this.GetMapper();
            var characterService = new CharacterService(context, mapper);
            var raidService      = new RaidService(context, characterService, mapper);

            var raidCreateBindingModel = new RaidCreateBindingModel
            {
                DateTime    = DateTime.Now,
                Destination = destination,
                LeaderId    = leaderId
            };

            await Assert.ThrowsAsync <ArgumentException>(async() => await raidService.CreateAsync(raidCreateBindingModel));
        }
        public async Task KickCharacterAsync_Should_Remove_Character_From_Raid()
        {
            var context = await this.GetDatabase();

            var mapper           = this.GetMapper();
            var characterService = new CharacterService(context, mapper);
            var raidService      = new RaidService(context, characterService, mapper);

            await raidService.RegisterCharacterAsync("1", "1");

            await raidService.KickPlayerAsync("1", "1");

            var expected = 0;
            var actual   = context.RaidCharacter.Count();

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 23
0
        public ActionResult Create(CharacterAddModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    CharacterService cs = new CharacterService(FILENAME, User.Identity.Name);
                    cs.AddCharacter(model.Name, model.Faction, model.Race, model.Class);
                    return(RedirectToAction("Index", "Home"));
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", e.Message);
                }
            }

            return(View(model));
        }
Ejemplo n.º 24
0
        public async Task <Response <CharacterResponseMessage> > UpdateAsync(Guid code, CharacterRequestMessage requestMessage)
        {
            var response = Response <CharacterResponseMessage> .Create();

            if (requestMessage == null)
            {
                return(response.WithBusinessError("Invalid data for update character"));
            }

            var updateResponse = await CharacterService.UpdateAsync(requestMessage.ToUpdateCharacterDto(code));

            if (updateResponse.HasError)
            {
                return(response.WithMessages(updateResponse.Messages));
            }

            return(response.SetValue(updateResponse.Data.Value.ToCharacterResponseMessage()));
        }
Ejemplo n.º 25
0
        public CharacterServiceTests(DatabaseFixture fixture)
        {
            var configuration = new MapperConfiguration(cfg =>
                                                        cfg.AddMaps(new[] {
                "UselessCore",
            })
                                                        );

            mapper = new Mapper(configuration);

            var mockMemoryCache = new Mock <IMemoryCache>();

            this.fixture = fixture;
            mockSectionBuilderFactory = new Mock <ISectionBuilderFactory>();
            mockSectionBuilderFactory.Setup(msbf => msbf.GetSectionBuilder(It.IsAny <Character>(), It.IsAny <List <BaseCharacterDto> >(), It.IsAny <string>())).Returns(new SectionBuilderStub());

            service = new CharacterService(fixture.Context, mockMemoryCache.Object, mapper, mockSectionBuilderFactory.Object);
        }
Ejemplo n.º 26
0
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            var houseUrl         = (string)parameter;
            var service          = new HouseService();
            var characterService = new CharacterService();

            House = await service.GetHouseAsync(houseUrl);

            foreach (var item in house.swornMembers)
            {
                var character = await characterService.GetCharacterAsync(item);

                SwornMembers.Add(character);
            }


            await base.OnNavigatedToAsync(parameter, mode, state);
        }
        public void Task_GetCharacter_Return_BadRequestResult()
        {
            //Arrange
            var dbContext = DataContextMocker.GetDataContext(nameof(Task_GetCharacter_Return_BadRequestResult));
            CharacterService characterService = new CharacterService(dbContext);
            var controller = new CharacterController(characterService);

            //Act
            var data = controller.Get();

            data = null;

            //Assert
            if (data != null)
            {
                Assert.IsType <BadRequestObjectResult>(data);
            }
        }
Ejemplo n.º 28
0
        public RollModule(
            CharacterService characterService,
            EffectsService effectsService,
            HelpService helpService,
            NpcService npcService,
            RollService rollService,
            SpecialService specialService,
            Random random)
        {
            _charService    = characterService;
            _effectsService = effectsService;
            _helpService    = helpService;
            _npcService     = npcService;
            _rollService    = rollService;
            _specialService = specialService;

            _random = random;
        }
Ejemplo n.º 29
0
    void IDialogController.DisplayService(CharacterService service)
    {
        // Check if the service can be refused
        if (service.IsRefusable)
        {
            var dialog = DialogRecord.GetPersuasionDialog(player, Npc, PersuasionResult.ServiceRefusal);
            var info   = dialog.GetInfo(player, Npc, isServiceRefusal: true);

            // If a response was found, the service has been refused by the npc
            if (info != null)
            {
                DisplayInfo(dialog, info);
                return;
            }
        }

        service.DisplayService(this, player, Npc);
    }
        public void Validate_WhenOnlyOneCharacterExistsInTheList_ReturnsEmptyString()
        {
            // Arrange
            var characterService = new CharacterService();
            var characters       = new List <Character>
            {
                new Farmer
                {
                    Location = Location.LeftBank
                }
            };

            // Act
            var result = characterService.Validate(characters);

            // Assert
            Assert.Equal(string.Empty, result);
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="contextManager"></param>
 public OrganizationMembershipController(IContextManager contextManager)
 {
     _fullService = new CharacterService(contextManager);
 }
Ejemplo n.º 32
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="contextManager"></param>
 public CharacterController(IContextManager contextManager)
 {
     _fullService = new CharacterService(contextManager);
 }