public KMHoldableCommander(FloatingHoldable holdable)
 {
     Holdable         = holdable;
     Selectable       = Holdable.GetComponent <Selectable>();
     FloatingHoldable = Holdable.GetComponent <FloatingHoldable>();
     Handler          = HoldableFactory.CreateHandler(this, holdable);
 }
    public IEnumerator Hold(bool frontFace = true)
    {
        FloatingHoldable holdable = FloatingHoldable.GetComponent <FloatingHoldable>();

        FloatingHoldable.HoldStateEnum holdState = holdable.HoldState;
        bool doForceRotate = false;

        if (holdState != global::FloatingHoldable.HoldStateEnum.Held)
        {
            SelectObject(Selectable.GetComponent <Selectable>());
            doForceRotate = true;
        }
        else if (frontFace != _heldFrontFace)
        {
            doForceRotate = true;
        }

        if (!doForceRotate)
        {
            yield break;
        }

        float       holdTime = holdable.PickupTime;
        IEnumerator forceRotationCoroutine = ForceHeldRotation(frontFace, holdTime);

        while (forceRotationCoroutine.MoveNext())
        {
            yield return(forceRotationCoroutine.Current);
        }
    }
Example #3
0
    public static void InitializePage(FloatingHoldable holdable)
    {
        Selectable holdableSelectable = holdable.GetComponent <Selectable>();
        var        currentPage        = holdable.GetComponentsInChildren <Selectable>(false).FirstOrDefault(x => x != holdableSelectable);

        _currentSelectable = currentPage?.GetCurrentChild();
        _currentSelectable?.HandleSelect(true);
        _currentSelectables     = currentPage?.Children;
        _currentSelectableIndex = _currentSelectables?.IndexOf(sel => sel == _currentSelectable) ?? -1;
    }
Example #4
0
    public TwitchHoldable(FloatingHoldable holdable, Type commandType = null, bool allowModded = false, string id = null)
    {
        Holdable    = holdable;
        CommandType = commandType;
        _defaultId  = id ?? holdable.name.ToLowerInvariant().Replace("(clone)", "");

        if (TwitchGame.BombActive)
        {
            var gameCommands = holdable.GetComponent <KMGameCommands>();
            if (gameCommands != null)
            {
                gameCommands.OnCauseStrike += OnStrike;
            }
        }

        if (allowModded)
        {
            // Find a suitable ProcessTwitchCommand method
            foreach (var component in holdable.GetComponentsInChildren <Component>(true))
            {
                if (component == null)
                {
                    continue;
                }

                var type            = component.GetType();
                var candidateMethod = type.GetMethod("ProcessTwitchCommand", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                if (candidateMethod == null)
                {
                    continue;
                }
                if (ValidateMethodCommandMethod(type, candidateMethod))
                {
                    HandlerMethod    = candidateMethod;
                    CommandComponent = component;

                    HelpMessageField = type.GetField("TwitchHelpMessage", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);

                    // Find a suitable TwitchShouldCancelCommand boolean field
                    FieldInfo f;
                    if ((f = type.GetField("TwitchShouldCancelCommand", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) != null && f.FieldType == typeof(bool))
                    {
                        CancelBool = f;
                    }
                    break;
                }
            }

            if (HandlerMethod == null)
            {
                // No method found.
                LogAllComponentTypes(holdable);
            }
        }
    }
Example #5
0
    public static IEnumerator StartAdvanced(FloatingHoldable holdable, [Group(1)] string command, [Group(2)] string parameters, string user, bool isWhisper)
    {
        if (parameters.RegexMatch(out Match m, @"(\d):(\d{1,3}):(\d{2})"))
        {
            var e = SetBombTimer(holdable, int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value), int.Parse(m.Groups[3].Value));
            while (e.MoveNext())
            {
                yield return(e.Current);
            }
        }
        else if (parameters.RegexMatch(out m, @"(\d{1,3}):(\d{2})"))
        {
            var e = SetBombTimer(holdable, 0, int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value));
            while (e.MoveNext())
            {
                yield return(e.Current);
            }
        }

        if (MultipleBombs.Installed() && parameters.RegexMatch(out m, @"(\d+) +bombs"))
        {
            var e = ChangeBombCount(holdable, int.Parse(m.Groups[1].Value));
            while (e.MoveNext())
            {
                yield return(e.Current);
            }
        }
        if (parameters.RegexMatch(out m, @"(\d+) +modules"))
        {
            var e = ChangeModuleCount(holdable, int.Parse(m.Groups[1].Value));
            while (e.MoveNext())
            {
                yield return(e.Current);
            }
        }

        yield return(null);

        SetSetting(holdable, parameters.Contains("hardcore"), user, isWhisper, s => s.IsHardCore, s => s.HardcoreToggle, TwitchPlaySettings.data.EnableFreeplayHardcore, TwitchPlaySettings.data.FreePlayHardcoreDisabled);
        yield return(null);

        SetSetting(holdable, parameters.Contains("modsonly"), user, isWhisper, s => s.OnlyMods, s => s.ModsOnly, TwitchPlaySettings.data.EnableFreeplayModsOnly, TwitchPlaySettings.data.FreePlayModsOnlyDisabled);
        yield return(null);

        SetSetting(holdable, parameters.Contains("needy") || parameters.Contains("needies"), user, isWhisper, s => s.HasNeedy, s => s.NeedyToggle, TwitchPlaySettings.data.EnableFreeplayNeedy, TwitchPlaySettings.data.FreePlayNeedyDisabled);
        yield return(null);

        if (command.EqualsIgnoreCase("start"))
        {
            holdable.GetComponent <FreeplayDevice>().StartButton.GetComponent <Selectable>().Trigger();
        }
    }
Example #6
0
 private static void SetSetting(FloatingHoldable holdable, bool on, string user, bool isWhisper, Func <FreeplaySettings, bool> getCurrent, Func <FreeplayDevice, ToggleSwitch> toggle, bool settingAllowed, string disabledMessage)
 {
     if (settingAllowed || !on || UserAccess.HasAccess(user, AccessLevel.Admin, true) || TwitchPlaySettings.data.AnarchyMode)
     {
         var device = holdable.GetComponent <FreeplayDevice>();
         if (on != getCurrent(device.CurrentSettings))
         {
             toggle(device).GetComponent <Selectable>().Trigger();
         }
     }
     else
     {
         IRCConnection.SendMessage(string.Format(disabledMessage, user), user, !isWhisper);
     }
 }
 public IRCConnectionManagerHandler(KMHoldableCommander commander, FloatingHoldable holdable) : base(commander, holdable)
 {
     _connectButton  = holdable.GetComponent <IRCConnectionManagerHoldable>().ConnectButton;
     _elevatorSwitch = TPElevatorSwitch.Instance;
     HelpMessage     = "Disconnect the IRC from twitch plays with !{0} disconnect.  For obvious reasons, only the streamer may do this.";
     if (_elevatorSwitch?.gameObject.activeInHierarchy ?? false)
     {
         HelpMessage += " Turn the elevator on with !{0} elevator on. Turn the Elevator off with !{0} elevator off. Flip the elevator on/off with !{0} elevator toggle";
     }
     if (commander != null)
     {
         commander.ID = "ircmanager";
     }
     Instance = this;
 }
    protected HoldableHandler(KMHoldableCommander commander, FloatingHoldable holdable)
    {
        HoldableCommander = commander;
        Holdable          = holdable;

        if (!BombMessageResponder.BombActive)
        {
            return;
        }
        KMGameCommands gameCommands = holdable.GetComponent <KMGameCommands>();

        if (gameCommands == null)
        {
            return;
        }
        gameCommands.OnCauseStrike += OnStrike;
    }
Example #9
0
    public static IEnumerator Throw(FloatingHoldable holdable, [Group(1)] int?optionalStrength = 3)
    {
        int strength = optionalStrength ?? 3;

        holdable.Pause();
        Rigidbody rigidbody = holdable.GetComponent <Rigidbody>();

        rigidbody.isKinematic        = false;
        rigidbody.useGravity         = true;
        rigidbody.velocity           = Random.onUnitSphere * rigidbody.mass * strength;
        rigidbody.angularVelocity    = Random.onUnitSphere * rigidbody.mass * strength;
        rigidbody.maxAngularVelocity = 100f;
        yield return(new WaitForSeconds(2));

        rigidbody.isKinematic = true;
        rigidbody.useGravity  = false;
        holdable.Resume();
    }
Example #10
0
    public static IEnumerator ChangeModuleCount(FloatingHoldable holdable, [Group(1)] int moduleCount)
    {
        var device             = holdable.GetComponent <FreeplayDevice>();
        int currentModuleCount = device.CurrentSettings.ModuleCount;
        var button             = (moduleCount > currentModuleCount ? device.ModuleCountIncrement : device.ModuleCountDecrement).GetComponent <Selectable>();

        for (int hitCount = 0; hitCount < Mathf.Abs(moduleCount - currentModuleCount); ++hitCount)
        {
            int lastModuleCount = device.CurrentSettings.ModuleCount;
            button.Trigger();
            yield return(new WaitForSeconds(0.01f));

            if (lastModuleCount == device.CurrentSettings.ModuleCount)
            {
                yield break;
            }
        }
    }
    public IEnumerator LetGoBomb()
    {
        if (FloatingHoldable.GetComponent <FloatingHoldable>().HoldState != global::FloatingHoldable.HoldStateEnum.Held)
        {
            yield break;
        }

        IEnumerator turnCoroutine = Hold(true);

        while (turnCoroutine.MoveNext())
        {
            yield return(turnCoroutine.Current);
        }

        while (FloatingHoldable.GetComponent <FloatingHoldable>().HoldState == global::FloatingHoldable.HoldStateEnum.Held)
        {
            DeselectObject(Selectable.GetComponent <Selectable>());
            yield return(new WaitForSeconds(0.1f));
        }
    }
Example #12
0
    private static IEnumerator SetBombTimer(FloatingHoldable holdable, int hours, int minutes, int seconds)
    {
        if (seconds >= 60)
        {
            yield break;
        }

        var device    = holdable.GetComponent <FreeplayDevice>();
        int timeIndex = (hours * 120) + (minutes * 2) + (seconds / 30);

        DebugHelper.Log("Freeplay time doubling section");
        //Double the available free play time. (The doubling stacks with the Multiple bombs module installed)
        float originalMaxTime = FreeplayDevice.MAX_SECONDS_TO_SOLVE;
        int   maxModules      = (int)_maxModuleField.GetValue(device);
        int   multiplier      = MultipleBombs.Installed() ? (MultipleBombs.GetMaximumBombCount() * 2) - 1 : 1;
        float newMaxTime      = 600f + (maxModules - 1) * multiplier * 60;

        FreeplayDevice.MAX_SECONDS_TO_SOLVE = newMaxTime;

        DebugHelper.Log("Freeplay settings reading section");
        float        currentTime      = device.CurrentSettings.Time;
        int          currentTimeIndex = Mathf.FloorToInt(currentTime) / 30;
        KeypadButton button           = timeIndex > currentTimeIndex ? device.TimeIncrement : device.TimeDecrement;
        Selectable   buttonSelectable = button.GetComponent <Selectable>();

        DebugHelper.Log("Freeplay time setting section");
        for (int hitCount = 0; hitCount < Mathf.Abs(timeIndex - currentTimeIndex); ++hitCount)
        {
            currentTime = device.CurrentSettings.Time;
            buttonSelectable.Trigger();
            yield return(new WaitForSeconds(0.01f));

            if (Mathf.FloorToInt(currentTime) == Mathf.FloorToInt(device.CurrentSettings.Time))
            {
                break;
            }
        }

        //Restore original max time, just in case Multiple bombs module was NOT installed, to avoid false detection.
        FreeplayDevice.MAX_SECONDS_TO_SOLVE = originalMaxTime;
    }
Example #13
0
    public static HoldableHandler CreateHandler(KMHoldableCommander commander, FloatingHoldable holdable)
    {
        if (commander != null)
        {
            commander.ID = holdable.name.ToLowerInvariant().Replace("(clone)", "");
        }

        foreach (Type type in ModHoldableTypes)
        {
            if (type?.FullName == null)
            {
                continue;
            }
            if (holdable.GetComponent(type) == null || !ModHoldableCreators.ContainsKey(type.FullName))
            {
                continue;
            }
            return(ModHoldableCreators[type.FullName](commander, holdable));
        }

        return(CreateModComponentSolver(commander, holdable));
    }
Example #14
0
    public static IEnumerator ChangeBombCount(FloatingHoldable holdable, [Group(1)] int bombCount)
    {
        if (!MultipleBombs.Installed())
        {
            yield break;
        }

        int currentBombCount = MultipleBombs.GetFreePlayBombCount();
        var buttonSelectable = holdable.GetComponent <Selectable>().Children[bombCount > currentBombCount ? 3 : 2];

        for (int hitCount = 0; hitCount < Mathf.Abs(bombCount - currentBombCount); ++hitCount)
        {
            int lastBombCount = MultipleBombs.GetFreePlayBombCount();
            buttonSelectable.Trigger();
            yield return(new WaitForSeconds(0.01f));

            // Stop here if we hit a maximum or minimum
            if (lastBombCount == MultipleBombs.GetFreePlayBombCount())
            {
                yield break;
            }
        }
    }
Example #15
0
 public static void Start(FloatingHoldable holdable) => holdable.GetComponent <FreeplayDevice>().StartButton.GetComponent <Selectable>().Trigger();
Example #16
0
 private static bool FindCancelBool(FloatingHoldable holdable, Type holdableType, out FieldInfo CancelField)
 {
     CancelField = holdableType.GetField("TwitchShouldCancelCommand", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
     return(CancelField?.GetValue(holdable.GetComponent(holdableType)) is bool);
 }