public void LoadLevel(string levelName, bool updatePlayerLevel, bool saveCurrentPlayer, WorldArea worldArea = null, Location location = null)
 {
     if (RPG.LoadLevel(levelName, updatePlayerLevel, saveCurrentPlayer, worldArea, location))
     {
         GetObject.AudioPlayer.StartAudio();
         InitialiseLevel();
     }
 }
Esempio n. 2
0
        private void CreateAndSaveCharacter()
        {
            var classDef = Rm_RPGHandler.Instance.Player.CharacterDefinitions.First(c => c.ID == SaveCharacterID);

            var startingScene     = classDef.StartingScene;
            var startingWorldArea = classDef.StartingWorldArea;
            var startingLocation  = classDef.StartingLocation;

            var playerToCreate = new PlayerSave(SaveName, SaveClassID, SaveGenderID, SaveRaceID, SaveSubRaceID, SaveCharacterID, CharacterName.text, startingScene);

            playerToCreate.Initialize();

            if (classDef.HasStartingPet)
            {
                var petDef = Rm_RPGHandler.Instance.Player.PetDefinitions.FirstOrDefault(p => p.ID == classDef.StartingPet);
                playerToCreate.CurrentPet = new PetData(petDef);
            }
            playerToCreate.WorldMap.CurrentWorldAreaID = startingWorldArea;
            playerToCreate.WorldMap.CurrentLocationID  = startingLocation;

            if (classDef.StartAtWorldLocation)
            {
                var locationScene =
                    Rm_RPGHandler.Instance.Customise.WorldMapLocations.First(w => w.ID == startingWorldArea).Locations.
                    First(l => l.ID == startingLocation).SceneName;
                playerToCreate.CurrentScene = locationScene;
            }

            //Save MetaData
            foreach (var metaData in MetaDataValues)
            {
                var newMetaData = new MetaDataInfo();
                newMetaData.ID      = metaData.Key;
                newMetaData.ValueID = metaData.Value;

                playerToCreate.Character.MetaData.Add(newMetaData);
            }

            //Save visual customisations
            var allCustomisations = FindObjectsOfType <VisualCustomiser>();
            var customisations    = allCustomisations.Select(e => e.VisualCustomisation);

            playerToCreate.VisualCustomisations = GeneralMethods.CopyObject(customisations).ToList();

            //Save and Load the player
            PlayerSaveLoadManager.Instance.Save(playerToCreate, true);
            RPG.LoadLevel(playerToCreate.CurrentScene, false, false);
        }
Esempio n. 3
0
 public void LoadPlayerWithForcedReload(PlayerSave player, string savePath, bool saveCurrent)
 {
     PlayerPrefs.SetString(LastSavedGameKey, savePath);
     RPG.LoadLevel(player.CurrentScene, false, saveCurrent, null, null, true);
 }
Esempio n. 4
0
 public void LoadPlayer(PlayerSave player, string savePath, bool saveCurrent)
 {
     PlayerPrefs.SetString(LastSavedGameKey, savePath);
     RPG.LoadLevel(player.CurrentScene, false, saveCurrent);
 }
Esempio n. 5
0
        public bool Load(string savePathOrPPrefKey)
        {
            GetObject.ClearReferences();
#if (!UNITY_IOS && !UNITY_ANDROID)
            if (!File.Exists(savePathOrPPrefKey))
            {
                return(false);
            }
            Debug.Log("SavePath: " + savePathOrPPrefKey);
            var fileLoad       = File.ReadAllText(savePathOrPPrefKey);
            var jsonFromEncode = fileLoad;
            if (encryptFiles)
            {
                jsonFromEncode = new Xor().Decrypt(fileLoad, GameDataSaveLoadManager.Instance.EncryptKey);
            }
#else
            var jsonFromEncode = PlayerPrefs.GetString(savePathOrPPrefKey, "");
#endif

            if (string.IsNullOrEmpty(jsonFromEncode))
            {
                return(false);
            }

            var loadedPlayerSave = JsonConvert.DeserializeObject <PlayerSave>(jsonFromEncode, new JsonSerializerSettings
            {
                TypeNameHandling       = TypeNameHandling.Objects,
                TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple,
                ObjectCreationHandling = ObjectCreationHandling.Replace
            });

            var loadedScene = SceneManager.GetActiveScene().name;
            if (loadedScene != loadedPlayerSave.CurrentScene)
            {
                RPG.LoadLevel(loadedPlayerSave.CurrentScene, false);
            }

            //todo: check this
            var classDef = Rm_RPGHandler.Instance.Player.CharacterDefinitions.FirstOrDefault(c => c.ID == loadedPlayerSave.Character.PlayerCharacterID);
            if (classDef == null)
            {
                Debug.Log("Class not found for character you're trying to load. Try creating a new character.");
                return(false);
            }

            var className = classDef.Name;

            var gameObject     = Resources.Load(classDef.ClassPrefabPath) as GameObject;
            var spawnTransform = GetObject.SpawnPositionTransform;

            var spawnPosition = spawnTransform.transform.position;
            if (!string.IsNullOrEmpty(loadedPlayerSave.WorldMap.CurrentLocationID))
            {
                var location = Rm_RPGHandler.Instance.Customise.WorldMapLocations.First(w => w.ID == loadedPlayerSave.WorldMap.CurrentWorldAreaID).
                               Locations.First(l => l.ID == loadedPlayerSave.WorldMap.CurrentLocationID);

                if (location.UseCustomLocation)
                {
                    spawnPosition = location.CustomSpawnLocation;
                }
            }

            if (spawnTransform != null)
            {
                //Spawn Player
                Object.Instantiate(gameObject, spawnPosition, GetObject.SpawnPositionTransform.rotation);

                GetObject.RPGCamera.transform.position = spawnPosition - (GetObject.SpawnPositionTransform.forward * 2);
            }
            else
            {
                Debug.LogError("[RPGAIO] Did not find spawn position. This is required to spawn the player.");
            }


            GetObject.ClearReferences();
            var playerMono = GetObject.PlayerMono;
            playerMono.SetPlayerSave(loadedPlayerSave);


#if (!UNITY_IOS && !UNITY_ANDROID)
            //Todo: allow savables for mobile
            //Debug.Log("Loading savables");
            LoadSavableGameObjects(savePathOrPPrefKey);
#endif


            //Debug.Log("Loaded file with ID " + loadedPlayerSave.SaveID);
            UserSaveLoadManager.Instance.LoadUserData();
            TimeLastSaved = Time.time;
            return(true);
        }
 public void ContinueClick()
 {
     PlayClickSound();
     RPG.LoadLevel(RecentSave.CurrentScene, false);
 }
 void PerformEvent()
 {
     RPG.LoadLevel(SceneName, true, true);
 }
    // Use this for initialization
    void Start()
    {
        //Run coroutine for movies/slides

        RPG.LoadLevel("MainMenu", false);
    }
 protected override void Eval(NodeChain nodeChain)
 {
     RPG.LoadLevel((string)ValueOf("Name"));
 }