Пример #1
0
        /// <summary>
        /// DailyVisit before function
        /// </summary>
        /// <param name="plantBlob"></param>
        /// <param name="plantLocation"></param>
        /// <param name="plantTile"></param>
        /// <param name="soilLocation"></param>
        /// <param name="soilTile"></param>
        /// <param name="universe"></param>
        /// <param name="weatherWatered"></param>
        /// <returns></returns>
        public bool DailyVisit(Blob plantBlob, Vector3I plantLocation, Tile plantTile, Vector3I soilLocation, Tile soilTile, EntityUniverseFacade universe, bool weatherWatered)
        {
            // Return true in case it concerns a greenhouse plant

            int  day     = universe.DayNightCycle().Day;
            int  season  = universe.DayNightCycle().GetSeason();
            bool watered = GameContext.FarmingDatabase.IsWateredMaterial(soilTile.Configuration);

            if (GameContext.PlantDatabase.IsGrowable(plantTile))
            {
                PlantConfiguration  plantConfiguration = GameContext.PlantDatabase.GetByTile(plantTile.Configuration);
                DeterministicRandom rnd       = GameContext.RandomSource;
                bool         requiresWatering = GameContext.PlantDatabase.RequiresWatering(plantTile);
                long         lastChangedDay   = plantBlob.GetLong("day", -1L);
                int          prevSeason2      = (int)plantBlob.GetLong("season", -1L);
                List <Totem> totems;
                Totem        totem;
                bool         plantedInGreenhouse = (PlantLogic.GetValidTotemsOfType(PlantLogic.GreenhouseTotemCode, out totems) && PlantLogic.IsInTotemsRegion(totems, plantLocation, out totem));

                if (plantConfiguration.LivesInSeason(SeasonHelper.FromInt(season)) ||
                    !plantConfiguration.LivesInSeason(SeasonHelper.FromInt(season)) && !plantedInGreenhouse)
                {
                    return(true);
                }

                Logger.WriteLine("Custom plant DailyVisit");

                if (prevSeason2 == -1)
                {
                    prevSeason2 = season;
                }

                if (lastChangedDay == -1 || lastChangedDay > day)
                {
                    lastChangedDay = day - 1;
                    PlantLogic.FarmDatabaseTileUpdated.Invoke(GameContext.FarmingDatabase, new object[] { plantLocation, lastChangedDay, plantConfiguration.GatherableIsHarvestable, season });
                }

                Vector2I window2 = default(Vector2I);
                Vector2I window3 = default(Vector2I);
                Logger.WriteLine("Plant: " + plantConfiguration.Code);
                Logger.WriteLine("Watered: " + watered.ToString() + " | RequiresWatering: " + requiresWatering.ToString() + " | CanWilt: " + plantConfiguration.CanWilt(plantTile, out window2).ToString() + " | CanWither: " + plantConfiguration.CanWither(plantTile, out window3).ToString());

                long totalDays  = day - lastChangedDay;
                int  growthDays = 0;
                int  daysPassed = 1;
                for (int i = 0; i < totalDays; i++)
                {
                    Vector2I window = default(Vector2I);
                    if (!watered && requiresWatering && plantConfiguration.CanWilt(plantTile, out window))
                    {
                        Logger.WriteLine("Wilting result:" + ((bool)PlantLogic.FarmDatabaseChangeTile.Invoke(GameContext.FarmingDatabase, new object[] { plantLocation, plantConfiguration.MakeWiltedTile(plantTile), universe, plantConfiguration.GatherableIsHarvestable, null, TileAccessFlags.IgnoreEntities })).ToString());
                        int transitionPeriod3 = rnd.Next(window.X, window.Y);
                        if (transitionPeriod3 <= daysPassed - growthDays &&
                            (bool)PlantLogic.FarmDatabaseChangeTile.Invoke(GameContext.FarmingDatabase, new object[] { plantLocation, plantConfiguration.MakeWiltedTile(plantTile), universe, plantConfiguration.GatherableIsHarvestable, null, TileAccessFlags.IgnoreEntities }))
                        {
                            Logger.WriteLine("Wilting greenhouse plant");
                            break;
                        }
                    }
                    if (!watered && requiresWatering && plantConfiguration.CanWither(plantTile, out window))
                    {
                        Logger.WriteLine("Withering result: " + ((bool)PlantLogic.FarmDatabaseChangeTile.Invoke(GameContext.FarmingDatabase, new object[] { plantLocation, plantConfiguration.MakeWitheredTile(plantTile), universe, plantConfiguration.GatherableIsHarvestable, null, TileAccessFlags.IgnoreEntities })).ToString());
                        int transitionPeriod2 = rnd.Next(window.X, window.Y);
                        if (transitionPeriod2 <= daysPassed - growthDays &&
                            (bool)PlantLogic.FarmDatabaseChangeTile.Invoke(GameContext.FarmingDatabase, new object[] { plantLocation, plantConfiguration.MakeWitheredTile(plantTile), universe, plantConfiguration.GatherableIsHarvestable, null, TileAccessFlags.IgnoreEntities }))
                        {
                            Logger.WriteLine("Withering greenhouse plant");
                            break;
                        }
                    }
                    if (!watered && requiresWatering && !plantConfiguration.CanWilt(plantTile, out window) && !plantConfiguration.CanWither(plantTile, out window))
                    {
                        Logger.WriteLine("Set as harvestable");
                        PlantLogic.FarmDatabaseTileUpdated.Invoke(GameContext.FarmingDatabase, new object[] { plantLocation, day, plantConfiguration.GatherableIsHarvestable, season });
                        break;
                    }
                    if ((watered || !requiresWatering || (plantConfiguration.GatherableIsHarvestable && rnd.NextBool())) && plantConfiguration.CanGrow(plantTile, SeasonHelper.FromInt(season), out window))
                    {
                        int transitionPeriod = rnd.Next(window.X, window.Y);
                        if (transitionPeriod <= daysPassed - growthDays &&
                            (bool)PlantLogic.FarmDatabaseChangeTile.Invoke(GameContext.FarmingDatabase, new object[] { plantLocation, plantConfiguration.MakeGrowTile(plantTile, rnd), universe, plantConfiguration.GatherableIsHarvestable, null, TileAccessFlags.IgnoreEntities }))
                        {
                            growthDays += transitionPeriod;
                            if (!universe.ReadTile(plantLocation, TileAccessFlags.None, out plantTile))
                            {
                                return(true);
                            }
                        }
                    }

                    daysPassed++;
                }


                if (!weatherWatered && watered)
                {
                    Tile unwateredTile = (Tile)PlantLogic.FarmDatabaseMakeUnwateredMaterial.Invoke(GameContext.FarmingDatabase, new object[] { soilTile });
                    PlantLogic.FarmDatabaseChangeTile.Invoke(null, new object[] { soilLocation, unwateredTile, universe, false, null, TileAccessFlags.IgnoreEntities });
                }

                Tile tempPlant            = default(Tile);
                PlantConfiguration config = default(PlantConfiguration);
                bool isMaterialWaterable  = (bool)PlantLogic.FarmDatabaseIsMaterialWaterable.Invoke(GameContext.FarmingDatabase, new object[] { soilTile.Configuration });
                if (weatherWatered && !watered && isMaterialWaterable && universe.ReadTile(plantLocation, TileAccessFlags.None, out tempPlant) && GameContext.PlantDatabase.TryGetByTile(tempPlant, out config))
                {
                    Tile wateredTile = (Tile)PlantLogic.FarmDatabaseMakeWateredMaterial.Invoke(GameContext.FarmingDatabase, new object[] { soilTile });
                    PlantLogic.FarmDatabaseChangeTile.Invoke(null, new object[] { soilLocation, wateredTile, universe, false, null, TileAccessFlags.IgnoreEntities });
                }

                return(false);
            }

            return(true);
        }