Exemple #1
0
 public override void Awake()
 {
     ExistByCondition.AwakeAll();
     base.Awake();
     periodicCounter  = GetComponentInChildren <PeriodicCounter>();
     periodicCounters = GetComponentsInChildren <PeriodicCounter>().ToList();
     Debug.LogFormat("Got periodic counters");
 }
    public void RunLevel(Level level, bool restarted = false)
    {
        Intermission.active = false;
        if (gameState.CurrentRun.continuousRun)
        {
            if (gameState.CurrentRun.triesLeft <= 0)
            {
                FailGame();
                return;
            }
            gameState.CurrentRun.triesLeft--;
            if (gameState.CurrentRun.levelsCompleted == 0)
            {
                gameState.CurrentRun.triesLeft = 4;
            }
        }
        lastLevel = level;
        Clear();
        currentLevel      = Instantiate(level);
        currentLevel.name = level.name;
        currentLevel.gameObject.SetActive(true);
        var commonObjects = Instantiate(GameLevels.instance.commonObjects);

        commonObjects.transform.SetParent(currentLevel.transform);
        commonObjects.SetActive(true);
        Controls.instance.activeUnit = Hero.instance;
        UI.instance.CloseAll();
        TimeManager.Wait(0).Then(() => {
            UI.instance.UpdateHUD();
        });

        Board.instance.Restore();
        Controls.instance.lockers.Clear();

        FindObjectsOfType <Figure>().ForEach(f => {
            if (f.Position == null || !f.Position.gameObject.activeInHierarchy)
            {
                f.Blink();
            }
        });

        ExistByCondition.AwakeAll();
        FindObjectsOfType <OnLevelStart>().ForEach(t => t.Run()); // then run existent onlevelstart triggers

        if (BlackMage.instance.GetComponent <HealthScale>() == null)
        {
            BlackMage.instance.maxHealth += 5 * (gameState.CurrentRun.difficulty - 4);
            BlackMage.instance.health    += 5 * (gameState.CurrentRun.difficulty - 4);
            if (BlackMage.instance.health < 1)
            {
                BlackMage.instance.health = BlackMage.instance.maxHealth = 1;
            }
        }

        Controls.instance.Ready();

        var intro = currentLevel.GetComponentsInChildren <Intermission>().FirstOrDefault(i => !i.ending);

        if (intro != null)
        {
            if (restarted || gameState.CurrentProfile.skipIntros)
            {
                intro.Hide();
            }
            else
            {
                intro.Show();
            }
        }

        levelIsRunning = true;
    }