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 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; } } }
internal static void LoadFamiliars() { FamiliarSaveData fsd = Helper.Data.ReadSaveData <FamiliarSaveData>("familiars") ?? new FamiliarSaveData(); foreach (FamiliarData f in fsd.dustSpriteFamiliars) { Monitor.Log($"Got saved Dust Familiar at {f.currentLocation}"); GameLocation l = null; if (Game1.getLocationFromName(f.currentLocation) != null) { l = Game1.getLocationFromName(f.currentLocation); } else { l = Game1.getFarm().buildings.FirstOrDefault(b => b.buildingType == "Slime Hutch")?.indoors.Value; } if (l == null) { continue; } Monitor.Log($"Returning saved Dust Familiar to {l.Name}"); DustSpriteFamiliar d = new DustSpriteFamiliar(f.position, f.ownerId); d.followingOwner = f.followingOwner; d.daysOld.Value = f.daysOld; d.exp.Value = f.exp; d.mainColor = f.mainColor; d.redColor = f.redColor; d.greenColor = f.greenColor; d.blueColor = f.blueColor; d.SetScale(); d.currentLocation = l; l.characters.Add(d); } foreach (FamiliarData f in fsd.dinoFamiliars) { Monitor.Log($"Got saved Dino Familiar at {f.currentLocation}"); GameLocation l = null; if (Game1.getLocationFromName(f.currentLocation) != null) { l = Game1.getLocationFromName(f.currentLocation); } else { l = Game1.getFarm().buildings.FirstOrDefault(b => b.buildingType == "Slime Hutch")?.indoors.Value; } if (l == null) { continue; } Monitor.Log($"Returning saved Dino Familiar to {l.Name}"); DinoFamiliar d = new DinoFamiliar(f.position, f.ownerId); d.followingOwner = f.followingOwner; d.daysOld.Value = f.daysOld; d.exp.Value = f.exp; d.mainColor = f.mainColor; d.redColor = f.redColor; d.greenColor = f.greenColor; d.blueColor = f.blueColor; d.SetScale(); d.currentLocation = l; l.characters.Add(d); } foreach (FamiliarData f in fsd.batFamiliars) { Monitor.Log($"Got saved Bat Familiar at {f.currentLocation}"); GameLocation l = null; if (Game1.getLocationFromName(f.currentLocation) != null) { l = Game1.getLocationFromName(f.currentLocation); } else { l = Game1.getFarm().buildings.FirstOrDefault(b => b.buildingType == "Slime Hutch")?.indoors.Value; } if (l == null) { continue; } Monitor.Log($"Returning saved Bat Familiar to {l.Name}"); BatFamiliar d = new BatFamiliar(f.position, f.ownerId); d.followingOwner = f.followingOwner; d.daysOld.Value = f.daysOld; d.exp.Value = f.exp; d.mainColor = f.mainColor; d.redColor = f.redColor; d.greenColor = f.greenColor; d.blueColor = f.blueColor; d.SetScale(); d.currentLocation = l; l.characters.Add(d); } foreach (FamiliarData f in fsd.junimoFamiliars) { Monitor.Log($"Got saved Junimo Familiar at {f.currentLocation}"); GameLocation l = null; if (Game1.getLocationFromName(f.currentLocation) != null) { l = Game1.getLocationFromName(f.currentLocation); } else { l = Game1.getFarm().buildings.FirstOrDefault(b => b.buildingType == "Slime Hutch")?.indoors.Value; } if (l == null) { continue; } Monitor.Log($"Returning saved Junimo Familiar to {l.Name}"); JunimoFamiliar d = new JunimoFamiliar(f.position, f.ownerId); d.followingOwner = f.followingOwner; d.daysOld.Value = f.daysOld; d.exp.Value = f.exp; d.mainColor = f.mainColor; d.redColor = f.redColor; d.greenColor = f.greenColor; d.blueColor = f.blueColor; if (f.color != null && f.color.A == 255) { d.color.Value = f.color; } else { d.color.Value = FamiliarsUtils.GetJunimoColor(); } d.SetScale(); d.currentLocation = l; l.characters.Add(d); } foreach (FamiliarData f in fsd.butterflyFamiliars) { Monitor.Log($"Got saved Butterfly Familiar at {f.currentLocation}"); GameLocation l = null; if (Game1.getLocationFromName(f.currentLocation) != null) { l = Game1.getLocationFromName(f.currentLocation); } else { l = Game1.getFarm().buildings.FirstOrDefault(b => b.buildingType == "Slime Hutch")?.indoors.Value; } if (l == null) { continue; } Monitor.Log($"Returning saved Butterfly Familiar to {l.Name}"); ButterflyFamiliar d = new ButterflyFamiliar(f.position, f.ownerId); d.followingOwner = f.followingOwner; d.daysOld.Value = f.daysOld; d.exp.Value = f.exp; d.mainColor = f.mainColor; d.redColor = f.redColor; d.greenColor = f.greenColor; d.blueColor = f.blueColor; d.baseFrame = f.baseFrame; d.SetScale(); d.currentLocation = l; d.baseFrame = f.baseFrame; d.reloadSprite(); l.characters.Add(d); } }
internal static void LoadFamiliars() { FamiliarSaveData fsd = Helper.Data.ReadSaveData <FamiliarSaveData>("familiars") ?? new FamiliarSaveData(); foreach (FamiliarData f in fsd.dustSpriteFamiliars) { GameLocation l = Game1.getLocationFromName(f.currentLocation); if (l != null) { Monitor.Log($"Returning saved Dust Familiar to {l.Name}"); DustSpriteFamiliar d = new DustSpriteFamiliar(f.position, f.ownerId); d.followingOwner = f.followingOwner; d.daysOld.Value = f.daysOld; d.exp.Value = f.exp; d.mainColor = f.mainColor; d.redColor = f.redColor; d.greenColor = f.greenColor; d.blueColor = f.blueColor; d.SetScale(); d.currentLocation = l; l.characters.Add(d); } } foreach (FamiliarData f in fsd.dinoFamiliars) { GameLocation l = Game1.getLocationFromName(f.currentLocation); if (l != null) { Monitor.Log($"Returning saved Dino Familiar to {l.Name}"); DinoFamiliar d = new DinoFamiliar(f.position, f.ownerId); d.followingOwner = f.followingOwner; d.daysOld.Value = f.daysOld; d.exp.Value = f.exp; d.mainColor = f.mainColor; d.redColor = f.redColor; d.greenColor = f.greenColor; d.blueColor = f.blueColor; d.SetScale(); d.currentLocation = l; l.characters.Add(d); } } foreach (FamiliarData f in fsd.batFamiliars) { GameLocation l = Game1.getLocationFromName(f.currentLocation); if (l != null) { Monitor.Log($"Returning saved Bat Familiar to {l.Name}"); BatFamiliar d = new BatFamiliar(f.position, f.ownerId); d.followingOwner = f.followingOwner; d.daysOld.Value = f.daysOld; d.exp.Value = f.exp; d.mainColor = f.mainColor; d.redColor = f.redColor; d.greenColor = f.greenColor; d.blueColor = f.blueColor; d.SetScale(); d.currentLocation = l; l.characters.Add(d); } } foreach (FamiliarData f in fsd.junimoFamiliars) { GameLocation l = Game1.getLocationFromName(f.currentLocation); if (l != null) { Monitor.Log($"Returning saved Junimo Familiar to {l.Name}"); JunimoFamiliar d = new JunimoFamiliar(f.position, f.ownerId); d.followingOwner = f.followingOwner; d.daysOld.Value = f.daysOld; d.exp.Value = f.exp; d.mainColor = f.mainColor; d.redColor = f.redColor; d.greenColor = f.greenColor; d.blueColor = f.blueColor; d.SetScale(); d.currentLocation = l; l.characters.Add(d); } } foreach (FamiliarData f in fsd.butterflyFamiliars) { GameLocation l = Game1.getLocationFromName(f.currentLocation); if (l != null) { Monitor.Log($"Returning saved Butterfly Familiar to {l.Name}"); ButterflyFamiliar d = new ButterflyFamiliar(f.position, f.ownerId); d.followingOwner = f.followingOwner; d.daysOld.Value = f.daysOld; d.exp.Value = f.exp; d.mainColor = f.mainColor; d.redColor = f.redColor; d.greenColor = f.greenColor; d.blueColor = f.blueColor; d.baseFrame = f.baseFrame; d.SetScale(); d.currentLocation = l; l.characters.Add(d); } } }