public static void SoundInTheNightEvent_tickUpdate_Prefix(SoundInTheNightEvent __instance, NetInt ___behavior, ref int ___timer, ref bool ___playedSound, GameTime time) { if (!Config.EnableMod || ___behavior != 1) { return; } var e = time.ElapsedGameTime.Milliseconds; if (___timer + e > 3500 && !playedDefence && (defence < 0 || defence > struckSound)) { SMonitor.Log("Playing defence sound"); Game1.playSound(Config.DefenceSound); playedDefence = true; } if (___timer + e > 5300 && !playedExplode && (defence < 0 || defence > struckSound)) { SMonitor.Log("Playing explode sound"); Game1.playSound(Config.ExplodeSound); playedExplode = true; } if (___timer + e > 5300 && struckSound < strikeLocations.Count - 1) { struckSound++; playedDefence = false; playedExplode = false; ___playedSound = false; ___timer = 1000; } }
public static bool SoundInTheNightEvent_setUp_Prefix(SoundInTheNightEvent __instance, ref int ___timer, NetInt ___behavior, ref string ___soundName, ref string ___message, ref Vector2 ___targetLocation, ref bool __result) { if (!Config.EnableMod || ___behavior != 1) { return(true); } Random r = new Random((int)Game1.uniqueIDForThisGame + (int)Game1.stats.DaysPlayed); Farm f = Game1.getLocationFromName("Farm") as Farm; strikeLocations = new List <Vector2>(); playedDefence = false; playedExplode = false; struck = 0; struckSound = 0; total = r.Next(Config.MinMeteorites, Config.MaxMeteorites + 1); defence = Game1.getFarm().objects.Values.ToList().FindAll(o => o.ParentSheetIndex + "" == Config.DefenceObject || o.Name == Config.DefenceObject || o.Name.EndsWith("/" + Config.DefenceObject)).Count *Config.MeteorsPerObject; ___soundName = "Meteorite"; ___message = Game1.content.LoadString("Strings\\Events:SoundInTheNight_Meteorite"); __result = true; for (int i = 0; i < total; i++) { var target = new Vector2(r.Next(5, f.map.GetLayer("Back").TileWidth - 20), r.Next(5, f.map.GetLayer("Back").TileHeight - 4)); if (!Config.StrikeAnywhere) { while (i <= target.X + 1f) { int j = (int)target.Y; while (j <= target.Y + 1f) { Vector2 v = new Vector2(i, j); if (!f.isTileOpenBesidesTerrainFeatures(v) || !f.isTileOpenBesidesTerrainFeatures(new Vector2(v.X + 1f, v.Y)) || !f.isTileOpenBesidesTerrainFeatures(new Vector2(v.X + 1f, v.Y - 1f)) || !f.isTileOpenBesidesTerrainFeatures(new Vector2(v.X, v.Y - 1f)) || f.doesTileHaveProperty((int)v.X, (int)v.Y, "Water", "Back") != null || f.doesTileHaveProperty((int)v.X + 1, (int)v.Y, "Water", "Back") != null) { continue; } j++; } i++; } } if (strikeLocations.Count == 0) { ___targetLocation = target; } strikeLocations.Add(target); __result = false; } if (!__result) { SMonitor.Log($"Starting meteorite strike with {strikeLocations.Count}/{total} meteorites, {defence} defence objects found"); } else { SMonitor.Log($"Cancelling meteorite strike with {strikeLocations.Count}/{total} meteorites, {defence} defence objects found"); } return(false); }
public static void SoundInTheNightEvent_makeChangesToLocation_Postfix(SoundInTheNightEvent __instance, NetInt ___behavior, ref Vector2 ___targetLocation) { if (!Config.EnableMod || ___behavior != 1 || struck >= strikeLocations.Count - 1) { return; } ___targetLocation = strikeLocations[++struck]; //SMonitor.Log($"continuing with meteor {struck} at {___targetLocation}"); __instance.makeChangesToLocation(); }
public static bool SoundInTheNightEvent_makeChangesToLocation_Prefix(SoundInTheNightEvent __instance, NetInt ___behavior, ref Vector2 ___targetLocation) { if (!Config.EnableMod || ___behavior != 1 || (defence > -1 && struck >= defence)) { SMonitor.Log($"dropping meteor {struck} at {___targetLocation}"); return(true); } SMonitor.Log($"dropping debris for struck meteor {struck} at {___targetLocation}"); Game1.createMultipleObjectDebris(386, (int)___targetLocation.X, (int)___targetLocation.Y, 6, Game1.MasterPlayer.UniqueMultiplayerID, Game1.getFarm()); Game1.createMultipleObjectDebris(390, (int)___targetLocation.X, (int)___targetLocation.Y, 6, Game1.MasterPlayer.UniqueMultiplayerID, Game1.getFarm()); Game1.createMultipleObjectDebris(535, (int)___targetLocation.X, (int)___targetLocation.Y, 2, Game1.MasterPlayer.UniqueMultiplayerID, Game1.getFarm()); return(false); }
public static bool DetectAnimalAttack(ref SoundInTheNightEvent __instance) { try { if (!Game1.IsMasterGame) { return(true); } var behavior = mod.Helper.Reflection.GetField <NetInt>(__instance, "behavior"); var targetBuilding = mod.Helper.Reflection.GetField <Building>(__instance, "targetBuilding"); if (behavior.GetValue() != null && behavior.GetValue().Value == SoundInTheNightEvent.dogs && targetBuilding != null && targetBuilding.GetValue() != null) { AnimalHouse indoors = targetBuilding.GetValue().indoors.Value as AnimalHouse; long idOfRemove = 0L; foreach (long a in indoors.animalsThatLiveHere) { if (!indoors.animals.ContainsKey(a)) { idOfRemove = a; break; } } if (!Game1.getFarm().animals.ContainsKey(idOfRemove)) { return(true); } mod.WildAnimalVictim = Game1.getFarm().animals[idOfRemove]; } return(true); } catch (Exception e) { mod.ErrorLog("There was an exception in a patch", e); return(true); } }
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; }
internal void SetUp() { FailureMessage = $"Could not set tonight's event to {Name}: a condition for this event has not been fulfilled, or another event is taking precedence."; Conditions = new List <KeyValuePair <Func <bool>, string> >(); AddCondition(() => !Game1.weddingToday, "there's a wedding today"); switch (Name) { case "capsule": FarmEvent = new SoundInTheNightEvent(0); PersonalFarmEvent = null; SuccessMessage = "A strange capsule event will occur tonight."; AddCondition(() => Game1.year > 1, "the game year is 1"); AddCondition(() => !Game1.MasterPlayer.mailReceived.Contains("Got_Capsule"), "the strange capsule event has happened before"); break; case "meteorite": FarmEvent = new SoundInTheNightEvent(1); PersonalFarmEvent = null; SuccessMessage = "A meteorite event will occur tonight."; break; case "wild_animal_attack": FarmEvent = null; PersonalFarmEvent = new SoundInTheNightEvent(2); SuccessMessage = "A wild animal attack event will occur tonight."; break; case "owl_statue": FarmEvent = new SoundInTheNightEvent(3); PersonalFarmEvent = null; SuccessMessage = "An owl statue event will occur tonight."; break; case "fairy": FarmEvent = new FairyEvent(); PersonalFarmEvent = null; SuccessMessage = "A crop fairy event will occur tonight."; AddCondition(() => !Game1.currentSeason.Equals("winter"), "it's winter"); break; case "witch": FarmEvent = new WitchEvent(); PersonalFarmEvent = null; SuccessMessage = "A witch event will occur tonight."; break; case "NPC_child_request": FarmEvent = null; PersonalFarmEvent = new QuestionEvent(1); SuccessMessage = "Your NPC spouse will request a child tonight."; AddCondition(() => Game1.player.isMarried(), "you are not married"); AddCondition(() => Game1.player.spouse != null, "you do not have a spouse"); AddCondition(() => Game1.getCharacterFromName(Game1.player.spouse).canGetPregnant(), "your spouse cannot have children (or is a roommate)"); AddCondition(() => Game1.player.currentLocation == Game1.getLocationFromName(Game1.player.homeLocation), "you are not at home"); break; case "PC_child_request": FarmEvent = null; PersonalFarmEvent = new QuestionEvent(3); SuccessMessage = "You or your PC spouse will request a child tonight."; AddCondition(() => Context.IsMultiplayer, "this is a single-player game"); AddCondition(() => Game1.player.isMarried(), "you are not married"); AddCondition(() => Game1.player.team.GetSpouse(Game1.player.UniqueMultiplayerID).HasValue, "you are not married to another farmer"); AddCondition(() => Game1.player.GetSpouseFriendship().NextBirthingDate == null, "you are already going to have a child"); AddCondition(() => Game1.otherFarmers.ContainsKey(Game1.player.team.GetSpouse(Game1.player.UniqueMultiplayerID).Value), "your spouse is not in the game"); AddCondition(() => Game1.otherFarmers[Game1.player.team.GetSpouse(Game1.player.UniqueMultiplayerID).Value].currentLocation == Game1.player.currentLocation, "you and your spouse are not in the same location"); AddCondition(() => Game1.otherFarmers[Game1.player.team.GetSpouse(Game1.player.UniqueMultiplayerID).Value].currentLocation == Game1.getLocationFromName(Game1.otherFarmers[Game1.player.team.GetSpouse(Game1.player.UniqueMultiplayerID).Value].homeLocation) || Game1.otherFarmers[Game1.player.team.GetSpouse(Game1.player.UniqueMultiplayerID).Value].currentLocation == Game1.getLocationFromName(Game1.player.homeLocation), "you and your spouse are not in either of your houses"); AddCondition(() => Helper.Reflection.GetMethod(typeof(Utility), "playersCanGetPregnantHere").Invoke <bool>(Game1.otherFarmers[Game1.player.team.GetSpouse(Game1.player.UniqueMultiplayerID).Value].currentLocation as FarmHouse), "you don't have a crib, your crib is already occupied, or you already have 2 children"); break; case "animal_birth": FarmEvent = null; PersonalFarmEvent = new QuestionEvent(2); SuccessMessage = "An animal birth event will occur tonight."; break; case "giant_crop": if (tile == null) { break; } // players can only specify a crop ID when conditions aren't being enforced if (id > -1) { giantCrop = new GiantCrop(id, new Vector2((int)tile.X - 1, (int)tile.Y - 1)); giantCrop.modData.Add(ModEntry.mod.ModManifest.UniqueID, SDate.Now().ToString()); break; } // weddings don't prevent giant crops from spawning Conditions.Clear(); // first check whether there's actually a crop there; this will be a hard condition regardless of config AddCondition(() => location.terrainFeatures.ContainsKey(tile) && location.terrainFeatures[tile] is HoeDirt, $"there is no hoe dirt at ({(int)tile.X}, {(int)tile.Y})"); AddCondition(() => (location.terrainFeatures[tile] as HoeDirt).crop != null, $"there is no crop at ({(int)tile.X}, {(int)tile.Y})"); if (!EnforceEventConditions(out string message)) { Monitor.Log($"Could not set giant crop spawn for tonight because {message}.", LogLevel.Info); break; } SuccessMessage = $"A giant crop will spawn at ({(int)tile.X}, {(int)tile.Y}) tonight."; giantCrop = new GiantCrop((location.terrainFeatures[tile] as HoeDirt).crop.indexOfHarvest, new Vector2((int)tile.X - 1, (int)tile.Y - 1)); giantCrop.modData.Add(ModEntry.mod.ModManifest.UniqueID, SDate.Now().ToString()); if (!Helper.ModRegistry.IsLoaded("spacechase0.moregiantcrops") && !Helper.ModRegistry.IsLoaded("spacechase0.jsonassets")) { AddCondition(() => (location.terrainFeatures[tile] as HoeDirt).crop.indexOfHarvest == 276 || (location.terrainFeatures[tile] as HoeDirt).crop.indexOfHarvest == 190 || (location.terrainFeatures[tile] as HoeDirt).crop.indexOfHarvest == 254, "this type of crop cannot be giant"); } AddCondition(() => location is Farm, "you are not in a farm location"); AddCondition(() => (location.terrainFeatures[tile] as HoeDirt).state.Value == 1, $"the crop at ({(int)tile.X}, {(int)tile.Y}) is not watered"); AddCondition(() => (int)(location.terrainFeatures[tile] as HoeDirt).crop.currentPhase == (location.terrainFeatures[tile] as HoeDirt).crop.phaseDays.Count - 1, $"the crop at ({(int)tile.X}, {(int)tile.Y}) is not fully grown"); AddCondition(() => CheckGiantCropSquareForCrops(), $"the crop at ({(int)tile.X}, {(int)tile.Y}) is not at the center of a 3x3 square of crops of the same type"); AddCondition(() => CheckGiantCropSquareForCharacters(), $"there is a character in the way"); break; default: break; } }