Пример #1
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))
                );
        }
Пример #2
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);
        }