コード例 #1
0
    public Module GetFocusedModule()
    {
        Module focused = null;

        //Debug.Log("finding focused module");
        foreach (Module module in Modules)
        {
            //Debug.LogFormat("Checking module {0}...", module.ModuleName);
            if (module.IsHeld())
            {
                focused = module;
                //Debug.Log("focused module found");
            }
        }
        //if(focused==null) Debug.Log("Couldn't find focused module. :(");
        return(focused);
    }
コード例 #2
0
    private IEnumerator CheckForBomb(bool first)
    {
        yield return(new WaitUntil(() => SceneManager.Instance.GameplayState.Bombs != null && SceneManager.Instance.GameplayState.Bombs.Count > 0));

        yield return(new WaitForSeconds(2.0f));

        Bombs.AddRange(SceneManager.Instance.GameplayState.Bombs);
        int i = 0;

        string[] keyModules =
        {
            "SouvenirModule", "MemoryV2", "TurnTheKey", "TurnTheKeyAdvanced", "theSwan", "HexiEvilFMN", "taxReturns"
        };
        foreach (Bomb bomb in Bombs)
        {
            BombCommanders.Add(new BombCommander(bomb, i));
            foreach (BombComponent bombComponent in bomb.BombComponents)
            {
                ComponentTypeEnum componentType = bombComponent.ComponentType;
                bool   keyModule  = false;
                string moduleName = string.Empty;

                switch (componentType)
                {
                case ComponentTypeEnum.Empty:
                case ComponentTypeEnum.Timer:
                    continue;

                case ComponentTypeEnum.NeedyCapacitor:
                case ComponentTypeEnum.NeedyKnob:
                case ComponentTypeEnum.NeedyVentGas:
                case ComponentTypeEnum.NeedyMod:
                    moduleName = bombComponent.GetModuleDisplayName();
                    keyModule  = true;
                    break;

                case ComponentTypeEnum.Mod:
                    KMBombModule KMModule = bombComponent.GetComponent <KMBombModule>();
                    keyModule = keyModules.Contains(KMModule.ModuleType);
                    goto default;

                default:
                    moduleName = bombComponent.GetModuleDisplayName();
                    break;
                }
                Module module = new Module(bombComponent, i)
                {
                    ComponentType = componentType,
                    IsKeyModule   = keyModule,
                    ModuleName    = moduleName,
                };

                Modules.Add(module);
            }
            i++;
        }
        strikeCounts.Clear();
        solveCounts.Clear();
        foreach (BombCommander commander in BombCommanders)
        {
            strikeCounts.Add(commander, commander.StrikeCount);
            solveCounts.Add(commander, commander.SolveCount);
        }
        BombActive = true;
        if (first)
        {
            arduinoConnection.Stop();
        }
        else
        {
            StartCoroutine(forceStop());
        }
        stop = false;
        wait = false;
    }
コード例 #3
0
    /*private IEnumerator Test()
     * {
     *  yield return null;
     *  setPins();
     *  yield return new WaitUntil(() => arduinoConnection._connected);
     *  minimumWait = arduinoConnection.Calibrate(String.Format("{0} {1} {2} 0 0 0", RP, GP, BP), goAbove);
     *  yield return new WaitForSeconds(3f);
     *  Debug.LogFormat("[Arduino Manager Holdable Service] Pins are: {0}, {1}, {2}. Baud rate is {3}. Implementation enabled: {4}, output time: {5}", RP, GP, BP, Baud, implementationEnabled, minimumWait);
     *  arduinoConnection.Stop();
     *  yield break;
     * }*/

    private IEnumerator getField()
    {
        yield return(null);

        setPins();
        while (currentState == KMGameInfo.State.Gameplay && implementationEnabled)
        {
            yield return(null);

            //Debug.Log("Getting field...");
            Module heldModule = null;
            if (BombActive)
            {
                //Debug.Log("Bomb active!");
                heldModule = GetFocusedModule();
            }
            if (heldModule != null && heldModule.IsSolved && BombActive)
            {
                //Debug.Log("Solved module selected: displaying green...");
                while (heldModule != null && heldModule.IsSolved)
                {
                    //Debug.Log("Updating module");
                    yield return(null);

                    if (ableToDisplay)
                    {
                        ableToDisplay = false; arduinoConnection.sendMSG(String.Format("{0} {1} {2} 0 255 0", RP, GP, BP)); stop = true;
                    }
                    heldModule = GetFocusedModule();
                }
                arduinoConnection.Stop();
                ableToDisplay = true;
            }
            else if (heldModule != null && BombActive)
            {
                //Debug.LogFormat("Checking field... {0}", heldModule.ModuleName);
                if (Reflectors.ContainsKey(heldModule.BombComponent))
                {
                    object    ReflectorOBJ   = Reflectors[heldModule.BombComponent];
                    Type      ReflectorType  = ReflectorOBJ.GetType();
                    FieldInfo ReflectedField = ReflectorType.GetField("arduinoRGBValues", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                    currentValues = (List <int>)ReflectedField.GetValue(ReflectorOBJ);
                }
                else
                {
                    List <int> outputValue = new List <int>();
                    foreach (var component in heldModule.BombComponent.GetComponentsInChildren <Component>(true))
                    {
                        var type = component.GetType();
                        outputValueField = type.GetField("arduinoRGBValues", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                        try { outputValue = (List <int>)outputValueField.GetValue(component); break; } catch { outputValue = new List <int>()
                                                                                                               {
                                                                                                                   0, 0, 0
                                                                                                               }; }
                    }
                    if (outputValue != null && outputValue.Count >= 3)
                    {
                        currentValues = outputValue;
                    }
                    //Debug.LogFormat("Got values {0} {1} {2}", currentValues[0], currentValues[1], currentValues[2]);
                }
                if (currentValues[0] != previousValues[0] || currentValues[1] != previousValues[1] || currentValues[2] != previousValues[2])
                {
                    previousValues = currentValues;
                    //Debug.LogFormat("New values found, sending {0} {1} {2}", currentValues[0], currentValues[1], currentValues[2]);
                    arduinoConnection.sendMSG(String.Format("{0} {1} {2} {3} {4} {5}", RP, GP, BP, currentValues[0] % 256, currentValues[1] % 256, currentValues[2] % 256));
                    setFrameColor(currentValues);
                    stop = true;
                }
                //else { Debug.Log("Not sending"); }
            }
            else if (heldModule == null && stop && currentState == KMGameInfo.State.Gameplay && arduinoConnection.isAbleToSend())
            {
                stop = false;
                arduinoConnection.Stop();
                currentValues = new List <int>()
                {
                    0, 0, 0
                };
                previousValues = new List <int>()
                {
                    0, 0, 0
                };
            }
        }
        currentValues = new List <int>()
        {
            0, 0, 0
        };
        previousValues = new List <int>()
        {
            0, 0, 0
        };
        yield break;
    }