예제 #1
0
        /// <summary>
        /// Engage in the boss fight minigame
        /// </summary>
        /// <param name="chatter">User that sent the message</param>
        public async Task <DateTime> BossFight(TwitchChatter chatter)
        {
            try
            {
                BossFight bossFight = new BossFight();
                int       funds     = await _bank.CheckBalanceAsync(chatter.Username, _broadcasterInstance.DatabaseId);

                if (_bossSettingsInstance.IsBossFightOnCooldown())
                {
                    TimeSpan cooldown = _bossSettingsInstance.CooldownTimePeriod.Subtract(DateTime.Now);

                    if (cooldown.Minutes >= 1)
                    {
                        _irc.SendPublicChatMessage(_bossSettingsInstance.CooldownEntry
                                                   .Replace("@timeleft@", cooldown.Minutes.ToString()));
                    }
                    else
                    {
                        _irc.SendPublicChatMessage(_bossSettingsInstance.CooldownEntry
                                                   .Replace("@timeleft@", cooldown.Seconds.ToString())
                                                   .Replace("minutes", "seconds"));
                    }

                    return(DateTime.Now);
                }

                if (_bossSettingsInstance.RefreshBossFight)
                {
                    _irc.SendPublicChatMessage($"The boss fight is currently being refreshed with new settings @{chatter.DisplayName}");
                    return(DateTime.Now);
                }

                if (bossFight.HasFighterAlreadyEntered(chatter.Username))
                {
                    _irc.SendPublicChatMessage($"You are already in this fight @{chatter.DisplayName}");
                    return(DateTime.Now);
                }

                if (funds < _bossSettingsInstance.Cost)
                {
                    _irc.SendPublicChatMessage($"You do need {_bossSettingsInstance.Cost} {_botConfig.CurrencyType} to enter this fight @{chatter.DisplayName}");
                    return(DateTime.Now);
                }

                if (!bossFight.IsEntryPeriodOver())
                {
                    ChatterType chatterType = ChatterType.DoesNotExist;

                    // join boss fight
                    if (chatter.Badges.Contains("moderator") ||
                        chatter.Badges.Contains("admin") ||
                        chatter.Badges.Contains("global_mod") ||
                        chatter.Badges.Contains("staff") ||
                        chatter.Username == _botConfig.Broadcaster.ToLower())
                    {
                        chatterType = ChatterType.Moderator;
                    }
                    else if (chatter.Badges.Contains("subscriber") || chatter.Badges.Contains("vip"))
                    {
                        chatterType = ChatterType.Subscriber;
                    }
                    // ToDo: Create new columns in the BossFightClassStats table for VIP stats
                    //else if (chatter.Badges.Contains("vip"))
                    //{
                    //    chatterType = ChatterType.VIP;
                    //}
                    else
                    {
                        chatterType = _twitchChatterListInstance.GetUserChatterType(chatter.Username);
                        if (chatterType == ChatterType.DoesNotExist)
                        {
                            using (HttpResponseMessage message = await _twitchInfo.CheckFollowerStatusAsync(chatter.TwitchId))
                            {
                                // check if chatter is a follower
                                if (!message.IsSuccessStatusCode)
                                {
                                    int currentExp = await _follower.CurrentExpAsync(chatter.Username, _broadcasterInstance.DatabaseId);

                                    if (_follower.IsRegularFollower(currentExp, _botConfig.RegularFollowerHours))
                                    {
                                        chatterType = ChatterType.RegularFollower;
                                    }
                                    else
                                    {
                                        chatterType = ChatterType.Follower;
                                    }
                                }
                                else
                                {
                                    chatterType = ChatterType.Viewer;
                                }
                            }
                        }
                    }

                    // make boss fight announcement if first fighter and start recruiting members
                    if (_bossSettingsInstance.Fighters.Count == 0)
                    {
                        _bossSettingsInstance.EntryPeriod = DateTime.Now.AddSeconds(_bossSettingsInstance.EntryPeriodSeconds);
                        _irc.SendPublicChatMessage(_bossSettingsInstance.EntryMessage.Replace("user@", chatter.Username));
                    }

                    FighterClass fighterClass = _bossSettingsInstance.ClassStats.Single(c => c.ChatterType == chatterType);
                    BossFighter  fighter      = new BossFighter {
                        Username = chatter.Username, FighterClass = fighterClass
                    };
                    bossFight.Produce(fighter);
                    await _bank.UpdateFundsAsync(chatter.Username, _broadcasterInstance.DatabaseId, funds - _bossSettingsInstance.Cost);

                    // display new boss level
                    if (!string.IsNullOrEmpty(bossFight.NextLevelMessage()))
                    {
                        _irc.SendPublicChatMessage(bossFight.NextLevelMessage());
                    }
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "MinigameFeature", "BossFight(TwitchChatter)", false, "!raid");
            }

            return(DateTime.Now);
        }