public void CompleteDead() { Gulch.GameEventListener.Instance.OnPlayerDead(); if (player.playerRuntimeData.playerSlot.IsWearableEquiped(player.playerRuntimeData.playerStock, ItemData.Wearable.Sun_Protection_Stone)) { if (Random.value > ItemData.WearableItemBuffData.Sun_Protection_Stone_decayPointNotIncreasedRate) { player.playerRuntimeData.currentDecayPoints++; } } else { player.playerRuntimeData.currentDecayPoints++; } EnemySaveData.ResetRevivableEnemy(); if (player.playerRuntimeData.currentDecayPoints >= player.playerData.PD_maxDecayPoint) { GameObject.Find("GameManager").GetComponent <GameManager>().playerCinemaMovement.TransitToBelial(); } else { GM?.ReloadScene(); } }
public override void Exit() { base.Exit(); player.InputHandler.ResetAll(); player.GetLittleSunHandler()?.littleSunMenu.Deactivate(); EnemySaveData.ResetRevivableEnemy(); refreshEnemy(); }
// protected IEnumerator refreshScene(Player player){ // // player.playerRuntimeData.lastLittleSunID = littleSunData.LittleSunID; // // EnemySaveData.ResetRevivableEnemy(); // // player.stateMachine.SwitchState(player.cinemaState); // // GameManager gameManager = GameObject.Find("GameManager").GetComponent<GameManager>(); // // yield return new WaitForSeconds(gameManager.uiHandler.uiEffectHandler.OnPlayUIEffect(UIEffect.Transition_CrossFadeWhite, UIEffectAnimationClip.start)); // // gameManager.LoadSceneCode(player.playerRuntimeData.currentSceneCode); // // yield return new WaitForSeconds(gameManager.uiHandler.uiEffectHandler.OnPlayUIEffect(UIEffect.Transition_CrossFadeWhite, UIEffectAnimationClip.end)); // // player.stateMachine.SwitchState(player.littleSunState); // // yield return null; // } public void OnLittleSunTravel() { LittleSunData data = littleSunMenu.GetCurrentSelectedLittleSun(); Player player = GameObject.Find("Player").GetComponent <Player>(); player.playerRuntimeData.lastLittleSunID = data.LittleSunID; player.SetLittleSunHandler(null); littleSunMenu.Deactivate(); GameObject.Find("GameManager").GetComponent <GameManager>().ReloadScene(); EnemySaveData.ResetRevivableEnemy(); isTeleported = true; }
public void Save(SaveSlot saveSlot) { FileStream fs = null; try { fs = new FileStream(saveDirectory + "/" + saveSlot.ToString() + ".tgb", FileMode.Create); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(fs, LittleSunData.LittleSuns); Player player = GameObject.Find("/Player").transform.Find("Player").GetComponent <Player>(); //Player player = GameObject.Find("Player").GetComponent<Player>(); bf.Serialize(fs, player.playerData.GetPlayerSaveData()); bf.Serialize(fs, player.playerAbilityData.GetPlayerAbility()); player.SaveToPlayerRuntimeData(); bf.Serialize(fs, player.playerRuntimeData.GetPlayerRuntimeSaveData()); bf.Serialize(fs, player.miscData.GetMiscSaveData()); bf.Serialize(fs, EnemySaveData.GetEnemyRuntimeSaveData()); bf.Serialize(fs, Loot.GetLootRuntimeSaveData()); fs.Close(); } catch (FileNotFoundException ex) { Debug.Log("On GameSaver::Save, " + ex.StackTrace); } finally{ fs?.Close(); } // StreamWriter streamWriter = null; // try{ // streamWriter = File.CreateText(saveDirectory + "/" + saveSlot.ToString() + ".json"); // GameJsonSaveData gameJsonSaveData; // gameJsonSaveData.littleSunData = LittleSunData.LittleSuns; // Player player = GameObject.Find("/Player").transform.Find("Player").GetComponent<Player>(); // gameJsonSaveData.playerSaveData = player.playerData.GetPlayerSaveData(); // gameJsonSaveData.playerAbility = player.playerAbilityData.GetPlayerAbility(); // player.SaveToPlayerRuntimeData(); // gameJsonSaveData.playerRuntimeSaveData = player.playerRuntimeData.GetPlayerRuntimeSaveData(); // gameJsonSaveData.miscSaveData = player.miscData.GetMiscSaveData(); // gameJsonSaveData.enemyRuntimeSaveData = EnemySaveData.GetEnemyRuntimeSaveData(); // gameJsonSaveData.lootRuntimeSaveData = Loot.GetLootRuntimeSaveData(); // streamWriter.Write(JsonUtility.ToJson(gameJsonSaveData)); // streamWriter.Close(); // } // catch(Exception ex){ // Debug.Log(ex.StackTrace); // } }
IEnumerator StartGame(bool isNewGame) { yield return(new WaitForSeconds(uiHandler.uiEffectHandler.OnPlayUIEffect(UIEffect.Transition_CrossFade, UIEffectAnimationClip.start))); ResetAllSceneCode(); // uiHandler.uiEffectHandler.OnPlayUIEffect(UIEffect.Transition_CrossFade, UIEffectAnimationClip.dark); if (isNewGame) { player.gameObject.SetActive(true); currentSceneCode = DefaultStartScene; player.InitSaveData(); EnemySaveData.Initialize(); Loot.Initialize(); LittleSunData.Initialize(); if (DefaultStartPoint) { player.SetPosition(DefaultStartPoint.position); player.playerRuntimeData.lastPosition = DefaultStartPoint.position; } } else { player.gameObject.SetActive(true); yield return(new WaitForEndOfFrame()); gameSaver.LoadAll(); yield return(new WaitUntil(() => gameSaver.IsLoaded())); yield return(new WaitForEndOfFrame()); // yield return new WaitForSeconds(5f); currentSceneCode = player.playerRuntimeData.currentSceneCode; elapsedSeconds = gameSaver.GetSaveSlotMeta(gameSaver.currentSaveSlot).elapsedSeconds; } uiHandler.StartGame(); player.InputHandler.ResetAll(); player.InitializeRuntimeData(); LoadSceneCode(); player.stateMachine.InitializeState(player.wakeupState); Camera.main.GetComponent <BasicFollower>().ClampCamera(player.transform.position); Camera.main.GetComponent <BasicFollower>().UpdateCameraFollowing(player.transform); yield return(new WaitForSeconds(uiHandler.uiEffectHandler.OnPlayUIEffect(UIEffect.Transition_CrossFade, UIEffectAnimationClip.end))); }
public void Load(SaveSlot saveSlot) { FileStream fs = null; string path = saveDirectory + "/" + saveSlot.ToString() + ".tgb"; if (File.Exists(path)) { try { isLoaded = false; fs = new FileStream(path, FileMode.Open); BinaryFormatter bf = new BinaryFormatter(); var littleSuns = (Dictionary <int, bool>)bf.Deserialize(fs); LittleSunData.SetLittleSunData(littleSuns); var playerSaveData = (D_PlayerStateMachine.PlayerSaveData)bf.Deserialize(fs); var ability = (D_PlayerAbility.PlayerAbility)bf.Deserialize(fs); Player player = GameObject.Find("Player").GetComponent <Player>(); player.playerData.SetPlayerSaveData(playerSaveData); player.playerAbilityData.SetPlayerAbility(ability); var runtimeData = (PlayerRuntimeData.PlayerRuntimeSaveData)bf.Deserialize(fs); player.playerRuntimeData.SetPlayerRuntimeSaveData(runtimeData); var miscSaveData = (MiscData.MiscSaveData)bf.Deserialize(fs); player.miscData.SetMiscSaveData(miscSaveData); var enemyRuntimeSaveData = (EnemySaveData.EnemyRuntimeSaveData)bf.Deserialize(fs); EnemySaveData.SetEnemyRuntimeSaveData(enemyRuntimeSaveData); var lootRuntimeSaveData = (Loot.LootRuntimeSaveData)bf.Deserialize(fs); Loot.SetLootRuntimeSaveData(lootRuntimeSaveData); } catch (FileNotFoundException ex) { Debug.Log("On GameSaver::Load, " + ex.StackTrace); } finally { fs?.Close(); isLoaded = true; } } // string path = saveDirectory + "/" + saveSlot.ToString() + ".json"; // if(File.Exists(path)){ // try{ // isLoaded = false; // StreamReader streamReader = File.OpenText(path); // GameJsonSaveData gameJsonSaveData = JsonUtility.FromJson<GameJsonSaveData>(streamReader.ReadToEnd()); // LittleSunData.SetLittleSunData(gameJsonSaveData.littleSunData); // Player player = GameObject.Find("Player").GetComponent<Player>(); // player.playerData.SetPlayerSaveData(gameJsonSaveData.playerSaveData); // player.playerAbilityData.SetPlayerAbility(gameJsonSaveData.playerAbility); // player.playerRuntimeData.SetPlayerRuntimeSaveData(gameJsonSaveData.playerRuntimeSaveData); // player.miscData.SetMiscSaveData(gameJsonSaveData.miscSaveData); // EnemySaveData.SetEnemyRuntimeSaveData(gameJsonSaveData.enemyRuntimeSaveData); // Loot.SetLootRuntimeSaveData(gameJsonSaveData.lootRuntimeSaveData); // streamReader.Close(); // } // catch(Exception ex){ // Debug.Log(ex.StackTrace); // } // finally{ // isLoaded = true; // } // } }
public void Load() { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/board.dat", FileMode.Open); BoardSave bs = (BoardSave)bf.Deserialize(file); file.Close(); for (int i = 0; i < bs.floors.Count; i++) { if (bs.floors[i] != null) { FloorSaveData floorData = bs.floors[i]; FloorData databaseData = tileDatabase.GetFloorByID(floorData.Id); floorPrefab.GetComponent <SpriteRenderer>().sprite = databaseData.Sprite; floorPrefab.GetComponent <Floor>().id = floorData.Id; floorPrefab.SetActive(floorData.IsActive); GameObject instance = Instantiate(floorPrefab, IndexToPosition(floorData.Position), Quaternion.identity) as GameObject; instance.transform.SetParent(boardHolder); generatedFloorPositions.Add(floorData.Position, instance); } } for (int i = 0; i < bs.walls.Count; i++) { if (bs.walls[i] != null) { WallSaveData wallData = bs.walls[i]; Wall wall = wallPrefab.GetComponent <Wall>(); WallData databaseData = tileDatabase.GetWallByID(wallData.Id); wallPrefab.GetComponent <SpriteRenderer>().sprite = databaseData.Sprite; wallPrefab.SetActive(wallData.IsActive); wall.id = wallData.Id; wall.hp = wallData.CurrentHealth; wall.defence = wallData.Defense; wall.maxHp = databaseData.MaxHealth; GameObject instance = Instantiate(wallPrefab, IndexToPosition(wallData.Position), Quaternion.identity) as GameObject; instance.transform.SetParent(boardHolder); generatedObjectPositions.Add(wallData.Position, instance); if (!generatedFloorPositions.ContainsKey(wallData.Position))//Keeps the generator from messing up on biomes that generate only walls { generatedFloorPositions.Add(wallData.Position, instance); } } } for (int i = 0; i < bs.generatedStructurePositions.Count; i++) { generatedStructurePositions.Add(bs.generatedStructurePositions[i], true); } for (int i = 0; i < bs.enemies.Count; i++) { if (bs.enemies[i] != null) { EnemySaveData enemyData = bs.enemies[i]; Wall wall = enemyPrefab.GetComponent <Wall>(); Enemy enemy = enemyPrefab.GetComponent <Enemy>(); EnemyData databaseData = tileDatabase.GetEnemyByID(enemyData.Id); wall.defence = enemyData.Defense; wall.hp = enemyData.CurrentHealth; wall.maxHp = databaseData.MaxHealth; wall.experienceValue = databaseData.Experience; wall.id = enemyData.Id; wall.itemDrop = databaseData.ItemDrop; wall.rarity = databaseData.DropRarity; enemy.enemyDesc = databaseData.EnemyDesc; enemy.enemyLevel = databaseData.EnemyLevel; enemy.enemySpeed = enemyData.EnemySpeed; enemy.playerDamage = enemyData.EnemyAttack; enemy.turnCounter = enemyData.TurnCounter; enemy.name = databaseData.Name; enemyPrefab.GetComponent <Animator>().runtimeAnimatorController = databaseData.Animation; Vector3 position = IndexToPosition(enemyData.Position); AddEnemy(position.x, position.y, enemyPrefab); } } for (int i = 0; i < bs.bags.Count; i++) { if (bs.bags[i] != null) { Vector3 position = IndexToPosition(bs.bags[i].Position); AddPickup((int)position.x, (int)position.y, bs.bags[i].Items); } } }
public void Save() { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(Application.persistentDataPath + "/board.dat"); BoardSave bs = new BoardSave(); foreach (KeyValuePair <int, GameObject> pair in generatedFloorPositions) { if (pair.Value != null) { FloorSaveData floorData = new FloorSaveData(pair.Value.GetComponent <Floor>().id, pair.Value.activeSelf, pair.Key); bs.floors.Add(floorData); } } foreach (KeyValuePair <int, GameObject> pair in generatedObjectPositions) { if (pair.Value != null) { if (pair.Value.tag == "Wall") { WallSaveData wallData = new WallSaveData(); Wall wall = pair.Value.GetComponent <Wall>(); wallData.CurrentHealth = wall.hp; wallData.Id = wall.id; wallData.Defense = wall.defence; wallData.Position = pair.Key; wallData.IsActive = pair.Value.activeSelf; bs.walls.Add(wallData); } } } foreach (KeyValuePair <int, bool> pair in generatedStructurePositions) { bs.generatedStructurePositions.Add(pair.Key); } for (int i = 0; i < manager.enemies.Count; i++) { if (manager.enemies[i] != null) { EnemySaveData enemyData = new EnemySaveData(); Enemy enemy = manager.enemies[i]; Wall wall = enemy.GetComponent <Wall>(); enemyData.CurrentHealth = wall.hp; enemyData.Defense = wall.defence; enemyData.Id = wall.id; enemyData.Position = generateKey((int)enemy.transform.position.x, (int)enemy.transform.position.y); enemyData.EnemyAttack = enemy.playerDamage; enemyData.EnemySpeed = enemy.enemySpeed; enemyData.TurnCounter = enemy.turnCounter; bs.enemies.Add(enemyData); } } for (int i = 0; i < lootBags.Count; i++) { if (lootBags[i] != null) { Pickup pickup = lootBags[i].GetComponent <Pickup>(); LootbagSaveData saveData = new LootbagSaveData(generateKey((int)lootBags[i].transform.position.x, (int)lootBags[i].transform.position.y), pickup.itemId); bs.bags.Add(saveData); } } bf.Serialize(file, bs); file.Close(); }