private bool HandleKey(string[] modulesBefore, string[] modulesAfter, FieldInfo keyTurned, FieldInfo otherKeyTurned, FieldInfo beforeKeyField, MethodInfo onKeyTurn)
    {
        if (!GetValue(_activatedField) || GetValue(keyTurned))
        {
            return(false);
        }
        KMBombInfo   bombInfo   = BombComponent.GetComponent <KMBombInfo>();
        KMBombModule bombModule = BombComponent.GetComponent <KMBombModule>();

        if (TwitchPlaySettings.data.EnforceSolveAllBeforeTurningKeys &&
            modulesAfter.Any(x => bombInfo.GetSolvedModuleNames().Count(x.Equals) != bombInfo.GetSolvableModuleNames().Count(x.Equals)))
        {
            bombModule.HandleStrike();
            return(false);
        }

        beforeKeyField.SetValue(null, TwitchPlaySettings.data.DisableTurnTheKeysSoftLock ? new string[0] : modulesBefore);
        onKeyTurn.Invoke(BombComponent.GetComponent(_componentType), null);
        if (GetValue(keyTurned))
        {
            //Check to see if any forbidden modules for this key were solved.
            if (TwitchPlaySettings.data.DisableTurnTheKeysSoftLock && bombInfo.GetSolvedModuleNames().Any(modulesBefore.Contains))
            {
                bombModule.HandleStrike();  //If so, Award a strike for it.
            }
            if (GetValue(otherKeyTurned))
            {
                int modules = bombInfo.GetSolvedModuleNames().Count(x => RightAfterA.Contains(x) || LeftAfterA.Contains(x));
                TwitchPlaySettings.AddRewardBonus(2 * modules);
                IRCConnection.SendMessage("Reward increased by {0} for defusing module !{1} ({2}).", modules * 2, Code, bombModule.ModuleDisplayName);
            }
        }
        return(false);
    }
Example #2
0
    private bool HandleKey(string[] modulesBefore, IEnumerable <string> modulesAfter, FieldInfo keyTurned, FieldInfo otherKeyTurned, FieldInfo beforeKeyField, MethodInfo onKeyTurn, FieldInfo animatorField)
    {
        if (!GetValue(ActivatedField) || GetValue(keyTurned))
        {
            return(false);
        }
        KMBombInfo   bombInfo    = Module.BombComponent.GetComponent <KMBombInfo>();
        KMBombModule bombModule  = Module.BombComponent.GetComponent <KMBombModule>();
        KMAudio      bombAudio   = Module.BombComponent.GetComponent <KMAudio>();
        Animator     keyAnimator = (Animator)animatorField.GetValue(Module.BombComponent.GetComponent(ComponentType));

        if (TwitchPlaySettings.data.EnforceSolveAllBeforeTurningKeys &&
            modulesAfter.Any(x => bombInfo.GetSolvedModuleNames().Count(x.Equals) != bombInfo.GetSolvableModuleNames().Count(x.Equals)))
        {
            keyAnimator.SetTrigger("WrongTurn");
            bombAudio.PlaySoundAtTransform("WrongKeyTurnFK", Module.transform);
            bombModule.HandleStrike();
            return(false);
        }

        beforeKeyField.SetValue(null, TwitchPlaySettings.data.DisableTurnTheKeysSoftLock ? new string[0] : modulesBefore);
        onKeyTurn.Invoke(Module.BombComponent.GetComponent(ComponentType), null);
        if (GetValue(keyTurned))
        {
            //Check to see if any forbidden modules for this key were solved.
            if (TwitchPlaySettings.data.DisableTurnTheKeysSoftLock && bombInfo.GetSolvedModuleNames().Any(modulesBefore.Contains))
            {
                bombModule.HandleStrike();                 //If so, Award a strike for it.
            }
            if (!GetValue(otherKeyTurned))
            {
                return(false);
            }
            int modules = bombInfo.GetSolvedModuleNames().Count(x => RightAfterA.Contains(x) || LeftAfterA.Contains(x));
            TwitchPlaySettings.AddRewardBonus((2 * modules * OtherModes.ScoreMultiplier).RoundToInt());
            IRCConnection.SendMessage($"Reward increased by {modules * 2} for defusing module !{Code} ({bombModule.ModuleDisplayName}).");
        }
        else
        {
            keyAnimator.SetTrigger("WrongTurn");
            bombAudio.PlaySoundAtTransform("WrongKeyTurnFK", Module.transform);
        }
        return(false);
    }