コード例 #1
0
 public static KeyValuePair <Vector2, TerrainFeature> checkRadiusForTerrainFeature(int radius, Type terrainType)
 {
     for (int x = -radius; x <= radius; x++)
     {
         for (int y = -radius; y <= radius; y++)
         {
             Vector2 pos = new Vector2((Game1.player.getTileX() + x), (Game1.player.getTileY() + y));
             bool    f   = Game1.player.currentLocation.isTerrainFeatureAt((int)pos.X, (int)pos.Y);
             if (f == false)
             {
                 continue;
             }
             TerrainFeature t = Game1.player.currentLocation.terrainFeatures[pos];  //((Game1.player.getTileX() + x) * Game1.tileSize, (Game1.player.getTileY() + y) * Game1.tileSize);
             if (t == null)
             {
                 continue;
             }
             if (t.GetType() == terrainType)
             {
                 return(new KeyValuePair <Vector2, TerrainFeature> (pos, t));
             }
         }
     }
     return(new KeyValuePair <Vector2, TerrainFeature>(new Vector2(), null));
 }
コード例 #2
0
        public List <Vector2> AnalyzeLocationInfo(GameLocation location)
        {
            foreach (KeyValuePair <Vector2, StardewValley.Object> entry in location.Objects.Pairs)
            {
                StardewValley.Object obj = entry.Value;
                Vector2 objectLocation   = entry.Key;

                this.monitor.Log($"Found {obj.Name} at {objectLocation.ToString()}", LogLevel.Info);
            }

            IEnumerable <KeyValuePair <Vector2, Chest> > chests = this.locationInformationHelper.FindAllInLocation <Chest>(location);

            this.monitor.Log($"Found {chests.Count()} chests");

            KeyValuePair <Vector2, Chest> chestAndLocation = chests.First();

            this.monitor.Log($"The first chest is at {chestAndLocation.Key.ToString()}", LogLevel.Info);

            foreach (Item item in chestAndLocation.Value.items)
            {
                this.monitor.Log($"Found {item.Stack} {item.Name} in chest", LogLevel.Info);
            }

            foreach (KeyValuePair <Vector2, TerrainFeature> tile in location.terrainFeatures.Pairs)
            {
                TerrainFeature item = tile.Value;
                Vector2        loc  = tile.Key;

                this.monitor.Log($"Found terrain feature {item.GetType().Name} at ${loc.ToString()}", LogLevel.Info);
            }

            List <Vector2> openSpaces = this.FindOpenSpaceAroundChest(location, chestAndLocation.Key, chestAndLocation.Value);

            return(openSpaces);
        }
コード例 #3
0
        public static bool performToolAction_Prefix(ref TerrainFeature __instance, Tool t, int damage, Vector2 tileLocation, GameLocation location, ref bool __result)
        {
            ModEntry.M.Log("performToolAction_Prefix A", StardewModdingAPI.LogLevel.Info);
            // Gotta have the original method available for mattock stand-ins.
            if (performToolActionOriginal == null)
            {
                return(true);
            }

            ModEntry.M.Log("performToolAction_Prefix B", StardewModdingAPI.LogLevel.Info);

            // If the tool is a mattock and this object is one that requires a specific type of tool that is supported,
            // run the function with a stand-in tool instead.
            if (t is Mattock mattock)
            {
                if (__instance is Tree || __instance is FruitTree || __instance is Bush || __instance is GiantCrop || __instance is Flooring)
                {
                    ModEntry.M.Log("Struck a feature:" + __instance.GetType().ToString(), StardewModdingAPI.LogLevel.Info);
                    // Treat the mattock as an axe for various terrain features.
                    Axe standinAxe = mattock.asAxe();
                    __result = (bool)performToolActionOriginal.Invoke(__instance, new object[] { __instance, standinAxe, damage, tileLocation, location });
                    return(false);
                }
                else if (__instance is ResourceClump clump)
                {
                    switch (clump.parentSheetIndex.Get())
                    {
                    case 600:                             // Stump
                    case 602:                             // Log
                    {
                        // Treat the mattock as an axe for stumps.
                        Axe standinAxe = mattock.asAxe();
                        __result = (bool)performToolActionOriginal.Invoke(__instance, new object[] { __instance, standinAxe, damage, tileLocation, location });
                        return(false);
                    }

                    case 622:                             // Iridium meteorite
                    case 672:                             // Boulder 1
                    case 752:                             // Boulder 2
                    case 754:                             // Boulder 3
                    case 756:                             // Icy Boulder 1
                    case 758:                             // Icy Boulder 2
                    {
                        // Treat the mattock as a pickaxe for boulders.
                        Pickaxe standinPickaxe = (t as Mattock).asPickaxe();
                        standinPickaxe.DoFunction(location, (int)(__instance.currentTileLocation.X * 64), (int)(__instance.currentTileLocation.Y * 64), 1, Game1.player);
                        //__result = (bool) performToolActionOriginal.Invoke(__instance, new object[] { __instance, standinPickaxe, damage, tileLocation, location });
                        return(false);
                    }
                    }
                }
            }

            // Otherwise, just do the default functionality.
            return(true);
        }
コード例 #4
0
        public TerrainFeatureUpdatePacket(GameLocation loc, Vector2 pos)
            : this()
        {
            location = Multiplayer.getUniqueLocationName(loc);
            posX     = pos.X;
            posY     = pos.Y;

            TerrainFeature tf = loc.terrainFeatures[pos];

            if (tf != null && tf.GetType() == typeof(TYPE))
            {
                str = Util.serialize <TYPE>(tf as TYPE);
            }
        }
コード例 #5
0
        static ValMap ToMap(TerrainFeature feature)
        {
            if (feature == null)
            {
                return(null);
            }
            var result = new ValMap();

            result.map[_type] = result["name"] = new ValString(feature.GetType().Name);
            if (feature is Tree tree)
            {
                result.map[_treeType]    = new ValNumber(tree.treeType.Value);
                result.map[_growthStage] = new ValNumber(tree.growthStage.Value);
                result.map[_health]      = new ValNumber(tree.health.Value);
                result.map[_stump]       = ValNumber.Truth(tree.stump.Value);
                result.map[_tapped]      = ValNumber.Truth(tree.tapped.Value);
                result.map[_hasSeed]     = ValNumber.Truth(tree.hasSeed.Value);
            }
            else if (feature is HoeDirt hoeDirt)
            {
                result.map[_dry] = ValNumber.Truth(hoeDirt.state.Value != 1);
                var crop = hoeDirt.crop;
                if (crop == null)
                {
                    result.map[_crop] = null;
                }
                else
                {
                    ValMap cropInfo = new ValMap();
                    cropInfo.map[_phase]         = new ValNumber(crop.currentPhase.Value);
                    cropInfo.map[_maxPhase]      = new ValNumber(crop.phaseDays.Count - 1);
                    cropInfo.map[_mature]        = ValNumber.Truth(crop.fullyGrown.Value);
                    cropInfo.map[_dead]          = ValNumber.Truth(crop.dead.Value);
                    cropInfo.map[_harvestMethod] = ValNumber.Truth(crop.harvestMethod.Value);
                    bool harvestable = (int)crop.currentPhase.Value >= crop.phaseDays.Count - 1 &&
                                       (!crop.fullyGrown.Value || (int)crop.dayOfCurrentPhase.Value <= 0);
                    cropInfo.map[_harvestable] = ValNumber.Truth(harvestable);

                    //Note: we might be able to get the name of the crop
                    // using crop.indexOfHarvest or crop.netSeedIndex
                    var product = new StardewValley.Object(crop.indexOfHarvest.Value, 0);
                    cropInfo.map[_name] = new ValString(product.DisplayName);

                    result.map[_crop] = cropInfo;
                }
            }
            return(result);
        }
コード例 #6
0
ファイル: ModEntry.cs プロジェクト: Fox536/TestMod
        private void SpawnTree(Farm farm, Vector2 point)
        {
            StardewValley.TerrainFeatures.Tree t = new Tree(1, 5);
            t.seasonUpdate(true);
            ClearResourceClump(ref farm.resourceClumps, point);
            TerrainFeature feature = null;

            if (farm.terrainFeatures.TryGetValue(point, out feature))
            {
                if (feature.GetType() != t.GetType())
                {
                    farm.terrainFeatures.Clear();
                    farm.terrainFeatures.Add(point, t);
                }
            }
            else
            {
                farm.terrainFeatures.Add(point, t);
            }
        }
コード例 #7
0
 public static KeyValuePair <Vector2, TerrainFeature> checkCardinalForTerrainFeature(Type terrainType)
 {
     for (int x = -1; x <= 1; x++)
     {
         for (int y = -1; y <= 1; y++)
         {
             if (x == -1 && y == -1)
             {
                 continue;                     //upper left
             }
             if (x == -1 && y == 1)
             {
                 continue;                    //bottom left
             }
             if (x == 1 && y == -1)
             {
                 continue;                    //upper right
             }
             if (x == 1 && y == 1)
             {
                 continue;                   //bottom right
             }
             Vector2 pos = new Vector2((Game1.player.getTileX() + x), (Game1.player.getTileY() + y));
             bool    f   = Game1.player.currentLocation.isTerrainFeatureAt((int)pos.X, (int)pos.Y);
             if (f == false)
             {
                 continue;
             }
             TerrainFeature t = Game1.player.currentLocation.terrainFeatures[pos];  //((Game1.player.getTileX() + x) * Game1.tileSize, (Game1.player.getTileY() + y) * Game1.tileSize);
             if (t == null)
             {
                 continue;
             }
             if (t.GetType() == terrainType)
             {
                 return(new KeyValuePair <Vector2, TerrainFeature>(pos, t));
             }
         }
     }
     return(new KeyValuePair <Vector2, TerrainFeature>(new Vector2(), null));
 }
コード例 #8
0
 private static void TerrainFeatures_OnValueRemoved(Vector2 key, TerrainFeature value)
 {
     monitor.Log($"value removed, {value.GetType()} {Environment.StackTrace}");
 }
コード例 #9
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);
                }
            }
        }