コード例 #1
0
 /// <inheritdoc />
 public override ISubject?GetSubjectFor(object entity, GameLocation?location)
 {
     return(entity switch
     {
         Bush bush => this.BuildSubject(bush, location),
         _ => null
     });
コード例 #2
0
        /*********
        ** Private methods
        *********/
        /// <summary>Get all crops in a location.</summary>
        /// <param name="location">The location to scan.</param>
        private IEnumerable <Crop> GetCropsIn(GameLocation?location)
        {
            if (location == null)
            {
                yield break;
            }

            // planted crops
            foreach (HoeDirt dirt in location.terrainFeatures.Values.OfType <HoeDirt>())
            {
                if (dirt.crop != null)
                {
                    yield return(dirt.crop);
                }
            }

            // garden pots
            foreach (IndoorPot pot in location.objects.Values.OfType <IndoorPot>())
            {
                Crop?crop = pot.hoeDirt.Value?.crop;
                if (crop != null)
                {
                    yield return(crop);
                }
            }
        }
コード例 #3
0
 public void CleanInventory(object obj, GameLocation?location, Farmer?who)
 {
     if (obj is T tobj)
     {
         CleanInventory(tobj, location, who);
     }
 }
コード例 #4
0
        private static bool Object_DayUpdatePostFarmEventOvernightActionsDelegate_Prefix(object __instance)
        {
            var locationField = __instance.GetType().GetTypeInfo().DeclaredFields.First(f => f.FieldType == typeof(GameLocation) && f.Name == "location");

            CurrentLocation          = (GameLocation?)locationField.GetValue(__instance);
            IsVanillaQueryInProgress = false;
            return(FlexibleSprinklers.Instance.SprinklerBehavior is ISprinklerBehavior.Independent);
        }
コード例 #5
0
 public WorkingInventory(object @object, IInventoryProvider provider, NetMutex?mutex, GameLocation?location, Farmer?player)
 {
     Object   = @object;
     Provider = provider;
     Mutex    = mutex;
     Location = location;
     Player   = player;
 }
コード例 #6
0
    public static bool WarpCharacter(NPC?character, GameLocation?targetLocation, XVector2 position)
    {
        if (!Config.IsUnconditionallyEnabled || !Config.Extras.Pathfinding.AllowNPCsOnFarm || !Config.Extras.Pathfinding.OptimizeWarpPoints)
        {
            return(true);
        }

        if (PathfindToNextScheduleLocation is null)
        {
            return(true);
        }

        if (character is null || Game1.player is not {
        } player)
        {
            return(true);
        }

        if (character.currentLocation is null)
        {
            return(true);
        }

        if (targetLocation is null)
        {
            return(true);
        }

        bool isFamily = false;

        // If the player has friendship data, check if the given character is married or a roommate.
        if (player.friendshipData.TryGetValue(character.Name, out var value))
        {
            isFamily = value.IsMarried() || value.IsRoommate();
        }
        // Check if the given character is a child.
        var characterChild = character as Child;

        if (!isFamily && (player.getChildren()?.Contains(characterChild) ?? false))
        {
            isFamily = true;
        }

        // https://github.com/aedenthorn/StardewValleyMods/blob/master/FreeLove/FarmerPatches.cs
        // If the character is family, a pet, or a spouse, run the logic.
        if (isFamily || character == player.getSpouse() || character == player.getPet())
        {
            // If the character is still sleeping, warp it because otherwise it just glides on the floor creepily.
            if (character.isSleeping.Value || character.layingDown)
            {
                return(true);
            }

            // If it's a pet, it appears that 'behavior 1' indicates sleeping.
            if (character is Pet {
                CurrentBehavior : Pet.behavior_Sleep or Pet.behavior_SitDown or Cat.behavior_Flop or Dog.behavior_SitSide
            })
コード例 #7
0
 /// <inheritdoc />
 public override ISubject?GetSubjectFor(object entity, GameLocation?location)
 {
     return(entity switch
     {
         FarmAnimal animal => this.BuildSubject(animal),
         Farmer player => this.BuildSubject(player),
         NPC npc => this.BuildSubject(npc),
         _ => null
     });
コード例 #8
0
        public override IList <Item?>?GetItems(Chest obj, GameLocation?location, Farmer?who)
        {
            if (who == null)
            {
                return(obj.items);
            }

            return(obj.GetItemsForPlayer(who.UniqueMultiplayerID));
        }
コード例 #9
0
ファイル: TileHelper.cs プロジェクト: watson81/StardewMods
        /*********
        ** Public methods
        *********/
        /****
        ** Location
        ****/
        /// <summary>Get the tile coordinates in the game location.</summary>
        /// <param name="location">The game location to search.</param>
        public static IEnumerable <Vector2> GetTiles(this GameLocation?location)
        {
            if (location?.Map?.Layers == null)
            {
                return(Enumerable.Empty <Vector2>());
            }

            Layer layer = location.Map.Layers[0];

            return(TileHelper.GetTiles(0, 0, layer.LayerWidth, layer.LayerHeight));
        }
コード例 #10
0
ファイル: ModEntry.cs プロジェクト: watson81/StardewMods
        /// <summary>Get whether the given location is the Small Beach Farm.</summary>
        /// <param name="location">The location to check.</param>
        /// <param name="farm">The farm instance.</param>
        private bool IsSmallBeachFarm(GameLocation?location, [NotNullWhen(true)] out Farm?farm)
        {
            if (Game1.whichModFarm?.ID == this.ModManifest.UniqueID && location is Farm {
                Name: "Farm"
            } farmInstance)
            {
                farm = farmInstance;
                return(true);
            }

            farm = null;
            return(false);
        }
コード例 #11
0
        /*********
        ** Private methods
        *********/
        /// <summary>Get whether time should be frozen in the given location.</summary>
        /// <param name="config">The mod configuration.</param>
        /// <param name="location">The location to check.</param>
        /// <param name="isCave">Whether the given location is a cave.</param>
        private bool ShouldFreezeTime(ModConfig config, GameLocation?location, out bool isCave)
        {
            isCave = location is MineShaft or FarmCave or VolcanoDungeon;
            bool isInside =
                !isCave &&
                location?.IsOutdoors == false &&
                location is not BugLand;    // incorrectly marked as indoors

            return
                (config.FreezeTime ||
                 (config.FreezeTimeCaves && isCave) ||
                 (config.FreezeTimeInside && isInside));
        }
コード例 #12
0
ファイル: ModAPI.cs プロジェクト: Pathoschild/smapi-mod-dump
    public bool OpenCraftingMenu(
        bool cooking,
        bool silent_open         = false,
        GameLocation?location    = null,
        Vector2?position         = null,
        Rectangle?area           = null,
        bool discover_containers = true,
        IList <Tuple <object, GameLocation> >?containers = null,
        IList <string>?listed_recipes = null
        )
    {
        if (listed_recipes == null && Mod.intCCStation != null)
        {
            listed_recipes = cooking ?
                             Mod.intCCStation.GetCookingRecipes() :
                             Mod.intCCStation.GetCraftingRecipes();
        }

        var menu = Game1.activeClickableMenu;

        if (menu != null)
        {
            if (!menu.readyToClose())
            {
                return(false);
            }

            CommonHelper.YeetMenu(menu);
            Game1.exitActiveMenu();
        }

        Game1.activeClickableMenu = Menus.BetterCraftingPage.Open(
            Mod,
            location,
            position,
            area,
            cooking: cooking,
            standalone_menu: true,
            material_containers: containers?.Select(val => new LocatedInventory(val.Item1, val.Item2)).ToList(),
            silent_open: silent_open,
            discover_containers: discover_containers,
            listed_recipes: listed_recipes
            );

        return(true);
    }
コード例 #13
0
        /*********
        ** Public methods
        *********/
        /// <summary>Determines whether the specified objects are equal.</summary>
        /// <returns>true if the specified objects are equal; otherwise, false.</returns>
        /// <param name="left">The first object to compare.</param>
        /// <param name="right">The second object to compare.</param>
        public bool Equals(GameLocation?left, GameLocation?right)
        {
            string?leftName  = left?.NameOrUniqueName;
            string?rightName = right?.NameOrUniqueName;

            if (leftName is null)
            {
                return(rightName is null);
            }

            if (rightName is null)
            {
                return(false);
            }

            return(leftName == rightName);
        }
コード例 #14
0
ファイル: Other.cs プロジェクト: Pathoschild/smapi-mod-dump
        // Narrates current location's name
        public static void narrateCurrentLocation()
        {
            currentLocation = Game1.currentLocation;

            if (currentLocation == null)
            {
                return;
            }

            if (previousLocation == currentLocation)
            {
                return;
            }

            previousLocation = currentLocation;
            MainClass.ScreenReader.Say($"{currentLocation.Name} Entered", true);
        }
コード例 #15
0
        public override bool IsValid(Chest obj, GameLocation?location, Farmer?who)
        {
            if (location != null)
            {
                Vector2?pos = GetTilePosition(obj, location, who);
                if (!pos.HasValue)
                {
                    return(false);
                }

                if (!TileHelper.GetObjectAtPosition(location, pos.Value, out var sobj) || sobj != obj)
                {
                    return(false);
                }
            }

            return(AllowedTypes.Contains(obj.SpecialChestType));
        }
コード例 #16
0
    public static bool IsSnowingHere(ref bool __result, GameLocation?location)
    {
        if (Precipitation != PrecipitationType.Snow)
        {
            if (Scene.Current is null)
            {
                return(true);
            }

            __result = false;
            return(false);
        }

        if (ReferenceEquals(location, Scene.SceneLocation.Value) || location is null)
        {
            __result = true;
            return(false);
        }

        return(true);
    }
コード例 #17
0
    public static bool PopulateRoutesFromLocationToLocationList()
    {
        if (!Config.IsUnconditionallyEnabled || !Config.Extras.OptimizeWarpPoints)
        {
            return(true);
        }

        var routeList = new ConcurrentBag <List <string> >();

        var locations = new Dictionary <string, GameLocation?>(Game1.locations.SelectF(location => new KeyValuePair <string, GameLocation?>(location.Name, location)));

        GameLocation?backwoodsLocation = Game1.locations.FirstOrDefaultF(location => location.Name == "Backwoods");

        // Iterate over every location in parallel, and collect all paths to every other location.
        Parallel.ForEach(Game1.locations, location => {
            if (Config.Extras.AllowNPCsOnFarm || location is not Farm && !ReferenceEquals(location, backwoodsLocation))
            {
                var route = new List <string>();
                ExploreWarpPointsImpl(location, route, routeList, locations);
            }
        });
コード例 #18
0
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="codex">Provides subject entries</param>
        /// <param name="gameHelper">Provides utility methods for interacting with the game code.</param>
        /// <param name="progressionMode">Whether to only show content once the player discovers it.</param>
        /// <param name="highlightUnrevealedGiftTastes">Whether to highlight item gift tastes which haven't been revealed in the NPC profile.</param>
        /// <param name="showAllGiftTastes">Whether to show all NPC gift tastes.</param>
        /// <param name="item">The underlying target.</param>
        /// <param name="context">The context of the object being looked up.</param>
        /// <param name="knownQuality">Whether the item quality is known. This is <c>true</c> for an inventory item, <c>false</c> for a map object.</param>
        /// <param name="location">The location containing the item, if applicable.</param>
        /// <param name="getCropSubject">Get a lookup subject for a crop.</param>
        /// <param name="fromCrop">The crop associated with the item (if applicable).</param>
        /// <param name="fromDirt">The dirt containing the crop (if applicable).</param>
        public ItemSubject(ISubjectRegistry codex, GameHelper gameHelper, bool progressionMode, bool highlightUnrevealedGiftTastes, bool showAllGiftTastes, Item item, ObjectContext context, bool knownQuality, GameLocation?location, Func <Crop, ObjectContext, HoeDirt?, ISubject> getCropSubject, Crop?fromCrop = null, HoeDirt?fromDirt = null)
            : base(gameHelper)
        {
            this.Codex           = codex;
            this.ProgressionMode = progressionMode;
            this.HighlightUnrevealedGiftTastes = highlightUnrevealedGiftTastes;
            this.ShowAllGiftTastes             = showAllGiftTastes;
            this.Target         = item;
            this.DisplayItem    = this.GetMenuItem(item);
            this.FromCrop       = fromCrop ?? fromDirt?.crop;
            this.FromDirt       = fromDirt;
            this.Context        = context;
            this.Location       = location;
            this.KnownQuality   = knownQuality;
            this.GetCropSubject = getCropSubject;

            this.SeedForCrop = item.ParentSheetIndex != 433 || this.FromCrop == null // ignore unplanted coffee beans (to avoid "see also: coffee beans" loop)
                ? this.TryGetCropForSeed(item)
                : null;

            this.Initialize(this.DisplayItem.DisplayName, this.GetDescription(this.DisplayItem), this.GetTypeValue(this.DisplayItem));
        }
コード例 #19
0
ファイル: ModAPI.cs プロジェクト: Pathoschild/smapi-mod-dump
    public bool OpenCraftingMenu(
        bool cooking,
        IList <Chest>?containers      = null,
        GameLocation?location         = null,
        Vector2?position              = null,
        bool silent_open              = false,
        IList <string>?listed_recipes = null
        )
    {
        var menu = Game1.activeClickableMenu;

        if (menu != null)
        {
            if (!menu.readyToClose())
            {
                return(false);
            }

            CommonHelper.YeetMenu(menu);
            Game1.exitActiveMenu();
        }

        Game1.activeClickableMenu = Menus.BetterCraftingPage.Open(
            Mod,
            location: location,
            position: position,
            cooking: cooking,
            standalone_menu: true,
            material_containers: containers?.ToList <object>(),
            discover_containers: true,
            silent_open: silent_open,
            listed_recipes: listed_recipes
            );

        return(true);
    }
コード例 #20
0
 /// <summary>Get the subject for an in-game entity.</summary>
 /// <param name="entity">The entity instance.</param>
 /// <param name="location">The location containing the entity, if applicable.</param>
 public ISubject?GetByEntity(object entity, GameLocation?location)
 {
     return(this.LookupProviders
            .Select(p => p.GetSubjectFor(entity, location))
            .FirstOrDefault(p => p != null));
 }
コード例 #21
0
 public override bool CanInsertItems(StorageFurniture obj, GameLocation?location, Farmer?who)
 {
     return(true);
 }
コード例 #22
0
 public override Vector2?GetTilePosition(StorageFurniture obj, GameLocation?location, Farmer?who)
 {
     return(obj.TileLocation);
 }
コード例 #23
0
 public override bool IsValid(StorageFurniture obj, GameLocation?location, Farmer?who)
 {
     return(true);
 }
コード例 #24
0
 public override NetMutex?GetMutex(StorageFurniture obj, GameLocation?location, Farmer?who)
 {
     return(obj.mutex);
 }
コード例 #25
0
 public override bool IsMutexRequired(StorageFurniture obj, GameLocation?location, Farmer?who)
 {
     return(true);
 }
コード例 #26
0
 public override Rectangle?GetMultiTileRegion(StorageFurniture obj, GameLocation?location, Farmer?who)
 {
     // TODO: Implement this
     return(null);
 }
コード例 #27
0
 public override bool IsItemValid(StorageFurniture obj, GameLocation?location, Farmer?who, Item item)
 {
     // TODO: Check if items are valid.
     return(true);
 }
コード例 #28
0
 public override IList <Item?>?GetItems(StorageFurniture obj, GameLocation?location, Farmer?who)
 {
     // TODO: Implement a managed item list that does the stuff storage
     // furniture does when accessing items.
     return(obj.heldItems);
 }
コード例 #29
0
 public override int GetActualCapacity(StorageFurniture obj, GameLocation?location, Farmer?who)
 {
     return(36);
 }
コード例 #30
0
 public override void CleanInventory(StorageFurniture obj, GameLocation?location, Farmer?who)
 {
     obj.ClearNulls();
 }