예제 #1
0
        internal static bool MineShaft_addLevelChests_prefix(MineShaft __instance)
        {
            if (config.OverrideTreasureRooms && !Game1.player.chestConsumedMineLevels.ContainsKey(__instance.mineLevel) && (helper.Reflection.GetField <NetBool>(__instance, "netIsTreasureRoom").GetValue().Value || (__instance.mineLevel < 120 && __instance.mineLevel % 20 == 0) || __instance.mineLevel == 10 || __instance.mineLevel == 50 || __instance.mineLevel == 70 || __instance.mineLevel == 90 || __instance.mineLevel == 110))
            {
                Vector2 spot = new Vector2(9, 9);
                if (__instance.mineLevel % 20 == 0 && __instance.mineLevel % 40 != 0)
                {
                    spot.Y += 4f;
                }

                switch (Game1.random.Next(4))
                {
                case 0:
                    LightPuzzles.CreatePuzzle(spot, __instance);
                    break;

                case 1:
                    OfferingPuzzles.CreatePuzzle(spot, __instance);
                    break;

                case 2:
                    RiddlePuzzles.CreatePuzzle(spot, __instance);
                    break;

                case 3:
                    TilePuzzles.CreatePuzzle(spot, __instance);
                    break;
                }
                return(false);
            }
            return(true);
        }
예제 #2
0
        internal static bool MineShaft_checkAction_prefix(MineShaft __instance, Location tileLocation, xTile.Dimensions.Rectangle viewport, Farmer who)
        {
            Tile tile = __instance.map.GetLayer("Buildings").PickTile(new Location(tileLocation.X * 64, tileLocation.Y * 64), viewport.Size);

            if (tile != null && who.IsLocalPlayer)
            {
                tile.Properties.TryGetValue("Action", out PropertyValue property);
                if (property != null)
                {
                    string action = property.ToString();

                    if (action.StartsWith("offerPuzzleSteal"))
                    {
                        OfferingPuzzles.StealAttempt(__instance, action, tileLocation, who);
                    }
                    else if (who.ActiveObject != null && action.StartsWith("offerPuzzle_"))
                    {
                        OfferingPuzzles.OfferObject(__instance, action, tileLocation, who);
                    }
                    else if (action.StartsWith("undergroundAltar_"))
                    {
                        Altars.OfferObject(__instance, action, tileLocation, who);
                    }
                    else if (action == "undergroundRiddles")
                    {
                        RiddlePuzzles.Interact(__instance, tileLocation, who);
                    }
                }
            }
            return(true);
        }
예제 #3
0
        public override void Entry(IModHelper helper)
        {
            context = this;
            Config  = this.Helper.ReadConfig <ModConfig>();
            if (!Config.EnableMod)
            {
                return;
            }

            tileSheetPath = this.Helper.Content.GetActualAssetKey(Path.Combine("assets", "underground_secrets.png"), ContentSource.ModFolder);

            HelperEvents.Initialize(Helper, Monitor, Config);
            UndergroundPatches.Initialize(Helper, Monitor, Config);
            Utils.Initialize(Helper, Monitor, Config);

            TilePuzzles.Initialize(Helper, Monitor, Config);
            OfferingPuzzles.Initialize(Helper, Monitor, Config);
            LightPuzzles.Initialize(Helper, Monitor, Config);
            Altars.Initialize(Helper, Monitor, Config);
            RiddlePuzzles.Initialize(Helper, Monitor, Config);
            CollapsingFloors.Initialize(Helper, Monitor, Config);
            Traps.Initialize(Helper, Monitor, Config);
            MushroomTrees.Initialize(Helper, Monitor, Config);

            //Helper.Events.Player.Warped += HelperEvents.Player_Warped;
            Helper.Events.GameLoop.UpdateTicked += HelperEvents.GameLoop_UpdateTicked;
            Helper.Events.GameLoop.GameLaunched += GameLoop_GameLaunched;

            var harmony = HarmonyInstance.Create(ModManifest.UniqueID);

            harmony.Patch(
                original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.performTouchAction)),
                prefix: new HarmonyMethod(typeof(UndergroundPatches), nameof(UndergroundPatches.GameLocation_performTouchAction_prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.loadMap)),
                postfix: new HarmonyMethod(typeof(UndergroundPatches), nameof(UndergroundPatches.GameLocation_loadMap_postfix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(MineShaft), "populateLevel"),
                transpiler: new HarmonyMethod(typeof(UndergroundPatches), nameof(UndergroundPatches.MineShaft_populateLevel_transpiler))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(MineShaft), "checkAction"),
                prefix: new HarmonyMethod(typeof(UndergroundPatches), nameof(UndergroundPatches.MineShaft_checkAction_prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(MineShaft), "addLevelChests"),
                prefix: new HarmonyMethod(typeof(UndergroundPatches), nameof(UndergroundPatches.MineShaft_addLevelChests_prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(MineShaft), nameof(MineShaft.enterMineShaft)),
                postfix: new HarmonyMethod(typeof(UndergroundPatches), nameof(UndergroundPatches.MineShaft_enterMineShaft_postfix))
                );
        }
예제 #4
0
        public static void AddSecrets(MineShaft shaft)
        {
            if (config.OverrideTreasureRooms && (helper.Reflection.GetField <NetBool>(shaft, "netIsTreasureRoom").GetValue().Value || (shaft.mineLevel < 121 && shaft.mineLevel % 20 == 0) || shaft.mineLevel == 10 || shaft.mineLevel == 50 || shaft.mineLevel == 70 || shaft.mineLevel == 90 || shaft.mineLevel == 110))
            {
                monitor.Log($"is treasure room");

                return;
            }

            List <Vector2> clearSpots        = new List <Vector2>();
            List <Vector2> clearCenters      = new List <Vector2>();
            List <Vector2> superClearCenters = new List <Vector2>();

            Vector2 tileBeneathLadder = helper.Reflection.GetField <NetVector2>(shaft, "netTileBeneathLadder").GetValue();

            monitor.Log($"tileBeneathLadder: {tileBeneathLadder}");

            for (int x = 0; x < shaft.map.Layers[0].LayerWidth; x++)
            {
                for (int y = 0; y < shaft.map.Layers[0].LayerHeight; y++)
                {
                    Tile build = shaft.map.GetLayer("Buildings").PickTile(new Location(x, y) * Game1.tileSize, Game1.viewport.Size);

                    if (build != null)
                    {
                        if (build.TileIndex == 115)
                        {
                            tileBeneathLadder = new Vector2(x, y + 1);
                            monitor.Log($"made tileBeneathLadder: {tileBeneathLadder}");
                        }
                        continue;
                    }

                    if (x == tileBeneathLadder.X && y == tileBeneathLadder.Y)
                    {
                        continue;
                    }
                    Tile tile = shaft.map.GetLayer("Back").PickTile(new Location(x, y) * Game1.tileSize, Game1.viewport.Size);
                    if (tile != null && (tile.TileIndex / 16 > 7 || tile.TileIndex % 16 < 9) && shaft.map.GetLayer("Front").PickTile(new Location(x, y) * Game1.tileSize, Game1.viewport.Size) == null)
                    {
                        clearSpots.Add(new Vector2(x, y));
                    }
                }
            }
            monitor.Log($"clearSpots contains tileBeneathLadder: {clearSpots.Contains(tileBeneathLadder)}");


            foreach (Vector2 spot in clearSpots)
            {
                int clear = GetTileClearance(shaft, spot, clearSpots);
                if (clear > 0)
                {
                    clearCenters.Add(spot);
                }
                if (clear > 1)
                {
                    superClearCenters.Add(spot);
                }
            }
            monitor.Log($"got {clearSpots.Count} clear spots in {shaft.Name}");
            monitor.Log($"got {clearCenters.Count} clear centers in {shaft.Name}");
            monitor.Log($"got {superClearCenters.Count} super clear centers in {shaft.Name}");

            monitor.Log($"adding underground_secrets tilesheet");
            TileSheet mine = shaft.map.TileSheets[0];

            helper.Reflection.GetField <Size>(mine, "m_sheetSize").SetValue(new Size(16, 18));
            shaft.map.AddTileSheet(new TileSheet(ModEntry.tileSheetId, shaft.map, ModEntry.tileSheetPath, new Size(16, 18), new Size(16, 16)));
            shaft.map.LoadTileSheets(Game1.mapDisplayDevice);
            TilePuzzles.Start(shaft, ref superClearCenters, ref clearCenters, ref clearSpots);
            LightPuzzles.Start(shaft, ref superClearCenters, ref clearCenters, ref clearSpots);
            OfferingPuzzles.Start(shaft, ref superClearCenters, ref clearCenters, ref clearSpots);
            Altars.Start(shaft, ref superClearCenters, ref clearCenters, ref clearSpots);
            RiddlePuzzles.Start(shaft, ref superClearCenters, ref clearCenters, ref clearSpots);
            Traps.Start(shaft, ref superClearCenters, ref clearCenters, ref clearSpots);
            if (shaft.mineLevel > 120)
            {
                CollapsingFloors.Start(shaft, ref superClearCenters, ref clearCenters, ref clearSpots);
            }
            MushroomTrees.Start(shaft, ref superClearCenters, ref clearCenters, ref clearSpots);
        }