コード例 #1
0
 private static void _IncrementModData(SObject obj, GameLocation location, Farmer who)
 {
     if (Utility.SpecificPlayerHasProfession("Ecologist", who) && obj.isForage(location) && !Utility.IsForagedMineral(obj))
     {
         AwesomeProfessions.Data.IncrementField($"{AwesomeProfessions.UniqueID}/ItemsForaged", amount: 1);
     }
     else if (Utility.SpecificPlayerHasProfession("Gemologist", who) && Utility.IsForagedMineral(obj))
     {
         AwesomeProfessions.Data.IncrementField($"{AwesomeProfessions.UniqueID}/MineralsCollected", amount: 1);
     }
 }
コード例 #2
0
        public static bool ScytheForage(StardewValley.Object o, Tool t, GameLocation loc)
        {
            if (o.IsSpawnedObject && !o.questItem.Value && o.isForage(loc) && CanHarvestObject(o, HARVEST_SCYTHING))
            {
                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.
#pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator
                if (vector.X == 0 && vector.Y == 0)
                {
#pragma warning restore RECS0018 // Comparison of floating point numbers with equality operator
                    foreach (System.Collections.Generic.KeyValuePair <Vector2, StardewValley.Object> pair in loc.Objects.Pairs)
                    {
                        if (pair.Value.Equals(o))
                        {
                            vector = pair.Key;
                            break;
                        }
                    }
                }
                Random random = new Random((int)Game1.uniqueIDForThisGame / 2 + (int)Game1.stats.DaysPlayed + (int)vector.X + (int)vector.Y * 777);
                if (who.professions.Contains(16))
                {
                    o.Quality = 4;
                }
                else if (random.NextDouble() < (double)((float)who.ForagingLevel / 30))
                {
                    o.Quality = 2;
                }
                else if (random.NextDouble() < (double)((float)who.ForagingLevel / 15))
                {
                    o.Quality = 1;
                }
                vector *= 64.0f;
                who.gainExperience(2, 7);
                Game1.createItemDebris(o.getOne(), vector, -1, null, -1);
                Game1.stats.ItemsForaged += 1;
                if (who.professions.Contains(13) && random.NextDouble() < 0.2)
                {
                    Game1.createItemDebris(o.getOne(), vector, -1, null, -1);
                    who.gainExperience(2, 7);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #3
0
 private bool IsGrabbable(SObject obj)
 {
     if (obj.bigCraftable.Value)
     {
         return(false);
     }
     else if (obj.isForage(null) && obj.ParentSheetIndex != ItemIds.GoldenWalnut)
     {
         return(true);
     }
     else
     {
         return(ForageableItems.Contains(obj.ParentSheetIndex));
     }
 }
コード例 #4
0
        /** Determine whether the given object can be harvested using the given method.
         * Assumes that isForage() returned true. */
        public static bool CanHarvestObject(StardewValley.Object obj, GameLocation loc, int method)
        {
            // Get harvest settings from config
            ModConfig.HarvestModeClass config = getInstance().config.HarvestMode;
            HarvestModeEnum            mode;

            if (obj.IsSpawnedObject && !obj.questItem.Value && obj.isForage(loc))
            {
                mode = config.Forage;
            }
            else
            {
                mode = HARVEST_PLUCKING;
            }
            return(CanHarvest(mode, method));
        }
コード例 #5
0
        private static void CollectObj(GameLocation loc, SVObject obj)
        {
            Farmer who = Game1.player;

            Vector2 vector = Util.GetLocationOf(loc, obj);

            if ((int)vector.X == -1 && (int)vector.Y == -1)
            {
                return;
            }
            if (obj.questItem.Value)
            {
                return;
            }

            int    quality = obj.Quality;
            Random random  = new Random((int)Game1.uniqueIDForThisGame / 2 + (int)Game1.stats.DaysPlayed + (int)vector.X + (int)vector.Y * 777);

            if (who.professions.Contains(16) && obj.isForage(loc))
            {
                obj.Quality = 4;
            }

            else if (obj.isForage(loc))
            {
                if (random.NextDouble() < who.ForagingLevel / 30f)
                {
                    obj.Quality = 2;
                }
                else if (random.NextDouble() < who.ForagingLevel / 15f)
                {
                    obj.Quality = 1;
                }
            }

            if (who.couldInventoryAcceptThisItem(obj))
            {
                Logger.Log($"picked up {obj.DisplayName} at [{vector.X},{vector.Y}]");
                if (who.IsLocalPlayer)
                {
                    loc.localSound("pickUpItem");
                    DelayedAction.playSoundAfterDelay("coin", 300);
                }

                if (!who.isRidingHorse() && !who.ridingMineElevator)
                {
                    who.animateOnce(279 + who.FacingDirection);
                }

                if (!loc.isFarmBuildingInterior())
                {
                    if (obj.isForage(loc))
                    {
                        who.gainExperience(2, 7);
                    }
                }
                else
                {
                    who.gainExperience(0, 5);
                }

                who.addItemToInventoryBool(obj.getOne());
                Game1.stats.ItemsForaged++;
                if (who.professions.Contains(13) && random.NextDouble() < 0.2 && !obj.questItem.Value && who.couldInventoryAcceptThisItem(obj) && !loc.isFarmBuildingInterior())
                {
                    who.addItemToInventoryBool(obj.getOne());
                    who.gainExperience(2, 7);
                }
                loc.Objects.Remove(vector);
                return;
            }
            obj.Quality = quality;
        }
コード例 #6
0
        public static void clear(GameLocation location, Type[] types = null, int[] parentSheetIndices = null)
        {
            List <Vector2>             list  = new List <Vector2>();
            List <Vector2>             list2 = new List <Vector2>();
            List <LargeTerrainFeature> list3 = new List <LargeTerrainFeature>();

            foreach (Vector2 vector in location.terrainFeatures.Keys)
            {
                TerrainFeature terrainFeature = location.terrainFeatures[vector];
                bool           flag           = Generator.GeneratorOptions.ContainsKey("Crop") && Generator.GeneratorOptions["Crop"] && terrainFeature is HoeDirt;
                if (flag)
                {
                    (terrainFeature as HoeDirt).crop = null;
                }
                bool flag2 = types == null || types.Contains(terrainFeature.GetType()) || types.Contains(typeof(TerrainFeature));
                if (flag2)
                {
                    list.Add(vector);
                }
            }
            foreach (Vector2 vector2 in location.Objects.Keys)
            {
                SObject @object = location.objects[vector2];
                bool    flag3   = types == null || types.Contains(@object.GetType()) || (parentSheetIndices != null && parentSheetIndices.Contains(@object.ParentSheetIndex)) || types.Contains(typeof(SObject)) || (Generator.GeneratorOptions.ContainsKey("Forage") && Generator.GeneratorOptions["Forage"] && @object.isForage(location));
                if (flag3)
                {
                    list2.Add(vector2);
                }
            }
            foreach (LargeTerrainFeature largeTerrainFeature in location.largeTerrainFeatures)
            {
                bool flag4 = types == null || types.Contains(largeTerrainFeature.GetType());
                if (flag4)
                {
                    list3.Add(largeTerrainFeature);
                }
            }
            bool flag5 = location is Farm;

            if (flag5)
            {
                Farm farm = location as Farm;
                List <ResourceClump> list4 = new List <ResourceClump>();
                foreach (ResourceClump resourceClump in farm.resourceClumps)
                {
                    bool flag6 = types == null || types.Contains(resourceClump.GetType()) || (parentSheetIndices != null && parentSheetIndices.Contains(resourceClump.parentSheetIndex.Value));
                    if (flag6)
                    {
                        list4.Add(resourceClump);
                    }
                }
                foreach (ResourceClump resourceClump2 in list4)
                {
                    bool flag7 = farm.resourceClumps.Contains(resourceClump2);
                    if (flag7)
                    {
                        farm.resourceClumps.Remove(resourceClump2);
                    }
                }
            }
            bool flag8 = location is Woods;

            if (flag8)
            {
                Woods woods = location as Woods;
                List <ResourceClump> list5 = new List <ResourceClump>();
                foreach (ResourceClump resourceClump3 in woods.stumps)
                {
                    bool flag9 = types == null || types.Contains(resourceClump3.GetType()) || (parentSheetIndices != null && parentSheetIndices.Contains(resourceClump3.parentSheetIndex.Value));
                    if (flag9)
                    {
                        list5.Add(resourceClump3);
                    }
                }
                foreach (ResourceClump resourceClump4 in list5)
                {
                    bool flag10 = woods.stumps.Contains(resourceClump4);
                    if (flag10)
                    {
                        woods.stumps.Remove(resourceClump4);
                    }
                }
            }
            bool flag11 = location is Forest;

            if (flag11)
            {
                Forest forest = location as Forest;
                bool   flag12 = forest.log != null && parentSheetIndices != null && parentSheetIndices.Contains(forest.log.parentSheetIndex.Value);
                if (flag12)
                {
                    forest.log = null;
                }
            }
            foreach (Vector2 vector3 in list)
            {
                bool flag13 = location.terrainFeatures.ContainsKey(vector3);
                if (flag13)
                {
                    location.terrainFeatures.Remove(vector3);
                }
            }
            foreach (Vector2 vector4 in list2)
            {
                bool flag14 = location.objects.ContainsKey(vector4);
                if (flag14)
                {
                    location.objects.Remove(vector4);
                }
            }
            foreach (LargeTerrainFeature largeTerrainFeature2 in list3)
            {
                bool flag15 = location.largeTerrainFeatures.Contains(largeTerrainFeature2);
                if (flag15)
                {
                    location.largeTerrainFeatures.Remove(largeTerrainFeature2);
                }
            }
        }
コード例 #7
0
        private void LocationEvents_ObjectsChanged(object sender, EventArgsLocationObjectsChanged e)
        {
            if (!Config.DoGlobalForage)
            {
                return;
            }

            GameLocation foragerMap;

            foragerMap = Game1.getLocationFromName(Config.GlobalForageMap);
            if (foragerMap == null)
            {
                return;
            }

            foragerMap.Objects.TryGetValue(new Vector2(Config.GlobalForageTileX, Config.GlobalForageTileY), out Object grabber);

            if (grabber == null || !grabber.Name.Contains("Grabber"))
            {
                return;
            }


            System.Random random = new System.Random();
            foreach (KeyValuePair <Vector2, Object> pair in e.Added)
            {
                if (pair.Value.ParentSheetIndex != 430 || pair.Value.bigCraftable.Value)
                {
                    continue;
                }

                if ((grabber.heldObject.Value as Chest).items.Count >= 36)
                {
                    return;
                }

                Object obj = pair.Value;
                if (obj.Stack == 0)
                {
                    obj.Stack = 1;
                }

                if (!obj.isForage(null) && !IsGrabbableWorld(obj))
                {
                    continue;
                }

                if (Game1.player.professions.Contains(16))
                {
                    obj.Quality = 4;
                }
                else if (random.NextDouble() < Game1.player.ForagingLevel / 30.0)
                {
                    obj.Quality = 2;
                }
                else if (random.NextDouble() < Game1.player.ForagingLevel / 15.0)
                {
                    obj.Quality = 1;
                }

                if (Game1.player.professions.Contains(13))
                {
                    while (random.NextDouble() < 0.2)
                    {
                        obj.Stack += 1;
                    }
                }

                Monitor.Log($"Grabbing truffle: {obj.Stack}x{quality[obj.Quality]}", LogLevel.Trace);
                (grabber.heldObject.Value as Chest).addItem(obj);
                e.Location.Objects.Remove(pair.Key);

                if (Config.DoGainExperience)
                {
                    gainExperience(FORAGING, 7);
                }
            }

            if ((grabber.heldObject.Value as Chest).items.Count > 0)
            {
                grabber.showNextIndex.Value = true;
            }
        }