Beispiel #1
0
        internal void saveLoaded(object sender, StardewModdingAPI.Events.SaveLoadedEventArgs e)
        {
            //Game1.getFarm().grandpaScore.Value = 3;
            reloadStaticClasses();
            FarmHouseStates.harmony.Patch(
                original: AccessTools.Method(typeof(Farm), nameof(Farm.draw)),
                transpiler: new HarmonyMethod(AccessTools.Method(typeof(Farm_draw_Patch), nameof(Farm_draw_Patch.Transpiler))),
                postfix: new HarmonyMethod(AccessTools.Method(typeof(Farm_draw_Patch), nameof(Farm_draw_Patch.Postfix)))
                );
            FarmHouseStates.harmony.Patch(
                original: AccessTools.Method(typeof(Farm), nameof(Farm.leftClick)),
                transpiler: new HarmonyMethod(AccessTools.Method(typeof(Farm_leftClick_Patch), nameof(Farm_leftClick_Patch.Transpiler)))
                );
            FarmHouseStates.harmony.Patch(
                original: AccessTools.Method(typeof(Farm), nameof(Farm.checkAction)),
                transpiler: new HarmonyMethod(AccessTools.Method(typeof(Farm_checkAction_Patch), nameof(Farm_checkAction_Patch.Transpiler)))
                );
            FarmHouseStates.harmony.Patch(
                original: AccessTools.Method(typeof(Farm), nameof(Farm.addGrandpaCandles)),
                transpiler: new HarmonyMethod(AccessTools.Method(typeof(Farm_addGrandpaCandles_Patch), nameof(Farm_addGrandpaCandles_Patch.Transpiler)))
                );

            foreach (Farmer player in Game1.getAllFarmers())
            {
                if (player.currentLocation != null && player.currentLocation is FarmHouse)
                {
                    Logger.Log("Current location is a farmhouse; getting bed spot from this farmhouse.");
                    player.mostRecentBed  = StardewValley.Utility.PointToVector2(FarmHouseStates.getBedSpot(player.currentLocation as FarmHouse)) * 64f;
                    player.position.Value = new StardewValley.Network.NetPosition(new NetVector2(player.mostRecentBed));
                    player.position.X    -= 64f;
                    player.position.Y    += 32f;
                }
                Logger.Log(player.Name + "'s most recent bed: " + player.mostRecentBed.ToString());
            }
        }
Beispiel #2
0
        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);
            }
        }
Beispiel #3
0
        private void GameLoop_GameLaunched(object sender, StardewModdingAPI.Events.GameLaunchedEventArgs e)
        {
            ObjectIDHelper.init();
            //FarmHouseStates.harmony.Patch(
            //    original: Helper.Reflection.GetMethod(new FarmHouse(), "doSetVisibleFloor").MethodInfo,
            //    prefix: new HarmonyMethod(AccessTools.Method(typeof(FarmHouse_doSetVisibleFloor_Patch), nameof(FarmHouse_doSetVisibleFloor_Patch.Prefix)))
            //);
            //Farmer Patches
            //FarmHouseStates.harmony.Patch(
            //    original: typeof(Farmer).GetConstructor(new Type[]
            //    {
            //        typeof(FarmerSprite),
            //        typeof(Vector2),
            //        typeof(int),
            //        typeof(string),
            //        typeof(List<Item>),
            //        typeof(bool)
            //    }),
            //    postfix: new HarmonyMethod(AccessTools.Method(typeof(Farmer_Ctor_Patch), nameof(Farmer_Ctor_Patch.Postfix)))
            //);

            FarmState.init();
            FarmHouseStates.init();
            OtherLocations.DecoratableStates.init();
            OtherLocations.FakeDecor.FakeDecorHandler.init();
        }
Beispiel #4
0
 public static void Postfix(Farmer who, Pet __instance)
 {
     if (__instance.isSleepingOnFarmerBed && __instance.currentLocation is FarmHouse)
     {
         __instance.position.Value = (StardewValley.Utility.PointToVector2(FarmHouseStates.getBedSpot(StardewValley.Utility.getHomeOfFarmer(who))) + new Microsoft.Xna.Framework.Vector2(-1f, 0f)) * 64f;
     }
 }
Beispiel #5
0
 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);
                 }
             }
         }
     }
 }
Beispiel #6
0
 private void Display_RenderedWorld(object sender, StardewModdingAPI.Events.RenderedWorldEventArgs e)
 {
     if (FarmHouseStates.getState(StardewValley.Utility.getHomeOfFarmer(Game1.player)) != null)
     {
         //FarmHouseStates.drawRender(e.SpriteBatch);
         //e.SpriteBatch.Draw(Image.Renderer.testRender, Vector2.Zero, new Rectangle(0, 0, Image.Renderer.testRender.Width, Image.Renderer.testRender.Height), Color.White, 0.0f, Vector2.Zero, 4f, Microsoft.Xna.Framework.Graphics.SpriteEffects.None, 1);
     }
 }
Beispiel #7
0
 internal void setPlayerByBed(FarmHouse house)
 {
     if (Game1.player.currentLocation.Equals(house))
     {
         Point   bedPoint    = FarmHouseStates.getBedSpot(house, false);
         Vector2 bedLocation = new Vector2(bedPoint.X, bedPoint.Y);
         Game1.player.setTileLocation(bedLocation);
         Logger.Log("Bed set to " + bedLocation.ToString());
     }
 }
        internal static bool Prefix(int which, int whichRoom, bool persist, DecoratableLocation __instance)
        {
            if (!(__instance is FarmHouse) || __instance is Cabin)
            {
                return(true);
            }
            List <Microsoft.Xna.Framework.Rectangle> floors = __instance.getFloors();

            if (!persist)
            {
                return(true);
            }

            if (__instance.floor.Count < floors.Count)
            {
                FarmHouseStates.setMissingFloorsToDefault(__instance as FarmHouse);
            }

            //__instance.floor.SetCountAtLeast(floors.Count);
            if (whichRoom == -1)
            {
                for (int index = 0; index < __instance.floor.Count; ++index)
                {
                    __instance.floor[index] = which;
                }
            }
            else
            {
                if (whichRoom > __instance.floor.Count - 1 || whichRoom >= floors.Count)
                {
                    return(false);
                }
                if (FarmHouseStates.floorDictionary.ContainsKey(floors[whichRoom]))
                {
                    string roomLabel = FarmHouseStates.floorDictionary[floors[whichRoom]];
                    Logger.Log("Finding all floors for room '" + roomLabel + "'...");
                    foreach (KeyValuePair <Rectangle, string> floorData in FarmHouseStates.floorDictionary)
                    {
                        if (floors.Contains(floorData.Key) && floorData.Value == roomLabel)
                        {
                            Logger.Log(floors.IndexOf(floorData.Key) + " was a part of " + roomLabel);
                            __instance.floor[floors.IndexOf(floorData.Key)] = which;
                        }
                    }
                }
                else
                {
                    __instance.floor[whichRoom] = which;
                }
            }
            return(false);
        }
Beispiel #9
0
        //internal void drawStuff(object sender, StardewModdingAPI.Events.RenderedHudEventArgs e)
        //{
        //    FarmHouseStates.testCaster.draw(e.SpriteBatch);
        //}

        internal void reloadStaticClasses()
        {
            Logger.Log("Reloading static classes...");
            FarmHouseStates.init();
            FarmHouseStates.clearAll();
            FarmState.init();
            FarmState.setUpFarm(Game1.getFarm());
            OtherLocations.DecoratableStates.init();
            OtherLocations.DecoratableStates.clearAll();
            OtherLocations.FakeDecor.FakeDecorHandler.init();
            //FarmHouseStates.render = FarmHouseStates.renderFarmHouse(Utility.getHomeOfFarmer(Game1.player));
            Logger.Log("House location is " + FarmState.houseLocation.ToString());
            Logger.Log("getPorchStandingSpot() returned " + FarmState.getPorchStandingSpot().ToString());
        }
Beispiel #10
0
        internal void newDay(object sender, EventArgs e)
        {
            FarmHouse house = (Game1.getLocationFromName("FarmHouse") as FarmHouse);

            FarmHouseStates.clear();
            fixVoidObjects(house);
            setPlayerByBed(house);
            fixSpousePosition(house);
            foreach (NPC npc in house.characters)
            {
                if (npc.isMarried() && npc.getSpouse().Equals(Game1.player))
                {
                    fixPaths(npc, house);
                }
            }
        }
Beispiel #11
0
        internal void fixSpousePosition(FarmHouse house)
        {
            if (!Game1.player.isMarried() || Game1.player.getSpouse().currentLocation != house)
            {
                return;
            }
            NPC spouse = Game1.player.getSpouse();

            if (spouse.getTileLocationPoint() == house.getKitchenStandingSpot())
            {
                //Spouse was placed at the kitchen standing spot, move them to modded one.
                Logger.Log("Spouse was in kitchen standing spot...");
                Point kitchenLocation = FarmHouseStates.getKitchenSpot(house);
                spouse.setTilePosition(kitchenLocation);
                Logger.Log(spouse.name + " was moved to " + kitchenLocation.ToString());
            }
            else if (isSpouseInSpouseRoom(spouse, house))
            {
                Logger.Log(spouse.name + " began the day in the spouse room...");
                FarmHouseState state = FarmHouseStates.getState(house);
                if (state.spouseRoomData == null)
                {
                    FarmHouseStates.updateFromMapPath(house, house.mapPath);
                }
                if (state.spouseRoomData != "")
                {
                    Logger.Log("Map defined spouse room location...");
                    string[] spouseRoomPoint    = state.spouseRoomData.Split(' ');
                    Vector2  spouseRoomLocation = new Vector2(Convert.ToInt32(spouseRoomPoint[0]) + 3, Convert.ToInt32(spouseRoomPoint[1]) + 4);
                    spouse.setTileLocation(spouseRoomLocation);
                    Logger.Log(spouse.name + " was moved to " + spouseRoomLocation.ToString());
                }
                else
                {
                    Logger.Log("Map did not define spouse room location.");
                }
            }
            else if (!house.isTileLocationOpen(new xTile.Dimensions.Location(spouse.getTileX(), spouse.getTileY())))
            {
                Logger.Log(spouse.name + " was in the void or was stuck, relocating...");
                spouse.setTilePosition(house.getRandomOpenPointInHouse(Game1.random));
            }
        }
 public static void Postfix(Farmer __instance)
 {
     Logger.Log("Running constructor patch...");
     Logger.Log("Current bed before patch is " + __instance.mostRecentBed.ToString());
     if (__instance.currentLocation != null && __instance.currentLocation is FarmHouse)
     {
         Logger.Log("Current location is a farmhouse; getting bed spot from this farmhouse.");
         __instance.mostRecentBed = StardewValley.Utility.PointToVector2(FarmHouseStates.getBedSpot(__instance.currentLocation as FarmHouse)) * 64f;
     }
     else
     {
         Logger.Log("Current location was not a farmhouse; getting bed spot from " + __instance.name + "'s farmhouse...");
         foreach (GameLocation location in Game1.locations)
         {
             if (location is FarmHouse && (location as FarmHouse).owner == __instance)
             {
                 Logger.Log("Found " + __instance.name + "'s farmhouse.");
                 __instance.mostRecentBed = StardewValley.Utility.PointToVector2(FarmHouseStates.getBedSpot(location as FarmHouse)) * 64f;
             }
         }
     }
     Logger.Log("Most recent bed: " + __instance.mostRecentBed.ToString());
 }
Beispiel #13
0
        public static Point getBedSpot(StardewValley.Locations.FarmHouse house, bool spouse = false)
        {
            Logger.Log("Getting bed location...");
            if (bedData == null)
            {
                FarmHouseStates.updateFromMapPath(house.mapPath);
            }
            if (FarmHouseStates.bedData != "")
            {
                Logger.Log("Map defined bed location...");
                string[] bedPoint = FarmHouseStates.bedData.Split(' ');

                return(new Point(Convert.ToInt32(bedPoint[0]) + (spouse ? 2 : 0), Convert.ToInt32(bedPoint[1])));
            }
            else
            {
                Logger.Log("Map did not define a bed location, using vanilla.");
                if (spouse)
                {
                    return(house.getSpouseBedSpot());
                }
                return(house.getBedSpot());
            }
        }
Beispiel #14
0
        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;
                        }
                    }
                }
            }
        }
        internal static bool Prefix(int which, int whichRoom, bool persist, DecoratableLocation __instance)
        {
            if (!(__instance is FarmHouse) || __instance is Cabin)
            {
                return(true);
            }
            List <Microsoft.Xna.Framework.Rectangle> walls = __instance.getWalls();

            if (!persist)
            {
                return(true);
            }

            Logger.Log("Checking wallpaper indexes before SetCountAtLeast...");
            for (int wallIndex = 0; wallIndex < __instance.wallPaper.Count; wallIndex++)
            {
                Logger.Log("Wall " + wallIndex + " has a wallpaper index of " + __instance.wallPaper[wallIndex] + ".");
            }

            if (__instance.wallPaper.Count < walls.Count)
            {
                FarmHouseStates.setMissingWallpaperToDefault(__instance as FarmHouse);
            }
            //__instance.wallPaper.SetCountAtLeast(walls.Count);

            Logger.Log("Checking wallpaper indexes after SetCountAtLeast...");
            for (int wallIndex = 0; wallIndex < __instance.wallPaper.Count; wallIndex++)
            {
                Logger.Log("Wall " + wallIndex + " has a wallpaper index of " + __instance.wallPaper[wallIndex] + ".");
            }
            if (whichRoom == -1)
            {
                Logger.Log("Whichroom was -1, applying to all walls...");
                for (int index = 0; index < __instance.wallPaper.Count; ++index)
                {
                    __instance.wallPaper[index] = which;
                }
            }
            else
            {
                Logger.Log("Setting wallpaper to " + which + "...");
                if (whichRoom > __instance.wallPaper.Count - 1 || whichRoom >= walls.Count)
                {
                    return(false);
                }
                if (FarmHouseStates.wallDictionary.ContainsKey(walls[whichRoom]))
                {
                    string roomLabel = FarmHouseStates.wallDictionary[walls[whichRoom]];
                    Logger.Log("Finding all walls for room '" + roomLabel + "'...");
                    foreach (KeyValuePair <Rectangle, string> wallData in FarmHouseStates.wallDictionary)
                    {
                        if (walls.Contains(wallData.Key) && wallData.Value == roomLabel)
                        {
                            Logger.Log(walls.IndexOf(wallData.Key) + " was a part of " + roomLabel);
                            __instance.wallPaper[walls.IndexOf(wallData.Key)] = which;
                        }
                    }
                }
                else
                {
                    __instance.wallPaper[whichRoom] = which;
                }
            }
            return(false);
        }
Beispiel #16
0
        internal void fixVoidObjects(FarmHouse house)
        {
            FarmHouseStates.fixObjectsOnMap(house);
            //Todo: Find all loose items and put them in a gift box
            List <Item> itemsToStore = new List <Item>();

            //for(int x = 0; x < house.map.GetLayer("Back").LayerWidth; x++)
            //{
            //    for(int y = 0; y < house.map.GetLayer("Back").LayerHeight; y++)
            //    {

            //    }
            //}
            Logger.Log("Fixing void objects...");
            Dictionary <Vector2, Vector2> replacementCoordinates = new Dictionary <Vector2, Vector2>();
            List <Vector2> deadObjects = new List <Vector2>();

            foreach (KeyValuePair <Vector2, StardewValley.Object> objectPair in house.objects.Pairs)
            {
                bool canBePlaced = isObjectSpotValid(objectPair.Value, objectPair.Key, house);
                Logger.Log("Tile blocked? " + (house.isTileOnMap(objectPair.Key) && !canBePlaced).ToString());
                if (house.isTileOnMap(objectPair.Key) && !canBePlaced)
                {
                    Logger.Log("Tile " + objectPair.Key.ToString() + " was not placeable!  Moving object...");
                    Point newSpot  = house.getRandomOpenPointInHouse(Game1.random);
                    int   attempts = 0;
                    while ((newSpot == Point.Zero || !objectPair.Value.canBePlacedHere(house, new Vector2(newSpot.X, newSpot.Y))) && attempts < 20)
                    {
                        newSpot = house.getRandomOpenPointInHouse(Game1.random);
                        attempts++;
                        Logger.Log("Failed to find empty open spot in the farmhouse for an object.  Attempt #" + attempts);
                    }
                    Logger.Log("Finished selecting spots.");
                    if (newSpot == Point.Zero)
                    {
                        Logger.Log("Could not find a suitable location for an object.  Storing it in a gift box.");
                        if (objectPair.Value is StardewValley.Objects.Chest)
                        {
                            StardewValley.Objects.Chest chest = (objectPair.Value as StardewValley.Objects.Chest);
                            Logger.Log("Object to be stored is a chest, so the contents will be stored separately.");
                            foreach (Item item in chest.items)
                            {
                                itemsToStore.Add(item);
                            }
                        }
                        itemsToStore.Add(objectPair.Value);
                        deadObjects.Add(objectPair.Key);
                    }
                    else
                    {
                        Vector2 tileLocation = new Vector2(newSpot.X, newSpot.Y);
                        replacementCoordinates[tileLocation] = objectPair.Key;
                        objectPair.Value.tileLocation.Value  = tileLocation;
                        deadObjects.Add(objectPair.Key);
                        Logger.Log("Placing object at " + tileLocation.ToString());
                    }
                }
                else
                {
                    Logger.Log("Skipping " + objectPair.Key.ToString() + " because it " + (house.isTileOnMap(objectPair.Key) ? "was on the map, and " : "was not on the map, and ") + (!canBePlaced ? "was not placeable." : "was placeable."));
                }
            }
            foreach (KeyValuePair <Vector2, Vector2> replacementPair in replacementCoordinates)
            {
                if (!house.objects.ContainsKey(replacementPair.Key))
                {
                    house.objects.Add(replacementPair.Key, house.objects[replacementPair.Value]);
                }
            }
            foreach (Vector2 deadObject in deadObjects)
            {
                house.objects.Remove(deadObject);
            }

            List <StardewValley.Objects.Furniture> deadFurniture = new List <StardewValley.Objects.Furniture>();

            foreach (StardewValley.Objects.Furniture furniture in house.furniture)
            {
                bool canBePlaced = isFurnitureSpotValid(furniture, house);
                Logger.Log("Tile blocked? " + (!house.isTileOnMap(furniture.tileLocation) || !canBePlaced).ToString());
                fixFurniture(furniture, house, ref deadFurniture, ref itemsToStore);
            }
            foreach (StardewValley.Objects.Furniture furniture in deadFurniture)
            {
                house.furniture.Remove(furniture);
            }

            Point chestSpot = house.getRandomOpenPointInHouse(Game1.random);

            StardewValley.Objects.Chest giftBox = new StardewValley.Objects.Chest(0, itemsToStore, new Vector2(chestSpot.X, chestSpot.Y), true);
        }
Beispiel #17
0
        public override void Entry(IModHelper helper)
        {
            Logger.monitor = Monitor;
            var harmony = HarmonyInstance.Create("mabelsyrup.farmhouse");

            FarmHouseStates.harmony     = harmony;
            FarmHouseStates.spouseRooms = new Dictionary <string, int>();
            FarmHouseStates.reflector   = helper.Reflection;

            //FarmHouse patches
            harmony.Patch(
                original: AccessTools.Method(typeof(FarmHouse), nameof(FarmHouse.getFloors)),
                postfix: new HarmonyMethod(AccessTools.Method(typeof(FarmHouse_Patch), nameof(FarmHouse_Patch.Postfix)))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(FarmHouse), nameof(FarmHouse.getWalls)),
                postfix: new HarmonyMethod(AccessTools.Method(typeof(FarmHouse_getWalls_Patch), nameof(FarmHouse_getWalls_Patch.Postfix)))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(FarmHouse), nameof(FarmHouse.setMapForUpgradeLevel)),
                prefix: new HarmonyMethod(AccessTools.Method(typeof(FarmHouse_setMapForUpgradeLevel_patch), nameof(FarmHouse_setMapForUpgradeLevel_patch.Prefix)))
                );
            harmony.Patch(
                original: helper.Reflection.GetMethod(new FarmHouse(), "doSetVisibleFloor").MethodInfo,
                prefix: new HarmonyMethod(AccessTools.Method(typeof(FarmHouse_doSetVisibleFloor_Patch), nameof(FarmHouse_doSetVisibleFloor_Patch.Prefix)))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(FarmHouse), nameof(FarmHouse.loadSpouseRoom)),
                prefix: new HarmonyMethod(AccessTools.Method(typeof(FarmHouse_loadSpouseRoom_Patch), nameof(FarmHouse_loadSpouseRoom_Patch.Prefix)))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(FarmHouse), nameof(FarmHouse.performTenMinuteUpdate)),
                prefix: new HarmonyMethod(AccessTools.Method(typeof(FarmHouse_performTenMinuteUpdate_patch), nameof(FarmHouse_performTenMinuteUpdate_patch.Prefix)))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(FarmHouse), nameof(FarmHouse.showSpouseRoom)),
                prefix: new HarmonyMethod(AccessTools.Method(typeof(FarmHouse_showSpouseRoom_Patch), nameof(FarmHouse_showSpouseRoom_Patch.Prefix)))
                );

            //harmony.Patch(
            //    original: AccessTools.Method(typeof(FarmHouse), nameof(FarmHouse.getKitchenStandingSpot)),
            //    prefix: new HarmonyMethod(AccessTools.Method(typeof(FarmHouse_getKitchenStandingSpot_Patch), nameof(FarmHouse_getKitchenStandingSpot_Patch.Prefix)))
            //);

            //DecoratableLocation patches
            harmony.Patch(
                original: helper.Reflection.GetMethod(new DecoratableLocation(), "doSetVisibleWallpaper").MethodInfo,
                prefix: new HarmonyMethod(AccessTools.Method(typeof(DecoratableLocation_doSetVisibleWallpaper_Patch), nameof(DecoratableLocation_doSetVisibleWallpaper_Patch.Prefix)))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(DecoratableLocation), nameof(DecoratableLocation.setFloor)),
                prefix: new HarmonyMethod(AccessTools.Method(typeof(DecoratableLocation_setFloor_Patch), nameof(DecoratableLocation_setFloor_Patch.Prefix)))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(DecoratableLocation), nameof(DecoratableLocation.setWallpaper)),
                prefix: new HarmonyMethod(AccessTools.Method(typeof(DecoratableLocation_setWallpaper_Patch), nameof(DecoratableLocation_setWallpaper_Patch.Prefix)))
                );
            FarmHouseStates.init(helper.Content);
            helper.Events.GameLoop.DayStarted  += newDay;
            helper.Events.World.NpcListChanged += npcListChanged;
            helper.Events.Player.Warped        += fixPlayerHouseWarp;
        }