Example #1
0
        private static void GiantCropPostfix(GiantCrop __instance)
        {
            var instanceName = Game1.objectInformation.ContainsKey(__instance.parentSheetIndex) ? Game1.objectInformation[__instance.parentSheetIndex].Split('/')[0] : String.Empty;

            instanceName = $"{AlternativeTextureModel.TextureType.GiantCrop}_{instanceName}";
            var instanceSeasonName = $"{instanceName}_{Game1.GetSeasonForLocation(__instance.currentLocation)}";

            if (AlternativeTextures.textureManager.DoesObjectHaveAlternativeTexture(instanceName) && AlternativeTextures.textureManager.DoesObjectHaveAlternativeTexture(instanceSeasonName))
            {
                var result = Game1.random.Next(2) > 0 ? AssignModData(__instance, instanceSeasonName, true) : AssignModData(__instance, instanceName, false);
                return;
            }
            else
            {
                if (AlternativeTextures.textureManager.DoesObjectHaveAlternativeTexture(instanceName))
                {
                    AssignModData(__instance, instanceName, false);
                    return;
                }

                if (AlternativeTextures.textureManager.DoesObjectHaveAlternativeTexture(instanceSeasonName))
                {
                    AssignModData(__instance, instanceSeasonName, true);
                    return;
                }
            }

            AssignDefaultModData(__instance, instanceSeasonName, true);
        }
            /// <summary>Generates a large object and places it on the specified map and tile.</summary>
            /// <param name="index">The parent sheet index (a.k.a. object ID) of the object type to spawn.</param>
            /// <param name="location">The GameLocation where the large object should be spawned.</param>
            /// <param name="tile">The x/y coordinates of the tile where the ore should be spawned.</param>
            public static bool SpawnLargeObject(int index, GameLocation location, Vector2 tile)
            {
                Monitor.VerboseLog($"Spawning large object. ID: {index}. Location: {tile.X},{tile.Y} ({location.Name}).");

                ResourceClump clump;

                if (index == 190 || index == 254 || index == 276) //if this should be a GiantCrop
                {
                    clump = new GiantCrop(index, tile);
                }
                else //if this should be a ResourceClump
                {
                    clump = new ResourceClump(index, 2, 2, tile);
                }

                if (location is Farm farm)
                {
                    farm.resourceClumps.Add(clump); //spawn the specified resource clump
                }
                else if (location is MineShaft mine)
                {
                    mine.resourceClumps.Add(clump); //spawn the specified resource clump
                }
                else //if this is not a farm or mine, which generally means it lacks a "resourceClumps" list
                {
                    location.largeTerrainFeatures.Add(new LargeResourceClump(clump)); //spawn a wrapped version of the specified resource clump
                }

                return(true);
            }
Example #3
0
 public static void Prefix(GiantCrop __instance, Tool t)
 {
     if (t is Axe axe && axe.UpgradeLevel == 6)   // Mythicite
     {
         // Setting it to 1 lets the real method end up getting it to 0 and taking care of everything
         __instance.health.Value = 1;
     }
 }
Example #4
0
        public static bool CheckIfPositionIsWithinGiantCrop(Vector2 position, GiantCrop g)
        {
            if (position.X >= g.tile.Value.X && position.X <= g.tile.Value.X + g.width.Value)
            {
                if (position.Y >= g.tile.Value.Y && position.Y < g.tile.Value.Y + g.height.Value)
                {
                    return(true);
                }
            }

            return(false);
        }
Example #5
0
        private static void fakeOne(int harvestIndex, bool giantCrop,
                                    Farmer near = null)
        {
            near ??= Game1.player;
            GameLocation location = near.currentLocation;

            var tiles = Utility.recursiveFindOpenTiles(location,
                                                       near.getTileLocation(), 1, 100);

            if (tiles.Count == 0)
            {
                throw new Exception($"Could not find an open tile in {location.Name}.");
            }
            Vector2 tileLocation = tiles[0];

            Crop crop = Utilities.MakeNonceCrop(harvestIndex,
                                                Utility.Vector2ToPoint(tileLocation));

            TerrainFeature feature;

            if (giantCrop)
            {
                if (location is Farm farm)
                {
                    feature = new GiantCrop(harvestIndex, tileLocation);
                    farm.resourceClumps.Add(feature as ResourceClump);
                }
                else
                {
                    throw new Exception($"Cannot fake a Giant Cropbeast in {location.Name}.");
                }
            }
            else
            {
                feature = new HoeDirt(0, crop);
                location.terrainFeatures.Add(tileLocation, feature);
            }

            CropTile cropTile = new CropTile(feature, crop, giantCrop, location,
                                             Utility.Vector2ToPoint(tileLocation), fake: true);

            if (cropTile.state != CropTile.State.Available)
            {
                cropTile.cleanUpFake();
                throw new Exception($"Faked a {cropTile.logDescription} but it had no available cropbeast mapping.");
            }

            cropTile.choose();
            DelayedAction.functionAfterDelay(() => Spawner.Spawn(cropTile), 0);
        }
 /*********
 ** Private methods
 *********/
 /// <summary>The method which transpiles <see cref="GiantCrop.draw"/>.</summary>
 private static bool Before_Draw(GiantCrop __instance, SpriteBatch spriteBatch, Vector2 tileLocation)
 {
     try
     {
         if (Mod.Sprites.TryGetValue(__instance.parentSheetIndex.Value, out Texture2D tex))
         {
             double shakeTimer = Mod.Instance.Helper.Reflection.GetField <float>(__instance, "shakeTimer").GetValue();
             spriteBatch.Draw(tex, Game1.GlobalToLocal(Game1.viewport, tileLocation * 64f - new Vector2(shakeTimer > 0.0 ? (float)(Math.Sin(2.0 * Math.PI / shakeTimer) * 2.0) : 0.0f, 64f)), null, Color.White, 0.0f, Vector2.Zero, 4f, SpriteEffects.None, (float)((tileLocation.Y + 2.0) * 64.0 / 10000.0));
             return(false);
         }
         return(true);
     }
     catch (Exception ex)
     {
         Log.Error($"Failed in {nameof(GiantCropPatcher)}.{nameof(Before_Draw)}:\n{ex}");
         return(true);
     }
 }
 public static bool Draw_Prefix(GiantCrop __instance, SpriteBatch spriteBatch, Vector2 tileLocation)
 {
     try
     {
         if (Mod.sprites.ContainsKey(__instance.parentSheetIndex.Value))
         {
             Texture2D tex        = Mod.sprites[__instance.parentSheetIndex.Value];
             double    shakeTimer = Mod.instance.Helper.Reflection.GetField <float>(__instance, "shakeTimer").GetValue();
             spriteBatch.Draw(tex, Game1.GlobalToLocal(Game1.viewport, tileLocation * 64f - new Vector2(shakeTimer > 0.0 ? (float)(Math.Sin(2.0 * Math.PI / shakeTimer) * 2.0) : 0.0f, 64f)), null, Color.White, 0.0f, Vector2.Zero, 4f, SpriteEffects.None, (float)(((double)tileLocation.Y + 2.0) * 64.0 / 10000.0));
             return(false);
         }
         return(true);
     }
     catch (Exception ex)
     {
         Log.error($"Failed in {nameof(GiantCropPatches)}.{nameof(Draw_Prefix)}:\n{ex}");
         return(true);
     }
 }
Example #8
0
        private static bool DrawPrefix(GiantCrop __instance, float ___shakeTimer, SpriteBatch spriteBatch, Vector2 tileLocation)
        {
            if (__instance.modData.ContainsKey("AlternativeTextureName"))
            {
                var textureModel = AlternativeTextures.textureManager.GetSpecificTextureModel(__instance.modData["AlternativeTextureName"]);
                if (textureModel is null)
                {
                    return(true);
                }

                var textureVariation = Int32.Parse(__instance.modData["AlternativeTextureVariation"]);
                if (textureVariation == -1 || AlternativeTextures.modConfig.IsTextureVariationDisabled(textureModel.GetId(), textureVariation))
                {
                    return(true);
                }

                var textureOffset = textureModel.GetTextureOffset(textureVariation);
                spriteBatch.Draw(textureModel.GetTexture(textureVariation), Game1.GlobalToLocal(Game1.viewport, tileLocation * 64f - new Vector2((___shakeTimer > 0f) ? ((float)Math.Sin(Math.PI * 2.0 / (double)___shakeTimer) * 2f) : 0f, 64f)), new Rectangle(0, textureOffset, 48, 63), Color.White, 0f, Vector2.Zero, 4f, SpriteEffects.None, (tileLocation.Y + 2f) * 64f / 10000f);

                return(false);
            }

            return(true);
        }
Example #9
0
        internal void SetUp()
        {
            FailureMessage = $"Could not set tonight's event to {Name}: a condition for this event has not been fulfilled, or another event is taking precedence.";
            Conditions     = new List <KeyValuePair <Func <bool>, string> >();
            AddCondition(() => !Game1.weddingToday, "there's a wedding today");

            switch (Name)
            {
            case "capsule":
                FarmEvent         = new SoundInTheNightEvent(0);
                PersonalFarmEvent = null;
                SuccessMessage    = "A strange capsule event will occur tonight.";
                AddCondition(() => Game1.year > 1,
                             "the game year is 1");
                AddCondition(() => !Game1.MasterPlayer.mailReceived.Contains("Got_Capsule"),
                             "the strange capsule event has happened before");
                break;

            case "meteorite":
                FarmEvent         = new SoundInTheNightEvent(1);
                PersonalFarmEvent = null;
                SuccessMessage    = "A meteorite event will occur tonight.";
                break;

            case "wild_animal_attack":
                FarmEvent         = null;
                PersonalFarmEvent = new SoundInTheNightEvent(2);
                SuccessMessage    = "A wild animal attack event will occur tonight.";
                break;

            case "owl_statue":
                FarmEvent         = new SoundInTheNightEvent(3);
                PersonalFarmEvent = null;
                SuccessMessage    = "An owl statue event will occur tonight.";
                break;

            case "fairy":
                FarmEvent         = new FairyEvent();
                PersonalFarmEvent = null;
                SuccessMessage    = "A crop fairy event will occur tonight.";
                AddCondition(() => !Game1.currentSeason.Equals("winter"), "it's winter");
                break;

            case "witch":
                FarmEvent         = new WitchEvent();
                PersonalFarmEvent = null;
                SuccessMessage    = "A witch event will occur tonight.";
                break;

            case "NPC_child_request":
                FarmEvent         = null;
                PersonalFarmEvent = new QuestionEvent(1);
                SuccessMessage    = "Your NPC spouse will request a child tonight.";
                AddCondition(() => Game1.player.isMarried(),
                             "you are not married");
                AddCondition(() => Game1.player.spouse != null,
                             "you do not have a spouse");
                AddCondition(() => Game1.getCharacterFromName(Game1.player.spouse).canGetPregnant(),
                             "your spouse cannot have children (or is a roommate)");
                AddCondition(() => Game1.player.currentLocation == Game1.getLocationFromName(Game1.player.homeLocation),
                             "you are not at home");
                break;

            case "PC_child_request":
                FarmEvent         = null;
                PersonalFarmEvent = new QuestionEvent(3);
                SuccessMessage    = "You or your PC spouse will request a child tonight.";
                AddCondition(() => Context.IsMultiplayer, "this is a single-player game");
                AddCondition(() => Game1.player.isMarried(), "you are not married");
                AddCondition(() => Game1.player.team.GetSpouse(Game1.player.UniqueMultiplayerID).HasValue,
                             "you are not married to another farmer");
                AddCondition(() => Game1.player.GetSpouseFriendship().NextBirthingDate == null,
                             "you are already going to have a child");
                AddCondition(() => Game1.otherFarmers.ContainsKey(Game1.player.team.GetSpouse(Game1.player.UniqueMultiplayerID).Value),
                             "your spouse is not in the game");
                AddCondition(() => Game1.otherFarmers[Game1.player.team.GetSpouse(Game1.player.UniqueMultiplayerID).Value].currentLocation == Game1.player.currentLocation,
                             "you and your spouse are not in the same location");
                AddCondition(() => Game1.otherFarmers[Game1.player.team.GetSpouse(Game1.player.UniqueMultiplayerID).Value].currentLocation == Game1.getLocationFromName(Game1.otherFarmers[Game1.player.team.GetSpouse(Game1.player.UniqueMultiplayerID).Value].homeLocation) ||
                             Game1.otherFarmers[Game1.player.team.GetSpouse(Game1.player.UniqueMultiplayerID).Value].currentLocation == Game1.getLocationFromName(Game1.player.homeLocation),
                             "you and your spouse are not in either of your houses");
                AddCondition(() => Helper.Reflection.GetMethod(typeof(Utility), "playersCanGetPregnantHere").Invoke <bool>(Game1.otherFarmers[Game1.player.team.GetSpouse(Game1.player.UniqueMultiplayerID).Value].currentLocation as FarmHouse),
                             "you don't have a crib, your crib is already occupied, or you already have 2 children");
                break;

            case "animal_birth":
                FarmEvent         = null;
                PersonalFarmEvent = new QuestionEvent(2);
                SuccessMessage    = "An animal birth event will occur tonight.";
                break;

            case "giant_crop":
                if (tile == null)
                {
                    break;
                }

                // players can only specify a crop ID when conditions aren't being enforced
                if (id > -1)
                {
                    giantCrop = new GiantCrop(id, new Vector2((int)tile.X - 1, (int)tile.Y - 1));
                    giantCrop.modData.Add(ModEntry.mod.ModManifest.UniqueID, SDate.Now().ToString());
                    break;
                }

                // weddings don't prevent giant crops from spawning
                Conditions.Clear();

                // first check whether there's actually a crop there; this will be a hard condition regardless of config
                AddCondition(() => location.terrainFeatures.ContainsKey(tile) && location.terrainFeatures[tile] is HoeDirt,
                             $"there is no hoe dirt at ({(int)tile.X}, {(int)tile.Y})");
                AddCondition(() => (location.terrainFeatures[tile] as HoeDirt).crop != null,
                             $"there is no crop at ({(int)tile.X}, {(int)tile.Y})");
                if (!EnforceEventConditions(out string message))
                {
                    Monitor.Log($"Could not set giant crop spawn for tonight because {message}.", LogLevel.Info);
                    break;
                }

                SuccessMessage = $"A giant crop will spawn at ({(int)tile.X}, {(int)tile.Y}) tonight.";

                giantCrop = new GiantCrop((location.terrainFeatures[tile] as HoeDirt).crop.indexOfHarvest, new Vector2((int)tile.X - 1, (int)tile.Y - 1));
                giantCrop.modData.Add(ModEntry.mod.ModManifest.UniqueID, SDate.Now().ToString());

                if (!Helper.ModRegistry.IsLoaded("spacechase0.moregiantcrops") && !Helper.ModRegistry.IsLoaded("spacechase0.jsonassets"))
                {
                    AddCondition(() => (location.terrainFeatures[tile] as HoeDirt).crop.indexOfHarvest == 276 ||
                                 (location.terrainFeatures[tile] as HoeDirt).crop.indexOfHarvest == 190 ||
                                 (location.terrainFeatures[tile] as HoeDirt).crop.indexOfHarvest == 254,
                                 "this type of crop cannot be giant");
                }
                AddCondition(() => location is Farm,
                             "you are not in a farm location");
                AddCondition(() => (location.terrainFeatures[tile] as HoeDirt).state.Value == 1,
                             $"the crop at ({(int)tile.X}, {(int)tile.Y}) is not watered");
                AddCondition(() => (int)(location.terrainFeatures[tile] as HoeDirt).crop.currentPhase == (location.terrainFeatures[tile] as HoeDirt).crop.phaseDays.Count - 1,
                             $"the crop at ({(int)tile.X}, {(int)tile.Y}) is not fully grown");
                AddCondition(() => CheckGiantCropSquareForCrops(),
                             $"the crop at ({(int)tile.X}, {(int)tile.Y}) is not at the center of a 3x3 square of crops of the same type");
                AddCondition(() => CheckGiantCropSquareForCharacters(),
                             $"there is a character in the way");
                break;

            default:
                break;
            }
        }
Example #10
0
        public TerrainFeature getRandomTF(Vector2 tile6)
        {
            TerrainFeature ter = null;

            int x3 = rnd.Next(0, 4);

            if (x3 == 0)
            {
                ter = new FruitTree(rnd.Next(628, 633));
            }
            else if (x3 == 1)
            {
                double y = rnd.NextDouble();
                if (y <= 0.33)
                {
                    ter = new GiantCrop(190, tile6);
                }
                else if (y <= 0.66)
                {
                    ter = new GiantCrop(254, tile6);
                }
                else
                {
                    ter = new GiantCrop(276, tile6);
                }
            }
            else if (x3 == 2)
            {
                ter = new Grass(rnd.Next(1, 4), rnd.Next(1, 4));
            }
            else if (x3 == 3)
            {
                int x4 = rnd.Next(0, 7);
                if (x4 == 0)
                {
                    ter = new ResourceClump(600, 2, 2, tile6);
                }
                if (x4 == 1)
                {
                    ter = new ResourceClump(602, 2, 2, tile6);
                }
                if (x4 == 2)
                {
                    ter = new ResourceClump(622, 2, 2, tile6);
                }
                if (x4 == 3)
                {
                    ter = new ResourceClump(672, 2, 2, tile6);
                }
                if (x4 == 4)
                {
                    ter = new ResourceClump(752, 2, 2, tile6);
                }
                if (x4 == 5)
                {
                    ter = new ResourceClump(754, 2, 2, tile6);
                }
                if (x4 == 6)
                {
                    ter = new ResourceClump(756, 2, 2, tile6);
                }
                if (x4 == 7)
                {
                    ter = new ResourceClump(758, 2, 2, tile6);
                }
            }
            else if (x3 == 4)
            {
                ter = new Tree(rnd.Next(1, 7));
            }

            return(ter);
        }