コード例 #1
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);
            }
        }
コード例 #2
0
        /// <summary>Apply the tool to the given tile.</summary>
        /// <param name="tile">The tile to modify.</param>
        /// <param name="tileObj">The object on the tile.</param>
        /// <param name="tileFeature">The feature on the tile.</param>
        /// <param name="player">The current player.</param>
        /// <param name="tool">The tool selected by the player (if any).</param>
        /// <param name="item">The item selected by the player (if any).</param>
        /// <param name="location">The current location.</param>
        public override bool Apply(Vector2 tile, SObject tileObj, TerrainFeature tileFeature, SFarmer player, Tool tool, Item item, GameLocation location)
        {
            // apply tool
            if (tool != null && this.CustomNames.Contains(tool.Name))
            {
                return(this.UseToolOnTile(tool, tile));
            }

            // apply item
            if (item != null && item.Stack > 0 && this.CustomNames.Contains(item.Name))
            {
                if (item is SObject obj && obj.canBePlacedHere(location, tile) && obj.placementAction(location, (int)(tile.X * Game1.tileSize), (int)(tile.Y * Game1.tileSize), player))
                {
                    this.ConsumeItem(player, item);
                    return(true);
                }
            }

            return(false);
        }
コード例 #3
0
        /****
        ** Methods
        ****/
        /// <summary>Grow all trees eligible for growth.</summary>
        private void GrowTrees()
        {
            foreach (GameLocation location in Game1.locations)
            {
                foreach (var entry in location.terrainFeatures)
                {
                    Vector2        tile    = entry.Key;
                    TerrainFeature feature = entry.Value;

                    if (this.Config.RegularTreesInstantGrow && feature is Tree)
                    {
                        this.GrowTree((Tree)feature, location, tile);
                    }
                    if (this.Config.FruitTreesInstantGrow && feature is FruitTree)
                    {
                        GrowFruitTree((FruitTree)feature, location, tile);
                    }
                }
            }
        }
コード例 #4
0
        private void Joystick_EndOfRouteReached(object sender, NpcMovementController.EndOfRouteReachedEventArgs e)
        {
            if (this.ai.CurrentController != this)
            {
                return;
            }

            if (this.targetObject != null)
            {
                this.targetObject.performUseAction(this.Forager.getTileLocation(), this.Forager.currentLocation);
                this.ignoreList.Add(this.targetObject);
            }
            else
            {
                this.Forager.currentLocation.localSound("leafrustle");
                this.Forager.currentLocation.temporarySprites.Add(new TemporaryAnimatedSprite("TileSheets\\animations", new Rectangle(0, 1085, 58, 58), 60f, 8, 0, this.Forager.GetGrabTile() * 64, false, this.Forager.FacingDirection == 3, 1f, 0.0f, Color.White, 1f, 0.0f, 0.0f, 0.0f, false));
            }

            double potentialChance = 0.02 + 1.0 / (this.foragedObjects.Count + 1) + this.Leader.LuckLevel / 100.0 + this.Leader.DailyLuck;
            double boost           = this.Leader.professions.Contains(Farmer.gatherer) ? 2.0 : 1.0;
            double realChance      = potentialChance * 0.33 + (this.ForagingLevel + 1) * 0.005 * boost;
            double current         = this.r.NextDouble();

            if (this.ai.Monitor.IsVerbose)
            {
                this.ai.Monitor.VerboseLog($"(Pick forage) Companion foraging level: {this.ForagingLevel} " +
                                           $"| potential chance: {potentialChance} " +
                                           $"| boost: {boost} " +
                                           $"| real chance: {realChance} " +
                                           $"| current: {current} " +
                                           $"| passed: {(current < realChance ? "Yes" : "No")}");
            }

            if (current < realChance || NpcAdventureMod.DebugFlags.Contains("forager.pickAlways"))
            {
                this.PickForageObject(this.targetObject);
            }

            this.targetObject = null;
            this.IsIdle       = true;
        }
コード例 #5
0
        /// <summary>Apply the tool to the given tile.</summary>
        /// <param name="tile">The tile to modify.</param>
        /// <param name="tileObj">The object on the tile.</param>
        /// <param name="tileFeature">The feature on the tile.</param>
        /// <param name="player">The current player.</param>
        /// <param name="tool">The tool selected by the player (if any).</param>
        /// <param name="item">The item selected by the player (if any).</param>
        /// <param name="location">The current location.</param>
        public override bool Apply(Vector2 tile, SObject tileObj, TerrainFeature tileFeature, Farmer player, Tool tool, Item item, GameLocation location)
        {
            if (item == null || item.Stack <= 0)
            {
                return(false);
            }

            switch (item.ParentSheetIndex)
            {
            // tree fertilizer
            case 805:
                if (tileFeature is Tree tree && !tree.fertilized.Value && tree.growthStage.Value < Tree.treeStage && tree.fertilize(location))
                {
                    this.ConsumeItem(player, item);
                    return(true);
                }
                return(false);

            // crop fertilizer
            default:
                // get unfertilised dirt
                if (!this.TryGetHoeDirt(tileFeature, tileObj, out HoeDirt dirt, out bool dirtCoveredByObj, out _) || dirt.fertilizer.Value != HoeDirt.noFertilizer)
                {
                    return(false);
                }

                // ignore if there's a giant crop, meteorite, etc covering the tile
                if (dirtCoveredByObj || this.GetResourceClumpCoveringTile(location, tile) != null)
                {
                    return(false);
                }

                // apply fertilizer
                bool fertilized = dirt.plant(item.ParentSheetIndex, (int)tile.X, (int)tile.Y, player, isFertilizer: true, location);
                if (fertilized)
                {
                    this.ConsumeItem(player, item);
                }
                return(fertilized);
            }
        }
コード例 #6
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));
 }
コード例 #7
0
        protected bool TryGetHoeDirt(TerrainFeature terrain, SObject obj, out HoeDirt dirt, out bool isCoveredByObj)
        {
            //Check to see if it's a garden pot
            if (obj is IndoorPot pot)
            {
                dirt           = pot.hoeDirt.Value;
                isCoveredByObj = false;
                return(true);
            }
            //Check to see if it's normal dirt
            if ((dirt = terrain as HoeDirt) != null)
            {
                isCoveredByObj = obj != null;
                return(true);
            }

            //Found nothing
            dirt           = null;
            isCoveredByObj = false;
            return(false);
        }
コード例 #8
0
        /// <summary>Apply the tool to the given tile.</summary>
        /// <param name="tile">The tile to modify.</param>
        /// <param name="tileObj">The object on the tile.</param>
        /// <param name="tileFeature">The feature on the tile.</param>
        /// <param name="player">The current player.</param>
        /// <param name="tool">The tool selected by the player (if any).</param>
        /// <param name="item">The item selected by the player (if any).</param>
        /// <param name="location">The current location.</param>
        public override bool Apply(Vector2 tile, SObject tileObj, TerrainFeature tileFeature, SFarmer player, Tool tool, Item item, GameLocation location)
        {
            if (!this.Enable)
            {
                return(false);
            }

            if (!(tileFeature is HoeDirt dirt) || dirt.state == HoeDirt.watered)
            {
                return(false);
            }

            WateringCan can       = (WateringCan)tool;
            int         prevWater = can.WaterLeft;

            can.WaterLeft = 100;
            this.UseToolOnTile(tool, tile);
            can.WaterLeft = prevWater;

            return(true);
        }
コード例 #9
0
        /// <summary>Apply the tool to the given tile.</summary>
        /// <param name="tile">The tile to modify.</param>
        /// <param name="tileObj">The object on the tile.</param>
        /// <param name="tileFeature">The feature on the tile.</param>
        /// <param name="player">The current player.</param>
        /// <param name="tool">The tool selected by the player (if any).</param>
        /// <param name="item">The item selected by the player (if any).</param>
        /// <param name="location">The current location.</param>
        public override bool Apply(Vector2 tile, SObject tileObj, TerrainFeature tileFeature, Farmer player, Tool tool, Item item, GameLocation location)
        {
            // clear weeds
            if (this.Config.ClearWeeds && this.IsWeed(tileObj))
            {
                return(this.UseToolOnTile(tool, tile));
            }

            // till plain dirt
            if (this.Config.TillDirt && tileFeature == null && tileObj == null)
            {
                return(this.UseToolOnTile(tool, tile));
            }

            // collect artifact spots
            if (this.Config.DigArtifactSpots && tileObj?.ParentSheetIndex == HoeAttachment.ArtifactSpotItemID)
            {
                return(this.UseToolOnTile(tool, tile));
            }

            return(false);
        }
コード例 #10
0
        /// <summary>Get the tilled dirt for a tile, if any.</summary>
        /// <param name="tileFeature">The feature on the tile.</param>
        /// <param name="tileObj">The object on the tile.</param>
        /// <param name="dirt">The tilled dirt found, if any.</param>
        /// <param name="isCoveredByObj">Whether there's an object placed over the tilled dirt.</param>
        /// <returns>Returns whether tilled dirt was found.</returns>
        protected bool TryGetHoeDirt(TerrainFeature tileFeature, SObject tileObj, out HoeDirt dirt, out bool isCoveredByObj)
        {
            // garden pot
            if (tileObj is IndoorPot pot)
            {
                dirt           = pot.hoeDirt.Value;
                isCoveredByObj = false;
                return(true);
            }

            // regular dirt
            if ((dirt = tileFeature as HoeDirt) != null)
            {
                isCoveredByObj = tileObj != null;
                return(true);
            }

            // none found
            dirt           = null;
            isCoveredByObj = false;
            return(false);
        }
コード例 #11
0
        /// <summary>Apply the tool to the given tile.</summary>
        /// <param name="tile">The tile to modify.</param>
        /// <param name="tileObj">The object on the tile.</param>
        /// <param name="tileFeature">The feature on the tile.</param>
        /// <param name="player">The current player.</param>
        /// <param name="tool">The tool selected by the player (if any).</param>
        /// <param name="item">The item selected by the player (if any).</param>
        /// <param name="location">The current location.</param>
        public override bool Apply(Vector2 tile, SObject tileObj, TerrainFeature tileFeature, SFarmer player, Tool tool, Item item, GameLocation location)
        {
            // clear twigs & weeds
            if (tileObj?.Name == "Twig" || tileObj?.Name.ToLower().Contains("weed") == true)
            {
                return(this.UseToolOnTile(tool, tile));
            }

            // cut non-fruit tree
            if (tileFeature is Tree)
            {
                return(this.CutTrees && this.UseToolOnTile(tool, tile));
            }

            // cut fruit tree
            if (tileFeature is FruitTree)
            {
                return(this.CutFruitTrees && this.UseToolOnTile(tool, tile));
            }

            // clear crops
            if (tileFeature is HoeDirt dirt && dirt.crop != null && (dirt.crop.dead || this.ClearCrops))
            {
                return(this.UseToolOnTile(tool, tile));
            }

            // clear stumps
            // This needs to check if the axe upgrade level is high enough first, to avoid spamming
            // 'need to upgrade your tool' messages. Based on ResourceClump.performToolAction.
            {
                ResourceClump clump = this.GetResourceClumpCoveringTile(location, tile);
                if (clump != null && this.ResourceUpgradeLevelsNeeded.ContainsKey(clump.parentSheetIndex) && tool.upgradeLevel >= this.ResourceUpgradeLevelsNeeded[clump.parentSheetIndex])
                {
                    this.UseToolOnTile(tool, tile);
                }
            }

            return(false);
        }
コード例 #12
0
 public Tile(string terrain, string feature, int base_buildingCapacity, int base_popCapacity)
 {
     if (TerrainType.instances.Exists(t => t.name == terrain))
     {
         this.terrain = TerrainType.instances.Find(t => t.name == terrain);
     }
     else
     {
         Debug.Log("ERROR: No terrain named " + terrain + " exists.");
     }
     if (TerrainFeature.instances.Exists(t => t.name == feature))
     {
         this.feature = TerrainFeature.instances.Find(t => t.name == feature);
     }
     else
     {
         Debug.Log("ERROR: No feature named " + terrain + " exists.");
     }
     this.base_buildingCapacity = base_buildingCapacity;
     this.base_popCapacity      = base_popCapacity;
     instances.Add(this);
 }
コード例 #13
0
        public override bool Apply(Vector2 tile, SObject tileObj, TerrainFeature tileFeature, SFarmer who, Tool tool, Item item, GameLocation location)
        {
            if (_config.CutDebris && (tileObj?.Name == "Twig" || tileObj?.Name.ToLower().Contains("weed") == true))
            {
                return(UseToolOnTile(tool, tile));
            }

            switch (tileFeature)
            {
            case Tree tree:
                if (_config.CutTrees)
                {
                    return(UseToolOnTile(tool, tile));
                }
                break;

            case HoeDirt dirt when dirt.crop != null:
                if (_config.CutDeadCrops && dirt.crop.dead.Value)
                {
                    return(UseToolOnTile(tool, tile));
                }
                if (_config.CutLiveCrops && !dirt.crop.dead.Value)
                {
                    return(UseToolOnTile(tool, tile));
                }
                break;
            }


            if (_config.CutDebris)
            {
                ResourceClump rc = ResourceClumpCoveringTile(location, tile);
                if (rc != null && _resourceUpgradeNeeded.ContainsKey(rc.parentSheetIndex.Value) && tool.UpgradeLevel >= _resourceUpgradeNeeded[rc.parentSheetIndex.Value])
                {
                    UseToolOnTile(tool, tile);
                }
            }
            return(false);
        }
コード例 #14
0
        /// <summary>Apply the tool to the given tile.</summary>
        /// <param name="tile">The tile to modify.</param>
        /// <param name="tileObj">The object on the tile.</param>
        /// <param name="tileFeature">The feature on the tile.</param>
        /// <param name="player">The current player.</param>
        /// <param name="tool">The tool selected by the player (if any).</param>
        /// <param name="item">The item selected by the player (if any).</param>
        /// <param name="location">The current location.</param>
        public override bool Apply(Vector2 tile, SObject tileObj, TerrainFeature tileFeature, Farmer player, Tool tool, Item item, GameLocation location)
        {
            // clear dead crops
            if (this.Config.ClearDeadCrops && tileFeature is HoeDirt dirt && dirt.crop != null && dirt.crop.dead.Value)
            {
                return(this.UseToolOnTile(this.FakePickaxe, tile, player, location));
            }

            // break mine containers
            if (this.Config.BreakMineContainers && tileObj is BreakableContainer container)
            {
                return(container.performToolAction(tool, location));
            }

            // attack monsters
            if (this.Config.AttackMonsters)
            {
                return(this.UseWeaponOnTile((MeleeWeapon)tool, tile, player, location));
            }

            return(false);
        }
コード例 #15
0
        public virtual void OnRequestGourmandCheck()
        {
            if (!Game1.IsMasterGame)
            {
                return;
            }
            string     gourmand_response = "";
            IslandWest island_farm       = Game1.getLocationFromName("IslandWest") as IslandWest;

            foreach (Vector2 key in island_farm.terrainFeatures.Keys)
            {
                TerrainFeature feature = island_farm.terrainFeatures[key];
                if (!(feature is HoeDirt))
                {
                    continue;
                }
                HoeDirt dirt = feature as HoeDirt;
                if (dirt.crop == null)
                {
                    continue;
                }
                bool harvestable = (int)dirt.crop.currentPhase >= dirt.crop.phaseDays.Count - 1 && (!dirt.crop.fullyGrown || (int)dirt.crop.dayOfCurrentPhase <= 0);
                if (dirt.crop.indexOfHarvest.Value == IndexForRequest(gourmandRequestsFulfilled.Value))
                {
                    if (harvestable)
                    {
                        Point target_tile      = new Point((int)key.X, (int)key.Y);
                        Point player_tile      = FindNearbyUnoccupiedTileThatFitsCharacter(island_farm, target_tile.X, target_tile.Y);
                        Point gourmand_tile    = FindNearbyUnoccupiedTileThatFitsCharacter(island_farm, target_tile.X, target_tile.Y, 2, player_tile);
                        int   farmer_direction = GetRelativeDirection(player_tile, target_tile);
                        gourmandResponseEvent.Fire(key.X + " " + key.Y + " " + player_tile.X + " " + player_tile.Y + " " + farmer_direction + " " + gourmand_tile.X + " " + gourmand_tile.Y + " 2");
                        return;
                    }
                    gourmand_response = "inProgress";
                }
            }
            gourmandResponseEvent.Fire(gourmand_response);
        }
コード例 #16
0
        internal static BaseFeatureSaveData CreateFeatureSaveData(Vector2 position, TerrainFeature feature,
                                                                  IReflectionHelper helper)
        {
            switch (feature)
            {
            case Tree tree:
                return(new TreeSaveData(position, tree));

            case FruitTree fruitTree:
                return(new FruitTreeSaveData(position, fruitTree));

            case CosmeticPlant cosmeticPlant:
                return(new CosmeticPlantSaveData(position, cosmeticPlant));

            case Grass grass:
                return(new GrassSaveData(position, grass));

            case DiggableWall wall:
                return(new DiggableWallSaveData(position, wall, helper));
            }

            return(new BaseFeatureSaveData(position, feature));
        }
コード例 #17
0
        /// <summary>Handle a game update if <see cref="ICheat.OnSaveLoaded"/> indicated updates were needed.</summary>
        /// <param name="context">The cheat context.</param>
        /// <param name="e">The update event arguments.</param>
        public override void OnUpdated(CheatContext context, UpdateTickedEventArgs e)
        {
            // skip if not using a tool
            if (!Context.IsPlayerFree || !Game1.player.UsingTool || !(Game1.player.CurrentTool is Axe || Game1.player.CurrentTool is Pickaxe))
            {
                return;
            }

            Farmer player = Game1.player;
            var    tool   = player.CurrentTool;

            // get affected tile
            Vector2 tile = new Vector2((int)player.GetToolLocation().X / Game1.tileSize, (int)player.GetToolLocation().Y / Game1.tileSize);

            // break stones
            if (tool is Pickaxe && player.currentLocation.objects.ContainsKey(tile))
            {
                Object obj = player.currentLocation.Objects[tile];
                if (obj != null && obj.name == "Stone")
                {
                    obj.MinutesUntilReady = 0;
                }
            }

            // break trees
            if (tool is Axe && player.currentLocation.terrainFeatures.ContainsKey(tile))
            {
                TerrainFeature obj = player.currentLocation.terrainFeatures[tile];
                if (obj is Tree tree && tree.health.Value > 1)
                {
                    tree.health.Value = 1;
                }
                else if (obj is FruitTree fruitTree && fruitTree.health.Value > 1)
                {
                    fruitTree.health.Value = 1;
                }
            }
コード例 #18
0
        public override bool GrabFeature(Vector2 tile, TerrainFeature feature)
        {
            if (Config.fruitTrees && feature is FruitTree tree && IsHarvestableFruitTree(tree))
            {
                // impl @ StardewValley::FruitTree::shake
                var daysUntilMature     = tree.daysUntilMature.Value;
                var isStruckByLightning = tree.struckByLightningCountdown.Value > 0;

                var fruitQuality = SObject.lowQuality;
                if (isStruckByLightning)
                {
                    fruitQuality = SObject.lowQuality;
                }
                else if (daysUntilMature <= -336)
                {
                    fruitQuality = SObject.bestQuality;
                }
                else if (daysUntilMature <= -224)
                {
                    fruitQuality = SObject.highQuality;
                }
                else if (daysUntilMature <= -112)
                {
                    fruitQuality = SObject.medQuality;
                }

                var crop = new SObject(isStruckByLightning ? ItemIds.Coal : tree.indexOfFruit.Value, tree.fruitsOnTree.Value, false, -1, fruitQuality);
                if (TryAddItem(crop))
                {
                    tree.fruitsOnTree.Value = 0;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
コード例 #19
0
        public override IEnumerable <ITarget> GetTargets(GameLocation location, Vector2 lookupTile)
        {
            // map objects
            foreach (KeyValuePair <Vector2, SObject> pair in location.objects.Pairs)
            {
                if (location is IslandShrine && pair.Value is ItemPedestal)
                {
                    continue; // part of the Fern Islands shrine puzzle, which is handled by the tile lookup provider
                }
                if (this.GameHelper.CouldSpriteOccludeTile(pair.Key, lookupTile))
                {
                    yield return(new ObjectTarget(this.GameHelper, pair.Value, pair.Key, this.Reflection, () => this.BuildSubject(pair.Value, ObjectContext.World, knownQuality: false)));
                }
            }

            // furniture
            foreach (var furniture in location.furniture)
            {
                Vector2 entityTile = furniture.TileLocation;
                if (this.GameHelper.CouldSpriteOccludeTile(entityTile, lookupTile))
                {
                    yield return(new ObjectTarget(this.GameHelper, furniture, entityTile, this.Reflection, () => this.BuildSubject(furniture, ObjectContext.Inventory)));
                }
            }

            // crops
            foreach (KeyValuePair <Vector2, TerrainFeature> pair in location.terrainFeatures.Pairs)
            {
                Vector2        entityTile = pair.Key;
                TerrainFeature feature    = pair.Value;

                if (feature is HoeDirt dirt && dirt.crop != null && this.GameHelper.CouldSpriteOccludeTile(entityTile, lookupTile))
                {
                    yield return(new CropTarget(this.GameHelper, dirt, entityTile, this.Reflection, this.JsonAssets, () => this.BuildSubject(dirt.crop, ObjectContext.World)));
                }
            }
        }
コード例 #20
0
        /// <summary>Apply the tool to the given tile.</summary>
        /// <param name="tile">The tile to modify.</param>
        /// <param name="tileObj">The object on the tile.</param>
        /// <param name="tileFeature">The feature on the tile.</param>
        /// <param name="player">The current player.</param>
        /// <param name="tool">The tool selected by the player (if any).</param>
        /// <param name="item">The item selected by the player (if any).</param>
        /// <param name="location">The current location.</param>
        public override bool Apply(Vector2 tile, SObject tileObj, TerrainFeature tileFeature, SFarmer player, Tool tool, Item item, GameLocation location)
        {
            if (item == null || item.Stack <= 0)
            {
                return(false);
            }

            // get dirt
            if (!(tileFeature is HoeDirt dirt) || dirt.fertilizer != HoeDirt.noFertilizer)
            {
                return(false);
            }

            // ignore if there's a giant crop, meteorite, etc covering the tile
            if (this.GetResourceClumpCoveringTile(location, tile) != null)
            {
                return(false);
            }

            // apply fertiliser
            dirt.fertilizer = item.parentSheetIndex;
            this.ConsumeItem(player, item);
            return(true);
        }
コード例 #21
0
ファイル: ModEntry.cs プロジェクト: InkyQuill/StardewMods-1
        //Update tick - check for removed grass and spawn hay if appropriate
        private void EighthUpdateTick(object sender, EventArgs e)
        {
            if (Game1.currentLocation?.terrainFeatures == null || lastTerrainFeatures == null || Game1.currentLocation != currentLocation)
            {
                return;
            }


            foreach (var item in this.lastTerrainFeatures.Where(x => x.Value is Grass && IsWithinRange(Game1.player.getTileLocation(), x.Key, 4)))
            {
                TerrainFeature x = null;
                if (!this.currentLocation.terrainFeatures.TryGetValue(item.Key, out x) || !(x is Grass))
                {
                    if (((Game1.IsMultiplayer ? Game1.recentMultiplayerRandom : new Random((int)((double)Game1.uniqueIDForThisGame + (double)item.Key.X * 1000.0 + (double)item.Key.Y * 11.0))).NextDouble() < 0.5))
                    {
                        if (Game1.player.CurrentTool is MeleeWeapon && (Game1.player.CurrentTool.Name.Contains("Scythe") || Game1.player.CurrentTool.parentSheetIndex == 47))
                        {
                            if (dropGrassStarterRandom.NextDouble() < config.ChanceToDropGrassStarterInsteadOfHay)
                            {
                                AttemptToGiveGrassStarter(item.Key, Game1.getFarm().piecesOfHay == Utility.numSilos() * 240);
                            }
                            else if (Game1.getFarm().tryToAddHay(1) != 0)
                            {
                                if (!BetterHayGrass.TryAddItemToInventory(178) && config.DropHayOnGroundIfNoRoomInInventory)
                                {
                                    BetterHayGrass.DropOnGround(item.Key, 178);
                                }
                            }
                        }
                    }
                }
            }

            lastTerrainFeatures = Game1.currentLocation?.terrainFeatures?.Pairs.ToDictionary(entry => entry.Key,
                                                                                             entry => entry.Value);
        }
コード例 #22
0
        public override IEnumerable <ITarget> GetTargets(GameLocation location, Vector2 lookupTile)
        {
            // map objects
            foreach (KeyValuePair <Vector2, SObject> pair in location.objects.Pairs)
            {
                if (this.GameHelper.CouldSpriteOccludeTile(pair.Key, lookupTile))
                {
                    yield return(new ObjectTarget(this.GameHelper, pair.Value, pair.Key, this.Reflection, () => this.BuildSubject(pair.Value, ObjectContext.World, knownQuality: false)));
                }
            }

            // furniture
            if (location is DecoratableLocation decoratableLocation)
            {
                foreach (var furniture in decoratableLocation.furniture)
                {
                    Vector2 entityTile = furniture.TileLocation;
                    if (this.GameHelper.CouldSpriteOccludeTile(entityTile, lookupTile))
                    {
                        yield return(new ObjectTarget(this.GameHelper, furniture, entityTile, this.Reflection, () => this.BuildSubject(furniture, ObjectContext.Inventory)));
                    }
                }
            }

            // crops
            foreach (KeyValuePair <Vector2, TerrainFeature> pair in location.terrainFeatures.Pairs)
            {
                Vector2        entityTile = pair.Key;
                TerrainFeature feature    = pair.Value;

                if (feature is HoeDirt dirt && dirt.crop != null && this.GameHelper.CouldSpriteOccludeTile(entityTile, lookupTile))
                {
                    yield return(new CropTarget(this.GameHelper, dirt, entityTile, this.Reflection, this.JsonAssets, () => this.BuildSubject(dirt.crop, ObjectContext.World)));
                }
            }
        }
コード例 #23
0
        private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
        {
            if (!e.IsMultipleOf(4))
            {
                return;
            }

            #region GetTileUnderCursor

            // get tile under cursor
            _currentTileBuilding = Game1.currentLocation is BuildableGameLocation buildableLocation
                ? buildableLocation.getBuildingAt(Game1.currentCursorTile)
                : null;

            if (Game1.currentLocation != null)
            {
                if (Game1.currentLocation.Objects == null ||
                    !Game1.currentLocation.Objects.TryGetValue(Game1.currentCursorTile, out _currentTile))
                {
                    _currentTile = null;
                }

                if (Game1.currentLocation.terrainFeatures == null ||
                    !Game1.currentLocation.terrainFeatures.TryGetValue(Game1.currentCursorTile, out _terrain))
                {
                    if (_currentTile is IndoorPot pot &&
                        pot.hoeDirt.Value != null)
                    {
                        _terrain = pot.hoeDirt.Value;
                    }
                    else
                    {
                        _terrain = null;
                    }
                }
            }
コード例 #24
0
        /// <summary>Apply the tool to the given tile.</summary>
        /// <param name="tile">The tile to modify.</param>
        /// <param name="tileObj">The object on the tile.</param>
        /// <param name="tileFeature">The feature on the tile.</param>
        /// <param name="player">The current player.</param>
        /// <param name="tool">The tool selected by the player (if any).</param>
        /// <param name="item">The item selected by the player (if any).</param>
        /// <param name="location">The current location.</param>
        public override bool Apply(Vector2 tile, SObject tileObj, TerrainFeature tileFeature, Farmer player, Tool tool, Item item, GameLocation location)
        {
            if (item == null || item.Stack <= 0)
            {
                return(false);
            }

            // get empty dirt
            if (!this.TryGetHoeDirt(tileFeature, tileObj, out HoeDirt dirt, out bool dirtCoveredByObj) || dirt.crop != null || dirt.fertilizer.Value != HoeDirt.noFertilizer)
            {
                return(false);
            }

            // ignore if there's a giant crop, meteorite, etc covering the tile
            if (dirtCoveredByObj || this.GetResourceClumpCoveringTile(location, tile) != null)
            {
                return(false);
            }

            // apply fertiliser
            dirt.fertilizer.Value = item.ParentSheetIndex;
            this.ConsumeItem(player, item);
            return(true);
        }
コード例 #25
0
        /// <summary>Apply the tool to the given tile.</summary>
        /// <param name="tile">The tile to modify.</param>
        /// <param name="tileObj">The object on the tile.</param>
        /// <param name="tileFeature">The feature on the tile.</param>
        /// <param name="player">The current player.</param>
        /// <param name="tool">The tool selected by the player (if any).</param>
        /// <param name="item">The item selected by the player (if any).</param>
        /// <param name="location">The current location.</param>
        public override bool Apply(Vector2 tile, SObject tileObj, TerrainFeature tileFeature, SFarmer player, Tool tool, Item item, GameLocation location)
        {
            if (item == null || item.Stack <= 0)
            {
                return(false);
            }

            // get dirt
            HoeDirt dirt = tileFeature as HoeDirt;

            if (dirt == null || dirt.crop != null)
            {
                return(false);
            }

            // sow seeds
            bool sowed = dirt.plant(item.parentSheetIndex, (int)tile.X, (int)tile.Y, player);

            if (sowed)
            {
                this.ConsumeItem(player, item);
            }
            return(sowed);
        }
コード例 #26
0
ファイル: ModEntry.cs プロジェクト: somnomania/smapi-mod-dump
        private string GetTerrainName(TerrainFeature t)
        {
            string outter = "";

            switch (t)
            {
            case Tree tree:
                Monitor.Log(tree.treeType.Value.ToString());

                break;

            default:
                outter = "Nothing Dork.";
                break;
            }

            /*
             * if (t is Tree tree)
             *  outter = Game1.objectInformation[tree.];
             * else
             *  outter = "Nothing Dork.";*/

            return(outter);
        }
コード例 #27
0
 /// <summary>Get whether a map terrain feature is a crop.</summary>
 /// <param name="terrain">The map terrain feature.</param>
 private bool IsCrop(TerrainFeature terrain)
 {
     return(terrain is HoeDirt dirt && dirt.crop != null);
 }
コード例 #28
0
 /// <summary>Get whether a terrain feature is automatable.</summary>
 /// <param name="location">The location to check.</param>
 /// <param name="tile">The tile to check.</param>
 /// <param name="terrainFeature">The terrain feature to check.</param>
 public bool IsAutomatable(GameLocation location, Vector2 tile, TerrainFeature terrainFeature)
 {
     return(this.GetEntityFor(location, tile, terrainFeature) != null);
 }
コード例 #29
0
        /****
        ** Targets
        ****/
        /// <summary>Get all potential lookup targets in the current location.</summary>
        /// <param name="location">The current location.</param>
        /// <param name="originTile">The tile from which to search for targets.</param>
        /// <param name="includeMapTile">Whether to allow matching the map tile itself.</param>
        public IEnumerable <ITarget> GetNearbyTargets(GameLocation location, Vector2 originTile, bool includeMapTile)
        {
            // NPCs
            foreach (NPC npc in location.characters)
            {
                if (!this.GameHelper.CouldSpriteOccludeTile(npc.getTileLocation(), originTile))
                {
                    continue;
                }

                TargetType type = TargetType.Unknown;
                if (npc is Child || npc.isVillager())
                {
                    type = TargetType.Villager;
                }
                else if (npc is Horse)
                {
                    type = TargetType.Horse;
                }
                else if (npc is Junimo)
                {
                    type = TargetType.Junimo;
                }
                else if (npc is Pet)
                {
                    type = TargetType.Pet;
                }
                else if (npc is Monster)
                {
                    type = TargetType.Monster;
                }

                yield return(new CharacterTarget(this.GameHelper, type, npc, npc.getTileLocation(), this.Reflection));
            }

            // animals
            foreach (FarmAnimal animal in (location as Farm)?.animals.Values ?? (location as AnimalHouse)?.animals.Values ?? Enumerable.Empty <FarmAnimal>())
            {
                if (!this.GameHelper.CouldSpriteOccludeTile(animal.getTileLocation(), originTile))
                {
                    continue;
                }

                yield return(new FarmAnimalTarget(this.GameHelper, animal, animal.getTileLocation()));
            }

            // map objects
            foreach (KeyValuePair <Vector2, SObject> pair in location.objects.Pairs)
            {
                Vector2 spriteTile = pair.Key;
                SObject obj        = pair.Value;

                if (!this.GameHelper.CouldSpriteOccludeTile(spriteTile, originTile))
                {
                    continue;
                }

                yield return(new ObjectTarget(this.GameHelper, obj, spriteTile, this.Reflection));
            }

            // furniture
            if (location is DecoratableLocation decoratableLocation)
            {
                foreach (var furniture in decoratableLocation.furniture)
                {
                    yield return(new ObjectTarget(this.GameHelper, furniture, furniture.TileLocation, this.Reflection));
                }
            }

            // terrain features
            foreach (KeyValuePair <Vector2, TerrainFeature> pair in location.terrainFeatures.Pairs)
            {
                Vector2        spriteTile = pair.Key;
                TerrainFeature feature    = pair.Value;

                if (!this.GameHelper.CouldSpriteOccludeTile(spriteTile, originTile))
                {
                    continue;
                }

                switch (feature)
                {
                case Bush bush:     // planted bush
                    yield return(new BushTarget(this.GameHelper, bush, this.Reflection));

                    break;

                case HoeDirt dirt when dirt.crop != null:
                    yield return(new CropTarget(this.GameHelper, dirt, spriteTile, this.Reflection, this.JsonAssets));

                    break;

                case FruitTree fruitTree:
                    if (this.Reflection.GetField <float>(fruitTree, "alpha").GetValue() < 0.8f)
                    {
                        continue;     // ignore when tree is faded out (so player can lookup things behind it)
                    }
                    yield return(new FruitTreeTarget(this.GameHelper, fruitTree, this.JsonAssets, spriteTile));

                    break;

                case Tree wildTree:
                    if (this.Reflection.GetField <float>(feature, "alpha").GetValue() < 0.8f)
                    {
                        continue;     // ignore when tree is faded out (so player can lookup things behind it)
                    }
                    yield return(new TreeTarget(this.GameHelper, wildTree, spriteTile, this.Reflection));

                    break;

                default:
                    yield return(new UnknownTarget(this.GameHelper, feature, spriteTile));

                    break;
                }
            }

            // large terrain features
            foreach (LargeTerrainFeature feature in location.largeTerrainFeatures)
            {
                Vector2 spriteTile = feature.tilePosition.Value;

                if (!this.GameHelper.CouldSpriteOccludeTile(spriteTile, originTile))
                {
                    continue;
                }

                switch (feature)
                {
                case Bush bush:     // wild bush
                    yield return(new BushTarget(this.GameHelper, bush, this.Reflection));

                    break;
                }
            }

            // players
            foreach (Farmer farmer in location.farmers)
            {
                if (!this.GameHelper.CouldSpriteOccludeTile(farmer.getTileLocation(), originTile))
                {
                    continue;
                }

                yield return(new FarmerTarget(this.GameHelper, farmer));
            }

            // buildings
            if (location is BuildableGameLocation buildableLocation)
            {
                foreach (Building building in buildableLocation.buildings)
                {
                    if (!this.GameHelper.CouldSpriteOccludeTile(new Vector2(building.tileX.Value, building.tileY.Value + building.tilesHigh.Value), originTile, Constant.MaxBuildingTargetSpriteSize))
                    {
                        continue;
                    }

                    yield return(new BuildingTarget(this.GameHelper, building));
                }
            }

            // tiles
            if (includeMapTile)
            {
                yield return(new TileTarget(this.GameHelper, originTile));
            }
        }
コード例 #30
0
ファイル: Game.cs プロジェクト: somnomania/smapi-mod-dump
        public void ServerStartGame()
        {
            if (IsGameInProgress)
            {
                Console.WriteLine("A game is already in progress!");
                return;
            }
            IsGameInProgress = true;

            Console.WriteLine("Server start game");


            NetworkUtility.SendChatMessageToAllPlayers("Game starting!");

            //Wipe objects
            foreach (GameLocation location in Game1.locations)
            {
                location.Objects.Clear();
                location.debris.Clear();
            }


            Game1.MasterPlayer.Money = 0;

            //Spawn chests
            new Chests().SpawnAndFillChests();

            #region Store tree locations or replant
            Random random = new Random();
            if (trees.Count == 0)            //Store info
            {
                foreach (GameLocation gameLocation in Game1.locations)
                {
                    foreach (var pair in gameLocation.terrainFeatures.Pairs)
                    {
                        TerrainFeature feature = pair.Value;
                        if (feature is Tree tree && tree.growthStage.Value >= 5)
                        {
                            Vector2 vector = pair.Key;
                            trees.Add(new TileLocation(gameLocation.Name, (int)vector.X, (int)vector.Y));
                        }
                    }
                }
            }
            else            //Replant
            {
                //Delete all trees
                foreach (GameLocation gameLocation in Game1.locations)
                {
                    List <Vector2> toRemove = new List <Vector2>();
                    foreach (Vector2 vector in gameLocation.terrainFeatures.Keys)
                    {
                        TerrainFeature feature = gameLocation.terrainFeatures[vector];
                        if (feature is Tree tree && tree.growthStage.Value >= 5)
                        {
                            toRemove.Add(vector);
                        }
                    }

                    foreach (Vector2 vector in toRemove)
                    {
                        gameLocation.terrainFeatures.Remove(vector);
                    }
                }

                //Replant
                foreach (TileLocation treeLocation in trees)
                {
                    treeLocation.GetGameLocation().terrainFeatures.Remove(treeLocation.CreateVector2());
                    treeLocation.GetGameLocation().terrainFeatures.Add(treeLocation.CreateVector2(), new Tree(random.Next(1, 4), 100));
                }
            }
            #endregion

            //Remove resource clumps (e.g. boulders) other than stumps and hollow logs
            var rc = Game1.getFarm().resourceClumps;
            foreach (var a in rc.Where(a => a.parentSheetIndex.Value != 600 || a.parentSheetIndex.Value != 602).ToList())
            {
                rc.Remove(a);
            }

            //Remove small stones and weeds
            var farmObjects = Game1.getFarm().objects;
            var keys        = farmObjects.Keys.ToList();
            for (int i = 0; i < keys.Count(); i++)
            {
                var key0 = keys[i];

                if (farmObjects[key0].name == "Stone" || farmObjects[key0].name == "Weeds")
                {
                    farmObjects.Remove(key0);
                }
            }

            //Setup alive players
            alivePlayers.Clear();
            foreach (Farmer player in Game1.getOnlineFarmers())
            {
                if (player != null && !(player == Game1.player && !modConfig.ShouldHostParticipate))
                {
                    Console.WriteLine($"Adding {player.Name} to the game");
                    alivePlayers.Add(player.UniqueMultiplayerID);
                }
            }

            //Storm index
            int stormIndex = Storm.GetRandomStormIndex();

            //Spawn players in & Tell the clients to start game
            var chosenSpawns = new Spawns().ScatterPlayers(Game1.getOnlineFarmers());
            foreach (Farmer player in chosenSpawns.Keys)
            {
                if (player == Game1.player)
                {
                    ClientStartGame(alivePlayers.Count, modConfig.ShouldHostParticipate, stormIndex);

                    if (modConfig.ShouldHostParticipate)
                    {
                        NetworkUtility.WarpFarmer(player, chosenSpawns[player]);
                    }
                    else
                    {
                        player.warpFarmer(new TileLocation("Forest", 100, 20).CreateWarp());
                    }
                }
                else
                {
                    NetworkUtility.BroadcastGameStartToClient(player, alivePlayers.Count, modConfig.ShouldHostParticipate, stormIndex);
                    NetworkUtility.WarpFarmer(player, chosenSpawns[player]);
                }
            }

            //Remove horses/NPCs
            foreach (GameLocation loc in Game1.locations)
            {
                foreach (NPC horse in loc.characters.Where(x => ModEntry.Config.KillAllNPCs || x is StardewValley.Characters.Horse).ToList())
                {
                    loc.characters.Remove(horse);
                }
            }

            //Freeze time
            Game1.timeOfDay       = 1400;
            FreezeTime.TimeFrozen = true;
        }