<commit_before>﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;

public class InfectionMonitor : MonoBehaviour {

	// Use this for initialization
	void Start () {
		ActiveSubroutines.OnMalwareListChange += OnMalwareListChange;
		ScanAndPrint();
	}

    void OnDestroy()
    {
        ActiveSubroutines.OnMalwareListChange -= OnMalwareListChange;
    }

	private void OnMalwareListChange(IMalware dead)
	{
		if (ActiveSubroutines.MalwareList.Count == 0)
		{
			OnWin();
		}
		else
		{
			ScanAndPrint();
		}
	}

	private void ScanAndPrint()
	{
		Dictionary<string, Tuple<int, IMalware>> malwareTypes = new Dictionary<string, Tuple<int, IMalware>>();
		foreach(IMalware imal in ActiveSubroutines.MalwareList)
		{
			if (malwareTypes.ContainsKey(imal.GetType().Name))
			{
				Tuple<int, IMalware> thisRecord = malwareTypes[imal.GetType().Name];
				malwareTypes[imal.GetType().Name] = new Tuple<int, IMalware>(thisRecord.First + 1, thisRecord.Second);
			}
			else
			{
				malwareTypes.Add(imal.GetType().Name, new Tuple<int, IMalware>(1, imal));
			}
		}

		string output = StrategyConsole.LineStartString + "INFECTION SCAN :\r\n";
		foreach(Tuple<int, IMalware> rec in malwareTypes.Values)
		{
			output += StrategyConsole.LineStartString + rec.First.ToString()+" ";
			if (rec.First > 1)
			{
				output +=  rec.Second.DisplayNamePlural;
			}
			else
			{
				output +=  rec.Second.DisplayNameSingular;
			}
			output += "\r\n";
		}

		StrategyConsole.WriteLines(output);
	}

	private void OnWin()
	{
        if (!CyberspaceBattlefield.Current.Abdicate)
        {
		    StrategyConsole.WriteLines(StrategyConsole.LineStartString+"SYSTEM CLEAN!\r\n> Esc to return to menu");
		    if (NetworkMap.CurrentLocation != null)
			    NetworkMap.CurrentLocation.IsInfected = false;
        }
	}

}
<commit_msg>Infection status now given by AI<commit_after>﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;

public class InfectionMonitor : MonoBehaviour {

	// Use this for initialization
	void Start () {
		ActiveSubroutines.OnMalwareListChange += OnMalwareListChange;
		ScanAndPrint();
	}

    void OnDestroy()
    {
        ActiveSubroutines.OnMalwareListChange -= OnMalwareListChange;
    }

	private void OnMalwareListChange(IMalware dead)
	{
		if (ActiveSubroutines.MalwareList.Count == 0)
		{
			OnWin();
		}
		else
		{
			ScanAndPrint();
		}
	}

	private void ScanAndPrint()
    {
        Dictionary<string, Tuple<int, IMalware>> malwareTypes = new Dictionary<string, Tuple<int, IMalware>>();
        foreach (IMalware imal in ActiveSubroutines.MalwareList)
        {
            if (malwareTypes.ContainsKey(imal.GetType().Name))
            {
                Tuple<int, IMalware> thisRecord = malwareTypes[imal.GetType().Name];
                malwareTypes[imal.GetType().Name] = new Tuple<int, IMalware>(thisRecord.First + 1, thisRecord.Second);
            }
            else
            {
                malwareTypes.Add(imal.GetType().Name, new Tuple<int, IMalware>(1, imal));
            }
        }
        PrintToAI(malwareTypes);
        //PrintToConsole(malwareTypes);
    }

    private void PrintToAI(Dictionary<string, Tuple<int, IMalware>> malwareTypes)
    {
        string output = "Infection scan reveals: ";

        int count = 0;
        foreach (Tuple<int, IMalware> rec in malwareTypes.Values)
        {
            output += rec.First.ToString() + " ";
            if (rec.First > 1)
            {
                output += rec.Second.DisplayNamePlural;
            }
            else
            {
                output += rec.Second.DisplayNameSingular;
            }
            if (count < malwareTypes.Values.Count)
                output += ", ";
            count++;
        }
        recentOutput = output;

        //throttle to the last scan within some seconds
        if (printingToAI == null)
            printingToAI = StartCoroutine(PrintAfterDelay());
    }
    private Coroutine printingToAI;
    private string recentOutput;

    private IEnumerator PrintAfterDelay()
    {
        yield return new WaitForSeconds(1f);
        AIRenderer.Instance.Output(AIRenderer.RIState.Searching, recentOutput);
        printingToAI = null;
    }


    private void PrintToConsole(Dictionary<string, Tuple<int, IMalware>> malwareTypes)
    {
        string output = StrategyConsole.LineStartString + "INFECTION SCAN :\r\n";
        foreach (Tuple<int, IMalware> rec in malwareTypes.Values)
        {
            output += StrategyConsole.LineStartString + rec.First.ToString() + " ";
            if (rec.First > 1)
            {
                output += rec.Second.DisplayNamePlural;
            }
            else
            {
                output += rec.Second.DisplayNameSingular;
            }
            output += "\r\n";
        }

        StrategyConsole.WriteLines(output);
    }

    private void OnWin()
	{
        if (!CyberspaceBattlefield.Current.Abdicate)
        {
            AIRenderer.Instance.Output(AIRenderer.RIState.Talking, "SYSTEM CLEAN!\r\n> [Esc] to return to menu.");
		    //StrategyConsole.WriteLines(StrategyConsole.LineStartString+"SYSTEM CLEAN!\r\n> Esc to return to menu");
		    if (NetworkMap.CurrentLocation != null)
			    NetworkMap.CurrentLocation.IsInfected = false;
        }
	}

}

{'fraction_non_alphanumeric': 0.11011404000747803, 'fraction_numerical': 0.002056459151243223, 'mean_word_length': 2.515111695137976, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6718461', 'n_tokens_mistral': 1752, 'n_tokens_neox': 1596, 'n_words': 310}