public static void Object_minutesElapsed_Postfix(Object __instance, int minutes, GameLocation environment) { if (__instance.name.Equals("Slime Incubator") && __instance.heldObject?.Value?.name?.EndsWith("Familiar Egg") == true && __instance.minutesUntilReady <= 0) { Vector2 v = new Vector2((float)((int)__instance.tileLocation.X), (float)((int)__instance.tileLocation.Y + 1)) * 64f; string name = __instance.heldObject.Value.name; if (!name.EndsWith("Familiar Egg")) { return; } Familiar familiar = null; Monitor.Log($"Hatched a familiar from {__instance.heldObject.Value.name} time {Game1.timeOfDay} owner {__instance.owner}"); long owner = __instance.owner; if (owner == 0) { owner = Game1.MasterPlayer.UniqueMultiplayerID; } switch (__instance.heldObject.Value.name) { case "Dino Familiar Egg": familiar = new DinoFamiliar(v, owner); break; case "Dust Sprite Familiar Egg": familiar = new DustSpriteFamiliar(v, owner); break; case "Bat Familiar Egg": familiar = new BatFamiliar(v, owner); break; case "Junimo Familiar Egg": familiar = new JunimoFamiliar(v, owner); break; case "Butterfly Familiar Egg": familiar = new ButterflyFamiliar(v, owner); break; } if (familiar != null) { Game1.showGlobalMessage(string.Format(Helper.Translation.Get("familiar-hatched"), Helper.Translation.Get(familiar.Name))); familiar.setTilePosition((int)__instance.tileLocation.X, (int)__instance.tileLocation.Y + 1); environment.characters.Add(familiar); __instance.heldObject.Value = null; __instance.ParentSheetIndex = 156; __instance.minutesUntilReady.Value = -1; } } }
public static bool monstersColliding(Familiar m1, Monster m2) { if (m1.Equals(m2) || m1.Health <= 0 || m2.Health <= 0 || m2.IsInvisible) { return(false); } Rectangle m1l = m1.GetBoundingBox(); Rectangle m2l = m2.GetBoundingBox(); return(m1l.Intersects(m2l)); }
public static bool withinMonsterThreshold(Familiar m1, Monster m2, int threshold) { if (m1.Equals(m2) || m1.Health <= 0 || m2.Health <= 0 || m2.IsInvisible || m2.isInvincible()) { return(false); } Vector2 m1l = m1.getTileLocation(); Vector2 m2l = m2.getTileLocation(); return(Math.Abs(m2l.X - m1l.X) <= (float)threshold && Math.Abs(m2l.Y - m1l.Y) <= (float)threshold); }
public static void Object_DayUpdate_Postfix(Object __instance, GameLocation location) { if (__instance.name.Equals("Slime Incubator") && __instance.minutesUntilReady <= 0 && __instance.heldObject.Value != null) { Vector2 v = new Vector2((float)((int)__instance.tileLocation.X), (float)((int)__instance.tileLocation.Y + 1)) * 64f; string name = __instance.heldObject.Value.name; if (!name.EndsWith("Familiar Egg")) { return; } Familiar familiar = null; switch (name) { case "Dino Familiar Egg": familiar = new DinoFamiliar(v, __instance.owner); break; case "Dust Sprite Familiar Egg": familiar = new DustSpriteFamiliar(v, __instance.owner); break; case "Bat Familiar Egg": familiar = new BatFamiliar(v, __instance.owner); break; case "Junimo Familiar Egg": familiar = new JunimoFamiliar(v, __instance.owner); break; case "Butterfly Familiar Egg": familiar = new ButterflyFamiliar(v, __instance.owner); break; } if (familiar != null) { Game1.showGlobalMessage(string.Format(Helper.Translation.Get("familiar-hatched"), Helper.Translation.Get(familiar.Name))); familiar.setTilePosition((int)__instance.tileLocation.X, (int)__instance.tileLocation.Y + 1); location.characters.Add(familiar); __instance.heldObject.Value = null; __instance.ParentSheetIndex = 156; __instance.minutesUntilReady.Value = -1; } } }
public static void monsterDrop(Familiar familiar, Monster monster, Farmer owner) { IList <int> objects = monster.objectsToDrop; if (Game1.player.isWearingRing(526)) { string result = ""; Game1.content.Load <Dictionary <string, string> >("Data\\Monsters").TryGetValue(monster.Name, out result); if (result != null && result.Length > 0) { string[] objectsSplit = result.Split(new char[] { '/' })[6].Split(new char[] { ' ' }); for (int i = 0; i < objectsSplit.Length; i += 2) { if (Game1.random.NextDouble() < Convert.ToDouble(objectsSplit[i + 1])) { objects.Add(Convert.ToInt32(objectsSplit[i])); } } } } if (objects == null || objects.Count == 0) { return; } int objectToAdd = objects[Game1.random.Next(objects.Count)]; if (objectToAdd < 0) { familiar.currentLocation.debris.Add(Game1.createItemDebris(new StardewValley.Object(Math.Abs(objectToAdd), Game1.random.Next(1, 4)), familiar.position, Game1.random.Next(4))); } else { familiar.currentLocation.debris.Add(Game1.createItemDebris(new StardewValley.Object(Math.Abs(objectToAdd), 1), familiar.position, Game1.random.Next(4))); } }