private void OnOneSecondElapsed(object sender, EventArgs args) { if (!Context.IsWorldReady || config.TicksInterval == 0) { return; } Player player = Game1.player; ticksElapsed = (byte)((ticksElapsed + 1) % config.TicksInterval); if (ticksElapsed == 0) { Rectangle bb = ExpandBoundingBox(Game1.player.GetBoundingBox(), Game1.tileSize * 5, Game1.tileSize * 5); GameLocation location = Game1.currentLocation; //AutoHarvest Grown Crops if (config.AutoHarvestCrops) { foreach (Vector2 position in location.terrainFeatures.Keys) { TerrainFeature feature = location.terrainFeatures[position]; if (feature is HoeDirt dirt) { Crop crop = dirt.crop; if (crop == null) { continue; } if (config.AutoDestroyDeadCrops && crop.dead) { dirt.destroyCrop(position); continue; } if (!crop.fullyGrown || !bb.Intersects(feature.getBoundingBox(position))) { continue; } crop.harvest((int)position.X, (int)position.Y, dirt); } } } //Collecting Forages if (config.AutoCollectForages) { ICollection <Vector2> keys = new List <Vector2>(location.Objects.Keys); foreach (Vector2 vec in keys) { SVObject obj = location.Objects[vec]; if (!bb.Intersects(obj.boundingBox)) { continue; } if (obj.isForage(location)) { Random random = new Random((int)Game1.uniqueIDForThisGame / 2 + (int)Game1.stats.DaysPlayed + (int)vec.X + (int)vec.Y * 777); if (player.professions.Contains(16)) { obj.quality = 4; } else { if (random.NextDouble() < player.ForagingLevel / 30f) { obj.quality = 2; } else if (random.NextDouble() < player.ForagingLevel / 15f) { obj.quality = 1; } } if (player.couldInventoryAcceptThisItem(obj)) { if (player.IsMainPlayer) { Game1.playSound("pickUpItem"); DelayedAction.playSoundAfterDelay("coin", 300); } player.animateOnce(279 + player.FacingDirection); if (!location.isFarmBuildingInterior()) { player.gainExperience(2, 7); } else { player.gainExperience(0, 5); } player.addItemToInventoryBool(obj.getOne(), false); Stats expr_70E = Game1.stats; uint itemsForaged = expr_70E.ItemsForaged; expr_70E.ItemsForaged = itemsForaged + 1u; if (player.professions.Contains(13) && random.NextDouble() < 0.2 && !obj.questItem && player.couldInventoryAcceptThisItem(obj) && !location.isFarmBuildingInterior()) { player.addItemToInventoryBool(obj.getOne(), false); player.gainExperience(2, 7); } location.Objects.Remove(vec); return; } } } } } }
private void OnKeyPressed(object sender, EventArgsKeyPressed e) { Player player = Game1.player; if (e.KeyPressed == Keys.C) { if (!config.UseToolsNearby || player.CurrentTool == null) { return; } Rectangle bb = ExpandBoundingBox(player.GetBoundingBox(), 1000, 1000); GameLocation location = player.currentLocation; Dictionary <Vector2, TerrainFeature> features = location.terrainFeatures; if (player.CurrentTool is Axe) { foreach (Vector2 loc in features.Keys) { TerrainFeature feature = features[loc]; if (feature.getBoundingBox(loc).Intersects(bb) && feature is Tree tree) { tree.health = 0; tree.performToolAction(player.CurrentTool, 0, loc, location); } } Dictionary <Vector2, SVObject> objects = new Dictionary <Vector2, SVObject>(location.Objects); foreach (Vector2 loc in objects.Keys) { SVObject obj = objects[loc]; if (obj != null && loc != null && obj.getBoundingBox(loc) != null && obj.getBoundingBox(loc).Intersects(bb) && (obj.Name == "Twig" || obj.name == "Weeds")) { obj.performToolAction(player.CurrentTool); location.removeObject(loc, false); Monitor.Log(string.Format("removed tile: {0}", obj.name)); } } if (location is Farm farm) { BreakStumps(player, bb, farm.resourceClumps); } else if (location is Woods woods) { BreakStumps(player, bb, woods.stumps); } else if (location is Forest forest) { if (BreakStump(player, bb, forest.log)) { forest.log = null; } } } else if (player.CurrentTool is Pickaxe) { int playerX = player.getStandingX() / Game1.tileSize, playerY = player.getStandingY() / Game1.tileSize; Dictionary <Vector2, SVObject> objects = new Dictionary <Vector2, SVObject>(location.Objects); foreach (Vector2 loc in objects.Keys) { int num = (int)loc.X / Game1.tileSize; int num2 = (int)loc.Y / Game1.tileSize; SVObject obj = objects[loc]; if (obj != null && loc != null && obj.getBoundingBox(loc) != null && obj.getBoundingBox(loc).Intersects(bb) && (obj.name == "Stone")) { location.Objects.Remove(loc); if (!(location is MineShaft)) { Game1.createRadialDebris(Game1.currentLocation, 14, num, num2, Game1.random.Next(2, 5), false, -1, false, -1); location.breakStone(obj.parentSheetIndex, num, num2, player, new Random()); } else if (location is MineShaft shaft) { if (GetPrivateValue <int>(shaft, "stonesLeftOnThisLevel") == 0) { return; } shaft.checkStoneForItems(obj.parentSheetIndex, num, num2, player); int stonesLeft = GetPrivateValue <int>(shaft, "stonesLeftOnThisLevel"); Monitor.Log("Stones left is " + stonesLeft); if (GetPrivateValue <int>(shaft, "stonesLeftOnThisLevel") == 0) { Monitor.Log("Creating ladder!"); shaft.createLadderDown(playerX, playerY); } } } } if (location is Farm farm) { BreakStumps(player, bb, farm.resourceClumps); } else if (location is Woods woods) { BreakStumps(player, bb, woods.stumps); } else if (location is MineShaft shaft) { BreakStumps(player, bb, shaft.resourceClumps); } } } else if (e.KeyPressed == Keys.PageDown) { GameLocation location = player.currentLocation; if (location != null && location is MineShaft mineshaft) { if (mineshaft.mineLevel == 120) { return; } Game1.enterMine(false, Game1.mine.mineLevel + 1, null); Game1.playSound("stairsdown"); } } }