/// <summary> /// Merges faction data from savevars into a new faction dictionary. /// Does not affect factions as read from FACTIONS.TXT. /// This resultant set of factions is the character's live faction setup. /// This is only used when importing a classic save. /// Daggerfall Unity uses a different method of storing faction data with saves. /// </summary> /// <param name="saveVars"></param> public Dictionary <int, FactionData> Merge(SaveVars saveVars) { // Create clone of base faction dictionary Dictionary <int, FactionData> dict = new Dictionary <int, FactionData>(); foreach (var kvp in factionDict) { dict.Add(kvp.Key, kvp.Value); } // Merge save faction data from savevars FactionData[] factions = saveVars.Factions; foreach (var srcFaction in factions) { if (dict.ContainsKey(srcFaction.id)) { FactionData dstFaction = dict[srcFaction.id]; // First a quick sanity check to ensure IDs are the same if (dstFaction.id != srcFaction.id) { throw new Exception(string.Format("ID mismatch while merging faction data. SrcFaction=#{0}, DstFaction=#{1}", srcFaction.id, dstFaction.id)); } // Copy live reputation value from SAVEVARS.DAT // Other values remain as pre-generated from faction.txt // This is to prevent bad save data polluting faction structure dstFaction.rep = srcFaction.rep; // May migrate other values later //dstFaction.type = srcFaction.type; //dstFaction.name = srcFaction.name; //dstFaction.region = srcFaction.region; //dstFaction.power = srcFaction.power; //dstFaction.flags = srcFaction.flags; //dstFaction.ruler = srcFaction.ruler; //dstFaction.ally1 = srcFaction.ally1; //dstFaction.ally2 = srcFaction.ally2; //dstFaction.ally3 = srcFaction.ally3; //dstFaction.enemy1 = srcFaction.enemy1; //dstFaction.enemy2 = srcFaction.enemy2; //dstFaction.enemy3 = srcFaction.enemy3; //dstFaction.face = srcFaction.face; //dstFaction.race = srcFaction.race; //dstFaction.flat1 = srcFaction.flat1; //dstFaction.flat2 = srcFaction.flat2; //dstFaction.sgroup = srcFaction.sgroup; //dstFaction.ggroup = srcFaction.ggroup; //dstFaction.vam = srcFaction.vam; // Store merged data back in new dictionary dict[srcFaction.id] = dstFaction; } } RelinkChildren(dict); return(dict); }
/// <summary> /// Merges faction data from savevars into a new faction dictionary. /// Does not affect factions as read from FACTIONS.TXT. /// This resultant set of factions is the character's live faction setup. /// This is only used when importing a classic save. /// Daggerfall Unity uses a different method of storing faction data with saves. /// </summary> /// <param name="saveVars"></param> public Dictionary <int, FactionData> Merge(SaveVars saveVars) { // Create clone of base faction dictionary Dictionary <int, FactionData> dict = new Dictionary <int, FactionData>(); foreach (var kvp in factionDict) { dict.Add(kvp.Key, kvp.Value); } // Merge save faction data from savevars FactionData[] factions = saveVars.Factions; foreach (var srcFaction in factions) { if (dict.ContainsKey(srcFaction.id)) { FactionData dstFaction = dict[srcFaction.id]; // First a quick sanity check to ensure IDs are the same if (dstFaction.id != srcFaction.id) { throw new Exception(string.Format("ID mismatch while merging faction data. SrcFaction=#{0}, DstFaction=#{1}", srcFaction.id, dstFaction.id)); } // Copy live data from SAVEVARS.DAT dstFaction.type = srcFaction.type; dstFaction.name = srcFaction.name; dstFaction.rep = srcFaction.rep; dstFaction.region = srcFaction.region; dstFaction.power = srcFaction.power; dstFaction.flags = srcFaction.flags; dstFaction.ruler = srcFaction.ruler; dstFaction.ally1 = srcFaction.ally1; dstFaction.ally2 = srcFaction.ally2; dstFaction.ally3 = srcFaction.ally3; dstFaction.enemy1 = srcFaction.enemy1; dstFaction.enemy2 = srcFaction.enemy2; dstFaction.enemy3 = srcFaction.enemy3; dstFaction.face = srcFaction.face; dstFaction.race = srcFaction.race; dstFaction.flat1 = srcFaction.flat1; dstFaction.flat2 = srcFaction.flat2; dstFaction.sgroup = srcFaction.sgroup; dstFaction.ggroup = srcFaction.ggroup; dstFaction.vam = srcFaction.vam; // Store data back in new dictionary dict[srcFaction.id] = dstFaction; } } return(dict); }
public void ImportClassicReputation(SaveVars saveVars) { // Get faction reader FactionFile factionFile = DaggerfallUnity.Instance.ContentReader.FactionFileReader; if (factionFile == null) { throw new Exception("PersistentFactionData.ImportClassicReputation() unable to load faction file reader."); } // Assign new faction dict factionDict = factionFile.Merge(saveVars); Debug.Log("Imported faction data from classic save."); }
public void ToJson() { SaveVars newSave = new SaveVars { PlayCount = playCount, EasyMode = easyMode, NormalMode = normalMode, HardMode = hardMode, EndlessKills = endlessKills, MachinegunChallenge = machinegunChallenge, MinigunChallenge = minigunChallenge, ShotgunChallenge = shotgunChallenge, LaserChallenge = laserChallenge, SniperChallenge = sniperChallenge, RocketChallenge = rocketChallenge, GEnemyChallenge = gEnemyChallenge, REnemyChallenge = rEnemyChallenge, OEnemyChallenge = oEnemyChallenge, PEnemyChallenge = pEnemyChallenge, CEnemyChallenge = cEnemyChallenge, YEnemyChallenge = yEnemyChallenge, SlowChallenge = slowChallenge, FastChallenge = fastChallenge, NoAbilityChallenge = noAbilityChallenge, AmmoChallenge = ammoChallenge, CrazyEnemyChallenge = crazyEnemyChallenge, UpsideDownChallenge = upsideDownChallenge, WeaponChallenges = weaponChallenges, EnemyChallenges = enemyChallenges, OtherChallenges = otherChallenges, Sound = sound, Music = music, }; string saveFile = "save.txt"; FileInfo fileInfo = new FileInfo(saveFile); string fullname = fileInfo.FullName; string json = JsonUtility.ToJson(newSave); File.Delete(fullname); File.WriteAllText(fullname, json); }
/// <summary> /// Import global variables from classic save. /// </summary> /// <param name="saveVars"></param> public void ImportClassicGlobalVars(SaveVars saveVars) { byte[] globals = saveVars.GlobalVars; for (int i = 0; i < globals.Length; i++) { GlobalVar globalVar = globalVarsDict[i]; if (globals[i] == 0) { globalVar.value = false; } else if (globals[i] == 1) { globalVar.value = true; } else { throw new Exception("ImportClassicGlobalVars() Ecnountered an unexpected global variable value."); } globalVarsDict[i] = globalVar; } }
public void ToJson() { SaveVars newSave = new SaveVars { Damage = damage, MaxHealth = maxHealth, HealthRegen = healthRegen, Speed = speed, Defense = defense, CritChance = critChance, CritDamage = critDamage, SwingSpeed = swingSpeed, EnemyTriggerDistance = enemyTriggerDistance, StartleDamage = startleDamage, StartleCritDamage = startleCritDamage, StartleCritChance = startleCritChance, EXP = exp, EXPNeeded = expNeeded, FullHealthSwing = fullHealthSwing, NotFullHealthSwing = notFullHealthSwing, SpeedByHealth = speedByHealth, SpeedByMissingHealth = speedByMissingHealth, MaxHPUpgrade = maxHPUpgrade, MaxHPMinusSpeedUpgrade = maxHPMinusSpeedUpgrade, HealthRegenUpgrade = healthRegenUpgrade, HealthRegenMinusHPUpgrade = healthRegenMinusHPUpgrade, HealthRegenMinusSpeedUpgrade = healthRegenMinusSpeedUpgrade, SpeedUpgrade = speedUpgrade, }; string saveFile = "save.txt"; FileInfo fileInfo = new FileInfo(saveFile); string fullname = fileInfo.FullName; string json = JsonUtility.ToJson(newSave); File.Delete(fullname); File.WriteAllText(fullname, json); }
void StartFromClassicSave() { DaggerfallUnity.ResetUID(); QuestMachine.Instance.ClearState(); RaiseOnNewGameEvent(); ResetWeaponManager(); // Save index must be in range if (classicSaveIndex < 0 || classicSaveIndex >= 6) { throw new IndexOutOfRangeException("classicSaveIndex out of range."); } // Open saves in parent path of Arena2 folder string path = SaveLoadManager.Instance.DaggerfallSavePath; SaveGames saveGames = new SaveGames(path); if (!saveGames.IsPathOpen) { throw new Exception(string.Format("Could not open Daggerfall saves path {0}", path)); } // Open save index if (!saveGames.TryOpenSave(classicSaveIndex)) { string error = string.Format("Could not open classic save index {0}.", classicSaveIndex); DaggerfallUI.MessageBox(error); DaggerfallUnity.LogMessage(string.Format(error), true); return; } // Get required save data SaveTree saveTree = saveGames.SaveTree; SaveVars saveVars = saveGames.SaveVars; SaveTreeBaseRecord positionRecord = saveTree.FindRecord(RecordTypes.CharacterPositionRecord); if (NoWorld) { playerEnterExit.DisableAllParents(); } else { // Set player to world position playerEnterExit.EnableExteriorParent(); StreamingWorld streamingWorld = FindStreamingWorld(); int worldX = positionRecord.RecordRoot.Position.WorldX; int worldZ = positionRecord.RecordRoot.Position.WorldZ; streamingWorld.TeleportToWorldCoordinates(worldX, worldZ); streamingWorld.suppressWorld = false; } GameObject cameraObject = GameObject.FindGameObjectWithTag("MainCamera"); PlayerMouseLook mouseLook = cameraObject.GetComponent <PlayerMouseLook>(); if (mouseLook) { // Classic save value ranges from -256 (looking up) to 256 (looking down). // The maximum up and down range of view in classic is similar to 45 degrees up and down in DF Unity. float pitch = positionRecord.RecordRoot.Pitch; if (pitch != 0) { pitch = (pitch * 45 / 256); } mouseLook.Pitch = pitch; float yaw = positionRecord.RecordRoot.Yaw; // In classic saves 2048 units of yaw is 360 degrees. if (yaw != 0) { yaw = (yaw * 360 / 2048); } mouseLook.Yaw = yaw; } // Set whether the player's weapon is drawn WeaponManager weaponManager = GameManager.Instance.WeaponManager; weaponManager.Sheathed = (!saveVars.WeaponDrawn); // Set game time DaggerfallUnity.Instance.WorldTime.Now.FromClassicDaggerfallTime(saveVars.GameTime); // Get character record List <SaveTreeBaseRecord> records = saveTree.FindRecords(RecordTypes.Character); if (records.Count != 1) { throw new Exception("SaveTree CharacterRecord not found."); } // Get prototypical character document data CharacterRecord characterRecord = (CharacterRecord)records[0]; characterDocument = characterRecord.ToCharacterDocument(); // Assign data to player entity PlayerEntity playerEntity = FindPlayerEntity(); playerEntity.AssignCharacter(characterDocument, characterRecord.ParsedData.level, characterRecord.ParsedData.maxHealth, false); // Assign biography modifiers playerEntity.BiographyResistDiseaseMod = saveVars.BiographyResistDiseaseMod; playerEntity.BiographyResistMagicMod = saveVars.BiographyResistMagicMod; playerEntity.BiographyAvoidHitMod = saveVars.BiographyAvoidHitMod; playerEntity.BiographyResistPoisonMod = saveVars.BiographyResistPoisonMod; playerEntity.BiographyFatigueMod = saveVars.BiographyFatigueMod; // Assign faction data playerEntity.FactionData.ImportClassicReputation(saveVars); // Assign global variables playerEntity.GlobalVars.ImportClassicGlobalVars(saveVars); // Set time of last check for raising skills playerEntity.TimeOfLastSkillIncreaseCheck = saveVars.LastSkillCheckTime; // Assign items to player entity playerEntity.AssignItems(saveTree); // Assign guild memberships playerEntity.AssignGuildMemberships(saveTree); // Assign diseases and poisons to player entity playerEntity.AssignDiseasesAndPoisons(saveTree); // Assign gold pieces playerEntity.GoldPieces = (int)characterRecord.ParsedData.physicalGold; // Assign weapon hand being used weaponManager.UsingRightHand = !saveVars.UsingLeftHandWeapon; // GodMode setting playerEntity.GodMode = saveVars.GodMode; // Setup bank accounts var bankRecords = saveTree.FindRecord(RecordTypes.BankAccount); Banking.DaggerfallBankManager.ReadNativeBankData(bankRecords); // Get regional data. playerEntity.RegionData = saveVars.RegionData; // Set time tracked by playerEntity for game minute-based updates playerEntity.LastGameMinutes = saveVars.GameTime; // Get breath remaining if player was submerged (0 if they were not in the water) playerEntity.CurrentBreath = saveVars.BreathRemaining; // TODO: Import classic spellbook playerEntity.DeserializeSpellbook(null); // Get last type of crime committed playerEntity.CrimeCommitted = (PlayerEntity.Crimes)saveVars.CrimeCommitted; // Get weather byte[] climateWeathers = saveVars.ClimateWeathers; // Enums for thunder and snow are reversed in classic and Unity, so they are converted here. for (int i = 0; i < climateWeathers.Length; i++) { // TODO: 0x80 flag can be set for snow or rain, to add fog to these weathers. This isn't in DF Unity yet, so // temporarily removing the flag. climateWeathers[i] &= 0x7f; if (climateWeathers[i] == 5) { climateWeathers[i] = 6; } else if (climateWeathers[i] == 6) { climateWeathers[i] = 5; } } GameManager.Instance.WeatherManager.PlayerWeather.ClimateWeathers = climateWeathers; // Load character biography text playerEntity.BackStory = saveGames.BioFile.Lines; // Validate spellbook item DaggerfallUnity.Instance.ItemHelper.ValidateSpellbookItem(playerEntity); // Start game DaggerfallUI.Instance.PopToHUD(); GameManager.Instance.PauseGame(false); DaggerfallUI.Instance.FadeBehaviour.FadeHUDFromBlack(); DaggerfallUI.PostMessage(PostStartMessage); lastStartMethod = StartMethods.LoadClassicSave; SaveIndex = -1; if (OnStartGame != null) { OnStartGame(this, null); } }
void OnGUI() { if (!IsReady()) { EditorGUILayout.HelpBox("DaggerfallUnity instance not ready. Have you set your Arena2 path?", MessageType.Info); return; } if (selectedSave != lastSelectedSave || currentSaveTree == null) { currentSaveTree = saveTrees[selectedSave]; currentSaveVars = saveVars[selectedSave]; if (currentSaveTree == null || currentSaveVars == null) { return; } currentItems = currentSaveTree.FindRecords(RecordTypes.Item).ToArray(); // Merge savetree faction data factionDict = factionFile.Merge(currentSaveVars); lastSelectedSave = selectedSave; } if (saveTrees != null && saveTrees.Length > 0) { DisplaySaveSelectGUI(); DisplaySaveImageGUI(); DisplaySaveStatsGUI(); DisplaySaveCharacterGUI(); scrollPos = GUILayoutHelper.ScrollView(scrollPos, () => { EditorGUILayout.Space(); showFactionsFoldout = GUILayoutHelper.Foldout(showFactionsFoldout, new GUIContent("Factions"), () => { GUILayoutHelper.Indent(() => { DisplayFactionsFoldout(); }); }); EditorGUILayout.Space(); showItemsFoldout = GUILayoutHelper.Foldout(showItemsFoldout, new GUIContent("Items"), () => { GUILayoutHelper.Indent(() => { DisplayItemsFoldout(); }); }); EditorGUILayout.Space(); showSaveTreeFoldout = GUILayoutHelper.Foldout(showSaveTreeFoldout, new GUIContent("SaveTree"), () => { EditorGUILayout.HelpBox("Temporarily Filtering out records of type Door and UnknownItemRecord to keep list manageable.", MessageType.Info); DisplaySaveTree(currentSaveTree.RootRecord); }); }); } }
void StartFromClassicSave() { DaggerfallUnity.ResetUID(); RaiseOnNewGameEvent(); ResetWeaponManager(); // Save index must be in range if (classicSaveIndex < 0 || classicSaveIndex >= 6) { throw new IndexOutOfRangeException("classicSaveIndex out of range."); } // Open saves in parent path of Arena2 folder string path = SaveLoadManager.Instance.DaggerfallSavePath; SaveGames saveGames = new SaveGames(path); if (!saveGames.IsPathOpen) { throw new Exception(string.Format("Could not open Daggerfall saves path {0}", path)); } // Open save index if (!saveGames.TryOpenSave(classicSaveIndex)) { string error = string.Format("Could not open classic save index {0}.", classicSaveIndex); DaggerfallUI.MessageBox(error); DaggerfallUnity.LogMessage(string.Format(error), true); return; } // Get required save data SaveTree saveTree = saveGames.SaveTree; SaveVars saveVars = saveGames.SaveVars; if (NoWorld) { playerEnterExit.DisableAllParents(); } else { // Set player to world position playerEnterExit.EnableExteriorParent(); StreamingWorld streamingWorld = FindStreamingWorld(); int worldX = saveTree.Header.CharacterPosition.Position.WorldX; int worldZ = saveTree.Header.CharacterPosition.Position.WorldZ; streamingWorld.TeleportToWorldCoordinates(worldX, worldZ); streamingWorld.suppressWorld = false; } // Set game time DaggerfallUnity.Instance.WorldTime.Now.FromClassicDaggerfallTime(saveVars.GameTime); // Get character record List <SaveTreeBaseRecord> records = saveTree.FindRecords(RecordTypes.Character); if (records.Count != 1) { throw new Exception("SaveTree CharacterRecord not found."); } // Get prototypical character document data CharacterRecord characterRecord = (CharacterRecord)records[0]; characterDocument = characterRecord.ToCharacterDocument(); // Assign data to player entity PlayerEntity playerEntity = FindPlayerEntity(); playerEntity.AssignCharacter(characterDocument, characterRecord.ParsedData.level, characterRecord.ParsedData.startingHealth); // Assign items to player entity playerEntity.AssignItems(saveTree); // Assign gold pieces playerEntity.GoldPieces = (int)characterRecord.ParsedData.physicalGold; // Start game DaggerfallUI.Instance.PopToHUD(); GameManager.Instance.PauseGame(false); DaggerfallUI.Instance.FadeHUDFromBlack(); DaggerfallUI.PostMessage(PostStartMessage); if (OnStartGame != null) { OnStartGame(this, null); } }
// Start is called before the first frame update void Start() { string saveFile = "save.txt"; FileInfo fileInfo = new FileInfo(saveFile); string fullname = fileInfo.FullName; if (playCount == -1) { if (!File.Exists(fullname)) { SaveVars saveVars = new SaveVars { PlayCount = 0, EasyMode = "unbeaten", NormalMode = "unbeaten", HardMode = "unbeaten", EndlessKills = 0, MachinegunChallenge = false, MinigunChallenge = false, ShotgunChallenge = false, LaserChallenge = false, SniperChallenge = false, RocketChallenge = false, GEnemyChallenge = false, REnemyChallenge = false, OEnemyChallenge = false, CEnemyChallenge = false, PEnemyChallenge = false, YEnemyChallenge = false, SlowChallenge = false, FastChallenge = false, NoAbilityChallenge = false, AmmoChallenge = false, CrazyEnemyChallenge = false, UpsideDownChallenge = false, WeaponChallenges = 0, EnemyChallenges = 0, OtherChallenges = 0, Music = true, Sound = true, }; playCount = saveVars.PlayCount; easyMode = saveVars.EasyMode; normalMode = saveVars.NormalMode; hardMode = saveVars.HardMode; endlessKills = saveVars.EndlessKills; machinegunChallenge = saveVars.MachinegunChallenge; minigunChallenge = saveVars.MinigunChallenge; shotgunChallenge = saveVars.ShotgunChallenge; laserChallenge = saveVars.LaserChallenge; sniperChallenge = saveVars.SniperChallenge; rocketChallenge = saveVars.RocketChallenge; gEnemyChallenge = saveVars.GEnemyChallenge; rEnemyChallenge = saveVars.REnemyChallenge; oEnemyChallenge = saveVars.OEnemyChallenge; pEnemyChallenge = saveVars.PEnemyChallenge; cEnemyChallenge = saveVars.CEnemyChallenge; yEnemyChallenge = saveVars.YEnemyChallenge; slowChallenge = saveVars.SlowChallenge; fastChallenge = saveVars.FastChallenge; noAbilityChallenge = saveVars.NoAbilityChallenge; ammoChallenge = saveVars.AmmoChallenge; crazyEnemyChallenge = saveVars.CrazyEnemyChallenge; upsideDownChallenge = saveVars.UpsideDownChallenge; weaponChallenges = saveVars.WeaponChallenges; enemyChallenges = saveVars.EnemyChallenges; otherChallenges = saveVars.OtherChallenges; music = saveVars.Music; sound = saveVars.Sound; string json = JsonUtility.ToJson(saveVars); File.WriteAllText(fullname, json); } else { string jsonString = File.ReadLines(fullname).First(); SaveVars jsonJson = JsonUtility.FromJson <SaveVars>(jsonString); playCount = jsonJson.PlayCount; easyMode = jsonJson.EasyMode; normalMode = jsonJson.NormalMode; hardMode = jsonJson.HardMode; endlessKills = jsonJson.EndlessKills; machinegunChallenge = jsonJson.MachinegunChallenge; minigunChallenge = jsonJson.MinigunChallenge; shotgunChallenge = jsonJson.ShotgunChallenge; laserChallenge = jsonJson.LaserChallenge; sniperChallenge = jsonJson.SniperChallenge; rocketChallenge = jsonJson.RocketChallenge; gEnemyChallenge = jsonJson.GEnemyChallenge; rEnemyChallenge = jsonJson.REnemyChallenge; oEnemyChallenge = jsonJson.OEnemyChallenge; pEnemyChallenge = jsonJson.PEnemyChallenge; cEnemyChallenge = jsonJson.CEnemyChallenge; yEnemyChallenge = jsonJson.YEnemyChallenge; slowChallenge = jsonJson.SlowChallenge; fastChallenge = jsonJson.FastChallenge; noAbilityChallenge = jsonJson.NoAbilityChallenge; ammoChallenge = jsonJson.AmmoChallenge; upsideDownChallenge = jsonJson.UpsideDownChallenge; crazyEnemyChallenge = jsonJson.CrazyEnemyChallenge; weaponChallenges = jsonJson.WeaponChallenges; enemyChallenges = jsonJson.EnemyChallenges; otherChallenges = jsonJson.OtherChallenges; music = jsonJson.Music; sound = jsonJson.Sound; } } }
void StartFromClassicSave() { DaggerfallUnity.ResetUID(); QuestMachine.Instance.ClearState(); RaiseOnNewGameEvent(); ResetWeaponManager(); // Save index must be in range if (classicSaveIndex < 0 || classicSaveIndex >= 6) { throw new IndexOutOfRangeException("classicSaveIndex out of range."); } // Open saves in parent path of Arena2 folder string path = SaveLoadManager.Instance.DaggerfallSavePath; SaveGames saveGames = new SaveGames(path); if (!saveGames.IsPathOpen) { throw new Exception(string.Format("Could not open Daggerfall saves path {0}", path)); } // Open save index if (!saveGames.TryOpenSave(classicSaveIndex)) { string error = string.Format("Could not open classic save index {0}.", classicSaveIndex); DaggerfallUI.MessageBox(error); DaggerfallUnity.LogMessage(string.Format(error), true); return; } // Get required save data SaveTree saveTree = saveGames.SaveTree; SaveVars saveVars = saveGames.SaveVars; SaveTreeBaseRecord positionRecord = saveTree.FindRecord(RecordTypes.CharacterPositionRecord); if (NoWorld) { playerEnterExit.DisableAllParents(); } else { // Set player to world position playerEnterExit.EnableExteriorParent(); StreamingWorld streamingWorld = FindStreamingWorld(); int worldX = positionRecord.RecordRoot.Position.WorldX; int worldZ = positionRecord.RecordRoot.Position.WorldZ; streamingWorld.TeleportToWorldCoordinates(worldX, worldZ); streamingWorld.suppressWorld = false; } GameObject cameraObject = GameObject.FindGameObjectWithTag("MainCamera"); PlayerMouseLook mouseLook = cameraObject.GetComponent <PlayerMouseLook>(); if (mouseLook) { // Classic save value ranges from -256 (looking up) to 256 (looking down). // The maximum up and down range of view in classic is similar to 45 degrees up and down in DF Unity. float pitch = positionRecord.RecordRoot.Pitch; if (pitch != 0) { pitch = (pitch * 45 / 256); } mouseLook.Pitch = pitch; float yaw = positionRecord.RecordRoot.Yaw; // In classic saves 2048 units of yaw is 360 degrees. if (yaw != 0) { yaw = (yaw * 360 / 2048); } mouseLook.Yaw = yaw; } // Set whether the player's weapon is drawn GameManager.Instance.WeaponManager.Sheathed = (!saveVars.WeaponDrawn); // Set game time DaggerfallUnity.Instance.WorldTime.Now.FromClassicDaggerfallTime(saveVars.GameTime); // Get character record List <SaveTreeBaseRecord> records = saveTree.FindRecords(RecordTypes.Character); if (records.Count != 1) { throw new Exception("SaveTree CharacterRecord not found."); } // Get prototypical character document data CharacterRecord characterRecord = (CharacterRecord)records[0]; characterDocument = characterRecord.ToCharacterDocument(); // Assign data to player entity PlayerEntity playerEntity = FindPlayerEntity(); playerEntity.AssignCharacter(characterDocument, characterRecord.ParsedData.level, characterRecord.ParsedData.maxHealth, false); // Assign biography modifiers playerEntity.BiographyResistDiseaseMod = saveVars.BiographyResistDiseaseMod; playerEntity.BiographyResistMagicMod = saveVars.BiographyResistMagicMod; playerEntity.BiographyAvoidHitMod = saveVars.BiographyAvoidHitMod; playerEntity.BiographyResistPoisonMod = saveVars.BiographyResistPoisonMod; playerEntity.BiographyFatigueMod = saveVars.BiographyFatigueMod; // Assign faction data playerEntity.FactionData.ImportClassicReputation(saveVars); // Assign global variables playerEntity.GlobalVars.ImportClassicGlobalVars(saveVars); // Set time of last check for raising skills playerEntity.TimeOfLastSkillIncreaseCheck = saveVars.LastSkillCheckTime; // Assign items to player entity playerEntity.AssignItems(saveTree); // Assign gold pieces playerEntity.GoldPieces = (int)characterRecord.ParsedData.physicalGold; // GodMode setting playerEntity.GodMode = saveVars.GodMode; // Setup bank accounts var bankRecords = saveTree.FindRecord(RecordTypes.BankAccount); Banking.DaggerfallBankManager.ReadNativeBankData(bankRecords); // Get regional data. playerEntity.RegionData = saveVars.RegionData; // Set time tracked by playerEntity for game minute-based updates playerEntity.LastGameMinutes = saveVars.GameTime; // Start game DaggerfallUI.Instance.PopToHUD(); GameManager.Instance.PauseGame(false); DaggerfallUI.Instance.FadeHUDFromBlack(); DaggerfallUI.PostMessage(PostStartMessage); lastStartMethod = StartMethods.LoadClassicSave; SaveIndex = -1; if (OnStartGame != null) { OnStartGame(this, null); } }
// Start is called before the first frame update void Start() { string saveFile = "save.txt"; FileInfo fileInfo = new FileInfo(saveFile); string fullname = fileInfo.FullName; if (damage == 0) { if (!File.Exists(fullname)) { SaveVars saveVars = new SaveVars { Damage = 5, MaxHealth = 100, HealthRegen = 0, Speed = 3, Defense = 0, CritChance = 10, CritDamage = 2, SwingSpeed = 2, EnemyTriggerDistance = 5, StartleDamage = 0, StartleCritDamage = 0, StartleCritChance = 0, EXP = 0, EXPNeeded = 10, FullHealthSwing = false, NotFullHealthSwing = false, SpeedByHealth = false, SpeedByMissingHealth = false, MaxHPUpgrade = 0, MaxHPMinusSpeedUpgrade = 0, HealthRegenUpgrade = 0, HealthRegenMinusHPUpgrade = 0, HealthRegenMinusSpeedUpgrade = 0, SpeedUpgrade = 0, }; damage = saveVars.Damage; maxHealth = saveVars.MaxHealth; healthRegen = saveVars.HealthRegen; speed = saveVars.Speed; defense = saveVars.Defense; critChance = saveVars.CritChance; critDamage = saveVars.CritDamage; swingSpeed = saveVars.SwingSpeed; enemyTriggerDistance = saveVars.EnemyTriggerDistance; startleDamage = saveVars.StartleDamage; startleCritDamage = saveVars.StartleCritDamage; startleCritChance = saveVars.StartleCritChance; exp = saveVars.EXP; expNeeded = saveVars.EXPNeeded; fullHealthSwing = saveVars.FullHealthSwing; notFullHealthSwing = saveVars.NotFullHealthSwing; speedByHealth = saveVars.SpeedByHealth; speedByMissingHealth = saveVars.SpeedByMissingHealth; maxHPUpgrade = saveVars.MaxHPUpgrade; maxHPMinusSpeedUpgrade = saveVars.MaxHPMinusSpeedUpgrade; healthRegenUpgrade = saveVars.HealthRegenUpgrade; healthRegenMinusHPUpgrade = saveVars.HealthRegenMinusHPUpgrade; healthRegenMinusSpeedUpgrade = saveVars.HealthRegenMinusSpeedUpgrade; speedUpgrade = saveVars.SpeedUpgrade; string json = JsonUtility.ToJson(saveVars); File.WriteAllText(fullname, json); } else { string jsonString = File.ReadLines(fullname).First(); SaveVars jsonJson = JsonUtility.FromJson <SaveVars>(jsonString); damage = jsonJson.Damage; maxHealth = jsonJson.MaxHealth; healthRegen = jsonJson.HealthRegen; speed = jsonJson.Speed; defense = jsonJson.Defense; critChance = jsonJson.CritChance; critDamage = jsonJson.CritDamage; swingSpeed = jsonJson.SwingSpeed; enemyTriggerDistance = jsonJson.EnemyTriggerDistance; startleDamage = jsonJson.StartleDamage; startleCritDamage = jsonJson.StartleCritDamage; startleCritChance = jsonJson.StartleCritChance; exp = jsonJson.EXP; expNeeded = jsonJson.EXPNeeded; fullHealthSwing = jsonJson.FullHealthSwing; notFullHealthSwing = jsonJson.NotFullHealthSwing; speedByHealth = jsonJson.SpeedByHealth; speedByMissingHealth = jsonJson.SpeedByMissingHealth; maxHPUpgrade = jsonJson.MaxHPUpgrade; maxHPMinusSpeedUpgrade = jsonJson.MaxHPMinusSpeedUpgrade; healthRegenUpgrade = jsonJson.HealthRegenUpgrade; healthRegenMinusHPUpgrade = jsonJson.HealthRegenMinusHPUpgrade; healthRegenMinusSpeedUpgrade = jsonJson.HealthRegenMinusSpeedUpgrade; speedUpgrade = jsonJson.SpeedUpgrade; } } }