コード例 #1
0
ファイル: ModEntry.cs プロジェクト: somnomania/smapi-mod-dump
        /// <summary>Draw tooltip for ingredients if cursor is hovering over them.</summary>
        /// <param name="__instance">The instance of the bundle menu.</param>
        /// <param name="b">The sprite batch.</param>
        public static void Postfix_draw(JunimoNoteMenu __instance, SpriteBatch b)
        {
            try
            {
                if (__instance.ingredientList == null || ingredientHoverText == null || ingredientHoverTitle == null)
                {
                    return;
                }

                int x = (int)input.GetCursorPosition().ScreenPixels.X, y = (int)input.GetCursorPosition().ScreenPixels.Y;
                for (int i = 0; i < __instance.ingredientList.Count; i++)
                {
                    if (__instance.ingredientList[i].bounds.Contains(x, y))
                    {
                        if (i >= ingredientHoverText.Length || i >= ingredientHoverTitle.Length)
                        {
                            continue;
                        }

                        IClickableMenu.drawToolTip(b, ingredientHoverText[i], ingredientHoverTitle[i], null);
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                Log("Error in draw: " + e.Message + Environment.NewLine + e.StackTrace);
            }
        }
コード例 #2
0
        /// <summary>Raised after the game state is updated (≈60 times per second).</summary>
        /// <param name="e">The event arguments.</param>
        /// <param name="reflection">Simplifies access to private game code.</param>
        /// <param name="input">An API for checking input state.</param>
        public void OnUpdateTicked(UpdateTickedEventArgs e, IReflectionHelper reflection, IInputHelper input)
        {
            if (Game1.player?.currentLocation != null)
            {
                Farmer player = Game1.player;

                // movement speed
                this.UpdateBuff();

                // infinite health/stamina
                if (this.Config.InfiniteHealth)
                {
                    player.health = player.maxHealth;
                }
                if (this.Config.InfiniteStamina)
                {
                    player.stamina = player.MaxStamina;
                }

                // fishing cheats
                if (player.CurrentTool is FishingRod rod)
                {
                    BobberBar bobberMenu = Game1.activeClickableMenu as BobberBar;

                    // max cast power
                    if (this.Config.ThrowBobberMax && rod.isTimingCast)
                    {
                        rod.castingPower = 1.01f;
                    }

                    // durable tackles
                    if (this.Config.DurableTackles && rod.attachments[1] != null)
                    {
                        rod.attachments[1].uses.Value = 0;
                    }

                    // instant bite
                    if (this.Config.InstantBite && rod.isFishing && !rod.hit && rod.timeUntilFishingBite > 0)
                    {
                        rod.timeUntilFishingBite = 0;
                    }

                    // always treasure
                    if (this.Config.AlwaysTreasure && bobberMenu != null)
                    {
                        reflection.GetField <bool>(bobberMenu, "treasure").SetValue(true);
                    }

                    // instant catch
                    if (this.Config.InstantCatch && bobberMenu != null)
                    {
                        reflection.GetField <float>(bobberMenu, "distanceFromCatching").SetValue(1);
                        if (reflection.GetField <bool>(bobberMenu, "treasure").GetValue())
                        {
                            reflection.GetField <bool>(bobberMenu, "treasureCaught").SetValue(true);
                        }
                    }
                }

                // one-hit break
                if (this.Config.OneHitBreak && player.UsingTool && (player.CurrentTool is Axe || player.CurrentTool is Pickaxe))
                {
                    Vector2 tile = new Vector2((int)player.GetToolLocation().X / Game1.tileSize, (int)player.GetToolLocation().Y / Game1.tileSize);

                    if (player.CurrentTool is Pickaxe && player.currentLocation.objects.ContainsKey(tile))
                    {
                        SObject obj = player.currentLocation.Objects[tile];
                        if (obj != null && obj.name == "Stone")
                        {
                            obj.MinutesUntilReady = 0;
                        }
                    }

                    if (player.CurrentTool is Axe && player.currentLocation.terrainFeatures.ContainsKey(tile))
                    {
                        TerrainFeature obj = player.currentLocation.terrainFeatures[tile];
                        if (obj is Tree tree && tree.health.Value > 1)
                        {
                            tree.health.Value = 1;
                        }
                        else if (obj is FruitTree fruitTree && fruitTree.health.Value > 1)
                        {
                            fruitTree.health.Value = 1;
                        }
                    }

                    List <ResourceClump> resourceClumps = new List <ResourceClump>();
                    if (player.currentLocation is MineShaft mineShaft)
                    {
                        resourceClumps.AddRange(mineShaft.resourceClumps);
                    }

                    if (player.currentLocation is Farm farm)
                    {
                        resourceClumps.AddRange(farm.resourceClumps);
                    }

                    if (player.currentLocation is Forest forest)
                    {
                        resourceClumps.Add(forest.log);
                    }

                    if (player.currentLocation is Woods woods)
                    {
                        resourceClumps.AddRange(woods.stumps);
                    }

                    foreach (ResourceClump r in resourceClumps)
                    {
                        if (r == null)
                        {
                            continue;
                        }
                        if (r.getBoundingBox(r.tile.Value).Contains((int)player.GetToolLocation().X, (int)player.GetToolLocation().Y) && r.health.Value > 0)
                        {
                            r.health.Value = 0;
                        }
                    }
                }

                // infinite watering can
                if (this.Config.InfiniteWateringCan && player.CurrentTool is WateringCan can)
                {
                    can.WaterLeft = can.waterCanMax;
                }

                // unlimited gifts
                if (this.Config.AlwaysGiveGift)
                {
                    foreach (Friendship friendship in player.friendshipData.Values)
                    {
                        friendship.GiftsThisWeek = 0;
                        friendship.GiftsToday    = 0;
                    }
                }

                // one-hit kill
                if (this.Config.OneHitKill)
                {
                    foreach (Monster monster in player.currentLocation.characters.OfType <Monster>())
                    {
                        if (monster.Health > 1)
                        {
                            monster.Health = 1;
                        }
                    }
                }

                // grow crops/trees
                if (this.ShouldGrowCrops && e.IsMultipleOf(15))
                {
                    this.GrowCrops(input.GetCursorPosition().Tile);
                }
                if (this.ShouldGrowTrees && e.IsMultipleOf(15))
                {
                    this.GrowTree(input.GetCursorPosition().Tile);
                }
            }