public static bool GameLocation_performTouchAction_prefix(GameLocation __instance, string fullActionString, Vector2 playerStandingPosition) { if (!(__instance is MineShaft)) { return(true); } ModEntry.context.Monitor.Log($"touch action at {playerStandingPosition} {fullActionString}"); string action = fullActionString.Split(' ')[0]; if (action == "collapseFloor") { CollapsingFloors.collapseFloor(__instance as MineShaft, playerStandingPosition); return(false); } if (action.StartsWith("tilePuzzle_")) { TilePuzzles.pressTile(__instance as MineShaft, playerStandingPosition, action); return(false); } if (action.StartsWith("lightPuzzle_")) { LightPuzzles.pressTile(__instance as MineShaft, playerStandingPosition, action); return(false); } if (action == "randomTrap") { Traps.TriggerRandomTrap(__instance as MineShaft, playerStandingPosition, true); return(false); } return(true); }
private static void AnswerResult(string responseKey) { string[] split = responseKey.Split('#'); int x = int.Parse(split[1]); int y = int.Parse(split[2]); Game1.player.currentLocation.removeTileProperty(x, y, "Buildings", "Action"); string type = split[3]; switch (type) { case "Y": Game1.player.currentLocation.removeTile(x, y - 1, "Front"); Game1.player.currentLocation.removeTile(x, y, "Buildings"); Utils.DropChest(Game1.player.currentLocation as MineShaft, new Vector2(x, y)); return; case "S": Game1.player.currentLocation.removeTile(x, y - 1, "Front"); Game1.player.currentLocation.removeTile(x, y, "Buildings"); CollapsingFloors.collapseFloor(Game1.player.currentLocation as MineShaft, Game1.player.getTileLocation()); return; default: Game1.player.currentLocation.setMapTileIndex(x, y - 1, litEyes + 16, "Front"); Traps.TriggerRandomTrap(Game1.player.currentLocation as MineShaft, Game1.player.getTileLocation(), false); return; } }
internal static void OfferObject(MineShaft shaft, string action, Location tileLocation, Farmer who) { monitor.Log($"Attempting to offer to altar"); string[] parts = action.Split('_').Skip(1).ToArray(); Vector2 spot = new Vector2(int.Parse(parts[1]), int.Parse(parts[2])); if (ores[int.Parse(parts[0])] == who.ActiveObject.ParentSheetIndex) { monitor.Log($"Made acceptable offering to altar"); who.reduceActiveItemByOne(); shaft.setMapTileIndex(tileLocation.X, tileLocation.Y, OfferingPuzzles.offerIdx + 1 + int.Parse(parts[0]), "Buildings"); shaft.setMapTileIndex(tileLocation.X, tileLocation.Y - 2, 245, "Front"); shaft.setTileProperty((int)spot.X - 1, (int)spot.Y + 1, "Buildings", "Action", $"offerPuzzleSteal_{parts[1]}_{parts[2]}"); shaft.setTileProperty((int)spot.X + 1, (int)spot.Y + 1, "Buildings", "Action", $"offerPuzzleSteal_{parts[1]}_{parts[2]}"); Utils.DropChest(shaft, spot); } else { monitor.Log($"Made unacceptable offering to altar"); who.reduceActiveItemByOne(); shaft.setMapTileIndex((int)spot.X - 1, (int)spot.Y + 1, OfferingPuzzles.offerIdx, "Buildings"); shaft.setMapTileIndex((int)spot.X + 1, (int)spot.Y + 1, OfferingPuzzles.offerIdx, "Buildings"); shaft.removeTileProperty((int)spot.X - 1, (int)spot.Y + 1, "Buildings", "Action"); shaft.removeTileProperty((int)spot.X + 1, (int)spot.Y + 1, "Buildings", "Action"); Traps.TriggerRandomTrap(shaft, new Vector2(who.getTileLocation().X, who.getTileLocation().Y), false); } }
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)) ); }
internal static void OfferObject(MineShaft shaft, string action, Location tileLocation, Farmer who) { string[] parts = action.Split('_').Skip(1).ToArray(); int type = int.Parse(parts[0]); int cx = int.Parse(parts[1]); int cy = int.Parse(parts[2]); if (who.ActiveObject == null) { Game1.activeClickableMenu = new DialogueBox(helper.Translation.Get($"altar-explain-{type}")); return; } int value = who.ActiveObject.salePrice(); who.reduceActiveItemByOne(); if (value < 10) { if (type == 0) { CollapsingFloors.collapseFloor(shaft, who.getTileLocation()); return; } else if (type == 1) { Traps.TriggerRandomTrap(shaft, who.getTileLocation(), false); return; } } string sound = "yoba"; if (type == 0) { sound = "grunt"; } else if (type == 1) { sound = "debuffSpell"; } shaft.playSound(sound, SoundContext.Default); BuffsDisplay buffsDisplay = Game1.buffsDisplay; Buff buff2 = GetBuff(value, who, shaft, type); buffsDisplay.addOtherBuff(buff2); }
internal static void StealAttempt(MineShaft shaft, string action, Location tileLocation, Farmer who) { monitor.Log($"Attempting to steal from altar"); string[] parts = action.Split('_').Skip(1).ToArray(); Vector2 spot = new Vector2(int.Parse(parts[0]), int.Parse(parts[1])); shaft.setMapTileIndex((int)spot.X - 1, (int)spot.Y + 1, OfferingPuzzles.offerIdx, "Buildings"); shaft.setMapTileIndex((int)spot.X + 1, (int)spot.Y + 1, OfferingPuzzles.offerIdx, "Buildings"); shaft.setMapTileIndex((int)spot.X - 1, (int)spot.Y - 1, 244, "Front"); shaft.setMapTileIndex((int)spot.X + 1, (int)spot.Y - 1, 244, "Front"); shaft.removeTileProperty((int)spot.X - 1, (int)spot.Y + 1, "Buildings", "Action"); shaft.removeTileProperty((int)spot.X + 1, (int)spot.Y + 1, "Buildings", "Action"); Traps.TriggerRandomTrap(shaft, new Vector2(who.getTileLocation().X, who.getTileLocation().Y), false); }
internal static void pressTile(MineShaft shaft, Vector2 playerStandingPosition, string action) { string[] parts = action.Split('_').Skip(1).ToArray(); monitor.Log($"Pressed floor number {parts[0]} (row: {parts[1]} center: {parts[2]},{parts[3]}) at {playerStandingPosition} {shaft.Name}"); int idx = int.Parse(parts[0]); int row = int.Parse(parts[1]); int cx = int.Parse(parts[2]); int cy = int.Parse(parts[3]); Vector2[] spots = Utils.getCenteredSpots(new Vector2(cx, cy), true); bool correct = CheckTileOrder(shaft, spots, idx, cx, cy); Layer layer = shaft.map.GetLayer("Back"); TileSheet tilesheet = shaft.map.GetTileSheet(ModEntry.tileSheetId); if (correct) { monitor.Log($"correct order, deactivating tile {idx}"); shaft.playSound("Ship", SoundContext.Default); layer.Tiles[(int)playerStandingPosition.X, (int)playerStandingPosition.Y] = new StaticTile(layer, tilesheet, BlendMode.Alpha, tileIndex: 16 * row + idx + 8); shaft.removeTileProperty(cx, cy, "Back", "TouchAction"); } else { shaft.playSound("Duggy", SoundContext.Default); monitor.Log($"wrong order, deactivating puzzle"); foreach (Vector2 spot in spots) { if (layer.Tiles[(int)spot.X, (int)spot.Y].TileIndex % 16 >= 8) { continue; } layer.Tiles[(int)spot.X, (int)spot.Y] = new StaticTile(layer, tilesheet, BlendMode.Alpha, tileIndex: layer.Tiles[(int)spot.X, (int)spot.Y].TileIndex + 8); shaft.removeTileProperty((int)spot.X, (int)spot.Y, "Back", "TouchAction"); } Traps.TriggerRandomTrap(shaft, playerStandingPosition, false); } }
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); }