Esempio n. 1
0
    public static void Assign(TwitchModule module, string user, [Group(1)] string targetUser)
    {
        targetUser = targetUser.FormatUsername();
        if (module.PlayerName == targetUser)
        {
            IRCConnection.SendMessage($"{user}, the module is already assigned to {targetUser}.");
            return;
        }

        if (TwitchPlaySettings.data.AnarchyMode)
        {
            IRCConnection.SendMessage($"{user}, assigning modules is not allowed in anarchy mode.");
            return;
        }

        if (!UserAccess.HasAccess(user, AccessLevel.Mod, true))
        {
            if (module.PlayerName != user || !module.ClaimQueue.Any(q => q.UserNickname == targetUser))
            {
                IRCConnection.SendMessage($"{user}, {module.Code} can only be reassigned if you have it claimed and the other user is in its claim queue.");
                return;
            }
            if (TwitchGame.Instance.Modules.Count(md => !md.Solved && targetUser.EqualsIgnoreCase(md.PlayerName)) >= TwitchPlaySettings.data.ModuleClaimLimit)
            {
                IRCConnection.SendMessage($"{user}, {module.Code} cannot be reassigned because it would take the other user above their claim limit.");
                return;
            }
        }

        if (module.TakeInProgress != null)
        {
            module.StopCoroutine(module.TakeInProgress);
            module.TakeInProgress = null;
            module.TakeUser       = null;
        }

        module.SetClaimedBy(targetUser);
        IRCConnection.SendMessageFormat(TwitchPlaySettings.data.AssignModule, module.Code, module.PlayerName, user, module.HeaderText);
    }