示例#1
0
    public IEnumerator stringWriter(Func <string> bases, Action <string> modify, Modifier modifier = Modifier.Remove)
    {
        _input = false;
        if (modifier == Modifier.Remove)
        {
            while (bases().Length > 0)
            {
                LoopingList <string> cList = getBaseList(bases);
                cList.RemoveAt(cList.Count - 1);
                modify(String.Join("", cList.ToArray()));
                yield return(new WaitForSeconds(WaitTime));
            }
            _input = true;
            yield break;
        }
        LoopingList <string> chList = getBaseList(bases);
        List <string>        final  = new List <string>();

        while (chList.Count > 0)
        {
            final.Add(chList[0]);
            chList.RemoveAt(0);
            modify(String.Join("", final.ToArray()));
            yield return(new WaitForSeconds(WaitTime));
        }
        _input = true;
    }
示例#2
0
 public void registerAns(string answer)
 {
     Logger(String.Format("Submitted answer: {0}, expected answer: {1}", answer, solvePair.Second));
     if (answer == solvePair.Second)
     {
         Logger("That's correct!");
         if (stage == 1)
         {
             Logger("Module solved!");
             GetComponent <KMBombModule>().HandlePass();
             _solved   = true;
             index     = 0;
             answerSet = new LoopingList <string>()
             {
                 "GG!"
             };
             StartCoroutine(newText("Module solved :D"));
             return;
         }
         newStage();
     }
     else
     {
         Logger("That's incorrect! Strike!");
         GetComponent <KMBombModule>().HandleStrike();
         stage = 0;
         newStage();
     }
     return;
 }
示例#3
0
    IEnumerator Starter()
    {
        moduleID = ++moduleIDCounter;
        Service  = FindObjectOfType <questionerService>();
        //Debug.Log("Setting dict");
        togglableObjects = new Dictionary <string, GameObject>()
        {
            /*{ "LetteredButtons", findFromRoot("LetteredButtons")},
             * { "BooleanButtons", findFromRoot("BooleanButtons")},*/
            { "Error", findFromRoot("Error") }
        };
        //Debug.Log("Setting to true");
        ableToSet = true;
        foreach (KeyValuePair <string, GameObject> kPair in togglableObjects)
        {
            kPair.Value.SetActive(false);
        }

        /*if (Service == null)
         * {
         *  Logger("Couldn't find service. Activating error screen...");
         *  grantSolve = true;
         *  toggleObject("Error", true);
         *  yield break;
         * }*/
        findFromRoot("Error").SetActive(false);
        Logger("Waiting for service to finish...");
        yield return(new WaitUntil(() => questionerService._done && displayText != null && inputText != null));

        Logger("Service finished, generating question...");
        foreach (string l in questionerService.toLog)
        {
            Logger(l);
        }
        redMat  = findFromRoot("RedOBJ").GetComponent <Renderer>().material;
        statusC = findFromRoot("Display").transform.Find("Sphere").gameObject;
        if (TwitchPlaysActive)
        {
            State     = ModuleState.TwitchCheck;
            answerSet = new LoopingList <string>()
            {
                ""
            };
            StartCoroutine(newText("Please press enter\non the module!"));
            yield return(new WaitUntil(() => State == ModuleState.Main));
        }
        if (!questionerService.webQuestions && API == null)
        {
            statusC.GetComponent <Renderer>().material = redMat;
            findFromRoot("colorblindText").GetComponent <TextMesh>().text = "R";
            finalQuestions = neitherQuestions.ToArray();
        }
        else if (!questionerService.webQuestions && API != null)
        {
            statusC.GetComponent <Renderer>().material = redMat;
            findFromRoot("colorblindText").GetComponent <TextMesh>().text = "R";
            finalQuestions = selectorQuestions.ToArray().Concat(neitherQuestions).ToArray();
        }
        else if (questionerService.webQuestions && API == null)
        {
            finalQuestions = webQuestions.ToArray().Concat(neitherQuestions).ToArray();
        }
        else
        {
            finalQuestions = webQuestions.ToArray().Concat(selectorQuestions).Concat(neitherQuestions).Concat(bothQuestions).ToArray();
        }
        if (RestrictQuestions)
        {
            finalQuestions = finalQuestions.Where(x => !selectorQuestions.Contains(x) && !bothQuestions.Contains(x)).ToArray();
        }
        sortModules();
        newStage();
        StartCoroutine(Blinker());
        if (API != null)
        {
            Logger(String.Format("Light is {0}, Selector modules ordered by their {1}s: {2}", questionerService.webQuestions ? "green" : "red", questionerService.webQuestions ? "sort key" : "ID", String.Join(", ", getSelectorModules().ToArray())));
        }
        _colorblind = GetComponent <KMColorblindMode>().ColorblindModeActive;
    }
示例#4
0
    private Tuple <string, string> getSolvePair(string[] set) //First: question, Second: answer
    {
        int index = -1;

        do
        {
            index = RNG.Range(0, set.Length);
        } while (dependsOnDisableds.Contains(finalQuestions[index]) && MSDisabledModules.Count == 0);
        int    repoIndex     = RNG.Range(1, fetchedModules.Count + 1);
        int    selectorIndex = RNG.Range(1, MSModules.Count + 1);
        int    disabledIndex = RNG.Range(1, MSDisabledModules.Count + 1);
        int    enabledIndex  = RNG.Range(1, MSEnabledModules.Count + 1);
        string sortType      = orderTypes[RNG.Range(0, orderTypes.Length)];
        //Debug.LogFormat("[Questioner module #{0}] Sort type is {1}.", moduleID, sortType);
        string rndModule = API != null?getModuleNameByID(MSModules[RNG.Range(0, MSModules.Count)]) : "";

        var bombSort = GetComponent <KMBombInfo>().GetModuleNames().ToList();

        bombSort.Sort();
        int    bombIndex    = RNG.Range(1, bombSort.Count + 1);
        string activeModule = "";

        switch (set[index])
        {
        case "Is the {1} module loaded in game (A-Z) the same module as the {1} module on the repo sorted by {2}?":
            activeModule = getModuleNameByID(MSModules[selectorIndex - 1]);
            break;

        case "Is the {0} module on the repo sorted by {2} loaded in the game?":
        case "What is the {3} letter/digit of the module that is the {0} on the repo sorted by {2}?":
            activeModule = sortedModules[sortType][repoIndex - 1].Name;
            break;

        case "What is the {3} letter/digit of the module that is the {5} one on a list of all disabled modules sorted by {2} on the repo?":
            //Debug.LogFormat("[Questioner module #{0}] Trying to get index {1} of {2}", moduleID, disabledIndex - 1, getSortageByProperty(sortType, MSDisabledModules).Count);
            activeModule = getModuleNameByID(getSortageByProperty(sortType, MSDisabledModules)[disabledIndex - 1]);
            break;

        case "What is the {3} letter/digit of the module that is the {6} one on a list of all enabled modules sorted by {2} on the repo?":
            //Debug.LogFormat("[Questioner module #{0}] Trying to get index {1} of {2}", moduleID, enabledIndex - 1, getSortageByProperty(sortType, MSEnabledModules).Count);
            activeModule = getModuleNameByID(getSortageByProperty(sortType, MSEnabledModules)[enabledIndex - 1]);
            break;

        case "What is the {3} letter/digit of the module that is loaded {1} in game?":
            activeModule = getModuleNameByID(MSModules[selectorIndex - 1]);
            break;

        case "Is {4} disabled by an enabled profile?":
            activeModule = getModuleNameByID(rndModule);
            break;

        case "What is the {3} letter/digit of the module that is the {5} one on a list of all disabled modules? (A-Z)":
            activeModule = getModuleNameByID(MSDisabledModules[disabledIndex - 1]);
            break;

        case "What is the {3} letter/digit of the module that is the {6} one on a list of all enabled modules? (A-Z)":
            activeModule = getModuleNameByID(MSEnabledModules[enabledIndex - 1]);
            break;

        case "What is the {3} letter/digit of the module that is {7} on the bomb sorted A-Z?":
            activeModule = bombSort[bombIndex - 1];
            break;

        case "What is the {3} letter/digit of the module that is {7} on the bomb sorted Z-A?":
            bombSort.Reverse();
            activeModule = bombSort[bombIndex - 1];
            break;
        }
        var newActive = modifyName(activeModule);

        int letterIndex = RNG.Range(1, newActive.Length + 1);

        string Letter = newActive[letterIndex - 1].ToString().ToUpperInvariant();

        string finalRepoIndex     = getStringByNum(repoIndex);
        string finalSelectorIndex = getStringByNum(selectorIndex);
        string finalDisabledIndex = getStringByNum(disabledIndex);
        string finalEnabledIndex  = getStringByNum(enabledIndex);
        string finalLetterIndex   = getStringByNum(letterIndex);

        string Answer = "";

        switch (set[index])
        {
        case "Is the {0} module on the repo sorted by {2} loaded in the game?":
            Answer = MSModules.Contains(getModuleIDByName(activeModule)) ? "YES" : "NO";
            //toggleObject("BooleanButtons");
            answerSet = new LoopingList <string>(boolAns);
            break;

        case "Is the {1} module loaded in game (A-Z) the same module as the {1} module on the repo sorted by {2}?":
            Answer = fetchedModules[repoIndex - 1].Name == activeModule ? "YES" : "NO";
            //toggleObject("BooleanButtons");
            answerSet = new LoopingList <string>(boolAns);
            break;

        case "What is the {3} letter/digit of the module that is the {0} on the repo sorted by {2}?":
        case "What is the {3} letter/digit of the module that is the {5} one on a list of all disabled modules sorted by {2} on the repo?":
        case "What is the {3} letter/digit of the module that is the {6} one on a list of all enabled modules sorted by {2} on the repo?":
        case "What is the {3} letter/digit of the module that is loaded {1} in game?":
        case "What is the {3} letter/digit of the module that is the {5} one on a list of all disabled modules? (A-Z)":
        case "What is the {3} letter/digit of the module that is the {6} one on a list of all enabled modules? (A-Z)":
        case "What is the {3} letter/digit of the module that is {7} on the bomb sorted A-Z?":
        case "What is the {3} letter/digit of the module that is {7} on the bomb sorted Z-A?":
            Answer = Letter;
            //toggleObject("LetteredButtons");
            answerSet = new LoopingList <string>(letterAns);
            break;

        case "Is {4} disabled by an enabled profile?":
            Answer = MSDisabledModules.Contains(getModuleIDByName(activeModule)) ? "YES" : "NO";
            //toggleObject("BooleanButtons");
            answerSet = new LoopingList <string>(boolAns);
            break;
        }
        Logger(String.Format("Active module: {0}", activeModule));
        return(new Tuple <string, string>(String.Format(set[index], finalRepoIndex, finalSelectorIndex, sortType, finalLetterIndex, getModuleNameByID(rndModule), finalDisabledIndex, finalEnabledIndex, getStringByNum(bombIndex)), Answer));
    }
示例#5
0
        /// <summary>
        /// This method generates move commands ehich try to get from a given point to another whilst staying on the outline
        /// of an island
        /// </summary>s
        /// <param name="p1">The starting point</param>
        /// <param name="p2">The ending point</param>
        /// <param name="zPos">The z position of the layer</param>
        /// <param name="outlineLines">The outline linesegments of the island</param>
        private static void generateMovesBetweenPoints(IntPoint p1, IntPoint p2, long zPos, List <List <LineSegment> > outlineLines, int moveSpeed, ref Queue <MoveSegment> moveQueue)
        {
            //TODO: sometimes it appears as if though when there are two points on the smae line a move if first genertated from p1 to the end (or start) of the
            //line and then back, there sould instead be a direct move from p1 to p2

            //If the two points are already equal then a move between them is not neccesary
            if (p1.Equals(p2))
            {
                return;
            }

            /*//If we are in plotting mode then we only need to lift up the pen and create a direct move
             * if (Global.Values.materialType == MaterialType.Pen)
             * {
             *  //Retract / lift up the pen
             *  Global.Values.MoveSegmentList.Add(new MoveSegment());
             *
             *  //Make a direct move
             *  var vec1 = new Vector3(p1.X, p1.Y, zPos + 1);
             *  var vec2 = new Vector3(p2.X, p2.Y, zPos + 1);
             *  Global.Values.MoveSegmentList.Add(new MoveSegment(vec1, vec2, moveSpeed));
             *
             *  //Move the pen down again
             *  vec1 = new Vector3(p2.X, p2.Y, zPos + 1);
             *  vec2 = new Vector3(p2.X, p2.Y, zPos);
             *  Global.Values.MoveSegmentList.Add(new MoveSegment(vec1, vec2, moveSpeed));
             *
             *  return;
             * }*/


            //If there are no outline linesegments then we need to generate a direct move
            if (outlineLines.Count < 1)
            {
                var vec1 = new Vector3(p1.X, p1.Y, zPos + 1); //);
                var vec2 = new Vector3(p2.X, p2.Y, zPos + 1); //);
                moveQueue.Enqueue(new MoveSegment(vec1, vec2, moveSpeed));
                return;
            }

            //First find out which point on which polygon is closest to the first point
            List <LineSegment> closestOutline = new List <LineSegment>();
            IntPoint           closestPoint   = new IntPoint();
            LineSegment        closestLine    = new LineSegment(new IntPoint(), new IntPoint());
            double             closesDistance = double.MaxValue;

            foreach (List <LineSegment> lines in outlineLines)
            {
                foreach (LineSegment line in lines)
                {
                    IntPoint newPoint;
                    var      distance = distanceToLine(line, p1, out newPoint);

                    if (distance < closesDistance)
                    {
                        closesDistance = distance;
                        closestPoint   = newPoint;
                        closestOutline = lines;
                        closestLine    = line;
                    }
                }
            }

            //We now need to create a move from the first point to the closest point on the polygon
            var v1 = new Vector3(p1.X, p1.Y, zPos);
            var v2 = new Vector3(closestPoint.X, closestPoint.Y, zPos);

            moveQueue.Enqueue(new MoveSegment(v1, v2, moveSpeed));

            //Next we need to determine which point point on the above determined polygon is closest to the second
            IntPoint    closestPoint2 = new IntPoint();
            LineSegment closestLine2  = new LineSegment(new IntPoint(), new IntPoint());

            closesDistance = double.MaxValue;

            foreach (LineSegment line in closestOutline)
            {
                IntPoint newPoint;
                var      distance = distanceToLine(line, p2, out newPoint);

                if (distance < closesDistance)
                {
                    closesDistance = distance;
                    closestPoint2  = newPoint;
                    closestLine2   = line;
                }
            }

            //Create an endless looping warpper for the list
            LoopingList <LineSegment> loopingList = new LoopingList <LineSegment>(ref closestOutline);

            //We now need to determine the index of the two lines
            int lineIndex = closestOutline.IndexOf(closestLine);
            int lineIndex2;// = closestOutline.IndexOf(closestLine2);

            //We now need to add move segments for each line on the outline between the two closest points

            //A while ago we moved to closestPoint so it is now our last point
            IntPoint lastPoint = closestPoint;

            //For each line between the two points we have to move from the last point to the second point on the list
            int indexDiff = loopingList.distanceBetweenElements(closestLine, closestLine2, out lineIndex2); //lineIndex2 - lineIndex;

            if (indexDiff > 0)
            {
                for (int i = lineIndex; i < lineIndex2; i++)
                {
                    v1 = new Vector3(lastPoint.X, lastPoint.Y, zPos);
                    var point2 = loopingList.elementAtIndex(i).Point2;
                    v2 = new Vector3(point2.X, point2.Y, zPos);
                    moveQueue.Enqueue(new MoveSegment(v1, v2, moveSpeed));
                    lastPoint = point2;//closestOutline[i].Point2;
                }
            }
            else if (indexDiff < 0)
            {
                for (int i = lineIndex; i > lineIndex2; i--)
                {
                    v1 = new Vector3(lastPoint.X, lastPoint.Y, zPos);
                    var point1 = loopingList.elementAtIndex(i).Point1;
                    //v2 = new Vector3(closestOutline[i].Point1.X, closestOutline[i].Point1.Y, zPos);
                    v2 = new Vector3(point1.X, point1.Y, zPos);
                    moveQueue.Enqueue(new MoveSegment(v1, v2, moveSpeed));
                    //Global.Values.MoveSegmentList.Add(new MoveSegment(v1, v2, moveSpeed));
                    lastPoint = point1;//closestOutline[i].Point1;
                }
            }

            //Next we have to move from the last point to the closest point 2
            v1 = new Vector3(lastPoint.X, lastPoint.Y, zPos);
            v2 = new Vector3(closestPoint2.X, closestPoint2.Y, zPos);
            moveQueue.Enqueue(new MoveSegment(v1, v2, moveSpeed));

            //We then finally have to move from the last point 2 to the closest point 2
            v1 = new Vector3(closestPoint2.X, closestPoint2.Y, zPos);
            v2 = new Vector3(p2.X, p2.Y, zPos);
            moveQueue.Enqueue(new MoveSegment(v1, v2, moveSpeed));
        }