public FarmController(IHeroService heroService, IFarmService farmService, IChronometerService chronometerService, IStringLocalizer <FarmController> stringLocalizer)
 {
     this.heroService        = heroService;
     this.farmService        = farmService;
     this.chronometerService = chronometerService;
     this.stringLocalizer    = stringLocalizer;
 }
        private Task UpdatePowers(HeroesDbContext context, IHeroService heroService)
        {
            var powers = context.HeroPowers.Include(hp => hp.Power).Where(hp => hp.LastTrainingTime != null || hp.LastChangeTime != null).ToList();

            foreach (var heroPower in powers)
            {
                var timePassed  = DateTime.Now.Subtract(heroPower.LastChangeTime.GetValueOrDefault()).TotalHours;
                var timeChanged = Convert.ToInt32(Math.Floor(timePassed));

                if (timeChanged < Constants.HERO_POWER_MIN_CHANGE_TIME)
                {
                    continue;
                }

                var percentage  = Math.Pow(0.8, timeChanged);
                var newStrength = Convert.ToInt32(Convert.ToDouble(heroPower.Strength) * percentage);

                heroPower.Strength       = newStrength;
                heroPower.LastChangeTime = DateTime.Now;

                context.HeroPowers.Update(heroPower);
                context.SaveChanges();
                heroService.ChangeOverallStrength(heroPower.HeroId);
            }
            return(Task.CompletedTask);
        }
示例#3
0
        public HitMutation(IHitService hitService,
                           IJWTService jWTService,
                           IHeroService heroService,
                           IValidatorService validatorService)
        {
            Name = "Mutation";

            Field <StringGraphType>(
                "createHit",
                arguments: new QueryArguments
            {
                new QueryArgument <NonNullGraphType <StringGraphType> > {
                    Name = "token"
                },
                new QueryArgument <NonNullGraphType <IdGraphType> > {
                    Name = "dragonId"
                }
            },
                resolve: context =>
            {
                var token    = context.GetArgument <string>("token");
                var dragonId = context.GetArgument <int>("dragonId");
                validatorService.ValidateToken(token);

                var heroName = jWTService.GetHeroNameFromToken(token);
                var hero     = heroService.GetHeroByName(heroName);

                hitService.CreateHit(hero, dragonId);

                return(null);
            });
        }
示例#4
0
 public FightService(
     IHeroService heroService,
     IHealthService healthService,
     IResourcePouchService resourcePouchService,
     IChronometerService chronometerService,
     ILevelService levelService,
     IStatisticsService statisticsService,
     IMonsterService monsterService,
     INotificationService notificationService,
     IEquipmentService equipmentService,
     IAmuletBagService amuletBagService,
     FarmHeroesDbContext context,
     IMapper mapper)
 {
     this.heroService          = heroService;
     this.healthService        = healthService;
     this.resourcePouchService = resourcePouchService;
     this.chronometerService   = chronometerService;
     this.levelService         = levelService;
     this.statisticsService    = statisticsService;
     this.monsterService       = monsterService;
     this.notificationService  = notificationService;
     this.equipmentService     = equipmentService;
     this.amuletBagService     = amuletBagService;
     this.context = context;
     this.mapper  = mapper;
 }
示例#5
0
 public PremiumFeaturesService(
     FarmHeroesDbContext context,
     IHeroService heroService)
 {
     this.context     = context;
     this.heroService = heroService;
 }
        public void GetAllHeroes_WithCorrectData_ShouldReturnListWithAllHeroes()
        {
            string errorMessagePrefix = "HeroService GetAllUsers() method does not work properly.";

            var repo = new Mock <IRepository <Hero> >();

            repo.Setup(r => r.All()).Returns(GetTestData().AsQueryable());

            this._heroService = new HeroService(repo.Object, null, null, null);

            var expectedResults = GetTestData();
            var actualResults   = this._heroService.GetAllHeroes().ToList();

            Assert.True(expectedResults.Count == actualResults.Count(), errorMessagePrefix);

            for (int i = 0; i < expectedResults.Count; i++)
            {
                var expectedEntry = expectedResults[i];
                var actualEntry   = actualResults[i];

                Assert.True(expectedEntry.Name == actualEntry.Name, errorMessagePrefix + " " + "Email is not returned properly.");
                Assert.True(expectedEntry.RealName == actualEntry.RealName, errorMessagePrefix + " " + "RealName is not returned properly.");
                Assert.True(expectedEntry.Image == actualEntry.Image, errorMessagePrefix + " " + "Image is not returned properly.");
            }
        }
示例#7
0
        public StatisticsController(ITournamentService tournamentService, IHeroService heroService, IStatsHelper statsHelper)
        {
            _tournamentService = tournamentService;
            _heroService       = heroService;

            _statsHelper = statsHelper;
        }
        public static async Task <HttpResponseMessage> Run
        (
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "heroes")] CreateHeroCommand command,
            HttpRequestMessage request,
            [Inject] IHeroService heroService,
            ILogger logger
        )
        {
            try
            {
                Hero hero = await heroService.Create(command);

                return(request.CreateResponse(HttpStatusCode.Created, hero));
            }
            catch (Exception ex) when(ex is ArgumentNullException || ex is FailedValidationException)
            {
                return(request.CreateResponse(HttpStatusCode.BadRequest));
            }
            catch (DuplicateException)
            {
                return(request.CreateResponse(HttpStatusCode.Conflict));
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message);
                throw;
            }
        }
 public HeroController(IHeroService heroService, IUserService userService, UserManager <ApplicationUser> userManager, FarmHeroesDbContext context)
 {
     this.heroService = heroService;
     this.userService = userService;
     this.userManager = userManager;
     this.context     = context;
 }
示例#10
0
 public HealthService(IMapper mapper, IHeroService heroService, IResourcePouchService resourcePouchService, FarmHeroesDbContext context)
 {
     this.mapper               = mapper;
     this.heroService          = heroService;
     this.resourcePouchService = resourcePouchService;
     this.context              = context;
 }
示例#11
0
 public ExploreHub(IExploreService exploreService, IItemService itemService, IHeroService heroService, ITiledService tiledService, IHubContext <BaseHub> baseHub) : base(baseHub)
 {
     _exploreService = exploreService;
     _itemService    = itemService;
     _heroService    = heroService;
     _tiledService   = tiledService;
 }
        public static async Task <HttpResponseMessage> Run
        (
            [HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "heroes/{id}")] ChangeHeroNameCommand command,
            HttpRequestMessage request,
            string id,
            [Inject] IHeroService heroService,
            ILogger logger
        )
        {
            try
            {
                await heroService.ChangeName(id, command);

                return(request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception ex) when(ex is ArgumentNullException || ex is FailedValidationException || ex is InvalidOperationException)
            {
                return(request.CreateResponse(HttpStatusCode.BadRequest));
            }
            catch (NotFoundException)
            {
                return(request.CreateResponse(HttpStatusCode.NotFound));
            }
            catch (DuplicateException)
            {
                return(request.CreateResponse(HttpStatusCode.Conflict));
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message);
                throw;
            }
        }
        public void GetById_WithExistentId_ShouldReturnCorrectHeroDetail()
        {
            string errorMessagePrefix = "HeroService GetById() method does not work properly.";

            var repo     = new Mock <IRepository <Hero> >();
            var userRepo = new Mock <IRepository <ApplicationUser> >();

            repo.Setup(r => r.All()).Returns(this.GetTestData().AsQueryable);
            userRepo.Setup(x => x.All()).Returns(new List <ApplicationUser>()
            {
                new ApplicationUser()
                {
                    Id = "1"
                }
            }.AsQueryable);

            this._heroService = new HeroService(repo.Object, null, userRepo.Object, null);

            var expectedResults = this.GetTestData().FirstOrDefault(x => x.Id == 1);
            var actualResults   = this._heroService.GetById("1", 1);

            Assert.True(expectedResults.Name == actualResults.Name, errorMessagePrefix + " " + "Email is not returned properly.");
            Assert.True(expectedResults.RealName == actualResults.RealName, errorMessagePrefix + " " + "RealName is not returned properly.");
            Assert.True(expectedResults.Image == actualResults.Image, errorMessagePrefix + " " + "Image is not returned properly.");
            Assert.True(expectedResults.CoverImage == actualResults.CoverImage, errorMessagePrefix + " " + "CoverImage is not returned properly.");
            Assert.True(expectedResults.Gender == actualResults.Gender, errorMessagePrefix + " " + "Gender is not returned properly.");
            Assert.True(expectedResults.Description == actualResults.Description, errorMessagePrefix + " " + "Description is not returned properly.");
            Assert.True(expectedResults.Birthday.ToString(CultureInfo.CurrentCulture) == actualResults.Birthday, errorMessagePrefix + " " + "Birthday is not returned properly.");
            Assert.True(expectedResults.Movies.Count == actualResults.Movies.Count(), errorMessagePrefix + " " + "Movies count is not returned properly.");
            Assert.True(expectedResults.Comments.Count == actualResults.Comments.Count(), errorMessagePrefix + " " + "Comments count is not returned properly.");
            Assert.True(expectedResults.EditHistory.Count == actualResults.EditHistory.Count(), errorMessagePrefix + " " + "Comments count is not returned properly.");
        }
示例#14
0
 public ChronometerService(FarmHeroesDbContext context, IHeroService heroService, IMapper mapper, IAmuletBagService amuletBagService)
 {
     this.context          = context;
     this.heroService      = heroService;
     this.amuletBagService = amuletBagService;
     this.mapper           = mapper;
 }
 public HeroMediator(IHeroService heroService, IMediatorService mediatorService,
                     IHeroViewModelFactory heroViewModelFactory)
 {
     _heroService          = heroService;
     _mediatorService      = mediatorService;
     _heroViewModelFactory = heroViewModelFactory;
 }
        public static async Task <HttpResponseMessage> Run
        (
            [HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = "heroes/{id}")] HttpRequestMessage request,
            string id,
            [Inject] IHeroService heroService,
            ILogger logger
        )
        {
            try
            {
                await heroService.Delete(id);

                return(request.CreateResponse(HttpStatusCode.OK));
            }
            catch (ArgumentNullException)
            {
                return(request.CreateResponse(HttpStatusCode.BadRequest));
            }
            catch (NotFoundException)
            {
                return(request.CreateResponse(HttpStatusCode.NotFound));
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message);
                throw;
            }
        }
示例#17
0
 public BattleService(HeroesDbContext context, IRewardService hashingManager, IHeroService heroService, IVillainService villainService, IOptions <AppSettings> appSettings)
 {
     _context        = context;
     _rewardService  = hashingManager;
     _heroService    = heroService;
     _villainService = villainService;
     _appSettings    = appSettings.Value;
 }
示例#18
0
 public HeroGrain(
     ILogger <HeroGrain> logger,
     IHeroService service
     )
 {
     _logger  = logger;
     _service = service;
 }
 public EquipmentService(IHeroService heroService, FarmHeroesDbContext context, IHttpContextAccessor httpContext, ITempDataDictionaryFactory tempDataDictionaryFactory, IMapper mapper)
 {
     this.heroService = heroService;
     this.context     = context;
     this.httpContext = httpContext;
     this.tempDataDictionaryFactory = tempDataDictionaryFactory;
     this.mapper = mapper;
 }
示例#20
0
 public BattlefieldController(IHeroService heroService, IBattlefieldService battlefieldService, IFightService fightService, IChronometerService chronometerService, IStringLocalizer <BattlefieldController> stringLocalizer)
 {
     this.heroService        = heroService;
     this.battlefieldService = battlefieldService;
     this.fightService       = fightService;
     this.chronometerService = chronometerService;
     this.stringLocalizer    = stringLocalizer;
 }
 public GameContext(IHeroService heroService, IInputService inputService, ITimeService timeService, ISpaceService spaceService, IRandomService randomService)
 {
     HeroService   = heroService;
     InputService  = inputService;
     TimeService   = timeService;
     SpaceService  = spaceService;
     RandomService = randomService;
 }
示例#22
0
 public MineService(IHeroService heroService, IResourcePouchService resourcePouchService, IStatisticsService statisticsService, IChronometerService chronometerService, IAmuletBagService amuletBagService)
 {
     this.heroService          = heroService;
     this.resourcePouchService = resourcePouchService;
     this.statisticsService    = statisticsService;
     this.chronometerService   = chronometerService;
     this.amuletBagService     = amuletBagService;
 }
 public CharacteristicsService(FarmHeroesDbContext context, IMapper mapper, IHeroService heroService, IResourcePouchService resourcePouchService, IHealthService healthService)
 {
     this.context          = context;
     this.mapper           = mapper;
     this.heroService      = heroService;
     this.resourcesService = resourcePouchService;
     this.healthService    = healthService;
 }
示例#24
0
 public HeroController(
     IHeroService p_heroService,
     ITrainService p_trainService
     )
 {
     _heroService  = p_heroService;
     _trainService = p_trainService;
 }
 public WorkCompletionActionFilter(IHeroService heroService, IBattlefieldService battlefieldService, IFarmService farmService, IDungeonService dungeonService, IHarbourService harbourService)
 {
     this.heroService        = heroService;
     this.battlefieldService = battlefieldService;
     this.farmService        = farmService;
     this.dungeonService     = dungeonService;
     this.harbourService     = harbourService;
 }
示例#26
0
        public HeroControllersGenerator(IContext <D, V> context, IDispatcher dispatcher, IGameContext gameContext, IHeroService heroService)
            : base(dispatcher, gameContext)
        {
            this.context     = context;
            this.heroService = heroService;

            this.Start();
        }
 public InventoryService(IHeroService heroService, IResourcePouchService resourcePouchService, FarmHeroesDbContext context, IMapper mapper, IHttpContextAccessor httpContext, ITempDataDictionaryFactory tempDataDictionaryFactory)
 {
     this.heroService          = heroService;
     this.resourcePouchService = resourcePouchService;
     this.context     = context;
     this.mapper      = mapper;
     this.httpContext = httpContext;
     this.tempDataDictionaryFactory = tempDataDictionaryFactory;
 }
示例#28
0
 public MineController(IHeroService heroService, IMineService mineService, IChronometerService chronometerService, IMapper mapper, IStringLocalizer <MineController> stringLocalizer, IResourcePouchService resourcePouchService)
 {
     this.heroService          = heroService;
     this.mineService          = mineService;
     this.chronometerService   = chronometerService;
     this.mapper               = mapper;
     this.stringLocalizer      = stringLocalizer;
     this.resourcePouchService = resourcePouchService;
 }
 public AmuletBagService(IHeroService heroService, IEquipmentService equipmentService, IResourcePouchService resourcePouchService, FarmHeroesDbContext context, IMapper mapper, LocalizationService localizationService)
 {
     this.heroService          = heroService;
     this.equipmentService     = equipmentService;
     this.resourcePouchService = resourcePouchService;
     this.context             = context;
     this.mapper              = mapper;
     this.localizationService = localizationService;
 }
 public QuestService(IIdentity identity)
 {
     questDal    = new QuestDal();
     heroDal     = new HeroDal();
     myHero      = heroDal.GetByPlayer(int.Parse(identity.Name));
     itemDal     = new ItemDal();
     eqService   = new EquipmentService();
     heroService = new HeroService(identity);
 }