示例#1
0
        public static void FarmHouse_resetLocalState_Postfix(ref FarmHouse __instance)
        {
            try
            {
                Farmer f = __instance.owner;

                if (f == null)
                {
                    return;
                }
                ModEntry.PMonitor.Log($"reset farmhouse state - upgrade level {__instance.upgradeLevel}");

                Misc.ResetSpouses(f);

                if (f.currentLocation == __instance && Misc.IsInBed(__instance, f.GetBoundingBox()))
                {
                    f.position.Value = Misc.GetFarmerBedPosition(__instance);
                }
                if (ModEntry.config.CustomBed && __instance.upgradeLevel > 0)
                {
                    Maps.ReplaceBed(__instance);
                }
                if (__instance.upgradeLevel > 0 && __instance.upgradeLevel < 4)
                {
                    Maps.BuildSpouseRooms(__instance);
                    __instance.setFloors();
                }
                if (Misc.ChangingKidsRoom())
                {
                    if (__instance.upgradeLevel > 1 && __instance.upgradeLevel < 4)
                    {
                        NPCPatches.SetCribs(__instance);
                        Maps.ExpandKidsRoom(__instance);
                    }
                }
                if (Misc.GetSpouses(f, 0).ContainsKey("Sebastian") && Game1.netWorldState.Value.hasWorldStateID("sebastianFrog"))
                {
                    if (Game1.random.NextDouble() < 0.1 && Game1.timeOfDay > 610)
                    {
                        DelayedAction.playSoundAfterDelay("croak", 1000, null, -1);
                    }
                }
            }
            catch (Exception ex)
            {
                Monitor.Log($"Failed in {nameof(FarmHouse_resetLocalState_Postfix)}:\n{ex}", LogLevel.Error);
            }
        }
示例#2
0
        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);
            }
        }
示例#3
0
        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 = Misc.ReorderSpousesForSleeping(allSpouses.FindAll((s) => ModEntry.config.RoommateRomance || !fh.owner.friendshipData[s].RoommateMarriage));

                    foreach (NPC character in fh.characters)
                    {
                        if (!(character.currentLocation == fh))
                        {
                            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);
                                    if (Game1.timeOfDay >= 2000 || Game1.timeOfDay <= 600)
                                    {
                                        character.position.Value      = bedPos;
                                        character.ignoreScheduleToday = true;
                                        if (!character.isSleeping.Value)
                                        {
                                            Monitor.Log($"putting {character.Name} to sleep");
                                            character.isSleeping.Value = true;
                                        }
                                        if (character.Sprite.CurrentAnimation == null)
                                        {
                                            if (!Misc.HasSleepingAnimation(character.Name))
                                            {
                                                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 if (Game1.timeOfDay < 2000 && Game1.timeOfDay > 600)
                            {
                                character.farmerPassesThrough = false;
                                character.HideShadow          = false;
                                character.isSleeping.Value    = false;
                            }
                        }
                    }
                    if (location == Game1.player.currentLocation && ModEntry.config.AllowSpousesToKiss)
                    {
                        Kissing.TrySpousesKiss();
                    }
                }
            }
        }