Exemple #1
0
    public void StartLevel(TeamRoster selectedRoster)
    {
        // This oddly named object points to all sorts of useful things that exist in all levels
        instance = FindObjectOfType <PlayerRig>();

        if (instance == null)
        {
            instance = Instantiate <PlayerRig>(Core.theCore.playerRigPrefab);
            instance.transform.position = Vector3.zero;
        }

        GameObject sunObject = GameObject.Find("Directional Light");

        if (sunObject != null)
        {
            sun            = sunObject.GetComponent <Light>();
            originalSunPos = sun.transform.rotation;
        }

        instance.gameObject.SetActive(true);

        Range[] ranges = new Range[2] {
            Range.WIDE, Range.WIDE
        };

        bool bAgainstElement = false;

        fMeleeZoneSize = 1.0f;

        Core.theCore.fEnemyTimescale  = 1.0f;
        Core.theCore.fPlayerTimescale = 1.0f;

        // Spawn the player's minions immediately. Then give a countdown to start the game

        roster = selectedRoster;
        for (int i = 0; i < (int)MinionSlot.NUM_MINION_SLOTS; i++)
        {
            Transform spawnPoint = instance.playerSpawnPoints [i];
            Minion    minion     = roster.minions [i];
            if (spawnPoint != null && minion != null)
            {
                // Create new game object
                GameObject go = new GameObject("PlayerMinion_" + i + "_" + minion.template.name);

                // Fill it with actor components
                Actor_Player actor = go.AddComponent <Actor_Player>();
                actor.InitFromMinion(minion);
                actor.transform.position = spawnPoint.position;

                // Add renderer to actor
                RenderActor render = Instantiate <RenderActor>(minion.template.render);
                render.transform.SetParent(actor.transform);
                render.transform.localPosition = Vector3.zero;
                render.transform.localScale    = new Vector3(-1.0f, 1.0f, 1.0f);
                render.Init(actor);
                actor.render = render;

                // Add audio sources
                actor.soundEffect                       = go.AddComponent <AudioSource>();
                actor.soundEffect.clip                  = minion.template.soundEffect;
                actor.soundEffect.playOnAwake           = false;
                actor.soundEffect.outputAudioMixerGroup = Core.GetAudioManager().soundEffectGroup;

                // And combo numbers
                if ((minion.template.canCombo || minion.template.bDeathtoll || minion.template.bRelentless) && minion.template.comboNumbers != null)
                {
                    ComboNumbers combo = Instantiate <ComboNumbers>(minion.template.comboNumbers);
                    combo.transform.SetParent(actor.transform);
                    combo.transform.localPosition = new Vector3(-0.17f, 0.215f, -0.13f);
                    actor.comboNumbers            = combo;
                }

                // Save a reference for later
                playerActors [i] = actor;

                //
                if (((MinionSlot)i).GetSlotType() == MinionSlotType.RANGED && (minion.template is Minion_Ranged))
                {
                    ranges [i == (int)MinionSlot.RANGED_1 ? 0 : 1] = ((Minion_Ranged)minion.template).range;
                }

                if (minion.template is Minion_Support && ((Minion_Support)(minion.template)).bWalls)
                {
                    bWalls = true;
                }

                foreach (Resurrection res in minion.template.resurrectionTriggers)
                {
                    singleUseResurrections.Add(new Resurrection(res));
                }

                if (minion.template.element.GetDamageMultiplier(location.element) < 1.0f && ((MinionSlot)i).GetSlotType() != MinionSlotType.SUPPORT)
                {
                    bAgainstElement = true;
                }

                Core.theCore.fEnemyTimescale  += minion.GetBuff(Stat.ENEMY_TIMESCALE);
                Core.theCore.fPlayerTimescale += minion.GetBuff(Stat.PLAYER_TIMESCALE);

                fMeleeZoneSize += minion.GetBuff(Stat.MELEEZONE_SIZE);
            }
        }

        roster.bHasThreeResurrectsAvailable = singleUseResurrections.Count == 6;
        roster.bHasActiveCollector          = false;

        // After ALL player minions are created, then calculate their passive buffs and store them off.
        for (int i = 0; i < (int)MinionSlot.NUM_MINION_SLOTS; i++)
        {
            if (playerActors [i] != null)
            {
                playerActors [i].CalculateMyAggregateBuffs();
                playerActors [i].SetMaxHealthFromBuffs();
                playerActors [i].minion.ResetTemporaryData();
            }
        }

        roster.RecalculateHealths();

        fRangedZoneMin = Ranges.GetMinRangeForPair(ranges [0], ranges [1]);
        fRangedZoneMax = Ranges.GetMaxRangeForPair(ranges [0], ranges [1]);
        fLaneWidth     = bWalls ? 4.0f : 6.0f;
        InitZones(bWalls);

        aiNumKilledPerWave  = new int[location.numWaves];
        aiNumSpawnedPerWave = new int[location.numWaves];
        abNewlyUnlocked     = new bool[location.numWaves];


        iCurrentWave = -1;
        AdvanceWave();
        fGracePeriodDuration = location.gracePeriodDuration;

        instance.elementalHint.enabled = bAgainstElement;
        if (bAgainstElement)
        {
            instance.elementalHint.text = LocalizationManager.GetLoc(location.element.GetHintText());
        }

        Core.GetAudioManager().SetLevelMusic(location.music);

        RequestState(LevelState.PLAYING);
    }