public bool PerformAction(GameLocation location, Vector2 pos, JunimoHarvester junimo, Guid guid) { var chest = Util.GetHutFromId(guid).output.Value; var(x, y) = pos; var up = new Vector2(x, y + 1); var right = new Vector2(x + 1, y); var down = new Vector2(x, y - 1); var left = new Vector2(x - 1, y); var direction = 0; Vector2[] positions = { up, right, down, left }; foreach (var nextPos in positions) { if (!Util.IsWithinRadius(location, Util.GetHutFromId(guid), nextPos)) { continue; } if (DebrisIndexAtTile(nextPos) > 0) { junimo.faceDirection(direction); return(MoveDebrisFromTileToChest(nextPos, location, chest)); } direction++; } return(false); }
public override void Update(GameTime time) { base.Update(time); if (this.junimoSendOutTimer > 0) { this.junimoSendOutTimer -= time.ElapsedGameTime.Milliseconds; if (this.junimoSendOutTimer <= 0 && this.myJunimos.Count <JunimoHarvester>() < 3 && !Game1.IsWinter && !Game1.isRaining && this.areThereMatureCropsWithinRadius() && Game1.farmEvent == null) { JunimoHarvester item = new JunimoHarvester(new Vector2((float)(this.tileX + 1), (float)(this.tileY + 1)) * (float)Game1.tileSize + new Vector2(0f, (float)(Game1.tileSize / 2)), this, this.getUnusedJunimoNumber()); Game1.getFarm().characters.Add(item); this.myJunimos.Add(item); this.junimoSendOutTimer = 1000; if (Utility.isOnScreen(Utility.Vector2ToPoint(new Vector2((float)(this.tileX + 1), (float)(this.tileY + 1))), Game1.tileSize, Game1.getFarm())) { try { Game1.playSound("junimoMeep1"); } catch (Exception) { } } } } }
private bool HarvestForageCrop(Guid id, Vector2 pos, JunimoHarvester junimo) { Farm farm = Game1.getFarm(); Vector2 up = new Vector2(pos.X, pos.Y + 1); Vector2 right = new Vector2(pos.X + 1, pos.Y); Vector2 down = new Vector2(pos.X, pos.Y - 1); Vector2 left = new Vector2(pos.X - 1, pos.Y); int direction = 0; Vector2[] positions = { up, right, down, left }; foreach (Vector2 nextPos in positions) { if (farm.objects.ContainsKey(nextPos) && farm.objects[nextPos].isForage(farm)) { junimo.faceDirection(direction); SetForageQuality(farm, nextPos); SObject item = farm.objects[nextPos]; Util.AddItemToHut(id, item); Util.SpawnParticles(nextPos); farm.objects.Remove(nextPos); return(true); } direction++; } return(false); }
public bool PerformAction(Farm farm, Vector2 pos, JunimoHarvester junimo, Chest chest) { Vector2 up = new Vector2(pos.X, pos.Y + 1); Vector2 right = new Vector2(pos.X + 1, pos.Y); Vector2 down = new Vector2(pos.X, pos.Y - 1); Vector2 left = new Vector2(pos.X - 1, pos.Y); int direction = 0; Vector2[] positions = { up, right, down, left }; foreach (Vector2 nextPos in positions) { if (farm.terrainFeatures.ContainsKey(nextPos) && IsHarvestableFruitTree(farm.terrainFeatures[nextPos])) { FruitTree tree = farm.terrainFeatures[nextPos] as FruitTree; junimo.faceDirection(direction); return(HarvestFromTree(farm, pos, junimo, chest, tree)); } direction++; } return(false); }
private static void returnToGreenhouseDoor(JunimoHarvester junimo, GameLocation location) { if (Utility.isOnScreen(Utility.Vector2ToPoint(junimo.position.Value / 64f), 64, junimo.currentLocation)) { junimo.jump(); } // junimo.pathfindToNextScheduleLocation; junimo.collidesWithOtherCharacters.Value = false; if (Game1.IsMasterGame) { junimo.controller = new PathFindController(junimo, location, GreenhouseDoor(location), 1, junimo.junimoReachedHut); if (junimo.controller.pathToEndPoint == null || junimo.controller.pathToEndPoint.Count == 0) { // BetterJunimos.SMonitor.Log( // $"returnToGreenhouseDoor: #{junimo.whichJunimoFromThisHut} could not pathfind", LogLevel.Debug); junimo.junimoReachedHut(junimo, junimo.currentLocation); return; } } // var path = string.Join(", ", junimo.controller.pathToEndPoint); // BetterJunimos.SMonitor.Log( // $"returnToGreenhouseDoor: #{junimo.whichJunimoFromThisHut} pathfind {junimo.controller.pathToEndPoint.Count} path {path}", // LogLevel.Debug); if (!Utility.isOnScreen(Utility.Vector2ToPoint(junimo.position.Value / 64f), 64, junimo.currentLocation)) { return; } location.playSound("junimoMeep1"); }
public bool PerformAction(Farm farm, Vector2 pos, JunimoHarvester junimo, Chest chest) { Vector2 up = new Vector2(pos.X, pos.Y + 1); Vector2 right = new Vector2(pos.X + 1, pos.Y); Vector2 down = new Vector2(pos.X, pos.Y - 1); Vector2 left = new Vector2(pos.X - 1, pos.Y); int direction = 0; Vector2[] positions = { up, right, down, left }; foreach (Vector2 nextPos in positions) { if (farm.terrainFeatures.ContainsKey(nextPos) && IsHarvestableTree(farm.terrainFeatures[nextPos])) { junimo.faceDirection(direction); //farm.terrainFeatures[nextPos].performUseAction(pos, junimo.currentLocation); UseToolOnTile(FakeAxe, nextPos, Game1.player, Game1.currentLocation); return(true); } direction++; } return(false); }
public bool PerformAction(Farm farm, Vector2 pos, JunimoHarvester junimo, Chest chest) { Vector2 up = new Vector2(pos.X, pos.Y + 1); Vector2 right = new Vector2(pos.X + 1, pos.Y); Vector2 down = new Vector2(pos.X, pos.Y - 1); Vector2 left = new Vector2(pos.X - 1, pos.Y); int direction = 0; Vector2[] positions = { up, right, down, left }; foreach (Vector2 nextPos in positions) { if (farm.objects.ContainsKey(nextPos) && farm.objects[nextPos].isForage(farm)) { junimo.faceDirection(direction); SetForageQuality(farm, nextPos); StardewValley.Object item = farm.objects[nextPos]; Util.AddItemToChest(farm, chest, item); Util.SpawnParticles(nextPos); farm.objects.Remove(nextPos); return(true); } direction++; } return(false); }
public bool PerformAction(Farm farm, Vector2 pos, JunimoHarvester junimo, Chest chest) { List <Item> foundItems = chest.items.ToList <Item>().FindAll(item => item != null && item.Category == ItemCategory && !(Util.Config.JunimoImprovements.AvoidPlantingCoffee && item.ParentSheetIndex == Util.CoffeeId) ); if (foundItems.Count == 0) { return(false); } foreach (Item foundItem in foundItems) { Crop crop = new Crop(foundItem.ParentSheetIndex, (int)pos.X, (int)pos.Y); if (crop.seasonsToGrowIn.Contains(Game1.currentSeason)) { if (Plant(farm, pos, foundItem.ParentSheetIndex)) { Util.RemoveItemFromChest(chest, foundItem); return(true); } } } return(false); }
public static void SpawnJunimoAtPosition(Vector2 pos, JunimoHut hut, int junimoNumber) { if (hut == null) { return; } Farm farm = Game1.getFarm(); /* * Added by Mizzion. This will set the color of the junimos based on what gem is inside the hut. */ bool isPrismatic = false; Color?gemColor = getGemColor(ref isPrismatic, hut);//Reflection.GetMethod(hut, "getGemColor").Invoke<Color>(isPrismatic); /* * End added By Mizzion */ JunimoHarvester junimoHarvester = new JunimoHarvester(pos, hut, junimoNumber, gemColor); junimoHarvester.isPrismatic.Value = isPrismatic; //Added by Mizzion, Fixes the Prismatic Junimos. farm.characters.Add((NPC)junimoHarvester); hut.myJunimos.Add(junimoHarvester); if (Game1.isRaining) { var alpha = Reflection.GetField <float>(junimoHarvester, "alpha"); alpha.SetValue(Config.FunChanges.RainyJunimoSpiritFactor); } if (!Utility.isOnScreen(Utility.Vector2ToPoint(pos), 64, farm)) { return; } farm.playSound("junimoMeep1"); }
public bool PerformAction(GameLocation location, Vector2 pos, JunimoHarvester junimo, Guid guid) { var up = new Vector2(pos.X, pos.Y + 1); var right = new Vector2(pos.X + 1, pos.Y); var down = new Vector2(pos.X, pos.Y - 1); var left = new Vector2(pos.X - 1, pos.Y); var direction = 0; Vector2[] positions = { up, right, down, left }; foreach (var nextPos in positions) { if (!Util.IsWithinRadius(location, Util.GetHutFromId(guid), nextPos)) { continue; } if (location.terrainFeatures.ContainsKey(nextPos) && IsHarvestableFruitTree(location.terrainFeatures[nextPos])) { var tree = location.terrainFeatures[nextPos] as FruitTree; junimo.faceDirection(direction); return(HarvestFromTree(pos, junimo, tree)); } direction++; } return(false); }
public static void CropHarvest_postfix(int xTile, int yTile, HoeDirt soil, JunimoHarvester junimoHarvester, Crop __instance, bool __result, int __state) { //__result is true is a crop was successfully harvested unless it's regrowable if (!__result && __instance.regrowAfterHarvest.Value < 0) { return; } //we reach this point if it's a regrowable crop and check its dayOfCurrentPhase from the prefix if (__instance.regrowAfterHarvest.Value > 0 && __state > 1) { return; } try { int cropId = __instance.indexOfHarvest.Value; string cropName = new StardewValley.Object(cropId, 1, false).Name; MultiYieldCrop.MultiYieldCrops.instance.SpawnHarvest(new Vector2(xTile, yTile), cropName, soil.fertilizer.Value, junimoHarvester); } catch (Exception ex) { Monitor.Log($"Failed in {nameof(CropHarvest_postfix)}:\n{ex}", LogLevel.Error); } }
public override void Update(GameTime time) { base.Update(time); if (this.junimoSendOutTimer <= 0) { return; } this.junimoSendOutTimer = this.junimoSendOutTimer - time.ElapsedGameTime.Milliseconds; if (this.junimoSendOutTimer > 0 || this.myJunimos.Count <JunimoHarvester>() >= 3 || (Game1.IsWinter || Game1.isRaining) || (!this.areThereMatureCropsWithinRadius() || Game1.farmEvent != null)) { return; } JunimoHarvester junimoHarvester = new JunimoHarvester(new Vector2((float)(this.tileX + 1), (float)(this.tileY + 1)) * (float)Game1.tileSize + new Vector2(0.0f, (float)(Game1.tileSize / 2)), this, this.getUnusedJunimoNumber()); Game1.getFarm().characters.Add((NPC)junimoHarvester); this.myJunimos.Add(junimoHarvester); this.junimoSendOutTimer = 1000; if (!Utility.isOnScreen(Utility.Vector2ToPoint(new Vector2((float)(this.tileX + 1), (float)(this.tileY + 1))), Game1.tileSize, (GameLocation)Game1.getFarm())) { return; } try { Game1.playSound("junimoMeep1"); } catch (Exception ex) { } }
public override void Update(GameTime time) { base.Update(time); output.Value.mutex.Update(Game1.getFarm()); if (output.Value.mutex.IsLockHeld() && Game1.activeClickableMenu == null) { output.Value.mutex.ReleaseLock(); } if (!Game1.IsMasterGame || junimoSendOutTimer <= 0) { return; } junimoSendOutTimer -= time.ElapsedGameTime.Milliseconds; if (junimoSendOutTimer <= 0 && myJunimos.Count() < 3 && !Game1.IsWinter && !Game1.isRaining && areThereMatureCropsWithinRadius() && Game1.farmEvent == null) { int junimoNumber = getUnusedJunimoNumber(); bool isPrismatic = false; Color? gemColor = getGemColor(ref isPrismatic); JunimoHarvester i = new JunimoHarvester(new Vector2((int)tileX + 1, (int)tileY + 1) * 64f + new Vector2(0f, 32f), this, junimoNumber, gemColor); i.isPrismatic.Value = isPrismatic; Game1.getFarm().characters.Add(i); myJunimos.Add(i); junimoSendOutTimer = 1000; if (Utility.isOnScreen(Utility.Vector2ToPoint(new Vector2((int)tileX + 1, (int)tileY + 1)), 64, Game1.getFarm())) { try { Game1.getFarm().playSound("junimoMeep1"); } catch (Exception) { } } } }
public bool PerformAction(Farm farm, Vector2 pos, JunimoHarvester junimo, Chest chest) { Item foundItem; foundItem = chest.items.FirstOrDefault(item => item != null && FruitTreeSeeds.Keys.Contains(item.ParentSheetIndex)); if (foundItem == null) { return(false); } Vector2 up = new Vector2(pos.X, pos.Y + 1); Vector2 right = new Vector2(pos.X + 1, pos.Y); Vector2 down = new Vector2(pos.X, pos.Y - 1); Vector2 left = new Vector2(pos.X - 1, pos.Y); Vector2[] positions = { up, right, down, left }; foreach (Vector2 nextPos in positions) { if (BorderClear(farm, nextPos)) { bool success = Plant(farm, nextPos, foundItem.ParentSheetIndex); if (success) { //Monitor.Log($"PerformAction planted {foundItem.Name} at {nextPos.X} {nextPos.Y}", LogLevel.Info); Util.RemoveItemFromChest(chest, foundItem); return(true); } else { Monitor.Log($"PerformAction could not plant {foundItem.Name} at {nextPos.X} {nextPos.Y}", LogLevel.Warn); } } } return(false); }
public static bool Prefix(JunimoHarvester __instance, ref PathNode currentNode, ref NetGuid ___netHome, ref bool __result) { __result = Util.Abilities.IsActionable(__instance.currentLocation, new Vector2(currentNode.x, currentNode.y), ___netHome.Value); return(false); }
public bool PerformAction(Farm farm, Vector2 pos, JunimoHarvester junimo, Chest chest) { if (farm.terrainFeatures.ContainsKey(pos) && farm.terrainFeatures[pos] is Grass g) { return(TryHarvestGrass(g, farm, pos)); } return(false); }
private static void Crop_harvest_Prefix(Crop __instance, JunimoHarvester junimoHarvester) { if (!harvestingField || Config.AutoCollect) { return; } __instance.harvestMethod.Value = 1; }
public static void Postfix(JunimoHarvester __instance, ref NetGuid ___netHome) { var hut = Util.GetHutFromId(___netHome.Value); var radius = Util.CurrentWorkingRadius; var retry = 0; do { var endPoint = __instance.currentLocation.IsGreenhouse ? EndPointInGreenhouse(__instance) : EndPointInFarm(hut, radius); // BetterJunimos.SMonitor.Log($"PatchPathfindToRandomSpotAroundHut: " + // $"#{__instance.whichJunimoFromThisHut} " + // $"in {__instance.currentLocation.Name} " + // $"from [{__instance.getTileX()} {__instance.getTileX()}] " + // $"to [{endPoint.X} {endPoint.Y}]", // LogLevel.Debug); // BetterJunimos.SMonitor.Log( // $"PatchPathfindToRandomSpotAroundHut: #{__instance.whichJunimoFromThisHut} current location is {__instance.currentLocation.Name}", // LogLevel.Trace); // BetterJunimos.SMonitor.Log( // $"PatchPathfindToRandomSpotAroundHut: #{__instance.whichJunimoFromThisHut} want to path to [{endPoint.X} {endPoint.Y}]", // LogLevel.Trace); __instance.controller = new PathFindController( __instance, __instance.currentLocation, endPoint, -1, __instance.reachFirstDestinationFromHut, 100); retry++; } while (retry <= 5 && __instance.controller?.pathToEndPoint == null); if (__instance.controller == null) { // BetterJunimos.SMonitor.Log( // $"PatchPathfindToRandomSpotAroundHut: #{__instance.whichJunimoFromThisHut} controller is null, will be despawned", // LogLevel.Trace); } else if (__instance.controller?.pathToEndPoint == null) { // BetterJunimos.SMonitor.Log( // $"PatchPathfindToRandomSpotAroundHut: #{__instance.whichJunimoFromThisHut} controller.pathToEndPoint is null, will be despawned", // LogLevel.Trace); } else { // BetterJunimos.SMonitor.Log( // $"PatchPathfindToRandomSpotAroundHut: #{__instance.whichJunimoFromThisHut} has a path", // LogLevel.Trace); } }
public static void Postfix(JunimoHarvester __instance, ref int ___harvestTimer) { string dialog = Dialog.GetDialog(___harvestTimer); if (dialog != null) { __instance.showTextAboveHead(dialog); } }
public static void Postfix(JunimoHarvester __instance) { JunimoHut hut = Util.GetHutFromId(Util.GetHutIdFromJunimo(__instance)); int radius = Util.MaxRadius; __instance.controller = new PathFindController(__instance, __instance.currentLocation, Utility.Vector2ToPoint( new Vector2((float)(hut.tileX.Value + 1 + Game1.random.Next(-radius, radius + 1)), (float)(hut.tileY.Value + 1 + Game1.random.Next(-radius, radius + 1)))), -1, new PathFindController.endBehavior(__instance.reachFirstDestinationFromHut), 100); }
public bool PerformAction(Farm farm, Vector2 pos, JunimoHarvester junimo, Chest chest) { if (farm.terrainFeatures.ContainsKey(pos) && farm.terrainFeatures[pos] is HoeDirt hd) { bool animate = Utility.isOnScreen(Utility.Vector2ToPoint(pos), 64, farm); hd.destroyCrop(pos, animate, farm); return(true); } return(false); }
private static Point EndPointInGreenhouse(JunimoHarvester jh) { var gw = jh.currentLocation.map.Layers[0].LayerWidth; var gh = jh.currentLocation.map.Layers[0].LayerHeight; return(new Vector2( 1 + Game1.random.Next(gw - 2), 1 + Game1.random.Next(gh - 2) ).ToPoint()); }
public bool PerformAction(GameLocation location, Vector2 pos, JunimoHarvester junimo, Guid guid) { if (!location.terrainFeatures.ContainsKey(pos) || location.terrainFeatures[pos] is not HoeDirt hd) { return(false); } var animate = Utility.isOnScreen(Utility.Vector2ToPoint(pos), 64, location); hd.destroyCrop(pos, animate, location); return(true); }
public bool PerformAction(GameLocation farm, Vector2 pos, JunimoHarvester junimo, Guid id) { if (!ModEntry.Config.HarvestGrassEnabled) { return(false); } if (farm.terrainFeatures.ContainsKey(pos) && farm.terrainFeatures[pos] is Grass g) { return(TryHarvestGrass(g, farm, pos)); } return(false); }
public static void Postfix(JunimoHarvester __instance, ref int ___harvestTimer) { if (Util.Progression.WorkFaster && ___harvestTimer == 999) { // skip last second of harvesting if faster ___harvestTimer = 0; } else if (___harvestTimer > 500 && ___harvestTimer < 1000 || (Util.Progression.WorkFaster && ___harvestTimer > 5)) { __instance.shake(50); } }
public bool PerformAction(Farm farm, Vector2 pos, JunimoHarvester junimo, Chest chest) { Item foundItem = chest.items.FirstOrDefault(item => item != null && item.Category == ItemCategory); if (foundItem == null) { return(false); } Fertilize(farm, pos, foundItem.ParentSheetIndex); Util.RemoveItemFromChest(chest, foundItem); return(true); }
public static void Postfix(JunimoHarvester __instance, ref NetGuid ___netHome) { JunimoHut hut = Util.GetHutFromId(___netHome.Value); int radius = Util.MaxRadius; int retry = 0; do { __instance.controller = new PathFindController(__instance, __instance.currentLocation, Utility.Vector2ToPoint( new Vector2((float)(hut.tileX.Value + 1 + Game1.random.Next(-radius, radius + 1)), (float)(hut.tileY.Value + 1 + Game1.random.Next(-radius, radius + 1)))), -1, new PathFindController.endBehavior(__instance.reachFirstDestinationFromHut), 100); retry++; } while (retry <= 5 && (__instance.controller == null || __instance.controller.pathToEndPoint == null)); }
public bool PerformAction(Farm farm, Vector2 pos, JunimoHarvester junimo, Chest chest) { if (farm.terrainFeatures.ContainsKey(pos) && farm.terrainFeatures[pos] is HoeDirt hd) { hd.state.Value = HoeDirt.watered; Multiplayer multiplayer = Util.Reflection.GetField <Multiplayer>(typeof(Game1), "multiplayer").GetValue(); multiplayer.broadcastSprites(Game1.currentLocation, new TemporaryAnimatedSprite(13, new Vector2(pos.X * 64f, pos.Y * 64f), Color.White, 10, Game1.random.NextDouble() < 0.5, 70f, 0, 64, (float)((pos.Y * 64.0 + 32.0) / 10000.0 - 0.00999999977648258), -1, 0)); return(true); } return(false); }
public static void Postfix(JunimoHarvester __instance) { var harvestTimer = Util.Reflection.GetField <int>(__instance, "harvestTimer"); int time = harvestTimer.GetValue(); if (Util.Config.JunimoImprovements.WorkFaster && time == 999) { // skip last second of harvesting if faster harvestTimer.SetValue(0); //__instance.pokeToHarvest(); } else if (time > 500 && time < 1000 || (Util.Config.JunimoImprovements.WorkFaster && time > 5)) { __instance.shake(50); } }
public bool PerformAction(IJunimoAbility ability, Guid id, Vector2 pos, JunimoHarvester junimo) { JunimoHut hut = Util.GetHutFromId(id); Chest chest = hut.output.Value; Farm farm = Game1.getFarm(); bool success = ability.PerformAction(farm, pos, junimo, chest); int requiredItem = ability.RequiredItem(); if (requiredItem != 0) { UpdateHutContainsItemCategory(id, chest, requiredItem); } return(success); }