Exemplo n.º 1
0
        private void SpawnHeroes(Level level)
        {
            int         playerCounter = 1;
            List <Team> teamList      = GameManager.GetInstance().GetAllTeams();
            int         startSection  = GameManager.GetInstance().SectionNo - 1;

            for (int i = 0; i < teamList.Count; i++)
            {
                if (teamList[i].TeamNo == 666)
                {
                    continue;
                }

                // Team newTeam = new Team(i+1);
                List <Hero> heroList = teamList[i].GetHeroTeamMembers();

                for (int j = 0; j < heroList.Count; j++)
                {
                    Hero h = heroList[j];
                    h          = ((GameObject)Instantiate(h.gameObject)).GetComponent <Hero>();
                    h.PlayerNo = playerCounter;
                    playerCounter++;
                    h.Type        = heroList[j].Type;
                    h.DisplayName = heroList[j].DisplayName;
                    h.name        = "Hero" + h.PlayerNo;

                    if (level.Sections[startSection] != null)
                    {
                        // spawn on generated level
                        Debug.Log("Spawn: " + h.name);
                        level.Sections[startSection].RespawnCharacter(h);
                        Debug.Log("Hero is spawned in Section " + startSection + 1);
                    }
                    else
                    {
                        // spawn on fix points like on multiplayermaps
                        if (transform.parent.transform.Find("Spawn Player" + (playerCounter - 1)) == null)
                        {
                            Debug.Log("no spawningpoint found for player " + (playerCounter - 1));
                        }
                        else
                        {
                            h.transform.position = transform.parent.transform.Find("Spawn Player" + ((playerCounter - 1) + (4 * i))).transform.position;
                        }
                    }

                    teamList[i].RemoveMember(heroList[j]);
                    teamList[i].AddMember(h);
                }
            }

            if (level != null)
            {
                for (int k = 0; k < GameManager.GetInstance().HeroCount; k++)
                {
                    Debug.Log("[CharacterSelection.cs] Add AI hero");
                    Hero choosenCharacter = ((GameObject)Instantiate(Datasheet.Heroes()[Random.Range(0, 2)])).GetComponent <Hero>();
                    choosenCharacter.name = "Hero" + playerCounter + "KI";
                    playerCounter++;
                    choosenCharacter.Type = Hero.Types.AI;

                    Debug.Log("Spawn AI: " + choosenCharacter.name);
                    level.Sections[startSection].RespawnCharacter(choosenCharacter);

                    if (GameManager.GetInstance().TeamCount == 1)
                    {
                        teamList[0].AddMember(choosenCharacter);
                    }
                }
            }
        }