Esempio n. 1
0
        public static bool performToolAction_Prefix(ref Object __instance, Tool t, GameLocation location, ref bool __result)
        {
            // If the tool is a mattock and this object is one that requires a specific type of tool that is supported,
            // run the function with a stand-in tool instead.
            if (t is Mattock mattock && !mattock.struckObjects.Contains(__instance))
            {
                // Treat the mattock as a pickaxe for stones.
                if (__instance.name.Equals("Stone") || __instance.name.Equals("Boulder"))
                {
                    Pickaxe standinPickaxe = mattock.asPickaxe();
                    standinPickaxe.DoFunction(location, (int)(__instance.TileLocation.X * 64 + 32), (int)(__instance.TileLocation.Y * 64 + 32), 1, Game1.player);
                    mattock.struckObjects.Add(__instance);
                    return(false);
                }
                // Treat the mattock as an axe for twigs.
                else if (__instance.name.Contains("Twig"))
                {
                    Axe standinAxe = mattock.asAxe();
                    standinAxe.DoFunction(location, (int)(__instance.TileLocation.X * 64 + 32), (int)(__instance.TileLocation.Y * 64 + 32), 1, Game1.player);
                    mattock.struckObjects.Add(__instance);
                    return(false);
                }
            }

            // Otherwise, just do the default functionality.
            return(true);
        }
        public static bool performToolAction_Prefix(ref TerrainFeature __instance, Tool t, int damage, Vector2 tileLocation, GameLocation location, ref bool __result)
        {
            ModEntry.M.Log("performToolAction_Prefix A", StardewModdingAPI.LogLevel.Info);
            // Gotta have the original method available for mattock stand-ins.
            if (performToolActionOriginal == null)
            {
                return(true);
            }

            ModEntry.M.Log("performToolAction_Prefix B", StardewModdingAPI.LogLevel.Info);

            // If the tool is a mattock and this object is one that requires a specific type of tool that is supported,
            // run the function with a stand-in tool instead.
            if (t is Mattock mattock)
            {
                if (__instance is Tree || __instance is FruitTree || __instance is Bush || __instance is GiantCrop || __instance is Flooring)
                {
                    ModEntry.M.Log("Struck a feature:" + __instance.GetType().ToString(), StardewModdingAPI.LogLevel.Info);
                    // Treat the mattock as an axe for various terrain features.
                    Axe standinAxe = mattock.asAxe();
                    __result = (bool)performToolActionOriginal.Invoke(__instance, new object[] { __instance, standinAxe, damage, tileLocation, location });
                    return(false);
                }
                else if (__instance is ResourceClump clump)
                {
                    switch (clump.parentSheetIndex.Get())
                    {
                    case 600:                             // Stump
                    case 602:                             // Log
                    {
                        // Treat the mattock as an axe for stumps.
                        Axe standinAxe = mattock.asAxe();
                        __result = (bool)performToolActionOriginal.Invoke(__instance, new object[] { __instance, standinAxe, damage, tileLocation, location });
                        return(false);
                    }

                    case 622:                             // Iridium meteorite
                    case 672:                             // Boulder 1
                    case 752:                             // Boulder 2
                    case 754:                             // Boulder 3
                    case 756:                             // Icy Boulder 1
                    case 758:                             // Icy Boulder 2
                    {
                        // Treat the mattock as a pickaxe for boulders.
                        Pickaxe standinPickaxe = (t as Mattock).asPickaxe();
                        standinPickaxe.DoFunction(location, (int)(__instance.currentTileLocation.X * 64), (int)(__instance.currentTileLocation.Y * 64), 1, Game1.player);
                        //__result = (bool) performToolActionOriginal.Invoke(__instance, new object[] { __instance, standinPickaxe, damage, tileLocation, location });
                        return(false);
                    }
                    }
                }
            }

            // Otherwise, just do the default functionality.
            return(true);
        }
Esempio n. 3
0
 private void OnButtonsChanged(object sender, ButtonsChangedEventArgs e)
 {
     if (!Context.IsWorldReady)
     {
         return;
     }
     if (e.Pressed.Contains(SButton.J))
     {
         destructionModeActive = !destructionModeActive;
         if (destructionModeActive)
         {
             Game1.chatBox.addMessage("Destruction Mode Enabled", Color.White);
         }
         else
         {
             Game1.chatBox.addMessage("Destruction Mode Disabled", Color.White);
         }
     }
     if (destructionModeActive && e.Held.Contains(SButton.MouseLeft))
     {
         Vector2 tile    = e.Cursor.GrabTile;
         Pickaxe pickaxe = new Pickaxe();
         float   stamina = Game1.player.stamina;
         if (location.terrainFeatures.TryGetValue(tile, out TerrainFeature feature) && feature is Flooring)
         {
             if (userNeedsToBeNextToTile)
             {
                 if (PlayerIsNextToTile(tile))
                 {
                     pickaxe.DoFunction(location, (int)(tile.X * Game1.tileSize), (int)(tile.Y * Game1.tileSize), 1, Game1.player);
                     Game1.player.stamina = stamina;
                 }
             }
             else
             {
                 pickaxe.DoFunction(location, (int)tile.X, (int)tile.Y, 1, Game1.player);
                 Game1.player.stamina = stamina;
             }
         }
     }
 }
        public static bool checkAction_Prefix(ref GameLocation __instance, Location tileLocation, xTile.Dimensions.Rectangle viewport, Farmer who, ref bool __result)
        {
            GameLocation location = __instance;
            ModHooks     hooks    = (ModHooks)typeof(Game1).GetField("hooks", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);

            __result = hooks.OnGameLocation_CheckAction(__instance, tileLocation, viewport, who, delegate
            {
                if (who.IsSitting())
                {
                    who.StopSitting();
                    return(true);
                }
                Microsoft.Xna.Framework.Rectangle value = new Microsoft.Xna.Framework.Rectangle(tileLocation.X * 64, tileLocation.Y * 64, 64, 64);
                foreach (Farmer current in location.farmers)
                {
                    if (current != Game1.player && current.GetBoundingBox().Intersects(value) && current.checkAction(who, location))
                    {
                        return(true);
                    }
                }
                if (location.currentEvent != null && location.currentEvent.isFestival)
                {
                    return(location.currentEvent.checkAction(tileLocation, viewport, who));
                }
                foreach (NPC current2 in location.characters)
                {
                    if (current2 != null && !current2.IsMonster && (!who.isRidingHorse() || !(current2 is Horse)) && current2.GetBoundingBox().Intersects(value) && current2.checkAction(who, location))
                    {
                        if (who.FarmerSprite.IsPlayingBasicAnimation(who.FacingDirection, carrying: false) || who.FarmerSprite.IsPlayingBasicAnimation(who.FacingDirection, carrying: true))
                        {
                            who.faceGeneralDirection(current2.getStandingPosition(), 0, opposite: false, useTileCalculations: false);
                        }
                        return(true);
                    }
                }
                if (who.IsLocalPlayer && who.currentUpgrade != null && location.name.Equals("Farm") && tileLocation.Equals(new Location((int)(who.currentUpgrade.positionOfCarpenter.X + 32f) / 64, (int)(who.currentUpgrade.positionOfCarpenter.Y + 32f) / 64)))
                {
                    if (who.currentUpgrade.daysLeftTillUpgradeDone == 1)
                    {
                        Game1.drawDialogue(Game1.getCharacterFromName("Robin"), Game1.content.LoadString("Data\\ExtraDialogue:Farm_RobinWorking_ReadyTomorrow"));
                    }
                    else
                    {
                        Game1.drawDialogue(Game1.getCharacterFromName("Robin"), Game1.content.LoadString("Data\\ExtraDialogue:Farm_RobinWorking" + (Game1.random.Next(2) + 1)));
                    }
                }
                foreach (ResourceClump current3 in location.resourceClumps)
                {
                    if (current3.getBoundingBox(current3.tile).Intersects(value) && current3.performUseAction(new Vector2(tileLocation.X, tileLocation.Y), location))
                    {
                        return(true);
                    }
                }
                Vector2 vector = new Vector2(tileLocation.X, tileLocation.Y);
                if (location.objects.ContainsKey(vector) && location.objects[vector].Type != null)
                {
                    if (who.isRidingHorse() && !(location.objects[vector] is Fence))
                    {
                        return(false);
                    }
                    if (vector.Equals(who.getTileLocation()) && !location.objects[vector].isPassable())
                    {
                        Tool tool = new Pickaxe();
                        tool.DoFunction(Game1.currentLocation, -1, -1, 0, who);
                        if (location.objects[vector].performToolAction(tool, location))
                        {
                            location.objects[vector].performRemoveAction(location.objects[vector].tileLocation, Game1.currentLocation);
                            location.objects[vector].dropItem(location, who.GetToolLocation(), new Vector2(who.GetBoundingBox().Center.X, who.GetBoundingBox().Center.Y));
                            Game1.currentLocation.Objects.Remove(vector);
                            return(true);
                        }
                        tool = new Axe();
                        tool.DoFunction(Game1.currentLocation, -1, -1, 0, who);
                        if (location.objects.ContainsKey(vector) && location.objects[vector].performToolAction(tool, location))
                        {
                            location.objects[vector].performRemoveAction(location.objects[vector].tileLocation, Game1.currentLocation);
                            location.objects[vector].dropItem(location, who.GetToolLocation(), new Vector2(who.GetBoundingBox().Center.X, who.GetBoundingBox().Center.Y));
                            Game1.currentLocation.Objects.Remove(vector);
                            return(true);
                        }
                        if (!location.objects.ContainsKey(vector))
                        {
                            return(true);
                        }
                    }
                    if (location.objects.ContainsKey(vector) && (location.objects[vector].Type.Equals("Crafting") || location.objects[vector].Type.Equals("interactive")))
                    {
                        if (who.ActiveObject == null && location.objects[vector].checkForAction(who))
                        {
                            return(true);
                        }
                        if (location.objects.ContainsKey(vector))
                        {
                            if (who.CurrentItem != null)
                            {
                                StardewValley.Object value2 = location.objects[vector].heldObject.Value;
                                location.objects[vector].heldObject.Value = null;
                                bool flag = location.objects[vector].performObjectDropInAction(who.CurrentItem, probe: true, who);
                                location.objects[vector].heldObject.Value = value2;
                                bool flag2 = location.objects[vector].performObjectDropInAction(who.CurrentItem, probe: false, who);
                                if ((flag | flag2) && who.isMoving())
                                {
                                    Game1.haltAfterCheck = false;
                                }
                                if (flag2)
                                {
                                    who.reduceActiveItemByOne();
                                    return(true);
                                }
                                return(location.objects[vector].checkForAction(who) | flag);
                            }
                            return(location.objects[vector].checkForAction(who));
                        }
                    }
                    else if (location.objects.ContainsKey(vector) && (bool)location.objects[vector].isSpawnedObject)
                    {
                        int quality   = location.objects[vector].quality;
                        Random random = new Random((int)Game1.uniqueIDForThisGame / 2 + (int)Game1.stats.DaysPlayed + (int)vector.X + (int)vector.Y * 777);
                        if (who.professions.Contains(16) && location.objects[vector].isForage(location))
                        {
                            location.objects[vector].Quality = 4;
                        }
                        else if (location.objects[vector].isForage(location))
                        {
                            if (random.NextDouble() < (double)((float)who.ForagingLevel / 30f))
                            {
                                location.objects[vector].Quality = 2;
                            }
                            else if (random.NextDouble() < (double)((float)who.ForagingLevel / 15f))
                            {
                                location.objects[vector].Quality = 1;
                            }
                        }
                        if ((bool)location.objects[vector].questItem && location.objects[vector].questId.Value != 0 && !who.hasQuest(location.objects[vector].questId))
                        {
                            return(false);
                        }
                        if (who.couldInventoryAcceptThisItem(location.objects[vector]))
                        {
                            if (who.IsLocalPlayer)
                            {
                                location.localSound("pickUpItem");
                                DelayedAction.playSoundAfterDelay("coin", 300);
                            }
                            who.animateOnce(279 + who.FacingDirection);
                            if (!location.isFarmBuildingInterior())
                            {
                                if (location.objects[vector].isForage(location))
                                {
                                    who.gainExperience(2, 7);
                                }
                            }
                            else
                            {
                                who.gainExperience(0, 5);
                            }
                            who.addItemToInventoryBool(location.objects[vector].getOne());
                            Game1.stats.ItemsForaged++;
                            if (who.professions.Contains(13) && random.NextDouble() < 0.2 && !location.objects[vector].questItem && who.couldInventoryAcceptThisItem(location.objects[vector]) && !location.isFarmBuildingInterior())
                            {
                                who.addItemToInventoryBool(location.objects[vector].getOne());
                                who.gainExperience(2, 7);
                            }
                            location.objects.Remove(vector);
                            return(true);
                        }
                        location.objects[vector].Quality = quality;
                    }
                }
                if (who.isRidingHorse())
                {
                    who.mount.checkAction(who, location);
                    return(true);
                }
                foreach (MapSeat current4 in location.mapSeats)
                {
                    if (current4.OccupiesTile(tileLocation.X, tileLocation.Y) && !current4.IsBlocked(location))
                    {
                        who.BeginSitting(current4);
                        return(true);
                    }
                }
                foreach (KeyValuePair <Vector2, TerrainFeature> current5 in location.terrainFeatures.Pairs)
                {
                    if (current5.Value.getBoundingBox(current5.Key).Intersects(value) && current5.Value.performUseAction(current5.Key, location))
                    {
                        Game1.haltAfterCheck = false;
                        return(true);
                    }
                }
                if (location.largeTerrainFeatures != null)
                {
                    foreach (LargeTerrainFeature current6 in location.largeTerrainFeatures)
                    {
                        if (current6.getBoundingBox().Intersects(value) && current6.performUseAction(current6.tilePosition, location))
                        {
                            Game1.haltAfterCheck = false;
                            return(true);
                        }
                    }
                }
                string text = null;
                Tile tile   = location.map.GetLayer("Buildings").PickTile(new Location(tileLocation.X * 64, tileLocation.Y * 64), viewport.Size);
                if (tile != null)
                {
                    tile.Properties.TryGetValue("Action", out PropertyValue value3);
                    if (value3 != null)
                    {
                        text = value3.ToString();
                    }
                }
                if (text == null)
                {
                    text = location.doesTileHaveProperty(tileLocation.X, tileLocation.Y, "Action", "Buildings");
                }
                NPC nPC = location.isCharacterAtTile(vector + new Vector2(0f, 1f));
                if (text != null)
                {
                    if (location.currentEvent == null && nPC != null && !nPC.IsInvisible && !nPC.IsMonster && (!who.isRidingHorse() || !(nPC is Horse)) && Utility.withinRadiusOfPlayer(nPC.getStandingX(), nPC.getStandingY(), 1, who) && nPC.checkAction(who, location))
                    {
                        if (who.FarmerSprite.IsPlayingBasicAnimation(who.FacingDirection, who.IsCarrying()))
                        {
                            who.faceGeneralDirection(nPC.getStandingPosition(), 0, opposite: false, useTileCalculations: false);
                        }
                        return(true);
                    }
                    return(location.performAction(text, who, tileLocation));
                }
                if (tile != null && location.checkTileIndexAction(tile.TileIndex))
                {
                    return(true);
                }
                Point value4 = new Point(tileLocation.X * 64, (tileLocation.Y - 1) * 64);
                bool flag3   = Game1.didPlayerJustRightClick();
                foreach (Furniture current7 in location.furniture)
                {
                    if (current7.boundingBox.Value.Contains((int)(vector.X * 64f), (int)(vector.Y * 64f)) && (int)current7.furniture_type != 12)
                    {
                        if (flag3)
                        {
                            if (who.ActiveObject != null && current7.performObjectDropInAction(who.ActiveObject, probe: false, who))
                            {
                                return(true);
                            }

                            if (who.CurrentTool != null && (who.CurrentTool is MeleeWeapon || who.CurrentTool is Slingshot) && current7.performObjectDropInAction(who.CurrentTool, probe: false, who))
                            {
                                return(true);
                            }
                            return(current7.checkForAction(who));
                        }
                        return(current7.clicked(who));
                    }
                    if ((int)current7.furniture_type == 6 && current7.boundingBox.Value.Contains(value4))
                    {
                        if (flag3)
                        {
                            if (who.ActiveObject != null && current7.performObjectDropInAction(who.ActiveObject, probe: false, who))
                            {
                                return(true);
                            }
                            return(current7.checkForAction(who));
                        }
                        return(current7.clicked(who));
                    }
                }
                return(false);
            });
        public override IActiveEffect onCast(Farmer player, int level, int targetX, int targetY)
        {
            level   += 1;
            targetX /= Game1.tileSize;
            targetY /= Game1.tileSize;
            Vector2 target = new Vector2(targetX, targetY);

            Tool dummyAxe  = new Axe(); dummyAxe.UpgradeLevel = level;
            Tool dummyPick = new Pickaxe(); dummyPick.UpgradeLevel = level;

            Mod.instance.Helper.Reflection.GetField <Farmer>(dummyAxe, "lastUser").SetValue(player);
            Mod.instance.Helper.Reflection.GetField <Farmer>(dummyPick, "lastUser").SetValue(player);

            GameLocation loc = player.currentLocation;

            for (int ix = targetX - level; ix <= targetX + level; ++ix)
            {
                for (int iy = targetY - level; iy <= targetY + level; ++iy)
                {
                    if (player.getCurrentMana() <= 0)
                    {
                        return(null);
                    }

                    Vector2 pos = new Vector2(ix, iy);

                    if (loc.objects.ContainsKey(pos))
                    {
                        var obj = loc.objects[pos];
                        if (obj.performToolAction(dummyAxe, loc))
                        {
                            if (obj.Type == "Crafting" && obj.Fragility != 2)
                            {
                                loc.debris.Add(new Debris(obj.bigCraftable.Value ? -obj.ParentSheetIndex : obj.ParentSheetIndex, pos, pos));
                            }
                            obj.performRemoveAction(pos, loc);
                            loc.objects.Remove(pos);
                            player.addMana(-3);
                            player.AddCustomSkillExperience(Magic.Skill, 1);
                        }
                        else
                        {
                            var oldStam = player.stamina;
                            dummyPick.DoFunction(loc, ix * Game1.tileSize, iy * Game1.tileSize, 0, player);
                            player.stamina = oldStam;
                            player.addMana(-3);
                            player.AddCustomSkillExperience(Magic.Skill, 1);
                        }
                    }

                    // Trees
                    if (level >= 2)
                    {
                        if (loc.terrainFeatures.ContainsKey(pos) && !(loc.terrainFeatures[pos] is HoeDirt))
                        {
                            TerrainFeature tf = loc.terrainFeatures[pos];
                            if (tf is Tree)
                            {
                                player.addMana(-3);
                            }
                            if (tf.performToolAction(dummyAxe, 0, pos, loc) || tf is Grass || (tf is Tree && tf.performToolAction(dummyAxe, 0, pos, loc)))
                            {
                                if (tf is Tree)
                                {
                                    player.AddCustomSkillExperience(Magic.Skill, 5);
                                }
                                loc.terrainFeatures.Remove(pos);
                            }
                            if (tf is Grass && loc is Farm)
                            {
                                (loc as Farm).tryToAddHay(1);
                                Game1.playSound("swordswipe");
                                loc.temporarySprites.Add(new TemporaryAnimatedSprite(28, pos * (float)Game1.tileSize + new Vector2((float)Game1.random.Next(-Game1.pixelZoom * 4, Game1.pixelZoom * 4), (float)Game1.random.Next(-Game1.pixelZoom * 4, Game1.pixelZoom * 4)), Color.Green, 8, Game1.random.NextDouble() < 0.5, (float)Game1.random.Next(60, 100), 0, -1, -1f, -1, 0));
                                loc.temporarySprites.Add(new TemporaryAnimatedSprite(Game1.objectSpriteSheetName, Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, 178, 16, 16), 750f, 1, 0, player.position - new Vector2(0.0f, (float)(Game1.tileSize * 2)), false, false, player.position.Y / 10000f, 0.005f, Color.White, (float)Game1.pixelZoom, -0.005f, 0.0f, 0.0f, false)
                                {
                                    motion     = { Y = -1f },
                                    layerDepth = (float)(1.0 - (double)Game1.random.Next(100) / 10000.0),
                                    delayBeforeAnimationStart = Game1.random.Next(350)
                                });
                            }
                        }
                    }

                    if (level >= 3)
                    {
                        ICollection <ResourceClump> clumps = (NetCollection <ResourceClump>)loc.GetType().GetField("resourceClumps", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).GetValue(loc);
                        if (loc is Woods)
                        {
                            clumps = (loc as Woods).stumps;
                        }
                        if (clumps != null)
                        {
                            foreach (var rc in clumps)
                            {
                                if (new Rectangle((int)rc.tile.X, (int)rc.tile.Y, rc.width.Value, rc.height.Value).Contains(ix, iy))
                                {
                                    player.addMana(-3);
                                    if (rc.performToolAction(dummyAxe, 1, pos, loc) || rc.performToolAction(dummyPick, 1, pos, loc))
                                    {
                                        clumps.Remove(rc);
                                        player.AddCustomSkillExperience(Magic.Skill, 10);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return(null);
        }
Esempio n. 6
0
        private void ClearCurrentLocation(GameLocation loc)
        {
            Axe fakeAxe = new Axe {
                UpgradeLevel = 4
            };
            Pickaxe fakePick = new Pickaxe {
                UpgradeLevel = 4
            };

            Game1.player.MagneticRadius = 650;
            int curStam = Convert.ToInt32(Game1.player.Stamina);

            for (int xTile = 0; xTile < loc.Map.Layers[0].LayerWidth; ++xTile)
            {
                for (int yTile = 0; yTile < loc.Map.Layers[0].LayerHeight; ++yTile)
                {
                    loc.objects.TryGetValue(new Vector2(xTile, yTile), out var obj);
                    loc.terrainFeatures.TryGetValue(new Vector2(xTile, yTile), out var ter);
                    SFarmer who   = Game1.player;
                    Vector2 useAt = (new Vector2(xTile, yTile) * Game1.tileSize) + new Vector2(Game1.tileSize / 2f);
                    if (obj != null)
                    {
                        bool forage = obj.IsSpawnedObject;//checkForAction(Game1.player);
                        if (forage)
                        {
                            DoForageHarvest(obj, loc, who);
                        }
                        if (obj.Name.ToLower().Contains("twig"))
                        {
                            fakeAxe.DoFunction(loc, (int)useAt.X, (int)useAt.Y, 0, who);
                        }
                        if (obj.Name.ToLower().Contains("stone"))
                        {
                            fakePick.DoFunction(loc, (int)useAt.X, (int)useAt.Y, 0, who);
                        }
                        if (obj.Name.ToLower().Contains("weed"))
                        {
                            fakeAxe.DoFunction(loc, (int)useAt.X, (int)useAt.Y, 0, who);
                        }
                    }

                    if (ter != null)
                    {
                        if (ter is Tree tree)
                        {
                            tree.health.Value = 1;
                            fakeAxe.DoFunction(loc, (int)useAt.X, (int)useAt.Y, 0, who);
                            fakeAxe.DoFunction(loc, (int)useAt.X, (int)useAt.Y, 0, who);
                        }

                        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 is HoeDirt dirt)
                        {
                            if (dirt.crop != null)
                            {
                                dirt.fertilizer.Value = 369;
                                dirt.state.Value      = 1;
                            }
                        }
                    }

                    //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);
                        }
                    }


                    //Try to do monsters
                    Rectangle rect = new Rectangle((int)useAt.X, (int)useAt.Y, 4, 4);
                    loc.damageMonster(rect, 1000, 1000, false, Game1.player);

                    /*var monster = loc.characters;
                     *
                     * foreach (var m in monster)
                     * {
                     *  if (m is Monster mon)
                     *  {
                     *      mon.Health = 1;
                     *      fakeAxe.DoFunction(loc, (int)useAt.X, (int)useAt.Y, 0, who);
                     *      //MeleeWeapon wep = new MeleeWeapon();
                     *      //wep.minDamage.Value = 100;
                     *      //wep.maxDamage.Value = 1000;
                     *      //wep.DoDamage(loc, mon.getTileX(), mon.getStandingY(), Game1.player.facingDirection.Value,  1, Game1.player);
                     *  }
                     * }*/

                    //Reset Stamina
                    Game1.player.Stamina = curStam;
                }
            }
        }
Esempio n. 7
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
                }
            }
        }
Esempio n. 8
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
        }
        public override IActiveEffect OnCast(Farmer player, int level, int targetX, int targetY)
        {
            level   += 1;
            targetX /= Game1.tileSize;
            targetY /= Game1.tileSize;

            Tool dummyAxe  = new Axe(); dummyAxe.UpgradeLevel = level;
            Tool dummyPick = new Pickaxe(); dummyPick.UpgradeLevel = level;

            Mod.Instance.Helper.Reflection.GetField <Farmer>(dummyAxe, "lastUser").SetValue(player);
            Mod.Instance.Helper.Reflection.GetField <Farmer>(dummyPick, "lastUser").SetValue(player);

            GameLocation loc = player.currentLocation;

            for (int tileX = targetX - level; tileX <= targetX + level; ++tileX)
            {
                for (int tileY = targetY - level; tileY <= targetY + level; ++tileY)
                {
                    if (player.GetCurrentMana() <= 0)
                    {
                        return(null);
                    }

                    Vector2 tile = new Vector2(tileX, tileY);

                    if (loc.objects.TryGetValue(tile, out SObject obj))
                    {
                        if (obj.performToolAction(dummyAxe, loc))
                        {
                            if (obj.Type == "Crafting" && obj.Fragility != 2)
                            {
                                loc.debris.Add(new Debris(obj.bigCraftable.Value ? -obj.ParentSheetIndex : obj.ParentSheetIndex, tile, tile));
                            }
                            obj.performRemoveAction(tile, loc);
                            loc.objects.Remove(tile);
                            player.AddMana(-3);
                            player.AddCustomSkillExperience(Magic.Skill, 1);
                        }
                        else
                        {
                            float oldStam = player.stamina;
                            dummyPick.DoFunction(loc, tileX * Game1.tileSize, tileY * Game1.tileSize, 0, player);
                            player.stamina = oldStam;
                            player.AddMana(-3);
                            player.AddCustomSkillExperience(Magic.Skill, 1);
                        }
                    }

                    // Trees
                    if (level >= 2)
                    {
                        if (loc.terrainFeatures.TryGetValue(tile, out TerrainFeature feature) && !(feature is HoeDirt))
                        {
                            if (feature is Tree)
                            {
                                player.AddMana(-3);
                            }
                            if (feature.performToolAction(dummyAxe, 0, tile, loc) || feature is Grass || (feature is Tree && feature.performToolAction(dummyAxe, 0, tile, loc)))
                            {
                                if (feature is Tree)
                                {
                                    player.AddCustomSkillExperience(Magic.Skill, 5);
                                }
                                loc.terrainFeatures.Remove(tile);
                            }
                            if (feature is Grass && loc is Farm farm)
                            {
                                farm.tryToAddHay(1);
                                loc.localSoundAt("swordswipe", tile);
                                farm.temporarySprites.Add(new TemporaryAnimatedSprite(28, tile * Game1.tileSize + new Vector2(Game1.random.Next(-Game1.pixelZoom * 4, Game1.pixelZoom * 4), Game1.random.Next(-Game1.pixelZoom * 4, Game1.pixelZoom * 4)), Color.Green, 8, Game1.random.NextDouble() < 0.5, Game1.random.Next(60, 100)));
                                farm.temporarySprites.Add(new TemporaryAnimatedSprite(Game1.objectSpriteSheetName, Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, 178, 16, 16), 750f, 1, 0, player.position - new Vector2(0.0f, Game1.tileSize * 2), false, false, player.position.Y / 10000f, 0.005f, Color.White, Game1.pixelZoom, -0.005f, 0.0f, 0.0f)
                                {
                                    motion     = { Y = -1f },
                                    layerDepth = (float)(1.0 - Game1.random.Next(100) / 10000.0),
                                    delayBeforeAnimationStart = Game1.random.Next(350)
                                });
                            }
                        }
                    }

                    if (level >= 3)
                    {
                        ICollection <ResourceClump> clumps = loc.resourceClumps;

                        if (loc is Woods woods)
                        {
                            clumps = woods.stumps;
                        }
                        if (clumps != null)
                        {
                            foreach (var rc in clumps)
                            {
                                if (new Rectangle((int)rc.tile.X, (int)rc.tile.Y, rc.width.Value, rc.height.Value).Contains(tileX, tileY))
                                {
                                    player.AddMana(-3);
                                    if (rc.performToolAction(dummyAxe, 1, tile, loc) || rc.performToolAction(dummyPick, 1, tile, loc))
                                    {
                                        clumps.Remove(rc);
                                        player.AddCustomSkillExperience(Magic.Skill, 10);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return(null);
        }