Ejemplo n.º 1
0
        private void UseTool(Vector2 startPos, Vector2 endPos, GameLocation loc)
        {
            var player = Game1.player;

            Axe fakeAxe = new Axe {
                UpgradeLevel = 4
            };
            Pickaxe fakePick = new Pickaxe {
                UpgradeLevel = 4
            };
            MeleeWeapon fakeSickle = new MeleeWeapon {
                UpgradeLevel = 4
            };
            Hoe fakeHoe = new Hoe {
                UpgradeLevel = 4
            };
            WateringCan fakeCan = new WateringCan {
                UpgradeLevel = 4
            };

            Game1.player.MagneticRadius = 650;

            for (int xTile = Convert.ToInt32(startPos.X); xTile <= Convert.ToInt32(endPos.X); ++xTile)
            {
                for (int yTile = Convert.ToInt32(startPos.Y); yTile <= Convert.ToInt32(endPos.Y); ++yTile)
                {
                    Vector2 useAt = (new Vector2(xTile, yTile) * Game1.tileSize) + new Vector2(Game1.tileSize / 2f);
                    Game1.player.lastClick = useAt;

                    loc.objects.TryGetValue(new Vector2(xTile, yTile), out var obj);
                    loc.terrainFeatures.TryGetValue(new Vector2(xTile, yTile), out var ter);

                    //Check obj
                    if (obj != null)
                    {
                        bool forage = obj.IsSpawnedObject;//checkForAction(Game1.player);
                        if (forage)
                        {
                            DoForageHarvest(obj, loc, player);
                        }
                        if (obj.Name.ToLower().Contains("twig"))
                        {
                            fakeAxe.DoFunction(loc, (int)useAt.X, (int)useAt.Y, 0, player);
                        }
                        if (obj.Name.ToLower().Contains("stone"))
                        {
                            fakePick.DoFunction(loc, (int)useAt.X, (int)useAt.Y, 0, player);
                        }
                        if (obj.Name.ToLower().Contains("weed"))
                        {
                            fakeAxe.DoFunction(loc, (int)useAt.X, (int)useAt.Y, 0, player);
                        }
                    }
                    //Check ter
                    if (ter != null)
                    {
                        if (ter is Tree tree)
                        {
                            fakeAxe.DoFunction(loc, (int)useAt.X, (int)useAt.Y, 0, player);
                        }

                        if (ter is Grass)
                        {
                            Random rdn = new Random();
                            loc.terrainFeatures.Remove(new Vector2(xTile, yTile));
                            Game1.createMultipleObjectDebris(178, xTile, yTile, rdn.Next(2), loc);
                        }
                    }

                    if (ter != null && ter is HoeDirt dirt)
                    {
                        if (dirt.crop == null &&
                            player.ActiveObject != null &&
                            ((player.ActiveObject.Category == SObject.SeedsCategory || player.ActiveObject.Category == -19) &&
                             dirt.canPlantThisSeedHere(player.ActiveObject.ParentSheetIndex, (int)useAt.X, (int)useAt.Y, player.ActiveObject.Category == -19)))
                        {
                            if ((dirt.plant(player.ActiveObject.ParentSheetIndex, (int)useAt.X, (int)useAt.Y, player, player.ActiveObject.Category == -19, loc) && player.IsLocalPlayer))
                            {
                                player.reduceActiveItemByOne();
                            }
                            Game1.haltAfterCheck = false;
                        }
                        else if (dirt.crop != null)
                        {
                            if (dirt.crop.fullyGrown.Value)
                            {
                                dirt.crop.harvest((int)useAt.X, (int)useAt.Y, dirt);
                            }
                            else if (player.ActiveObject != null && player.ActiveObject.Category == -19)
                            {
                                dirt.fertilizer.Value = player.ActiveObject.ParentSheetIndex;
                                player.reduceActiveItemByOne();
                            }
                            else
                            {
                                fakeCan.DoFunction(loc, (int)useAt.X, (int)useAt.Y, 0, Game1.player);
                            }
                        }
                        else
                        {
                            fakePick.DoFunction(loc, (int)useAt.X, (int)useAt.Y, 0, Game1.player);
                        }
                    }
                    else
                    {
                        fakeHoe.DoFunction(loc, (int)useAt.X, (int)useAt.Y, 1, Game1.player);
                    }


                    //Lets try bush shit
                    Rectangle rectangle = new Rectangle((int)useAt.X + 32, (int)useAt.Y - 32, 4, 192);
                    foreach (LargeTerrainFeature largeTerrainFeature in loc.largeTerrainFeatures)
                    {
                        if (largeTerrainFeature is Bush bush && bush.getBoundingBox().Intersects(rectangle))
                        {
                            bush.performUseAction(bush.tilePosition.Value, loc);
                        }
                    }

                    //Resource Clumps
                    ResourceClump clump = GetResourceClumpCoveringTile(loc, new Vector2(useAt.X, useAt.Y));
                    if (clump != null)
                    {
                        if (clump.parentSheetIndex.Value == 600)
                        {
                            clump.health.Value = 1;
                            fakeAxe.DoFunction(loc, (int)useAt.X, (int)useAt.Y, 1, Game1.player);
                        }

                        if (clump.parentSheetIndex.Value == 602)
                        {
                            clump.health.Value = 1;
                            fakeAxe.DoFunction(loc, (int)useAt.X, (int)useAt.Y, 1, Game1.player);
                        }

                        if (clump.parentSheetIndex.Value == 672)
                        {
                            clump.health.Value = 1;
                            fakePick.DoFunction(loc, (int)useAt.X, (int)useAt.Y, 1, Game1.player);
                        }
                    }

                    Game1.player.Stamina = Game1.player.MaxStamina;//So we dont passout lol
                }
            }
        }
Ejemplo n.º 2
0
        private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
        {
            if (!(e.IsDown(_actKey) || e.IsDown(_cropKey)) || !Context.IsWorldReady)
            {
                return;
            }
            if (Game1.currentLocation == null || Game1.player == null || (Game1.player.UsingTool || !Game1.player.CanMove || (Game1.activeClickableMenu != null || Game1.CurrentEvent != null)) || Game1.gameMode != 3)
            {
                return;
            }
            GameLocation    currentLocation = Game1.currentLocation;
            ICursorPosition cur             = Helper.Input.GetCursorPosition();
            var             c = Game1.getMousePosition();

            Vector2[] grid = GetTileGrid(cur.Tile * 64f, _upgradeLevel).ToArray();



            if (_powerLevel <= -1)
            {
                _powerLevel = 1;
            }
            Game1.player.toolPower = _powerLevel;

            //May need to rewrite this crap

            //Action key pressed.
            if (e.IsDown(_actKey))
            {
                foreach (var i in grid)
                {
                    var g = i;
                    currentLocation.Objects.TryGetValue(g, out SObject @object);
                    currentLocation.terrainFeatures.TryGetValue(g, out TerrainFeature @terain);

                    //Not sure if this will work lets test
                    g = (g * Game1.tileSize) + new Vector2(Game1.tileSize / 2f);

                    /*
                     * if (currentLocation.doesTileHaveProperty((int)(i.X), (int)(i.Y), "Water", "Back") != null ||
                     * currentLocation.doesTileHaveProperty((int)(i.X), (int)(i.Y), "WaterSource", "Back") != null ||
                     * (currentLocation as BuildableGameLocation)?.getBuildingAt(g) != null &&
                     * (currentLocation as BuildableGameLocation).getBuildingAt(g).buildingType.Value.Equals("Well"))
                     * {
                     *  // ISSUE: explicit non-virtual call
                     *  if (currentLocation.orePanPoint.Value != Point.Zero)
                     *      _ghostPan.DoFunction(currentLocation, (int)i.X, (int)i.Y, 1, Game1.player);
                     *  else
                     *      UseghostWaterCan(currentLocation, (int)i.X, (int)i.Y);
                     * }
                     * else*/
                    Vector2 ca = new Vector2(i.X, i.Y) * 64f;

                    if (@object != null)
                    {
                        if (@object.Name.Equals("Twig") || @object.Name.Contains("ood Fence"))
                        {
                            _ghostAxe.DoFunction(currentLocation, (int)ca.X, (int)ca.Y, 0, Game1.player);
                        }
                        else if (@object.Name.Contains("Weed"))
                        {
                            _ghostScythe.DoDamage(currentLocation, (int)ca.X, (int)ca.Y, Game1.player.getFacingDirection(), 0, Game1.player);
                        }
                        else if (@object.Name.Contains("Stone"))
                        {
                            _ghostPickaxe.DoFunction(currentLocation, (int)ca.X, (int)ca.Y, 0, Game1.player);
                        }
                    }
                    else if (currentLocation is AnimalHouse &&
                             _ghostShearPail.TargetAnimal(currentLocation,
                                                          (int)ca.X,
                                                          (int)ca.Y,
                                                          Game1.player) !=
                             null)
                    {
                        _ghostShearPail.DoFunction(currentLocation, (int)ca.X, (int)ca.Y, 0, Game1.player);
                    }
                    else if (@terain != null)
                    {
                        //Monitor.Log($"terrainFeature wasn't null ....");
                        //Lets do som checks

                        if (@terain is Tree tree)
                        {
                            _ghostAxe.DoFunction(currentLocation, (int)ca.X, (int)ca.Y, 0, Game1.player);
                        }
                        else if (@terain is HoeDirt dirt)
                        {
                            if (currentLocation.IsFarm || currentLocation.Name.Contains("Greenhouse"))
                            {
                                if (dirt.crop != null || dirt.fertilizer.Value != 0)
                                {
                                    if (dirt.crop != null && (dirt.crop.harvestMethod.Value == 1 && dirt.readyForHarvest() || !dirt.crop.dead.Value))
                                    {
                                        _ghostScythe.DoDamage(currentLocation, (int)ca.X, (int)ca.Y, Game1.player.getFacingDirection(), 0, Game1.player);
                                    }
                                    else
                                    {
                                        UseghostWaterCan(currentLocation, (int)ca.X, (int)ca.Y);
                                    }
                                }
                                else if (_hoeDirtTool.Equals("Pickaxe", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    _ghostPickaxe.DoFunction(currentLocation, (int)ca.X, (int)ca.Y, 1, Game1.player);
                                }
                                else if (_hoeDirtTool.Equals("Hoe", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    _ghostHoe.DoFunction(currentLocation, (int)ca.X, (int)ca.Y, _powerLevel + 1, Game1.player);
                                }
                                else
                                {
                                    UseghostWaterCan(currentLocation, (int)ca.X, (int)ca.Y);
                                }
                            }
                        }
                        else if (@terain is Grass grass)
                        {
                            _ghostScythe.DoDamage(currentLocation, (int)ca.X, (int)ca.Y, Game1.player.getFacingDirection(), 0, Game1.player);
                        }
                    }
                    else if (currentLocation is SlimeHutch)
                    {
                        UseghostWaterCan(currentLocation, (int)ca.X, (int)ca.Y);
                    }
                    else
                    {
                        //Monitor.Log("All if's failed... run for the hills.");
                        //if (currentLocation.doesTileHaveProperty((int)(i.X), (int)(i.Y), "Diggable", "Back") != null)
                        // _ghostHoe.DoFunction(currentLocation, (int)i.X, (int)i.Y, 0, Game1.player);

                        /*
                         * Farmer player1 = Game1.player;
                         * player1.stamina = (float)(player1.stamina + (2.0 - Game1.player.MiningLevel * 0.100000001490116));
                         * _ghostAxe.DoFunction(currentLocation, (int)i.X, (int)i.Y, 1, Game1.player);
                         * _ghostPickaxe.DoFunction(currentLocation, (int)i.X, (int)i.Y, 1, Game1.player);
                         * if (currentLocation.doesTileHaveProperty((int)(i.X), (int)(i.Y), "Diggable", "Back") != null)
                         * {
                         *  Game1.player.toolPower = Game1.player.toolPower >= _ghostHoe.UpgradeLevel ? _ghostHoe.UpgradeLevel : Game1.player.toolPower;
                         *  Farmer player2 = Game1.player;
                         *  player2.stamina = (float)(player2.stamina + (2.0 - Game1.player.FarmingLevel * 0.100000001490116));
                         *  _ghostHoe.DoFunction(currentLocation, (int)i.X, (int)i.Y, _powerLevel + 1, Game1.player);
                         * }*/
                    }
                }
            }
            //Crop key pressed
            if (e.IsDown(_cropKey))
            {
                foreach (var i in grid)
                {
                    var g = i;
                    currentLocation.Objects.TryGetValue(g, out SObject @object);
                    currentLocation.terrainFeatures.TryGetValue(g, out TerrainFeature @terrain);

                    //Not sure if this will work lets test
                    g = (g * Game1.tileSize) + new Vector2(Game1.tileSize / 2f);

                    if (@object != null)
                    {
                        if (@object.Name.Equals("Artifact Spot"))
                        {
                            _ghostHoe.DoFunction(currentLocation, (int)i.X, (int)i.Y, 0, Game1.player);
                        }
                    }
                    else if (@terrain != null)
                    {
                        Farmer player = Game1.player;

                        /*
                         *  public const int dry = 0;
                         *  public const int watered = 1;
                         *  public const int invisible = 2;
                         *  public const int noFertilizer = 0;
                         *  public const int fertilizerLowQuality = 368;
                         *  public const int fertilizerHighQuality = 369;
                         *  public const int waterRetentionSoil = 370;
                         *  public const int waterRetentionSoilQUality = 371;
                         *  public const int speedGro = 465;
                         *  public const int superSpeedGro = 466;
                         *  Plant Category = -74
                         *  Fertilizer = -19
                         */
                        if (@terrain is HoeDirt dirt)
                        {
                            if (dirt.crop == null &&
                                player.ActiveObject != null &&
                                ((player.ActiveObject.Category == SObject.SeedsCategory || player.ActiveObject.Category == -19) &&
                                 dirt.canPlantThisSeedHere(player.ActiveObject.ParentSheetIndex, (int)i.X, (int)i.Y, player.ActiveObject.Category == -19)))
                            {
                                if ((dirt.plant(player.ActiveObject.ParentSheetIndex, (int)i.X, (int)i.Y, player, player.ActiveObject.Category == -19, currentLocation) && player.IsLocalPlayer))
                                {
                                    player.reduceActiveItemByOne();
                                }
                                Game1.haltAfterCheck = false;
                            }
                        }
                    }
                    else
                    {
                        //@object and terrainFeature was null, must be dirt.
                        _ghostHoe.DoFunction(currentLocation, (int)i.X, (int)i.Y, 0, Game1.player);
                    }
                }
            }
            _powerLevel          = -1;
            Game1.player.Stamina = Game1.player.MaxStamina;
            //End May need to rewrite
        }