public static FarmEvent PickPersonalFarmEvent_PostFix(FarmEvent __result) { Monitor.Log("Attempting to apply Harmony postfix to Utility.pickPersonalFarmEvent()", LogLevel.Trace); try { if (ModEntry.eventData != null && ModEntry.eventData.PersonalFarmEvent != null && (!ModEntry.Config.EnforceEventConditions || ModEntry.eventData.EnforceEventConditions(out _))) { if (ModEntry.Config.EnforceEventConditions && (__result is BirthingEvent || __result is PlayerCoupleBirthingEvent)) { Monitor.Log("Birth event has overriden player-provided event.", LogLevel.Debug); return(__result); } return(ModEntry.eventData.PersonalFarmEvent); } return(__result); } catch (Exception ex) { Monitor.Log($"Failed in {nameof(PickPersonalFarmEvent_PostFix)}:\n{ex}", LogLevel.Error); return(__result); } }
public override FarmEvent OnUtility_PickFarmEvent(Func <FarmEvent> action) { FarmEvent original = this.previousHooks.OnUtility_PickFarmEvent(action); SelectFarmEvent selectEvent = new SelectFarmEvent(original); return(BookcaseEvents.SelectFarmEvent.Post(selectEvent) ? null : selectEvent.SelectedEvent); }
public static FarmEvent PickFarmEvent_PostFix(FarmEvent __result) { Monitor.Log("Attempting to apply Harmony postfix to Utility.pickFarmEvent()", LogLevel.Trace); try { if (ModEntry.eventData != null) { if (ModEntry.Config.EnforceEventConditions && (__result is WorldChangeEvent || (__result is SoundInTheNightEvent ev && Helper.Reflection.GetField <NetInt>(ev, "behavior").GetValue() == 4))) { Monitor.Log("World change event has overriden player-provided event.", LogLevel.Debug); return(__result); } if (ModEntry.Config.EnforceEventConditions && !ModEntry.eventData.EnforceEventConditions(out string reason)) { Monitor.Log($"Player-provided event {ModEntry.eventData.Name} could not run because {reason}.", LogLevel.Debug); return(__result); } if (ModEntry.eventData.FarmEvent != null) { return(ModEntry.eventData.FarmEvent); } if (ModEntry.eventData.PersonalFarmEvent != null) { return(null); } } return(__result); } catch (Exception ex) { Monitor.Log($"Failed in {nameof(PickFarmEvent_PostFix)}:\n{ex}", LogLevel.Error); return(__result); } }
private void changeFarmEvent(object sender, EventArgsChooseNightlyFarmEvent args) { if (Game1.player.professions.Contains(PROFESSION_NIGHTLY_EVENTS) && !Game1.weddingToday && (args.NightEvent == null || (args.NightEvent is SoundInTheNightEvent && Helper.Reflection.GetField <NetInt>(args.NightEvent, "behavior").GetValue().Value == 2))) { //Log.Async("Doing event check"); FarmEvent ev = null; //for (uint i = 0; i < 100 && ev == null; ++i) // Testing purposes. { Game1.stats.daysPlayed += 999999; // To rig the rng to not just give the same results. try // Just in case. Want to make sure stats.daysPlayed gets fixed { ev = pickFarmEvent(); } catch (Exception) { } Game1.stats.daysPlayed -= 999999; //if (ev != null) Log.Async("ev=" + ev + " " + (ev is SoundInTheNightEvent ? (Util.GetInstanceField(typeof(SoundInTheNightEvent), ev, "behavior") + " " + Util.GetInstanceField(typeof(SoundInTheNightEvent), ev, "soundName")) : "?")); if (ev != null && ev.setUp()) { ev = null; } } if (ev != null) { Log.info($"Applying {ev} as tonight's nightly event, due to having PROFESSION_NIGHTLY_EVENTS"); args.NightEvent = ev; } } }
public static bool PickPersonalFarmEventPrefix(ref FarmEvent __result) { if (Game1.weddingToday) { Game1.showGlobalMessage($"Cannot attempt animal birth - wedding today"); return(true); } if (Game1.player.isMarried() && Game1.player.GetSpouseFriendship().DaysUntilBirthing == 0) { Game1.showGlobalMessage($"Cannot attempt animal birth - days until birthing child is 0"); return(true); } if (!Game1.IsMasterGame) { Game1.showGlobalMessage($"Cannot toggle attempt animal birth - not master game"); return(true); } __result = (FarmEvent) new QuestionEvent(2); return(false); }
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); }
internal static FarmEvent InvokeChooseNightlyFarmEvent(FarmEvent vanilla) { var args = new EventArgsChooseNightlyFarmEvent(); args.NightEvent = vanilla; Log.trace("Event: SelectHotbarSlot"); if (ChooseNightlyFarmEvent == null) { return(args.NightEvent); } Util.invokeEvent("SpaceEvents.SelectHotbarSlot", SelectHotbarSlot.GetInvocationList(), null, args); return(args.NightEvent); }
internal static FarmEvent InvokeChooseNightlyFarmEvent(FarmEvent vanilla) { var args = new EventArgsChooseNightlyFarmEvent { NightEvent = vanilla }; Log.Trace("Event: ChooseNightlyFarmEvent"); if (SpaceEvents.ChooseNightlyFarmEvent == null) { return(args.NightEvent); } Util.InvokeEvent("SpaceEvents.ChooseNightlyFarmEvent", SpaceEvents.ChooseNightlyFarmEvent.GetInvocationList(), null, args); return(args.NightEvent); }
public static void PickFarmEvent_Postfix(ref FarmEvent __result) { try { if (__result == null) { if (Game1.random.NextDouble() < 0.45) { __result = new WitchEvent(); } } } catch (Exception ex) { HatService.Monitor.Log($"Failed in {nameof(PickFarmEvent_Postfix)}:\n{ex}"); } }
public static void PickFarmEvent_Postfix(ref FarmEvent __result) { if (__result != null) { return; } Random random = new Random((int)Game1.stats.DaysPlayed + (int)Game1.uniqueIDForThisGame / 2); if (Game1.player.mailReceived.Contains(FAIRYFLAG) && random.NextDouble() < 0.25) { Log.Trace("RSV: Setting fairy event chance to 25%"); __result = new FairyEvent(); Game1.player.RemoveMail(FAIRYFLAG); } else if (Game1.player.mailReceived.Contains(METEORFLAG) && random.NextDouble() < 0.10) { Log.Trace("RSV: Setting meteor event chance to 10%"); __result = new SoundInTheNightEvent(1); Game1.player.RemoveMail(METEORFLAG); } }
public static void Utility_pickFarmEvent_Postfix(ref FarmEvent __result) { if (!Config.EnableMod) { return; } if (__result != null && !(__result is FairyEvent) && !(__result is WitchEvent)) { if (!(__result is SoundInTheNightEvent)) { return; } int b = AccessTools.FieldRefAccess <SoundInTheNightEvent, NetInt>(__result as SoundInTheNightEvent, "behavior").Value; if (b != 0 && b != 1 && b != 3) { return; } } SMonitor.Log("Checking for night event"); Random r = new Random((int)(Game1.stats.DaysPlayed + (uint)((int)Game1.uniqueIDForThisGame / 2))); if (Config.CumulativeChance) { float currentWeight = 0; double chance = r.NextDouble(); if (!Game1.currentSeason.Equals("winter")) { currentWeight += Config.FairyChance; if (chance < currentWeight / 100f) { __result = new FairyEvent(); SMonitor.Log("Setting fairy event"); return; } } currentWeight += Config.WitchChance; if (chance < currentWeight / 100f) { __result = new WitchEvent(); SMonitor.Log("Setting witch event"); return; } currentWeight += Config.MeteorChance; if (chance < currentWeight / 100f) { __result = new SoundInTheNightEvent(1); SMonitor.Log("Setting meteor event"); return; } currentWeight += Config.OwlChance; if (chance < currentWeight / 100f) { __result = new SoundInTheNightEvent(3); SMonitor.Log("Setting owl event"); return; } if (Game1.year > 1 && !Game1.MasterPlayer.mailReceived.Contains("Got_Capsule")) { currentWeight += Config.CapsuleChance; if (chance < currentWeight / 100f) { Game1.MasterPlayer.mailReceived.Add("Got_Capsule"); __result = new SoundInTheNightEvent(0); SMonitor.Log("Setting capsule event"); return; } } } else { if (r.NextDouble() < Config.FairyChance && !Game1.currentSeason.Equals("winter")) { __result = new FairyEvent(); SMonitor.Log("Setting fairy event"); return; } if (r.NextDouble() < Config.WitchChance) { __result = new WitchEvent(); SMonitor.Log("Setting witch event"); return; } if (r.NextDouble() < Config.MeteorChance) { __result = new SoundInTheNightEvent(1); SMonitor.Log("Setting meteor event"); return; } if (r.NextDouble() < Config.OwlChance) { __result = new SoundInTheNightEvent(3); SMonitor.Log("Setting owl event"); return; } if (r.NextDouble() < Config.CapsuleChance && Game1.year > 1 && !Game1.MasterPlayer.mailReceived.Contains("Got_Capsule")) { Game1.MasterPlayer.mailReceived.Add("Got_Capsule"); __result = new SoundInTheNightEvent(0); SMonitor.Log("Setting capsule event"); return; } } __result = null; }
/********* ** Private methods *********/ /// <summary>The method to call after <see cref="Utility.pickFarmEvent"/>.</summary> private static void After_PickFarmEvent(ref FarmEvent __result) { __result = SpaceEvents.InvokeChooseNightlyFarmEvent(__result); }
public static void Postfix(ref FarmEvent __result) { SelectFarmEvent selectEvent = new SelectFarmEvent(__result); __result = BookcaseEvents.SelectPersonalEvent.Post(selectEvent) ? null : selectEvent.SelectedEvent; }
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 void Postfix(ref FarmEvent __result) { SpaceEvents.InvokeChooseNightlyFarmEvent(__result); }
public SelectFarmEvent(FarmEvent original) { this.OriginalEvent = original; this.SelectedEvent = original; }
public static FarmEvent pickFarmEvent() { FarmEvent ret = null; { Random random = new Random((int)Game1.stats.DaysPlayed + (int)Game1.uniqueIDForThisGame / 2); if (Game1.weddingToday) { ret = (FarmEvent)null; } else if ((int)Game1.stats.DaysPlayed == 31) { ret = (FarmEvent) new SoundInTheNightEvent(4); } else if (Game1.player.mailForTomorrow.Contains("jojaPantry%&NL&%") || Game1.player.mailForTomorrow.Contains("jojaPantry")) { ret = (FarmEvent) new WorldChangeEvent(0); } else if (Game1.player.mailForTomorrow.Contains("ccPantry%&NL&%") || Game1.player.mailForTomorrow.Contains("ccPantry")) { ret = (FarmEvent) new WorldChangeEvent(1); } else if (Game1.player.mailForTomorrow.Contains("jojaVault%&NL&%") || Game1.player.mailForTomorrow.Contains("jojaVault")) { ret = (FarmEvent) new WorldChangeEvent(6); } else if (Game1.player.mailForTomorrow.Contains("ccVault%&NL&%") || Game1.player.mailForTomorrow.Contains("ccVault")) { ret = (FarmEvent) new WorldChangeEvent(7); } else if (Game1.player.mailForTomorrow.Contains("jojaBoilerRoom%&NL&%") || Game1.player.mailForTomorrow.Contains("jojaBoilerRoom")) { ret = (FarmEvent) new WorldChangeEvent(2); } else if (Game1.player.mailForTomorrow.Contains("ccBoilerRoom%&NL&%") || Game1.player.mailForTomorrow.Contains("ccBoilerRoom")) { ret = (FarmEvent) new WorldChangeEvent(3); } else if (Game1.player.mailForTomorrow.Contains("jojaCraftsRoom%&NL&%") || Game1.player.mailForTomorrow.Contains("jojaCraftsRoom")) { ret = (FarmEvent) new WorldChangeEvent(4); } else if (Game1.player.mailForTomorrow.Contains("ccCraftsRoom%&NL&%") || Game1.player.mailForTomorrow.Contains("ccCraftsRoom")) { ret = (FarmEvent) new WorldChangeEvent(5); } else if (Game1.player.mailForTomorrow.Contains("jojaFishTank%&NL&%") || Game1.player.mailForTomorrow.Contains("jojaFishTank")) { ret = (FarmEvent) new WorldChangeEvent(8); } else if (Game1.player.mailForTomorrow.Contains("ccFishTank%&NL&%") || Game1.player.mailForTomorrow.Contains("ccFishTank")) { ret = (FarmEvent) new WorldChangeEvent(9); } else if (Game1.player.isMarried() && Game1.player.spouse != null && Game1.getCharacterFromName(Game1.player.spouse, false).daysUntilBirthing == 0) { ret = (FarmEvent) new BirthingEvent(); } else if (Game1.player.isMarried() && Game1.player.spouse != null && (Game1.getCharacterFromName(Game1.player.spouse, false).canGetPregnant() && random.NextDouble() < 0.05)) { ret = (FarmEvent) new QuestionEvent(1); } else if (random.NextDouble() < 0.01 && !Game1.currentSeason.Equals("winter")) { ret = (FarmEvent) new FairyEvent(); } else if (random.NextDouble() < 0.01) { ret = (FarmEvent) new WitchEvent(); } else if (random.NextDouble() < 0.01) { ret = (FarmEvent) new SoundInTheNightEvent(1); } else if (random.NextDouble() < 0.01 && Game1.year > 1) { ret = (FarmEvent) new SoundInTheNightEvent(0); } else if (random.NextDouble() < 0.01) { ret = (FarmEvent) new SoundInTheNightEvent(3); } else if (random.NextDouble() < 0.5) { ret = (FarmEvent) new QuestionEvent(2); } else { ret = (FarmEvent) new SoundInTheNightEvent(2); } } return(SpaceEvents.InvokeChooseNightlyFarmEvent(ret)); }