Exemplo n.º 1
0
        private async void StartFight()
        {
            var minimumParticipants = await settingsService.GetIntegerSetting(SettingNames.BOSS_PARTICIPANT_MINIMUM);

            var pauseSecondsNotEnoughParticipants = await settingsService.GetIntegerSetting(SettingNames.BOSS_WAITING_SECONDS_AFTER_FAILED_ROUND);

            if (currentRound.Participants.Count < minimumParticipants)
            {
                LogOutput.LogInformation("[Bossfight] Abort boss round as not enough participants were found.");
                chatOutputService.SendMessage(bossOutputFormatter.GetOutput_NotEnoughParticipants(pauseSecondsNotEnoughParticipants / 60));
                cooldownTime = TimeSpan.FromSeconds(pauseSecondsNotEnoughParticipants);
                currentRound = null;
            }
            else
            {
                LogOutput.LogInformation("[Bossfight] Creating a new boss round.");
                currentRound.BossEnemy = await pokemonService.GetRandomPokemonWithParticipantCount(currentRound.Participants.Count);

                await CalculateFight();

                cooldownTime = TimeSpan.FromSeconds(await settingsService.GetIntegerSetting(SettingNames.BOSS_WAITING_SECONDS_BETWEEN_ROUNDS));
            }

            new Thread(() =>
            {
                DecreaseCooldownTime();
            }).Start();
        }
Exemplo n.º 2
0
        private async Task <TwitchChatReplyMessage> ParticipateInBossFight(TwitchChatMessage twitchChatMessage)
        {
            LogOutput.LogInformation($"[Bossfight] User requested to particpate in boss fight: {twitchChatMessage.TwitchUsername}, ID {twitchChatMessage.TwitchUserId}");

            TransferTwitchuser user_entered_battle = await userService.GetUser(twitchChatMessage.TwitchUserId);

            if (user_entered_battle == null)
            {
                LogOutput.LogInformation($"[Bossfight] User is not registered: {twitchChatMessage.TwitchUsername}, ID {twitchChatMessage.TwitchUserId}");
                return(new TwitchChatReplyMessage(twitchChatMessage.TwitchUsername, "Du bist noch nicht registriert. Schreibe !registrieren [Glumanda/Schiggy/Bisasam/Pikachu/Evoli] in den Chat, um dich zu registrieren."));
            }

            if (!bossService.IsBattleReady())
            {
                LogOutput.LogInformation($"[Bossfight] Battle is not ready: {twitchChatMessage.TwitchUsername}, ID {twitchChatMessage.TwitchUserId}");
                return(new TwitchChatReplyMessage(twitchChatMessage.TwitchUsername, "Aktuell streift kein Pokemon durch die Gegend. Versuche es in " + bossService.GetRemainingCoolDown().Minutes + " Minute(n) und " + bossService.GetRemainingCoolDown().Seconds + " Sekunde(n) erneut."));;
            }

            if (!bossService.IsBattleWaiting())
            {
                LogOutput.LogInformation($"[Bossfight] Creating a new boss round: {twitchChatMessage.TwitchUsername}, ID {twitchChatMessage.TwitchUserId}");
                bossService.StartNewBattleRound();
                chatOutputService.SendMessage(twitchChatMessage.TwitchUsername + " hat ein wildes Pokemon entdeckt! Schreibe !boss in den Chat, um ihm im Kampf beizustehen.");
            }

            bossService.AddUserToCurrentRound(user_entered_battle);
            LogOutput.LogInformation($"[Bossfight] User entered bossfight: {twitchChatMessage.TwitchUsername}, ID {twitchChatMessage.TwitchUserId}");

            return(null);
        }
Exemplo n.º 3
0
        private void CheckForTimeouts()
        {
            while (true)
            {
                List <UserfightRound> expiredFightToRemoveList         = new List <UserfightRound>();
                List <UserfightRound> expiredOnGoingFightsToRemoveList = new List <UserfightRound>();

                foreach (var expiredFight in expiredFights)
                {
                    if (expiredFight.CreatedDt.AddSeconds(timeUntilStartSec + expiredTimeoutSec) >= DateTimeOffset.Now)
                    {
                        //Monsters are ready to fight again
                        //TODO: Chat output!
                        expiredFightToRemoveList.Add(expiredFight);
                    }
                }

                //Find expired rounds
                foreach (var onGoingFight in onGoingFights)
                {
                    if ((DateTimeOffset.Now - onGoingFight.CreatedDt).TotalSeconds > timeUntilStartSec)
                    {
                        chatOutputService.SendMessage(onGoingFight.Defender.DisplayName + " hat die Herausforderung von " + onGoingFight.Attacker.DisplayName + " nicht angenommen. Die Runde wurde abgebrochen.");
                        expiredFights.Add(onGoingFight);
                        expiredOnGoingFightsToRemoveList.Add(onGoingFight);
                    }
                }

                //Remove expired rounds
                foreach (var expiredFight in expiredFightToRemoveList)
                {
                    expiredFights.Remove(expiredFight);
                }

                foreach (var expiredOnGoingRound in expiredOnGoingFightsToRemoveList)
                {
                    onGoingFights.Remove(expiredOnGoingRound);
                }

                //Wait for one second
                Thread.Sleep(1000);
            }
        }