internal void fixPlayerHouseWarp(StardewModdingAPI.Events.WarpedEventArgs e) { Farmer farmer = e.Player; FarmHouse house = (e.NewLocation as FarmHouse); //if(e.OldLocation is Farm) //{ // if (farmer.getTileLocationPoint() == house.getEntryLocation() || new Point(farmer.getTileLocationPoint().X, farmer.getTileLocationPoint().Y - 1) == house.getEntryLocation()) // { // Logger.Log("Player warped to the farmhouse, and was in the entry location. Setting player to modded entry (if any)..."); // Point entryPoint = FarmHouseStates.getEntryLocation(house); // farmer.setTileLocation(new Vector2(entryPoint.X, entryPoint.Y)); // } //} if (e.OldLocation is Cellar) { if (farmer.getTileLocationPoint() == new Point(4, 25) || farmer.getTileLocationPoint() == new Point(5, 24)) { Logger.Log("Player warped to the farmhouse from the cellar, and was in the cellar return location. Setting player to modded cellar return (if any)..."); Point cellarPoint = FarmHouseStates.getCellarLocation(house); if (cellarPoint != new Point(-1, -1)) { //farmer.setTileLocation(new Vector2(cellarPoint.X, cellarPoint.Y)); farmer.position.Value = new Vector2(cellarPoint.X * 64f, cellarPoint.Y * 64f); Logger.Log("Set player to " + cellarPoint.X + ", " + cellarPoint.Y); } } else { Logger.Log("Player warped to the farmhouse from the cellar, but was not in the cellar return location. Player was at " + farmer.getTileLocationPoint().X + ", " + farmer.getTileLocationPoint().Y); } } if (farmer.getTileLocationPoint() == house.getEntryLocation()) { Logger.Log("Player warped to the farmhouse, and was in the entry location. Setting player to modded entry (if any)..."); Point entryPoint = FarmHouseStates.getEntryLocation(house); farmer.position.Value = new Vector2(entryPoint.X * 64f, entryPoint.Y * 64f); //farmer.setTileLocation(new Vector2()); } else { Logger.Log("Player warped to the farmhouse, but was not at the entry location! Player is at " + farmer.getTileLocationPoint().ToString() + " as a point, and " + farmer.getTileLocation().ToString() + " as a Vector2" + ", not the entry location " + house.getEntryLocation().ToString()); Logger.Log("Player warped from " + e.OldLocation.name + "."); Logger.Log("House upgrade level is " + house.upgradeLevel + "."); if (FarmHouseStates.getState(house).entryData != null) { Logger.Log("House entry data is " + FarmHouseStates.getState(house).entryData); } else { Logger.Log("House entry data not initialized!"); } Logger.Log("Player physical centerpoint is (" + farmer.GetBoundingBox().Center.X + ", " + farmer.GetBoundingBox().Bottom + "), with a bounding box of " + farmer.GetBoundingBox().ToString()); } if (house is Cabin) { fixWarps(house as Cabin); } }
internal void fixPaths(NPC npc, FarmHouse house) { if (npc.getTileLocationPoint() == house.getEntryLocation()) { Logger.Log(npc.name + " entered at the entry point, repositioning at modded entry (if any)..."); npc.setTilePosition(FarmHouseStates.getEntryLocation(house)); } Logger.Log("Fixing paths for " + npc.name + "..."); if (npc.isMarried() && npc.getSpouse() == Game1.player) { Logger.Log(npc.name + " is married to " + Game1.player.name + "..."); if (npc.controller != null && npc.controller.endPoint != null && npc.controller.endPoint == house.getKitchenStandingSpot()) { Logger.Log(npc.name + " is pathing to the kitchen..."); npc.willDestroyObjectsUnderfoot = false; npc.controller = new PathFindController(npc, house, FarmHouseStates.getKitchenSpot(house), 0); if (npc.controller.pathToEndPoint == null) { npc.willDestroyObjectsUnderfoot = true; npc.controller = new PathFindController(npc, house, FarmHouseStates.getKitchenSpot(house), 0); npc.setNewDialogue(Game1.LoadStringByGender((int)((NetFieldBase <int, NetInt>)npc.gender), "Strings\\StringsFromCSFiles:NPC.cs.4500"), false, false); } else if (Game1.timeOfDay > 1300) { if (Game1.shortDayNameFromDayOfSeason(Game1.dayOfMonth).ToLower().Equals("mon") || Game1.shortDayNameFromDayOfSeason(Game1.dayOfMonth).ToLower().Equals("fri") && !npc.name.Equals((object)"Maru") && (!npc.name.Equals((object)"Penny") && !npc.name.Equals((object)"Harvey"))) { npc.setNewDialogue("MarriageDialogue", "funReturn_", -1, false, true); } else { npc.setNewDialogue("MarriageDialogue", "jobReturn_", -1, false, false); } } } else if (npc.controller != null && npc.controller.endPoint != null && npc.controller.endPoint == house.getSpouseBedSpot(npc.name)) { Logger.Log(npc.name + " is heading to bed..."); npc.willDestroyObjectsUnderfoot = false; npc.controller = new PathFindController(npc, house, FarmHouseStates.getBedSpot(house, true), 0); if (npc.controller.pathToEndPoint == null) { npc.willDestroyObjectsUnderfoot = true; npc.controller = new PathFindController(npc, house, FarmHouseStates.getBedSpot(house, true), 0); npc.setNewDialogue(Game1.LoadStringByGender((int)((NetFieldBase <int, NetInt>)npc.gender), "Strings\\StringsFromCSFiles:NPC.cs.4500"), false, false); } else if (Game1.timeOfDay > 1300) { if (Game1.shortDayNameFromDayOfSeason(Game1.dayOfMonth).ToLower().Equals("mon") || Game1.shortDayNameFromDayOfSeason(Game1.dayOfMonth).ToLower().Equals("fri") && !npc.name.Equals((object)"Maru") && (!npc.name.Equals((object)"Penny") && !npc.name.Equals((object)"Harvey"))) { npc.setNewDialogue("MarriageDialogue", "funReturn_", -1, false, true); } else { npc.setNewDialogue("MarriageDialogue", "jobReturn_", -1, false, false); } } } } }
public static void setFarmhouseCollision(Farm farm, Vector2 topLeft, FarmHouse house) { Map map = farm.map; Map collisionMap = getFarmHouseCollisionMap(house); //FarmHouseStates.loader.Load<Map>("assets/maps/Collision_FarmHouse.tbin", StardewModdingAPI.ContentSource.ModFolder); TileSheet sheet = null; foreach (TileSheet tSheet in map.TileSheets) { if (tSheet.ImageSource.Contains("outdoorsTileSheet")) { sheet = tSheet; break; } } if (sheet == null) { sheet = map.TileSheets[0]; Logger.Log("Could not find outdoor tilesheet! Defaulting to the first available tilesheet, '" + sheet.Id + "'..."); } string houseWarp = "Warp " + FarmHouseStates.getEntryLocation(house).X + " " + FarmHouseStates.getEntryLocation(house).Y + " FarmHouse"; Logger.Log("House warp set to '" + houseWarp + "'"); Logger.Log("Finding the front door on the collision map for the farmhouse..."); Vector2 frontDoor = new Vector2(-1, -1); for (int x = 0; x < collisionMap.GetLayer("Buildings").LayerWidth; x++) { for (int y = 0; y < collisionMap.GetLayer("Buildings").LayerHeight; y++) { if (collisionMap.GetLayer("Buildings").Tiles[x, y] != null && collisionMap.GetLayer("Buildings").Tiles[x, y].Properties.ContainsKey("Action")) { string tileAction = collisionMap.GetLayer("Buildings").Tiles[x, y].Properties["Action"].ToString(); if (tileAction.Contains("Warp") && tileAction.Contains("FarmHouse")) { Logger.Log("Found the front door! Located at (" + x + ", " + y + ")"); frontDoor = new Vector2(x, y); break; } } } if (frontDoor.X != -1) { break; } } if (frontDoor.X == -1) { frontDoor = new Vector2(5, 4); } topLeft.X -= frontDoor.X; topLeft.Y -= frontDoor.Y; bool useDefaultPorch = true; if (collisionMap.Properties.ContainsKey("Porch")) { string porchProperty = Utility.cleanup(collisionMap.Properties["Porch"]); string[] coords = porchProperty.Split(' '); if (coords.Length >= 2) { Vector2 coordsFromString = getCoordsFromString(porchProperty); porchStandingLocation = new Point((int)(coordsFromString.X + topLeft.X), (int)(coordsFromString.Y + topLeft.Y)); Logger.Log("Found valid porch property; porch is now at " + porchStandingLocation.ToString()); useDefaultPorch = false; } } if (useDefaultPorch) { porchStandingLocation = new Point((int)topLeft.X + 7, (int)topLeft.Y + 5); } chimneys.Clear(); for (int x = 0; x < collisionMap.GetLayer("Back").LayerWidth; x++) { for (int y = 0; y < collisionMap.GetLayer("Back").LayerHeight; y++) { Vector2 currentTile = new Vector2(x + topLeft.X, y + topLeft.Y); if (collisionMap.GetLayer("Back").Tiles[x, y] != null) { if (map.GetLayer("Back").Tiles[x + (int)topLeft.X, y + (int)topLeft.Y] == null) { map.GetLayer("Back").Tiles[x + (int)topLeft.X, y + (int)topLeft.Y] = new StaticTile(map.GetLayer("Back"), sheet, BlendMode.Alpha, 16); } foreach (string key in collisionMap.GetLayer("Back").Tiles[x, y].Properties.Keys) { map.GetLayer("Back").Tiles[x + (int)topLeft.X, y + (int)topLeft.Y].Properties[key] = collisionMap.GetLayer("Back").Tiles[x, y].Properties[key]; } } if (collisionMap.GetLayer("Buildings").Tiles[x, y] != null) { if (map.GetLayer("Buildings").Tiles[x + (int)topLeft.X, y + (int)topLeft.Y] == null) { map.GetLayer("Buildings").Tiles[x + (int)topLeft.X, y + (int)topLeft.Y] = new StaticTile(map.GetLayer("Buildings"), sheet, BlendMode.Alpha, 16); } if (collisionMap.GetLayer("Buildings").Tiles[x, y].TileSheet == sheet && collisionMap.GetLayer("Buildings").Tiles[x, y].TileIndex == 125) { map.GetLayer("Buildings").Tiles[x + (int)topLeft.X, y + (int)topLeft.Y].Properties["Passable"] = "T"; } foreach (string key in collisionMap.GetLayer("Buildings").Tiles[x, y].Properties.Keys) { if (key.Equals("Action")) { string warpValue = collisionMap.GetLayer("Buildings").Tiles[x, y].Properties[key].ToString(); if (warpValue.Contains("Warp") && warpValue.Contains("FarmHouse")) { map.GetLayer("Buildings").Tiles[x + (int)topLeft.X, y + (int)topLeft.Y].Properties[key] = houseWarp; } } else if (key.Equals("Chimney")) { Logger.Log("Found a chimney at tile (" + x + ", " + y + ")"); string chimneyValue = collisionMap.GetLayer("Buildings").Tiles[x, y].Properties[key].ToString(); if (chimneyValue.Split(' ').Length == 1) { Vector2 newChimney = new Vector2((topLeft.X + x + 0.5f) * 64f, (topLeft.Y + y + 0.5f) * 64f); Logger.Log("Chimney did not specify pixel coordinates; using tile center instead: " + newChimney.ToString()); chimneys.Add(newChimney); } else { Vector2 chimneyPosition = getCoordsFromString(chimneyValue); Vector2 newChimney = new Vector2((topLeft.X + x) * 64f + chimneyPosition.X, (topLeft.Y + y) * 64f + chimneyPosition.Y); Logger.Log("Chimney did specified pixel coordinates; " + chimneyPosition.ToString() + ": " + newChimney.ToString()); chimneys.Add(newChimney); } } else { map.GetLayer("Buildings").Tiles[x + (int)topLeft.X, y + (int)topLeft.Y].Properties[key] = collisionMap.GetLayer("Buildings").Tiles[x, y].Properties[key]; } } removeEverythingFromTile(farm, currentTile); } //else if(map.GetLayer("Buildings").Tiles[x + (int)topLeft.X, y + (int)topLeft.Y] != null) //{ // map.GetLayer("Buildings").Tiles[x + (int)topLeft.X, y + (int)topLeft.Y] = null; //} if (castsShadow(collisionMap, x, y) && (y == collisionMap.GetLayer("Buildings").LayerHeight - 1 || !castsShadow(collisionMap, x, y + 1))) { Logger.Log("Tile (" + x + ", " + y + ") casts a shadow..."); if (x == 0 || !castsShadow(collisionMap, x - 1, y)) { Logger.Log("Shadow is on the LEFT"); buildingShadows[new Vector2(x + (int)topLeft.X, y + (int)topLeft.Y)] = SHADOW_LEFT; } else if (x == collisionMap.GetLayer("Back").LayerWidth - 1 || !castsShadow(collisionMap, x + 1, y)) { Logger.Log("Shadow is on the RIGHT"); buildingShadows[new Vector2(x + (int)topLeft.X, y + (int)topLeft.Y)] = SHADOW_RIGHT; } else { buildingShadows[new Vector2(x + (int)topLeft.X, y + (int)topLeft.Y)] = SHADOW_MID; } } } } }