Beispiel #1
0
        public FightResult CalculateUnlimited(FightOptions input)
        {
            var challenger = input.Challenger;
            var defender   = input.Defender;

            var exchange_challenger = challenger.Pokemon.GetRandomPokemon().Copy();
            var exchange_defender   = defender.Pokemon.GetRandomPokemon().Copy();

            //Fight until there are no Pokemon left.
            while (true)
            {
                //Step 1 - Check if the trainers still got Pokemon left
                if (defender.Pokemon.FirstOrDefault() == null)
                {
                    return(new FightResult(challenger.User, input.Kz_WithPokemonExchange ? exchange_defender : null));
                }
                if (challenger.Pokemon.FirstOrDefault() == null)
                {
                    return(new FightResult(defender.User, input.Kz_WithPokemonExchange ? exchange_challenger : null));
                }

                //Step 2 - Calculate next fight round
                var result = CalulateOneVSOne(input);

                if (result.Winner.User.Equals(defender.User))
                {
                    challenger.Pokemon.RemoveAt(0);
                }
                else
                {
                    defender.Pokemon.RemoveAt(0);
                }
            }
        }
Beispiel #2
0
        private FightRoundResult CalulateOneVSOne(FightOptions input)
        {
            bool challengerAttackFirst = randomGenerator.Next(0, 2) == 0;
            var  challenger            = input.Challenger;
            var  defender = input.Defender;

            while (((challenger.Pokemon.FirstOrDefault()?.HP ?? 0) > 0) && (defender.Pokemon.FirstOrDefault()?.HP ?? 0) > 0)
            {
                var defender_pokemon = defender.Pokemon[0];
                var attacker_pokemon = challenger.Pokemon[0];

                if (challengerAttackFirst)
                {
                    var damage = input.ParticipantBonus + attacker_pokemon.ATK * PokemonService.GetTypeAdvantageMultiplikator(attacker_pokemon.Type, defender_pokemon.Type) + randomGenerator.Next(-2, 3);
                    defender_pokemon.HP -= damage;

                    if (defender_pokemon.HP <= 0)
                    {
                        return(new FightRoundResult(challenger));
                    }

                    damage = defender_pokemon.ATK * PokemonService.GetTypeAdvantageMultiplikator(defender_pokemon.Type, attacker_pokemon.Type) + randomGenerator.Next(-2, 3);
                    attacker_pokemon.HP -= damage;

                    if (attacker_pokemon.HP <= 0)
                    {
                        return(new FightRoundResult(defender));
                    }
                }
                else
                {
                    var damage = defender_pokemon.ATK * PokemonService.GetTypeAdvantageMultiplikator(defender_pokemon.Type, attacker_pokemon.Type) + randomGenerator.Next(-2, 3);
                    attacker_pokemon.HP -= damage;

                    if (attacker_pokemon.HP <= 0)
                    {
                        return(new FightRoundResult(defender));
                    }

                    damage = attacker_pokemon.ATK * PokemonService.GetTypeAdvantageMultiplikator(attacker_pokemon.Type, defender_pokemon.Type) + randomGenerator.Next(-2, 3);
                    defender_pokemon.HP -= damage;

                    if (defender_pokemon.HP <= 0)
                    {
                        return(new FightRoundResult(challenger));
                    }
                }
            }

            return(null);
        }
Beispiel #3
0
        public async Task <FightResult> Fight()
        {
            FightParticipant attacker;
            FightParticipant defender;

            if (isSelectedFight)
            {
                attacker = Attacker.ToFightParticipantSelectedFightTeam();
                defender = Defender.ToFightParticipantSelectedFightTeam();
            }
            else
            {
                attacker = Attacker.ToFightParticipantRandomFightTeam();
                defender = Defender.ToFightParticipantRandomFightTeam();
            }

            //Determinate the Pokemon the users gonna exchange if the lose.
            TransferPokemon exchangePokemonATK = attacker.Pokemon[randomGenerator.Next(0, 6)];
            TransferPokemon exchangePokemonDEF = defender.Pokemon[randomGenerator.Next(0, 6)];

            Fight        fight        = new Fight();
            FightOptions fightOptions = new FightOptions(attacker, defender, true);

            var result = fight.CalculateUnlimited(fightOptions);

            if (result.Winner.Equals(Attacker))
            {
                if (withExchange)
                {
                    await ExchangePokemon(true, exchangePokemonDEF);
                }
                return(new FightResult(result.Winner, exchangePokemonDEF));
            }
            else
            {
                if (withExchange)
                {
                    await ExchangePokemon(false, exchangePokemonATK);
                }
                return(new FightResult(result.Winner, exchangePokemonATK));
            }
        }
Beispiel #4
0
        private async Task CalculateFight()
        {
            List <TransferTwitchuser> winners = new List <TransferTwitchuser>();
            var    bossOriginalHP             = currentRound.BossEnemy.HP;
            double atk_participants_bonus;

            if (currentRound.Participants.Count >= 10)
            {
                atk_participants_bonus = await settingsService.GetFloatSetting(SettingNames.BOSS_PARTICIPANT_BONUS);
            }
            else
            {
                atk_participants_bonus = (await settingsService.GetFloatSetting(SettingNames.BOSS_PARTICIPANT_BONUS_U10)) * currentRound.Participants.Count;
            }

            LogOutput.LogInformation("[Bossfight] Calculating boss fight. Boss Pokemon:" + currentRound.BossEnemy.Name + ", HP:" + currentRound.BossEnemy.HP);

            //Fight
            for (int i = 0; i < currentRound.Participants.Count; i++)
            {
                //Reset fight values
                currentRound.BossEnemy.HP = bossOriginalHP / 2;

                var fightOptions = new FightOptions(currentRound.Participants[i].ToFightParticipantRandomPokemon(), CreateBossParticipant(currentRound.BossEnemy), false, atk_participants_bonus);
                var result       = new Fight().CalculateUnlimited(fightOptions);

                if (result.Winner.Equals(currentRound.Participants[i]))
                {
                    winners.Add(currentRound.Participants[i]);
                }
            }

            //Register all winner pokemon and write chat msg
            #region Register all winner pokemon and write chat msg

            string output_message;
            if (winners.Any())
            {
                output_message = bossOutputFormatter.GetOutput_BossWinners(currentRound.BossEnemy.Name);

                for (int w = 0; w < winners.Count; w++)
                {
                    await userService.AddPokemon(winners[w].Id, currentRound.BossEnemy, false);

                    var avResult = await userService.CheckAndAddAchievement(winners[w].Id);

                    if (avResult.AchievementUnlocked == true)
                    {
                        foreach (var unlockedAV in avResult.UnlockedAchievements)
                        {
                            chatOutputService.SendMessage(bossOutputFormatter.GetOutput_AvUnlocked(winners[w].DisplayName, unlockedAV.AchievementName, unlockedAV.NPCName));
                        }
                    }

                    output_message += winners[w].DisplayName;
                    if (!(w + 1).Equals(winners.Count))
                    {
                        output_message += ", ";
                    }
                }
                output_message += ".";
            }
            else
            {
                output_message = bossOutputFormatter.GetOuput_BossNoWinners(currentRound.BossEnemy.Name, await settingsService.GetIntegerSetting(SettingNames.BOSS_WAITING_SECONDS_BETWEEN_ROUNDS) / 60);
            }

            //Chat output
            chatOutputService.SendMessage(output_message);
            LogOutput.LogInformation("[Bossfight] Boss fight ended. Winners:" + string.Join(",", winners.Select(w => w.DisplayName)));

            #endregion Register all winner pokemon and write chat msg

            //Clean up
            currentRound = null;
        }