예제 #1
0
    public IEnumerator LoadData()
    {
        AudioManager.instance.ChangeMusic(AudioManager.ThemeType.nexus1);

        yield return(StartCoroutine(LoadScenes()));

        Debug.Log("Calling retrieve save data");
        RetrieveSaveData();


        //TODO
        // ---- General ---- //
        if (pGenerator == null)
        {
            pGenerator = PathGenerator.instance;
        }
        if (pGenerator == null)
        {
            Debug.LogError("No PathGenerator found when trying to load data");
        }

        pGenerator.floor = act;

        if (statistics == null)
        {
            statistics = StatisticsEnd.instance;
        }
        if (statistics == null)
        {
            Debug.LogError("No StatisticsEnd found when trying to load data");
        }

        statistics.SetElapsedTime(gameTime);

        if (gManager == null)
        {
            gManager = GameManager.instance;
        }
        if (gManager == null)
        {
            Debug.LogError("No GameManager found when trying to load data");
        }

        if (gBuffs == null)
        {
            gBuffs = GlobalBuffs.instance;
        }
        if (gBuffs == null)
        {
            Debug.LogError("No GlobalBuffs found when trying to store data");
        }

        gBuffs.SetupFromSave(globalHotDots);

        if (goldManager == null)
        {
            goldManager = GoldManager.instance;
        }
        if (goldManager == null)
        {
            Debug.LogError("No GoldManager found when trying to store data");
        }

        goldManager.LoadFromSave(gold);

        if (aManager == null)
        {
            aManager = AscensionManager.instance;
        }
        if (aManager == null)
        {
            Debug.LogError("No AscensionManager found when trying to store data");
        }
        aManager.currentAscension = chapter;


        //Team loading
        if (PlayerCharactersUnlockeables.instance == null)
        {
            Debug.LogError("No PlayerCharactersUnlockeables found when trying to load data");
        }

        PlayerCharactersUnlockeables.instance.RetrieveUnlocks();
        int            i        = 0;
        List <Fighter> fighters = new List <Fighter>();

        foreach (KeyValuePair <GameObject, bool> characters in PlayerCharactersUnlockeables.instance.GetUnlockeables())
        {
            if (team[i])
            {
                fighters.Add(characters.Key.GetComponent <Fighter>());
            }
            i++;
        }
        gManager.teamA = fighters.ToArray();
        gManager.SetupFromSave();

        //Relics
        if (rStorage == null)
        {
            rStorage = RelicStorage.instance;
        }
        if (rStorage == null)
        {
            Debug.LogError("No RelicStorage found when trying to store data");
        }

        rStorage.EnableRelicsFromSave(relics);

        // World ------//
        pGenerator.GenerateNewWorlds(worldTypes, worldWeatherTypes);

        if (pSelector == null)
        {
            pSelector = PathSelector.instance;
        }
        if (pSelector == null)
        {
            Debug.LogError("No PathSelector found when trying to load data");
        }

        pSelector.SetCurrentWorld(playerPos);

        //Characters ---- //
        i = 0;
        foreach (Fighter f in gManager.teamA)
        {
            f.GetComponent <FighterExperience>().SetLevel(levels[f.fUnlockIndex], i + 1);
            f.GetComponent <FighterExperience>().SetCurrentExperience(experience[f.fUnlockIndex]);
            f.GetComponent <FighterExperience>().SetPerkPoints(unusedPerks[f.fUnlockIndex]);

            f.hp     = stats[f.fUnlockIndex, 0];
            f.str    = stats[f.fUnlockIndex, 2];
            f.def    = stats[f.fUnlockIndex, 3];
            f.spd    = stats[f.fUnlockIndex, 4];
            f.energy = stats[f.fUnlockIndex, 1];

            f._hp     = _stats[f.fUnlockIndex, 0];
            f._str    = _stats[f.fUnlockIndex, 2];
            f._def    = _stats[f.fUnlockIndex, 3];
            f._spd    = _stats[f.fUnlockIndex, 4];
            f._energy = _stats[f.fUnlockIndex, 1];

            foreach (KeyValuePair <int, PasiveSkill> skills in f.GetComponentInChildren <SkillTree>().characterSkillTree)
            {
                if (talents[f.fUnlockIndex, skills.Key])
                {
                    skills.Value.LoadFromSave();
                }
            }

            int attackLength = 0;
            for (int k = 0; k < attacks.GetLength(1); k++)
            {
                if (attacks[f.fUnlockIndex, k] != -1)
                {
                    attackLength++;
                }
            }

            f.attacks = new FighterAttack[attackLength];
            for (int k = 0; k < f.attacks.Length; k++)
            {
                if (attacks[f.fUnlockIndex, k] != -1)
                {
                    f.attacks[k] = new FighterAttack(AttackStorage.instance.GetAllSkills()
                                                     [attacks[f.fUnlockIndex, k]].GetComponent <UpgradedAttack>()
                                                     , attackLevels[f.fUnlockIndex, k]);
                    //AttackStorage.instance.GetSkills()[attacks[f.fUnlockIndex, k]].GetComponent<Attack>();
                }
            }

            f.Get3DUI().UpdateManaAndHealth();

            i++;
        }

        SceneManager.UnloadSceneAsync("Loader");
        SceneManager.UnloadSceneAsync("Loading");
        SceneManager.UnloadSceneAsync("Menu");
    }