public static SavedWorld BrandNewWorld(string name) { var obj = new SavedWorld { name = name }; return(obj); }
private void GenerateVaultDungeonLayout() { dungeonInstance = Instantiate(dungeonPrefab); navMeshSurface = dungeonInstance.GetComponentInChildren <NavMeshSurface>(); if (dungeonType.environmentType == "vault") { layout = new TreasureVault(); } else { layout = new Tomb(); } var vaultLayout = (TreasureVault)layout; vaultLayout.Initialize(); float ruinLevel = Random.Range(0f, 0.25f); if (resettled) { var numStructures = Random.Range(3, 11); for (int i = 0; i < numStructures; i++) { socialStructures.Add(new SocialStructure(180 / numStructures, true)); } layout.ResettleRooms(socialStructures); layout.layout.ApplyRuin(ruinLevel); } else { vaultLayout.AddMonsters(targetLevel); } vaultLayout.CreateAffinities(); vaultLayout.CreateRandomEnemyBuffs(targetLevel); var obj = Instantiate(darkRuinsLighting); obj.transform.parent = dungeonInstance.transform; foreach (var socialStruture in socialStructures) { Debug.Log(socialStruture.Print()); } //Debug.Log(layout.PrintGrid()); for (int i = 0; i < layout.numFloors; i++) { seeds.Add(Random.Range(int.MinValue, int.MaxValue)); } if (dungeonData != null) { dungeonData.entered = true; dungeonData.dungeonData = vaultLayout; dungeonData.seeds = seeds; SavedWorld.OverwriteDungeonData(dungeonData); } InstantiateVaultDungeonLayout(); }
public static void CreateWorld(string name) { if (!Directory.Exists(Application.persistentDataPath + "/worlds")) { Directory.CreateDirectory(Application.persistentDataPath + "/worlds"); } var saveObject = SavedWorld.BrandNewWorld(name); BinaryFormatter bf = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); bf.Serialize(ms, saveObject); File.WriteAllBytes(Application.persistentDataPath + "/worlds/" + name + ".world", ms.ToArray()); }
public void SaveWorld() { GameLog.AddText("<color=green>Autosaved world state.</color>"); var saveObject = SavedWorld.ConvertFrom(gameObject); BinaryFormatter bf = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); bf.Serialize(ms, saveObject); if (!Directory.Exists(Application.persistentDataPath + "/worlds")) { Directory.CreateDirectory(Application.persistentDataPath + "/worlds"); } File.WriteAllBytes(Application.persistentDataPath + "/worlds/" + worldName + ".world", ms.ToArray()); }
public static byte[] Serialize() { var world = new SavedWorld(); //Get the top level objects world.TopLevelObjects = SaveManager.GetTopLevelObjects(); BinaryFormatter bin = new BinaryFormatter(); //Serialize the SavedWorld using (MemoryStream mem = new MemoryStream()) { bin.Serialize(mem, world); return(Compressor.Compress(mem.ToArray())); } }
public static SavedWorld ConvertFrom(GameObject go) { var obj = new SavedWorld(); var worldAutoSaver = go.GetComponent <WorldAutoSaver>(); if (PlayerCharacter.localPlayer != null) { foreach (var item in PlayerCharacter.localPlayer.inventory.items) { obj.inventory.Add(SavedItem.ConvertFrom(item)); } } obj.name = worldAutoSaver.worldName; if (OverworldGenerator.instance != null) { obj.savedOverworld = true; obj.elevation = OverworldGenerator.instance.elevation; foreach (var landmark in OverworldLandmarkGenerator.landmarks) { if (landmark.type == "base") { obj.baseCoords = SavedVector2.ConvertFrom(landmark.position); } else if (landmark.type == "dungeon") { obj.dungeons.Add(SavedDungeon.ConvertFrom((OverworldDungeon)landmark)); } } } else if (lastSavedWorld != null) { obj.savedOverworld = lastSavedWorld.savedOverworld; obj.elevation = lastSavedWorld.elevation; obj.baseCoords = lastSavedWorld.baseCoords; obj.dungeons = lastSavedWorld.dungeons; } lastSavedWorld = obj; return(obj); }