Exemplo n.º 1
0
        void Events_TimeChanged(object sender, EventArgs e)
        {
            StardewValley.GameLocation location = StardewValley.Game1.currentLocation;
            int time = StardewValley.Game1.timeOfDay;

            if (location != null && !location.IsOutdoors && ((!location.Name.Equals("UndergroundMine") && !location.Name.Equals("FarmCave")) || FreezeTimeInMines))

            /*
             * 3 conditions here:
             * Location exists, not null at beginning of game.  Required to avoid null pointer crash when next conditions are checked
             * Location is not outdoors
             * Location is either
             *      not a mineshaft or farmcave
             *      FreezeTimeInMines is true
             * time is not jumping by more than 10 mins (would imply change through a mod)
             */
            {
                if (time != 600)
                //that is, if a new day didn't start
                {
                    Command.CallCommand("world_settime " + lasttime.ToString());
                    //we set the current time to the last time
                }
            }
            else
            {
                lasttime = time;
                //so if the above conditions are true, then time should be advancing with each tick, and we should update our lasttime
            }
        }
Exemplo n.º 2
0
 public static GameLocation GetLocationFromName(string name)
 {
     StardewValley.GameLocation loc = StardewValley.Game1.getLocationFromName(name);
     if (loc == null)
     {
         throw new ArgumentNullException(nameof(name));
     }
     return(GameLocation.Wrap(loc));
 }
Exemplo n.º 3
0
 public static bool TryGetLocationFromName(string name, out GameLocation location)
 {
     location = default(GameLocation);
     StardewValley.GameLocation loc = StardewValley.Game1.getLocationFromName(name);
     if (loc == null)
     {
         return(false);
     }
     location = GameLocation.Wrap(loc);
     return(true);
 }
Exemplo n.º 4
0
 public GameLocation this[string name]
 {
     get
     {
         StardewValley.GameLocation loc = StardewValley.Game1.getLocationFromName(name);
         if (loc == null)
         {
             throw new KeyNotFoundException();
         }
         return(GameLocation.Wrap(loc));
     }
 }
Exemplo n.º 5
0
 public static MachineRemove Create(GameLocation location, SVObject machine)
 => new(
Exemplo n.º 6
0
 public static bool ScytheForage(StardewValley.Object o, StardewValley.Tool t, StardewValley.GameLocation loc)
 {
     if (o.isSpawnedObject && !o.questItem && o.isForage(loc))
     {
         var    who     = t.getLastFarmerToUse();
         var    vector  = o.TileLocation;
         int    quality = o.quality;
         Random random  = new Random((int)StardewValley.Game1.uniqueIDForThisGame / 2 + (int)StardewValley.Game1.stats.DaysPlayed + (int)vector.X + (int)vector.Y * 777);
         if (who.professions.Contains(16))
         {
             quality = 4;
         }
         else if (random.NextDouble() < (double)((float)who.ForagingLevel / 30))
         {
             quality = 2;
         }
         else if (random.NextDouble() < (double)((float)who.ForagingLevel / 15))
         {
             quality = 1;
         }
         who.gainExperience(2, 7);
         StardewValley.Game1.createObjectDebris(o.ParentSheetIndex, (int)vector.X, (int)vector.Y, -1, quality, 1, loc);
         StardewValley.Game1.stats.ItemsForaged += 1;
         if (who.professions.Contains(13) && random.NextDouble() < 0.2)
         {
             StardewValley.Game1.createObjectDebris(o.ParentSheetIndex, (int)vector.X, (int)vector.Y, -1, quality, 1, loc);
             who.gainExperience(2, 7);
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 7
0
        //Stolen (with explicit permission) from original author Bwdy
        //https://github.com/bwdymods/SDV-bwdyworks/blob/master/ModUtil.cs
        public static HashSet <string> GetAllCharacterNames(bool onlyDateable = false, bool onlyVillager = false, StardewValley.GameLocation onlyThisLocation = null)
        {
            HashSet <string> characters = new HashSet <string>(); //hashset ensures only unique values exist

            if (onlyThisLocation != null)
            {
                foreach (var c in onlyThisLocation.characters)
                {
                    if (!string.IsNullOrWhiteSpace(c.Name))
                    {
                        if (!onlyVillager || c.isVillager())
                        {
                            if (!onlyDateable || c.datable.Value)
                            {
                                characters.Add(c.Name);
                            }
                        }
                    }
                }
                return(characters); //only checking the one location
            }
            //start with NPCDispositions
            Dictionary <string, string> dictionary = StardewValley.Game1.content.Load <Dictionary <string, string> >("Data\\NPCDispositions");

            foreach (string s in dictionary.Keys)
            {
                var c = StardewValley.Game1.getCharacterFromName(s, onlyVillager);
                if (c != null) //simple nullcheck to ensure they weren't removed
                {
                    if (!onlyDateable || c.datable.Value)
                    {
                        if (!string.IsNullOrWhiteSpace(c.Name))
                        {
                            characters.Add(c.Name);
                        }
                    }
                }
            }
            //iterate locations for mod-added NPCs that aren't in the data
            foreach (var loc in StardewValley.Game1.locations)
            {
                foreach (var c in loc.characters)
                {
                    if (!string.IsNullOrWhiteSpace(c.Name))
                    {
                        if (!onlyVillager || c.isVillager())
                        {
                            if (!onlyDateable || c.datable.Value)
                            {
                                characters.Add(c.Name);
                            }
                        }
                    }
                }
            }

            //return the list
            return(characters);
        }
Exemplo n.º 8
0
 private bool IsLocationAFarm(StardewValley.GameLocation location)
 {
     return(location.GetType().IsSubclassOf(typeof(StardewValley.Farm)));
 }
Exemplo n.º 9
0
 internal static GameLocation Wrap(StardewValley.GameLocation location)
 {
     return(new GameLocation(location));
 }
Exemplo n.º 10
0
 internal GameLocation(StardewValley.GameLocation location)
 {
     Location = location;
 }
Exemplo n.º 11
0
 internal WarpList(StardewValley.GameLocation location) : base(location.warps, Warp.Wrap, Warp.Unwrap)
 {
 }
Exemplo n.º 12
0
 public static bool ScytheForage(StardewValley.Object o, StardewValley.Tool t, StardewValley.GameLocation loc)
 {
     if (o.isSpawnedObject && !o.questItem && o.isForage(loc))
     {
         var who    = t.getLastFarmerToUse();
         var vector = o.TileLocation;
         // For objects stored in GameLocation.Objects, the TileLocation is not always set.
         // So determine its location by looping trough all such objects.
         if (vector.X == 0 && vector.Y == 0)
         {
             foreach (System.Collections.Generic.KeyValuePair <Microsoft.Xna.Framework.Vector2, StardewValley.Object> pair in loc.Objects.Pairs)
             {
                 if (pair.Value.Equals(o))
                 {
                     vector = pair.Key;
                     break;
                 }
             }
         }
         int    quality = o.quality;
         Random random  = new Random((int)StardewValley.Game1.uniqueIDForThisGame / 2 + (int)StardewValley.Game1.stats.DaysPlayed + (int)vector.X + (int)vector.Y * 777);
         if (who.professions.Contains(16))
         {
             quality = 4;
         }
         else if (random.NextDouble() < (double)((float)who.ForagingLevel / 30))
         {
             quality = 2;
         }
         else if (random.NextDouble() < (double)((float)who.ForagingLevel / 15))
         {
             quality = 1;
         }
         who.gainExperience(2, 7);
         StardewValley.Game1.createObjectDebris(o.ParentSheetIndex, (int)vector.X, (int)vector.Y, -1, quality, 1, loc);
         StardewValley.Game1.stats.ItemsForaged += 1;
         if (who.professions.Contains(13) && random.NextDouble() < 0.2)
         {
             StardewValley.Game1.createObjectDebris(o.ParentSheetIndex, (int)vector.X, (int)vector.Y, -1, quality, 1, loc);
             who.gainExperience(2, 7);
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }