Ejemplo n.º 1
0
    private void SpawnChildren()
    {
        List <GameObject> neighbors = new List <GameObject>();

        target.GetComponent <Node>().ChangeLevelOffset(-1);
        foreach (GameObject t in target.GetComponent <Node>().Neighbors())
        {
            if (DiseaseFactory.Targetable(t) && !manager.NodeVisited(t))
            {
                neighbors.Add(t);
            }
        }
        List <GameObject> newDiseases = new List <GameObject>();

        if (neighbors.Count > 0)
        {
            int numberToInfect = Random.Range(1, neighbors.Count);
            if (numberToInfect > value)
            {
                numberToInfect = value;
            }
            int newValue = (int)Mathf.Ceil((float)value / (float)numberToInfect);
            while (numberToInfect > 0)
            {
                if (neighbors.Count > 0)
                {
                    int        val      = Random.Range(0, neighbors.Count - 1);
                    GameObject infectee = neighbors[val];
                    neighbors.Remove(infectee);
                    GameObject newDisease = GameObject.Instantiate(diseasePrefab);
                    if (value - newValue <= 0)
                    {
                        newValue = value;
                    }
                    newDisease.GetComponent <Disease>().SetTarget(manager, infectee, newValue);
                    newDiseases.Add(newDisease);
                    value -= newValue;
                    --numberToInfect;
                }
            }
        }
        manager.AddChildDiseases(gameObject, newDiseases);
    }