// Copied from LibraryMuseum.cs
        //
        // Adds support for item swap
        public static bool IsTileSuitableForMuseumPiece(int x, int y)
        {
            LibraryMuseum museum = Game1.currentLocation as LibraryMuseum;

            // Allow item to be placed at spot with another item
            if (museum.museumPieces.ContainsKey(new Vector2((float)x, (float)y)))
            {
                return(true);
            }

            // Allow item to be placed at empty spots
            switch (museum.getTileIndexAt(new Point(x, y), "Buildings"))
            {
            case 1072:
            case 1073:
            case 1074:
            case 1237:
            case 1238:
                return(true);

            default:
                // Prevent items from being placed outside the designated area
                return(false);
            }
        }
Beispiel #2
0
        /// <summary>Get the custom fields indicating what an item is needed for.</summary>
        /// <param name="obj">The machine whose output to represent.</param>
        /// <param name="metadata">Provides metadata that's not available from the game data directly.</param>
        private IEnumerable <ICustomField> GetNeededForFields(SObject obj, Metadata metadata)
        {
            if (obj == null)
            {
                yield break;
            }

            List <string> neededFor = new List <string>();

            // bundles
            {
                string[] bundles = (
                    from bundle in this.GetUnfinishedBundles(obj)
                    orderby bundle.Area, bundle.DisplayName
                    let countNeeded = this.GetIngredientCountNeeded(bundle, obj)
                                      select countNeeded > 1
                        ? $"{this.GetTranslatedBundleArea(bundle)}: {bundle.DisplayName} x {countNeeded}"
                        : $"{this.GetTranslatedBundleArea(bundle)}: {bundle.DisplayName}"
                    ).ToArray();
                if (bundles.Any())
                {
                    neededFor.Add(this.Translate(L10n.Item.NeededForCommunityCenter, new { bundles = string.Join(", ", bundles) }));
                }
            }

            // polyculture achievement
            if (metadata.Constants.PolycultureCrops.Contains(obj.ParentSheetIndex))
            {
                int needed = metadata.Constants.PolycultureCount - this.GameHelper.GetShipped(obj.ParentSheetIndex);
                if (needed > 0)
                {
                    neededFor.Add(this.Translate(L10n.Item.NeededForPolyculture, new { count = needed }));
                }
            }

            // full shipment achievement
            if (this.GameHelper.GetFullShipmentAchievementItems().Any(p => p.Key == obj.ParentSheetIndex && !p.Value))
            {
                neededFor.Add(this.Translate(L10n.Item.NeededForFullShipment));
            }

            // a full collection achievement
            LibraryMuseum museum = Game1.locations.OfType <LibraryMuseum>().FirstOrDefault();

            if (museum != null && museum.isItemSuitableForDonation(obj))
            {
                neededFor.Add(this.Translate(L10n.Item.NeededForFullCollection));
            }

            // yield
            if (neededFor.Any())
            {
                yield return(new GenericField(this.GameHelper, this.Translate(L10n.Item.NeededFor), string.Join(", ", neededFor)));
            }
        }
        private void process()
        {
            LibraryMuseum museum = Game1.getLocationFromName(name) as LibraryMuseum;

            if (museum == null)
            {
                return;
            }

            museum.museumPieces = Util.deserialize <SerializableDictionary <Vector2, int> >(artifacts);
            Multiplayer.locations[name].updateMuseumCache();
            message();
        }
        public void ToggleOption(bool showItemHoverInformation)
        {
            _helper.Events.Player.InventoryChanged -= OnInventoryChanged;
            _helper.Events.Display.Rendered        -= OnRendered;
            _helper.Events.Display.RenderedHud     -= OnRenderedHud;
            _helper.Events.Display.Rendering       -= OnRendering;

            if (showItemHoverInformation)
            {
                _communityCenter = Game1.getLocationFromName("CommunityCenter") as CommunityCenter;
                _bundleData      = Game1.netWorldState.Value.BundleData;
                PopulateRequiredBundles();

                _libraryMuseum = Game1.getLocationFromName("ArchaeologyHouse") as LibraryMuseum;

                _helper.Events.Player.InventoryChanged += OnInventoryChanged;
                _helper.Events.Display.Rendered        += OnRendered;
                _helper.Events.Display.RenderedHud     += OnRenderedHud;
                _helper.Events.Display.Rendering       += OnRendering;
            }
        }
        public void ToggleOption(bool showItemHoverInformation)
        {
            _events.Player.InventoryChanged -= OnInventoryChanged;
            _events.Display.Rendered        -= OnRendered;
            _events.Display.RenderedHud     -= OnRenderedHud;
            _events.Display.Rendering       -= OnRendering;

            if (showItemHoverInformation)
            {
                _communityCenter = Game1.getLocationFromName("CommunityCenter") as CommunityCenter;
                _bundleData      = Game1.content.Load <Dictionary <String, String> >("Data\\Bundles");
                PopulateRequiredBundles();

                _libraryMuseum = Game1.getLocationFromName("ArchaeologyHouse") as LibraryMuseum;

                _events.Player.InventoryChanged += OnInventoryChanged;
                _events.Display.Rendered        += OnRendered;
                _events.Display.RenderedHud     += OnRenderedHud;
                _events.Display.Rendering       += OnRendering;
            }
        }
Beispiel #6
0
        /// <summary>Get the data to display for this subject.</summary>
        /// <param name="metadata">Provides metadata that's not available from the game data directly.</param>
        public override IEnumerable <ICustomField> GetData(Metadata metadata)
        {
            // get data
            Item    item       = this.Target;
            SObject obj        = item as SObject;
            bool    isObject   = obj != null;
            bool    isCrop     = this.FromCrop != null;
            bool    isSeed     = this.SeedForCrop != null;
            bool    isDeadCrop = this.FromCrop?.dead.Value == true;
            bool    canSell    = obj?.canBeShipped() == true || metadata.Shops.Any(shop => shop.BuysCategories.Contains(item.Category));

            // get overrides
            bool showInventoryFields = true;

            {
                ObjectData objData = metadata.GetObject(item, this.Context);
                if (objData != null)
                {
                    this.Name = objData.NameKey != null?this.Translate(objData.NameKey) : this.Name;

                    this.Description = objData.DescriptionKey != null?this.Translate(objData.DescriptionKey) : this.Description;

                    this.Type = objData.TypeKey != null?this.Translate(objData.TypeKey) : this.Type;

                    showInventoryFields = objData.ShowInventoryFields ?? true;
                }
            }

            // don't show data for dead crop
            if (isDeadCrop)
            {
                yield return(new GenericField(this.Translate(L10n.Crop.Summary), this.Translate(L10n.Crop.SummaryDead)));

                yield break;
            }

            // crop fields
            if (isCrop || isSeed)
            {
                // get crop
                Crop crop = this.FromCrop ?? this.SeedForCrop;

                // get harvest schedule
                int  harvestablePhase   = crop.phaseDays.Count - 1;
                bool canHarvestNow      = (crop.currentPhase.Value >= harvestablePhase) && (!crop.fullyGrown.Value || crop.dayOfCurrentPhase.Value <= 0);
                int  daysToFirstHarvest = crop.phaseDays.Take(crop.phaseDays.Count - 1).Sum(); // ignore harvestable phase

                // add next-harvest field
                if (isCrop)
                {
                    // calculate next harvest
                    int   daysToNextHarvest = 0;
                    SDate dayOfNextHarvest  = null;
                    if (!canHarvestNow)
                    {
                        // calculate days until next harvest
                        int daysUntilLastPhase = daysToFirstHarvest - crop.dayOfCurrentPhase.Value - crop.phaseDays.Take(crop.currentPhase.Value).Sum();
                        {
                            // growing: days until next harvest
                            if (!crop.fullyGrown.Value)
                            {
                                daysToNextHarvest = daysUntilLastPhase;
                            }

                            // regrowable crop harvested today
                            else if (crop.dayOfCurrentPhase.Value >= crop.regrowAfterHarvest.Value)
                            {
                                daysToNextHarvest = crop.regrowAfterHarvest.Value;
                            }

                            // regrowable crop
                            else
                            {
                                daysToNextHarvest = crop.dayOfCurrentPhase.Value; // dayOfCurrentPhase decreases to 0 when fully grown, where <=0 is harvestable
                            }
                        }
                        dayOfNextHarvest = SDate.Now().AddDays(daysToNextHarvest);
                    }

                    // generate field
                    string summary;
                    if (canHarvestNow)
                    {
                        summary = this.Translate(L10n.Crop.HarvestNow);
                    }
                    else if (Game1.currentLocation.Name != Constant.LocationNames.Greenhouse && !crop.seasonsToGrowIn.Contains(dayOfNextHarvest.Season))
                    {
                        summary = this.Translate(L10n.Crop.HarvestTooLate, new { date = this.Stringify(dayOfNextHarvest) });
                    }
                    else
                    {
                        summary = $"{this.Stringify(dayOfNextHarvest)} ({this.Text.GetPlural(daysToNextHarvest, L10n.Generic.Tomorrow, L10n.Generic.InXDays).Tokens(new { count = daysToNextHarvest })})";
                    }

                    yield return(new GenericField(this.Translate(L10n.Crop.Harvest), summary));
                }

                // crop summary
                {
                    List <string> summary = new List <string>();

                    // harvest
                    summary.Add(crop.regrowAfterHarvest.Value == -1
                        ? this.Translate(L10n.Crop.SummaryHarvestOnce, new { daysToFirstHarvest = daysToFirstHarvest })
                        : this.Translate(L10n.Crop.SummaryHarvestMulti, new { daysToFirstHarvest = daysToFirstHarvest, daysToNextHarvests = crop.regrowAfterHarvest })
                                );

                    // seasons
                    summary.Add(this.Translate(L10n.Crop.SummarySeasons, new { seasons = string.Join(", ", this.Text.GetSeasonNames(crop.seasonsToGrowIn)) }));

                    // drops
                    if (crop.minHarvest != crop.maxHarvest && crop.chanceForExtraCrops.Value > 0)
                    {
                        summary.Add(this.Translate(L10n.Crop.SummaryDropsXToY, new { min = crop.minHarvest, max = crop.maxHarvest, percent = Math.Round(crop.chanceForExtraCrops.Value * 100, 2) }));
                    }
                    else if (crop.minHarvest.Value > 1)
                    {
                        summary.Add(this.Translate(L10n.Crop.SummaryDropsX, new { count = crop.minHarvest }));
                    }

                    // crop sale price
                    Item drop = GameHelper.GetObjectBySpriteIndex(crop.indexOfHarvest.Value);
                    summary.Add(this.Translate(L10n.Crop.SummarySellsFor, new { price = GenericField.GetSaleValueString(this.GetSaleValue(drop, false, metadata), 1, this.Text) }));

                    // generate field
                    yield return(new GenericField(this.Translate(L10n.Crop.Summary), "-" + string.Join($"{Environment.NewLine}-", summary)));
                }
            }

            // crafting
            if (obj?.heldObject?.Value != null)
            {
                if (obj is Cask cask)
                {
                    // get cask data
                    SObject     agingObj       = cask.heldObject.Value;
                    ItemQuality curQuality     = (ItemQuality)agingObj.Quality;
                    string      curQualityName = this.Translate(L10n.For(curQuality));

                    // calculate aging schedule
                    float effectiveAge = metadata.Constants.CaskAgeSchedule.Values.Max() - cask.daysToMature.Value;
                    var   schedule     =
                        (
                            from entry in metadata.Constants.CaskAgeSchedule
                            let quality = entry.Key
                                          let baseDays = entry.Value
                                                         where baseDays > effectiveAge
                                                         orderby baseDays ascending
                                                         let daysLeft = (int)Math.Ceiling((baseDays - effectiveAge) / cask.agingRate.Value)
                                                                        select new
                    {
                        Quality = quality,
                        DaysLeft = daysLeft,
                        HarvestDate = SDate.Now().AddDays(daysLeft)
                    }
                        )
                        .ToArray();

                    // display fields
                    yield return(new ItemIconField(this.Translate(L10n.Item.Contents), obj.heldObject.Value));

                    if (cask.MinutesUntilReady <= 0 || !schedule.Any())
                    {
                        yield return(new GenericField(this.Translate(L10n.Item.CaskSchedule), this.Translate(L10n.Item.CaskScheduleNow, new { quality = curQualityName })));
                    }
                    else
                    {
                        string scheduleStr = string.Join(Environment.NewLine, (
                                                             from entry in schedule
                                                             let tokens = new { quality = this.Translate(L10n.For(entry.Quality)), count = entry.DaysLeft, date = entry.HarvestDate }
                                                             let str = this.Text.GetPlural(entry.DaysLeft, L10n.Item.CaskScheduleTomorrow, L10n.Item.CaskScheduleInXDays).Tokens(tokens)
                                                                       select $"-{str}"
                                                             ));
                        yield return(new GenericField(this.Translate(L10n.Item.CaskSchedule), this.Translate(L10n.Item.CaskSchedulePartial, new { quality = curQualityName }) + Environment.NewLine + scheduleStr));
                    }
                }
                else if (obj is Furniture)
                {
                    string summary = this.Translate(L10n.Item.ContentsPlaced, new { name = obj.heldObject.Value.DisplayName });
                    yield return(new ItemIconField(this.Translate(L10n.Item.Contents), obj.heldObject.Value, summary));
                }
                else
                {
                    string summary = obj.MinutesUntilReady <= 0
                        ? this.Translate(L10n.Item.ContentsReady, new { name = obj.heldObject.Value.DisplayName })
                        : this.Translate(L10n.Item.ContentsPartial, new { name = obj.heldObject.Value.DisplayName, time = this.Stringify(TimeSpan.FromMinutes(obj.MinutesUntilReady)) });
                    yield return(new ItemIconField(this.Translate(L10n.Item.Contents), obj.heldObject.Value, summary));
                }
            }

            // item
            if (showInventoryFields)
            {
                // needed for
                {
                    List <string> neededFor = new List <string>();

                    // bundles
                    if (isObject)
                    {
                        string[] bundles = (from bundle in this.GetUnfinishedBundles(obj) orderby bundle.Area, bundle.DisplayName select $"{this.GetTranslatedBundleArea(bundle)}: {bundle.DisplayName}").ToArray();
                        if (bundles.Any())
                        {
                            neededFor.Add(this.Translate(L10n.Item.NeededForCommunityCenter, new { bundles = string.Join(", ", bundles) }));
                        }
                    }

                    // polyculture achievement
                    if (isObject && metadata.Constants.PolycultureCrops.Contains(obj.ParentSheetIndex))
                    {
                        int needed = metadata.Constants.PolycultureCount - GameHelper.GetShipped(obj.ParentSheetIndex);
                        if (needed > 0)
                        {
                            neededFor.Add(this.Translate(L10n.Item.NeededForPolyculture, new { count = needed }));
                        }
                    }

                    // full shipment achievement
                    if (isObject && GameHelper.GetFullShipmentAchievementItems().Any(p => p.Key == obj.ParentSheetIndex && !p.Value))
                    {
                        neededFor.Add(this.Translate(L10n.Item.NeededForFullShipment));
                    }

                    // a full collection achievement
                    LibraryMuseum museum = Game1.locations.OfType <LibraryMuseum>().FirstOrDefault();
                    if (museum != null && museum.isItemSuitableForDonation(obj))
                    {
                        neededFor.Add(this.Translate(L10n.Item.NeededForFullCollection));
                    }

                    // yield
                    if (neededFor.Any())
                    {
                        yield return(new GenericField(this.Translate(L10n.Item.NeededFor), string.Join(", ", neededFor)));
                    }
                }

                // sale data
                if (canSell && !isCrop)
                {
                    // sale price
                    string saleValueSummary = GenericField.GetSaleValueString(this.GetSaleValue(item, this.KnownQuality, metadata), item.Stack, this.Text);
                    yield return(new GenericField(this.Translate(L10n.Item.SellsFor), saleValueSummary));

                    // sell to
                    List <string> buyers = new List <string>();
                    if (obj?.canBeShipped() == true)
                    {
                        buyers.Add(this.Translate(L10n.Item.SellsToShippingBox));
                    }
                    buyers.AddRange(
                        from shop in metadata.Shops
                        where shop.BuysCategories.Contains(item.Category)
                        let name = this.Translate(shop.DisplayKey).ToString()
                                   orderby name
                                   select name
                        );
                    yield return(new GenericField(this.Translate(L10n.Item.SellsTo), string.Join(", ", buyers)));
                }

                // gift tastes
                var giftTastes = this.GetGiftTastes(item, metadata);
                yield return(new ItemGiftTastesField(this.Translate(L10n.Item.LovesThis), giftTastes, GiftTaste.Love));

                yield return(new ItemGiftTastesField(this.Translate(L10n.Item.LikesThis), giftTastes, GiftTaste.Like));
            }

            // fence
            if (item is Fence fence)
            {
                string healthLabel = this.Translate(L10n.Item.FenceHealth);

                // health
                if (Game1.getFarm().isBuildingConstructed(Constant.BuildingNames.GoldClock))
                {
                    yield return(new GenericField(healthLabel, this.Translate(L10n.Item.FenceHealthGoldClock)));
                }
                else
                {
                    float  maxHealth = fence.isGate.Value ? fence.maxHealth.Value * 2 : fence.maxHealth.Value;
                    float  health    = fence.health.Value / maxHealth;
                    double daysLeft  = Math.Round(fence.health.Value * metadata.Constants.FenceDecayRate / 60 / 24);
                    double percent   = Math.Round(health * 100);
                    yield return(new PercentageBarField(healthLabel, (int)fence.health, (int)maxHealth, Color.Green, Color.Red, this.Translate(L10n.Item.FenceHealthSummary, new { percent = percent, count = daysLeft })));
                }
            }

            // recipes
            if (item.GetSpriteType() == ItemSpriteType.Object)
            {
                RecipeModel[] recipes = GameHelper.GetRecipesForIngredient(this.DisplayItem).ToArray();
                if (recipes.Any())
                {
                    yield return(new RecipesForIngredientField(this.Translate(L10n.Item.Recipes), item, recipes, this.Text));
                }
            }

            // owned
            if (showInventoryFields && !isCrop && !(item is Tool))
            {
                yield return(new GenericField(this.Translate(L10n.Item.Owned), this.Translate(L10n.Item.OwnedSummary, new { count = GameHelper.CountOwnedItems(item) })));
            }

            // see also crop
            bool seeAlsoCrop =
                isSeed &&
                item.ParentSheetIndex != this.SeedForCrop.indexOfHarvest.Value && // skip seeds which produce themselves (e.g. coffee beans)
                !(item.ParentSheetIndex >= 495 && item.ParentSheetIndex <= 497) && // skip random seasonal seeds
                item.ParentSheetIndex != 770;    // skip mixed seeds

            if (seeAlsoCrop)
            {
                Item drop = GameHelper.GetObjectBySpriteIndex(this.SeedForCrop.indexOfHarvest.Value);
                yield return(new LinkField(this.Translate(L10n.Item.SeeAlso), drop.DisplayName, () => new ItemSubject(this.Text, drop, ObjectContext.Inventory, false, this.SeedForCrop)));
            }
        }
Beispiel #7
0
 public override void receiveKeyPress(Keys key)
 {
     if (fadeTimer > 0)
     {
         return;
     }
     if (Game1.options.doesInputListContain(Game1.options.menuButton, key) && !Game1.isOneOfTheseKeysDown(Game1.oldKBState, Game1.options.menuButton) && readyToClose())
     {
         state         = 2;
         fadeTimer     = 500;
         fadeIntoBlack = true;
     }
     else if (Game1.options.doesInputListContain(Game1.options.menuButton, key) && !Game1.isOneOfTheseKeysDown(Game1.oldKBState, Game1.options.menuButton) && !holdingMuseumPiece && menuMovingDown)
     {
         if (heldItem != null)
         {
             Game1.playSound("bigDeSelect");
             Utility.CollectOrDrop(heldItem);
             heldItem = null;
         }
         ReturnToDonatableItems();
     }
     else if (Game1.options.SnappyMenus && heldItem == null && !reOrganizing)
     {
         base.receiveKeyPress(key);
     }
     if (!Game1.options.SnappyMenus)
     {
         if (Game1.options.doesInputListContain(Game1.options.moveDownButton, key))
         {
             Game1.panScreen(0, 4);
         }
         else if (Game1.options.doesInputListContain(Game1.options.moveRightButton, key))
         {
             Game1.panScreen(4, 0);
         }
         else if (Game1.options.doesInputListContain(Game1.options.moveUpButton, key))
         {
             Game1.panScreen(0, -4);
         }
         else if (Game1.options.doesInputListContain(Game1.options.moveLeftButton, key))
         {
             Game1.panScreen(-4, 0);
         }
     }
     else
     {
         if (heldItem == null && !reOrganizing)
         {
             return;
         }
         LibraryMuseum museum = Game1.currentLocation as LibraryMuseum;
         Vector2       newCursorPositionTile2 = new Vector2((int)((Utility.ModifyCoordinateFromUIScale(Game1.getMouseX()) + (float)Game1.viewport.X) / 64f), (int)((Utility.ModifyCoordinateFromUIScale(Game1.getMouseY()) + (float)Game1.viewport.Y) / 64f));
         if (!museum.isTileSuitableForMuseumPiece((int)newCursorPositionTile2.X, (int)newCursorPositionTile2.Y) && (!reOrganizing || !museum.museumPieces.ContainsKey(newCursorPositionTile2)))
         {
             newCursorPositionTile2 = museum.getFreeDonationSpot();
             Game1.setMousePosition((int)Utility.ModifyCoordinateForUIScale(newCursorPositionTile2.X * 64f - (float)Game1.viewport.X + 32f), (int)Utility.ModifyCoordinateForUIScale(newCursorPositionTile2.Y * 64f - (float)Game1.viewport.Y + 32f));
             return;
         }
         if (key == Game1.options.getFirstKeyboardKeyFromInputButtonList(Game1.options.moveUpButton))
         {
             newCursorPositionTile2 = museum.findMuseumPieceLocationInDirection(newCursorPositionTile2, 0, 21, !reOrganizing);
         }
         else if (key == Game1.options.getFirstKeyboardKeyFromInputButtonList(Game1.options.moveRightButton))
         {
             newCursorPositionTile2 = museum.findMuseumPieceLocationInDirection(newCursorPositionTile2, 1, 21, !reOrganizing);
         }
         else if (key == Game1.options.getFirstKeyboardKeyFromInputButtonList(Game1.options.moveDownButton))
         {
             newCursorPositionTile2 = museum.findMuseumPieceLocationInDirection(newCursorPositionTile2, 2, 21, !reOrganizing);
         }
         else if (key == Game1.options.getFirstKeyboardKeyFromInputButtonList(Game1.options.moveLeftButton))
         {
             newCursorPositionTile2 = museum.findMuseumPieceLocationInDirection(newCursorPositionTile2, 3, 21, !reOrganizing);
         }
         if (!Game1.viewport.Contains(new Location((int)(newCursorPositionTile2.X * 64f + 32f), Game1.viewport.Y + 1)))
         {
             Game1.panScreen((int)(newCursorPositionTile2.X * 64f - (float)Game1.viewport.X), 0);
         }
         else if (!Game1.viewport.Contains(new Location(Game1.viewport.X + 1, (int)(newCursorPositionTile2.Y * 64f + 32f))))
         {
             Game1.panScreen(0, (int)(newCursorPositionTile2.Y * 64f - (float)Game1.viewport.Y));
         }
         Game1.setMousePosition((int)Utility.ModifyCoordinateForUIScale((int)newCursorPositionTile2.X * 64 - Game1.viewport.X + 32), (int)Utility.ModifyCoordinateForUIScale((int)newCursorPositionTile2.Y * 64 - Game1.viewport.Y + 32));
     }
 }
Beispiel #8
0
        public override void receiveLeftClick(int x, int y, bool playSound = true)
        {
            if (fadeTimer > 0)
            {
                return;
            }
            Item oldItem = heldItem;

            if (!holdingMuseumPiece)
            {
                int inventory_index = inventory.getInventoryPositionOfClick(x, y);
                if (heldItem == null)
                {
                    if (inventory_index >= 0 && inventory_index < inventory.actualInventory.Count && inventory.highlightMethod(inventory.actualInventory[inventory_index]))
                    {
                        heldItem = inventory.actualInventory[inventory_index].getOne();
                        inventory.actualInventory[inventory_index].Stack--;
                        if (inventory.actualInventory[inventory_index].Stack <= 0)
                        {
                            inventory.actualInventory[inventory_index] = null;
                        }
                    }
                }
                else
                {
                    heldItem = inventory.leftClick(x, y, heldItem);
                }
            }
            if (oldItem == null && heldItem != null && Game1.isAnyGamePadButtonBeingPressed())
            {
                receiveGamePadButton(Buttons.DPadUp);
            }
            if (oldItem != null && heldItem != null && (y < Game1.viewport.Height - (height - (IClickableMenu.borderWidth + IClickableMenu.spaceToClearTopBorder + 192)) || menuMovingDown))
            {
                int mapXTile2 = (int)(Utility.ModifyCoordinateFromUIScale(x) + (float)Game1.viewport.X) / 64;
                int mapYTile2 = (int)(Utility.ModifyCoordinateFromUIScale(y) + (float)Game1.viewport.Y) / 64;
                if ((Game1.currentLocation as LibraryMuseum).isTileSuitableForMuseumPiece(mapXTile2, mapYTile2) && (Game1.currentLocation as LibraryMuseum).isItemSuitableForDonation(heldItem))
                {
                    int objectID     = heldItem.parentSheetIndex;
                    int rewardsCount = (Game1.currentLocation as LibraryMuseum).getRewardsForPlayer(Game1.player).Count;
                    (Game1.currentLocation as LibraryMuseum).museumPieces.Add(new Vector2(mapXTile2, mapYTile2), (heldItem as Object).parentSheetIndex);
                    Game1.playSound("stoneStep");
                    if ((Game1.currentLocation as LibraryMuseum).getRewardsForPlayer(Game1.player).Count > rewardsCount && !holdingMuseumPiece)
                    {
                        sparkleText = new SparklingText(Game1.dialogueFont, Game1.content.LoadString("Strings\\StringsFromCSFiles:NewReward"), Color.MediumSpringGreen, Color.White);
                        Game1.playSound("reward");
                        globalLocationOfSparklingArtifact = new Vector2((float)(mapXTile2 * 64 + 32) - sparkleText.textWidth / 2f, mapYTile2 * 64 - 48);
                    }
                    else
                    {
                        Game1.playSound("newArtifact");
                    }
                    Game1.player.completeQuest(24);
                    heldItem.Stack--;
                    if (heldItem.Stack <= 0)
                    {
                        heldItem = null;
                    }
                    int pieces = (Game1.currentLocation as LibraryMuseum).museumPieces.Count();
                    if (!holdingMuseumPiece)
                    {
                        Game1.stats.checkForArchaeologyAchievements();
                        switch (pieces)
                        {
                        case 95:
                            Game1.multiplayer.globalChatInfoMessage("MuseumComplete", Game1.player.farmName);
                            break;

                        case 40:
                            Game1.multiplayer.globalChatInfoMessage("Museum40", Game1.player.farmName);
                            break;

                        default:
                            Game1.multiplayer.globalChatInfoMessage("donation", Game1.player.name, "object:" + objectID);
                            break;
                        }
                    }
                    ReturnToDonatableItems();
                }
            }
            else if (heldItem == null && !inventory.isWithinBounds(x, y))
            {
                int           mapXTile = (int)(Utility.ModifyCoordinateFromUIScale(x) + (float)Game1.viewport.X) / 64;
                int           mapYTile = (int)(Utility.ModifyCoordinateFromUIScale(y) + (float)Game1.viewport.Y) / 64;
                Vector2       v        = new Vector2(mapXTile, mapYTile);
                LibraryMuseum location = Game1.currentLocation as LibraryMuseum;
                if (location.museumPieces.ContainsKey(v))
                {
                    heldItem = new Object(location.museumPieces[v], 1);
                    location.museumPieces.Remove(v);
                    holdingMuseumPiece = !location.museumAlreadyHasArtifact(heldItem.parentSheetIndex);
                }
            }
            if (heldItem != null && oldItem == null)
            {
                menuMovingDown = true;
                reOrganizing   = false;
            }
            if (okButton != null && okButton.containsPoint(x, y) && readyToClose())
            {
                if (fadeTimer <= 0)
                {
                    Game1.playSound("bigDeSelect");
                }
                state         = 2;
                fadeTimer     = 800;
                fadeIntoBlack = true;
            }
        }
Beispiel #9
0
        /// <summary>Get the custom fields indicating what an item is needed for.</summary>
        /// <param name="obj">The machine whose output to represent.</param>
        /// <param name="metadata">Provides metadata that's not available from the game data directly.</param>
        private IEnumerable <ICustomField> GetNeededForFields(SObject obj, Metadata metadata)
        {
            if (obj == null)
            {
                yield break;
            }

            List <string> neededFor = new List <string>();

            // fetch info
            var recipes =
                (
                    from recipe in this.GameHelper.GetRecipesForIngredient(this.DisplayItem)
                    let item = recipe.CreateItem(this.DisplayItem)
                               orderby item.DisplayName
                               select new { recipe.Type, item.DisplayName, TimesCrafted = recipe.GetTimesCrafted(Game1.player) }
                )
                .ToArray();

            // bundles
            {
                string[] missingBundles =
                    (
                        from bundle in this.GetUnfinishedBundles(obj)
                        orderby bundle.Area, bundle.DisplayName
                        let countNeeded = this.GetIngredientCountNeeded(bundle, obj)
                                          select countNeeded > 1
                            ? $"{this.GetTranslatedBundleArea(bundle)}: {bundle.DisplayName} x {countNeeded}"
                            : $"{this.GetTranslatedBundleArea(bundle)}: {bundle.DisplayName}"
                    )
                    .ToArray();
                if (missingBundles.Any())
                {
                    neededFor.Add(L10n.Item.NeededForCommunityCenter(bundles: string.Join(", ", missingBundles)));
                }
            }

            // polyculture achievement (ship 15 crops)
            if (metadata.Constants.PolycultureCrops.Contains(obj.ParentSheetIndex))
            {
                int needed = metadata.Constants.PolycultureCount - this.GameHelper.GetShipped(obj.ParentSheetIndex);
                if (needed > 0)
                {
                    neededFor.Add(L10n.Item.NeededForPolyculture(count: needed));
                }
            }

            // full shipment achievement (ship every item)
            if (this.GameHelper.GetFullShipmentAchievementItems().Any(p => p.Key == obj.ParentSheetIndex && !p.Value))
            {
                neededFor.Add(L10n.Item.NeededForFullShipment());
            }

            // full collection achievement (donate every artifact)
            LibraryMuseum museum = Game1.locations.OfType <LibraryMuseum>().FirstOrDefault();

            if (museum != null && museum.isItemSuitableForDonation(obj))
            {
                neededFor.Add(L10n.Item.NeededForFullCollection());
            }

            // gourmet chef achievement (cook every recipe)
            {
                string[] uncookedNames = (from recipe in recipes where recipe.Type == RecipeType.Cooking && recipe.TimesCrafted <= 0 select recipe.DisplayName).ToArray();
                if (uncookedNames.Any())
                {
                    neededFor.Add(L10n.Item.NeededForGourmetChef(recipes: string.Join(", ", uncookedNames)));
                }
            }

            // craft master achievement (craft every item)
            {
                string[] uncraftedNames = (from recipe in recipes where recipe.Type == RecipeType.Crafting && recipe.TimesCrafted <= 0 select recipe.DisplayName).ToArray();
                if (uncraftedNames.Any())
                {
                    neededFor.Add(L10n.Item.NeededForCraftMaster(recipes: string.Join(", ", uncraftedNames)));
                }
            }

            // yield
            if (neededFor.Any())
            {
                yield return(new GenericField(this.GameHelper, L10n.Item.NeededFor(), string.Join(", ", neededFor)));
            }
        }
        // Added [item swap] support
        public override void receiveLeftClick(int x, int y, bool playSound = true)
        {
            Item heldItem = this.heldItem;

            if (!holdingMuseumPiece)
            {
                this.heldItem = null;
            }

            LibraryMuseum museum = Game1.currentLocation as LibraryMuseum;

            // Place item at a museum slot
            if (heldItem != null && this.heldItem != null &&
                (y < Game1.viewport.Height - (height - (IClickableMenu.borderWidth + IClickableMenu.spaceToClearTopBorder + 192))))
            {
                int x1 = (x + Game1.viewport.X) / 64;
                int y1 = (y + Game1.viewport.Y) / 64;

                // Place item at an empty museum slot
                if (museum.isTileSuitableForMuseumPiece(x1, y1) &&
                    museum.isItemSuitableForDonation(this.heldItem))
                {
                    int parentSheetIndex = this.heldItem.ParentSheetIndex;
                    int count            = museum.getRewardsForPlayer(Game1.player).Count;

                    // Add item to the current position
                    museum.museumPieces.Add(new Vector2((float)x1, (float)y1), (this.heldItem as StardewValley.Object).ParentSheetIndex);


                    Game1.playSound("stoneStep");
                    holdingMuseumPiece = false;

                    // Clear hover information
                    selectedItemDescription = null;
                    selectedItemTitle       = null;
                    selectedItem            = null;

                    // Play item placement sound
                    Game1.playSound("newArtifact");

                    // If the player has no donatable item in his inventory, hide the inventory
                    //if (!museum.doesFarmerHaveAnythingToDonate(Game1.player))
                    //{
                    //    showInventory = false;
                    //}

                    //Game1.player.completeQuest(24);
                    --this.heldItem.Stack;
                    if (this.heldItem.Stack <= 0)
                    {
                        this.heldItem = (Item)null;
                    }

                    //int num = museum.museumPieces.Count();
                    //if (num >= 95)
                    //{
                    //    Game1.getAchievement(5);
                    //}
                    //else if (num >= 40)
                    //{
                    //    Game1.getAchievement(28);
                    //}
                }

                // Place item at an already in-use museum slot and swap it with its current item
                else if (LibraryMuseumHelper.IsTileSuitableForMuseumPiece(x1, y1) &&
                         museum.isItemSuitableForDonation(this.heldItem))
                {
                    Vector2 keySrc  = new Vector2((float)oldX1, (float)oldY1);
                    Vector2 keyDest = new Vector2((float)x1, (float)y1);

                    Item swapItem = null;

                    // Remove current item at museum slot
                    LibraryMuseum currentLocation = Game1.currentLocation as LibraryMuseum;
                    if (currentLocation.museumPieces.ContainsKey(keyDest))
                    {
                        swapItem = (Item) new StardewValley.Object(currentLocation.museumPieces[keyDest], 1, false, -1, 0);
                        currentLocation.museumPieces.Remove(keyDest);
                    }

                    // Place held item at the museum slot
                    currentLocation.museumPieces.Add(keyDest, (this.heldItem as StardewValley.Object).ParentSheetIndex);

                    // Place removed item at the old location of the held item to complete the swap
                    if (swapItem != null)
                    {
                        currentLocation.museumPieces.Add(keySrc, (swapItem as StardewValley.Object).ParentSheetIndex);
                    }

                    Game1.playSound("stoneStep");
                    holdingMuseumPiece = false;

                    // Clear hover information
                    selectedItemDescription = null;
                    selectedItemTitle       = null;
                    selectedItem            = null;

                    Game1.playSound("newArtifact");

                    --this.heldItem.Stack;
                    if (this.heldItem.Stack <= 0)
                    {
                        this.heldItem = (Item)null;
                    }
                }
            }

            // Grab an item which is already located in the museum
            else if (this.heldItem == null)
            {
                Vector2       key             = new Vector2((float)((x + Game1.viewport.X) / 64), (float)((y + Game1.viewport.Y) / 64));
                LibraryMuseum currentLocation = Game1.currentLocation as LibraryMuseum;
                if (currentLocation.museumPieces.ContainsKey(key))
                {
                    // save current slot of the item so it can be swapped
                    this.heldItem = (Item) new StardewValley.Object(currentLocation.museumPieces[key], 1, false, -1, 0);
                    oldX1         = (int)key.X;
                    oldY1         = (int)key.Y;

                    // Hover information
                    selectedItemDescription = this.heldItem?.getDescription();
                    selectedItemTitle       = this.heldItem?.DisplayName;

                    selectedItem = this.heldItem;

                    // Restart the info fade timer
                    lock (lockInfoFadeTimer)
                    {
                        if (infoFadeTimer != null)
                        {
                            infoFadeTimerCurrentValue = infoFadeTimerStartValue;
                            infoFadeTimer.Start();
                        }
                    }

                    currentLocation.museumPieces.Remove(key);
                    holdingMuseumPiece = !currentLocation.museumAlreadyHasArtifact(this.heldItem.ParentSheetIndex);
                }
            }

            //if (this.heldItem != null && heldItem == null)
            //{
            //    this.menuMovingDown = true;
            //}

            //if (!readyToClose())
            //{
            //    return;
            //}

            //state = 2;
            //fadeTimer = 800;
            //fadeIntoBlack = true;
            //Game1.playSound("bigDeSelect");
        }
        // Added [item swap] support
        public override void receiveLeftClick(int x, int y, bool playSound = true)
        {
            if (this.fadeTimer > 0)
            {
                return;
            }

            Item heldItem = this.heldItem;

            if (!holdingMuseumPieceRef.GetValue())
            {
                this.heldItem         = this.inventory.leftClick(x, y, this.heldItem, true);
                selectedInventoryItem = this.heldItem != null;
            }

            LibraryMuseum museum = Game1.currentLocation as LibraryMuseum;

            // Place item at a museum slot
            if (heldItem != null && this.heldItem != null &&
                (y < Game1.viewport.Height - (height - (IClickableMenu.borderWidth + IClickableMenu.spaceToClearTopBorder + 192)) ||
                 this.menuMovingDown || !selectedInventoryItem || !inventory.isWithinBounds(x, y)))
            {
                int x1 = (x + Game1.viewport.X) / 64;
                int y1 = (y + Game1.viewport.Y) / 64;

                // Place item at an empty museum slot
                if (museum.isTileSuitableForMuseumPiece(x1, y1) &&
                    museum.isItemSuitableForDonation(this.heldItem))
                {
                    int parentSheetIndex = this.heldItem.ParentSheetIndex;
                    int count            = museum.getRewardsForPlayer(Game1.player).Count;

                    // Add item to the current position
                    museum.museumPieces.Add(new Vector2((float)x1, (float)y1), (this.heldItem as StardewValley.Object).ParentSheetIndex);


                    Game1.playSound("stoneStep");
                    holdingMuseumPieceRef.SetValue(false);

                    PrepareHideItemInfoTooltip();

                    // Rewards
                    if (museum.getRewardsForPlayer(Game1.player).Count > count)
                    {
                        this.sparkleText = new SparklingText(Game1.dialogueFont, Game1.content.LoadString("Strings\\StringsFromCSFiles:NewReward"), Color.MediumSpringGreen, Color.White, false, 0.1, 2500, -1, 500);
                        Game1.playSound("reward");
                        this.globalLocationOfSparklingArtifact = new Vector2((float)(x1 * 64 + 32) - this.sparkleText.textWidth / 2f, (float)(y1 * 64 - 48));
                    }

                    else
                    {
                        Game1.playSound("newArtifact");
                    }

                    // If the player has no donatable item in his inventory, hide the inventory
                    if (!museum.doesFarmerHaveAnythingToDonate(Game1.player))
                    {
                        showInventory = false;
                    }

                    Game1.player.completeQuest(24);
                    --this.heldItem.Stack;
                    if (this.heldItem.Stack <= 0)
                    {
                        this.heldItem = (Item)null;
                    }

                    this.menuMovingDown = false;
                    int num = museum.museumPieces.Count();
                    if (num >= 95)
                    {
                        Game1.getAchievement(5);
                    }
                    else if (num >= 40)
                    {
                        Game1.getAchievement(28);
                    }
                    else if (selectedInventoryItem)
                    {
                        multiplayer.globalChatInfoMessage("donation", Game1.player.Name, "object:" + (object)parentSheetIndex);
                    }
                }

                // Place item at an already in-use museum slot and swap it with its current item
                else if (LibraryMuseumHelper.IsTileSuitableForMuseumPiece(x1, y1) &&
                         museum.isItemSuitableForDonation(this.heldItem) && !selectedInventoryItem)
                {
                    Vector2 keySrc  = new Vector2((float)oldX1, (float)oldY1);
                    Vector2 keyDest = new Vector2((float)x1, (float)y1);

                    Item swapItem = null;

                    // Remove current item at museum slot
                    LibraryMuseum currentLocation = Game1.currentLocation as LibraryMuseum;
                    if (currentLocation.museumPieces.ContainsKey(keyDest))
                    {
                        swapItem = (Item) new StardewValley.Object(currentLocation.museumPieces[keyDest], 1, false, -1, 0);
                        currentLocation.museumPieces.Remove(keyDest);
                    }

                    // Place held item at the museum slot
                    currentLocation.museumPieces.Add(keyDest, (this.heldItem as StardewValley.Object).ParentSheetIndex);

                    // Place removed item at the old location of the held item to complete the swap
                    if (swapItem != null)
                    {
                        currentLocation.museumPieces.Add(keySrc, (swapItem as StardewValley.Object).ParentSheetIndex);
                    }

                    Game1.playSound("stoneStep");
                    holdingMuseumPieceRef.SetValue(false);

                    PrepareHideItemInfoTooltip();

                    Game1.playSound("newArtifact");

                    --this.heldItem.Stack;
                    if (this.heldItem.Stack <= 0)
                    {
                        this.heldItem = (Item)null;
                    }
                }
            }

            // Grab an item which is already located in the museum
            else if (this.heldItem == null && (!inventory.isWithinBounds(x, y) || !showInventory) &&
                     (okButton == null || !okButton.containsPoint(x, y)))
            {
                Vector2       key             = new Vector2((float)((x + Game1.viewport.X) / 64), (float)((y + Game1.viewport.Y) / 64));
                LibraryMuseum currentLocation = Game1.currentLocation as LibraryMuseum;
                if (currentLocation.museumPieces.ContainsKey(key))
                {
                    // save current slot of the item so it can be swapped
                    this.heldItem = (Item) new StardewValley.Object(currentLocation.museumPieces[key], 1, false, -1, 0);
                    oldX1         = (int)key.X;
                    oldY1         = (int)key.Y;

                    // Hover information
                    selectedItemDescription = this.heldItem?.getDescription();
                    selectedItemTitle       = this.heldItem?.DisplayName;

                    selectedItem = this.heldItem;

                    // Restart the info fade timer
                    lock (lockInfoFadeTimer)
                    {
                        if (infoFadeTimer != null)
                        {
                            infoFadeTimerCurrentValue = infoFadeTimerStartValue;
                            infoFadeTimer.Start();
                        }
                    }

                    currentLocation.museumPieces.Remove(key);
                    holdingMuseumPieceRef.SetValue(!currentLocation.museumAlreadyHasArtifact(this.heldItem.ParentSheetIndex));
                }
            }

            if (this.heldItem != null && heldItem == null)
            {
                this.menuMovingDown = true;
            }

            if (!showInventory || okButton == null || !okButton.containsPoint(x, y) || !readyToClose())
            {
                return;
            }

            state         = 2;
            fadeTimer     = 800;
            fadeIntoBlack = true;
            Game1.playSound("bigDeSelect");
        }
Beispiel #12
0
        /// <summary>The method invoked when the player presses a controller, keyboard, or mouse button.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event data.</param>
        private void InputEvents_ButtonPressed(object sender, EventArgsInput e)
        {
            if (e.IsActionButton && Context.IsPlayerFree && LibraryMuseumHelper.IsPlayerAtCounter(Game1.player))
            {
                LibraryMuseum museum    = Game1.currentLocation as LibraryMuseum;
                bool          canDonate = museum.doesFarmerHaveAnythingToDonate(Game1.player);

                int donatedItems = LibraryMuseumHelper.MuseumPieces;

                if (canDonate)
                {
                    if (donatedItems > 0)
                    {
                        // Can donate, rearrange museum and collect rewards
                        if (LibraryMuseumHelper.HasPlayerCollectibleRewards(Game1.player))
                        {
                            ShowDialog(MuseumInteractionDialogType.DonateRearrangeCollect);
                        }

                        // Can donate and rearrange museum
                        else
                        {
                            ShowDialog(MuseumInteractionDialogType.DonateRearrange);
                        }
                    }

                    // Can donate & collect rewards & no item donated yet (cannot rearrange museum)
                    else if (LibraryMuseumHelper.HasPlayerCollectibleRewards(Game1.player))
                    {
                        ShowDialog(MuseumInteractionDialogType.DonateCollect);
                    }

                    // Can donate & no item donated yet (cannot rearrange)
                    else
                    {
                        ShowDialog(MuseumInteractionDialogType.Donate);
                    }
                }

                // No item to donate, donated at least one item and can potentially collect a reward
                else if (donatedItems > 0)
                {
                    // Can rearrange and collect a reward
                    if (LibraryMuseumHelper.HasPlayerCollectibleRewards(Game1.player))
                    {
                        ShowDialog(MuseumInteractionDialogType.RearrangeCollect);
                    }

                    // Can rearrange and no rewards available
                    else
                    {
                        ShowDialog(MuseumInteractionDialogType.Rearrange);
                    }
                }

                else
                {
                    // Show original game message. Currently in the following cases:
                    //  - When no item has been donated yet
                }
            }
        }
Beispiel #13
0
        /// <summary>Get the data to display for this subject.</summary>
        /// <param name="metadata">Provides metadata that's not available from the game data directly.</param>
        public override IEnumerable <ICustomField> GetData(Metadata metadata)
        {
            // get data
            Item   item       = this.Target;
            Object obj        = item as Object;
            bool   isObject   = obj != null;
            bool   isCrop     = this.FromCrop != null;
            bool   isSeed     = this.SeedForCrop != null;
            bool   isDeadCrop = this.FromCrop?.dead == true;
            bool   canSell    = obj?.canBeShipped() == true || metadata.Shops.Any(shop => shop.BuysCategories.Contains(item.category));

            // get overrides
            bool showInventoryFields = true;

            {
                ObjectData objData = metadata.GetObject(item, this.Context);
                if (objData != null)
                {
                    this.Name           = objData.Name ?? this.Name;
                    this.Description    = objData.Description ?? this.Description;
                    this.Type           = objData.Type ?? this.Type;
                    showInventoryFields = objData.ShowInventoryFields ?? true;
                }
            }

            // don't show data for dead crop
            if (isDeadCrop)
            {
                yield return(new GenericField("Crop", "This crop is dead."));

                yield break;
            }

            // crop fields
            if (isCrop || isSeed)
            {
                // get crop
                Crop crop = this.FromCrop ?? this.SeedForCrop;

                // get harvest schedule
                int  harvestablePhase   = crop.phaseDays.Count - 1;
                bool canHarvestNow      = (crop.currentPhase >= harvestablePhase) && (!crop.fullyGrown || crop.dayOfCurrentPhase <= 0);
                int  daysToFirstHarvest = crop.phaseDays.Take(crop.phaseDays.Count - 1).Sum(); // ignore harvestable phase

                // add next-harvest field
                if (isCrop)
                {
                    // calculate next harvest
                    int      daysToNextHarvest = 0;
                    GameDate dayOfNextHarvest  = null;
                    if (!canHarvestNow)
                    {
                        // calculate days until next harvest
                        int daysUntilLastPhase = daysToFirstHarvest - crop.dayOfCurrentPhase - crop.phaseDays.Take(crop.currentPhase).Sum();
                        {
                            // growing: days until next harvest
                            if (!crop.fullyGrown)
                            {
                                daysToNextHarvest = daysUntilLastPhase;
                            }

                            // regrowable crop harvested today
                            else if (crop.dayOfCurrentPhase >= crop.regrowAfterHarvest)
                            {
                                daysToNextHarvest = crop.regrowAfterHarvest;
                            }

                            // regrowable crop
                            else
                            {
                                daysToNextHarvest = crop.dayOfCurrentPhase; // dayOfCurrentPhase decreases to 0 when fully grown, where <=0 is harvestable
                            }
                        }
                        dayOfNextHarvest = GameHelper.GetDate(metadata.Constants.DaysInSeason).GetDayOffset(daysToNextHarvest);
                    }

                    // generate field
                    string summary;
                    if (canHarvestNow)
                    {
                        summary = "now";
                    }
                    else if (Game1.currentLocation.Name != Constant.LocationNames.Greenhouse && !crop.seasonsToGrowIn.Contains(dayOfNextHarvest.Season))
                    {
                        summary = $"too late in the season for the next harvest (would be on {dayOfNextHarvest})";
                    }
                    else
                    {
                        summary = $"{dayOfNextHarvest} ({TextHelper.Pluralise(daysToNextHarvest, "tomorrow", $"in {daysToNextHarvest} days")})";
                    }

                    yield return(new GenericField("Harvest", summary));
                }

                // crop summary
                {
                    List <string> summary = new List <string>();

                    // harvest
                    summary.Add($"-harvest after {daysToFirstHarvest} {TextHelper.Pluralise(daysToFirstHarvest, "day")}" + (crop.regrowAfterHarvest != -1 ? $", then every {TextHelper.Pluralise(crop.regrowAfterHarvest, "day", $"{crop.regrowAfterHarvest} days")}" : ""));

                    // seasons
                    summary.Add($"-grows in {string.Join(", ", crop.seasonsToGrowIn)}");

                    // drops
                    if (crop.minHarvest != crop.maxHarvest && crop.chanceForExtraCrops > 0)
                    {
                        summary.Add($"-drops {crop.minHarvest} to {crop.maxHarvest} ({Math.Round(crop.chanceForExtraCrops * 100, 2)}% chance of extra crops)");
                    }
                    else if (crop.minHarvest > 1)
                    {
                        summary.Add($"-drops {crop.minHarvest}");
                    }

                    // crop sale price
                    Item drop = GameHelper.GetObjectBySpriteIndex(crop.indexOfHarvest);
                    summary.Add($"-sells for {GenericField.GetSaleValueString(this.GetSaleValue(drop, false, metadata), 1)}");

                    // generate field
                    yield return(new GenericField("Crop", string.Join(Environment.NewLine, summary)));
                }
            }

            // crafting
            if (obj?.heldObject != null)
            {
                if (obj is Cask)
                {
                    // get cask data
                    Cask        cask           = (Cask)obj;
                    Object      agingObj       = cask.heldObject;
                    ItemQuality currentQuality = (ItemQuality)agingObj.quality;

                    // calculate aging schedule
                    float effectiveAge = metadata.Constants.CaskAgeSchedule.Values.Max() - cask.daysToMature;
                    var   schedule     =
                        (
                            from entry in metadata.Constants.CaskAgeSchedule
                            let quality = entry.Key
                                          let baseDays = entry.Value
                                                         where baseDays > effectiveAge
                                                         orderby baseDays ascending
                                                         let daysLeft = (int)Math.Ceiling((baseDays - effectiveAge) / cask.agingRate)
                                                                        select new
                    {
                        Quality = quality,
                        DaysLeft = daysLeft,
                        HarvestDate = GameHelper.GetDate(metadata.Constants.DaysInSeason).GetDayOffset(daysLeft)
                    }
                        )
                        .ToArray();

                    // display fields
                    yield return(new ItemIconField("Contents", obj.heldObject));

                    if (cask.minutesUntilReady <= 0 || !schedule.Any())
                    {
                        yield return(new GenericField("Aging", $"{currentQuality.GetName()} quality ready"));
                    }
                    else
                    {
                        string scheduleStr = string.Join(Environment.NewLine, (from entry in schedule select $"-{entry.Quality.GetName()} {TextHelper.Pluralise(entry.DaysLeft, "tomorrow", $"in {entry.DaysLeft} days")} ({entry.HarvestDate})"));
                        yield return(new GenericField("Aging", $"-{currentQuality.GetName()} now (use pickaxe to stop aging){Environment.NewLine}" + scheduleStr));
                    }
                }
                else
                {
                    yield return(new ItemIconField("Contents", obj.heldObject, $"{obj.heldObject.Name} " + (obj.minutesUntilReady > 0 ? "in " + TextHelper.Stringify(TimeSpan.FromMinutes(obj.minutesUntilReady)) : "ready")));
                }
            }

            // item
            if (showInventoryFields)
            {
                // needed for
                {
                    List <string> neededFor = new List <string>();

                    // bundles
                    if (isObject)
                    {
                        string[] bundles = (from bundle in this.GetUnfinishedBundles(obj) orderby bundle.Area, bundle.Name select $"{bundle.Area}: {bundle.Name}").ToArray();
                        if (bundles.Any())
                        {
                            neededFor.Add($"community center ({string.Join(", ", bundles)})");
                        }
                    }

                    // polyculture achievement
                    if (isObject && metadata.Constants.PolycultureCrops.Contains(obj.ParentSheetIndex))
                    {
                        int needed = metadata.Constants.PolycultureCount - GameHelper.GetShipped(obj.ParentSheetIndex);
                        if (needed > 0)
                        {
                            neededFor.Add($"polyculture achievement (ship {needed} more)");
                        }
                    }

                    // full shipment achievement
                    if (isObject && GameHelper.GetFullShipmentAchievementItems().Any(p => p.Key == obj.ParentSheetIndex && !p.Value))
                    {
                        neededFor.Add("full shipment achievement (ship one)");
                    }

                    // a full collection achievement
                    LibraryMuseum museum = Game1.locations.OfType <LibraryMuseum>().FirstOrDefault();
                    if (museum != null && museum.isItemSuitableForDonation(obj))
                    {
                        neededFor.Add("full collection achievement (donate one to museum)");
                    }

                    // yield
                    if (neededFor.Any())
                    {
                        yield return(new GenericField("Needed for", string.Join(", ", neededFor)));
                    }
                }

                // sale data
                if (canSell && !isCrop)
                {
                    // sale price
                    string saleValueSummary = GenericField.GetSaleValueString(this.GetSaleValue(item, this.KnownQuality, metadata), item.Stack);
                    yield return(new GenericField("Sells for", saleValueSummary));

                    // sell to
                    List <string> buyers = new List <string>();
                    if (obj?.canBeShipped() == true)
                    {
                        buyers.Add("shipping box");
                    }
                    buyers.AddRange(from shop in metadata.Shops where shop.BuysCategories.Contains(item.category) orderby shop.DisplayName select shop.DisplayName);
                    yield return(new GenericField("Sells to", TextHelper.OrList(buyers.ToArray())));
                }

                // gift tastes
                var giftTastes = this.GetGiftTastes(item, metadata);
                yield return(new ItemGiftTastesField("Loves this", giftTastes, GiftTaste.Love));

                yield return(new ItemGiftTastesField("Likes this", giftTastes, GiftTaste.Like));
            }

            // fence
            if (item is Fence)
            {
                Fence fence = (Fence)item;

                // health
                if (Game1.getFarm().isBuildingConstructed(Constant.BuildingNames.GoldClock))
                {
                    yield return(new GenericField("Health", "no decay with Gold Clock"));
                }
                else
                {
                    float maxHealth = fence.isGate ? fence.maxHealth * 2 : fence.maxHealth;
                    float health    = fence.health / maxHealth;
                    float daysLeft  = fence.health * metadata.Constants.FenceDecayRate / 60 / 24;
                    yield return(new PercentageBarField("Health", (int)fence.health, (int)maxHealth, Color.Green, Color.Red, $"{Math.Round(health * 100)}% (roughly {Math.Round(daysLeft)} days left)"));
                }
            }

            // recipes
            if (item.GetSpriteType() == ItemSpriteType.Object)
            {
                RecipeModel[] recipes = GameHelper.GetRecipesForIngredient(this.DisplayItem).ToArray();
                if (recipes.Any())
                {
                    yield return(new RecipesForIngredientField("Recipes", item, recipes));
                }
            }

            // owned
            if (showInventoryFields && !isCrop && !(item is Tool))
            {
                yield return(new GenericField("Owned", $"you own {GameHelper.CountOwnedItems(item)} of these"));
            }
        }
        private void PlayerEvents_InventoryChanged(object sender, EventArgsInventoryChanged e)
        {
            if (!Context.IsWorldReady)
            {
                return;
            }

            if (!itemDicGenerated)
            {
                return;
            }

            LibraryMuseum museum = Game1.locations.OfType <LibraryMuseum>().FirstOrDefault();

            if (museum == null)
            {
                return;
            }

            Dictionary <int, Item> donateableItemDic = new Dictionary <int, Item>();

            foreach (ItemStackChange itemStack in e.Added)
            {
                if (museum.isItemSuitableForDonation(itemStack.Item))
                {
                    if (itemDic.Any(x => x.Value.Name.Equals(itemStack.Item.Name)))
                    {
                        donateableItemDic.Add(itemDic.FirstOrDefault(x => x.Value.Equals(itemStack.Item)).Key, itemStack.Item);
                    }
                    else
                    {
                        this.Monitor.Log($"{Game1.player.Name} - Donateable Item: Didn't found ID for {itemStack.Item}.", LogLevel.Error);
                    }
                }
            }

            if (donateableItemDic.Count == 0)
            {
                return;
            }

            List <int> donatedItemList = new List <int>();

            foreach (KeyValuePair <Vector2, int> pair in museum.museumPieces.Pairs)
            {
                donatedItemList.Add(pair.Value);
            }

            bool anyItemsToDonate = false;

            foreach (KeyValuePair <int, Item> donateableItem in donateableItemDic)
            {
                if (!donatedItemList.Contains(donateableItem.Key))
                {
                    anyItemsToDonate = true;
                }
            }

            if (anyItemsToDonate)
            {
                Game1.addHUDMessage(new HUDMessage(Helper.Translation.Get("message-type.found-museum-item")));
            }
        }
Beispiel #15
0
 public override void receiveKeyPress(Keys key)
 {
     if (fadeTimer > 0)
     {
         return;
     }
     if (Game1.options.doesInputListContain(Game1.options.menuButton, key) && readyToClose())
     {
         state         = 2;
         fadeTimer     = 500;
         fadeIntoBlack = true;
     }
     else if (Game1.options.SnappyMenus && heldItem == null && !reOrganizing)
     {
         base.receiveKeyPress(key);
     }
     if (!Game1.options.SnappyMenus)
     {
         if (Game1.options.doesInputListContain(Game1.options.moveDownButton, key))
         {
             Game1.panScreen(0, 4);
         }
         else if (Game1.options.doesInputListContain(Game1.options.moveRightButton, key))
         {
             Game1.panScreen(4, 0);
         }
         else if (Game1.options.doesInputListContain(Game1.options.moveUpButton, key))
         {
             Game1.panScreen(0, -4);
         }
         else if (Game1.options.doesInputListContain(Game1.options.moveLeftButton, key))
         {
             Game1.panScreen(-4, 0);
         }
     }
     else
     {
         if (heldItem == null && !reOrganizing)
         {
             return;
         }
         LibraryMuseum museum = Game1.currentLocation as LibraryMuseum;
         int           y      = Game1.getMouseY();
         Vector2       newCursorPositionTile2 = new Vector2((Game1.getMouseX() + Game1.viewport.X) / 64, (y + Game1.viewport.Y) / 64);
         if (!museum.isTileSuitableForMuseumPiece((int)newCursorPositionTile2.X, (int)newCursorPositionTile2.Y) && (!reOrganizing || !museum.museumPieces.ContainsKey(newCursorPositionTile2)))
         {
             newCursorPositionTile2 = museum.getFreeDonationSpot();
             Game1.setMousePosition((int)(newCursorPositionTile2.X * 64f - (float)Game1.viewport.X + 32f), (int)(newCursorPositionTile2.Y * 64f - (float)Game1.viewport.Y + 32f));
             return;
         }
         if (key == Game1.options.getFirstKeyboardKeyFromInputButtonList(Game1.options.moveUpButton))
         {
             newCursorPositionTile2 = museum.findMuseumPieceLocationInDirection(newCursorPositionTile2, 0, 21, !reOrganizing);
         }
         else if (key == Game1.options.getFirstKeyboardKeyFromInputButtonList(Game1.options.moveRightButton))
         {
             newCursorPositionTile2 = museum.findMuseumPieceLocationInDirection(newCursorPositionTile2, 1, 21, !reOrganizing);
         }
         else if (key == Game1.options.getFirstKeyboardKeyFromInputButtonList(Game1.options.moveDownButton))
         {
             newCursorPositionTile2 = museum.findMuseumPieceLocationInDirection(newCursorPositionTile2, 2, 21, !reOrganizing);
         }
         else if (key == Game1.options.getFirstKeyboardKeyFromInputButtonList(Game1.options.moveLeftButton))
         {
             newCursorPositionTile2 = museum.findMuseumPieceLocationInDirection(newCursorPositionTile2, 3, 21, !reOrganizing);
         }
         if (!Game1.viewport.Contains(new Location((int)(newCursorPositionTile2.X * 64f + 32f), Game1.viewport.Y + 1)))
         {
             Game1.panScreen((int)(newCursorPositionTile2.X * 64f - (float)Game1.viewport.X), 0);
         }
         else if (!Game1.viewport.Contains(new Location(Game1.viewport.X + 1, (int)(newCursorPositionTile2.Y * 64f + 32f))))
         {
             Game1.panScreen(0, (int)(newCursorPositionTile2.Y * 64f - (float)Game1.viewport.Y));
         }
         Game1.setMousePosition((int)newCursorPositionTile2.X * 64 - Game1.viewport.X + 32, (int)newCursorPositionTile2.Y * 64 - Game1.viewport.Y + 32);
     }
 }