Exemple #1
0
        /// <summary>The mod entry point, called after the mod is first loaded.</summary>
        /// <param name="helper">Provides simplified APIs for writing mods.</param>
        public override void Entry(IModHelper helper)
        {
            config = Helper.ReadConfig <ModConfig>();

            if (!config.EnableMod)
            {
                return;
            }

            PMonitor = Monitor;
            PHelper  = helper;

            mp     = helper.Reflection.GetField <Multiplayer>(typeof(Game1), "multiplayer").GetValue();
            myRand = new Random();

            helper.Events.GameLoop.GameLaunched    += HelperEvents.GameLoop_GameLaunched;
            helper.Events.GameLoop.SaveLoaded      += HelperEvents.GameLoop_SaveLoaded;
            helper.Events.Input.ButtonPressed      += HelperEvents.Input_ButtonPressed;
            helper.Events.GameLoop.DayStarted      += HelperEvents.GameLoop_DayStarted;
            helper.Events.GameLoop.DayEnding       += HelperEvents.GameLoop_DayEnding;
            helper.Events.GameLoop.ReturnedToTitle += HelperEvents.GameLoop_ReturnedToTitle;

            NPCPatches.Initialize(Monitor);
            LocationPatches.Initialize(Monitor);
            FarmerPatches.Initialize(Monitor, Helper);
            Maps.Initialize(Monitor);
            Kissing.Initialize(Monitor);
            UIPatches.Initialize(Monitor, Helper);
            EventPatches.Initialize(Monitor, Helper);
            HelperEvents.Initialize(Monitor, Helper);
            FileIO.Initialize(Monitor, Helper);
            Misc.Initialize(Monitor, Helper);

            var harmony = HarmonyInstance.Create(this.ModManifest.UniqueID);


            // npc patches

            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), nameof(NPC.marriageDuties)),
                postfix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_marriageDuties_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), nameof(NPC.getSpouse)),
                prefix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_getSpouse_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), nameof(NPC.isRoommate)),
                prefix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_isRoommate_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), nameof(NPC.isMarried)),
                prefix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_isMarried_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), nameof(NPC.isMarriedOrEngaged)),
                prefix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_isMarriedOrEngaged_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), nameof(NPC.tryToReceiveActiveObject)),
                prefix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_tryToReceiveActiveObject_Prefix)),
                transpiler: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_tryToReceiveActiveObject_Transpiler)),
                postfix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_tryToReceiveActiveObject_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), nameof(NPC.checkAction)),
                prefix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_checkAction_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), nameof(NPC.spouseObstacleCheck)),
                postfix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_spouseObstacleCheck_Postfix))
                );


            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), "engagementResponse"),
                postfix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_engagementResponse_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), nameof(NPC.playSleepingAnimation)),
                postfix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_playSleepingAnimation_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Child), nameof(Child.reloadSprite)),
                postfix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.Child_reloadSprite_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Child), nameof(Child.resetForPlayerEntry)),
                postfix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.Child_resetForPlayerEntry_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Child), nameof(Child.dayUpdate)),
                prefix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.Child_dayUpdate_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Child), nameof(Child.tenMinuteUpdate)),
                postfix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.Child_tenMinuteUpdate_Postfix))
                );


            // location patches


            harmony.Patch(
                original: AccessTools.Method(typeof(Beach), nameof(Beach.checkAction)),
                prefix: new HarmonyMethod(typeof(LocationPatches), nameof(LocationPatches.Beach_checkAction_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(ManorHouse), nameof(ManorHouse.performAction)),
                prefix: new HarmonyMethod(typeof(LocationPatches), nameof(LocationPatches.ManorHouse_performAction_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(FarmHouse), nameof(FarmHouse.getWalls)),
                postfix: new HarmonyMethod(typeof(LocationPatches), nameof(LocationPatches.FarmHouse_getWalls_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(FarmHouse), nameof(FarmHouse.getFloors)),
                postfix: new HarmonyMethod(typeof(LocationPatches), nameof(LocationPatches.FarmHouse_getFloors_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.performAction)),
                prefix: new HarmonyMethod(typeof(LocationPatches), nameof(LocationPatches.GameLocation_performAction_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Beach), "resetLocalState"),
                postfix: new HarmonyMethod(typeof(LocationPatches), nameof(LocationPatches.Beach_resetLocalState_Postfix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(FarmHouse), "resetLocalState"),
                postfix: new HarmonyMethod(typeof(LocationPatches), nameof(LocationPatches.FarmHouse_resetLocalState_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(GameLocation), "checkEventPrecondition"),
                prefix: new HarmonyMethod(typeof(LocationPatches), nameof(LocationPatches.GameLocation_checkEventPrecondition_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(FarmHouse), nameof(FarmHouse.performTenMinuteUpdate)),
                postfix: new HarmonyMethod(typeof(LocationPatches), nameof(LocationPatches.FarmHouse_performTenMinuteUpdate_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Desert), nameof(Desert.getDesertMerchantTradeStock)),
                postfix: new HarmonyMethod(typeof(LocationPatches), nameof(LocationPatches.Desert_getDesertMerchantTradeStock_Postfix))
                );



            // pregnancy patches

            harmony.Patch(
                original: AccessTools.Method(typeof(Utility), nameof(Utility.pickPersonalFarmEvent)),
                prefix: new HarmonyMethod(typeof(Pregnancy), nameof(Pregnancy.Utility_pickPersonalFarmEvent_Prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(QuestionEvent), nameof(QuestionEvent.setUp)),
                prefix: new HarmonyMethod(typeof(Pregnancy), nameof(Pregnancy.QuestionEvent_setUp_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(BirthingEvent), nameof(BirthingEvent.setUp)),
                prefix: new HarmonyMethod(typeof(Pregnancy), nameof(Pregnancy.BirthingEvent_setUp_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(BirthingEvent), nameof(BirthingEvent.tickUpdate)),
                prefix: new HarmonyMethod(typeof(Pregnancy), nameof(Pregnancy.BirthingEvent_tickUpdate_Prefix))
                );


            // Farmer patches

            harmony.Patch(
                original: AccessTools.Method(typeof(Farmer), nameof(Farmer.doDivorce)),
                prefix: new HarmonyMethod(typeof(FarmerPatches), nameof(FarmerPatches.Farmer_doDivorce_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Farmer), nameof(Farmer.isMarried)),
                prefix: new HarmonyMethod(typeof(FarmerPatches), nameof(FarmerPatches.Farmer_isMarried_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Farmer), nameof(Farmer.checkAction)),
                prefix: new HarmonyMethod(typeof(FarmerPatches), nameof(FarmerPatches.Farmer_checkAction_Prefix))
                );

            // UI patches

            harmony.Patch(
                original: AccessTools.Method(typeof(SocialPage), "drawNPCSlot"),
                prefix: new HarmonyMethod(typeof(UIPatches), nameof(UIPatches.SocialPage_drawNPCSlot_prefix)),
                transpiler: new HarmonyMethod(typeof(UIPatches), nameof(UIPatches.SocialPage_drawSlot_transpiler))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(SocialPage), "drawFarmerSlot"),
                transpiler: new HarmonyMethod(typeof(UIPatches), nameof(UIPatches.SocialPage_drawSlot_transpiler))
                );

            harmony.Patch(
                original: typeof(DialogueBox).GetConstructor(new Type[] { typeof(List <string>) }),
                prefix: new HarmonyMethod(typeof(UIPatches), nameof(UIPatches.DialogueBox_Prefix))
                );

            // Event patches

            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.answerDialogueQuestion)),
                prefix: new HarmonyMethod(typeof(EventPatches), nameof(EventPatches.Event_answerDialogueQuestion_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Event), "setUpCharacters"),
                postfix: new HarmonyMethod(typeof(EventPatches), nameof(EventPatches.Event_setUpCharacters_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.command_playSound)),
                prefix: new HarmonyMethod(typeof(EventPatches), nameof(EventPatches.Event_command_playSound_Prefix))
                );
        }
Exemple #2
0
        public static void TrySpousesKiss()
        {
            GameLocation location = Game1.currentLocation;

            if (location == null || !ReferenceEquals(location.GetType(), typeof(FarmHouse)))
            {
                return;
            }

            Farmer owner = (location as FarmHouse).owner;

            lastKissTime++;

            if (location == null || location.characters == null)
            {
                return;
            }

            List <NPC> list = location.characters.ToList();

            Misc.ShuffleList(ref list);

            foreach (NPC npc1 in list)
            {
                if (!owner.friendshipData.ContainsKey(npc1.Name))
                {
                    continue;
                }

                if (!ModEntry.config.RoommateRomance && owner.friendshipData[npc1.Name].RoommateMarriage)
                {
                    continue;
                }


                foreach (NPC npc2 in list)
                {
                    if (!owner.friendshipData.ContainsKey(npc2.Name))
                    {
                        continue;
                    }

                    if (npc1.Name == npc2.Name || (!ModEntry.config.RoommateRomance && owner.friendshipData[npc2.Name].RoommateMarriage))
                    {
                        continue;
                    }

                    if (lastKissTime >= ModEntry.config.MinSpouseKissInterval)
                    {
                        kissingSpouses.Clear();
                    }


                    float distance = Vector2.Distance(npc1.position, npc2.position);
                    if (
                        npc1.getSpouse() != null && npc2.getSpouse() != null &&
                        npc1.getSpouse().Name == npc2.getSpouse().Name &&
                        distance < ModEntry.config.MaxDistanceToKiss &&
                        !kissingSpouses.Contains(npc1.Name) &&
                        !kissingSpouses.Contains(npc2.Name) &&
                        owner.getFriendshipHeartLevelForNPC(npc1.Name) >= ModEntry.config.MinHeartsForKiss &&
                        owner.getFriendshipHeartLevelForNPC(npc2.Name) >= ModEntry.config.MinHeartsForKiss &&
                        lastKissTime > ModEntry.config.MinSpouseKissInterval &&
                        ModEntry.myRand.NextDouble() < ModEntry.config.SpouseKissChance &&
                        (!ModEntry.config.PreventRelativesFromKissing || !Misc.AreSpousesRelated(npc1.Name, npc2.Name))
                        )
                    {
                        kissingSpouses.Add(npc1.Name);
                        kissingSpouses.Add(npc2.Name);
                        ModEntry.PMonitor.Log("spouses kissing");
                        lastKissTime = 0;
                        Vector2 npc1pos  = npc1.position;
                        Vector2 npc2pos  = npc2.position;
                        int     npc1face = npc1.facingDirection;
                        int     npc2face = npc1.facingDirection;
                        Vector2 midpoint = new Vector2((npc1.position.X + npc2.position.X) / 2, (npc1.position.Y + npc2.position.Y) / 2);
                        PerformKiss(npc1, midpoint, npc2.Name);
                        PerformKiss(npc2, midpoint, npc1.Name);
                        DelayedAction action = new DelayedAction(1000);
                        var           t      = Task.Run(async delegate
                        {
                            await Task.Delay(TimeSpan.FromSeconds(1));
                            npc1.position.Value  = npc1pos;
                            npc2.position.Value  = npc2pos;
                            npc1.FacingDirection = npc1face;
                            npc2.FacingDirection = npc2face;
                            return;
                        });
                    }
                }
            }
        }
        public static void GameLoop_OneSecondUpdateTicked(object sender, OneSecondUpdateTickedEventArgs e)
        {
            foreach (GameLocation location in Game1.locations)
            {
                if (location is FarmHouse)
                {
                    FarmHouse fh = location as FarmHouse;
                    if (fh.owner == null)
                    {
                        continue;
                    }

                    List <string> allSpouses = Misc.GetSpouses(fh.owner, 1).Keys.ToList();
                    List <string> bedSpouses = allSpouses.FindAll((s) => ModEntry.config.RoommateRomance || !fh.owner.friendshipData[s].RoommateMarriage);

                    foreach (NPC character in fh.characters)
                    {
                        if (!(character.currentLocation is FarmHouse))
                        {
                            continue;
                        }

                        if (allSpouses.Contains(character.Name))
                        {
                            if (Misc.IsInBed(fh, character.GetBoundingBox()))
                            {
                                character.farmerPassesThrough = true;
                                if (!character.isMoving() && !Kissing.kissingSpouses.Contains(character.Name))
                                {
                                    Vector2 bedPos = Misc.GetSpouseBedPosition(fh, bedSpouses, character.name);
                                    character.position.Value = bedPos;
                                    if (Game1.timeOfDay >= 2000 || Game1.timeOfDay <= 600)
                                    {
                                        if (!character.isSleeping)
                                        {
                                            character.isSleeping.Value = true;
                                            if (!Misc.HasSleepingAnimation(character.name.Value))
                                            {
                                                character.Sprite.StopAnimation();
                                                character.faceDirection(0);
                                            }
                                            else
                                            {
                                                character.playSleepingAnimation();
                                            }
                                        }
                                    }
                                    else
                                    {
                                        character.faceDirection(3);
                                        character.isSleeping.Value = false;
                                    }
                                }
                                else
                                {
                                    character.isSleeping.Value = false;
                                }
                                character.HideShadow = true;
                            }
                            else
                            {
                                character.farmerPassesThrough = false;
                                character.HideShadow          = false;
                                character.isSleeping.Value    = false;
                            }
                        }
                    }
                    if (location == Game1.player.currentLocation && ModEntry.config.AllowSpousesToKiss)
                    {
                        Kissing.TrySpousesKiss();
                    }
                }
            }
        }
Exemple #4
0
        /// <summary>The mod entry point, called after the mod is first loaded.</summary>
        /// <param name="helper">Provides simplified APIs for writing mods.</param>
        public override void Entry(IModHelper helper)
        {
            config = Helper.ReadConfig <ModConfig>();

            if (!config.EnableMod)
            {
                return;
            }

            PMonitor = Monitor;
            PHelper  = helper;

            mp     = helper.Reflection.GetField <Multiplayer>(typeof(Game1), "multiplayer").GetValue();
            myRand = new Random();

            helper.Events.GameLoop.GameLaunched    += HelperEvents.GameLoop_GameLaunched;
            helper.Events.GameLoop.SaveLoaded      += HelperEvents.GameLoop_SaveLoaded;
            helper.Events.Input.ButtonPressed      += HelperEvents.Input_ButtonPressed;
            helper.Events.GameLoop.DayStarted      += HelperEvents.GameLoop_DayStarted;
            helper.Events.GameLoop.DayEnding       += HelperEvents.GameLoop_DayEnding;
            helper.Events.GameLoop.ReturnedToTitle += HelperEvents.GameLoop_ReturnedToTitle;

            NPCPatches.Initialize(Monitor, config);
            LocationPatches.Initialize(Monitor);
            FarmerPatches.Initialize(Monitor, Helper);
            Maps.Initialize(Monitor);
            Kissing.Initialize(Monitor);
            UIPatches.Initialize(Monitor, Helper);
            EventPatches.Initialize(Monitor, Helper);
            HelperEvents.Initialize(Monitor, Helper);
            FileIO.Initialize(Monitor, Helper);
            Misc.Initialize(Monitor, Helper, config);
            Divorce.Initialize(Monitor, Helper);
            FurniturePatches.Initialize(Monitor, Helper, config);
            ObjectPatches.Initialize(Monitor, Helper, config);
            NetWorldStatePatches.Initialize(Monitor, Helper, config);

            var harmony = HarmonyInstance.Create(ModManifest.UniqueID);


            // npc patches

            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), nameof(NPC.marriageDuties)),
                postfix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_marriageDuties_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), nameof(NPC.getSpouse)),
                prefix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_getSpouse_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), nameof(NPC.isRoommate)),
                prefix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_isRoommate_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), nameof(NPC.isMarried)),
                prefix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_isMarried_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), nameof(NPC.isMarriedOrEngaged)),
                prefix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_isMarriedOrEngaged_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), nameof(NPC.tryToReceiveActiveObject)),
                prefix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_tryToReceiveActiveObject_Prefix)),
                transpiler: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_tryToReceiveActiveObject_Transpiler)),
                postfix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_tryToReceiveActiveObject_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), nameof(NPC.checkAction)),
                prefix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_checkAction_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), nameof(NPC.spouseObstacleCheck)),
                postfix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_spouseObstacleCheck_Postfix))
                );


            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), "engagementResponse"),
                postfix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_engagementResponse_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), nameof(NPC.playSleepingAnimation)),
                postfix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_playSleepingAnimation_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), nameof(NPC.GetDispositionModifiedString)),
                prefix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_GetDispositionModifiedString_Prefix)),
                postfix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_GetDispositionModifiedString_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), "loadCurrentDialogue"),
                prefix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_loadCurrentDialogue_Prefix)),
                postfix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_loadCurrentDialogue_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), nameof(NPC.tryToRetrieveDialogue)),
                prefix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_tryToRetrieveDialogue_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), nameof(NPC.setSpouseRoomMarriageDialogue)),
                prefix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_setSpouseRoomMarriageDialogue_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), nameof(NPC.setRandomAfternoonMarriageDialogue)),
                prefix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.NPC_setRandomAfternoonMarriageDialogue_Prefix))
                );


            // Child patches

            harmony.Patch(
                original: typeof(Character).GetProperty("displayName").GetMethod,
                postfix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.Character_displayName_Getter_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Child), nameof(Child.reloadSprite)),
                postfix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.Child_reloadSprite_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Child), nameof(Child.resetForPlayerEntry)),
                postfix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.Child_resetForPlayerEntry_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Child), nameof(Child.dayUpdate)),
                prefix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.Child_dayUpdate_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Child), nameof(Child.isInCrib)),
                prefix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.Child_isInCrib_Prefix))
                );

            /*
             * harmony.Patch(
             * original: AccessTools.Method(typeof(Child), nameof(Child.tenMinuteUpdate)),
             * postfix: new HarmonyMethod(typeof(NPCPatches), nameof(NPCPatches.Child_tenMinuteUpdate_Postfix))
             * );
             */

            // Location patches

            harmony.Patch(
                original: AccessTools.Method(typeof(Beach), nameof(Beach.checkAction)),
                prefix: new HarmonyMethod(typeof(LocationPatches), nameof(LocationPatches.Beach_checkAction_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(ManorHouse), nameof(ManorHouse.performAction)),
                prefix: new HarmonyMethod(typeof(LocationPatches), nameof(LocationPatches.ManorHouse_performAction_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(FarmHouse), nameof(FarmHouse.checkAction)),
                postfix: new HarmonyMethod(typeof(LocationPatches), nameof(LocationPatches.FarmHouse_checkAction_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(FarmHouse), nameof(FarmHouse.updateFarmLayout)),
                postfix: new HarmonyMethod(typeof(LocationPatches), nameof(LocationPatches.FarmHouse_updateFarmLayout_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(FarmHouse), nameof(FarmHouse.getWalls)),
                postfix: new HarmonyMethod(typeof(LocationPatches), nameof(LocationPatches.FarmHouse_getWalls_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(FarmHouse), nameof(FarmHouse.getFloors)),
                postfix: new HarmonyMethod(typeof(LocationPatches), nameof(LocationPatches.FarmHouse_getFloors_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.performAction)),
                prefix: new HarmonyMethod(typeof(LocationPatches), nameof(LocationPatches.GameLocation_performAction_Prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.answerDialogue)),
                prefix: new HarmonyMethod(typeof(LocationPatches), nameof(LocationPatches.GameLocation_answerDialogue_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(FarmHouse), "resetLocalState"),
                postfix: new HarmonyMethod(typeof(LocationPatches), nameof(LocationPatches.FarmHouse_resetLocalState_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Beach), "resetLocalState"),
                postfix: new HarmonyMethod(typeof(LocationPatches), nameof(LocationPatches.Beach_resetLocalState_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(GameLocation), "checkEventPrecondition"),
                prefix: new HarmonyMethod(typeof(LocationPatches), nameof(LocationPatches.GameLocation_checkEventPrecondition_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(FarmHouse), nameof(FarmHouse.performTenMinuteUpdate)),
                postfix: new HarmonyMethod(typeof(LocationPatches), nameof(LocationPatches.FarmHouse_performTenMinuteUpdate_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Desert), nameof(Desert.getDesertMerchantTradeStock)),
                postfix: new HarmonyMethod(typeof(LocationPatches), nameof(LocationPatches.Desert_getDesertMerchantTradeStock_Postfix))
                );



            // pregnancy patches

            harmony.Patch(
                original: AccessTools.Method(typeof(Utility), nameof(Utility.pickPersonalFarmEvent)),
                prefix: new HarmonyMethod(typeof(Pregnancy), nameof(Pregnancy.Utility_pickPersonalFarmEvent_Prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(QuestionEvent), nameof(QuestionEvent.setUp)),
                prefix: new HarmonyMethod(typeof(Pregnancy), nameof(Pregnancy.QuestionEvent_setUp_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(BirthingEvent), nameof(BirthingEvent.setUp)),
                prefix: new HarmonyMethod(typeof(Pregnancy), nameof(Pregnancy.BirthingEvent_setUp_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(BirthingEvent), nameof(BirthingEvent.tickUpdate)),
                prefix: new HarmonyMethod(typeof(Pregnancy), nameof(Pregnancy.BirthingEvent_tickUpdate_Prefix))
                );


            // Farmer patches

            harmony.Patch(
                original: AccessTools.Method(typeof(Farmer), nameof(Farmer.doDivorce)),
                prefix: new HarmonyMethod(typeof(FarmerPatches), nameof(FarmerPatches.Farmer_doDivorce_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Farmer), nameof(Farmer.isMarried)),
                prefix: new HarmonyMethod(typeof(FarmerPatches), nameof(FarmerPatches.Farmer_isMarried_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Farmer), nameof(Farmer.getSpouse)),
                prefix: new HarmonyMethod(typeof(FarmerPatches), nameof(FarmerPatches.Farmer_getSpouse_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Farmer), nameof(Farmer.checkAction)),
                prefix: new HarmonyMethod(typeof(FarmerPatches), nameof(FarmerPatches.Farmer_checkAction_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Farmer), nameof(Farmer.GetSpouseFriendship)),
                prefix: new HarmonyMethod(typeof(FarmerPatches), nameof(FarmerPatches.Farmer_GetSpouseFriendship_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Farmer), nameof(Farmer.getChildren)),
                prefix: new HarmonyMethod(typeof(FarmerPatches), nameof(FarmerPatches.Farmer_getChildren_Prefix))
                );


            // UI patches

            harmony.Patch(
                original: AccessTools.Method(typeof(SocialPage), "drawNPCSlot"),
                prefix: new HarmonyMethod(typeof(UIPatches), nameof(UIPatches.SocialPage_drawNPCSlot_prefix)),
                transpiler: new HarmonyMethod(typeof(UIPatches), nameof(UIPatches.SocialPage_drawSlot_transpiler))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(SocialPage), "drawFarmerSlot"),
                transpiler: new HarmonyMethod(typeof(UIPatches), nameof(UIPatches.SocialPage_drawSlot_transpiler))
                );

            harmony.Patch(
                original: typeof(DialogueBox).GetConstructor(new Type[] { typeof(List <string>) }),
                prefix: new HarmonyMethod(typeof(UIPatches), nameof(UIPatches.DialogueBox_Prefix))
                );


            // Event patches

            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.answerDialogueQuestion)),
                prefix: new HarmonyMethod(typeof(EventPatches), nameof(EventPatches.Event_answerDialogueQuestion_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Event), "setUpCharacters"),
                postfix: new HarmonyMethod(typeof(EventPatches), nameof(EventPatches.Event_setUpCharacters_Postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.command_playSound)),
                prefix: new HarmonyMethod(typeof(EventPatches), nameof(EventPatches.Event_command_playSound_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.command_loadActors)),
                prefix: new HarmonyMethod(typeof(EventPatches), nameof(EventPatches.Event_command_loadActors_Prefix)),
                postfix: new HarmonyMethod(typeof(EventPatches), nameof(EventPatches.Event_command_loadActors_Postfix))
                );


            // Object patches

            harmony.Patch(
                original: AccessTools.Method(typeof(Object), nameof(Object.draw), new Type[] { typeof(SpriteBatch), typeof(int), typeof(int), typeof(float) }),
                prefix: new HarmonyMethod(typeof(ObjectPatches), nameof(ObjectPatches.Object_draw_Prefix))
                );

            // Furniture patches

            harmony.Patch(
                original: AccessTools.Method(typeof(BedFurniture), nameof(BedFurniture.draw), new Type[] { typeof(SpriteBatch), typeof(int), typeof(int), typeof(float) }),
                prefix: new HarmonyMethod(typeof(FurniturePatches), nameof(FurniturePatches.BedFurniture_draw_Prefix))
                );

            // Game1 patches

            harmony.Patch(
                original: AccessTools.Method(typeof(Game1), nameof(Game1.prepareSpouseForWedding)),
                prefix: new HarmonyMethod(typeof(Game1Patches), nameof(Game1Patches.prepareSpouseForWedding_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(Game1), nameof(Game1.getCharacterFromName), new Type[] { typeof(string), typeof(bool), typeof(bool) }),
                prefix: new HarmonyMethod(typeof(Game1Patches), nameof(Game1Patches.getCharacterFromName_Prefix))
                );


            // NetWorldState patch

            harmony.Patch(
                original: AccessTools.Method(typeof(NetWorldState), nameof(NetWorldState.hasWorldStateID)),
                prefix: new HarmonyMethod(typeof(NetWorldStatePatches), nameof(NetWorldStatePatches.hasWorldStateID_Prefix))
                );
        }
        public static void FarmHouse_performTenMinuteUpdate_Postfix(FarmHouse __instance, int timeOfDay)
        {
            try
            {
                if (__instance.owner == null)
                {
                    return;
                }

                List <string> mySpouses = Misc.GetSpouses(__instance.owner, 1).Keys.ToList();
                if (Game1.IsMasterGame && Game1.timeOfDay >= 2200 && Game1.IsMasterGame)
                {
                    int           upgradeLevel = __instance.upgradeLevel;
                    List <string> roomSpouses  = mySpouses.FindAll((s) => Maps.roomIndexes.ContainsKey(s) || Maps.tmxSpouseRooms.ContainsKey(s));
                    List <string> bedSpouses   = mySpouses.FindAll((s) => ModEntry.config.RoommateRomance || !__instance.owner.friendshipData[s].RoommateMarriage);
                    foreach (NPC c in __instance.characters)
                    {
                        if (c.isMarried())
                        {
                            string spouseName = c.Name;

                            if (Misc.GetSpouses(Game1.player, 1).ContainsKey(spouseName))
                            {
                                c.checkForMarriageDialogue(timeOfDay, __instance);
                            }

                            Point bedSpot;
                            if (timeOfDay >= 2200)
                            {
                                if (!bedSpouses.Contains(c.Name))
                                {
                                    if (!roomSpouses.Exists((n) => n == spouseName))
                                    {
                                        bedSpot = __instance.getRandomOpenPointInHouse(ModEntry.myRand);
                                    }
                                    else
                                    {
                                        int     offset = roomSpouses.IndexOf(spouseName) * 7;
                                        Vector2 spot   = (upgradeLevel == 1) ? new Vector2(32f, 5f) : new Vector2(38f, 14f);
                                        bedSpot = new Point((int)spot.X + offset, (int)spot.Y);
                                    }
                                }
                                else
                                {
                                    int  bedWidth = Misc.GetBedWidth(__instance);
                                    bool up       = upgradeLevel > 1;

                                    Point bedStart = new Point(21 - (up ? (bedWidth / 2) - 1 : 0) + (up ? 6 : 0), 2 + (up ? 9 : 0));
                                    int   x        = 1 + (int)((bedSpouses.IndexOf(spouseName) + 1) / (float)(bedSpouses.Count + 1) * (bedWidth - 2));
                                    bedSpot = new Point(bedStart.X + x, bedStart.Y + 2);
                                }

                                c.controller = null;
                                if (c.Position != Misc.GetSpouseBedPosition(__instance, bedSpouses, c.Name) && (!Misc.IsInBed(__instance, c.GetBoundingBox()) || !Kissing.kissingSpouses.Contains(c.Name)))
                                {
                                    c.controller = new PathFindController(c, __instance, bedSpot, 0, new PathFindController.endBehavior(FarmHouse.spouseSleepEndFunction));
                                    if (c.controller.pathToEndPoint == null || !__instance.isTileOnMap(c.controller.pathToEndPoint.Last <Point>().X, c.controller.pathToEndPoint.Last <Point>().Y))
                                    {
                                        c.controller = null;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Monitor.Log($"Failed in {nameof(FarmHouse_performTenMinuteUpdate_Postfix)}:\n{ex}", LogLevel.Error);
            }
        }
Exemple #6
0
        internal static void afterDialogueBehavior(Farmer who, string whichAnswer)
        {
            Monitor.Log("answer " + whichAnswer);

            if (Misc.GetSpouses(Game1.player, 1).ContainsKey(whichAnswer))
            {
                Monitor.Log("divorcing " + whichAnswer);
                string s2 = Game1.content.LoadStringReturnNullIfNotFound("Strings\\Locations:ManorHouse_DivorceBook_Question_" + Game1.player.spouse);
                if (s2 == null)
                {
                    s2 = Game1.content.LoadStringReturnNullIfNotFound("Strings\\Locations:ManorHouse_DivorceBook_Question");
                }
                List <Response> responses = new List <Response>();
                responses.Add(new Response($"divorce_Yes_{whichAnswer}", Game1.content.LoadString("Strings\\Lexicon:QuestionDialogue_Yes")));
                if (ModEntry.config.ComplexDivorce)
                {
                    responses.Add(new Response($"divorce_complex_{whichAnswer}", Helper.Translation.Get("divorce_complex")));
                }
                responses.Add(new Response("No", Game1.content.LoadString("Strings\\Lexicon:QuestionDialogue_No")));
                (Game1.activeClickableMenu as DialogueBox)?.closeDialogue();
                Game1.currentLocation.createQuestionDialogue(s2, responses.ToArray(), afterDialogueBehavior);
            }
            else if (whichAnswer.StartsWith("divorce_Yes_"))
            {
                Monitor.Log("confirmed " + whichAnswer);
                string spouse = whichAnswer.Split('_')[2];
                if (Game1.player.Money >= 50000 || spouse == "Krobus")
                {
                    Monitor.Log("divorce initiated successfully");
                    if (!Game1.player.isRoommate(spouse))
                    {
                        Game1.player.Money        -= 50000;
                        ModEntry.divorceHeartsLost = ModEntry.config.FriendlyDivorce ? 0 : -1;
                    }
                    else
                    {
                        ModEntry.divorceHeartsLost = 0;
                    }
                    ModEntry.spouseToDivorce          = spouse;
                    Game1.player.divorceTonight.Value = true;
                    string s = Game1.content.LoadStringReturnNullIfNotFound("Strings\\Locations:ManorHouse_DivorceBook_Filed_" + spouse);
                    if (s == null)
                    {
                        s = Game1.content.LoadStringReturnNullIfNotFound("Strings\\Locations:ManorHouse_DivorceBook_Filed");
                    }
                    Game1.drawObjectDialogue(s);
                    if (!Game1.player.isRoommate(spouse))
                    {
                        ModEntry.mp.globalChatInfoMessage("Divorce", new string[]
                        {
                            Game1.player.Name
                        });
                    }
                }
                else
                {
                    Monitor.Log("not enough money to divorce");
                    Game1.drawObjectDialogue(Game1.content.LoadString("Strings\\UI:NotEnoughMoney1"));
                }
            }
            else if (whichAnswer.StartsWith("divorce_complex_"))
            {
                complexDivorceSpouse       = whichAnswer.Replace("divorce_complex_", "");
                ModEntry.divorceHeartsLost = 1;
                ShowNextDialogue("divorce_fault_", Game1.currentLocation);
            }
            else if (whichAnswer.StartsWith("divorce_fault_"))
            {
                Monitor.Log("divorce fault");
                string r = Helper.Translation.Get(whichAnswer);
                if (r != null)
                {
                    if (int.TryParse(r.Split('#')[r.Split('#').Length - 1], out int lost))
                    {
                        ModEntry.divorceHeartsLost += lost;
                    }
                }
                string      nextKey = $"divorce_{r.Split('#')[r.Split('#').Length - 2]}reason_";
                Translation test    = Helper.Translation.Get(nextKey + "q");
                if (!test.HasValue())
                {
                    ShowNextDialogue($"divorce_method_", Game1.currentLocation);
                    return;
                }
                ShowNextDialogue($"divorce_{r.Split('#')[r.Split('#').Length - 2]}reason_", Game1.currentLocation);
            }
            else if (whichAnswer.Contains("reason_"))
            {
                Monitor.Log("divorce reason");
                string r = Helper.Translation.Get(whichAnswer);
                if (r != null)
                {
                    if (int.TryParse(r.Split('#')[r.Split('#').Length - 1], out int lost))
                    {
                        ModEntry.divorceHeartsLost += lost;
                    }
                }

                ShowNextDialogue($"divorce_method_", Game1.currentLocation);
            }
            else if (whichAnswer.StartsWith("divorce_method_"))
            {
                Monitor.Log("divorce method");
                ModEntry.spouseToDivorce = complexDivorceSpouse;
                string r = Helper.Translation.Get(whichAnswer);
                if (r != null)
                {
                    if (int.TryParse(r.Split('#')[r.Split('#').Length - 1], out int lost))
                    {
                        ModEntry.divorceHeartsLost += lost;
                    }
                }

                if (Game1.player.Money >= 50000 || complexDivorceSpouse == "Krobus")
                {
                    if (!Game1.player.isRoommate(complexDivorceSpouse))
                    {
                        int money = 50000;
                        if (int.TryParse(r.Split('#')[r.Split('#').Length - 2], out int mult))
                        {
                            money = (int)Math.Round(money * mult / 100f);
                        }
                        Monitor.Log($"money cost {money}");
                        Game1.player.Money -= money;
                    }
                    Game1.player.divorceTonight.Value = true;
                    string s = Game1.content.LoadStringReturnNullIfNotFound("Strings\\Locations:ManorHouse_DivorceBook_Filed_" + complexDivorceSpouse);
                    if (s == null)
                    {
                        s = Game1.content.LoadStringReturnNullIfNotFound("Strings\\Locations:ManorHouse_DivorceBook_Filed");
                    }
                    Game1.drawObjectDialogue(s);
                    if (!Game1.player.isRoommate(complexDivorceSpouse))
                    {
                        ModEntry.mp.globalChatInfoMessage("Divorce", new string[]
                        {
                            Game1.player.Name
                        });
                    }
                    Monitor.Log($"hearts lost {ModEntry.divorceHeartsLost}");
                }
                else
                {
                    Game1.drawObjectDialogue(Game1.content.LoadString("Strings\\UI:NotEnoughMoney1"));
                }
            }
        }
Exemple #7
0
        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 {Misc.GetExtraCribs()} cribs");
                for (int i = 1; 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 + 1}");
                    Helper.Reflection.GetField <HashSet <string> >(farmHouse, "_appliedMapOverrides").SetValue(amo);
                    farmHouse.ApplyMapOverride(override_map, $"crib{i+1}", null, rect);
                }
            }
        }
Exemple #8
0
 public static bool Farmer_isMarried_Prefix(Farmer __instance, ref bool __result)
 {
     try
     {
         __result = __instance.team.IsMarried(__instance.UniqueMultiplayerID) || Misc.GetSpouses(__instance, 1).Count > 0;
         return(false);
     }
     catch (Exception ex)
     {
         Monitor.Log($"Failed in {nameof(Farmer_isMarried_Prefix)}:\n{ex}", LogLevel.Error);
     }
     return(true);
 }
Exemple #9
0
        public static void BuildSpouseRooms(FarmHouse farmHouse)
        {
            if (config.DisableCustomSpousesRooms)
            {
                return;
            }

            try
            {
                if (farmHouse is Cabin)
                {
                    Monitor.Log("BuildSpouseRooms for Cabin");
                }

                Farmer f = farmHouse.owner;
                if (f == null)
                {
                    return;
                }
                Misc.ResetSpouses(f);
                Monitor.Log("Building all spouse rooms");
                if (Misc.GetSpouses(f, 1).Count == 0 || farmHouse.upgradeLevel > 3)
                {
                    ModEntry.PMonitor.Log("No spouses");
                    farmHouse.showSpouseRoom();
                    return;
                }

                List <string> spousesWithRooms = new List <string>();

                foreach (string spouse in Misc.GetSpouses(f, 1).Keys)
                {
                    Monitor.Log($"checking {spouse} for spouse room");
                    if (roomIndexes.ContainsKey(spouse) || tmxSpouseRooms.ContainsKey(spouse))
                    {
                        Monitor.Log($"Adding {spouse} to list for spouse rooms");
                        spousesWithRooms.Add(spouse);
                    }
                }

                if (spousesWithRooms.Count == 0)
                {
                    ModEntry.PMonitor.Log("No spouses with rooms");
                    return;
                }

                spousesWithRooms = new List <string>(Misc.ReorderSpousesForRooms(spousesWithRooms));

                if (!spousesWithRooms.Any())
                {
                    return;
                }

                if (!ModEntry.config.BuildAllSpousesRooms)
                {
                    if (f.spouse != null && !f.friendshipData[f.spouse].IsEngaged() && (roomIndexes.ContainsKey(f.spouse) || tmxSpouseRooms.ContainsKey(f.spouse)))
                    {
                        Monitor.Log($"Building spouse room for official spouse {f.spouse}");
                        BuildOneSpouseRoom(farmHouse, f.spouse, -1);
                    }
                    else
                    {
                        Monitor.Log($"No spouse room for official spouse {f.spouse}, placing for {spousesWithRooms[0]} instead.");
                        BuildOneSpouseRoom(farmHouse, spousesWithRooms[0], -1);
                        spousesWithRooms = new List <string>(spousesWithRooms.Skip(1));
                    }
                    return;
                }

                Monitor.Log($"Building {spousesWithRooms.Count} additional spouse rooms");

                List <string> sheets = new List <string>();
                for (int i = 0; i < farmHouse.map.TileSheets.Count; i++)
                {
                    sheets.Add(farmHouse.map.TileSheets[i].Id);
                }
                int untitled   = sheets.IndexOf("untitled tile sheet");
                int floorsheet = sheets.IndexOf("walls_and_floors");
                int indoor     = sheets.IndexOf("indoor");

                Monitor.Log($"Map has sheets: {string.Join(", ", sheets)}");

                int startx = 29;

                int ox = ModEntry.config.ExistingSpouseRoomOffsetX;
                int oy = ModEntry.config.ExistingSpouseRoomOffsetY;
                if (farmHouse.upgradeLevel > 1)
                {
                    ox += 6;
                    oy += 9;
                }

                Monitor.Log($"Preliminary adjustments");

                for (int i = 0; i < 7; i++)
                {
                    farmHouse.setMapTileIndex(ox + startx + i, oy + 11, 0, "Buildings", indoor);
                    farmHouse.removeTile(ox + startx + i, oy + 9, "Front");
                    farmHouse.removeTile(ox + startx + i, oy + 10, "Buildings");
                    farmHouse.setMapTileIndex(ox + startx - 1 + i, oy + 10, 165, "Front", indoor);
                    farmHouse.removeTile(ox + startx + i, oy + 10, "Back");
                }
                for (int i = 0; i < 8; i++)
                {
                    farmHouse.setMapTileIndex(ox + startx - 1 + i, oy + 10, 165, "Front", indoor);
                }
                for (int i = 0; i < 10; i++)
                {
                    farmHouse.removeTile(ox + startx + 6, oy + 0 + i, "Buildings");
                    farmHouse.removeTile(ox + startx + 6, oy + 0 + i, "Front");
                }
                for (int i = 0; i < 7; i++)
                {
                    // horiz hall
                    farmHouse.setMapTileIndex(ox + startx + i, oy + 10, (i % 2 == 0 ? 352: 336), "Back", floorsheet);
                }


                for (int i = 0; i < 7; i++)
                {
                    //farmHouse.removeTile(ox + startx - 1, oy + 4 + i, "Back");
                    //farmHouse.setMapTileIndex(ox + 28, oy + 4 + i, (i % 2 == 0 ? 352 : ModEntry.config.HallTileEven), "Back", 0);
                }


                farmHouse.removeTile(ox + startx - 1, oy + 9, "Front");
                farmHouse.removeTile(ox + startx - 1, oy + 10, "Buildings");

                if (farmHouse.upgradeLevel > 1)
                {
                    farmHouse.setMapTileIndex(ox + startx - 1, oy + 10, 163, "Front", indoor);
                }
                farmHouse.removeTile(ox + startx + 6, oy + 0, "Front");
                farmHouse.removeTile(ox + startx + 6, oy + 0, "Buildings");



                int count = -1;

                ExtendMap(farmHouse, ox + startx + 8 + (7 * spousesWithRooms.Count));

                // remove and rebuild spouse rooms
                for (int j = 0; j < spousesWithRooms.Count; j++)
                {
                    farmHouse.removeTile(ox + startx + 6 + (7 * count), oy + 0, "Buildings");
                    for (int i = 0; i < 10; i++)
                    {
                        farmHouse.removeTile(ox + startx + 6 + (7 * count), oy + 1 + i, "Buildings");
                    }
                    BuildOneSpouseRoom(farmHouse, spousesWithRooms[j], count++);
                }

                Monitor.Log($"Building far wall");

                // far wall
                farmHouse.setMapTileIndex(ox + startx + 6 + (7 * count), oy + 0, 11, "Buildings", indoor);
                for (int i = 0; i < 10; i++)
                {
                    farmHouse.setMapTileIndex(ox + startx + 6 + (7 * count), oy + 1 + i, 68, "Buildings", indoor);
                }
                farmHouse.setMapTileIndex(ox + startx + 6 + (7 * count), oy + 10, 130, "Front", indoor);
            }
            catch (Exception ex)
            {
                Monitor.Log($"Failed in {nameof(BuildSpouseRooms)}:\n{ex}", LogLevel.Error);
            }
            farmHouse.getWalls();
            farmHouse.getFloors();
        }
Exemple #10
0
        public static void Input_ButtonPressed(object sender, ButtonPressedEventArgs e)
        {
            if ((e.Button != SButton.MouseLeft && e.Button != SButton.MouseRight) || Game1.currentLocation == null || !(Game1.currentLocation is ManorHouse) || Game1.currentLocation.lastQuestionKey == null || !Game1.currentLocation.lastQuestionKey.StartsWith("divorce"))
            {
                return;
            }

            IClickableMenu menu = Game1.activeClickableMenu;

            if (menu == null || !ReferenceEquals(menu.GetType(), typeof(DialogueBox)))
            {
                return;
            }
            int             resp  = (int)typeof(DialogueBox).GetField("selectedResponse", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(menu);
            List <Response> resps = (List <Response>) typeof(DialogueBox).GetField("responses", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(menu);

            if (resp < 0 || resps == null || resp >= resps.Count || resps[resp] == null)
            {
                return;
            }


            Game1.currentLocation.lastQuestionKey = "";
            string whichAnswer = resps[resp].responseKey;

            Monitor.Log("answer " + whichAnswer);

            if (Misc.GetSpouses(Game1.player, 1).ContainsKey(whichAnswer))
            {
                string s2 = Game1.content.LoadStringReturnNullIfNotFound("Strings\\Locations:ManorHouse_DivorceBook_Question_" + Game1.player.spouse);
                if (s2 == null)
                {
                    s2 = Game1.content.LoadStringReturnNullIfNotFound("Strings\\Locations:ManorHouse_DivorceBook_Question");
                }
                List <Response> responses = new List <Response>();
                responses.Add(new Response($"Yes_{whichAnswer}", Game1.content.LoadString("Strings\\Lexicon:QuestionDialogue_Yes")));
                if (ModEntry.config.ComplexDivorce)
                {
                    responses.Add(new Response($"divorce_complex_{whichAnswer}", Helper.Translation.Get("divorce_complex")));
                }
                responses.Add(new Response("No", Game1.content.LoadString("Strings\\Lexicon:QuestionDialogue_No")));
                Game1.currentLocation.createQuestionDialogue(s2, responses.ToArray(), $"divorce_{whichAnswer}");
            }
            else if (whichAnswer.StartsWith("Yes_"))
            {
                string spouse = whichAnswer.Substring(4);
                ModEntry.spouseToDivorce = spouse;
                if (Game1.player.Money >= 50000 || spouse == "Krobus")
                {
                    if (!Game1.player.isRoommate(spouse))
                    {
                        Game1.player.Money        -= 50000;
                        ModEntry.divorceHeartsLost = ModEntry.config.FriendlyDivorce ? 0 : -1;
                    }
                    else
                    {
                        ModEntry.divorceHeartsLost = 0;
                    }
                    Game1.player.divorceTonight.Value = true;
                    string s = Game1.content.LoadStringReturnNullIfNotFound("Strings\\Locations:ManorHouse_DivorceBook_Filed_" + spouse);
                    if (s == null)
                    {
                        s = Game1.content.LoadStringReturnNullIfNotFound("Strings\\Locations:ManorHouse_DivorceBook_Filed");
                    }
                    Game1.drawObjectDialogue(s);
                    if (!Game1.player.isRoommate(spouse))
                    {
                        ModEntry.mp.globalChatInfoMessage("Divorce", new string[]
                        {
                            Game1.player.Name
                        });
                    }
                }
                else
                {
                    Game1.drawObjectDialogue(Game1.content.LoadString("Strings\\UI:NotEnoughMoney1"));
                }
            }
            else if (whichAnswer.StartsWith("divorce_complex_"))
            {
                complexDivorceSpouse       = whichAnswer.Replace("divorce_complex_", "");
                ModEntry.divorceHeartsLost = 1;
                ShowNextDialogue("divorce_fault_", Game1.currentLocation);
            }
            else if (whichAnswer.StartsWith("divorce_fault_"))
            {
                Monitor.Log("divorce fault");
                string r = Helper.Translation.Get(whichAnswer);
                if (r != null)
                {
                    if (int.TryParse(r.Split('#')[r.Split('#').Length - 1], out int lost))
                    {
                        ModEntry.divorceHeartsLost += lost;
                    }
                }
                string      nextKey = $"divorce_{r.Split('#')[r.Split('#').Length - 2]}reason_";
                Translation test    = Helper.Translation.Get(nextKey + "q");
                if (!test.HasValue())
                {
                    ShowNextDialogue($"divorce_method_", Game1.currentLocation);
                    return;
                }
                ShowNextDialogue($"divorce_{r.Split('#')[r.Split('#').Length - 2]}reason_", Game1.currentLocation);
            }
            else if (whichAnswer.Contains("reason_"))
            {
                Monitor.Log("divorce reason");
                string r = Helper.Translation.Get(whichAnswer);
                if (r != null)
                {
                    if (int.TryParse(r.Split('#')[r.Split('#').Length - 1], out int lost))
                    {
                        ModEntry.divorceHeartsLost += lost;
                    }
                }

                ShowNextDialogue($"divorce_method_", Game1.currentLocation);
            }
            else if (whichAnswer.StartsWith("divorce_method_"))
            {
                Monitor.Log("divorce method");
                ModEntry.spouseToDivorce = complexDivorceSpouse;
                string r = Helper.Translation.Get(whichAnswer);
                if (r != null)
                {
                    if (int.TryParse(r.Split('#')[r.Split('#').Length - 1], out int lost))
                    {
                        ModEntry.divorceHeartsLost += lost;
                    }
                }

                if (Game1.player.Money >= 50000 || complexDivorceSpouse == "Krobus")
                {
                    if (!Game1.player.isRoommate(complexDivorceSpouse))
                    {
                        int money = 50000;
                        if (int.TryParse(r.Split('#')[r.Split('#').Length - 2], out int mult))
                        {
                            money = (int)Math.Round(money * mult / 100f);
                        }
                        Monitor.Log($"money cost {money}");
                        Game1.player.Money -= money;
                    }
                    Game1.player.divorceTonight.Value = true;
                    string s = Game1.content.LoadStringReturnNullIfNotFound("Strings\\Locations:ManorHouse_DivorceBook_Filed_" + complexDivorceSpouse);
                    if (s == null)
                    {
                        s = Game1.content.LoadStringReturnNullIfNotFound("Strings\\Locations:ManorHouse_DivorceBook_Filed");
                    }
                    Game1.drawObjectDialogue(s);
                    if (!Game1.player.isRoommate(complexDivorceSpouse))
                    {
                        ModEntry.mp.globalChatInfoMessage("Divorce", new string[]
                        {
                            Game1.player.Name
                        });
                    }
                    Monitor.Log($"hearts lost {ModEntry.divorceHeartsLost}");
                }
                else
                {
                    Game1.drawObjectDialogue(Game1.content.LoadString("Strings\\UI:NotEnoughMoney1"));
                }
            }
        }
Exemple #11
0
        public static bool Object_draw_Prefix(Object __instance, SpriteBatch spriteBatch, float alpha)
        {
            if (!Config.EnableMod || !Config.CustomBed || !(__instance is BedFurniture) || (__instance is BedFurniture && (__instance as BedFurniture)?.bedType != BedFurniture.BedType.Double))
            {
                return(true);
            }

            int        bedWidth     = Misc.GetBedWidth(Utility.getHomeOfFarmer(Game1.getFarmer(__instance.owner)));
            NetVector2 drawPosition = Helper.Reflection.GetField <NetVector2>(__instance as BedFurniture, "drawPosition").GetValue();

            __instance.boundingBox.Width = (bedWidth + 1) * 64;

            Rectangle drawn_rect   = (__instance as BedFurniture).sourceRect.Value;
            int       third        = drawn_rect.Width / 3;
            Rectangle drawn_first  = new Rectangle(drawn_rect.X, drawn_rect.Y, third, drawn_rect.Height);
            Rectangle drawn_second = new Rectangle(drawn_rect.X + third, drawn_rect.Y, third, drawn_rect.Height);
            Rectangle drawn_third  = new Rectangle(drawn_rect.X + third + third, drawn_rect.Y, third, drawn_rect.Height);

            spriteBatch.Draw(Furniture.furnitureTexture, Game1.GlobalToLocal(Game1.viewport, drawPosition + ((__instance.shakeTimer > 0) ? new Vector2(Game1.random.Next(-1, 2), Game1.random.Next(-1, 2)) : Vector2.Zero)), new Rectangle?(drawn_first), Color.White * alpha, 0f, Vector2.Zero, 4f, __instance.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (__instance.boundingBox.Value.Top + 1) / 10000f);
            for (int i = 1; i < bedWidth; i++)
            {
                spriteBatch.Draw(Furniture.furnitureTexture, Game1.GlobalToLocal(Game1.viewport, drawPosition + ((__instance.shakeTimer > 0) ? new Vector2(Game1.random.Next(-1, 2), Game1.random.Next(-1, 2)) : Vector2.Zero)) + new Vector2(third * i * 4, 0), new Rectangle?(drawn_second), Color.White * alpha, 0f, Vector2.Zero, 4f, __instance.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (__instance.boundingBox.Value.Top + 1) / 10000f);
            }
            spriteBatch.Draw(Furniture.furnitureTexture, Game1.GlobalToLocal(Game1.viewport, drawPosition + ((__instance.shakeTimer > 0) ? new Vector2(Game1.random.Next(-1, 2), Game1.random.Next(-1, 2)) : Vector2.Zero)) + new Vector2(third * (bedWidth) * 4, 0), new Rectangle?(drawn_third), Color.White * alpha, 0f, Vector2.Zero, 4f, __instance.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (__instance.boundingBox.Value.Top + 1) / 10000f);

            drawn_rect.X += drawn_rect.Width;
            drawn_first   = new Rectangle(drawn_rect.X, drawn_rect.Y, third, drawn_rect.Height);
            drawn_second  = new Rectangle(drawn_rect.X + third, drawn_rect.Y, third, drawn_rect.Height);
            drawn_third   = new Rectangle(drawn_rect.X + third + third, drawn_rect.Y, third, drawn_rect.Height);

            int solidHeight = 41;

            Rectangle drawn_first_t  = new Rectangle(drawn_rect.X, drawn_rect.Y + solidHeight, third, drawn_rect.Height - solidHeight);
            Rectangle drawn_second_t = new Rectangle(drawn_rect.X + third, drawn_rect.Y + solidHeight, third, drawn_rect.Height - solidHeight);
            Rectangle drawn_third_t  = new Rectangle(drawn_rect.X + third * 2, drawn_rect.Y + solidHeight, third, drawn_rect.Height - solidHeight);

            float sheetAlpha = alpha;

            if (Config.TransparentSheets)
            {
                sheetAlpha *= Config.SheetTransparency;
            }

            spriteBatch.Draw(Furniture.furnitureTexture, Game1.GlobalToLocal(Game1.viewport, drawPosition + ((__instance.shakeTimer > 0) ? new Vector2(Game1.random.Next(-1, 2), Game1.random.Next(-1, 2)) : Vector2.Zero)), new Rectangle?(drawn_first), Color.White * sheetAlpha, 0f, Vector2.Zero, 4f, __instance.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (__instance.boundingBox.Value.Bottom - 1) / 10000f);
            if (Config.TransparentSheets)
            {
                spriteBatch.Draw(Furniture.furnitureTexture, Game1.GlobalToLocal(Game1.viewport, drawPosition + ((__instance.shakeTimer > 0) ? new Vector2(Game1.random.Next(-1, 2), Game1.random.Next(-1, 2)) : Vector2.Zero)) + new Vector2(0, solidHeight * 4), new Rectangle?(drawn_first_t), Color.White, 0f, Vector2.Zero, 4f, __instance.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (__instance.boundingBox.Value.Bottom - 2) / 10000f);
            }

            for (int i = 1; i < bedWidth; i++)
            {
                spriteBatch.Draw(Furniture.furnitureTexture, Game1.GlobalToLocal(Game1.viewport, drawPosition + ((__instance.shakeTimer > 0) ? new Vector2(Game1.random.Next(-1, 2), Game1.random.Next(-1, 2)) : Vector2.Zero)) + new Vector2(third * i * 4, 0), new Rectangle?(drawn_second), Color.White * sheetAlpha, 0f, Vector2.Zero, 4f, __instance.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (__instance.boundingBox.Value.Bottom - 1) / 10000f);
                if (Config.TransparentSheets)
                {
                    spriteBatch.Draw(Furniture.furnitureTexture, Game1.GlobalToLocal(Game1.viewport, drawPosition + ((__instance.shakeTimer > 0) ? new Vector2(Game1.random.Next(-1, 2), Game1.random.Next(-1, 2)) : Vector2.Zero)) + new Vector2(0, solidHeight * 4) + new Vector2(third * i * 4, 0), new Rectangle?(drawn_second_t), Color.White, 0f, Vector2.Zero, 4f, __instance.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (__instance.boundingBox.Value.Bottom - 1) / 10000f);
                }
            }
            spriteBatch.Draw(Furniture.furnitureTexture, Game1.GlobalToLocal(Game1.viewport, drawPosition + ((__instance.shakeTimer > 0) ? new Vector2(Game1.random.Next(-1, 2), Game1.random.Next(-1, 2)) : Vector2.Zero)) + new Vector2(third * (bedWidth) * 4, 0), new Rectangle?(drawn_third), Color.White * sheetAlpha, 0f, Vector2.Zero, 4f, __instance.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (__instance.boundingBox.Value.Bottom - 1) / 10000f);
            if (Config.TransparentSheets)
            {
                spriteBatch.Draw(Furniture.furnitureTexture, Game1.GlobalToLocal(Game1.viewport, drawPosition + ((__instance.shakeTimer > 0) ? new Vector2(Game1.random.Next(-1, 2), Game1.random.Next(-1, 2)) : Vector2.Zero)) + new Vector2(0, solidHeight * 4) + new Vector2(third * (bedWidth) * 4, 0), new Rectangle?(drawn_third_t), Color.White, 0f, Vector2.Zero, 4f, __instance.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (__instance.boundingBox.Value.Bottom - 1) / 10000f);
            }

            return(false);
        }
Exemple #12
0
        internal static void ExpandKidsRoom(FarmHouse farmHouse)
        {
            return;

            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 width      = 14;
            int height     = 9;
            int startx     = 15;
            int starty     = 0;
            int ox         = ModEntry.config.ExistingKidsRoomOffsetX;
            int oy         = ModEntry.config.ExistingKidsRoomOffsetY;

            Map map = PHelper.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 < width * height; i++)
            {
                backIndexes.Add(getTileIndexAt(map, ox + startx + (i % width), oy + starty + (i / width), "Back"));
                backSheets.Add(sheets.IndexOf(getTileSheetIDAt(map, ox + startx + (i % width), oy + starty + (i / width), "Back")));
                frontIndexes.Add(getTileIndexAt(map, ox + startx + (i % width), oy + starty + (i / width), "Front"));
                frontSheets.Add(sheets.IndexOf(getTileSheetIDAt(map, ox + startx + (i % width), oy + starty + (i / width), "Front")));
                buildIndexes.Add(getTileIndexAt(map, ox + startx + (i % width), oy + starty + (i / width), "Buildings"));
                buildSheets.Add(sheets.IndexOf(getTileSheetIDAt(map, ox + startx + (i % width), oy + starty + (i / width), "Buildings")));
            }

            if (extraWidth > 0)
            {
                Monitor.Log("total width: " + (29 + ox + extraWidth));
                ExtendMap(farmHouse, 29 + ox + extraWidth);
            }

            int cribsWidth = (Math.Max(ModEntry.config.ExtraCribs, 0) + 1) * 3;
            int bedsWidth  = (Math.Max(ModEntry.config.ExtraKidsBeds, 0) + 1) * 4;
            int spaceWidth = Math.Max(ModEntry.config.ExtraKidsRoomWidth, 0) + 3;

            // cribs
            int k = 0;

            if (ModEntry.config.ExtraCribs >= 0)
            {
                for (int j = 0; j < ModEntry.config.ExtraCribs + 1; j++)
                {
                    for (int i = 0; i < 3 * height; i++)
                    {
                        int x  = ox + startx + (3 * j) + i % 3;
                        int y  = oy + starty + i / 3;
                        int xt = i % 3;
                        int yt = i / 3;

                        setupTile(x, y, xt, yt, farmHouse, frontIndexes, frontSheets, 14, 0);
                        setupTile(x, y, xt, yt, farmHouse, buildIndexes, buildSheets, 14, 1);
                        setupTile(x, y, xt, yt, farmHouse, backIndexes, backSheets, 14, 2);
                    }
                    farmHouse.setTileProperty(ox + startx + (3 * j), oy + starty + 5, "Buildings", "Action", $"Crib{j}");
                    farmHouse.setTileProperty(ox + startx + (3 * j) + 1, oy + starty + 5, "Buildings", "Action", $"Crib{j}");
                    farmHouse.setTileProperty(ox + startx + (3 * j) + 2, oy + starty + 5, "Buildings", "Action", $"Crib{j}");
                }
            }
            else             // remove existing crib
            {
                k = 0;
                for (int i = 0; i < 3 * height; i++)
                {
                    k %= (3 * height);

                    int x  = ox + startx + i % 3;
                    int y  = oy + starty + i / 3;
                    int xt = 3 + (k % 3);
                    int yt = k / 3;

                    setupTile(x, y, xt, yt, farmHouse, frontIndexes, frontSheets, 14, 0);
                    setupTile(x, y, xt, yt, farmHouse, buildIndexes, buildSheets, 14, 1);
                    setupTile(x, y, xt, yt, farmHouse, backIndexes, backSheets, 14, 2);
                    k++;
                }
            }

            // mid space

            k = 0;
            for (int i = 0; i < 3 * height; i++)
            {
                k %= (3 * height);

                int x  = cribsWidth + ox + startx + i % 3;
                int y  = oy + starty + i / 3;
                int xt = 3 + (k % 3);
                int yt = k / 3;

                setupTile(x, y, xt, yt, farmHouse, frontIndexes, frontSheets, 14, 0);
                setupTile(x, y, xt, yt, farmHouse, buildIndexes, buildSheets, 14, 1);
                setupTile(x, y, xt, yt, farmHouse, backIndexes, backSheets, 14, 2);
                k++;
            }

            if (ModEntry.config.ExtraKidsRoomWidth > 0)
            {
                k = 0;
                for (int j = 0; j < ModEntry.config.ExtraKidsRoomWidth / 3; j++)
                {
                    k = 0;
                    for (int i = 0; i < 3 * height; i++)
                    {
                        k %= (3 * height);

                        int x  = cribsWidth + 3 + ox + startx + (3 * j) + i % 3;
                        int y  = oy + starty + i / 3;
                        int xt = 3 + (k % 3);
                        int yt = k / 3;

                        setupTile(x, y, xt, yt, farmHouse, frontIndexes, frontSheets, 14, 0);
                        setupTile(x, y, xt, yt, farmHouse, buildIndexes, buildSheets, 14, 1);
                        setupTile(x, y, xt, yt, farmHouse, backIndexes, backSheets, 14, 2);
                        k++;
                    }
                }
                for (int j = 0; j < ModEntry.config.ExtraKidsRoomWidth % 3; j++)
                {
                    k %= 3;
                    for (int i = 0; i < height; i++)
                    {
                        int x  = cribsWidth + 3 + (3 * (ModEntry.config.ExtraKidsRoomWidth / 3)) + ox + startx + j;
                        int y  = oy + starty + i;
                        int xt = 3 + j;
                        int yt = i;

                        setupTile(x, y, xt, yt, farmHouse, frontIndexes, frontSheets, 14, 0);
                        setupTile(x, y, xt, yt, farmHouse, buildIndexes, buildSheets, 14, 1);
                        setupTile(x, y, xt, yt, farmHouse, backIndexes, backSheets, 14, 2);
                    }
                }
            }


            // beds
            if (ModEntry.config.ExtraKidsBeds >= 0)
            {
                for (int j = 0; j < ModEntry.config.ExtraKidsBeds + 1; j++)
                {
                    k = 0;
                    for (int i = 0; i < 4 * height; i++)
                    {
                        k %= (4 * height);

                        int x  = cribsWidth + spaceWidth + ox + startx + (4 * j) + i % 4;
                        int y  = oy + starty + i / 4;
                        int xt = 6 + (k % 4);
                        int yt = k / 4;

                        setupTile(x, y, xt, yt, farmHouse, frontIndexes, frontSheets, 14, 0);
                        setupTile(x, y, xt, yt, farmHouse, buildIndexes, buildSheets, 14, 1);
                        setupTile(x, y, xt, yt, farmHouse, backIndexes, backSheets, 14, 2);
                        k++;
                    }
                }

                // far bed and wall
                k = 0;
                for (int i = 0; i < 4 * height; i++)
                {
                    k %= (4 * height);
                    setupTile(cribsWidth + spaceWidth + bedsWidth + ox + startx + i % 4, oy + starty + i / 4, 10 + (k % 4), k / 4, farmHouse, frontIndexes, frontSheets, 14, 0);
                    setupTile(cribsWidth + spaceWidth + bedsWidth + ox + startx + i % 4, oy + starty + i / 4, 10 + (k % 4), k / 4, farmHouse, buildIndexes, buildSheets, 14, 1);
                    setupTile(cribsWidth + spaceWidth + bedsWidth + ox + startx + i % 4, oy + starty + i / 4, 10 + (k % 4), k / 4, farmHouse, backIndexes, backSheets, 14, 2);
                    k++;
                }
            }
            else if (ModEntry.config.ExtraKidsBeds == -1)
            {
                // remove left bed

                k = 0;
                for (int i = 0; i < 3 * height; i++)
                {
                    k %= (3 * height);

                    int x  = cribsWidth + spaceWidth + ox + startx + i % 3;
                    int y  = oy + starty + i / 3;
                    int xt = 3 + (k % 3);
                    int yt = k / 3;

                    setupTile(x, y, xt, yt, farmHouse, frontIndexes, frontSheets, 14, 0);
                    setupTile(x, y, xt, yt, farmHouse, buildIndexes, buildSheets, 14, 1);
                    setupTile(x, y, xt, yt, farmHouse, backIndexes, backSheets, 14, 2);
                    k++;
                }
                // extra strip

                for (int i = 0; i < height; i++)
                {
                    setupTile(cribsWidth + spaceWidth + 3 + ox + startx, oy + starty + i, 3, i, farmHouse, frontIndexes, frontSheets, 14, 0);
                    setupTile(cribsWidth + spaceWidth + 3 + ox + startx, oy + starty + i, 3, i, farmHouse, buildIndexes, buildSheets, 14, 1);
                    setupTile(cribsWidth + spaceWidth + 3 + ox + startx, oy + starty + i, 3, i, farmHouse, backIndexes, backSheets, 14, 2);
                }

                // far wall and bed
                k = 0;

                for (int i = 0; i < 4 * height; i++)
                {
                    k %= (4 * height);
                    setupTile(cribsWidth + spaceWidth + 4 + ox + startx + i % 4, oy + starty + i / 4, 10 + (k % 4), k / 4, farmHouse, frontIndexes, frontSheets, 14, 0);
                    setupTile(cribsWidth + spaceWidth + 4 + ox + startx + i % 4, oy + starty + i / 4, 10 + (k % 4), k / 4, farmHouse, buildIndexes, buildSheets, 14, 1);
                    setupTile(cribsWidth + spaceWidth + 4 + ox + startx + i % 4, oy + starty + i / 4, 10 + (k % 4), k / 4, farmHouse, backIndexes, backSheets, 14, 2);
                    k++;
                }
            }
            else
            {
                // remove both beds
                k = 0;
                for (int i = 0; i < 3 * height; i++)
                {
                    k %= (3 * height);

                    int x  = cribsWidth + spaceWidth + ox + startx + i % 3;
                    int y  = oy + starty + i / 3;
                    int xt = 3 + (k % 3);
                    int yt = k / 3;

                    setupTile(x, y, xt, yt, farmHouse, frontIndexes, frontSheets, 14, 0);
                    setupTile(x, y, xt, yt, farmHouse, buildIndexes, buildSheets, 14, 1);
                    setupTile(x, y, xt, yt, farmHouse, backIndexes, backSheets, 14, 2);
                    k++;
                }
                k = 0;
                for (int i = 0; i < 3 * height; i++)
                {
                    k %= (3 * height);

                    int x  = cribsWidth + spaceWidth + 3 + ox + startx + i % 3;
                    int y  = oy + starty + i / 3;
                    int xt = 3 + (k % 3);
                    int yt = k / 3;

                    setupTile(x, y, xt, yt, farmHouse, frontIndexes, frontSheets, 14, 0);
                    setupTile(x, y, xt, yt, farmHouse, buildIndexes, buildSheets, 14, 1);
                    setupTile(x, y, xt, yt, farmHouse, backIndexes, backSheets, 14, 2);
                    k++;
                }

                // extra strip

                for (int i = 0; i < height; i++)
                {
                    setupTile(cribsWidth + spaceWidth + 6 + ox + startx, oy + starty + i, i == height - 1 ? 12 : 3, i, farmHouse, frontIndexes, frontSheets, 14, 0);
                    setupTile(cribsWidth + spaceWidth + 6 + ox + startx, oy + starty + i, 3, i, farmHouse, buildIndexes, buildSheets, 14, 1);
                    setupTile(cribsWidth + spaceWidth + 6 + ox + startx, oy + starty + i, 3, i, farmHouse, backIndexes, backSheets, 14, 2);
                }

                // far wall

                for (int i = 0; i < height; i++)
                {
                    setupTile(cribsWidth + spaceWidth + 7 + ox + startx, oy + starty + i, 13, i, farmHouse, frontIndexes, frontSheets, 14, 0);
                    setupTile(cribsWidth + spaceWidth + 7 + ox + startx, oy + starty + i, 13, i, farmHouse, buildIndexes, buildSheets, 14, 1);
                    setupTile(cribsWidth + spaceWidth + 7 + ox + startx, oy + starty + i, 13, i, farmHouse, backIndexes, backSheets, 14, 2);
                }
            }
            // bottom
            for (int i = 0; i < extraWidth; i++)
            {
                Tile tile = map.GetLayer("Buildings").PickTile(new Location((29 + ox + i) * Game1.tileSize, (9 + oy) * Game1.tileSize), Game1.viewport.Size);
                if (tile == null || tile.TileIndex == -1)
                {
                    Monitor.Log($"Adding building tile at {29 + ox + i},{ 9 + oy}");
                    farmHouse.setMapTileIndex(29 + ox + i, 9 + oy, 0, "Buildings");
                }
            }
        }
Exemple #13
0
        public static void ReplaceBed(FarmHouse farmHouse)
        {
            return;

            try
            {
                Monitor.Log("Replacing bed");
                if (farmHouse == null || farmHouse.map == null)
                {
                    return;
                }

                // bed
                Map map;
                if (ModEntry.config.SleepOnCovers && !config.TransparentSheets)
                {
                    map = PHelper.Content.Load <Map>("assets/CustomBed.tmx");
                }
                else
                {
                    map = PHelper.Content.Load <Map>("Maps\\" + farmHouse.Name + ((farmHouse.upgradeLevel == 0) ? "" : (((farmHouse.upgradeLevel == 3) ? "2" : string.Concat(farmHouse.upgradeLevel)) + "_marriage")), ContentSource.GameContent);

                    if (!ModEntry.config.TransparentSheets && farmHouse.owner != null && !farmHouse.owner.activeDialogueEvents.ContainsKey("pennyRedecorating"))
                    {
                        int whichQuilt = -1;
                        if (farmHouse.owner.mailReceived.Contains("pennyQuilt0"))
                        {
                            whichQuilt = 0;
                        }
                        else if (farmHouse.owner.mailReceived.Contains("pennyQuilt1"))
                        {
                            whichQuilt = 1;
                        }
                        else if (farmHouse.owner.mailReceived.Contains("pennyQuilt2"))
                        {
                            whichQuilt = 2;
                        }
                        if (whichQuilt != -1)
                        {
                            Point startTile = Point.Zero;
                            if (farmHouse.upgradeLevel >= 2)
                            {
                                startTile = new Point(27, 12);
                            }
                            else if (farmHouse.upgradeLevel == 1)
                            {
                                startTile = new Point(21, 3);
                            }
                            if (!startTile.Equals(Point.Zero))
                            {
                                int startIndex = 61 + whichQuilt * 3;
                                setMapTileIndex(ref map, startTile.X, startTile.Y, startIndex, "Front", 1);
                                setMapTileIndex(ref map, startTile.X + 1, startTile.Y, startIndex + 1, "Front", 1);
                                setMapTileIndex(ref map, startTile.X + 2, startTile.Y, startIndex + 2, "Front", 1);
                                setMapTileIndex(ref map, startTile.X, startTile.Y + 1, startIndex + 12, "Front", 1);
                                setMapTileIndex(ref map, startTile.X + 1, startTile.Y + 1, startIndex + 13, "Front", 1);
                                setMapTileIndex(ref map, startTile.X + 2, startTile.Y + 1, startIndex + 14, "Front", 1);
                            }
                        }
                    }
                }
                int           untitled = 0;
                List <string> sheets   = new List <string>();
                for (int i = 0; i < farmHouse.map.TileSheets.Count; i++)
                {
                    sheets.Add(farmHouse.map.TileSheets[i].Id);
                    Monitor.Log($"bed sheet {farmHouse.map.TileSheets[i].Id} index: {i}");
                }
                untitled = sheets.IndexOf("untitled tile sheet");


                int ox = ModEntry.config.ExistingBedOffsetX;
                int oy = ModEntry.config.ExistingBedOffsetY;
                if (farmHouse.upgradeLevel > 1)
                {
                    ox += 6;
                    oy += 9;
                }

                int bedWidth = Misc.GetBedWidth(farmHouse);
                int width    = bedWidth - 1;
                int start    = 21 - (farmHouse.upgradeLevel > 1 ? (bedWidth / 2) - 1 : 0);

                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>();

                int sheetx = 0;
                int sheety = 0;
                if (!ModEntry.config.SleepOnCovers || config.TransparentSheets)
                {
                    sheetx = ox + 21;
                    sheety = oy + 2;
                }

                for (int i = 0; i < 12; i++)
                {
                    farmHouse.removeTile(ox + 21 + (i % 3), oy + 2 + (i / 3), "Front");
                    if (i > 2 && i < 9)
                    {
                        //farmHouse.removeTile(ox + 21 + (i % 3), oy + 2 + (i / 3), "Buildings");
                    }
                    backIndexes.Add(getTileIndexAt(map, sheetx + (i % 3), sheety + (i / 3), "Back"));
                    frontIndexes.Add(getTileIndexAt(map, sheetx + (i % 3), sheety + (i / 3), "Front"));
                    buildIndexes.Add(getTileIndexAt(map, sheetx + (i % 3), sheety + (i / 3), "Buildings"));
                    if (ModEntry.config.SleepOnCovers && !config.TransparentSheets)
                    {
                        backSheets.Add(untitled);
                        frontSheets.Add(untitled);
                        buildSheets.Add(untitled);
                    }
                    else
                    {
                        backSheets.Add(sheets.IndexOf(getTileSheetIDAt(map, sheetx + (i % 3), sheety + (i / 3), "Back")));
                        frontSheets.Add(sheets.IndexOf(getTileSheetIDAt(map, sheetx + (i % 3), sheety + (i / 3), "Front")));
                        buildSheets.Add(sheets.IndexOf(getTileSheetIDAt(map, sheetx + (i % 3), sheety + (i / 3), "Buildings")));
                    }
                }


                setupTile(start + ox, 2 + oy, 0, 0, farmHouse, frontIndexes, frontSheets, 3, 0);
                setupTile(start + ox, 3 + oy, 0, 1, farmHouse, frontIndexes, frontSheets, 3, 0);
                setupTile(start + ox, 3 + oy, 0, 1, farmHouse, buildIndexes, buildSheets, 3, 1);
                setupTile(start + ox, 4 + oy, 0, 2, farmHouse, frontIndexes, frontSheets, 3, 0);
                setupTile(start + ox, 4 + oy, 0, 2, farmHouse, backIndexes, backSheets, 3, 2);
                setupTile(start + ox, 5 + oy, 0, 3, farmHouse, buildIndexes, buildSheets, 3, 1);

                if (ModEntry.config.TransparentSheets)
                {
                    farmHouse.removeTile(start + ox, 4 + oy, "Back");
                    farmHouse.setMapTileIndex(start + ox, 4 + oy, 212, "Back", untitled);
                }

                farmHouse.setTileProperty(start + ox, oy + 3, "Back", "Bed", "T");
                farmHouse.setTileProperty(start + ox, oy + 4, "Back", "Bed", "T");
                farmHouse.setTileProperty(start + ox, oy + 3, "Back", "NoFurniture", "T");
                farmHouse.setTileProperty(start + ox, oy + 4, "Back", "NoFurniture", "T");

                //farmHouse.removeTile(ox + start, oy + 3, "Buildings");
                for (int i = 1; i < width; i++)
                {
                    //farmHouse.removeTile(ox + start + i, oy + 3, "Buildings");

                    setupTile(i + start + ox, 2 + oy, 1, 0, farmHouse, frontIndexes, frontSheets, 3, 0);
                    setupTile(i + start + ox, 3 + oy, 1, 1, farmHouse, frontIndexes, frontSheets, 3, 0);
                    setupTile(i + start + ox, 3 + oy, 1, 1, farmHouse, buildIndexes, buildSheets, 3, 1);
                    setupTile(i + start + ox, 4 + oy, 1, 2, farmHouse, frontIndexes, frontSheets, 3, 0);
                    setupTile(i + start + ox, 4 + oy, 1, 2, farmHouse, backIndexes, backSheets, 3, 2);
                    setupTile(i + start + ox, 5 + oy, 1, 3, farmHouse, buildIndexes, buildSheets, 3, 1);

                    if (ModEntry.config.TransparentSheets)
                    {
                        farmHouse.removeTile(i + start + ox, 4 + oy, "Back");
                        farmHouse.setMapTileIndex(i + start + ox, 4 + oy, 213, "Back", untitled);
                    }

                    farmHouse.setTileProperty(i + start + ox, oy + 3, "Back", "Bed", "T");
                    farmHouse.setTileProperty(i + start + ox, oy + 4, "Back", "Bed", "T");
                    farmHouse.setTileProperty(i + start + ox, oy + 3, "Back", "NoFurniture", "T");
                    farmHouse.setTileProperty(i + start + ox, oy + 4, "Back", "NoFurniture", "T");
                }
                //farmHouse.removeTile(width + ox + start, oy + 3, "Buildings");

                setupTile(width + start + ox, 2 + oy, 2, 0, farmHouse, frontIndexes, frontSheets, 3, 0);
                setupTile(width + start + ox, 3 + oy, 2, 1, farmHouse, frontIndexes, frontSheets, 3, 0);
                setupTile(width + start + ox, 3 + oy, 2, 1, farmHouse, buildIndexes, buildSheets, 3, 1);
                setupTile(width + start + ox, 4 + oy, 2, 2, farmHouse, frontIndexes, frontSheets, 3, 0);
                setupTile(width + start + ox, 4 + oy, 2, 2, farmHouse, backIndexes, backSheets, 3, 2);
                setupTile(width + start + ox, 5 + oy, 2, 3, farmHouse, buildIndexes, buildSheets, 3, 1);

                if (ModEntry.config.TransparentSheets)
                {
                    farmHouse.removeTile(width + start + ox, 4 + oy, "Back");
                    farmHouse.setMapTileIndex(width + start + ox, 4 + oy, 214, "Back", untitled);
                }

                farmHouse.setTileProperty(width + start + ox, oy + 3, "Back", "Bed", "T");
                farmHouse.setTileProperty(width + start + ox, oy + 4, "Back", "Bed", "T");
                farmHouse.setTileProperty(width + start + ox, oy + 3, "Back", "NoFurniture", "T");
                farmHouse.setTileProperty(width + start + ox, oy + 4, "Back", "NoFurniture", "T");

                farmHouse.setTileProperty(21 + ox, oy + 4, "Back", "asdf", "asdf");
                farmHouse.setTileProperty(22 + ox, oy + 4, "Back", "TouchAction", "Sleep");
                farmHouse.setTileProperty(23 + ox, oy + 4, "Back", "TouchAction", "Sleep2");
            }
            catch (Exception ex)
            {
                Monitor.Log($"Failed in {nameof(ReplaceBed)}:\n{ex}", LogLevel.Error);
            }
        }