public static bool Utility_pickPersonalFarmEvent_Prefix(ref FarmEvent __result) { lastBirthingSpouse = null; lastPregnantSpouse = null; ModEntry.PMonitor.Log("picking event"); if (Game1.weddingToday) { __result = null; return(false); } List <NPC> allSpouses = Misc.GetSpouses(Game1.player, 1).Values.ToList(); Misc.ShuffleList(ref allSpouses); foreach (NPC spouse in allSpouses) { if (spouse == null) { Monitor.Log($"Utility_pickPersonalFarmEvent_Prefix spouse is null"); continue; } Farmer f = spouse.getSpouse(); Friendship friendship = f.friendshipData[spouse.Name]; if (friendship.DaysUntilBirthing <= 0 && friendship.NextBirthingDate != null) { lastBirthingSpouse = spouse; __result = new BirthingEvent(); return(false); } } foreach (NPC spouse in allSpouses) { Farmer f = spouse.getSpouse(); if (!ModEntry.config.RoommateRomance && f.friendshipData[spouse.Name].RoommateMarriage) { continue; } int heartsWithSpouse = f.getFriendshipHeartLevelForNPC(spouse.Name); Friendship friendship = f.friendshipData[spouse.Name]; List <Child> kids = f.getChildren(); bool can = spouse.daysAfterLastBirth <= 0 && Utility.getHomeOfFarmer(f).upgradeLevel >= 2 && friendship.DaysUntilBirthing < 0 && heartsWithSpouse >= 10 && friendship.DaysMarried >= 7 && (ModEntry.config.MaxChildren < 0 || kids.Count == 0 || (kids.Count < ModEntry.config.MaxChildren)); ModEntry.PMonitor.Log($"Checking ability to get pregnant: {spouse.Name} {can}:{(Utility.getHomeOfFarmer(f).upgradeLevel < 2 ? $" house level too low {Utility.getHomeOfFarmer(f).upgradeLevel}":"")}{(friendship.DaysMarried < 7 ? $" not married long enough {friendship.DaysMarried}":"")}{(friendship.DaysUntilBirthing >= 0 ? "Already pregnant! Gives birth in: "+friendship.DaysUntilBirthing:"")}"); if (can && Game1.player.currentLocation == Game1.getLocationFromName(Game1.player.homeLocation) && ModEntry.myRand.NextDouble() < ModEntry.config.BabyRequestChance) { ModEntry.PMonitor.Log("Making a baby!"); lastPregnantSpouse = spouse; __result = new QuestionEvent(1); return(false); } } return(true); }
public static bool Prefix(ref FarmEvent __result) { //Skip if there's a wedding if (Game1.weddingToday) { return(true); } //Skip if there's a birth //(This is very close to the original code) if (Game1.player.isMarried() && Game1.player.GetSpouseFriendship().DaysUntilBirthing <= 0 && Game1.player.GetSpouseFriendship().NextBirthingDate != null) { if (Game1.player.spouse != null) { __result = new BirthingEvent(); return(false); } long key = Game1.player.team.GetSpouse(Game1.player.UniqueMultiplayerID).Value; if (Game1.otherFarmers.ContainsKey(key)) { __result = new PlayerCoupleBirthingEvent(); return(false); } } Random random = new Random((int)Game1.stats.DaysPlayed + (int)Game1.uniqueIDForThisGame / 2 ^ 470124797 + (int)Game1.player.UniqueMultiplayerID); //Checking for a baby QuestionEvent if (Game1.player.isMarried()) { //(It helps the flow of if statements to get local variables here, even if unnecessary.) bool message = ModEntry.MessagesConfig(); string npcSpouse = Game1.player.spouse; long? playerSpouse = Game1.player.team.GetSpouse(Game1.player.UniqueMultiplayerID); //QuestionEvent for an NPC spouse if (npcSpouse != null && Game1.getCharacterFromName(npcSpouse, true).canGetPregnant() && Game1.player.currentLocation == Game1.getLocationFromName(Game1.player.homeLocation.Value)) { //QuestionEvent(1) is possible bool isGaySpouse = Game1.getCharacterFromName(npcSpouse, true).isGaySpouse(); if (message) { if (isGaySpouse) { ModEntry.monitor.Log(npcSpouse + " may ask you about adopting a baby tonight.", StardewModdingAPI.LogLevel.Info); } else { ModEntry.monitor.Log(npcSpouse + " may ask you about having a baby tonight.", StardewModdingAPI.LogLevel.Info); } } //Random check //(ModEntry.GetFamilyData().BabyQuestionChance defaults to 5 -> the default 0.05 value) int questionPercent = ModEntry.GetFamilyData().BabyQuestionChance; if (random.NextDouble() < (questionPercent / 100.0)) { if (message) { if (isGaySpouse) { ModEntry.monitor.Log(npcSpouse + " will ask you about adopting a baby tonight.", StardewModdingAPI.LogLevel.Info); } else { ModEntry.monitor.Log(npcSpouse + " will ask you about having a baby tonight.", StardewModdingAPI.LogLevel.Info); } } __result = new QuestionEvent(1); return(false); } if (message) { if (isGaySpouse) { ModEntry.monitor.Log(npcSpouse + " could have asked about adopting a baby tonight, but luck was not on your side. (" + questionPercent + "% chance.)", StardewModdingAPI.LogLevel.Info); } else { ModEntry.monitor.Log(npcSpouse + " could have asked about having a baby tonight, but luck was not on your side. (" + questionPercent + "% chance.)", StardewModdingAPI.LogLevel.Info); } } } //QuestionEvent for a player spouse else if (playerSpouse.HasValue && Game1.player.GetSpouseFriendship().NextBirthingDate == null) { Game1.otherFarmers.TryGetValue(playerSpouse.Value, out Farmer otherFarmer); if (otherFarmer != null && otherFarmer.currentLocation == Game1.player.currentLocation && (otherFarmer.currentLocation == Game1.getLocationFromName(otherFarmer.homeLocation.Value) || otherFarmer.currentLocation == Game1.getLocationFromName(Game1.player.homeLocation.Value))) { //(I needed to use reflection because Utility.playersCanGetPregnantHere is a private method.) if (ModEntry.helper.Reflection.GetMethod(typeof(Utility), "playersCanGetPregnantHere", true).Invoke <bool>(new object[] { otherFarmer.currentLocation as FarmHouse })) { //QuestionEvent(3) is possible if (message) { ModEntry.monitor.Log(otherFarmer.Name + " may ask about having a baby tonight.", StardewModdingAPI.LogLevel.Info); } //Random check //(ModEntry.GetFamilyData().BabyQuestionChance defaults to 5 -> the default 0.05 value) int questionPercent = ModEntry.GetFamilyData().BabyQuestionChance; if (random.NextDouble() < (questionPercent / 100.0)) { if (message) { ModEntry.monitor.Log(otherFarmer.Name + " will ask about having a baby tonight.", StardewModdingAPI.LogLevel.Info); } __result = new QuestionEvent(3); return(false); } if (message) { ModEntry.monitor.Log(otherFarmer.Name + " could have asked about having a baby tonight, but luck was not on your side. (There was a " + questionPercent + "% chance.)", StardewModdingAPI.LogLevel.Info); } } } } else if (message) { ModEntry.monitor.Log("Your spouse cannot ask about having a baby tonight."); } } //If no other event happened, then check for animal events __result = random.NextDouble() < 0.5 ? (FarmEvent) new QuestionEvent(2) : (FarmEvent) new SoundInTheNightEvent(2); return(false); }
public static bool BirthingEvent_tickUpdate_Prefix(GameTime time, BirthingEvent __instance, ref bool __result, ref int ___timer, string ___soundName, ref bool ___playedSound, string ___message, ref bool ___naming, bool ___getBabyName, bool ___isMale, string ___babyName) { if (!Config.EnableMod || !___getBabyName) { return(true); } Game1.player.CanMove = false; ___timer += time.ElapsedGameTime.Milliseconds; Game1.fadeToBlackAlpha = 1f; if (!___naming) { Game1.activeClickableMenu = new NamingMenu(new NamingMenu.doneNamingBehavior(__instance.returnBabyName), Game1.content.LoadString(___isMale ? "Strings\\Events:BabyNamingTitle_Male" : "Strings\\Events:BabyNamingTitle_Female"), ""); ___naming = true; } if (___babyName != null && ___babyName != "" && ___babyName.Length > 0) { double chance = (lastBirthingSpouse.Name.Equals("Maru") || lastBirthingSpouse.Name.Equals("Krobus")) ? 0.5 : 0.0; chance += (Game1.player.hasDarkSkin() ? 0.5 : 0.0); bool isDarkSkinned = new Random((int)Game1.uniqueIDForThisGame + (int)Game1.stats.DaysPlayed).NextDouble() < chance; string newBabyName = ___babyName; DisposableList <NPC> all_characters = Utility.getAllCharacters(); bool collision_found = false; do { collision_found = false; using (DisposableList <NPC> .Enumerator enumerator = all_characters.GetEnumerator()) { while (enumerator.MoveNext()) { if (enumerator.Current.Name.Equals(newBabyName)) { newBabyName += " "; collision_found = true; break; } } } }while (collision_found); Child baby = new Child(newBabyName, ___isMale, isDarkSkinned, Game1.player) { Age = 0, Position = new Vector2(16f, 4f) * 64f + new Vector2(0f + myRand.Next(-64, 48), -24f + myRand.Next(-24, 24)), }; baby.modData["aedenthorn.FreeLove/OtherParent"] = lastBirthingSpouse.Name; Utility.getHomeOfFarmer(Game1.player).characters.Add(baby); Game1.playSound("smallSelect"); Game1.getCharacterFromName(lastBirthingSpouse.Name).daysAfterLastBirth = 5; Game1.player.friendshipData[lastBirthingSpouse.Name].NextBirthingDate = null; if (Game1.player.getChildrenCount() == 2) { Game1.getCharacterFromName(lastBirthingSpouse.Name).shouldSayMarriageDialogue.Value = true; Game1.getCharacterFromName(lastBirthingSpouse.Name).currentMarriageDialogue.Insert(0, new MarriageDialogueReference("Data\\ExtraDialogue", "NewChild_SecondChild" + myRand.Next(1, 3), true, new string[0])); Game1.getSteamAchievement("Achievement_FullHouse"); } else if (lastBirthingSpouse.isGaySpouse()) { Game1.getCharacterFromName(lastBirthingSpouse.Name).currentMarriageDialogue.Insert(0, new MarriageDialogueReference("Data\\ExtraDialogue", "NewChild_Adoption", true, new string[] { ___babyName })); } else { Game1.getCharacterFromName(lastBirthingSpouse.Name).currentMarriageDialogue.Insert(0, new MarriageDialogueReference("Data\\ExtraDialogue", "NewChild_FirstChild", true, new string[] { ___babyName })); } Game1.morningQueue.Enqueue(delegate { mp.globalChatInfoMessage("Baby", new string[] { Lexicon.capitalize(Game1.player.Name), Game1.player.spouse, Lexicon.getGenderedChildTerm(___isMale), Lexicon.getPronoun(___isMale), baby.displayName }); }); if (Game1.keyboardDispatcher != null) { Game1.keyboardDispatcher.Subscriber = null; } Game1.player.Position = Utility.PointToVector2(Utility.getHomeOfFarmer(Game1.player).getBedSpot()) * 64f; Game1.globalFadeToClear(null, 0.02f); lastBirthingSpouse = null; __result = true; return(false); } __result = false; return(false); }