示例#1
0
        public string GetWeatherForDate(WorldDate date, GameLocation location)
        {
            if (location is null)
            {
                throw new ArgumentNullException(nameof(location));
            }

            string val;

            if (location is Desert)
            {
                val = "Desert";
            }
            else
            {
                GameLocation.LocationContext ctx = location.GetLocationContext();
                switch (ctx)
                {
                case GameLocation.LocationContext.Default:
                    val = "Default";
                    break;

                case GameLocation.LocationContext.Island:
                    val = "Island";
                    break;

                default:
                    throw new ArgumentException("Invalid location context");
                }
            }

            return(GetWeatherForDate(date, val));
        }
示例#2
0
        public static int GetWeather(GameLocation location)
        {
            // special case: day events override weather in the valley
            if (!(location is IslandLocation))
            {
                if (Utility.isFestivalDay(Game1.dayOfMonth, Game1.currentSeason) || (SaveGame.loaded?.weddingToday ?? Game1.weddingToday))
                {
                    return(Game1.weather_sunny);
                }
            }

            // get from weather data
            LocationWeather model = Game1.netWorldState.Value.GetWeatherForLocation(location.GetLocationContext());

            if (model != null)
            {
                if (model.isSnowing.Value)
                {
                    return(Game1.weather_snow);
                }
                if (model.isRaining.Value)
                {
                    return(model.isLightning.Value ? Game1.weather_lightning : Game1.weather_rain);
                }
                if (model.isDebrisWeather.Value)
                {
                    return(Game1.weather_debris);
                }
            }
            return(Game1.weather_sunny);
        }
示例#3
0
        private void Input_ButtonPressed(object sender, ButtonPressedEventArgs e)
        {
            Vector2      tile     = e.Cursor.GrabTile;
            GameLocation location = Game1.currentLocation;

            if (
                Context.IsPlayerFree &&
                SButtonExtensions.IsActionButton(e.Button) &&
                (location.furniture.Count > 0) &&
                IsHutchAtTile(location, tile)
                )
            {
                location.playSound("leafrustle");

                if (CanSpawn(location))
                {
                    bool island = location.GetLocationContext() == GameLocation.LocationContext.Island;
                    if (!location.IsOutdoors && Config.IslandButterflies)
                    {
                        island = true;
                    }

                    do
                    {
                        Vector2 v = new Vector2(tile.X + (float)Game1.random.Next(1, 3), tile.Y - 2f + (float)Game1.random.Next(-1, 2));
                        location.addCritter(new Butterfly(v, island).setStayInbounds(true));
                    } while (Game1.random.NextDouble() < 0.8);
                }
            }
        }
示例#4
0
 public virtual bool IsInSeasonHere(GameLocation location)
 {
     if (fruitSeason.Value == "island")
     {
         if (location.GetLocationContext() == GameLocation.LocationContext.Island)
         {
             return(true);
         }
         return(Game1.GetSeasonForLocation(location).Equals("summer"));
     }
     return(Game1.GetSeasonForLocation(location).Equals(fruitSeason));
 }
示例#5
0
        private static bool CanSpawn(GameLocation loc)
        {
            if (loc.IsOutdoors)
            {
                // the game hutch code will
                //     spawn butterfies in the rain or snow or wind debris.
                //     spawn after dark
                //     spawn any season
                // Is...Here method return true for the Desert when it is raining/etc in the valley/town.
                // the Desert LocationContext is the same as valley/town. there are really only two contexts. valley/town and island.
                // we spawn in more sensible conditions.

                bool island  = loc.GetLocationContext() == StardewValley.GameLocation.LocationContext.Island;
                bool desert  = loc.Name.Equals("Desert", StringComparison.Ordinal);
                bool isClear = !(Game1.IsRainingHere(loc) || Game1.IsLightningHere(loc) || Game1.IsSnowingHere(loc) || Game1.IsDebrisWeatherHere(loc));

                bool spawn = island || desert || (!Game1.currentSeason.Equals("winter", StringComparison.Ordinal) || Config.WinterButterflies);
                spawn = spawn && (isClear || desert);
                spawn = spawn && !Game1.isStartingToGetDarkOut();

                return(spawn);
            }
            return(true);
        }
示例#6
0
 public static bool IsObjectWorking(GameLocation location, UtilityObjectInstance obj)
 {
     return((!obj.Template.mustBeOn || obj.WorldObject.IsOn) &&
            (!obj.Template.onlyDay || Game1.timeOfDay < 1800) &&
            (!obj.Template.onlyNight || Game1.timeOfDay >= 1800) &&
            (!obj.WorldObject.IsSprinkler() || Game1.timeOfDay == 600) &&
            (!obj.Template.onlyMorning || Game1.timeOfDay == 600) &&
            (!obj.Template.mustBeFull || obj.WorldObject.heldObject.Value != null) &&
            (!obj.Template.mustBeWorking || obj.WorldObject.MinutesUntilReady > 0) &&
            (obj.Template.mustContain == null || obj.Template.mustContain.Length == 0 || obj.WorldObject.heldObject.Value?.Name == obj.Template.mustContain) &&
            (!obj.Template.mustHaveSun || ((location.IsOutdoors || location.IsGreenhouse) && !Game1.netWorldState.Value.GetWeatherForLocation(location.GetLocationContext()).isRaining.Value)) &&
            (!obj.Template.mustHaveRain || (location.IsOutdoors && Game1.netWorldState.Value.GetWeatherForLocation(location.GetLocationContext()).isRaining.Value)) &&
            (!obj.Template.mustHaveLightning || (location.IsOutdoors && !Game1.netWorldState.Value.GetWeatherForLocation(location.GetLocationContext()).isLightning.Value)));
 }
示例#7
0
        public static void ChangeStorageObjects(string location, PipeGroup group, GridType type, float hours)
        {
            var netPower = group.powerVector.X + group.powerVector.Y;

            if (group.storageVector.X + netPower < 0) // not enough stored power
            {
                return;
            }

            GameLocation gl = Game1.getLocationFromName(location, false);

            if (gl == null)
            {
                gl = Game1.getLocationFromName(location, true);
                if (gl == null)
                {
                    SMonitor.Log($"Invalid game location {location}", StardewModdingAPI.LogLevel.Error);
                    return;
                }
            }
            var chargeKey     = type == GridType.water ? "aedenthorn.UtilityGrid/waterCharge" : "aedenthorn.UtilityGrid/electricCharge";
            var changeObjects = new Dictionary <Vector2, float>();

            foreach (var v in utilitySystemDict[location][type].objects.Keys.ToArray())
            {
                if (!group.pipes.Contains(v))
                {
                    continue;
                }
                var obj      = utilitySystemDict[location][type].objects[v];
                var objW     = obj.WorldObject;
                var objT     = obj.Template;
                var capacity = type == GridType.water ? objT.waterChargeCapacity : objT.electricChargeCapacity;
                if (capacity == 0)
                {
                    continue;
                }
                float charge = 0;
                if (obj.WorldObject.modData.TryGetValue(chargeKey, out string chargeString))
                {
                    float.TryParse(chargeString, NumberStyles.Float, CultureInfo.InvariantCulture, out charge);
                }
                if (type == GridType.water && hours > 0 && objT.fillWaterFromRain && gl.IsOutdoors && Game1.netWorldState.Value.GetWeatherForLocation(gl.GetLocationContext()).isRaining.Value)
                {
                    charge = Math.Min(charge + objT.waterChargeRate * hours, objT.waterChargeCapacity);
                    objW.modData[chargeKey] = charge + "";
                }
                if (netPower != 0)
                {
                    if (netPower > 0)
                    {
                        changeObjects.Add(v, Math.Min(capacity - charge, type == GridType.water ? objT.waterChargeRate : objT.electricChargeRate));
                    }
                    else
                    {
                        changeObjects.Add(v, Math.Min(charge, type == GridType.water ? objT.waterDischargeRate : objT.electricDischargeRate));
                    }
                }
            }

            // change charges

            while (changeObjects != null && changeObjects.Count > 0 && netPower != 0)
            {
                var eachPower = netPower / changeObjects.Count;
                foreach (var v in changeObjects.Keys.ToArray())
                {
                    var   obj           = utilitySystemDict[location][type].objects[v].WorldObject;
                    var   objT          = utilitySystemDict[location][type].objects[v].Template;
                    float currentCharge = 0;
                    float diff          = changeObjects[v];
                    if (obj.modData.TryGetValue(chargeKey, out string chargeString))
                    {
                        float.TryParse(chargeString, NumberStyles.Float, CultureInfo.InvariantCulture, out currentCharge);
                    }
                    if (eachPower > 0)
                    {
                        var capacity = type == GridType.water ? objT.waterChargeCapacity : objT.electricChargeCapacity;
                        var add      = Math.Min(capacity - currentCharge, Math.Min(diff, eachPower));
                        if (hours > 0)
                        {
                            SMonitor.Log($"adding {add * hours} {type} energy to {obj.Name} at {v}");
                            obj.modData[chargeKey] = Math.Min(capacity, currentCharge + add * hours) + "";
                        }
                        changeObjects[v] -= add;
                        if (add != eachPower)
                        {
                            changeObjects.Remove(v);
                        }
                    }
                    else
                    {
                        float subtract = Math.Min(currentCharge, Math.Min(diff, -eachPower));
                        if (hours > 0)
                        {
                            SMonitor.Log($"subtracting {subtract * hours} {type} energy from {obj.Name} at {v}");
                            obj.modData[chargeKey] = Math.Max(0, currentCharge - subtract * hours) + "";
                        }
                        changeObjects[v] -= subtract;
                        if (subtract != -eachPower)
                        {
                            changeObjects.Remove(v);
                        }
                    }
                }
            }
        }
示例#8
0
        private static void SpawnButterflies(GameLocation loc, int hutchCount, Rectangle?boundingBox)
        {
            // if the hutch did not spawn anything, then we will not
            if (hutchCount > 0)
            {
                bool island = loc.GetLocationContext() == StardewValley.GameLocation.LocationContext.Island;
                int  min    = 0;
                int  max    = 0;

                if (!loc.IsOutdoors)
                {
                    if (Config.MinIndoors > 0)
                    {
                        if (hutchCount < Config.MinIndoors)
                        {
                            min = Config.MinIndoors - hutchCount;
                        }
                        max = Config.MaxIndoors - hutchCount;
                        if (Config.IslandButterflies)
                        {
                            island = true;
                        }
                    }
                }
                else
                {
                    if (Config.MinOutdoors > 0)
                    {
                        if (CanSpawn(loc))
                        {
                            if (hutchCount < Config.MinOutdoors)
                            {
                                min = Config.MinOutdoors - hutchCount;
                            }
                            max = Config.MaxOutdoors - hutchCount;
                        }
                        else
                        {
                            // remove hutch spawned butterflies in instances we think they should not spawn
                            // the game will not spawn ambient butterfies in these conditions.
                            // so just remove all butterflies

                            if (Debug)
                            {
                                Log.Debug($"Remove Butterflies. critters={loc.critters.Count}");
                            }

                            for (int i = loc.critters.Count - 1; i >= 0; i--)
                            {
                                if (loc.critters[i] is Butterfly)
                                {
                                    loc.critters.RemoveAt(i);
                                    if (Debug)
                                    {
                                        Log.Debug($"    Remove Butterfly idx={i}");
                                    }
                                }
                            }
                        }
                    }
                }
                max = Math.Max(max, 0);// possible for max to go <= 0 if the game spawns a ton of butterflies

                if (max > 0)
                {
                    int spawnCount = Rand.Next(min, max + 1);//result always < upper value.
                    if (Debug)
                    {
                        int x = -1;
                        int y = -1;
                        if (boundingBox.HasValue)
                        {
                            x = boundingBox.Value.X / Game1.tileSize;
                            y = boundingBox.Value.Y / Game1.tileSize;
                        }
                        Log.Debug($"Butterfly spawns={spawnCount}, hutchSpawned={hutchCount}, HutchAt={x},{y}");
                    }

                    for (int i = 0; i < spawnCount; i++)
                    {
                        loc.addCritter(new Butterfly(loc.getRandomTile(), island).setStayInbounds(true));
                    }
                }
            }
            //else
            //{
            //    if (Debug)
            //        Log.Debug("Hutch did not spawn butterflies");
            //}
        }