Ejemplo n.º 1
0
        /// <summary>Get the data to display for this subject.</summary>
        public override IEnumerable <ICustomField> GetData()
        {
            // get info
            Building building     = this.Target;
            bool     built        = !building.isUnderConstruction();
            int?     upgradeLevel = this.GetUpgradeLevel(building);

            // construction / upgrade
            if (!built || building.daysUntilUpgrade.Value > 0)
            {
                int   daysLeft  = building.isUnderConstruction() ? building.daysOfConstructionLeft.Value : building.daysUntilUpgrade.Value;
                SDate readyDate = SDate.Now().AddDays(daysLeft);
                yield return(new GenericField(I18n.Building_Construction(), I18n.Building_Construction_Summary(date: this.Stringify(readyDate))));
            }

            // owner
            Farmer?owner = this.GetOwner();

            if (owner != null)
            {
                yield return(new LinkField(I18n.Building_Owner(), owner.Name, () => this.Codex.GetByEntity(owner, owner.currentLocation) !));
            }
            else if (building.indoors.Value is Cabin)
            {
                yield return(new GenericField(I18n.Building_Owner(), I18n.Building_Owner_None()));
            }

            // stable horse
            if (built && building is Stable stable)
            {
                Horse horse = Utility.findHorse(stable.HorseId);
                if (horse != null)
                {
                    yield return(new LinkField(I18n.Building_Horse(), horse.Name, () => this.Codex.GetByEntity(horse, horse.currentLocation) !));

                    yield return(new GenericField(I18n.Building_HorseLocation(), I18n.Building_HorseLocation_Summary(location: horse.currentLocation.Name, x: horse.getTileX(), y: horse.getTileY())));
                }
            }

            // animals
            if (built && building.indoors.Value is AnimalHouse animalHouse)
            {
                // animal counts
                yield return(new GenericField(I18n.Building_Animals(), I18n.Building_Animals_Summary(count: animalHouse.animalsThatLiveHere.Count, max: animalHouse.animalLimit.Value)));

                // feed trough
                if (building is Barn or Coop && upgradeLevel >= 2)
                {
                    yield return(new GenericField(I18n.Building_FeedTrough(), I18n.Building_FeedTrough_Automated()));
                }
                else
                {
                    this.GetFeedMetrics(animalHouse, out int totalFeedSpaces, out int filledFeedSpaces);
                    yield return(new GenericField(I18n.Building_FeedTrough(), I18n.Building_FeedTrough_Summary(filled: filledFeedSpaces, max: totalFeedSpaces)));
                }
            }
Ejemplo n.º 2
0
        /// <summary>Get the data to display for this subject.</summary>
        public override IEnumerable <ICustomField> GetData()
        {
            // get info
            Building building     = this.Target;
            bool     built        = !building.isUnderConstruction();
            int?     upgradeLevel = this.GetUpgradeLevel(building);

            // construction / upgrade
            if (!built || building.daysUntilUpgrade.Value > 0)
            {
                int   daysLeft  = building.isUnderConstruction() ? building.daysOfConstructionLeft.Value : building.daysUntilUpgrade.Value;
                SDate readyDate = SDate.Now().AddDays(daysLeft);
                yield return(new GenericField(I18n.Building_Construction(), I18n.Building_Construction_Summary(date: this.Stringify(readyDate))));
            }

            // owner
            Farmer owner = this.GetOwner();

            if (owner != null)
            {
                yield return(new LinkField(I18n.Building_Owner(), owner.Name, () => this.Codex.GetByEntity(owner)));
            }
            else if (building.indoors.Value is Cabin)
            {
                yield return(new GenericField(I18n.Building_Owner(), I18n.Building_Owner_None()));
            }

            // stable horse
            if (built && building is Stable stable)
            {
                Horse horse = Utility.findHorse(stable.HorseId);
                if (horse != null)
                {
                    yield return(new LinkField(I18n.Building_Horse(), horse.Name, () => this.Codex.GetByEntity(horse)));

                    yield return(new GenericField(I18n.Building_HorseLocation(), I18n.Building_HorseLocation_Summary(location: horse.currentLocation.Name, x: horse.getTileX(), y: horse.getTileY())));
                }
            }

            // animals
            if (built && building.indoors.Value is AnimalHouse animalHouse)
            {
                // animal counts
                yield return(new GenericField(I18n.Building_Animals(), I18n.Building_Animals_Summary(count: animalHouse.animalsThatLiveHere.Count, max: animalHouse.animalLimit.Value)));

                // feed trough
                if ((building is Barn || building is Coop) && upgradeLevel >= 2)
                {
                    yield return(new GenericField(I18n.Building_FeedTrough(), I18n.Building_FeedTrough_Automated()));
                }
                else
                {
                    this.GetFeedMetrics(animalHouse, out int totalFeedSpaces, out int filledFeedSpaces);
                    yield return(new GenericField(I18n.Building_FeedTrough(), I18n.Building_FeedTrough_Summary(filled: filledFeedSpaces, max: totalFeedSpaces)));
                }
            }

            // slimes
            if (built && building.indoors.Value is SlimeHutch slimeHutch)
            {
                // slime count
                int slimeCount = slimeHutch.characters.OfType <GreenSlime>().Count();
                yield return(new GenericField(I18n.Building_Slimes(), I18n.Building_Slimes_Summary(count: slimeCount, max: 20)));

                // water trough
                yield return(new GenericField(I18n.Building_WaterTrough(), I18n.Building_WaterTrough_Summary(filled: slimeHutch.waterSpots.Count(p => p), max: slimeHutch.waterSpots.Count)));
            }

            // upgrade level
            if (built)
            {
                var upgradeLevelSummary = this.GetUpgradeLevelSummary(building, upgradeLevel).ToArray();
                if (upgradeLevelSummary.Any())
                {
                    yield return(new CheckboxListField(I18n.Building_Upgrades(), upgradeLevelSummary));
                }
            }

            // specific buildings
            if (built)
            {
                switch (building)
                {
                // fish pond
                case FishPond pond:
                    if (pond.fishType.Value <= -1)
                    {
                        yield return(new GenericField(I18n.Building_FishPond_Population(), I18n.Building_FishPond_Population_Empty()));
                    }
                    else
                    {
                        // get fish population
                        SObject fish = pond.GetFishObject();
                        fish.Stack = pond.FishCount;
                        var pondData = pond.GetFishPondData();

                        // population field
                        {
                            string populationStr = $"{fish.DisplayName} ({I18n.Generic_Ratio(pond.FishCount, pond.maxOccupants.Value)})";
                            if (pond.FishCount < pond.maxOccupants.Value)
                            {
                                SDate nextSpawn = SDate.Now().AddDays(pondData.SpawnTime - pond.daysSinceSpawn.Value);
                                populationStr += Environment.NewLine + I18n.Building_FishPond_Population_NextSpawn(relativeDate: this.GetRelativeDateStr(nextSpawn));
                            }

                            yield return(new ItemIconField(this.GameHelper, I18n.Building_FishPond_Population(), fish, text: populationStr));
                        }

                        // output
                        yield return(new ItemIconField(this.GameHelper, I18n.Building_OutputReady(), pond.output.Value));

                        // drops
                        int chanceOfAnyDrop = (int)Math.Round(Utility.Lerp(0.15f, 0.95f, pond.currentOccupants.Value / 10f) * 100);
                        yield return(new FishPondDropsField(this.GameHelper, I18n.Building_FishPond_Drops(), pond.currentOccupants.Value, pondData, preface: I18n.Building_FishPond_Drops_Preface(chance: chanceOfAnyDrop.ToString())));

                        // quests
                        if (pondData.PopulationGates?.Any(gate => gate.Key > pond.lastUnlockedPopulationGate.Value) == true)
                        {
                            yield return(new CheckboxListField(I18n.Building_FishPond_Quests(), this.GetPopulationGates(pond, pondData)));
                        }
                    }
                    break;

                // Junimo hut
                case JunimoHut hut:
                    yield return(new GenericField(I18n.Building_JunimoHarvestingEnabled(), I18n.Stringify(!hut.noHarvest.Value)));

                    yield return(new ItemIconListField(this.GameHelper, I18n.Building_OutputReady(), hut.output.Value?.items, showStackSize: true));

                    break;

                // mill
                case Mill mill:
                    yield return(new ItemIconListField(this.GameHelper, I18n.Building_OutputProcessing(), mill.input.Value?.items, showStackSize: true));

                    yield return(new ItemIconListField(this.GameHelper, I18n.Building_OutputReady(), mill.output.Value?.items, showStackSize: true));

                    break;

                // silo
                case Building _ when building.buildingType.Value == "Silo":
                {
                    // hay summary
                    Farm farm      = Game1.getFarm();
                    int  siloCount = Utility.numSilos();
                    int  hayCount  = farm.piecesOfHay.Value;
                    int  maxHay    = Math.Max(farm.piecesOfHay.Value, siloCount * 240);
                    yield return(new GenericField(
                                     I18n.Building_StoredHay(),
                                     siloCount == 1
                                    ? I18n.Building_StoredHay_SummaryOneSilo(hayCount: hayCount, maxHay: maxHay)
                                    : I18n.Building_StoredHay_SummaryMultipleSilos(hayCount: hayCount, maxHay: maxHay, siloCount: siloCount)
                                     ));
                }
                break;
                }
            }
        }