Beispiel #1
0
    private void OnActivate()
    {
        HashSet <int>        securityProtocols;
        HashSet <Vector2Int> answerExample;

        SusadminData.Generate(out securityProtocols, out vulnerability, out safetyLevel, out compatibilityIndices, out virusesPower, out answerExample);
        this.securityProtocols = securityProtocols.ToArray().Shuffle().ToList();
        string installedSecurityProtocolNames = this.securityProtocols.Select(id => SusadminData.GetSecurityProtocolName(id)).Join(", ");

        Debug.LogFormat("[SUSadmin #{0}] Installed security protocols: {1}", moduleId, installedSecurityProtocolNames);
        Debug.LogFormat("[SUSadmin #{0}] Possible viruses:", moduleId);
        foreach (Vector2Int id in SusadminData.GetPossibleVirusesId(securityProtocols))
        {
            Debug.LogFormat("[SUSadmin #{0}] \t{1}: ci:{2}; p:{3}", moduleId, SusadminData.GetVirusName(id), compatibilityIndices[id.x][id.y], virusesPower[id.x][id.y]);
        }
        Debug.LogFormat("[SUSadmin #{0}] Vulnerability: {1}", moduleId, vulnerability);
        Debug.LogFormat("[SUSadmin #{0}] Safety level: {1}", moduleId, safetyLevel);
        Debug.LogFormat("[SUSadmin #{0}] Answer example: {1}", moduleId, answerExample.Select(id => SusadminData.GetVirusName(id)).Join(", "));
        startingTimeInMinutes = Mathf.FloorToInt(Bomb.GetTime() / 60f);
        osVersion             = GetOSVersion(vulnerability);
        if (osVersion < 0 || (osVersion == 0 && Random.Range(0, 2) == 0))
        {
            osIsBoom   = true;
            osVersion *= -1;
        }
        Debug.LogFormat("[SUSadmin #{0}] OS version: {1} v{2}", moduleId, osIsBoom ? "BoomOS" : "BombOS", osVersion);
        Selectable.OnFocus   += () => selected = true;
        Selectable.OnDefocus += () => selected = false;
        watchingCoroutine     = StartCoroutine(Watch());
        readyToWrite          = true;
        UpdateConsole();
    }
Beispiel #2
0
    private IEnumerator ProcessCommand()
    {
        Action EndCommandProcessing = () => {
            this.command     = "";
            shouldUpdateText = true;
            readyToWrite     = true;
        };
        string command = this.command.ToLower().Trim();

        if (command == "")
        {
            EndCommandProcessing();
            yield break;
        }
        if (Regex.IsMatch(command, "^status( |$)"))
        {
            if (command.Split(' ').Where(s => s != "").Count() > 1)
            {
                WriteLine(PrintError("ERROR") + ": invalid arguments count");
            }
            else
            {
                WriteLine(PrintOSVersion());
                WriteLine("Installed security protocols:");
                foreach (int sp in securityProtocols)
                {
                    WriteLine("    " + PrintSecurityProtocolName(sp));
                }
                WriteLine("Safety Level: " + (safetyLevelIsPublic ? PrintNumber(safetyLevel.ToString()) : PrintError("UNKNOWN")));
                if (installedViruses.Count > 0)
                {
                    WriteLine("Installed viruses:");
                    int           i    = 0;
                    List <string> line = new List <string>();
                    foreach (Vector2Int virusId in installedViruses)
                    {
                        if (i++ % 4 == 0 && i != 1)
                        {
                            WriteLine(PrintError("  " + line.Join("   ")));
                            line.Clear();
                        }
                        line.Add(SusadminData.GetVirusName(virusId));
                    }
                    WriteLine(PrintError("  " + line.Join("   ")));
                }
            }
            EndCommandProcessing();
            yield break;
        }
        if (Regex.IsMatch(command, "^info( |$)"))
        {
            string[] args = command.Split(' ').Skip(1).Where(s => s != "").ToArray();
            if (args.Length == 0)
            {
                WriteLine(PrintError("ERROR") + ": invalid arguments count");
                EndCommandProcessing();
                yield break;
            }
            foreach (string virusName in args)
            {
                if (!SusadminData.VirusNameExists(virusName))
                {
                    WriteLine(PrintError("ERROR") + ": virus not found");
                    break;
                }
                Vector2Int id = SusadminData.GetVirusId(virusName);
                WriteLine(string.Format(" {0}: ci={1}; p={2}", virusName.ToUpper(), compatibilityIndices[id.x][id.y], virusesPower[id.x][id.y]));
            }
            EndCommandProcessing();
            yield break;
        }
        if (Regex.IsMatch(command, @"^(install|add)( |$)"))
        {
            string[] args = command.Split(' ').Where(s => s != "").Skip(1).ToArray();
            if (args.Length == 0)
            {
                WriteLine(PrintError("ERROR") + ": invalid arguments count");
            }
            else
            {
                yield return(Loader("Installing", 4 * args.Length));

                InstallViruses(args);
                WriteLine("Installed");
            }
            EndCommandProcessing();
            yield break;
        }
        if (Regex.IsMatch(command, @"^(delete|del|remove|rm)( | $)"))
        {
            string[] args = command.Split(' ').Where(s => s != "").Skip(1).ToArray();
            if (args.Length == 0)
            {
                WriteLine(PrintError("ERROR") + ": invalid arguments count");
            }
            else
            {
                yield return(Loader("Deletion", 4 * args.Length));

                DeleteViruses(args);
                WriteLine("Deleted");
            }
            EndCommandProcessing();
            yield break;
        }
        if (Regex.IsMatch(command, @"^clear( |$)"))
        {
            if (command.Split(' ').Where(s => s != "").Count() > 1)
            {
                WriteLine(PrintError("ERROR") + ": invalid arguments count");
            }
            else
            {
                yield return(Loader("Deletion all viruses", 4 * installedViruses.Count));

                installedViruses = new List <Vector2Int>();
                Debug.LogFormat("[SUSadmin #{0}] All viruses deleted", moduleId);
                WriteLine("All viruses deleted");
            }
            EndCommandProcessing();
            yield break;
        }
        if (Regex.IsMatch(command, @"^activate( |$)"))
        {
            if (command.Split(' ').Where(s => s != "").Count() > 1)
            {
                WriteLine(PrintError("ERROR") + ": invalid arguments count");
                EndCommandProcessing();
                yield break;
            }
            if (installedViruses.Count == 0)
            {
                WriteLine(PrintError("ERROR") + ": no viruses to activate");
                EndCommandProcessing();
                yield break;
            }
            yield return(Loader("Activation", 4 * installedViruses.Count));

            HashSet <int> compatibilityIndices = new HashSet <int>(installedViruses.Select(id => this.compatibilityIndices[id.x][id.y]));
            HashSet <int> sp = new HashSet <int>(securityProtocols);
            int           minCompatibilityIndex = compatibilityIndices.Min();
            int           maxCompatibilityIndex = compatibilityIndices.Max();
            int           totalPower            = installedViruses.Select(id => virusesPower[id.x][id.y]).Sum();
            Debug.LogFormat("[SUSadmin #{0}] Submitted viruses: {1}", moduleId, InstalledVirusesName.Join(", "));
            Debug.LogFormat("[SUSadmin #{0}] Submitted total power: {1}", moduleId, totalPower);
            if (maxCompatibilityIndex - minCompatibilityIndex > vulnerability)
            {
                Debug.LogFormat("[SUSadmin #{0}] Viruses conflict. Min: {1}. Max: {2}", moduleId, minCompatibilityIndex, maxCompatibilityIndex);
                WriteLine(PrintError("ERROR" + ": Viruses conflict"));
                yield return(Loader(PrintError("STRIKE")));

                WriteLine("STRIKE");
                Module.HandleStrike();
            }
            else if (installedViruses.Any(id => !SusadminData.VirusIsInvisible(id, sp)))
            {
                string detectedVirusName = SusadminData.GetVirusName(installedViruses.First(id => !SusadminData.VirusIsInvisible(id, sp)));
                Debug.LogFormat("[SUSadmin #{0}] Virus detected: {1}", moduleId, detectedVirusName);
                WriteLine(string.Format("{0}: Virus {1} detected", PrintError("ERROR"), PrintError(detectedVirusName)));
                yield return(Loader(PrintError("STRIKE")));

                WriteLine("STRIKE");
                Module.HandleStrike();
            }
            else if (totalPower < safetyLevel)
            {
                Debug.LogFormat("[SUSadmin #{0}] Expected total power: {1}", moduleId, safetyLevel);
                WriteLine(string.Format("{0}: OS detected viruses", PrintError("ERROR")));
                WriteLine("OS safety level: " + PrintNumber(safetyLevel.ToString()));
                safetyLevelIsPublic = true;
                yield return(Loader(PrintError("STRIKE")));

                WriteLine("STRIKE");
                Module.HandleStrike();
            }
            else
            {
                forceSolved = false;
                Debug.LogFormat("[SUSadmin #{0}] Module solved", moduleId);
                WriteLine("Network damaged!");
                yield return(Loader("Solving module"));

                WriteLine("Module solved");
                linePointer = linePointer == 0 ? LINES_COUNT : linePointer - 1;
                solved      = true;
                Module.HandlePass();
                yield return(SelfDestruct());

                yield break;
            }
            EndCommandProcessing();
            yield break;
        }
        WriteLine(PrintError("ERROR") + ": Unknown command");
        EndCommandProcessing();
    }