Exemplo n.º 1
0
    // Use this for initialization
    public void spawnItems()
    {
        associations = FindObjectOfType <CandidateAssociations>();
        townSquare   = (Locations.Location)associations.locations[1];
        for (int i = 0; i < npcIsUsed.Length; i++)
        {
            npcIsUsed[i] = false;
        }

        // generating objects for candidate A
        itemsA     = associations.itemNamesA;
        candidateA = associations.CandidateAName;
        houseA     = associations.houseA;
        foreach (Vector3 location in houseA.itemSpawnLocations)
        {
            isPlacedA.Add(false);
        }
        npcNameA = candidateA + "_NPC";

        // generating objects for candidate B
        itemsB     = associations.itemNamesB;
        candidateB = associations.CandidateBName;
        houseB     = associations.houseB;
        foreach (Vector3 location in houseB.itemSpawnLocations)
        {
            isPlacedB.Add(false);
        }
        npcNameB = candidateB + "_NPC";

        foreach (Vector3 location in townSquare.itemSpawnLocations)
        {
            isPlacedInTown.Add(false);
        }

        System.Random rnd = new System.Random();

        // randomly placing clue items for candidate A
        for (int i = 0; i < itemsA.Count; i++)
        {
            bool   hasPlaced = false;
            string itemName  = candidateA + "_" + itemsA [i];
            Debug.Log("Going to instantiate: " + itemName);
            GameObject currentObject = GameObject.Find(itemName);

            while (!hasPlaced)
            {
                int place = rnd.Next(houseA.itemSpawnLocations.Length);
                if (!isPlacedA[place])
                {
                    currentObject.transform.position = houseA.itemSpawnLocations[place];
                    isPlacedA[place] = true;
                    hasPlaced        = true;
                }
            }
        }

        // randomly placing clue items for candidate B
        for (int i = 0; i < itemsB.Count; i++)
        {
            bool   hasPlaced = false;
            string itemName  = candidateB + "_" + itemsB [i];
            Debug.Log("Going to instantiate: " + itemName);
            GameObject currentObject = GameObject.Find(itemName);

            while (!hasPlaced)
            {
                int place = rnd.Next(houseB.itemSpawnLocations.Length);
                if (!isPlacedB[place])
                {
                    currentObject.transform.position = houseB.itemSpawnLocations[place];
                    isPlacedB[place] = true;
                    hasPlaced        = true;
                }
            }
        }

        // spawning NPC for candidate A
        GameObject currentNPC = Instantiate(Resources.Load("NPC/" + npcNameA)) as GameObject;

        while (!placedNPC)
        {
            npcSpawnPoint = rnd.Next(townSquare.itemSpawnLocations.Length);
            if (!isPlacedInTown[npcSpawnPoint])
            {
                currentNPC.transform.position = townSquare.itemSpawnLocations[npcSpawnPoint];
                isPlacedInTown[npcSpawnPoint] = true;
                placedNPC = true;
            }
        }

        // spawning NPC for candidate B
        currentNPC = Instantiate(Resources.Load("NPC/" + npcNameB)) as GameObject;
        placedNPC  = false;

        while (!placedNPC)
        {
            npcSpawnPoint = rnd.Next(townSquare.itemSpawnLocations.Length);
            if (!isPlacedInTown[npcSpawnPoint])
            {
                currentNPC.transform.position = townSquare.itemSpawnLocations[npcSpawnPoint];
                isPlacedInTown[npcSpawnPoint] = true;
                placedNPC = true;
            }
        }

        // spawning non-interactable NPCs
        for (int i = 0; i < 4; i++)
        {
            placedNPC = false;
            npcToUse  = Random.Range(1, 17);

            while (npcIsUsed[npcToUse - 1])
            {
                npcToUse = Random.Range(1, 17);
            }

            Debug.Log("Trying to instantiate npc" + npcToUse);
            currentNPC = Instantiate(Resources.Load("NPC/npc" + npcToUse)) as GameObject;

            while (!placedNPC)
            {
                npcSpawnPoint = rnd.Next(townSquare.itemSpawnLocations.Length);
                if (!isPlacedInTown[npcSpawnPoint])
                {
                    currentNPC.transform.position = townSquare.itemSpawnLocations[npcSpawnPoint];
                    isPlacedInTown[npcSpawnPoint] = true;
                    placedNPC = true;
                    npcIsUsed[npcToUse - 1] = true;
                }
            }
        }
    }
Exemplo n.º 2
0
    void Start()
    {
        ic = CandidateContainer.Load(path);

        while (true)
        {
            randCandidateA = findValidCandidate("A");
            if (randCandidateA != -1)
            {
                availableCandidates[randCandidateA] = -1;
                randAMoral = ic.candidates[randCandidateA].moral;
                break;
            }
        }
        while (true)
        {
            randCandidateB = findValidCandidate("B");
            if (randCandidateB != -1)
            {
                availableCandidates[randCandidateB] = -1;
                break;
            }
        }

        GameObject player = GameObject.Find("Player");

        CandidateAssociations cAssociations = FindObjectOfType <CandidateAssociations>();

        Vector3[] townSpawn = { new Vector3(-105.9f, -220.2f, 0), new Vector3(-109, -194.4f, 0), new Vector3(-102.8f, -162.2f, 0), new Vector3(-90, -194, 0), new Vector3(-77.2f, -210, 0), new Vector3(-70.6f, -191, 0), new Vector3(-61.5f, -200.5f, 0), new Vector3(-48.2f, -162, 0), new Vector3(-32, -213, 0), new Vector3(-23, -181.2f, 0), new Vector3(-19.7f, -162.4f, 0) };
        cAssociations.locations.Add(new Locations.Location(new Vector3(-48, -220, 0), "Town Square", townSpawn));

        foreach (CandidateXML candidate in ic.candidates)
        {
            if (candidate.id.Equals(randCandidateA.ToString()))
            {
                candidateA = transform.Find("First Candidate Profile");

                try {
                    candidateAController           = candidateA.GetComponent <CandidateAController>();
                    candidateAController.sprite    = sprites[randCandidateA];
                    candidateAController.fullname  = candidate.fullname;
                    cAssociations.CandidateAName   = candidate.fullname.Split(' ')[0];
                    candidateAController.moral     = candidate.moral;
                    candidateAController.goodArray = candidate.goodArray;
                    candidateAController.badArray  = candidate.badArray;
                    candidateAController.houseSize = candidate.houseSize;
                    Locations locations = player.GetComponent <Locations>();
                    for (int i = 0; i < locations.locations.Count; i++)
                    {
                        Locations.Location loco = (Locations.Location)locations.locations[i];
                        if (candidateAController.houseSize.Equals(loco.size))
                        {
                            cAssociations.houseA = loco;
                            cAssociations.locations.Add(loco);
                            locations.locations.RemoveAt(i);
                            break;
                        }
                    }
                    cAssociations.npcNameA = candidate.npcName;
                    cAssociations.itemNamesA.Add(candidate.itemName1);
                    cAssociations.itemNamesA.Add(candidate.itemName2);
                    candidateAController.birthdate   = candidate.birthdate;
                    candidateAController.ethnicity   = candidate.ethnicity;
                    candidateAController.occupation  = candidate.occupation;
                    candidateAController.skills      = candidate.skills;
                    candidateAController.description = candidate.description;
                    candidateAController.traits      = candidate.traits;
                } catch (NullReferenceException) {
                    print("stupid exception");
                }
            }
            else if (candidate.id.Equals(randCandidateB.ToString()))
            {
                candidateB = transform.Find("Second Candidate Profile");

                try {
                    candidateBController           = candidateB.GetComponent <CandidateBController>();
                    candidateBController.sprite    = sprites[randCandidateB];
                    candidateBController.fullname  = candidate.fullname;
                    cAssociations.CandidateBName   = candidate.fullname.Split(' ')[0];
                    candidateBController.moral     = candidate.moral;
                    candidateBController.goodArray = candidate.goodArray;
                    candidateBController.badArray  = candidate.badArray;
                    candidateBController.houseSize = candidate.houseSize;
                    Locations locations = player.GetComponent <Locations>();
                    for (int i = 0; i < locations.locations.Count; i++)
                    {
                        Locations.Location loco = (Locations.Location)locations.locations[i];
                        if (candidateBController.houseSize.Equals(loco.size))
                        {
                            cAssociations.houseB = loco;
                            cAssociations.locations.Add(loco);
                            locations.locations.RemoveAt(i);
                            break;
                        }
                    }
                    cAssociations.npcNameB = candidate.npcName;
                    cAssociations.itemNamesB.Add(candidate.itemName1);
                    cAssociations.itemNamesB.Add(candidate.itemName2);
                    candidateBController.birthdate   = candidate.birthdate;
                    candidateBController.ethnicity   = candidate.ethnicity;
                    candidateBController.occupation  = candidate.occupation;
                    candidateBController.skills      = candidate.skills;
                    candidateBController.description = candidate.description;
                    candidateBController.traits      = candidate.traits;
                } catch (NullReferenceException) {
                    print("stupid exception");
                }
            }
        }

        FindObjectOfType <ObjectSpawning>().spawnItems();
    }
Exemplo n.º 3
0
    void OpenTheGui()
    {
        player.DisableMovement();
        interactor.interacting = true;
        if (!isGenerated)
        {
            //Create the menu from stored locations
            CandidateAssociations cAssociations = FindObjectOfType <CandidateAssociations>();
            for (int i = 0; i < cAssociations.locations.Count; i++)
            {
                Locations.Location loco = (Locations.Location)cAssociations.locations[0];
                // To instantiate
                GameObject newButton = (GameObject)Instantiate(buttonPrefab);
                newButton.transform.SetParent(Content.transform, false);
                newButton.transform.localScale = new Vector3(1, 1, 1);
                if (i == 0)
                {
                    if (isNotRegen)
                    {
                        newButton.name = "Office";
                        newButton.GetComponentInChildren <Text>().text = "Office";
                        isNotRegen = false;
                    }
                    else
                    {
                        GameObject.Destroy(newButton);
                    }
                }

                else if (i == 1)
                {
                    newButton.name = "Town Square";
                    newButton.GetComponentInChildren <Text>().text = "Town Square";
                    loco = (Locations.Location)cAssociations.locations[1];
                }

                else if (i == 2)
                {
                    newButton.name = cAssociations.CandidateAName;
                    newButton.GetComponentInChildren <Text>().text = cAssociations.CandidateAName + "'s House";
                    loco = cAssociations.houseA;
                }
                else
                {
                    newButton.name = cAssociations.CandidateBName;
                    newButton.GetComponentInChildren <Text>().text = cAssociations.CandidateBName + "'s House";
                    loco = cAssociations.houseB;
                }
                Button thisButton = newButton.GetComponent <Button>();

                Vector3 capturedLocation = loco.entrance;
                thisButton.onClick.AddListener(() => {
                    StartCoroutine(WarpTo(capturedLocation, thisButton.GetComponentInChildren <Text>().text));
                    WarpUI.SetActive(false);
                    player.EnableMovement();
                    interactor.interacting = false;
                });
            }
            other.GetComponent <Locations>().isGenerated = true;
        }

        // Open up the GUI
        WarpUI.SetActive(true);
    }