public void LoadFromString(string savestring) { string[] savedata = Regex.Split(savestring, "--"); List <Item> itemList = new List <Item>(); SerializableDictionary <Vector2, StardewValley.Object> objects = new SerializableDictionary <Vector2, StardewValley.Object>(); for (int i = 1; i < savedata.Length; i++) { string[] entry = Regex.Split(savedata[i], ";;;"); int row = (int)Math.Floor(craftables[2] / 24.0); int col = craftables[2] % 24; if (entry[0] == "Tracks") { if (Game1.getLocationFromName(entry[1]).terrainFeatures.ContainsKey(new Vector2(int.Parse(entry[4]), int.Parse(entry[5])))) { Game1.getLocationFromName(entry[1]).terrainFeatures.Remove(new Vector2(int.Parse(entry[4]), int.Parse(entry[5]))); } RailroadTrack rt = new RailroadTrack(row, col); Game1.getLocationFromName(entry[1]).terrainFeatures.Add(new Vector2(int.Parse(entry[4]), int.Parse(entry[5])), rt); LoadData.terrainFeatureList.Add(rt); continue; } if (entry[3] != "-1") { if (entry[1] == "Inventory") { itemList = Game1.player.items; } else if (entry[2] == "-1") { itemList = (Game1.getLocationFromName(entry[1]).objects[new Vector2(int.Parse(entry[4]), int.Parse(entry[4]))] as Chest).items; } else { itemList = ((Game1.getLocationFromName(entry[1]) as BuildableGameLocation).buildings[int.Parse(entry[2])].indoors.objects[new Vector2(int.Parse(entry[4]), int.Parse(entry[5]))] as Chest).items; } Item slot = itemList[int.Parse(entry[3])]; if (entry[0] == "CraftedTracks") { itemList[int.Parse(entry[3])] = new StardewValley.Object(craftables[0], slot.Stack); } else if (entry[0] == "CraftedJunimo") { itemList[int.Parse(entry[3])] = new StardewValley.Object(craftables[1], slot.Stack); } if (entry[0] == "LinkedChest") { LinkedChest newLinkedChest = new LinkedChest(Game1.getLocationFromName(entry[1]), true, true); newLinkedChest.inList = (slot as Chest).items; newLinkedChest.index = int.Parse(entry[3]); newLinkedChest.location = Game1.getLocationFromName(entry[1]); newLinkedChest.building = int.Parse(entry[2]); newLinkedChest.tileLocation = new Vector2(int.Parse(entry[4]), int.Parse(entry[5])); newLinkedChest.playerChoiceColor = (slot as Chest).playerChoiceColor; Item[] items = new Item[(slot as Chest).items.Count]; (slot as Chest).items.CopyTo(items); newLinkedChest.items = new List <Item>(items); newLinkedChest.objectID = int.Parse(entry[6]); if (int.Parse(entry[6]) > 0) { int findJunimo = objectlist.FindIndex(x => x is JunimoHelper && (x as JunimoHelper).objectID == int.Parse(entry[6])); if (findJunimo >= 0) { newLinkedChest.linkedJunimo = (JunimoHelper)objectlist[findJunimo]; newLinkedChest.linkedJunimo.targetChest = newLinkedChest; } } itemList[int.Parse(entry[3])] = newLinkedChest; objectlist.Add(newLinkedChest); } } else { if (entry[2] == "-1") { objects = Game1.getLocationFromName(entry[1]).objects; } else { objects = (Game1.getLocationFromName(entry[1]) as BuildableGameLocation).buildings[int.Parse(entry[2])].indoors.objects; } Chest slot = (Chest)objects[new Vector2(int.Parse(entry[4]), int.Parse(entry[5]))]; if (entry[0] == "LinkedChest") { LinkedChest newLinkedChest = new LinkedChest(Game1.getLocationFromName(entry[1]), false, true); newLinkedChest.inventory = false; newLinkedChest.index = -1; newLinkedChest.location = Game1.getLocationFromName(entry[1]); newLinkedChest.building = int.Parse(entry[2]); if (newLinkedChest.building > 0) { newLinkedChest.location = (Game1.getLocationFromName(entry[1]) as BuildableGameLocation).buildings[newLinkedChest.building].indoors; newLinkedChest.bgl = (BuildableGameLocation)Game1.getLocationFromName(entry[1]); } newLinkedChest.tileLocation = new Vector2(int.Parse(entry[4]), int.Parse(entry[5])); newLinkedChest.playerChoiceColor = (slot as Chest).playerChoiceColor; Item[] items = new Item[(slot as Chest).items.Count]; (slot as Chest).items.CopyTo(items); newLinkedChest.items = new List <Item>(items); newLinkedChest.objectID = int.Parse(entry[6]); if (int.Parse(entry[6]) > 0) { int findJunimo = objectlist.FindIndex(x => x is JunimoHelper && (x as JunimoHelper).objectID == int.Parse(entry[6])); if (findJunimo >= 0) { newLinkedChest.linkedJunimo = (JunimoHelper)objectlist[findJunimo]; newLinkedChest.linkedJunimo.targetChest = newLinkedChest; } } objects[new Vector2(int.Parse(entry[4]), int.Parse(entry[5]))] = newLinkedChest; objectlist.Add(newLinkedChest); } else if (entry[0] == "JunimoHelper") { JunimoHelper newJunimo = new JunimoHelper(Game1.getLocationFromName(entry[1]), new Vector2(int.Parse(entry[4]), int.Parse(entry[5])), craftables[3], false); newJunimo.color = (slot as Chest).playerChoiceColor; newJunimo.index = -1; if (entry.Length > 7) { newJunimo.direction = int.Parse(entry[7]); } newJunimo.location = Game1.getLocationFromName(entry[1]); newJunimo.building = int.Parse(entry[2]); if (newJunimo.building > 0) { newJunimo.location = (Game1.getLocationFromName(entry[1]) as BuildableGameLocation).buildings[newJunimo.building].indoors; newJunimo.bgl = (BuildableGameLocation)Game1.getLocationFromName(entry[1]); } newJunimo.tileLocation = new Vector2(int.Parse(entry[4]), int.Parse(entry[5])); Item[] items = new Item[(slot as Chest).items.Count]; (slot as Chest).items.CopyTo(items); newJunimo.itemChest.items = new List <Item>(items); newJunimo.objectID = int.Parse(entry[6]); if (int.Parse(entry[6]) > 0) { int findChest = objectlist.FindIndex(x => x is LinkedChest && (x as LinkedChest).objectID == int.Parse(entry[6])); if (findChest >= 0) { newJunimo.targetChest = (LinkedChest)objectlist[findChest]; newJunimo.targetChest.linkedJunimo = newJunimo; } } objects[new Vector2(int.Parse(entry[4]), int.Parse(entry[5]))] = newJunimo; objectlist.Add(newJunimo); } } } }
private void transform() { GameLocation gl = Game1.currentLocation; List <Vector2> vl = new List <Vector2>(); List <Vector2> vl2 = new List <Vector2>(); List <Vector2> vl3 = new List <Vector2>(); List <Vector2> vl4 = new List <Vector2>(); Dictionary <Vector2, StardewValley.Object> allObjects = gl.objects; List <Vector2> sVectors = new List <Vector2>(); Vector2 check = new Vector2(0, 0); Vector2 pPosition = new Vector2(Game1.player.getTileLocation().X, Game1.player.getTileLocation().Y); for (float i = -3; i <= 3.0; i++) { for (float j = -3; j <= 3.0; j++) { check = (new Vector2(i, j) + pPosition); if (allObjects.ContainsKey(check) && allObjects[check].name == "Tracks") { vl.Add(check); } if (allObjects.ContainsKey(check) && allObjects[check].name == "Junimo Helper") { vl2.Add(check); } if (allObjects.ContainsKey(check) && allObjects[check] is Chest && (allObjects[check] as Chest).items.Count == 1 && !(allObjects[check] is LinkedChest) && (allObjects[check] as Chest).items.FindIndex(x => (x is StardewValley.Object) && x.Name == "Junimo Helper") >= 0) { vl4.Add(check); } if (allObjects.ContainsKey(check) && allObjects[check] is JunimoHelper) { if ((allObjects[check] as JunimoHelper).targetChest == null) { vl3.Add(check); } } } } for (int i = 0; i < vl4.Count; i++) { LinkedChest newChest = new LinkedChest(true); (allObjects[vl4[i]] as Chest).items.RemoveAt(0); allObjects.Remove(vl4[i]); allObjects.Add(vl4[i], newChest); newChest.tileLocation = vl4[i]; newChest.linkedJunimo = null; newChest.objectID = -1; LoadData.objectlist.Add(newChest); Game1.activeClickableMenu.exitThisMenu(); } for (int i = 0; i < vl.Count; i++) { int row = (int)Math.Floor(this.textureOriginTracks / 24.0); int col = this.textureOriginTracks % 24; if (!gl.terrainFeatures.ContainsKey(vl[i]) && Game1.currentLocation.name == "Farm") { TerrainFeature t = new RailroadTrack(row, col); gl.terrainFeatures.Add(vl[i], t); LoadData.terrainFeatureList.Add(t); } else { Game1.player.addItemToInventory(gl.objects[vl[i]]); } gl.objects.Remove(vl[i]); } for (int i = 0; i < vl2.Count; i++) { gl.objects.Remove(vl2[i]); JunimoHelper junimo = new JunimoHelper(vl2[i], this.textureOriginHelper, false); gl.objects.Add(vl2[i], junimo); LoadData.objectlist.Add(junimo); } for (int i = 0; i < vl3.Count; i++) { (gl.objects[vl3[i]] as JunimoHelper).checkForChest(); } }