Exemple #1
0
        public bool SetSkillLevel(string twitchUserId, string identifier, string skill, int level, double experience = 0)
        {
            var user = gameData.FindUser(twitchUserId);

            if (user == null)
            {
                return(false);
            }

            if (level < 1 || level > GameMath.MaxLevel)
            {
                return(false);
            }

            var character = gameData.GetCharacterByUserId(user.Id, identifier);

            if (character == null)
            {
                return(false);
            }

            var skills = gameData.GetCharacterSkills(character.SkillsId);

            if (skills == null)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(skill))
            {
                return(false);
            }

            var allSkills   = skills.GetSkills();
            var targetSkill = allSkills.FirstOrDefault(x => x.Name.Equals(skill.Trim(), StringComparison.CurrentCultureIgnoreCase));

            if (targetSkill == null)
            {
                return(false);
            }

            targetSkill.Level      = level;
            targetSkill.Experience = experience;
            return(true);
        }
Exemple #2
0
        private User TryGetUser(IPatreonData data)
        {
            var firstName      = data.FullName?.Split(' ')?.FirstOrDefault();
            var twitchUserName = "";

            if (!string.IsNullOrEmpty(data.TwitchUrl))
            {
                twitchUserName = data.TwitchUrl.Split('/').LastOrDefault()?.ToLower();
            }
            var emailLower = data.Email.ToLower();
            var emailuser  = emailLower.Split('@').FirstOrDefault();

            return(gameData.FindUser(u =>
            {
                if (u == null)
                {
                    return false;
                }

                var email = u.Email?.ToLower() ?? string.Empty;

                if (!string.IsNullOrEmpty(twitchUserName) && u.UserName.ToLower() == twitchUserName)
                {
                    return true;
                }

                if (!string.IsNullOrEmpty(data.TwitchUserId) && u.UserId == data.TwitchUserId)
                {
                    return true;
                }

                if (!string.IsNullOrEmpty(u.UserName) && (u.UserName.ToLower() == firstName?.ToLower() || u.UserName.ToLower() == emailuser))
                {
                    return true;
                }

                if (email == emailLower || email.StartsWith(emailuser + "@"))
                {
                    return true;
                }

                return false;
            }));
        }
Exemple #3
0
        public bool EndSessionAndRaid(
            SessionToken token, string userIdOrUsername, bool isWarRaid)
        {
            var currentSession = gameData.GetSession(token.SessionId);

            if (currentSession == null)
            {
                return(false);
            }

            var sessionUser = gameData.GetUser(currentSession.UserId);
            var user        = gameData.FindUser(userIdOrUsername);

            if (user == null)
            {
                return(false);
            }

            var targetSession = gameData.GetUserSession(user.Id);

            if (targetSession == null)
            {
                return(false);
            }

            var characters = gameData.GetSessionCharacters(currentSession);

            var ge = gameData.CreateSessionEvent(
                isWarRaid ? GameEventType.WarRaid : GameEventType.Raid,
                targetSession, new
            {
                RaiderUserName = sessionUser.UserName,
                RaiderUserId   = sessionUser.UserId,
                Players        = characters.Select(x => gameData.GetUser(x.UserId).UserId).ToArray()
            });

            gameData.Add(ge);
            EndSession(token);
            return(true);
        }
Exemple #4
0
        public bool EndSessionAndRaid(
            SessionToken token, string userIdOrUsername, bool isWarRaid)
        {
            var currentSession = gameData.GetSession(token.SessionId);

            if (currentSession == null)
            {
                logger.LogError($"Unable to do a streamer raid. No active session for {token.TwitchUserName}.");
                return(false);
            }

            var sessionUser = gameData.GetUser(currentSession.UserId);

            if (userIdOrUsername.StartsWith("war ", StringComparison.OrdinalIgnoreCase))
            {
                userIdOrUsername = userIdOrUsername.Replace("war ", "", StringComparison.OrdinalIgnoreCase);
                isWarRaid        = true;
            }

            var user = gameData.FindUser(userIdOrUsername);

            if (user == null)
            {
                logger.LogError($"Unable to do a streamer raid. No user found for {userIdOrUsername}.");
                return(false);
            }

            var targetSession = gameData.GetSessionByUserId(user.Id);

            if (targetSession == null)
            {
                logger.LogError($"Unable to do a streamer raid. Target user {userIdOrUsername} does not have an active session.");
                return(false);
            }

            var characters = gameData.GetSessionCharacters(currentSession);

            //var state = gameData.GetSessionState(token.SessionId);
            var ge = gameData.CreateSessionEvent(
                isWarRaid ? GameEventType.WarRaid : GameEventType.Raid,

                targetSession, new StreamRaidInfo
            {
                RaiderUserName = sessionUser.UserName,
                RaiderUserId   = sessionUser.UserId,
                Players        = characters.Select(x =>
                {
                    var u = gameData.GetUser(x.UserId);
                    return(new UserCharacter {
                        CharacterId = x.Id, UserId = u?.UserId, Username = u?.UserName
                    });
                }).ToList()
            });

            gameData.Add(ge);
            EndSession(token);

#if DEBUG
            logger.LogDebug(sessionUser + " is " + (isWarRaid ? "initiating a raid war on" : "raiding") + " " + user.DisplayName + " with " + characters.Count + " players.");
#endif

            return(true);
        }