Ejemplo n.º 1
0
        public static int GetMaxCan(WateringCan can)
        {
            if (can == null)
            {
                return(-1);
            }
            switch (can.UpgradeLevel)
            {
            case 0:
                can.waterCanMax = 40;
                break;

            case 1:
                can.waterCanMax = 55;
                break;

            case 2:
                can.waterCanMax = 70;
                break;

            case 3:
                can.waterCanMax = 85;
                break;

            case 4:
                can.waterCanMax = 100;
                break;

            default:
                return(-1);
            }

            return(can.waterCanMax);
        }
Ejemplo n.º 2
0
        public static void Postfix(StardewValley.Farmer who, Dictionary <Item, int[]> __result)
        {
            Tool tool = who.getToolFromName("Axe");

            if (tool != null && tool.UpgradeLevel == 4)
            {
                var newTool = new Axe();
                newTool.UpgradeLevel = 5;
                __result.Add(newTool, new int[] { 100000, 1, CobaltBarItem.INDEX });
            }

            tool = who.getToolFromName("Watering Can");
            if (tool != null && tool.UpgradeLevel == 4)
            {
                var newTool = new WateringCan();
                newTool.UpgradeLevel = 5;
                __result.Add(newTool, new int[] { 100000, 1, CobaltBarItem.INDEX });
            }

            tool = who.getToolFromName("Pickaxe");
            if (tool != null && tool.UpgradeLevel == 4)
            {
                var newTool = new Pickaxe();
                newTool.UpgradeLevel = 5;
                __result.Add(newTool, new int[] { 100000, 1, CobaltBarItem.INDEX });
            }

            tool = who.getToolFromName("Hoe");
            if (tool != null && tool.UpgradeLevel == 4)
            {
                var newTool = new Hoe();
                newTool.UpgradeLevel = 5;
                __result.Add(newTool, new int[] { 100000, 1, CobaltBarItem.INDEX });
            }
        }
Ejemplo n.º 3
0
    // Use this for initialization
    void Start()
    {
        playerStamina = GetComponent <PlayerStamina> ();

        camera = Camera.main;
        tool   = Tools.NONE;

        hoe               = GetComponent <Hoe> ();
        plant             = GetComponent <PlantSeeds> ();
        wateringCan       = GetComponent <WateringCan> ();
        sickle            = GetComponent <Sickle> ();
        none              = GetComponent <None> ();
        holdingItem       = GetComponent <HoldingItem> ();
        inventory         = GetComponent <InventoryManager> ();
        fountainCollision = GetComponent <FountainCollider> ();
        NPCCollision      = GetComponentInChildren <NPCCollision> ();
        if (SceneManager.GetActiveScene().name.Contains("Outside") || SceneManager.GetActiveScene().name == "Farming" || SceneManager.GetActiveScene().name == "Farm")
        {
            outside = true;
        }
        else
        {
            outside = false;
        }

        anim          = GetComponent <Animator> ();
        hoeGO         = this.transform.Find("hoe").gameObject;
        wcanGO        = this.transform.Find("wateringcan").gameObject;
        sickleGO      = this.transform.Find("sickle").gameObject;
        buttonToPress = FindObjectOfType(typeof(ButtonToPress)) as ButtonToPress;
    }
Ejemplo n.º 4
0
        public override void InteractEvil(ref GameObject ref_held_obj, ref string original_tag, ref LayerMask original_layer)
        {
            float random = Random.Range(0, 100);

            if (random > 50 && script_plant != null)
            {
                Timing.RunCoroutine(Trample());
            }
            if (ref_held_obj != null)
            {
                // Check if watering can
                if (original_tag == "WaterCan")
                {
                    WateringCan wateringCan = ref_held_obj.GetComponent <WateringCan>();
                    if (wateringCan.WaterAmount != 0)
                    {
                        wateringCan.WaterAmount = 0;
                        SoundManager.Instance.PlayPourWater();
                        if (script_plant != null)
                        {
                            script_plant.currentWater = 100f;
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        //change result to sapphire if appropriate
        internal static void FishingRod_DoFunction_Postfix(ref WateringCan __instance, int x, int y, int power, Farmer who)
        {
            if (!Game1.player.eventsSeen.Contains(UNSEALEVENT))
            {
                return;
            }

            try
            {
                if (who.UniqueMultiplayerID != Game1.player.UniqueMultiplayerID)
                {
                    return;
                }
                int tileX = x / 64;
                int tileY = y / 64;

                if (tileX == 145 && tileY == 69 && Game1.currentLocation.Name.Equals("Custom_Ridgeside_RidgesideVillage") && !Game1.player.mailReceived.Contains(FLAGHEROSTATUE))
                {
                    SpawnJAItemAsDebris("Village Hero Sculpture", tileX, tileY, Game1.currentLocation);
                    Game1.player.mailReceived.Add(FLAGHEROSTATUE);
                }
            }
            catch (Exception e)
            {
                Log.Error($"Harmony patch \"{nameof(FishingRod_DoFunction_Postfix)}\" has encountered an error. \n{e.ToString()}");
            }
        }
Ejemplo n.º 6
0
        private void WaterTile(Vector2 tile, bool useWatercanAnimation = false)
        {
            TerrainFeature terrainFeature;

            StardewValley.Object obj;
            WateringCan          can = new WateringCan();
            GameLocation         loc = Game1.currentLocation;

            loc.terrainFeatures.TryGetValue(tile, out terrainFeature);
            if (terrainFeature != null)
            {
                terrainFeature.performToolAction(can, 0, tile, (GameLocation)null);
            }

            loc.Objects.TryGetValue(tile, out obj);
            if (obj != null)
            {
                obj.performToolAction(can, (GameLocation)null);
            }

            //Watercan animation (only for sline sprinklers, because default animation don't make any sense here
            if (mp != null && useWatercanAnimation)
            {
                mp.broadcastSprites(loc, new TemporaryAnimatedSprite[]
                {
                    new TemporaryAnimatedSprite(13, tile * (float)Game1.tileSize, Color.White, 10, Game1.random.NextDouble() < 0.5, 70f, 0, -1, -1f, -1, 0)
                    {
                        delayBeforeAnimationStart = 150
                    }
                });
            }
        }
Ejemplo n.º 7
0
        //Public access to add drink to body if you pres RMB with the watering can
        public void DrinkWateringCan()
        {
            Farmer      player      = Game1.player;
            WateringCan wateringCan = (WateringCan)player.CurrentTool;

            if (wateringCan.WaterLeft > 0)
            {
                float waterLeft  = wateringCan.WaterLeft * 100;
                float fillAmount = Math.Max(maxWater - water, glassOfWater);
                if (waterLeft < fillAmount)
                {
                    AddWater(waterLeft, 0.65f);
                    wateringCan.WaterLeft = 0;
                }
                else
                {
                    wateringCan.WaterLeft -= (int)(fillAmount / 100.0);
                    AddWater(fillAmount, 0.65f);
                }
                Animations.AnimateDrinking(false);
            }
            else
            {
                player.doEmote(4);
                Game1.showRedMessage("Out of water");
            }
        }
Ejemplo n.º 8
0
 protected override void OnWateringCanAction(WateringCan wateringCan)
 {
     if (!IsEmpty)
     {
         return;
     }
     PlaySound(Sound.Bubbles);
     IsEmpty = false;
 }
Ejemplo n.º 9
0
        /*
         * public void PlaceOn(GameObject plantObj)
         * {
         *  PlacedPlant = plantObj.GetComponent<Plant>();
         *  isTaken = true;
         * }
         */

        public override void Interact(ref GameObject ref_held_obj, ref string original_tag, ref LayerMask original_layer)
        {
            if (ref_held_obj == null) // Interacting entity not holding anything
            {
                if (ref_placed_plant && script_plant.HasGrown)
                {
                    // Eject with some velocity to make it more clear to the user
                    float random_angle = Random.Range(0f, Mathf.PI * 2);
                    ref_placed_plant.GetComponent <Rigidbody2D>().velocity = (new Vector2(Mathf.Cos(random_angle), Mathf.Sin(random_angle))) * ejection_velocity;
                    // Unroot the plant
                    ref_placed_plant.tag   = "Plant";
                    ref_placed_plant.layer = LayerMask.NameToLayer("Seeds");
                    ref_placed_plant.GetComponent <Holdable>().Interact(ref ref_held_obj, ref original_tag, ref original_layer);
                    ref_placed_plant = null;
                    script_plant     = null;
                }
            }
            else
            {
                // Check if plant
                if (original_tag == "Plant")
                {
                    if (ref_placed_plant == null) // No plants are currently on the plot
                    {
                        // Assign held plant to plot
                        ref_placed_plant     = ref_held_obj.gameObject;
                        ref_placed_plant.tag = "Planted";
                        ref_placed_plant.GetComponent <Rigidbody2D>().simulated = false;
                        ref_placed_plant.GetComponent <Plant>().IsPlaced        = true;
                        ref_placed_plant.transform.rotation = Quaternion.identity;
                        ref_placed_plant.layer = LayerMask.NameToLayer("Planted"); // Prevents selection cursor from targetting this over Plot
                        script_plant           = ref_placed_plant.GetComponent <Plant>();

                        // Free the previously held plant
                        ref_held_obj = null;
                        SoundManager.Instance.PlayRandomFlowerGetSound();
                    }
                }

                // Check if watering can
                if (original_tag == "WaterCan" && script_plant != null)
                {
                    WateringCan wateringCan = ref_held_obj.GetComponent <WateringCan>();
                    if (wateringCan.WaterAmount <= 0)
                    {
                        UIManager.Instance.SendAMessage("Water can is empty!");
                    }
                    else
                    {
                        script_plant.currentWater = 100f;
                        wateringCan.WaterAmount  -= 25f;
                        SoundManager.Instance.PlayPourWater();
                    }
                }
            }
        }
Ejemplo n.º 10
0
 public static void WateringCan_DoFunction_Postfix(WateringCan __instance, int x, int y, Farmer who)
 {
     if (!Config.EnableMod || !Game1.currentLocation.CanRefillWateringCanOnTile(x / 64, y / 64))
     {
         return;
     }
     __instance.waterCanMax = (int)(__instance.waterCanMax * Config.VolumeMult);
     AccessTools.FieldRefAccess <WateringCan, int>(__instance, "waterLeft") = __instance.waterCanMax;
     SMonitor.Log($"Filled watering can to {__instance.waterCanMax}");
 }
Ejemplo n.º 11
0
        protected override void _UnapplyTo(Item item)
        {
            base._UnapplyTo(item);
            WateringCan tool = item as WateringCan;

            if (tool != null)
            {
                tool.IsBottomless = false;
            }
        }
Ejemplo n.º 12
0
        protected override void _ApplyTo(Item item)
        {
            base._ApplyTo(item);
            WateringCan tool = item as WateringCan;

            if (tool != null)
            {
                tool.IsBottomless = true;
                tool.WaterLeft    = tool.waterCanMax;
            }
        }
        public static void RefillWateringCan()
        {
            WateringCan can = Util.FindToolFromInventory <WateringCan>(Config.FindCanFromInventory);

            if (can == null || can.WaterLeft >= Util.GetMaxCan(can) ||
                !Util.IsThereAnyWaterNear(Game1.player.currentLocation, Game1.player.getTileLocation()))
            {
                return;
            }
            can.WaterLeft = can.waterCanMax;
            Game1.playSound("slosh");
            DelayedAction.playSoundAfterDelay("glug", 250);
        }
Ejemplo n.º 14
0
 public override void Interact(ref GameObject ref_held_obj, ref string original_tag, ref LayerMask original_layer)
 {
     if (ref_held_obj != null) // Not holding anything
     {
         if (original_tag == "WaterCan")
         {
             WateringCan wateringCan = ref_held_obj.GetComponent <WateringCan>();
             wateringCan.WaterAmount = 100f;
             wateringCan.RunParticles();
             SoundManager.Instance.PlayWaterCanFill();
         }
     }
 }
Ejemplo n.º 15
0
        public static void WaterNearbyCrops()
        {
            WateringCan can = Util.FindToolFromInventory <WateringCan>(Game1.player, InstanceHolder.Config.FindCanFromInventory);

            if (can == null)
            {
                return;
            }

            Util.GetMaxCan(can);
            bool watered = false;

            foreach (KeyValuePair <Vector2, HoeDirt> kv in Util.GetFeaturesWithin <HoeDirt>(InstanceHolder.Config.AutoWaterRadius))
            {
                HoeDirt dirt    = kv.Value;
                float   consume = 2 * (1.0f / (can.UpgradeLevel / 2.0f + 1));
                if (dirt.crop == null || dirt.crop.dead.Value || dirt.state.Value != 0 ||
                    !(Game1.player.Stamina >= consume) ||
                    can.WaterLeft <= 0)
                {
                    continue;
                }

                dirt.state.Value      = 1;
                Game1.player.Stamina -= consume;
                can.WaterLeft--;
                watered = true;
            }
            foreach (IndoorPot pot in Util.GetObjectsWithin <IndoorPot>(InstanceHolder.Config.AutoWaterRadius))
            {
                if (pot.hoeDirt.Value == null)
                {
                    continue;
                }

                HoeDirt dirt    = pot.hoeDirt.Value;
                float   consume = 2 * (1.0f / (can.UpgradeLevel / 2.0f + 1));
                if (dirt.crop != null && !dirt.crop.dead.Value && dirt.state.Value != 1 && Game1.player.Stamina >= consume && can.WaterLeft > 0)
                {
                    dirt.state.Value        = 1;
                    pot.showNextIndex.Value = true;
                    Game1.player.Stamina   -= consume;
                    can.WaterLeft--;
                    watered = true;
                }
            }
            if (watered)
            {
                Game1.playSound("slosh");
            }
        }
Ejemplo n.º 16
0
        public static bool WateringCan_DoFunction_Prefix(WateringCan __instance, GameLocation location, int x, int y, int power, Farmer who)
        {
            if (!Config.EnableMod || !Config.FillAdjacent || Game1.currentLocation.CanRefillWateringCanOnTile(x / 64, y / 64) || who.toolPower == 0)
            {
                return(true);
            }
            var ptr        = AccessTools.Method(typeof(Tool), nameof(Tool.DoFunction)).MethodHandle.GetFunctionPointer();
            var baseMethod = (Action <GameLocation, int, int, int, Farmer>)Activator.CreateInstance(typeof(Action <GameLocation, int, int, int, Farmer>), __instance, ptr);

            baseMethod(location, x, y, power, who);
            who.stopJittering();

            return(false);
        }
Ejemplo n.º 17
0
        public override bool Apply(Vector2 tile, SObject tileObj, TerrainFeature tileFeature, SFarmer who, Tool tool, Item item, GameLocation location)
        {
            if (!(tileFeature is HoeDirt dirt) || dirt.state == HoeDirt.watered)
            {
                return(false);
            }
            WateringCan can           = (WateringCan)tool;
            int         previousWater = can.WaterLeft;

            can.WaterLeft = 100;
            this.UseToolOnTile(tool, tile);
            can.WaterLeft = previousWater;
            return(true);
        }
Ejemplo n.º 18
0
 private void OnTimeChanged(object sender, TimeChangedEventArgs e)
 {
     if (Game1.isRaining)
     {
         if (requireEquipped)
         {
             if (Game1.player.CurrentTool is WateringCan can)
             {
                 if (Game1.player.currentLocation.IsOutdoors)
                 {
                     if (can.WaterLeft + waterIncreaseAmount > can.waterCanMax)
                     {
                         can.WaterLeft += (can.waterCanMax - can.WaterLeft);
                     }
                     else
                     {
                         can.WaterLeft += waterIncreaseAmount;
                     }
                 }
             }
         }
         else
         {
             WateringCan can = null;
             foreach (Item item in Game1.player.Items)
             {
                 if (item is WateringCan can1)
                 {
                     can = can1;
                     break;
                 }
             }
             if (can != null)
             {
                 if (Game1.player.currentLocation.IsOutdoors)
                 {
                     if (can.WaterLeft + waterIncreaseAmount > can.waterCanMax)
                     {
                         can.WaterLeft += (can.waterCanMax - can.WaterLeft);
                     }
                     else
                     {
                         can.WaterLeft += waterIncreaseAmount;
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 19
0
        /*********
        ** Private methods
        *********/
        /// <summary>Use a tool on a tile.</summary>
        /// <param name="tool">The tool to use.</param>
        /// <param name="tile">The tile to affect.</param>
        /// <param name="player">The current player.</param>
        /// <param name="location">The current location.</param>
        /// <returns>Returns <c>true</c> for convenience when implementing tools.</returns>
        private bool UseWateringCanOnTile(Tool tool, Vector2 tile, Farmer player, GameLocation location)
        {
            WateringCan can       = (WateringCan)tool;
            int         prevWater = can.WaterLeft;

            can.WaterLeft = 100;
            try
            {
                return(this.UseToolOnTile(tool, tile, player, location));
            }
            finally
            {
                can.WaterLeft = prevWater;
            }
        }
        /// <summary>Apply the tool to the given tile.</summary>
        /// <param name="tile">The tile to modify.</param>
        /// <param name="tileObj">The object on the tile.</param>
        /// <param name="tileFeature">The feature on the tile.</param>
        /// <param name="player">The current player.</param>
        /// <param name="tool">The tool selected by the player (if any).</param>
        /// <param name="item">The item selected by the player (if any).</param>
        /// <param name="location">The current location.</param>
        public override bool Apply(Vector2 tile, SObject tileObj, TerrainFeature tileFeature, SFarmer player, Tool tool, Item item, GameLocation location)
        {
            if (!this.TryGetHoeDirt(tileFeature, tileObj, out HoeDirt dirt, out _) || dirt.state.Value == HoeDirt.watered)
            {
                return(false);
            }

            WateringCan can       = (WateringCan)tool;
            int         prevWater = can.WaterLeft;

            can.WaterLeft = 100;
            this.UseToolOnTile(tool, tile);
            can.WaterLeft = prevWater;

            return(true);
        }
Ejemplo n.º 21
0
        private void TemporarilyFakeInteraction(Action action)
        {
            // get references
            // (Note: change net values directly to avoid sync bugs, since the value will be reset when we're done.)
            Farmer                    player             = Game1.player;
            NetRef <Horse>            mountField         = this.Reflection.GetField <NetRef <Horse> >(Game1.player, "netMount").GetValue();
            IReflectedField <Horse>   mountFieldValue    = this.Reflection.GetField <Horse>(mountField, "value");
            IReflectedField <Vector2> mountPositionValue = this.Reflection.GetField <Vector2>(player.mount.position.Field, "value");

            // save current state
            Horse       mount            = mountField.Value;
            Vector2     mountPosition    = mount.Position;
            WateringCan wateringCan      = player.CurrentTool as WateringCan;
            int         waterInCan       = wateringCan?.WaterLeft ?? 0;
            float       stamina          = player.stamina;
            Vector2     position         = player.Position;
            int         facingDirection  = player.FacingDirection;
            int         currentToolIndex = player.CurrentToolIndex;
            bool        canMove          = player.canMove; // fix player frozen due to animations when performing an action

            // move mount out of the way
            mountFieldValue.SetValue(null);
            mountPositionValue.SetValue(new Vector2(-5, -5));

            // perform action
            try
            {
                action();
            }
            finally
            {
                // move mount back
                mountPositionValue.SetValue(mountPosition);
                mountFieldValue.SetValue(mount);

                // restore previous state
                if (wateringCan != null)
                {
                    wateringCan.WaterLeft = waterInCan;
                }
                player.stamina          = stamina;
                player.Position         = position;
                player.FacingDirection  = facingDirection;
                player.CurrentToolIndex = currentToolIndex;
                player.canMove          = canMove;
            }
        }
Ejemplo n.º 22
0
 public Multitool(MultitoolMod m)
 {
     this.mod                     = m;
     this.attachedTools           = new Dictionary <string, Tool>();
     this.axe                     = new Axe();
     this.pickaxe                 = new Pickaxe();
     this.scythe                  = new MeleeWeapon(47);
     this.scythe                  = (MeleeWeapon)this.scythe.getOne();
     this.scythe.Category         = -99;
     this.wateringCan             = new WateringCan();
     this.hoe                     = new Hoe();
     attachedTools["axe"]         = this.axe;
     attachedTools["pickaxe"]     = this.pickaxe;
     attachedTools["melee"]       = this.scythe;
     attachedTools["wateringcan"] = this.wateringCan;
     attachedTools["hoe"]         = this.hoe;
 }
Ejemplo n.º 23
0
        public static void Prefix(WateringCan __instance, GameLocation location, int x, int y, int power, Farmer who)
        {
            List <Vector2> source = WCanAccessor.tilesAffected(__instance, new Vector2((float)(x / 64), (float)(y / 64)), power, who);

#pragma warning disable AvoidNetField
#pragma warning disable AvoidImplicitNetFieldCast
            if (location.doesTileHaveProperty(x / 64, y / 64, "Water", "Back") != null || location.doesTileHaveProperty(x / 64, y / 64, "WaterSource", "Back") != null || location is BuildableGameLocation && (location as BuildableGameLocation).getBuildingAt(source.First <Vector2>()) != null && ((location as BuildableGameLocation).getBuildingAt(source.First <Vector2>()).buildingType.Equals((object)"Well") && (int)((NetFieldBase <int, NetInt>)(location as BuildableGameLocation).getBuildingAt(source.First <Vector2>()).daysOfConstructionLeft) <= 0) || !(bool)((NetFieldBase <bool, NetBool>)location.isOutdoors) && location.doesTileHavePropertyNoNull(x / 64, y / 64, "Action", "Buildings").Equals("kitchen") && location.getTileIndexAt(x / 64, y / 64, "Buildings") == 172)
#pragma warning restore AvoidImplicitNetFieldCast
#pragma warning restore AvoidNetField
            {
            }
            else if (__instance.WaterLeft > 0 || who.hasWateringCanEnchantment)
            {
                float consumed = (float)(2 * (who.toolPower + 1)) - (float)who.FarmingLevel * 0.1f;
                float restored = Math.Min(who.HasAdornment(ToolType.WateringCan, Mod.Config.GEODE_LESS_STAMINA), 4) * 2;
                who.Stamina += Math.Min(consumed, restored);
            }
        }
Ejemplo n.º 24
0
        /// <summary>Temporarily dismount and set up the player to interact with a tile, then return it to the previous state afterwards.</summary>
        /// <param name="action">The action to perform.</param>
        private void TemporarilyFakeInteraction(Action action)
        {
            // get references
            SFarmer        player     = Game1.player;
            NetRef <Horse> mountField = this.Reflection.GetField <NetRef <Horse> >(Game1.player, "netMount").GetValue(); // change value directly to bypass the game's on-dismount logic

            // save current state
            Horse       mount            = mountField.Value;
            Vector2     mountPosition    = this.Position;
            WateringCan wateringCan      = player.CurrentTool as WateringCan;
            int         waterInCan       = wateringCan?.WaterLeft ?? 0;
            float       stamina          = player.stamina;
            Vector2     position         = player.Position;
            int         facingDirection  = player.FacingDirection;
            int         currentToolIndex = player.CurrentToolIndex;
            bool        canMove          = Game1.player.canMove; // fix player frozen due to animations when performing an action

            // move mount out of the way
            mountField.Value = null;
            this.Position    = new Vector2(-5, -5);

            // perform action
            try
            {
                action();
            }
            finally
            {
                // move mount back
                this.Position    = mountPosition;
                mountField.Value = mount;

                // restore previous state
                if (wateringCan != null)
                {
                    wateringCan.WaterLeft = waterInCan;
                }
                player.stamina          = stamina;
                player.Position         = position;
                player.FacingDirection  = facingDirection;
                player.CurrentToolIndex = currentToolIndex;
                Game1.player.canMove    = canMove;
            }
        }
Ejemplo n.º 25
0
        /// <summary>Temporarily dismount and set up the player to interact with a tile, then return it to the previous state afterwards.</summary>
        /// <param name="action">The action to perform.</param>
        private void TemporarilyFakeInteraction(Action action)
        {
            // get references
            SFarmer player = Game1.player;
            IReflectedField <Horse> mountField = this.Reflection.GetField <Horse>(Game1.player, "mount");

            // save current state
            Horse       mount            = mountField.GetValue();
            Vector2     mountPosition    = this.Current.position;
            WateringCan wateringCan      = player.CurrentTool as WateringCan;
            int         waterInCan       = wateringCan?.WaterLeft ?? 0;
            float       stamina          = player.stamina;
            Vector2     position         = player.position;
            int         facingDirection  = player.facingDirection;
            int         currentToolIndex = player.CurrentToolIndex;
            bool        canMove          = Game1.player.canMove; // fix player frozen due to animations when performing an action

            // move mount out of the way
            mountField.SetValue(null);
            this.Current.position = new Vector2(-5, -5);

            // perform action
            try
            {
                action();
            }
            finally
            {
                // move mount back
                this.Current.position = mountPosition;
                mountField.SetValue(mount);

                // restore previous state
                if (wateringCan != null)
                {
                    wateringCan.WaterLeft = waterInCan;
                }
                player.stamina          = stamina;
                player.position         = position;
                player.facingDirection  = facingDirection;
                player.CurrentToolIndex = currentToolIndex;
                Game1.player.canMove    = canMove;
            }
        }
Ejemplo n.º 26
0
 private void DoAction()
 {
     if (Helper.Input.GetState(SButton.MouseRight) == SButtonState.Pressed)
     {
         Vector2 tile = Game1.currentCursorTile;
         if (Game1.currentLocation.objects.TryGetValue(tile, out StardewValley.Object check))
         {
             if (check.name.ToLower().Contains("sprinkler"))
             {
                 //Defines radius & checks for pressure nozzle
                 int sprinklerRadius = 0;
                 if (check.heldObject.Value != null && Utility.IsNormalObjectAtParentSheetIndex(check.heldObject, 915))
                 {
                     sprinklerRadius++;
                 }
                 //Determines sprinkler type, adjusts radius accordingly
                 if (check.name.ToLower().Contains("iridium"))
                 {
                     sprinklerRadius += 2;
                 }
                 else if (check.name.ToLower().Contains("quality"))
                 {
                     sprinklerRadius++;
                 }
                 //Creates area that needs to be watered
                 List <Vector2> tileNeedWater = MakeVector2TileGrid(tile, sprinklerRadius);
                 //Waters the area specified
                 WateringCan waterCan = new WateringCan
                 {
                     WaterLeft = 100
                 };
                 float stamina = Game1.player.Stamina;
                 foreach (Vector2 waterTile in tileNeedWater)
                 {
                     waterCan.DoFunction(Game1.currentLocation, (int)(waterTile.X * Game1.tileSize), (int)(waterTile.Y * Game1.tileSize), 1, Game1.player);
                     waterCan.WaterLeft++;
                     Game1.player.Stamina = stamina;
                 }
             }
         }
     }
 }
        /// <summary>Fill the pet bowls if the player is holding a filled watering can and the cursor is over a bowl.</summary>
        /// <param name="farm">The current location.</param>
        /// <param name="tile">The tile being interacted with.</param>
        private bool TryFillPetBowls(Farm farm, Vector2 tile)
        {
            WateringCan wateringCan = Game1.player.CurrentTool as WateringCan;

            if (wateringCan == null || wateringCan.WaterLeft <= 0)
            {
                return(false);
            }

            // fill bowls if under cursor
            int tileID = farm.getTileIndexAt((int)tile.X, (int)tile.Y, "Buildings");

            if (tileID == 2201 || tileID == 2202)
            {
                farm.setMapTileIndex(52, 7, 2204, "Buildings");
                farm.setMapTileIndex(53, 7, 2205, "Buildings");
                this.PetBowlsFilled = true;
                return(true);
            }
            return(false);
        }
Ejemplo n.º 28
0
        internal static void WateringCan_DoFunction_Postfix(ref WateringCan __instance, int x, int y, int power, Farmer who)
        {
            if (!Game1.player.eventsSeen.Contains(UNSEALEVENT))
            {
                return;
            }

            try
            {
                int tileX = x / 64;
                int tileY = y / 64;
                if (tileX == 11 && tileY == 7 && Game1.currentLocation.Name.Equals("Custom_Ridgeside_RSVGreenhouse2") && !Game1.player.mailReceived.Contains(FLAGCANDELABRUM))
                {
                    SpawnJAItemAsDebris("Pale Candelabrum", tileX, tileY, Game1.currentLocation);
                    Game1.player.mailReceived.Add(FLAGCANDELABRUM);
                }
            }
            catch (Exception e)
            {
                Log.Error($"Harmony patch \"{nameof(WateringCan_DoFunction_Postfix)}\" has encountered an error. \n{e.ToString()}");
            }
        }
Ejemplo n.º 29
0
        /*
         * Private Methods
         */
        //Events

        private void OnSaveLoaded(object sender, SaveLoadedEventArgs e)
        {
            //Make sure that the activate key is valid
            if (!Enum.TryParse(_toolConfig.KeyBindClear, true, out _actKey))
            {
                _actKey = SButton.Z;
                Monitor.Log("Keybind was invalid. setting it to Z");
            }
            //Make sure the crop key is valid
            if (!Enum.TryParse(_toolConfig.KeyBindCrop, true, out _cropKey))
            {
                _cropKey = SButton.X;
                Monitor.Log("Keybind was invalid. setting it to X");
            }

            //Set up Phantom Tools
            _hoeDirtTool = "PickAxe";
            _ghostScythe = new CustomScythe(47)
            {
                UpgradeLevel = _toolConfig.ToolLevel
            };
            _ghostAxe = new Axe {
                UpgradeLevel = LevelCheck(_toolConfig.ToolLevel)
            };
            _ghostPickaxe = new Pickaxe {
                UpgradeLevel = LevelCheck(_toolConfig.ToolLevel)
            };
            _ghostHoe = new Hoe {
                UpgradeLevel = LevelCheck(_toolConfig.ToolLevel)
            };
            _ghostWaterCan = new WateringCan {
                UpgradeLevel = LevelCheck(_toolConfig.ToolLevel)
            };
            _ghostPan = new Pan();
            _usePailonOtherAnimals = _toolConfig.UsePailonOtherAnimals;
            _ghostShearPail        = new CustomShearPail(_usePailonOtherAnimals);
        }
Ejemplo n.º 30
0
        public static Tool getToolFromDescription(byte index, int upgradeLevel)
        {
            Tool t = null;

            switch (index)
            {
            case 0:
                t = new Axe();
                break;

            case 1:
                t = new Hoe();
                break;

            case 2:
                t = new FishingRod();
                break;

            case 3:
                t = new Pickaxe();
                break;

            case 4:
                t = new WateringCan();
                break;

            case 5:
                t = new MeleeWeapon(0, upgradeLevel);
                break;

            case 6:
                t = new Slingshot();
                break;
            }
            t.UpgradeLevel = upgradeLevel;
            return(t);
        }