コード例 #1
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="I">The itme to display.</param>
 /// <param name="Position">The position of the item.</param>
 /// <param name="BoundingBox">The bounding box for the item.</param>
 /// <param name="Scale"></param>
 /// <param name="DrawStackNumber"></param>
 /// <param name="DrawColor"></param>
 public ItemDisplayButton(Item I, StardustCore.Animations.AnimatedSprite Background, Vector2 Position, Rectangle BoundingBox, float Scale, bool DrawStackNumber, Color DrawColor)
 {
     this.item            = I;
     this.defaultBounds   = BoundingBox;
     this.Position        = Position;
     this.scale           = Scale;
     this.drawStackNumber = DrawStackNumber;
     this.drawColor       = DrawColor;
     this.background      = Background;
 }
コード例 #2
0
        public int HarvestContents(StardewValley.Farmer player)
        {
            int numItemsHarvested = 0;

            try
            {
                //Harvest items into inventory
                foreach (var container in _buildingInfo.ReadyToHarvestContainers)
                {
                    //Get the item stored in the container
                    StardewValley.Item item = null;
                    if (container.name.Equals("Crystalarium"))
                    {
                        item = (StardewValley.Item)container.heldObject.Value.getOne();
                        if (TryAddItemToPlayerInventory(player, item, container))
                        {
                            numItemsHarvested++;
                        }
                    }
                    else if (container.name.Equals("Auto-Grabber"))
                    {
                        var chest = container.heldObject.Value as Chest;
                        //Netcode.NetObjectList<Item> chestItems = new Netcode.NetObjectList<Item>();
                        //chestItems.AddRange(chest.items.ToList());

                        foreach (var chestItem in chest.items.ToList())
                        {
                            if (chestItem != null)
                            {
                                //Get stack size and add that to number of items harvested.
                                if (TryAddItemToPlayerInventory(player, chestItem, container))
                                {
                                    numItemsHarvested += chestItem.Stack;
                                }
                            }
                        }
                    }
                    else
                    {
                        item = (StardewValley.Item)container.heldObject.Value;
                        if (TryAddItemToPlayerInventory(player, item, container))
                        {
                            numItemsHarvested++;
                        }
                    }
                }
            }
            catch (InventoryFullException ex)
            {
                ex.NumItemsHarvestedBeforeFull = numItemsHarvested;
                throw ex;
            }

            return(numItemsHarvested);
        }
コード例 #3
0
        internal ItemEatenEventArgs ItemEatenEvent(Farmer who, StardewValley.Item item)
        {
            var args = new ItemEatenEventArgs
            {
                Farmer = who,
                Item   = item
            };

            ItemEaten?.Invoke(this, args);
            return(args);
        }
コード例 #4
0
 /// <summary>
 /// A copy of the Utlity.cs code for highlightSmallObjects, but with rings included
 /// </summary>
 /// <param name="item">The Stardew Valley item</param>
 /// <returns>True if the item should be draggable, false otherwise</returns>
 private static bool HighlightBundleCompatibleItems(SVItem item)
 {
     if (item is Ring)
     {
         return(true);
     }
     else if (item is SVObject)
     {
         return(!(bool)((NetFieldBase <bool, NetBool>)(item as SVObject).bigCraftable));
     }
     return(false);
 }
コード例 #5
0
        private static bool Prefix(StardewValley.Item __instance, ref bool __result, ISalable other)
        {
            if (Constants.TargetPlatform == GamePlatform.Android)
            {
                return(false);
            }
            if (__instance is SObject obj1 && other is SObject obj2)
            {
                __result = obj1.preservedParentSheetIndex.Value == obj2.preservedParentSheetIndex.Value;
                return(false);
            }

            return(true);
        }
コード例 #6
0
        public static void IClickableMenu_DrawHoverText_Prefix(
            ref string[] buffIconsToDisplay,
            StardewValley.Item hoveredItem)
        {
            if (!Utils.IsItemFoodAndNotYetEaten(hoveredItem))
            {
                return;
            }

            string[] dummyBuffIcons = new string[AssetManager.DummyIndexForHidingBuffs + 1];
            for (int i = 0; i < dummyBuffIcons.Length; ++i)
            {
                dummyBuffIcons[i] = "0";
            }
            dummyBuffIcons[AssetManager.DummyIndexForHidingBuffs] = "1";
            buffIconsToDisplay = dummyBuffIcons;
            AssetManager.IsCurrentHoveredItemHidingBuffs = true;
        }
コード例 #7
0
ファイル: Mod.cs プロジェクト: ceruleandeep/SDV-bwdyworks
 private void GameLoop_UpdateTicked(object sender, UpdateTickedEventArgs e)
 {
     tickUpdateLimiter++;
     if (tickUpdateLimiter < 10)
     {
         return;
     }
     tickUpdateLimiter = 0;
     if (Game1.player == null)
     {
         return;
     }
     if (EatingPrimed)
     {
         if (!Game1.player.isEating)
         {
             EatingPrimed = false;
             //make sure we didn't say no
             if (Game1.player.ActiveObject == null || Game1.player.ActiveObject.Stack < eatingQuantity)
             {
                 Modworks.Events.ItemEatenEvent(Game1.player, EatingItem);
             }
             EatingItem = null;
         }
     }
     else if (Game1.player.isEating)
     {
         EatingPrimed = true;
         if (Game1.player.itemToEat == null)
         {
             return;
         }
         EatingItem = Game1.player.itemToEat;
         if (Game1.player.ActiveObject == null)
         {
             return;
         }
         eatingQuantity = Game1.player.ActiveObject.Stack;
     }
 }
コード例 #8
0
ファイル: ModEntry.cs プロジェクト: somnomania/smapi-mod-dump
        /// <summary>
        /// Fixes the item name that you get at the start of the game
        /// </summary>
        public void FixParsnipSeedBox()
        {
            GameLocation farmHouse = Game1.locations.Where(x => x.Name == "FarmHouse").First();

            List <StardewValley.Objects.Chest> chestsInRoom =
                farmHouse.Objects.Values.Where(x =>
                                               x.DisplayName == "Chest")
                .Cast <StardewValley.Objects.Chest>()
                .Where(x => x.giftbox.Value)
                .ToList();

            if (chestsInRoom.Count > 0)
            {
                string             parsnipSeedsName = ItemList.GetItemName((int)ObjectIndexes.ParsnipSeeds);
                StardewValley.Item itemInChest      = chestsInRoom[0].items[0];
                if (itemInChest.Name == "Parsnip Seeds")
                {
                    itemInChest.Name        = parsnipSeedsName;
                    itemInChest.DisplayName = parsnipSeedsName;
                }
            }
        }
コード例 #9
0
 public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1)
 {
     this.index     = -1;
     this.inventory = false;
     inList         = new List <Item>();
     this.checkIfBuilding();
     base.draw(spriteBatch, x, y, alpha);
     if (this.objectID == -1 && this.linkedJunimo == null)
     {
         Vector2 vector2 = this.getScale() * (float)Game1.pixelZoom;
         Vector2 local   = Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), (float)(y * Game1.tileSize - Game1.tileSize)));
         Microsoft.Xna.Framework.Rectangle destinationRectangle = new Microsoft.Xna.Framework.Rectangle((int)((double)local.X - (double)vector2.X / 2.0) + (this.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0), (int)((double)local.Y - (double)vector2.Y / 2.0) + (this.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0), (int)((double)Game1.tileSize + (double)vector2.X), (int)((double)(Game1.tileSize * 2) + (double)vector2.Y / 2.0));
         spriteBatch.Draw(Game1.bigCraftableSpriteSheet, destinationRectangle, new Microsoft.Xna.Framework.Rectangle?(StardewValley.Object.getSourceRectForBigCraftable(this.showNextIndex ? this.ParentSheetIndex + 1 : LoadData.craftables[3] + 68 + this.frame)), Color.White * alpha, 0.0f, Vector2.Zero, SpriteEffects.None, (float)((double)Math.Max(0.0f, (float)((y + 1) * Game1.tileSize - Game1.pixelZoom * 6) / 10000f) + (this.parentSheetIndex == 105 ? 0.00350000010803342 : 0.0) + (double)x * 9.99999974737875E-06));
     }
     if (!this.isEmpty())
     {
         Vector2            vector2 = this.getScale() * (float)Game1.pixelZoom;
         Vector2            local   = Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), (float)(y * Game1.tileSize - Game1.tileSize)));
         StardewValley.Item item    = this.items[0];
         Microsoft.Xna.Framework.Rectangle itemDestinationRectangle = new Microsoft.Xna.Framework.Rectangle((int)((double)local.X - (double)vector2.X / 2.0) + (this.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0), (int)((double)local.Y - (double)vector2.Y / 2.0) + (this.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0), (int)((double)Game1.tileSize + (double)vector2.X), (int)((double)(Game1.tileSize) + (double)vector2.Y / 2.0));
         spriteBatch.Draw(Game1.objectSpriteSheet, itemDestinationRectangle, new Microsoft.Xna.Framework.Rectangle?(Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, item.parentSheetIndex, 16, 16)), Color.White * 0.8f, 0.0f, Vector2.Zero, SpriteEffects.None, (float)((double)Math.Max(0.0f, (float)((y + 1) * Game1.tileSize - Game1.pixelZoom * 6) / 10000f) + (this.parentSheetIndex == 105 ? 0.00350000010803342 : 0.0) + (double)x * 9.99999974737875E-06));
     }
 }
コード例 #10
0
        public static ValMap ToMap(StardewValley.Item item)
        {
            if (item == null)
            {
                return(null);
            }
            var result = new ValMap();

            result.map[_type] = new ValString(item.GetType().Name);
            // ToDo: limit the following to ones that really apply for this type.
            result.map[_name]     = new ValString(item.Name);
            result["displayName"] = new ValString(item.DisplayName);
            result["stack"]       = new ValNumber(item.Stack);
            result["maxStack"]    = new ValNumber(item.maximumStackSize());
            result["category"]    = new ValString(item.getCategoryName());
            result["value"]       = new ValNumber(item.salePrice());
            result["description"] = new ValString(item.getDescription().Trim());
            if (item is StardewValley.Tools.WateringCan can)
            {
                result["waterLeft"] = new ValNumber(can.WaterLeft);
                result["waterMax"]  = new ValNumber(can.waterCanMax);
            }
            return(result);
        }
コード例 #11
0
        public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1)
        {
            this.tileLocation.X = x;
            this.tileLocation.Y = y;


            this.nearPlayer = false;

            if (this.location == Game1.currentLocation && Math.Abs(x - Game1.player.getTileLocation().X) <= 2 && Math.Abs(y - Game1.player.getTileLocation().Y) <= 2)
            {
                this.nearPlayer = true;
            }



            int shift           = 0;
            int mainoffsetTiles = this.mainoffset;

            if (Game1.isDarkOut() || this.stop == true)
            {
                shift = 8; mainoffsetTiles = 0; this.stop = true;
            }


            int offsetTiles = this.offset;

            if (this.emote > 0)
            {
                offsetTiles = 56 + 4 * (this.emote - 1);
            }



            Vector2 vector2 = this.getScale() * (float)Game1.pixelZoom;
            Vector2 local   = Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), (float)(y * Game1.tileSize - Game1.tileSize)));

            if (this.onTracks)
            {
                local = local + this.runFrame;
                if (this.direction < 2)
                {
                    local = new Vector2(local.X, local.Y - 16f);
                }
            }
            Microsoft.Xna.Framework.Rectangle destinationRectangle = new Microsoft.Xna.Framework.Rectangle((int)((double)local.X - (double)vector2.X / 2.0) + (this.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0), (int)((double)local.Y - (double)vector2.Y / 2.0) + (this.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0), (int)((double)Game1.tileSize + (double)vector2.X), (int)((double)(Game1.tileSize * 2) + (double)vector2.Y / 2.0));


            if (this.emote != 3)
            {
                spriteBatch.Draw(Game1.bigCraftableSpriteSheet, destinationRectangle, new Microsoft.Xna.Framework.Rectangle?(StardewValley.Object.getSourceRectForBigCraftable(this.showNextIndex ? this.ParentSheetIndex + 1 : this.ParentSheetIndex + this.frame + mainoffsetTiles + shift)), this.color * alpha, 0.0f, Vector2.Zero, SpriteEffects.None, (float)((double)Math.Max(0.0f, (float)((y + 1) * Game1.tileSize - Game1.pixelZoom * 6) / 10000f) + (this.parentSheetIndex == 105 ? 0.00350000010803342 : 0.0) + (double)x * 9.99999974737875E-06));
            }
            if ((shift == 0 || this.emote > 0) && nearPlayer && (!this.onTracks || this.emote == 3))
            {
                if (this.emote == 0)
                {
                    alpha = 0.5f;
                }
                if (this.emote == 3)
                {
                    spriteBatch.Draw(Game1.bigCraftableSpriteSheet, destinationRectangle, new Microsoft.Xna.Framework.Rectangle?(StardewValley.Object.getSourceRectForBigCraftable(this.showNextIndex ? this.ParentSheetIndex + 1 : this.ParentSheetIndex + offsetTiles + this.frame)), this.color * alpha, 0.0f, Vector2.Zero, SpriteEffects.None, (float)((double)Math.Max(0.0f, (float)((y + 1) * Game1.tileSize - Game1.pixelZoom * 6) / 10000f) + (this.parentSheetIndex == 105 ? 0.00350000010803342 : 0.0) + (double)x * 9.99999974737875E-06));
                }
                else
                {
                    spriteBatch.Draw(Game1.bigCraftableSpriteSheet, destinationRectangle, new Microsoft.Xna.Framework.Rectangle?(StardewValley.Object.getSourceRectForBigCraftable(this.showNextIndex ? this.ParentSheetIndex + 1 : this.ParentSheetIndex + offsetTiles + this.frame)), Color.White * alpha, 0.0f, Vector2.Zero, SpriteEffects.None, (float)((double)Math.Max(0.0f, (float)((y + 1) * Game1.tileSize - Game1.pixelZoom * 6) / 10000f) + (this.parentSheetIndex == 105 ? 0.00350000010803342 : 0.0) + (double)x * 9.99999974737875E-06));
                }
            }

            if (!this.itemChest.isEmpty())
            {
                StardewValley.Item item = this.itemChest.items[0];
                Microsoft.Xna.Framework.Rectangle itemDestinationRectangle = new Microsoft.Xna.Framework.Rectangle((int)((double)local.X - (double)vector2.X / 2.0) + (this.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0), (int)((double)local.Y - (double)vector2.Y / 2.0) + (this.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0), (int)((double)Game1.tileSize + (double)vector2.X), (int)((double)(Game1.tileSize) + (double)vector2.Y / 2.0));
                spriteBatch.Draw(Game1.objectSpriteSheet, itemDestinationRectangle, new Microsoft.Xna.Framework.Rectangle?(Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, item.parentSheetIndex, 16, 16)), Color.White * 1f, 0.0f, Vector2.Zero, SpriteEffects.None, (float)((double)Math.Max(0.0f, (float)((y + 1) * Game1.tileSize - Game1.pixelZoom * 6) / 10000f) + (this.parentSheetIndex == 105 ? 0.00350000010803342 : 0.0) + (double)x * 9.99999974737875E-06));
            }
            this.checkIfBuilding();
        }
コード例 #12
0
        /// <summary>
        /// The new method that replaces Stardew Valley's Bundle.cs's tryToDepositThisItem with this file's NewTryToDepositItem
        /// </summary>
        /// <param name="item">The item you are trying to deposit</param>
        /// <param name="slot">The slot you're trying to deposit to</param>
        /// <param name="noteTextureName">Unsure what this is</param>
        /// <returns>What item the player should get back after trying to depositing</returns>
        public SVItem NewTryToDepositItem(SVItem item, ClickableTextureComponent slot, string noteTextureName)
        {
            SVBundle bundle =
                Globals.ModRef.Helper.Reflection
                .GetField <SVBundle>(_currentActiveBundleMenu, "currentPageBundle", true)
                .GetValue();

            if (!bundle.depositsAllowed)
            {
                if (Game1.player.hasCompletedCommunityCenter())
                {
                    Game1.showRedMessage(Game1.content.LoadString("Strings\\UI:JunimoNote_MustBeAtAJM"));
                }
                else
                {
                    Game1.showRedMessage(Game1.content.LoadString("Strings\\UI:JunimoNote_MustBeAtCC"));
                }
                return(item);
            }

            bool isRing = item is Ring;

            if (!(item is SVObject || isRing) || item is Furniture)
            {
                return(item);
            }
            SVObject @object       = item as SVObject;
            bool     ringDeposited = false;

            for (int index = 0; index < bundle.ingredients.Count; ++index)
            {
                if (!bundle.ingredients[index].completed &&
                    bundle.ingredients[index].index == (int)((NetFieldBase <int, NetInt>)item.parentSheetIndex) &&
                    (
                        item.Stack >= bundle.ingredients[index].stack &&
                        (isRing || (int)((NetFieldBase <int, NetInt>)@object.quality) >= bundle.ingredients[index].quality)
                    ) &&
                    slot.item == null)
                {
                    if (isRing)
                    {
                        ringDeposited = true;
                    }
                    item.Stack -= bundle.ingredients[index].stack;
                    bundle.ingredients[index] = new BundleIngredientDescription(bundle.ingredients[index].index, bundle.ingredients[index].stack, bundle.ingredients[index].quality, true);
                    bundle.ingredientDepositAnimation(slot, noteTextureName, false);
                    slot.item = new SVObject(bundle.ingredients[index].index, bundle.ingredients[index].stack, false, -1, bundle.ingredients[index].quality);
                    Game1.playSound("newArtifact");
                    (Game1.getLocationFromName("CommunityCenter") as CommunityCenter).bundles.FieldDict[bundle.bundleIndex][index] = true;
                    slot.sourceRect.X = 512;
                    slot.sourceRect.Y = 244;

                    Multiplayer multiplayer = Globals.ModRef.Helper.Reflection
                                              .GetField <Multiplayer>(typeof(Game1), "multiplayer", true)
                                              .GetValue();
                    multiplayer.globalChatInfoMessage("BundleDonate", Game1.player.displayName, slot.item.DisplayName);
                }
            }
            if (!ringDeposited && item.Stack > 0)
            {
                return(item);
            }
            return(null);
        }
コード例 #13
0
 public static bool IsItemFoodAndNotYetEaten(StardewValley.Item item)
 {
     return(item is StardewValley.Object o && o is not null &&
            !o.bigCraftable.Value && o.Category == ModEntry.CookingCategory &&
            !ModEntry.Instance.States.Value.FoodsEaten.Contains(o.Name));
 }
コード例 #14
0
ファイル: ModEntry.cs プロジェクト: heyseth/SDVMods
        private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
        {
            if (!Context.IsWorldReady)
            {
                return;
            }

            // Handle drawing umbrella
            if (lastItem != Game1.player.CurrentItem) // Selected item has changed
            {
                if (Game1.player.CurrentItem is object)
                {
                    if (umbrellaNames.Contains(Game1.player.CurrentItem.Name))
                    {
                        drawUmbrella               = true;
                        drawRegularFarmer          = false;
                        justDrewFarmer             = false;
                        umbrellaTexture            = umbrellaPlayerTextures[umbrellaNames.IndexOf(Game1.player.CurrentItem.Name)];
                        umbrellaOverlayTextureBack = umbrellaTextureBack[umbrellaNames.IndexOf(Game1.player.CurrentItem.Name)];
                        umbrellaOverlayTextureSide = umbrellaTextureSide[umbrellaNames.IndexOf(Game1.player.CurrentItem.Name)];
                        redrawFarmer();
                    }
                    else if (!justDrewFarmer)
                    {
                        drawRegularFarmer = true;
                        drawUmbrella      = false;
                        redrawFarmer();
                        justDrewFarmer = true;
                    }
                }
                else if (!justDrewFarmer)
                {
                    drawRegularFarmer = true;
                    drawUmbrella      = false;
                    redrawFarmer();
                    justDrewFarmer = true;
                }
            }

            // Handle wetness buff
            if (Game1.currentLocation.IsOutdoors & Game1.IsRainingHere(Game1.player.currentLocation) & Game1.player.currentLocation.Name != "Desert")
            {
                if (Game1.player.CurrentItem is object)
                {
                    if (!umbrellaNames.Contains(Game1.player.CurrentItem.Name))
                    {
                        ticksInRain += 1;
                        if (Game1.buffsDisplay.otherBuffs.FindIndex(p => p.which == wetBuffIndex) != -1)
                        {
                            Game1.buffsDisplay.otherBuffs.FirstOrDefault(p => p.which == wetBuffIndex).millisecondsDuration = 10000;
                        }
                    }
                    else
                    {
                        ticksInRain = 0;
                    }
                }
                else
                {
                    ticksInRain += 1;
                    if (Game1.buffsDisplay.otherBuffs.FindIndex(p => p.which == wetBuffIndex) != -1)
                    {
                        Game1.buffsDisplay.otherBuffs.FirstOrDefault(p => p.which == wetBuffIndex).millisecondsDuration = 10000;
                    }
                }
                if (ticksInRain > 120 & Game1.buffsDisplay.otherBuffs.FindIndex(p => p.which == wetBuffIndex) == -1 & Config.enableWetness)
                {
                    addWetBuff();
                }
            }
            else
            {
                ticksInRain = 0;
            }

            // Handle stamina drain
            if (Game1.buffsDisplay.otherBuffs.FindIndex(p => p.which == wetBuffIndex) != -1 & Context.IsPlayerFree)
            {
                if (Game1.player.Stamina - staminaDrainRatePerTick > 1)
                {
                    staminaDrainShield = 0f;
                    if (Game1.player.hat.Value is object)
                    {
                        if (customBestHats.Contains(Game1.player.hat.Value.Name))
                        {
                            staminaDrainShield += 0.9f;
                        }
                        else if (customGoodHats.Contains(Game1.player.hat.Value.Name))
                        {
                            staminaDrainShield += 0.5f;
                        }
                        else if (bestHats.Contains(Game1.player.hat.Value.which.Value))
                        {
                            staminaDrainShield += 0.9f;
                        }
                        else if (goodHats.Contains(Game1.player.hat.Value.which.Value))
                        {
                            staminaDrainShield += 0.5f;
                        }
                    }
                    if (Game1.player.shirtItem.Value is object)
                    {
                        if (Game1.player.shirtItem.Value.Name == "Rain Coat")
                        {
                            staminaDrainShield += 0.2f;
                        }
                    }
                    if (staminaDrainShield > 1)
                    {
                        staminaDrainShield = 1;
                    }
                    Game1.player.Stamina -= staminaDrainRatePerTick * (1 - staminaDrainShield);
                }
            }

            lastItem = Game1.player.CurrentItem;
        }