public static bool GameLocation_performAction_Prefix(GameLocation __instance, string action, Farmer who, ref bool __result, Location tileLocation) { try { if (action.Split(' ')[0] == "Crib" && who.IsLocalPlayer) { Monitor.Log($"Acting on crib tile {tileLocation}"); FarmHouse farmHouse = __instance as FarmHouse; Microsoft.Xna.Framework.Rectangle?crib_location = farmHouse.GetCribBounds(); if (crib_location == null) { return(true); } for (int i = 0; i <= Misc.GetExtraCribs(); i++) { Microsoft.Xna.Framework.Rectangle rect = new Microsoft.Xna.Framework.Rectangle(crib_location.Value.X + i * 3, crib_location.Value.Y, crib_location.Value.Width, crib_location.Value.Height); if (rect.Contains(tileLocation.X, tileLocation.Y)) { Monitor.Log($"Acting on crib idx {i}"); using (List <NPC> .Enumerator enumerator = __instance.characters.GetEnumerator()) { while (enumerator.MoveNext()) { NPC j = enumerator.Current; if (j is Child) { if (rect.Contains(j.getTileLocationPoint())) { if ((j as Child).Age == 1) { Monitor.Log($"Tossing {j.Name}"); (j as Child).toss(who); } else if ((j as Child).Age == 0) { Monitor.Log($"{j.Name} is sleeping"); Game1.drawObjectDialogue(Game1.parseText(Game1.content.LoadString("Strings\\Locations:FarmHouse_Crib_NewbornSleeping", j.displayName))); } else if ((j as Child).isInCrib() && (j as Child).Age == 2) { Monitor.Log($"acting on {j.Name}"); return(j.checkAction(who, __instance)); } __result = true; return(false); } } } } __result = true; return(false); } } } } catch (Exception ex) { Monitor.Log($"Failed in {nameof(ManorHouse_performAction_Prefix)}:\n{ex}", LogLevel.Error); } return(true); }
internal static void ExpandKidsRoom(FarmHouse farmHouse) { ModEntry.PMonitor.Log("Expanding kids room"); //int extraWidth = Math.Max(ModEntry.config.ExtraCribs,0) * 3 + Math.Max(ModEntry.config.ExtraKidsRoomWidth, 0) + Math.Max(ModEntry.config.ExtraKidsBeds, 0) * 4; int extraWidth = Math.Max(ModEntry.config.ExtraKidsRoomWidth, 0); int roomWidth = 14; int height = 9; int startx = 15; int starty = 0; //int ox = ModEntry.config.ExistingKidsRoomOffsetX; int ox = 0; //int oy = ModEntry.config.ExistingKidsRoomOffsetY; int oy = 0; Map map = Helper.Content.Load <Map>("Maps\\" + farmHouse.Name + "2" + (Misc.GetSpouses(farmHouse.owner, 1).Count > 0? "_marriage":""), ContentSource.GameContent); List <string> sheets = new List <string>(); for (int i = 0; i < map.TileSheets.Count; i++) { sheets.Add(map.TileSheets[i].Id); } List <int> backIndexes = new List <int>(); List <int> frontIndexes = new List <int>(); List <int> buildIndexes = new List <int>(); List <int> backSheets = new List <int>(); List <int> frontSheets = new List <int>(); List <int> buildSheets = new List <int>(); for (int i = 0; i < roomWidth * height; i++) { backIndexes.Add(getTileIndexAt(map, ox + startx + (i % roomWidth), oy + starty + (i / roomWidth), "Back")); backSheets.Add(sheets.IndexOf(getTileSheetIDAt(map, ox + startx + (i % roomWidth), oy + starty + (i / roomWidth), "Back"))); frontIndexes.Add(getTileIndexAt(map, ox + startx + (i % roomWidth), oy + starty + (i / roomWidth), "Front")); frontSheets.Add(sheets.IndexOf(getTileSheetIDAt(map, ox + startx + (i % roomWidth), oy + starty + (i / roomWidth), "Front"))); buildIndexes.Add(getTileIndexAt(map, ox + startx + (i % roomWidth), oy + starty + (i / roomWidth), "Buildings")); buildSheets.Add(sheets.IndexOf(getTileSheetIDAt(map, ox + startx + (i % roomWidth), oy + starty + (i / roomWidth), "Buildings"))); } if (extraWidth > 0) { Monitor.Log("total width: " + (29 + ox + extraWidth)); ExtendMap(farmHouse, 29 + ox + extraWidth); } int k = 0; if (ModEntry.config.ExtraKidsRoomWidth > 0) { for (int j = 0; j < ModEntry.config.ExtraKidsRoomWidth - 1; j++) { k %= 3; for (int i = 0; i < height; i++) { int x = roomWidth + j + ox + startx - 2; int y = oy + starty + i; int xt = 4 + k; int yt = i; setupTile(x, y, xt, yt, farmHouse, frontIndexes, frontSheets, roomWidth, 0); setupTile(x, y, xt, yt, farmHouse, buildIndexes, buildSheets, roomWidth, 1); setupTile(x, y, xt, yt, farmHouse, backIndexes, backSheets, roomWidth, 2); } k++; } for (int i = 0; i < height; i++) { int x = startx + roomWidth + ox + extraWidth - 3; int y = oy + starty + i; int xt = roomWidth - 2; int yt = i; setupTile(x, y, xt, yt, farmHouse, frontIndexes, frontSheets, roomWidth, 0); setupTile(x, y, xt, yt, farmHouse, buildIndexes, buildSheets, roomWidth, 1); setupTile(x, y, xt, yt, farmHouse, backIndexes, backSheets, roomWidth, 2); } } // far wall for (int i = 0; i < height; i++) { int x = startx + roomWidth + ox + extraWidth - 2; int y = oy + starty + i; int xt = roomWidth - 1; int yt = i; setupTile(x, y, xt, yt, farmHouse, frontIndexes, frontSheets, roomWidth, 0); setupTile(x, y, xt, yt, farmHouse, buildIndexes, buildSheets, roomWidth, 1); setupTile(x, y, xt, yt, farmHouse, backIndexes, backSheets, roomWidth, 2); } // bottom barrier for (int i = 0; i < extraWidth; i++) { int x = startx + roomWidth + ox + i; Tile tile = farmHouse.map.GetLayer("Buildings").PickTile(new Location(x * Game1.tileSize, (9 + oy) * Game1.tileSize), Game1.viewport.Size); if (tile == null || tile.TileIndex == -1) { Monitor.Log($"Adding building tile at {startx + roomWidth + ox + i},{ 9 + oy}"); farmHouse.setMapTileIndex(x, 9 + oy, 0, "Buildings"); } } Microsoft.Xna.Framework.Rectangle?crib_location = farmHouse.GetCribBounds(); if (crib_location != null) { Monitor.Log($"Adding cribs"); for (int i = 0; i < Misc.GetExtraCribs(); i++) { Microsoft.Xna.Framework.Rectangle rect = new Microsoft.Xna.Framework.Rectangle(crib_location.Value.X + i * 3, crib_location.Value.Y, crib_location.Value.Width, crib_location.Value.Height); Monitor.Log($"Adding crib at {rect}"); Map override_map = Game1.game1.xTileContent.Load <Map>("Maps\\FarmHouse_Crib_" + farmHouse.cribStyle.Value); HashSet <string> amo = Helper.Reflection.GetField <HashSet <string> >(farmHouse, "_appliedMapOverrides").GetValue(); amo.Remove($"crib{i + 2}"); Helper.Reflection.GetField <HashSet <string> >(farmHouse, "_appliedMapOverrides").SetValue(amo); farmHouse.ApplyMapOverride(override_map, $"crib{i+2}", null, rect); } } }