private static void CompleteEvent() { string playerTerm = Game1.content.LoadString("Strings\\Locations:Beach_Mariner_Player_" + (Game1.player.IsMale ? "Male" : "Female")); string preface = Helper.Translation.Get("SwimMod_Mariner_Completed"); Game1.drawObjectDialogue(string.Format(preface, playerTerm)); Game1.stopMusicTrack(Game1.MusicContext.Default); Game1.playSound("Cowboy_Secret"); Game1.player.mailReceived.Add("SwimMod_Mariner_Completed"); Game1.player.currentLocation.resetForPlayerEntry(); SwimMaps.AddScubaChest(Game1.player.currentLocation, new Vector2(10, 6), "ScubaTank"); }
public override void Entry(IModHelper helper) { config = Helper.ReadConfig <ModConfig>(); if (!config.EnableMod) { return; } SMonitor = Monitor; myRand = new Random(); SwimPatches.Initialize(Monitor, helper, config); SwimDialog.Initialize(Monitor, helper, config); SwimMaps.Initialize(Monitor, helper, config); SwimHelperEvents.Initialize(Monitor, helper, config); SwimUtils.Initialize(Monitor, helper, config); helper.Events.GameLoop.UpdateTicked += SwimHelperEvents.GameLoop_UpdateTicked; helper.Events.Input.ButtonPressed += SwimHelperEvents.Input_ButtonPressed; helper.Events.Input.ButtonReleased += SwimHelperEvents.Input_ButtonReleased; helper.Events.GameLoop.DayStarted += SwimHelperEvents.GameLoop_DayStarted; helper.Events.GameLoop.GameLaunched += SwimHelperEvents.GameLoop_GameLaunched; helper.Events.GameLoop.SaveLoaded += SwimHelperEvents.GameLoop_SaveLoaded; helper.Events.Display.RenderedHud += SwimHelperEvents.Display_RenderedHud; helper.Events.Display.RenderedWorld += SwimHelperEvents.Display_RenderedWorld; helper.Events.Player.InventoryChanged += SwimHelperEvents.Player_InventoryChanged; helper.Events.Player.Warped += SwimHelperEvents.Player_Warped; var harmony = HarmonyInstance.Create(this.ModManifest.UniqueID); harmony.Patch( original: AccessTools.Method(typeof(FarmerRenderer), nameof(FarmerRenderer.draw), new Type[] { typeof(SpriteBatch), typeof(FarmerSprite.AnimationFrame), typeof(int), typeof(Rectangle), typeof(Vector2), typeof(Vector2), typeof(float), typeof(int), typeof(Color), typeof(float), typeof(float), typeof(Farmer) }), prefix: new HarmonyMethod(typeof(SwimPatches), nameof(SwimPatches.FarmerRenderer_draw_Prefix)), postfix: new HarmonyMethod(typeof(SwimPatches), nameof(SwimPatches.FarmerRenderer_draw_Postfix)) ); harmony.Patch( original: AccessTools.Method(typeof(FarmerSprite), "checkForFootstep"), prefix: new HarmonyMethod(typeof(SwimPatches), nameof(SwimPatches.FarmerSprite_checkForFootstep_Prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.startEvent)), postfix: new HarmonyMethod(typeof(SwimPatches), nameof(SwimPatches.GameLocation_StartEvent_Postfix)) ); harmony.Patch( original: AccessTools.Method(typeof(Event), nameof(Event.exitEvent)), postfix: new HarmonyMethod(typeof(SwimPatches), nameof(SwimPatches.Event_exitEvent_Postfix)) ); harmony.Patch( original: AccessTools.Method(typeof(Farmer), "updateCommon"), prefix: new HarmonyMethod(typeof(SwimPatches), nameof(SwimPatches.Farmer_updateCommon_Prefix)), postfix: new HarmonyMethod(typeof(SwimPatches), nameof(SwimPatches.Farmer_updateCommon_Postfix)), transpiler: new HarmonyMethod(typeof(SwimPatches), nameof(SwimPatches.Farmer_updateCommon_Transpiler)) ); harmony.Patch( original: AccessTools.Method(typeof(Farmer), nameof(Farmer.setRunning)), prefix: new HarmonyMethod(typeof(SwimPatches), nameof(SwimPatches.Farmer_setRunning_Prefix)), postfix: new HarmonyMethod(typeof(SwimPatches), nameof(SwimPatches.Farmer_setRunning_Postfix)) ); harmony.Patch( original: AccessTools.Method(typeof(Farmer), nameof(Farmer.changeIntoSwimsuit)), postfix: new HarmonyMethod(typeof(SwimPatches), nameof(SwimPatches.Farmer_changeIntoSwimsuit_Postfix)) ); harmony.Patch( original: AccessTools.Method(typeof(Toolbar), nameof(Toolbar.draw), new Type[] { typeof(SpriteBatch) }), prefix: new HarmonyMethod(typeof(SwimPatches), nameof(SwimPatches.Toolbar_draw_Prefix)) ); /* * * harmony.Patch( * original: AccessTools.Method(typeof(Wand), nameof(Wand.DoFunction)), * transpiler: new HarmonyMethod(typeof(SwimPatches), nameof(SwimPatches.Wand_DoFunction_Transpiler)) * ); * */ harmony.Patch( original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.draw)), prefix: new HarmonyMethod(typeof(SwimPatches), nameof(SwimPatches.GameLocation_draw_Prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.UpdateWhenCurrentLocation)), postfix: new HarmonyMethod(typeof(SwimPatches), nameof(SwimPatches.GameLocation_UpdateWhenCurrentLocation_Postfix)) ); harmony.Patch( original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.resetForPlayerEntry)), prefix: new HarmonyMethod(typeof(SwimPatches), nameof(SwimPatches.GameLocation_resetForPlayerEntry_Prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.isCollidingPosition), new Type[] { typeof(Rectangle), typeof(xTile.Dimensions.Rectangle), typeof(bool), typeof(int), typeof(bool), typeof(Character) }), prefix: new HarmonyMethod(typeof(SwimPatches), nameof(SwimPatches.GameLocation_isCollidingPosition_Prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.performTouchAction)), prefix: new HarmonyMethod(typeof(SwimPatches), nameof(SwimPatches.GameLocation_performTouchAction_Prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.checkAction)), prefix: new HarmonyMethod(typeof(SwimPatches), nameof(SwimPatches.GameLocation_checkAction_Prefix)) ); harmony.Patch( original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.isCollidingPosition), new Type[] { typeof(Rectangle), typeof(xTile.Dimensions.Rectangle), typeof(bool), typeof(int), typeof(bool), typeof(Character), typeof(bool), typeof(bool), typeof(bool) }), postfix: new HarmonyMethod(typeof(SwimPatches), nameof(SwimPatches.GameLocation_isCollidingPosition_Postfix)) ); harmony.Patch( original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.sinkDebris)), postfix: new HarmonyMethod(typeof(SwimPatches), nameof(SwimPatches.GameLocation_sinkDebris_Postfix)) ); }
public static void AbigailCaveTick() { Game1.player.CurrentToolIndex = Game1.player.items.Count; List <NPC> list = Game1.player.currentLocation.characters.ToList().FindAll((n) => (n is Monster) && (n as Monster).Health <= 0); foreach (NPC n in list) { Game1.player.currentLocation.characters.Remove(n); } if (abigailTicks < 0) { return; } Game1.exitActiveMenu(); if (abigailTicks == 0) { FieldInfo f1 = Game1.player.currentLocation.characters.GetType().GetField("OnValueRemoved", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); f1.SetValue(Game1.player.currentLocation.characters, null); } Vector2 v = Vector2.Zero; float yrt = (float)(1 / Math.Sqrt(2)); if (Helper.Input.IsDown(SButton.Up)) { if (Helper.Input.IsDown(SButton.Right)) { v = new Vector2(yrt, -yrt); } else if (Helper.Input.IsDown(SButton.Left)) { v = new Vector2(-yrt, -yrt); } else { v = new Vector2(0, -1); } } else if (Helper.Input.IsDown(SButton.Down)) { if (Helper.Input.IsDown(SButton.Right)) { v = new Vector2(yrt, yrt); } else if (Helper.Input.IsDown(SButton.Left)) { v = new Vector2(-yrt, yrt); } else { v = new Vector2(0, 1); } } else if (Helper.Input.IsDown(SButton.Right)) { v = new Vector2(1, 0); } else if (Helper.Input.IsDown(SButton.Left)) { v = new Vector2(-1, 0); } else if (Helper.Input.IsDown(SButton.MouseLeft)) { float x = Game1.viewport.X + Game1.getOldMouseX() - Game1.player.position.X; float y = Game1.viewport.Y + Game1.getOldMouseY() - Game1.player.position.Y; float dx = Math.Abs(x); float dy = Math.Abs(y); if (y < 0) { if (x > 0) { if (dy > dx) { if (dy - dx > dy / 2) { v = new Vector2(0, -1); } else { v = new Vector2(yrt, -yrt); } } else { if (dx - dy > x / 2) { v = new Vector2(1, 0); } else { v = new Vector2(yrt, -yrt); } } } else { if (dy > dx) { if (dy - dx > dy / 2) { v = new Vector2(0, -1); } else { v = new Vector2(-yrt, -yrt); } } else { if (dx - dy > x / 2) { v = new Vector2(-1, 0); } else { v = new Vector2(-yrt, -yrt); } } } } else { if (x > 0) { if (dy > dx) { if (dy - dx > dy / 2) { v = new Vector2(0, 1); } else { v = new Vector2(yrt, yrt); } } else { if (dx - dy > x / 2) { v = new Vector2(1, 0); } else { v = new Vector2(yrt, yrt); } } } else { if (dy > dx) { if (dy - dx > dy / 2) { v = new Vector2(0, -1); } else { v = new Vector2(-yrt, yrt); } } else { if (dx - dy > x / 2) { v = new Vector2(-1, 0); } else { v = new Vector2(-yrt, yrt); } } } } } if (v != Vector2.Zero && Game1.player.millisecondsPlayed - lastProjectile > 350) { Game1.player.currentLocation.projectiles.Add(new AbigailProjectile(1, 383, 0, 0, 0, v.X * 6, v.Y * 6, new Vector2(Game1.player.getStandingX() - 24, Game1.player.getStandingY() - 48), "Cowboy_monsterDie", "Cowboy_gunshot", false, true, Game1.player.currentLocation, Game1.player, true)); lastProjectile = Game1.player.millisecondsPlayed; } foreach (SButton button in abigailShootButtons) { if (Helper.Input.IsDown(button)) { switch (button) { case SButton.Up: break; case SButton.Right: v = new Vector2(1, 0); break; case SButton.Down: v = new Vector2(0, 1); break; default: v = new Vector2(-1, 0); break; } } } abigailTicks++; if (abigailTicks > 80000 / 16f) { if (Game1.player.currentLocation.characters.ToList().FindAll((n) => (n is Monster)).Count > 0) { return; } abigailTicks = -1; Game1.player.hat.Value = null; Game1.stopMusicTrack(Game1.MusicContext.Default); if (!Game1.player.mailReceived.Contains("ScubaFins")) { Game1.playSound("Cowboy_Secret"); SwimMaps.AddScubaChest(Game1.player.currentLocation, new Vector2(8, 8), "ScubaFins"); } Game1.player.currentLocation.setMapTile(8, 16, 91, "Buildings", null); Game1.player.currentLocation.setMapTile(9, 16, 92, "Buildings", null); Game1.player.currentLocation.setTileProperty(9, 16, "Back", "Water", "T"); Game1.player.currentLocation.setMapTile(10, 16, 93, "Buildings", null); Game1.player.currentLocation.setMapTile(8, 17, 107, "Buildings", null); Game1.player.currentLocation.setMapTile(9, 17, 108, "Back", null); Game1.player.currentLocation.setTileProperty(9, 17, "Back", "Water", "T"); Game1.player.currentLocation.removeTile(9, 17, "Buildings"); Game1.player.currentLocation.setMapTile(10, 17, 109, "Buildings", null); Game1.player.currentLocation.setMapTile(8, 18, 139, "Buildings", null); Game1.player.currentLocation.setMapTile(9, 18, 140, "Buildings", null); Game1.player.currentLocation.setMapTile(10, 18, 141, "Buildings", null); SwimMaps.AddWaterTiles(Game1.player.currentLocation); } else { if (Game1.random.NextDouble() < 0.04) { int which = Game1.random.Next(3); Point p = new Point(); switch (Game1.random.Next(4)) { case 0: p = new Point(8 + which, 1); break; case 1: p = new Point(1, 8 + which); break; case 2: p = new Point(8 + which, 16); break; case 3: p = new Point(16, 8 + which); break; } Game1.player.currentLocation.characters.Add(new AbigailMetalHead(new Vector2(p.X * Game1.tileSize, p.Y * Game1.tileSize), 0)); } } }
public static void GameLoop_DayStarted(object sender, DayStartedEventArgs e) { foreach (KeyValuePair <string, DiveMap> kvp in ModEntry.diveMaps) { GameLocation location = Game1.getLocationFromName(kvp.Key); if (location == null) { Monitor.Log($"GameLocation {kvp.Key} not found in day started loop"); continue; } if (kvp.Value.Features.Contains("OceanTreasure") || kvp.Value.Features.Contains("OceanResources") || kvp.Value.Features.Contains("Minerals")) { Monitor.Log($"Clearing overlay objects from GameLocation {location.Name} "); location.overlayObjects.Clear(); } if (kvp.Value.Features.Contains("OceanTreasure")) { Monitor.Log($"Adding ocean treasure to GameLocation {location.Name} "); SwimMaps.AddOceanTreasure(location); } if (kvp.Value.Features.Contains("OceanResources")) { Monitor.Log($"Adding ocean forage to GameLocation {location.Name} "); SwimMaps.AddOceanForage(location); } if (kvp.Value.Features.Contains("Minerals")) { Monitor.Log($"Adding minerals to GameLocation {location.Name} "); SwimMaps.AddMinerals(location); } if (kvp.Value.Features.Contains("SmolFishies") || kvp.Value.Features.Contains("BigFishies") || kvp.Value.Features.Contains("Crabs")) { Monitor.Log($"Clearing characters from GameLocation {location.Name} "); location.characters.Clear(); } if (kvp.Value.Features.Contains("SmolFishies")) { Monitor.Log($"Adding smol fishies to GameLocation {location.Name} "); SwimMaps.AddFishies(location); } if (kvp.Value.Features.Contains("BigFishies")) { Monitor.Log($"Adding big fishies to GameLocation {location.Name} "); SwimMaps.AddFishies(location, false); } if (kvp.Value.Features.Contains("Crabs")) { Monitor.Log($"Adding crabs to GameLocation {location.Name} "); SwimMaps.AddCrabs(location); } if (kvp.Value.Features.Contains("WaterTiles")) { Monitor.Log($"Adding water tiles to GameLocation {location.Name} "); SwimMaps.AddWaterTiles(location); } if (kvp.Value.Features.Contains("Underwater")) { Monitor.Log($"Removing water tiles from GameLocation {location.Name} "); SwimMaps.RemoveWaterTiles(location); } } if (Game1.getLocationFromName("ScubaCave") != null && !Game1.player.mailReceived.Contains("ScubaMask")) { SwimMaps.AddScubaChest(Game1.getLocationFromName("ScubaCave"), new Vector2(10, 14), "ScubaMask"); } ModEntry.marinerQuestionsWrongToday = false; ModEntry.oxygen = SwimUtils.MaxOxygen(); }