public static PlayerSave CreateSave(string name, string checkpointName = null, string resourcePath = "") { string currentVersion = VersionNumberScript.version; PlayerSave save = new PlayerSave(); save.name = name; save.timePlayed = 0; save.presetBlueprints = new string[5]; save.currentHealths = new float[] { 1000, 250, 500 }; save.partInventory = new List <EntityBlueprint.PartInfo>(); save.sectorsSeen = new List <string>(); save.missions = new List <Mission>(); // this section contains default information for a new save. Edit this to change how the default save // is created. EntityBlueprint blueprint = ScriptableObject.CreateInstance <EntityBlueprint>(); blueprint.name = "Player Save Blueprint"; blueprint.parts = new List <EntityBlueprint.PartInfo>(); blueprint.coreSpriteID = "core1_light"; blueprint.coreShellSpriteID = "core1_shell"; blueprint.baseRegen = CoreUpgraderScript.GetRegens(blueprint.coreShellSpriteID); blueprint.shellHealth = CoreUpgraderScript.defaultHealths; save.currentPlayerBlueprint = JsonUtility.ToJson(blueprint); save.abilityCaps = CoreUpgraderScript.minAbilityCap; save.shards = 0; save.version = currentVersion; save.resourcePath = resourcePath; save.abilityHotkeys = new AbilityHotkeyStruct(); File.WriteAllText(Application.persistentDataPath + "\\Saves" + "\\" + name, JsonUtility.ToJson(save)); return(save); }
public void OnPointerClick(PointerEventData eventData) { if (player.reputation >= repCost) { player.blueprint.coreShellSpriteID = coreID; player.blueprint.baseRegen = CoreUpgraderScript.GetRegens(coreID); player.Rebuild(); CoreUpgraderScript.DrawScreen(); NodeEditorFramework.Standard.UpgradeCoreCondition.OnCoreUpgrade.Invoke(); } else { Debug.Log("Not enough reputation!" + player.reputation + " " + repCost); } }
public void Initialize() { string currentPath; if (!File.Exists(Application.persistentDataPath + "\\CurrentSavePath")) { currentPath = Application.persistentDataPath + "\\TestSave"; } else { currentPath = File.ReadAllLines(Application.persistentDataPath + "\\CurrentSavePath")[0]; } if (File.Exists(currentPath)) { // Load string json = File.ReadAllText(currentPath); save = JsonUtility.FromJson <PlayerSave>(json); if (save.timePlayed != 0) { player.spawnPoint = save.position; } if (SectorManager.testJsonPath != null) { save.resourcePath = SectorManager.testJsonPath; } else if (save.resourcePath == "") { save.resourcePath = SectorManager.jsonPath; } player.cursave = save; SectorManager.instance.LoadSectorFile(save.resourcePath); taskManager.Initialize(true); // Re-init DialogueSystem.InitCanvases(); player.blueprint = ScriptableObject.CreateInstance <EntityBlueprint>(); player.blueprint.name = "Player Save Blueprint"; if (save.currentPlayerBlueprint != null && save.currentPlayerBlueprint != "") { JsonUtility.FromJsonOverwrite(save.currentPlayerBlueprint, player.blueprint); } else { Debug.LogError("Save should have been given a currentPlayerBlueprint by now."); player.blueprint.parts = new List <EntityBlueprint.PartInfo>(); player.blueprint.coreSpriteID = "core1_light"; player.blueprint.coreShellSpriteID = "core1_shell"; player.blueprint.baseRegen = CoreUpgraderScript.GetRegens(player.blueprint.coreShellSpriteID); player.blueprint.shellHealth = CoreUpgraderScript.defaultHealths; } player.abilityCaps = save.abilityCaps; player.shards = save.shards; player.SetCredits(save.credits); player.reputation = save.reputation; if (save.presetBlueprints.Length != 5) { save.presetBlueprints = new string[5]; } Camera.main.GetComponent <CameraScript>().Initialize(player); taskManager.taskVariables.Clear(); for (int i = 0; i < save.taskVariableNames.Length; i++) { taskManager.taskVariables.Add(save.taskVariableNames[i], save.taskVariableValues[i]); } } else { Debug.LogError("There was not a save or test save that was ready on load."); save = new PlayerSave(); save.presetBlueprints = new string[5]; save.currentHealths = new float[] { 1000, 250, 500 }; save.partInventory = new List <EntityBlueprint.PartInfo>(); player.blueprint = ScriptableObject.CreateInstance <EntityBlueprint>(); player.blueprint.name = "Player Save Blueprint"; player.blueprint.coreSpriteID = "core1_light"; player.blueprint.coreShellSpriteID = "core1_shell"; player.blueprint.baseRegen = CoreUpgraderScript.GetRegens(player.blueprint.coreShellSpriteID); player.blueprint.shellHealth = CoreUpgraderScript.defaultHealths; player.blueprint.parts = new List <EntityBlueprint.PartInfo>(); player.cursave = save; player.abilityCaps = CoreUpgraderScript.minAbilityCap; } }
// Update is called once per frame void Update() { float[] totalHealths = CoreUpgraderScript.defaultHealths; float[] totalRegens = CoreUpgraderScript.GetRegens(cursorScript?.player?.blueprint?.coreShellSpriteID); float shipMass = 1; float enginePower = 200; float weight = Entity.coreWeight; float speed = Craft.initSpeed; foreach (DisplayPart part in statsDatabase.GetParts()) { switch (part.info.abilityID) { case 13: enginePower *= Mathf.Pow(1.1F, part.info.tier); speed += 15 * part.info.tier; break; case 17: totalRegens[0] += 50 * part.info.tier; break; case 18: totalHealths[0] += 250 * part.info.tier; break; case 19: totalRegens[2] += 50 * part.info.tier; break; case 20: totalHealths[2] += 250 * part.info.tier; break; } PartBlueprint blueprint = ResourceManager.GetAsset <PartBlueprint>(part.info.partID); totalHealths[0] += blueprint.health / 2; totalHealths[1] += blueprint.health / 4; shipMass += blueprint.mass; weight += blueprint.mass * Entity.weightMultiplier; } string buildStat = ""; if (statsDatabase.GetMode() == BuilderMode.Yard || statsDatabase.GetMode() == BuilderMode.Workshop) { buildStat = "\nTOTAL BUILD VALUE: \n" + statsDatabase.GetBuildValue() + " CREDITS"; } else { string colorTag = "<color=white>"; if (cursorScript.buildCost > 0) { colorTag = "<color=red>"; } else if (cursorScript.buildCost < 0) { colorTag = "<color=lime>"; } buildStat = "TOTAL BUILD COST: " + "\n" + colorTag + statsDatabase.GetBuildCost() + " CREDITS</color>"; } display.text = "SHELL: " + totalHealths[0] + "\n" + "CORE: " + totalHealths[1] + "\n" + "ENERGY: " + totalHealths[2] + "\n" + "SPEED: " + (int)Craft.GetPhysicsSpeed(speed, weight) + "\n" + "WEIGHT: " + (int)weight + "\n" + buildStat; regenDisplay.text = "REGEN: " + totalRegens[0] + "\n\n" + "REGEN: " + totalRegens[2]; }
public void Initialize() { instance = this; string currentPath; var CurrentSavePath = System.IO.Path.Combine(Application.persistentDataPath, "CurrentSavePath"); if (!File.Exists(CurrentSavePath)) { currentPath = System.IO.Path.Combine(Application.persistentDataPath, "TestSave"); } else { currentPath = File.ReadAllLines(CurrentSavePath)[0]; } if (File.Exists(currentPath)) { // Load string json = File.ReadAllText(currentPath); save = JsonUtility.FromJson <PlayerSave>(json); if (save.timePlayed != 0) { player.spawnPoint = save.position; player.Dimension = save.lastDimension; } if (SectorManager.testJsonPath != null) { save.resourcePath = SectorManager.testJsonPath; } else if (save.resourcePath == "") { save.resourcePath = SectorManager.jsonPath; } player.cursave = save; if (save.factions != null) { for (int i = 0; i < save.factions.Length; i++) { FactionManager.SetFactionRelations(save.factions[i], save.relations[i]); } } SectorManager.instance.LoadSectorFile(save.resourcePath); save.missions.RemoveAll(m => !taskManager.questCanvasPaths.Exists(p => System.IO.Path.GetFileNameWithoutExtension(p) == m.name)); taskManager.Initialize(true); // Re-init DialogueSystem.InitCanvases(); player.blueprint = ScriptableObject.CreateInstance <EntityBlueprint>(); player.blueprint.name = "Player Save Blueprint"; if (!string.IsNullOrEmpty(save.currentPlayerBlueprint)) { var print = SectorManager.TryGettingEntityBlueprint(save.currentPlayerBlueprint); player.blueprint = print; } else { Debug.LogError("Save should have been given a currentPlayerBlueprint by now."); player.blueprint.parts = new List <EntityBlueprint.PartInfo>(); player.blueprint.coreSpriteID = "core1_light"; player.blueprint.coreShellSpriteID = "core1_shell"; player.blueprint.baseRegen = CoreUpgraderScript.GetRegens(player.blueprint.coreShellSpriteID); player.blueprint.shellHealth = CoreUpgraderScript.defaultHealths; } player.abilityCaps = save.abilityCaps; player.shards = save.shards; player.SetCredits(save.credits); player.reputation = save.reputation; if (save.presetBlueprints.Length != 5) { save.presetBlueprints = new string[5]; } Camera.main.GetComponent <CameraScript>().Initialize(player); taskManager.taskVariables.Clear(); for (int i = 0; i < save.taskVariableNames.Length; i++) { taskManager.taskVariables.Add(save.taskVariableNames[i], save.taskVariableValues[i]); } } else { Debug.LogError("There was not a save or test save that was ready on load."); save = new PlayerSave(); save.presetBlueprints = new string[5]; save.currentHealths = new float[] { 1000, 250, 500 }; save.partInventory = new List <EntityBlueprint.PartInfo>(); player.blueprint = ScriptableObject.CreateInstance <EntityBlueprint>(); player.blueprint.name = "Player Save Blueprint"; player.blueprint.coreSpriteID = "core1_light"; player.blueprint.coreShellSpriteID = "core1_shell"; player.blueprint.baseRegen = CoreUpgraderScript.GetRegens(player.blueprint.coreShellSpriteID); player.blueprint.shellHealth = CoreUpgraderScript.defaultHealths; player.blueprint.parts = new List <EntityBlueprint.PartInfo>(); player.cursave = save; player.abilityCaps = CoreUpgraderScript.minAbilityCap; } }
// Update is called once per frame void Update() { float[] totalHealths = CoreUpgraderScript.defaultHealths; float[] totalRegens = CoreUpgraderScript.GetRegens(cursorScript?.player?.blueprint?.coreShellSpriteID); float shipMass = 1; float enginePower = 200; float weight = Entity.coreWeight; float speed = Craft.initSpeed; foreach (DisplayPart part in statsDatabase.GetParts()) { switch (part.info.abilityID) { case 13: enginePower *= Mathf.Pow(1.1F, part.info.tier); speed += 15 * part.info.tier; break; case 17: totalRegens[0] += ShellRegen.regens[0] * part.info.tier; break; case 18: totalHealths[0] += ShellMax.maxes[0] * part.info.tier; break; case 19: totalRegens[2] += ShellRegen.regens[2] * part.info.tier; break; case 20: totalHealths[2] += ShellMax.maxes[2] * part.info.tier; break; case 22: totalRegens[1] += ShellRegen.regens[1] * part.info.tier; break; case 23: totalHealths[1] += ShellMax.maxes[1] * part.info.tier; break; } PartBlueprint blueprint = ResourceManager.GetAsset <PartBlueprint>(part.info.partID); totalHealths[0] += blueprint.health / 2; totalHealths[1] += blueprint.health / 4; shipMass += blueprint.mass; weight += blueprint.mass * Entity.weightMultiplier; } string buildStat; if (statsDatabase.GetMode() == BuilderMode.Yard || statsDatabase.GetMode() == BuilderMode.Workshop) { buildStat = $"\nTOTAL BUILD VALUE: \n{statsDatabase.GetBuildValue()} CREDITS"; } else { string colorTag = "<color=white>"; if (cursorScript.buildCost > 0) { colorTag = "<color=red>"; } else if (cursorScript.buildCost < 0) { colorTag = "<color=lime>"; } buildStat = $"TOTAL BUILD COST: \n{colorTag}{statsDatabase.GetBuildCost()} CREDITS</color>"; } string displayText = string.Join("\n", new string[] { $"SHELL: {totalHealths[0]}", $"CORE: {totalHealths[1]}", $"ENERGY: {totalHealths[2]}", $"SPEED: {(int)Craft.GetPhysicsSpeed(speed, weight)}", $"WEIGHT: {(int)weight}", buildStat }); display.text = displayText; regenDisplay.text = $"REGEN: {totalRegens[0]}\nREGEN: {totalRegens[1]}\nREGEN: {totalRegens[2]}"; }