public override ITrackedStack GetOutput() { FarmAnimal animal = this.UnprocessedAnimals.FirstOrDefault(); if (animal == null) { return(null); } this.UnprocessedAnimals.RemoveAt(0); Tool tool = new Shears(); if (animal.toolUsedForHarvest == "Milk Pail") { tool = new MilkPail(); } var produce = new SObject(animal.currentProduce, 1, false, -1, animal.produceQuality); FieldInfo info = typeof(FarmAnimal).GetField("currentProduce", BindingFlags.Instance | BindingFlags.Public); NetInt netint = new NetInt(-1); info.SetValue(animal, netint); this.produceCount += 1; return(new TrackedItem(produce)); }
public bool Shear(Mobile from, Shears shears) { if (Wool > 0) { Carve(from, shears); return(true); } return(false); }
public static void ShearingAndMilking(Farmer player) { int radius = InstanceHolder.Config.AnimalHarvestRadius * Game1.tileSize; Rectangle bb = Util.Expand(player.GetBoundingBox(), radius); foreach (FarmAnimal animal in Util.GetAnimalsList(player)) { string lowerType = animal.type.Value.ToLower(); if (animal.currentProduce.Value < 0 || animal.age.Value < animal.ageWhenMature.Value || player.CurrentTool == null || !animal.GetBoundingBox().Intersects(bb)) { continue; } if ((!lowerType.Contains("sheep") || !(player.CurrentTool is Shears) || !(player.Stamina >= 4f)) && (!lowerType.Contains("cow") || !(player.CurrentTool is MilkPail) || !(player.Stamina >= 4f)) && (!lowerType.Contains("goat") || !(player.CurrentTool is MilkPail) || !(player.Stamina >= 4f))) { continue; } if (!player.addItemToInventoryBool( new Object(Vector2.Zero, animal.currentProduce.Value, null, false, true, false, false) { Quality = animal.produceQuality.Value })) { continue; } switch (player.CurrentTool) { case Shears _: Shears.playSnip(player); break; case MilkPail _: player.currentLocation.localSound("Milking"); DelayedAction.playSoundAfterDelay("fishingRodBend", 300); DelayedAction.playSoundAfterDelay("fishingRodBend", 1200); break; default: continue; } animal.doEmote(20); Game1.playSound("coin"); animal.currentProduce.Value = -1; if (animal.showDifferentTextureWhenReadyForHarvest.Value) { animal.Sprite.LoadTexture("Animals\\Sheared" + animal.type.Value); } player.gainExperience(0, 5); } }
/********* ** Private methods *********/ /// <summary>The method to call before <see cref="Shears.beginUsing"/>.</summary> private static bool Before_BeginUsing(Shears __instance, GameLocation location, int x, int y, Farmer who, ref bool __result) { x = (int)who.GetToolLocation().X; y = (int)who.GetToolLocation().Y; Rectangle toolRect = new Rectangle(x - 32, y - 32, 64, 64); if (location is IAnimalLocation animalLoc) { Mod.Instance.Helper.Reflection.GetField <FarmAnimal>(__instance, "animal").SetValue(Utility.GetBestHarvestableFarmAnimal(animalLoc.Animals.Values, __instance, toolRect)); } who.Halt(); int currentFrame = who.FarmerSprite.CurrentFrame; who.FarmerSprite.animateOnce(283 + who.FacingDirection, 50f, 4); who.FarmerSprite.oldFrame = currentFrame; who.UsingTool = true; who.CanMove = false; __result = true; return(false); }
public static void LoadContentPacks(object sender, EventArgs e) { foreach (IContentPack contentPack in MailFrameworkModEntry.ModHelper.ContentPacks.GetOwned()) { if (File.Exists(Path.Combine(contentPack.DirectoryPath, "mail.json"))) { bool hasTranslation = contentPack.Translation.GetTranslations().Any(); MailFrameworkModEntry.ModMonitor.Log($"Reading content pack: {contentPack.Manifest.Name} {contentPack.Manifest.Version} from {contentPack.DirectoryPath}"); List <MailItem> mailItems = contentPack.ReadJsonFile <List <MailItem> >("mail.json"); foreach (MailItem mailItem in mailItems) { Dictionary <int, string> objects = null; Dictionary <int, string> bigObjects = null; Dictionary <int, string> furnitures = null; Dictionary <int, string> weapons = null; Dictionary <int, string> boots = null; //Populate all Indexes based on the given name. Ignore the letter otherwise. if (mailItem.CollectionConditions != null && mailItem.CollectionConditions.Any(c => { if (c.Name != null && c.Collection != Collection.Crafting) { objects ??= MailFrameworkModEntry.ModHelper.Content.Load <Dictionary <int, string> >(PathUtilities.NormalizeAssetName("Data/ObjectInformation"), ContentSource.GameContent); KeyValuePair <int, string> pair = objects.FirstOrDefault(o => o.Value.StartsWith(c.Name + "/")); if (pair.Value != null) { c.Index = pair.Key; } else { MailFrameworkModEntry.ModMonitor.Log($"No object found with the name '{c.Name}' for a condition for letter '{mailItem.Id}'.\n This letter will be ignored.", LogLevel.Warn); MailDao.RemoveLetter(new Letter(mailItem.Id, null, null)); return(true); } } return(false); })) { continue; } bool Condition(Letter l) => (!Game1.player.mailReceived.Contains(l.Id) || mailItem.Repeatable) && (mailItem.Recipe == null || !Game1.player.cookingRecipes.ContainsKey(mailItem.Recipe)) && (mailItem.Date == null || SDate.Now() >= new SDate(Convert.ToInt32(mailItem.Date.Split(' ')[0]), mailItem.Date.Split(' ')[1], Convert.ToInt32(mailItem.Date.Split(' ')[2].Replace("Y", "")))) && (mailItem.Days == null || mailItem.Days.Contains(SDate.Now().Day)) && (mailItem.Seasons == null || mailItem.Seasons.Contains(SDate.Now().Season)) && (mailItem.Weather == null || (Game1.isRaining && "rainy".Equals(mailItem.Weather)) || (!Game1.isRaining && "sunny".Equals(mailItem.Weather))) && (mailItem.FriendshipConditions == null || (mailItem.FriendshipConditions.TrueForAll(f => Game1.player.getFriendshipHeartLevelForNPC(f.NpcName) >= f.FriendshipLevel)) && mailItem.FriendshipConditions.TrueForAll(f => f.FriendshipStatus == null || (Game1.player.friendshipData.ContainsKey(f.NpcName) && f.FriendshipStatus.Any(s => s == Game1.player.friendshipData[f.NpcName].Status)))) && (mailItem.SkillConditions == null || mailItem.SkillConditions.TrueForAll(s => Game1.player.getEffectiveSkillLevel((int)s.SkillName) >= s.SkillLevel)) && (mailItem.StatsConditions == null || (mailItem.StatsConditions.TrueForAll(s => s.StatsLabel == null || Game1.player.stats.getStat(s.StatsLabel) >= s.Amount) && mailItem.StatsConditions.TrueForAll(s => s.StatsName == null || MailFrameworkModEntry.ModHelper.Reflection.GetProperty <uint>(Game1.player.stats, s.StatsName.ToString()).GetValue() >= s.Amount))) && (mailItem.CollectionConditions == null || (mailItem.CollectionConditions.TrueForAll(c => (c.Collection == Collection.Shipped && Game1.player.basicShipped.ContainsKey(c.Index) && Game1.player.basicShipped[c.Index] >= c.Amount) || (c.Collection == Collection.Fish && Game1.player.fishCaught.ContainsKey(c.Index) && Game1.player.fishCaught[c.Index][0] >= c.Amount) || (c.Collection == Collection.Artifacts && Game1.player.archaeologyFound.ContainsKey(c.Index) && Game1.player.archaeologyFound[c.Index][0] >= c.Amount) || (c.Collection == Collection.Minerals && Game1.player.mineralsFound.ContainsKey(c.Index) && Game1.player.mineralsFound[c.Index] >= c.Amount) || (c.Collection == Collection.Cooking && Game1.player.recipesCooked.ContainsKey(c.Index) && Game1.player.recipesCooked[c.Index] >= c.Amount) || (c.Collection == Collection.Crafting && Game1.player.craftingRecipes.ContainsKey(c.Name) && Game1.player.craftingRecipes[c.Name] >= c.Amount) ))) && (mailItem.RandomChance == null || new Random((int)(((ulong)Game1.stats.DaysPlayed * 1000000000000000) + (((ulong)l.Id.GetHashCode()) % 1000000000 * 1000000) + Game1.uniqueIDForThisGame % 1000000)).NextDouble() < mailItem.RandomChance) && (mailItem.Buildings == null || (mailItem.RequireAllBuildings ? mailItem.Buildings.TrueForAll(b => Game1.getFarm().isBuildingConstructed(b)) : mailItem.Buildings.Any(b => Game1.getFarm().isBuildingConstructed(b)))) && (mailItem.MailReceived == null || (mailItem.RequireAllMailReceived ? !mailItem.MailReceived.Except(Game1.player.mailReceived).Any() : mailItem.MailReceived.Intersect(Game1.player.mailReceived).Any())) && (mailItem.MailNotReceived == null || !mailItem.MailNotReceived.Intersect(Game1.player.mailReceived).Any()) && (mailItem.EventsSeen == null || (mailItem.RequireAllEventsSeen ? !mailItem.EventsSeen.Except(Game1.player.eventsSeen).Any() : mailItem.EventsSeen.Intersect(Game1.player.eventsSeen).Any())) && (mailItem.EventsNotSeen == null || !mailItem.EventsNotSeen.Intersect(Game1.player.eventsSeen).Any()) && (mailItem.RecipeKnown == null || (mailItem.RequireAllRecipeKnown ? mailItem.RecipeKnown.All(r => Game1.player.knowsRecipe(r)) : mailItem.RecipeKnown.Any(r => Game1.player.knowsRecipe(r)))) && (mailItem.RecipeNotKnown == null || mailItem.RecipeNotKnown.All(r => !Game1.player.knowsRecipe(r))) && (mailItem.ExpandedPrecondition == null || (ConditionsCheckerApi != null && ConditionsCheckerApi.CheckConditions(mailItem.ExpandedPrecondition))) && (mailItem.ExpandedPreconditions == null || (ConditionsCheckerApi != null && ConditionsCheckerApi.CheckConditions(mailItem.ExpandedPreconditions))) && (mailItem.HouseUpgradeLevel == null || mailItem.HouseUpgradeLevel <= Game1.player.HouseUpgradeLevel) ; if (mailItem.Attachments != null && mailItem.Attachments.Count > 0) { List <Item> attachments = new List <Item>(); mailItem.Attachments.ForEach(i => { if (i == null) { return; } switch (i.Type) { case ItemType.Object: if (i.Name != null) { objects ??= MailFrameworkModEntry.ModHelper.Content.Load <Dictionary <int, string> >(PathUtilities.NormalizeAssetName("Data/ObjectInformation"), ContentSource.GameContent); KeyValuePair <int, string> pair = objects.FirstOrDefault(o => o.Value.StartsWith(i.Name + "/")); if (pair.Value != null) { i.Index = pair.Key; } else { MailFrameworkModEntry.ModMonitor.Log($"No object found with the name {i.Name} for letter {mailItem.Id}.", LogLevel.Warn); } } if (i.Index.HasValue) { attachments.Add(new StardewValley.Object(Vector2.Zero, i.Index.Value, i.Stack ?? 1)); } else { MailFrameworkModEntry.ModMonitor.Log($"An index value is required to attach an object for letter {mailItem.Id}.", LogLevel.Warn); } break; case ItemType.BigObject: case ItemType.BigCraftable: if (i.Name != null) { bigObjects ??= MailFrameworkModEntry.ModHelper.Content.Load <Dictionary <int, string> >(PathUtilities.NormalizeAssetName("Data/BigCraftablesInformation"), ContentSource.GameContent); KeyValuePair <int, string> pair = bigObjects.FirstOrDefault(o => o.Value.StartsWith(i.Name + "/")); if (pair.Value != null) { i.Index = pair.Key; } else { MailFrameworkModEntry.ModMonitor.Log($"No big craftable found with the name {i.Name} for letter {mailItem.Id}.", LogLevel.Warn); } } if (i.Index.HasValue) { Item item = new StardewValley.Object(Vector2.Zero, i.Index.Value); if (i.Stack.HasValue) { item.Stack = i.Stack.Value; } attachments.Add(item); } else { MailFrameworkModEntry.ModMonitor.Log($"An index value is required to attach a big craftable for letter {mailItem.Id}.", LogLevel.Warn); } break; case ItemType.Tool: Tool tool = null; switch (i.Name) { case "Axe": tool = new Axe(); break; case "Hoe": tool = new Hoe(); break; case "Watering Can": tool = new WateringCan(); break; case "Scythe": tool = new MeleeWeapon(47); break; case "Golden Scythe": tool = new MeleeWeapon(53); break; case "Pickaxe": tool = new Pickaxe(); break; case "Milk Pail": tool = new MilkPail(); break; case "Shears": tool = new Shears(); break; case "Fishing Rod": tool = new FishingRod(i.UpgradeLevel); break; case "Pan": tool = new Pan(); break; case "Return Scepter": tool = new Wand(); break; default: MailFrameworkModEntry.ModMonitor.Log($"Tool with name {i.Name} not found for letter {mailItem.Id}.", LogLevel.Warn); break; } if (tool != null) { if (!NoUpgradeLevelTools.Contains(i.Name)) { tool.UpgradeLevel = i.UpgradeLevel; } attachments.Add(tool); } break; case ItemType.Ring: objects ??= MailFrameworkModEntry.ModHelper.Content.Load <Dictionary <int, string> >("Data\\ObjectInformation", ContentSource.GameContent); if (i.Name != null) { KeyValuePair <int, string> pair = objects.FirstOrDefault(o => o.Value.StartsWith(i.Name + "/")); if (pair.Value != null) { i.Index = pair.Key; } else { MailFrameworkModEntry.ModMonitor.Log($"No ring found with the name {i.Name} for letter {mailItem.Id}.", LogLevel.Warn); } } if (i.Index.HasValue) { if (objects[i.Index.Value].Split('/')[3] == "Ring") { attachments.Add(new Ring(i.Index.Value)); } else { MailFrameworkModEntry.ModMonitor.Log($"A valid ring is required to attach an ring for letter {mailItem.Id}.", LogLevel.Warn); } } else { MailFrameworkModEntry.ModMonitor.Log($"An index value is required to attach an ring for letter {mailItem.Id}.", LogLevel.Warn); } break; case ItemType.Furniture: if (i.Name != null) { furnitures ??= MailFrameworkModEntry.ModHelper.Content.Load <Dictionary <int, string> >(PathUtilities.NormalizeAssetName("Data/Furniture"), ContentSource.GameContent); KeyValuePair <int, string> pair = furnitures.FirstOrDefault(o => o.Value.StartsWith(i.Name + "/")); if (pair.Value != null) { i.Index = pair.Key; } else { MailFrameworkModEntry.ModMonitor.Log($"No furniture found with the name {i.Name} for letter {mailItem.Id}.", LogLevel.Warn); } } if (i.Index.HasValue) { attachments.Add(Furniture.GetFurnitureInstance(i.Index.Value)); } else { MailFrameworkModEntry.ModMonitor.Log($"An index value is required to attach a furniture for letter {mailItem.Id}.", LogLevel.Warn); } break; case ItemType.Weapon: if (i.Name != null) { weapons ??= MailFrameworkModEntry.ModHelper.Content.Load <Dictionary <int, string> >(PathUtilities.NormalizeAssetName("Data/Weapons"), ContentSource.GameContent); KeyValuePair <int, string> pair = weapons.FirstOrDefault(o => o.Value.StartsWith(i.Name + "/")); if (pair.Value != null) { i.Index = pair.Key; } else { MailFrameworkModEntry.ModMonitor.Log($"No weapon found with the name {i.Name} for letter {mailItem.Id}.", LogLevel.Warn); } } if (i.Index.HasValue) { int index = i.Index.Value; attachments.Add(SlingshotIndexes.Contains(index) ? (Item) new Slingshot(index) : (Item) new MeleeWeapon(index)); } else { MailFrameworkModEntry.ModMonitor.Log($"An index value is required to attach a weapon for letter {mailItem.Id}.", LogLevel.Warn); } break; case ItemType.Boots: if (i.Name != null) { boots ??= MailFrameworkModEntry.ModHelper.Content.Load <Dictionary <int, string> >(PathUtilities.NormalizeAssetName("Data/Boots"), ContentSource.GameContent); KeyValuePair <int, string> pair = boots.FirstOrDefault(o => o.Value.StartsWith(i.Name + "/")); if (pair.Value != null) { i.Index = pair.Key; } else { MailFrameworkModEntry.ModMonitor.Log($"No boots found with the name {i.Name} for letter {mailItem.Id}.", LogLevel.Warn); } } if (i.Index.HasValue) { attachments.Add(new Boots(i.Index.Value)); } else { MailFrameworkModEntry.ModMonitor.Log($"An index value is required to attach a boots for letter {mailItem.Id}.", LogLevel.Warn); } break; case ItemType.DGA: if (DgaApi != null) { try { object dgaObject = DgaApi.SpawnDGAItem(i.Name); if (dgaObject is StardewValley.Item dgaItem) { if (dgaItem is StardewValley.Object) { dgaItem.Stack = i.Stack ?? 1; } else { dgaItem.Stack = 1; } attachments.Add(dgaItem); } else { MailFrameworkModEntry.ModMonitor.Log($"No DGA item found with the ID {i.Name} for letter {mailItem.Id}.", LogLevel.Warn); } } catch (Exception ex) { MailFrameworkModEntry.ModMonitor.Log($"Error trying to create item with the DGA ID {i.Name} for letter {mailItem.Id}.", LogLevel.Warn); MailFrameworkModEntry.ModMonitor.Log(ex.Message, LogLevel.Trace); } } else { MailFrameworkModEntry.ModMonitor.Log($"No DGA API found, so item with the ID {i.Name} for letter {mailItem.Id} will be ignored.", LogLevel.Warn); } break; default: MailFrameworkModEntry.ModMonitor.Log($"Invalid attachment type '{i.Type}' found in letter {mailItem.Id}.", LogLevel.Warn); break; } }); MailDao.SaveLetter( new Letter( mailItem.Id , hasTranslation && mailItem.Text != null ? contentPack.Translation.Get(mailItem.Text) : mailItem.Text , attachments , Condition , (l) => { Game1.player.mailReceived.Add(l.Id); if (mailItem.AdditionalMailReceived != null) { Game1.player.mailReceived.AddRange(mailItem.AdditionalMailReceived); } } , mailItem.WhichBG ) { TextColor = mailItem.TextColor, Title = hasTranslation && mailItem.Title != null ? contentPack.Translation.Get(mailItem.Title) : mailItem.Title, GroupId = mailItem.GroupId, LetterTexture = mailItem.LetterBG != null ? GetTextureAsset(contentPack, mailItem.LetterBG) : null, UpperRightCloseButtonTexture = mailItem.UpperRightCloseButton != null ? GetTextureAsset(contentPack, mailItem.UpperRightCloseButton) : null, AutoOpen = mailItem.AutoOpen, }); } else { MailDao.SaveLetter( new Letter( mailItem.Id , hasTranslation && mailItem.Text != null ? contentPack.Translation.Get(mailItem.Text) : mailItem.Text , mailItem.Recipe , Condition , (l) => { Game1.player.mailReceived.Add(l.Id); if (mailItem.AdditionalMailReceived != null) { Game1.player.mailReceived.AddRange(mailItem.AdditionalMailReceived); } } , mailItem.WhichBG ) { TextColor = mailItem.TextColor, Title = hasTranslation && mailItem.Title != null ? contentPack.Translation.Get(mailItem.Title) : mailItem.Title, GroupId = mailItem.GroupId, LetterTexture = mailItem.LetterBG != null ? GetTextureAsset(contentPack, mailItem.LetterBG) : null, UpperRightCloseButtonTexture = mailItem.UpperRightCloseButton != null ? GetTextureAsset(contentPack, mailItem.UpperRightCloseButton) : null, AutoOpen = mailItem.AutoOpen, }); } } } else { MailFrameworkModEntry.ModMonitor.Log($"Ignoring content pack: {contentPack.Manifest.Name} {contentPack.Manifest.Version} from {contentPack.DirectoryPath}\nIt does not have an mail.json file.", LogLevel.Warn); } } }
/********* ** Private methods *********/ /// <summary>The method to call before <see cref="MilkPail.beginUsing"/>.</summary> private static bool Before_BeginUsing(Shears __instance, GameLocation location, int x, int y, Farmer who, ref bool __result) { x = (int)who.GetToolLocation().X; y = (int)who.GetToolLocation().Y; Rectangle toolRect = new Rectangle(x - 32, y - 32, 64, 64); var animalField = Mod.Instance.Helper.Reflection.GetField <FarmAnimal>(__instance, "animal"); var animal = animalField.GetValue(); if (location is IAnimalLocation animalLoc) { animalField.SetValue(animal = Utility.GetBestHarvestableFarmAnimal(animalLoc.Animals.Values, __instance, toolRect)); } if (animal != null && animal.currentProduce.Value > 0 && (animal.age.Value >= animal.ageWhenMature.Value && animal.toolUsedForHarvest.Value.Equals(__instance.BaseName)) && who.couldInventoryAcceptThisObject(animal.currentProduce.Value, 1)) { animal.doEmote(20); animal.friendshipTowardFarmer.Value = Math.Min(1000, animal.friendshipTowardFarmer.Value + 5); who.currentLocation.localSound("Milking"); animal.pauseTimer = 1500; } else if (animal != null && animal.currentProduce.Value > 0 && animal.age.Value >= animal.ageWhenMature.Value) { if (who != null && Game1.player.Equals(who)) { if (!animal.toolUsedForHarvest.Value.Equals(__instance.BaseName)) { if (animal.toolUsedForHarvest.Value != null && !animal.toolUsedForHarvest.Value.Equals("null")) { Game1.showRedMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:MilkPail.cs.14167", animal.toolUsedForHarvest.Value)); } } else if (!who.couldInventoryAcceptThisObject(animal.currentProduce.Value, 1)) { Game1.showRedMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:Crop.cs.588")); } } } else if (who != null && Game1.player.Equals(who)) { DelayedAction.playSoundAfterDelay("fishingRodBend", 300); DelayedAction.playSoundAfterDelay("fishingRodBend", 1200); string dialogue = ""; if (animal != null && !animal.toolUsedForHarvest.Value.Equals(__instance.BaseName)) { dialogue = Game1.content.LoadString("Strings\\StringsFromCSFiles:MilkPail.cs.14175", animal.displayName); } if (animal != null && animal.isBaby() && animal.toolUsedForHarvest.Value.Equals(__instance.BaseName)) { dialogue = Game1.content.LoadString("Strings\\StringsFromCSFiles:MilkPail.cs.14176", animal.displayName); } if (animal != null && animal.age.Value >= animal.ageWhenMature.Value && animal.toolUsedForHarvest.Value.Equals(__instance.BaseName)) { dialogue = Game1.content.LoadString("Strings\\StringsFromCSFiles:MilkPail.cs.14177", animal.displayName); } if (dialogue.Length > 0) { DelayedAction.showDialogueAfterDelay(dialogue, 1000); } } who.Halt(); int currentFrame = who.FarmerSprite.CurrentFrame; who.FarmerSprite.animateOnce(287 + who.FacingDirection, 50f, 4); who.FarmerSprite.oldFrame = currentFrame; who.UsingTool = true; who.CanMove = false; return(true); }
void SwitchTutorialState() { switch (tutorialState) { case "clean_leaves": if (GameObject.Find("TutPosStart_clean_leaves") != null) { startPos = GameObject.Find("TutPosStart_clean_leaves").transform.position; LeafBlower lb = GameObject.Find("Tools/LeafBlower").GetComponent <LeafBlower>(); if (lb.bLeaves1) { endPos = lb.psLeaves1.transform.position; } else if (lb.bLeaves2) { endPos = lb.psLeaves2.transform.position; } else if (lb.bLeaves3) { endPos = lb.psLeaves3.transform.position; } else if (lb.bLeaves4) { endPos = lb.psLeaves4.transform.position; } else if (lb.bLeaves5) { endPos = lb.psLeaves5.transform.position; } StartPointing(); StartCoroutine("MovePoinnter"); } break; case "cut_branches": if (GameObject.Find("TutPosStart_cut_branches") != null) { startPos = GameObject.Find("TutPosStart_cut_branches").transform.position; Shears sh = GameObject.Find("Tools/Shears").GetComponent <Shears>(); string[] branchNames = sh.BranchesToCut.Split(new char[] { ',' }, System.StringSplitOptions.RemoveEmptyEntries); if (branchNames.Length > 0) { int ind = Mathf.FloorToInt(Random.Range(0, branchNames.Length)); if (GameObject.Find(branchNames[ind]) != null) { endPos = GameObject.Find(branchNames[ind]).transform.position; StartPointing(); StartCoroutine("MovePoinnter"); } } } break; case "clean_dirt": if (GameObject.Find("TutPosStart_clean_dirt") != null) { startPos = GameObject.Find("TutPosStart_clean_dirt").transform.position; WaterHose wh = GameObject.Find("Tools2/WaterHose/Nozzle").GetComponent <WaterHose>(); string[] names = wh.LeftToBeCleaned.Split(new char[] { ',' }, System.StringSplitOptions.RemoveEmptyEntries); if (names.Length > 0) { int ind = Mathf.FloorToInt(Random.Range(0, names.Length)); if (GameObject.Find(names[ind]) != null) { endPos = GameObject.Find(names[ind]).transform.position; transform.position = startPos; StartPointing(); StartCoroutine("MovePoinnter"); } } } break; case "clean_stains": if (GameObject.Find("TutPosStart_clean_stains") != null) { startPos = GameObject.Find("TutPosStart_clean_stains").transform.position; WaterGun wg = GameObject.Find("Tools2/Compressor/WaterGun").GetComponent <WaterGun>(); string[] names = wg.LeftToBeCleaned.Split(new char[] { ',' }, System.StringSplitOptions.RemoveEmptyEntries); if (names.Length > 0) { int ind = Mathf.FloorToInt(Random.Range(0, names.Length)); if (GameObject.Find(names[ind]) != null) { endPos = GameObject.Find(names[ind]).transform.position + new Vector3(.5f, -.5f, 0); transform.position = startPos; StartPointing(); StartCoroutine("MovePoinnter"); } } } break; case "wheel_brush": if (GameObject.Find("TutPosStart_wheel_brush") != null) { startPos = GameObject.Find("TutPosStart_wheel_brush").transform.position; WheelBrush wb = GameObject.Find("Tools/WheelBrush").GetComponent <WheelBrush>(); string[] names = wb.LeftToBeCleaned.Split(new char[] { ',' }, System.StringSplitOptions.RemoveEmptyEntries); if (names.Length > 0) { int ind = Mathf.FloorToInt(Random.Range(0, names.Length)); if (GameObject.Find(names[ind]) != null) { endPos = GameObject.Find(names[ind]).transform.position + new Vector3(.5f, -.5f, 0); transform.position = startPos; StartPointing(); StartCoroutine("MovePoinnter"); } } } break; case "bubbles": if (GameObject.Find("TutPosStart_bubbles") != null) { startPos = GameObject.Find("TutPosStart_bubbles").transform.position; StartCoroutine("MovePoinnter_Bubbles"); } break; case "wax_car": if (GameObject.Find("TutPosStart_wax_car") != null) { startPos = GameObject.Find("TutPosStart_wax_car").transform.position; CleaningCloth cc = GameObject.Find("Tools/CleaningCloth").GetComponent <CleaningCloth>(); string[] names = cc.LeftToBeCleaned.Split(new char[] { ',' }, System.StringSplitOptions.RemoveEmptyEntries); if (names.Length > 0) { int ind = Mathf.FloorToInt(Random.Range(0, names.Length)); if (GameObject.Find(names[ind]) != null) { endPos = GameObject.Find(names[ind]).transform.position + new Vector3(.5f, -.5f, 0); transform.position = startPos; StartPointing(); StartCoroutine("MovePoinnter"); } } } break; case "polisher": if (GameObject.Find("TutPosStart_polisher") != null) { startPos = GameObject.Find("TutPosStart_polisher").transform.position; Polisher pol = GameObject.Find("Tools/Polisher").GetComponent <Polisher>(); string[] names = pol.LeftToBeCleaned.Split(new char[] { ',' }, System.StringSplitOptions.RemoveEmptyEntries); if (names.Length > 0) { int ind = Mathf.FloorToInt(Random.Range(0, names.Length)); if (GameObject.Find(names[ind]) != null) { endPos = GameObject.Find(names[ind]).transform.position + new Vector3(.5f, -.5f, 0); transform.position = startPos; StartPointing(); StartCoroutine("MovePoinnter"); } } } break; case "inflate_tires": if (GameObject.Find("TutPosStart_inflate_tires") != null) { startPos = GameObject.Find("TutPosStart_inflate_tires").transform.position; TirePump tp = GameObject.Find("Tools/TirePump").GetComponent <TirePump>(); string[] names = tp.LeftToBeCleaned.Split(new char[] { ',' }, System.StringSplitOptions.RemoveEmptyEntries); if (names.Length > 0) { int ind = Mathf.FloorToInt(Random.Range(0, names.Length)); if (GameObject.Find(names[ind] + "/Valwe") != null) { endPos = GameObject.Find(names[ind] + "/Valwe").transform.position + new Vector3(.5f, -.5f, 0); transform.position = startPos; StartPointing(); StartCoroutine("MovePoinnter"); } } } break; case "fuel": if (GameObject.Find("TutPosStart_fuel") != null) { startPos = GameObject.Find("TutPosStart_fuel").transform.position; endPos = GameObject.Find("FuelTank").transform.position + new Vector3(.5f, -.5f, 0); transform.position = startPos; StartPointing(); StartCoroutine("MovePoinnter"); } break; default: break; } }
public static bool Prefix(Shears __instance, GameLocation location, int x, int y, Farmer who, ref bool __result) { x = ( int )who.GetToolLocation(false).X; y = ( int )who.GetToolLocation(false).Y; Rectangle toolRect = new Rectangle(x - 32, y - 32, 64, 64); var __instance_animal = Mod.instance.Helper.Reflection.GetField <FarmAnimal>(__instance, "animal"); if (location is IAnimalLocation animalLoc) { __instance_animal.SetValue(Utility.GetBestHarvestableFarmAnimal(animalLoc.Animals.Values, __instance, toolRect)); } if (__instance_animal.GetValue() != null && ( int )(NetFieldBase <int, NetInt>)__instance_animal.GetValue().currentProduce > 0 && (( int )(NetFieldBase <int, NetInt>)__instance_animal.GetValue().age >= ( int )( byte )(NetFieldBase <byte, NetByte>)__instance_animal.GetValue().ageWhenMature&& __instance_animal.GetValue().toolUsedForHarvest.Equals(( object )__instance.BaseName)) && who.couldInventoryAcceptThisObject(( int )(NetFieldBase <int, NetInt>)__instance_animal.GetValue().currentProduce, 1, 0)) { __instance_animal.GetValue().doEmote(20, true); __instance_animal.GetValue().friendshipTowardFarmer.Value = Math.Min(1000, ( int )(NetFieldBase <int, NetInt>)__instance_animal.GetValue().friendshipTowardFarmer + 5); who.currentLocation.localSound("Milking"); __instance_animal.GetValue().pauseTimer = 1500; } else if (__instance_animal.GetValue() != null && ( int )(NetFieldBase <int, NetInt>)__instance_animal.GetValue().currentProduce > 0 && ( int )(NetFieldBase <int, NetInt>)__instance_animal.GetValue().age >= ( int )( byte )(NetFieldBase <byte, NetByte>)__instance_animal.GetValue().ageWhenMature) { if (who != null && Game1.player.Equals(( object )who)) { if (!__instance_animal.GetValue().toolUsedForHarvest.Equals(( object )__instance.BaseName)) { if (!((NetFieldBase <string, NetString>)__instance_animal.GetValue().toolUsedForHarvest == ( NetString )null) && !__instance_animal.GetValue().toolUsedForHarvest.Equals(( object )"null")) { Game1.showRedMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:MilkPail.cs.14167", ( object )__instance_animal.GetValue().toolUsedForHarvest)); } } else if (!who.couldInventoryAcceptThisObject(( int )(NetFieldBase <int, NetInt>)__instance_animal.GetValue().currentProduce, 1, 0)) { Game1.showRedMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:Crop.cs.588")); } } } else if (who != null && Game1.player.Equals(( object )who)) { DelayedAction.playSoundAfterDelay("fishingRodBend", 300, ( GameLocation )null, -1); DelayedAction.playSoundAfterDelay("fishingRodBend", 1200, ( GameLocation )null, -1); string dialogue = ""; if (__instance_animal.GetValue() != null && !__instance_animal.GetValue().toolUsedForHarvest.Equals(( object )__instance.BaseName)) { dialogue = Game1.content.LoadString("Strings\\StringsFromCSFiles:MilkPail.cs.14175", ( object )__instance_animal.GetValue().displayName); } if (__instance_animal.GetValue() != null && __instance_animal.GetValue().isBaby() && __instance_animal.GetValue().toolUsedForHarvest.Equals(( object )__instance.BaseName)) { dialogue = Game1.content.LoadString("Strings\\StringsFromCSFiles:MilkPail.cs.14176", ( object )__instance_animal.GetValue().displayName); } if (__instance_animal.GetValue() != null && ( int )(NetFieldBase <int, NetInt>)__instance_animal.GetValue().age >= ( int )( byte )(NetFieldBase <byte, NetByte>)__instance_animal.GetValue().ageWhenMature&& __instance_animal.GetValue().toolUsedForHarvest.Equals(( object )__instance.BaseName)) { dialogue = Game1.content.LoadString("Strings\\StringsFromCSFiles:MilkPail.cs.14177", ( object )__instance_animal.GetValue().displayName); } if (dialogue.Length > 0) { DelayedAction.showDialogueAfterDelay(dialogue, 1000); } } who.Halt(); int currentFrame = who.FarmerSprite.CurrentFrame; who.FarmerSprite.animateOnce(287 + who.FacingDirection, 50f, 4); who.FarmerSprite.oldFrame = currentFrame; who.UsingTool = true; who.CanMove = false; return(true); }
//JsonSerializer a = new JsonSerializer(); public void loadData() { config = instance.Helper.Data.ReadJsonFile <ModData>($"data/{Constants.SaveFolderName}.json") ?? new ModData(); List <List <string> > itemInfo = config.itemInfo; maxTab = config.maxTab; cost = config.cost; int y = 0; int z = 1; invs[0] = Game1.player.Items; invs.Add(new List <Item>()); for (int i = 0; i < itemInfo.Count; i++) { if (y == 36) { invs.Add(new List <Item>()); z++; y = 0; } if (itemInfo[i][0] == "null") { invs[z].Add((null)); } else if (itemInfo[i][0] == "toolz") { Tool x = (Tool)null; if (itemInfo[i][1] == "0") { x = new Axe(); x.UpgradeLevel = int.Parse(itemInfo[i][2]); } else if (itemInfo[i][1] == "1") { x = new Hoe(); } else if (itemInfo[i][1] == "2") { x = new FishingRod(int.Parse(itemInfo[i][2])); } else if (itemInfo[i][1] == "3") { x = new Pickaxe(); x.UpgradeLevel = int.Parse(itemInfo[i][2]); } else if (itemInfo[i][1] == "4") { x = new WateringCan(); x.UpgradeLevel = int.Parse(itemInfo[i][2]); } else if (itemInfo[i][1] == "5") { x = new MeleeWeapon(int.Parse(itemInfo[i][3])); //sprite index?? x.UpgradeLevel = int.Parse(itemInfo[i][2]); } else if (itemInfo[i][1] == "6") { x = new Slingshot(); x.UpgradeLevel = int.Parse(itemInfo[i][2]); } else if (itemInfo[i][1] == "7") { x = new Lantern(); //x.UpgradeLevel = int.Parse(itemInfo[i][2]); } else if (itemInfo[i][1] == "8") { x = new MagnifyingGlass(); } else if (itemInfo[i][1] == "9") { x = new MilkPail(); } else if (itemInfo[i][1] == "10") { x = new Pan(); } else if (itemInfo[i][1] == "11") { x = new Raft(); } else if (itemInfo[i][1] == "12") { x = new Seeds(itemInfo[i][2], int.Parse(itemInfo[i][3])); } else if (itemInfo[i][1] == "13") { x = new Shears(); } else if (itemInfo[i][1] == "14") { x = new Sword(itemInfo[i][2], int.Parse(itemInfo[i][3])); } else if (itemInfo[i][1] == "15") { x = new Wand(); } invs[z].Add(x); } else { StardewValley.Object x = new StardewValley.Object(int.Parse(itemInfo[i][0]), int.Parse(itemInfo[i][1])); //x.SpecialVariable = int.Parse(itemInfo[i][2]); //x.Category = int.Parse(itemInfo[i][3]); //x.Name = itemInfo[i][4]; //x.DisplayName = itemInfo[i][5]; invs[z].Add((Item)(x)); } y++; } }