Exemplo n.º 1
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();
                    }
                }
            }
        }