private void ConstructBattleService(IHeroRepository heroRepository, IBattleFactory battleFactory)
 {
     try
     {
         try
         {
             _battleService = Activator.CreateInstance(typeof(BattleService),
                                                       BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null,
                                                       new object[] { battleFactory, heroRepository },
                                                       null) as BattleService;
         }
         catch (Exception)
         {
             _battleService = Activator.CreateInstance(typeof(BattleService),
                                                       BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null,
                                                       new object[] { heroRepository, battleFactory },
                                                       null) as BattleService;
         }
     }
     catch (Exception)
     {
         _battleService = null;
     }
     Assert.That(_battleService, Is.Not.Null, "Failed to instantiate a BattleService.");
 }
Exemplo n.º 2
0
        private BattleService battleService;            //战斗服务

        public void Initialize()
        {
            //初始化所有服务类
            userService   = new UserService();
            actorService  = new ActorService();
            battleService = new BattleService();
        }
        public void GetFirstAttacker_FirstPokemonIsQuicker_FirstPokemonIsAttacker()
        {
            // ARRANGE
            var firstPokemon = new PokemonDTO()
            {
                Id        = Guid.Parse("8372c3f3-8281-4c21-8d0f-8830817bc2fb"),
                BaseStats = new BaseStat()
                {
                    Speed = 2
                }
            };

            var secondPokemon = new PokemonDTO()
            {
                Id        = Guid.Parse("23ed4579-a8a3-4258-ae11-b52f48ee563b"),
                BaseStats = new BaseStat()
                {
                    Speed = 1
                }
            };

            var logger = new NullLogger <BattleService>();

            var service = new BattleService(null, logger);

            // ACT
            var result = service.GetFirstAttacker(firstPokemon, secondPokemon);

            // ASSERT
            Assert.Equal(Guid.Parse("8372c3f3-8281-4c21-8d0f-8830817bc2fb"), result);
        }
Exemplo n.º 4
0
        // GET: Battle
        public ActionResult Index()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new BattleService(userId);
            var model   = service.GetBattles();

            return(View(model));
        }
Exemplo n.º 5
0
        public BattleApi()
        {
            IBattleService battleService = new BattleService(new ElementServiceBase());

            _battleController = new BattleController(battleService);
            IUserService userService = new UserService();

            _userController = new UserController(userService);
        }
Exemplo n.º 6
0
 BaseEffectsProcessor processor()
 {
     if (_processor == null)
     {
         var pType = BattleService.Get().effectsProcessorType(effectType);
         _processor = Activator.CreateInstance(pType) as BaseEffectsProcessor;
     }
     return(_processor);
 }
Exemplo n.º 7
0
 BaseResultProcessor processor()
 {
     if (_processor == null)
     {
         var pType = BattleService.Get().resultProcessorType(GetType());
         _processor = Activator.CreateInstance(pType) as BaseResultProcessor;
     }
     return(_processor);
 }
        public BattleSettingsViewModel()
        {
            _battleService     = new BattleService();
            BattleSettingsItem = RestoreFromFile() ?? InitDefaultValues();
#if DEBUG
            //var logBattle = _battleService.ExecuteBattle(BattleSettingsItem);
            //var battleLog = new BattleLog { DataContext = new BattleLogViewModel { LogBattle = logBattle } };
            //battleLog.Show();
#endif
        }
        public void CanAddBattleshipToPlain()
        {
            var mockPlain = new Mock <IHaveBattleships>();
            var service   = new BattleService();

            var battleship = new Battleships.StateManager.Entities.Battleship(new Position(1, 1), new Position(2, 1));

            service.AddBattleship(mockPlain.Object, battleship);

            mockPlain.Verify(x => x.AddBattleship(battleship), Times.Once);
        }
Exemplo n.º 10
0
        public void Shoot_WHEN_InvokedAndNoMapFound_THEN_ThrowsMapNotInitializedException()
        {
            var mapRepoMock         = new Mock <IRepository <Map> >();
            var scoreRepositoryMock = new Mock <IRepository <Score> >();

            mapRepoMock.SetupGet(c => c.Entity).Returns((Map)null);
            var battleService = new BattleService(mapRepoMock.Object, scoreRepositoryMock.Object);

            var act = new Func <ShootResult>(() => battleService.Shoot(10, 2));

            act.Should().ThrowExactly <MapNotInitializedException>();
        }
        public async Task Battle_SecondPokemonStronger_FirstPokemonWins()
        {
            // ARRANGE
            var firstPokemon = new PokemonDTO()
            {
                Id        = Guid.Parse("8372c3f3-8281-4c21-8d0f-8830817bc2fb"),
                BaseStats = new BaseStat()
                {
                    HealthPoints   = 50,
                    SpecialAttack  = 10,
                    Attack         = 10,
                    SpecialDefense = 10,
                    Defense        = 10,
                    Speed          = 2
                }
            };

            var secondPokemon = new PokemonDTO()
            {
                Id        = Guid.Parse("9372c3f3-8281-4c21-8d0f-8830817bc2fb"),
                BaseStats = new BaseStat()
                {
                    HealthPoints   = 100,
                    SpecialAttack  = 10,
                    Attack         = 10,
                    SpecialDefense = 10,
                    Defense        = 10,
                    Speed          = 2
                }
            };

            var pokemonServiceMock = new Mock <IPokemonService>();

            pokemonServiceMock
            .Setup(x => x.Get(Guid.Parse("8372c3f3-8281-4c21-8d0f-8830817bc2fb"), CancellationToken.None))
            .ReturnsAsync(firstPokemon);
            pokemonServiceMock
            .Setup(x => x.Get(Guid.Parse("9372c3f3-8281-4c21-8d0f-8830817bc2fb"), CancellationToken.None))
            .ReturnsAsync(secondPokemon);

            var logger = new NullLogger <BattleService>();

            var service = new BattleService(pokemonServiceMock.Object, logger);

            // ACT
            var result = await service.Battle(firstPokemon.Id, secondPokemon.Id, CancellationToken.None);

            // ASSERT
            Assert.Equal(secondPokemon.Id, result.WinnerID);
            Assert.Equal(firstPokemon.Id, result.LoserID);
            Assert.False(result.Draw);
        }
Exemplo n.º 12
0
        public void Shoot_WHEN_InvokedWithOutOfRange_THEN_ThrowsOutOfRangeException()
        {
            var mapRepoMock         = new Mock <IRepository <Map> >();
            var scoreRepositoryMock = new Mock <IRepository <Score> >();
            var mapWithShips        = new Map(10, 10);

            mapRepoMock.SetupGet(c => c.Entity).Returns(mapWithShips);
            var battleService = new BattleService(mapRepoMock.Object, scoreRepositoryMock.Object);

            var act = new Func <ShootResult>(() => battleService.Shoot(10, 2));

            act.Should().ThrowExactly <ArgumentOutOfRangeException>();
        }
        public void CannotHitEnemyPlainIfPositionIsWrong()
        {
            var mockPlain = new Mock <ICanGetHit>();

            var service = new BattleService();

            var position = new Position(2, 2);

            mockPlain.Setup(x => x.TakeHit(position)).Returns(false);
            var result = service.Shoot(mockPlain.Object, position);

            Assert.Equal(AttackResult.Miss, result);
            mockPlain.Verify(x => x.TakeHit(position), Times.Once);
        }
Exemplo n.º 14
0
        static void RunTestFight()
        {
            WarriorService warriorService = new WarriorService();
            BattleService  battleService  = new BattleService();

            var warriors = warriorService.SpawnWarriors(4);
            var list2    = new List <Warrior>();

            list2.Add(warriors[2]);
            list2.Add(warriors[3]);

            battleService.CommenceBattle(warriors);
            battleService.CommenceBattle(list2);
        }
Exemplo n.º 15
0
        private static FightResponseDTO TestPokemonFightWithGivenPokemons(List <PokemonModelDTO> pokemonList)
        {
            var pokedexService = PokedexServiceMock.PokedexService(pokemonList);
            var battleService  = new BattleService(pokedexService);
            var result         = battleService.StartTheFight(new BaseRequest <FightConfigurationDTO>
            {
                Data = new FightConfigurationDTO
                {
                    PokemonLeft  = pokemonList[1].Name,
                    PokemonRight = pokemonList[2].Name
                }
            });

            return(result);
        }
Exemplo n.º 16
0
 private void fight(RobotDifficulty difficulty)
 {
     try
     {
         var battleResult = BattleService.PerformBattle(_userId, difficulty);
         var str          = formatBattleResult(battleResult);
         resultLabel.Text = str;
         BattleService.RecordBattle(_userId, str);
         updateStatistics(battleResult.Hero);
     }
     catch (Exception exception)
     {
         resultLabel.Text = formatErrorMessage(exception.Message);
     }
 }
Exemplo n.º 17
0
 public TBattleRecord(List <MatchUser> users, string battleId = null)
 {
     if (users == null || users.Count == 0)
     {
         return;
     }
     BattleId      = string.IsNullOrEmpty(battleId) ? Guid.NewGuid().ToString("N") : battleId;
     BattleVersion = BattleService.BATTLE_VERSION;
     BattleSeed    = BattleService.GenerateSeed();
     BattleType    = users[0].BattleType;
     PlayerList    = users.Select(u => new TBattlePlayer(u)).ToList();
     FrameCount    = -1;
     IsRealTime    = !users.Any(u => u.IsRobot);
     BattleResult  = null;
     SnapShot      = null;
 }
Exemplo n.º 18
0
        public void Shoot_WHEN_InvokedAndMissed_THEN_ReturnsMissedStatus()
        {
            var mapRepoMock         = new Mock <IRepository <Map> >();
            var scoreRepositoryMock = new Mock <IRepository <Score> >();

            scoreRepositoryMock.SetupGet(c => c.Entity).Returns(new Score());
            var mapWithShips = new Map(10, 10);
            var ship         = CreateShipWithCoordinates();

            AssignShipToMap(mapWithShips, ship);
            mapRepoMock.SetupGet(c => c.Entity).Returns(mapWithShips);
            var battleService = new BattleService(mapRepoMock.Object, scoreRepositoryMock.Object);

            var result = battleService.Shoot(1, 1);

            result.LastShootStatus.Should().BeEquivalentTo(ShootStatus.Missed);
        }
Exemplo n.º 19
0
    public void CalledEveryFrame()
    {
        foreach (KeyValuePair <int, float> kvp in runtimeData.skillContinueSet)
        {
            int   key        = kvp.Key;
            float effectTime = kvp.Value;
            if (effectTime == 0)
            {
                continue;
            }

            effectTime -= Time.deltaTime;
            if (effectTime <= 0)
            {
                BattleService battle = GameCore.GetRegistServices <BattleService>();
                battle.GetSkillByID(key);
            }
            effectTime = Mathf.Min(0, effectTime);
        }
    }
Exemplo n.º 20
0
 public TBattlePlayer(MatchUser user)
 {
     if (user == null)
     {
         return;
     }
     PlayerId      = user.UserId;
     PlayerName    = user.UserName;
     PlayerLevel   = user.CurLevel;
     ServerId      = user.ServerId;
     PlayerSeed    = BattleService.GenerateSeed();
     TowerPool     = user.TowerPool;
     Hero          = user.Hero;
     CriticalScale = user.CriticalScale;
     PlayerFrame   = new TBattlePlayerFrame()
     {
         FrameList = new List <TBattleFrame>()
     };
     PlayerAI = user.PlayerAI;
     FieldId  = user.FieldId;
 }
        public ActionResult Index()
        {
            var userId     = User.Identity.GetUserId();
            var user       = db.Users.Find(userId);
            var challenges = db.Challenges.Where(c => c.ChallengerId == userId || c.ReceiverId == userId && c.Accepted == false).ToList();
            var battles    = db.Battles.Where(b => b.Challenge.ChallengerId == userId || b.Challenge.ReceiverId == userId).ToList();

            var battleService = new BattleService();

            battleService.RunBattles();

            if (user.Stamina < user.MaxStamina)
            {
                var staminaService = new StaminaService();
                staminaService.UpdateStamina(userId);
            }

            ViewBag.UserId     = userId;
            ViewBag.Challenges = challenges;
            ViewBag.Battles    = battles;

            return(View(db.Users.ToList()));
        }
Exemplo n.º 22
0
        protected override Task <(bool Success, string Message)> CheckCustomPreconditionsAsync()
        {
            var baseResult = base.CheckCustomPreconditionsAsync();

            if (!baseResult.Result.Success)
            {
                return(baseResult);
            }

            if (!BattleService.UserInBattle(Context.User.Id))
            {
                return(Task.FromResult((false, "You aren't in a battle.")));
            }

            Player = Battle.GetPlayer(Context.User.Id);
            if (Player == null)
            {
                return(Task.FromResult((false, "You aren't in this battle.")));
            }

            if (!Battle.IsUsersMessage(Player, Context.Message))
            {
                return(Task.FromResult((false, "Click your own message!")));
            }

            if (Battle.IsProcessing)
            {
                return(Task.FromResult((false, "Too fast.")));
            }

            if (!Player.IsAlive)
            {
                return(Task.FromResult((false, "You are dead.")));
            }

            return(baseResult);
        }
Exemplo n.º 23
0
    public void DoReleaseSkill(int skillID)
    {
        if (targetEntity != null)
        {
            this.m_Transform.LookAt(targetEntity.m_Transform.position);
        }

        EntityAnimEnum s     = EntityAnimEnum.Attack;
        Skill          skill = GameCore.GetRegistServices <BattleService>().GetSkillByID(skillID);

        if (skill != null)
        {
            s = skill.playAniWhenRelease;
        }
        this.entityVisual.PlayReleaseSkill(s);     //动画
        this.controllRemote.DoReleaseSkill(skill); //更新cd

        //技能结算
        BattleService battle = GameCore.GetRegistServices <BattleService>();

        //battle.QuestSkillCalculate(selectSkillID, this.controllRemote, targetEntity.GetControllRemote());
        battle.QuestSkillCalculate(skillID, this);
        //this.targetEntity.SendCmd(entityID, Command.CaughtDamage, string.Empty);
    }
Exemplo n.º 24
0
        void RunServices()
        {
            var db = new ApplicationDbContext();

            var userId = User.Identity.GetUserId();
            var user   = db.Users.Find(userId);

            if ((DateTimeOffset.Now - user.LastRainbowGemTime).TotalHours >= 24)
            {
                user.RainbowGems++;
                user.LastRainbowGemTime = DateTimeOffset.Now;
            }

            user.LastActive = DateTimeOffset.Now;
            db.SaveChanges();

            if (db.Travels.Any(t => t.UserId == userId))
            {
                var travelService = new TravelService();
                travelService.CheckArrivalTime(userId);
            }

            if (user.Stamina < user.MaxStamina)
            {
                var staminaService = new StaminaService();
                staminaService.UpdateStamina(userId);
            }

            var battleService = new BattleService();

            battleService.RunBattles();

            var auctionService = new AuctionService();

            auctionService.CheckAuctions();
        }
Exemplo n.º 25
0
    private void Start()
    {
        _battle = GameServiceCollection.GetService <BattleService>();

        _battle.StartBattle(this);
    }
Exemplo n.º 26
0
 private CampService()
 {
     BattleService = BattleService.GetInstance();
 }
Exemplo n.º 27
0
        public async Task RodandoBot(string[] args)
        {
            var discord = new DiscordClient(new DiscordConfiguration
            {
                Token           = Parameters.token,
                TokenType       = TokenType.Bot,
                MinimumLogLevel = LogLevel.Debug
            });

            discord.UseInteractivity(new InteractivityConfiguration()
            {
                Timeout             = System.TimeSpan.FromSeconds(30),
                PollBehaviour       = PollBehaviour.KeepEmojis,
                PaginationBehaviour = PaginationBehaviour.Ignore,
                PaginationDeletion  = PaginationDeletion.KeepEmojis
            });

            this.Database             = new DataContext();
            this.StartsRepository     = new StartsRepository(this.Database);
            this.ItemRepository       = new ItemRepository(this.Database);
            this.CharactersRepository = new CharactersRepository(this.Database);
            this.AtributesRepository  = new AtributesRepository(this.Database);
            this.MonsterRepository    = new MonsterRepository(this.Database);
            this.BattleService        = new BattleService(this.Database);


            var services = new ServiceCollection()
                           .AddSingleton(this.Database)
                           .AddSingleton(this.StartsRepository)
                           .AddSingleton(this.ItemRepository)
                           .AddSingleton(this.CharactersRepository)
                           .AddSingleton(this.AtributesRepository)
                           .AddSingleton(this.MonsterRepository)
                           .AddSingleton(this.BattleService)
                           .BuildServiceProvider();


            var commands = discord.UseCommandsNext(new CommandsNextConfiguration
            {
                Services       = services,
                StringPrefixes = Parameters.Prefix
            });

            commands.RegisterCommands <LavaLinkCommands>();
            commands.RegisterCommands <StartCommands>();
            commands.RegisterCommands <AssignAtributtesCharacter>();
            commands.RegisterCommands <StatusCommands>();
            commands.RegisterCommands <ItemCommands>();
            commands.RegisterCommands <MonsterCommands>();
            commands.RegisterCommands <BattleCommands>();
            commands.RegisterCommands <B3Commands>();

            //B3Api.B3Api.B3(args);

            var endPoint = new ConnectionEndpoint
            {
                Hostname = "127.0.0.1",
                Port     = 2333
            };

            var lavaLinkConfig = new LavalinkConfiguration
            {
                Password       = "******",
                RestEndpoint   = endPoint,
                SocketEndpoint = endPoint
            };

            var lavalink = discord.UseLavalink();
            await discord.ConnectAsync();

            await lavalink.ConnectAsync(lavaLinkConfig);



            //espera infinita, para o bot ficar online continuamente.
            await Task.Delay(-1);
        }
Exemplo n.º 28
0
 public void Setup()
 {
     _battleService = new BattleService();
 }
Exemplo n.º 29
0
        public BattleServiceTest()
        {
            _logger = new Mock <ILogger <BattleService> >();

            _battleService = new BattleService(_logger.Object);
        }
Exemplo n.º 30
0
 public BattleController(BattleService battleService, BattleProvider battleProvider)
 {
     _battleService  = battleService;
     _battleProvider = battleProvider;
 }