Пример #1
0
    //Esta función se usa únicamente en el SaveGame. La he separado para que quede más claro la información que se guarda en cada archivo
    private Save CreateSaveGameObject()
    {
        //Construyo archivo de guardado e inicializo todas las variables en el save
        Save save = new Save();

        save.s_lastLevelWon = lastLevelWon;

        save.s_currentXp = currentExp;

        for (int i = 0; i < characterDataForCurrentLevel.Count; i++)
        {
            save.s_charactersUnlocked.Add(characterDataForCurrentLevel[i].idCharacter);
        }

        for (int i = 0; i < levelIDsUnlocked.Count; i++)
        {
            save.s_levelIDsUnlocked.Add(levelIDsUnlocked[i]);
        }

        #region Characters
        KnightData _knight = FindObjectOfType <KnightData>();

        save.s_KnightPowerLevel = _knight.unitPowerLevel;
        if (_knight.isCharacterUnlocked)
        {
            for (int i = 0; i < _knight.idSkillsBought.Count; i++)
            {
                save.s_KnightSkillsIds.Add(_knight.idSkillsBought[i]);
            }
        }

        RogueData _rogue = FindObjectOfType <RogueData>();

        save.s_RoguePowerLevel = _rogue.unitPowerLevel;
        if (_rogue.isCharacterUnlocked)
        {
            for (int i = 0; i < _rogue.idSkillsBought.Count; i++)
            {
                save.s_RogueSkillsIds.Add(_rogue.idSkillsBought[i]);
            }
        }

        MageData _mage = FindObjectOfType <MageData>();

        save.s_MagePowerLevel = _mage.unitPowerLevel;
        if (_mage.isCharacterUnlocked)
        {
            for (int i = 0; i < _mage.idSkillsBought.Count; i++)
            {
                save.s_MageSkillsIds.Add(_mage.idSkillsBought[i]);
            }
        }

        BerserkerData _berserker = FindObjectOfType <BerserkerData>();

        save.s_BerserkerPowerLevel = _berserker.unitPowerLevel;
        if (_berserker.isCharacterUnlocked)
        {
            for (int i = 0; i < _berserker.idSkillsBought.Count; i++)
            {
                save.s_BerserkerSkillsIds.Add(_berserker.idSkillsBought[i]);
            }
        }

        ValkyrieData _valkyrie = FindObjectOfType <ValkyrieData>();

        save.s_ValkyriePowerLevel = _valkyrie.unitPowerLevel;
        if (_valkyrie.isCharacterUnlocked)
        {
            for (int i = 0; i < _valkyrie.idSkillsBought.Count; i++)
            {
                save.s_ValkyrieSkillsIds.Add(_valkyrie.idSkillsBought[i]);
            }
        }

        DruidData _druid = FindObjectOfType <DruidData>();

        save.s_DruidPowerLevel = _druid.unitPowerLevel;
        if (_druid.isCharacterUnlocked)
        {
            for (int i = 0; i < _druid.idSkillsBought.Count; i++)
            {
                save.s_DruidSkillsIds.Add(_druid.idSkillsBought[i]);
            }
        }

        MonkData _monk = FindObjectOfType <MonkData>();

        save.s_MonkPowerLevel = _monk.unitPowerLevel;
        if (_monk.isCharacterUnlocked)
        {
            for (int i = 0; i < _monk.idSkillsBought.Count; i++)
            {
                save.s_MonkSkillsIds.Add(_monk.idSkillsBought[i]);
            }
        }

        SamuraiData _samurai = FindObjectOfType <SamuraiData>();

        save.s_SamuraiPowerLevel = _samurai.unitPowerLevel;
        if (_samurai.isCharacterUnlocked)
        {
            for (int i = 0; i < _samurai.idSkillsBought.Count; i++)
            {
                save.s_SamuraiSkillsIds.Add(_samurai.idSkillsBought[i]);
            }
        }

        #endregion

        save.s_enemiesKilled         = enemiesKilled;
        save.s_randomLevelsCompleted = randomLevelsCompleted;

        return(save);
    }
Пример #2
0
    public void ReseteSaveFile()
    {
        if (File.Exists(Application.persistentDataPath + "/gamesave.save"))
        {
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(Application.persistentDataPath + "/gamesave.save", FileMode.Open);
            Save            save = (Save)bf.Deserialize(file);
            file.Close();

            //Aqui se hace lo contrario que en el CreateSaveGameObject. Se toman las variables del save y se aplican esos valores a las variables que se usan en código
            currentExp = 0;

            lastLevelWon = 0;

            characterDataForCurrentLevel.Clear();

            allLevelNodes = FindObjectsOfType <LevelNode>();
            for (int i = 0; i < allLevelNodes.Length; i++)
            {
                allLevelNodes[i].HideThisLevel();
            }

            levelIDsUnlocked.Clear();

            for (int i = 0; i < allLevelNodes.Length; i++)
            {
                if (allLevelNodes[i].idLevel == 1)
                {
                    levelIDsUnlocked.Add(allLevelNodes[i].idLevel);
                    allLevelNodes[i].UnlockThisLevel();
                }
            }

            #region Characters



            KnightData _knight = FindObjectOfType <KnightData>();

            _knight.unitPowerLevel = _knight.initialPowerLevelOnlyUsedForResetSaveFile;
            _knight.HideShowMeshCharacterData(true);
            _knight.isCharacterUnlocked = true;
            _knight.idSkillsBought.Clear();

            MageData _mage = FindObjectOfType <MageData>();
            _mage.unitPowerLevel = _mage.initialPowerLevelOnlyUsedForResetSaveFile;
            _mage.HideShowMeshCharacterData(true);
            _mage.isCharacterUnlocked = true;
            _mage.idSkillsBought.Clear();

            //Añado al mago y al caballero para que salgan en la caja de selección al principio
            characterDataForCurrentLevel.Add(_knight);
            characterDataForCurrentLevel.Add(_mage);

            RogueData _rogue = FindObjectOfType <RogueData>();
            _rogue.unitPowerLevel = _rogue.initialPowerLevelOnlyUsedForResetSaveFile;
            _rogue.HideShowMeshCharacterData(false);
            _rogue.isCharacterUnlocked = false;
            _rogue.idSkillsBought.Clear();

            BerserkerData _berserker = FindObjectOfType <BerserkerData>();
            _berserker.unitPowerLevel = _berserker.initialPowerLevelOnlyUsedForResetSaveFile;
            _berserker.HideShowMeshCharacterData(false);
            _berserker.isCharacterUnlocked = false;
            _berserker.idSkillsBought.Clear();

            ValkyrieData _valkyrie = FindObjectOfType <ValkyrieData>();
            _valkyrie.unitPowerLevel = _valkyrie.initialPowerLevelOnlyUsedForResetSaveFile;
            _valkyrie.HideShowMeshCharacterData(false);
            _valkyrie.isCharacterUnlocked = false;
            _valkyrie.idSkillsBought.Clear();

            DruidData _druid = FindObjectOfType <DruidData>();
            _druid.unitPowerLevel = _druid.initialPowerLevelOnlyUsedForResetSaveFile;
            _druid.HideShowMeshCharacterData(false);
            _druid.isCharacterUnlocked = false;
            _druid.idSkillsBought.Clear();

            MonkData _monk = FindObjectOfType <MonkData>();
            _monk.unitPowerLevel = _monk.initialPowerLevelOnlyUsedForResetSaveFile;
            _monk.HideShowMeshCharacterData(false);
            _monk.isCharacterUnlocked = false;
            _monk.idSkillsBought.Clear();

            SamuraiData _samurai = FindObjectOfType <SamuraiData>();
            _samurai.unitPowerLevel = _samurai.initialPowerLevelOnlyUsedForResetSaveFile;
            _samurai.HideShowMeshCharacterData(false);
            _samurai.isCharacterUnlocked = false;
            _samurai.idSkillsBought.Clear();

            #endregion

            enemiesKilled         = 0;
            randomLevelsCompleted = 0;

            Debug.Log("File Reseted");
            Debug.Log("-----");
        }

        else
        {
            Debug.Log("Se ha intentado cargar y no existe archivo de guardado");
        }

        print(Application.persistentDataPath);
    }
Пример #3
0
    public void LoadGame()
    {
        Debug.Log(Application.persistentDataPath);

        if (File.Exists(Application.persistentDataPath + "/gamesave.save"))
        {
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(Application.persistentDataPath + "/gamesave.save", FileMode.Open);
            Save            save = (Save)bf.Deserialize(file);
            file.Close();

            lastLevelWon = save.s_lastLevelWon;

            //Aqui se hace lo contrario que en el CreateSaveGameObject. Se toman las variables del save y se aplican esos valores a las variables que se usan en código
            currentExp = save.s_currentXp;

            characterDataForCurrentLevel.Clear();

            for (int i = 0; i < allCharacters.Length; i++)
            {
                if (save.s_charactersUnlocked.Contains(allCharacters[i].idCharacter))
                {
                    characterDataForCurrentLevel.Add(allCharacters[i]);
                    allCharacters[i].isCharacterUnlocked = true;
                    allCharacters[i].HideShowMeshCharacterData(true);
                }
            }

            allLevelNodes = FindObjectsOfType <LevelNode>();

            //List<LevelNode> allLevelNodesList = new List<LevelNode>(allLevelNodes);

            //allLevelNodesList.Sort(delegate (LevelNode a, LevelNode b)
            //{
            //    return (a.GetComponent<LevelNode>().idLevel).CompareTo(b.GetComponent<LevelNode>().idLevel);

            //});

            //allLevelNodes = allLevelNodesList.ToArray();

            levelIDsUnlocked.Clear();

            levelIDsUnlocked = new List <int>(save.s_levelIDsUnlocked);

            for (int i = 0; i < allLevelNodes.Length; i++)
            {
                for (int j = 0; j < levelIDsUnlocked.Count; j++)
                {
                    if (allLevelNodes[i].idLevel == levelIDsUnlocked[j])
                    {
                        if (lastLevelWon <= allLevelNodes[i].idLevel)
                        {
                            lastLevelWon = allLevelNodes[i].idLevel;
                        }

                        allLevelNodes[i].WinLevel();
                        allLevelNodes[i].UnlockThisLevel();
                        allLevelNodes[i].UnlockConnectedLevels();
                        break;
                    }
                }
            }


            //for (int i = 0; i < save.s_levelIDsUnlocked.Count; i++)
            //{
            //    levelIDsUnlocked.Add(save.s_levelIDsUnlocked[i]);

            //    if (allLevelNodes[save.s_levelIDsUnlocked[i-1]].idLevel < lastLevelWon)
            //    {
            //        allLevelNodes[save.s_levelIDsUnlocked[i-1]].WinLevel();
            //    }

            //    else if (allLevelNodes[save.s_levelIDsUnlocked[i-1]].idLevel == lastLevelWon-1)
            //    {
            //        allLevelNodes[save.s_levelIDsUnlocked[i-1]].UnlockConnectedLevels();
            //    }

            //    //allLevelNodes[save.s_levelIDsUnlocked[i]].UnlockThisLevel();
            //}

            //if (allLevelNodes[2].isUnlocked)
            //{
            //    allLevelNodes[1].UnlockThisLevel();
            //}


            #region Characters

            UITableManager UITM = FindObjectOfType <UITableManager>();


            KnightData _knight = FindObjectOfType <KnightData>();

            _knight.unitPowerLevel = save.s_KnightPowerLevel;
            if (_knight.isCharacterUnlocked)
            {
                for (int i = 0; i < save.s_KnightSkillsIds.Count; i++)
                {
                    _knight.idSkillsBought.Add(save.s_KnightSkillsIds[i]);
                }

                UITM.SetCharacterUpgradeBookInfo(_knight);
            }

            RogueData _rogue = FindObjectOfType <RogueData>();

            _rogue.unitPowerLevel = save.s_RoguePowerLevel;
            if (_rogue.isCharacterUnlocked)
            {
                for (int i = 0; i < save.s_RogueSkillsIds.Count; i++)
                {
                    _rogue.idSkillsBought.Add(save.s_RogueSkillsIds[i]);
                }

                UITM.SetCharacterUpgradeBookInfo(_rogue);
            }

            MageData _mage = FindObjectOfType <MageData>();

            _mage.unitPowerLevel = save.s_MagePowerLevel;
            if (_mage.isCharacterUnlocked)
            {
                for (int i = 0; i < save.s_MageSkillsIds.Count; i++)
                {
                    _mage.idSkillsBought.Add(save.s_MageSkillsIds[i]);
                }

                UITM.SetCharacterUpgradeBookInfo(_mage);
            }

            BerserkerData _berserker = FindObjectOfType <BerserkerData>();

            _berserker.unitPowerLevel = save.s_BerserkerPowerLevel;
            if (_berserker.isCharacterUnlocked)
            {
                for (int i = 0; i < save.s_BerserkerSkillsIds.Count; i++)
                {
                    _berserker.idSkillsBought.Add(save.s_BerserkerSkillsIds[i]);
                }

                UITM.SetCharacterUpgradeBookInfo(_berserker);
            }

            ValkyrieData _valkyrie = FindObjectOfType <ValkyrieData>();

            _valkyrie.unitPowerLevel = save.s_ValkyriePowerLevel;
            if (_valkyrie.isCharacterUnlocked)
            {
                for (int i = 0; i < save.s_ValkyrieSkillsIds.Count; i++)
                {
                    _valkyrie.idSkillsBought.Add(save.s_ValkyrieSkillsIds[i]);
                }

                UITM.SetCharacterUpgradeBookInfo(_valkyrie);
            }

            DruidData _druid = FindObjectOfType <DruidData>();

            _druid.unitPowerLevel = save.s_DruidPowerLevel;
            if (_druid.isCharacterUnlocked)
            {
                for (int i = 0; i < save.s_DruidSkillsIds.Count; i++)
                {
                    _druid.idSkillsBought.Add(save.s_DruidSkillsIds[i]);
                }

                UITM.SetCharacterUpgradeBookInfo(_druid);
            }

            MonkData _monk = FindObjectOfType <MonkData>();

            _monk.unitPowerLevel = save.s_MonkPowerLevel;
            if (_monk.isCharacterUnlocked)
            {
                for (int i = 0; i < save.s_MonkSkillsIds.Count; i++)
                {
                    _monk.idSkillsBought.Add(save.s_MonkSkillsIds[i]);
                }

                UITM.SetCharacterUpgradeBookInfo(_monk);
            }

            SamuraiData _samurai = FindObjectOfType <SamuraiData>();

            _samurai.unitPowerLevel = save.s_SamuraiPowerLevel;
            if (_samurai.isCharacterUnlocked)
            {
                for (int i = 0; i < save.s_SamuraiSkillsIds.Count; i++)
                {
                    _samurai.idSkillsBought.Add(save.s_SamuraiSkillsIds[i]);
                }

                UITM.SetCharacterUpgradeBookInfo(_samurai);
            }


            #endregion

            enemiesKilled         = save.s_enemiesKilled;
            randomLevelsCompleted = save.s_randomLevelsCompleted;

            Debug.Log("File Load");
            Debug.Log("-----");
        }

        else
        {
            Debug.Log("Se ha intentado cargar y no existe archivo de guardado");

            SaveGame();
        }
    }