コード例 #1
0
        /// <summary>Get the custom fields indicating what an item is needed for.</summary>
        /// <param name="obj">The machine whose output to represent.</param>
        private IEnumerable <ICustomField> GetNeededForFields(SObject obj)
        {
            if (obj == null || obj.GetItemType() != ItemType.Object)
            {
                yield break;
            }

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

            // 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(I18n.Item_NeededFor_CommunityCenter(bundles: string.Join(", ", missingBundles)));
                }
            }

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

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

            // full collection achievement (donate every artifact)
            if (obj.needsToBeDonated())
            {
                neededFor.Add(I18n.Item_NeededFor_FullCollection());
            }

            // recipe achievements
            {
                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();

                // 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(I18n.Item_NeededFor_GourmetChef(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(I18n.Item_NeededFor_CraftMaster(recipes: string.Join(", ", uncraftedNames)));
                }
            }

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