public static void Display_RenderedHud(object sender, RenderedHudEventArgs e) { if (Game1.player.currentLocation.Name == "ScubaAbigailCave") { if (abigailTicks > 0 && abigailTicks < 80000 / 16) { SwimUtils.MakeOxygenBar((80000 / 16) - abigailTicks, 80000 / 16); } e.SpriteBatch.Draw(ModEntry.OxygenBarTexture, new Vector2((int)Math.Round(Game1.viewport.Width * 0.13f), 100), Color.White); return; } int maxOx = SwimUtils.MaxOxygen(); if (ModEntry.oxygen < maxOx) { SwimUtils.MakeOxygenBar(ModEntry.oxygen, maxOx); e.SpriteBatch.Draw(ModEntry.OxygenBarTexture, new Vector2((int)Math.Round(Game1.viewport.Width * 0.13f), 100), Color.White); } }
public static void Display_RenderedHud(object sender, RenderedHudEventArgs e) { if (Game1.player.currentLocation.Name == "ScubaAbigailCave") { if (abigailTicks > 0 && abigailTicks < 30 * 5) { e.SpriteBatch.Draw(Game1.mouseCursors, new Vector2(Game1.viewport.Width, Game1.viewport.Height) / 2 - new Vector2(78, 31) / 2, new Rectangle?(new Rectangle(353, 1649, 78, 31)), new Color(255, 255, 255, abigailTicks > 30 * 3 ? (int)Math.Round(255 * (abigailTicks - 90) / 60f) : 255), 0f, Vector2.Zero, 3f, SpriteEffects.None, 0.99f); } if (abigailTicks > 0 && abigailTicks < 80000 / 16) { SwimUtils.MakeOxygenBar((80000 / 16) - abigailTicks, 80000 / 16); } e.SpriteBatch.Draw(ModEntry.OxygenBarTexture, new Vector2((int)Math.Round(Game1.viewport.Width * 0.13f), 100), Color.White); return; } int maxOx = SwimUtils.MaxOxygen(); if (ModEntry.oxygen < maxOx) { SwimUtils.MakeOxygenBar(ModEntry.oxygen, maxOx); e.SpriteBatch.Draw(ModEntry.OxygenBarTexture, new Vector2((int)Math.Round(Game1.viewport.Width * 0.13f), 100), Color.White); } }
public static void GameLoop_UpdateTicked(object sender, UpdateTickedEventArgs e) { if (Game1.player.currentLocation == null || Game1.player == null || !Game1.displayFarmer || Game1.player.position == null) { return; } ModEntry.isUnderwater = SwimUtils.IsMapUnderwater(Game1.player.currentLocation.Name); if (Game1.player.currentLocation.Name == "ScubaAbigailCave") { AbigailCaveTick(); } if (Game1.activeClickableMenu == null) { if (ModEntry.isUnderwater) { if (ModEntry.oxygen >= 0) { if (!SwimUtils.IsWearingScubaGear()) { ModEntry.oxygen--; } else { if (ModEntry.oxygen < SwimUtils.MaxOxygen()) { ModEntry.oxygen++; } if (ModEntry.oxygen < SwimUtils.MaxOxygen()) { ModEntry.oxygen++; } } } if (ModEntry.oxygen < 0 && !surfacing) { surfacing = true; Game1.playSound("pullItemFromWater"); DiveLocation diveLocation = ModEntry.diveMaps[Game1.player.currentLocation.Name].DiveLocations.Last(); SwimUtils.DiveTo(diveLocation); } } else { surfacing = false; if (ModEntry.oxygen < SwimUtils.MaxOxygen()) { ModEntry.oxygen++; } if (ModEntry.oxygen < SwimUtils.MaxOxygen()) { ModEntry.oxygen++; } } } if (SwimUtils.IsWearingScubaGear()) { ticksWearingScubaGear++; if (Config.BreatheSound && breatheEffect != null && (lastBreatheSound == 0 || ticksWearingScubaGear - lastBreatheSound > 6000 / 16)) { Monitor.Log("Playing breathe sound"); lastBreatheSound = ticksWearingScubaGear; breatheEffect.Play(0.5f * Game1.options.soundVolumeLevel, 0f, 0f); } } else { if (breatheEffect != null && lastBreatheSound != 0) { breatheEffect.Dispose(); LoadBreatheSound(); } lastBreatheSound = 0; ticksWearingScubaGear = 0; } if (isJumping) { float difx = endJumpLoc.X - startJumpLoc.X; float dify = endJumpLoc.Y - startJumpLoc.Y; float completed = Game1.player.freezePause / (float)Config.JumpTimeInMilliseconds; if (Game1.player.freezePause <= 0) { Game1.player.position.Value = endJumpLoc; isJumping = false; if (ModEntry.willSwim) { Game1.player.currentLocation.playSound("waterSlosh", NetAudio.SoundContext.Default); Game1.player.swimming.Value = true; } else { if (!Config.SwimSuitAlways) { Game1.player.changeOutOfSwimSuit(); } } return; } Game1.player.position.Value = new Vector2(endJumpLoc.X - (difx * completed), endJumpLoc.Y - (dify * completed) - (float)Math.Sin(completed * Math.PI) * 64); return; } // only if ready to swim from here on! if (!Config.ReadyToSwim || !Context.IsPlayerFree) { return; } if (Game1.player.swimming) { if (!SwimUtils.IsInWater() && !isJumping) { Monitor.Log("Swimming out of water"); ModEntry.willSwim = false; Game1.player.freezePause = Config.JumpTimeInMilliseconds; Game1.player.currentLocation.playSound("dwop", NetAudio.SoundContext.Default); Game1.player.currentLocation.playSound("waterSlosh", NetAudio.SoundContext.Default); isJumping = true; startJumpLoc = Game1.player.position.Value; endJumpLoc = Game1.player.position.Value; Game1.player.swimming.Value = false; if (Game1.player.bathingClothes && !Config.SwimSuitAlways) { Game1.player.changeOutOfSwimSuit(); } } DiveMap dm = null; Point edgePos = Game1.player.getTileLocationPoint(); if (ModEntry.diveMaps.ContainsKey(Game1.player.currentLocation.Name)) { dm = ModEntry.diveMaps[Game1.player.currentLocation.Name]; } if (Game1.player.position.Y > Game1.viewport.Y + Game1.viewport.Height - 16) { Game1.player.position.Value = new Vector2(Game1.player.position.X, Game1.viewport.Y + Game1.viewport.Height - 17); if (dm != null) { EdgeWarp edge = dm.EdgeWarps.Find((x) => x.ThisMapEdge == "Bottom" && x.FirstTile <= edgePos.X && x.LastTile >= edgePos.X); if (edge != null) { Point pos = SwimUtils.GetEdgeWarpDestination(edgePos.X, edge); if (pos != Point.Zero) { Monitor.Log("warping south"); Game1.warpFarmer(edge.OtherMapName, pos.X, pos.Y, false); } } } } else if (Game1.player.position.Y < Game1.viewport.Y - 16) { Game1.player.position.Value = new Vector2(Game1.player.position.X, Game1.viewport.Y - 15); if (dm != null) { EdgeWarp edge = dm.EdgeWarps.Find((x) => x.ThisMapEdge == "Top" && x.FirstTile <= edgePos.X && x.LastTile >= edgePos.X); if (edge != null) { Point pos = SwimUtils.GetEdgeWarpDestination(edgePos.X, edge); if (pos != Point.Zero) { Monitor.Log("warping north"); Game1.warpFarmer(edge.OtherMapName, pos.X, pos.Y, false); } } } } else if (Game1.player.position.X > Game1.viewport.X + Game1.viewport.Width - 32) { Game1.player.position.Value = new Vector2(Game1.viewport.X + Game1.viewport.Width - 33, Game1.player.position.Y); if (dm != null) { EdgeWarp edge = dm.EdgeWarps.Find((x) => x.ThisMapEdge == "Right" && x.FirstTile <= edgePos.Y && x.LastTile >= edgePos.Y); if (edge != null) { Point pos = SwimUtils.GetEdgeWarpDestination(edgePos.Y, edge); if (pos != Point.Zero) { Monitor.Log("warping east"); Game1.warpFarmer(edge.OtherMapName, pos.X, pos.Y, false); } } } if (Game1.player.currentLocation.Name == "Forest") { if (Game1.player.position.Y / 64 > 74) { Game1.warpFarmer("Beach", 0, 13, false); } else { Game1.warpFarmer("Town", 0, 100, false); } } } else if (Game1.player.position.X < Game1.viewport.X - 32) { Game1.player.position.Value = new Vector2(Game1.viewport.X - 31, Game1.player.position.Y); if (dm != null) { EdgeWarp edge = dm.EdgeWarps.Find((x) => x.ThisMapEdge == "Left" && x.FirstTile <= edgePos.X && x.LastTile >= edgePos.X); if (edge != null) { Point pos = SwimUtils.GetEdgeWarpDestination(edgePos.Y, edge); if (pos != Point.Zero) { Monitor.Log("warping west"); Game1.warpFarmer(edge.OtherMapName, pos.X, pos.Y, false); } } } if (Game1.player.currentLocation.Name == "Town") { Game1.warpFarmer("Forest", 119, 43, false); } else if (Game1.player.currentLocation.Name == "Beach") { Game1.warpFarmer("Forest", 119, 111, false); } } if (Game1.player.bathingClothes && SwimUtils.IsWearingScubaGear() && !Config.SwimSuitAlways) { Game1.player.changeOutOfSwimSuit(); } else if (!Game1.player.bathingClothes && (!SwimUtils.IsWearingScubaGear() || Config.SwimSuitAlways)) { Game1.player.changeIntoSwimsuit(); } if (Game1.player.boots.Value != null && ModEntry.scubaFinsID != -1 && Game1.player.boots.Value.indexInTileSheet == ModEntry.scubaFinsID) { int buffId = 42883167; Buff buff = Game1.buffsDisplay.otherBuffs.FirstOrDefault((Buff p) => p.which == buffId); if (buff == null) { BuffsDisplay buffsDisplay = Game1.buffsDisplay; Buff buff2 = new Buff(0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 1, "Scuba Fins", Helper.Translation.Get("scuba-fins")); buff2.which = buffId; buff = buff2; buffsDisplay.addOtherBuff(buff2); } buff.millisecondsDuration = 50; } } else { if (SwimUtils.IsInWater() && !isJumping) { Monitor.Log("In water not swimming"); ModEntry.willSwim = true; Game1.player.freezePause = Config.JumpTimeInMilliseconds; Game1.player.currentLocation.playSound("dwop", NetAudio.SoundContext.Default); isJumping = true; startJumpLoc = Game1.player.position.Value; endJumpLoc = Game1.player.position.Value; Game1.player.swimming.Value = true; if (!Game1.player.bathingClothes && !SwimUtils.IsWearingScubaGear()) { Game1.player.changeIntoSwimsuit(); } } } SwimUtils.CheckIfMyButtonDown(); if (!ModEntry.myButtonDown || Game1.player.millisecondsPlayed - lastJump < 250 || SwimUtils.IsMapUnderwater(Game1.player.currentLocation.Name)) { return; } if (Helper.Input.IsDown(SButton.MouseLeft) && !Game1.player.swimming && (Game1.player.CurrentTool is WateringCan || Game1.player.CurrentTool is FishingRod)) { return; } List <Vector2> tiles = SwimUtils.GetTilesInDirection(5); Vector2 jumpLocation = Vector2.Zero; double distance = -1; int maxDistance = 0; switch (Game1.player.FacingDirection) { case 0: distance = Math.Abs(Game1.player.position.Y - tiles.Last().Y *Game1.tileSize); maxDistance = 72; break; case 2: distance = Math.Abs(Game1.player.position.Y - tiles.Last().Y *Game1.tileSize); maxDistance = 48; break; case 1: case 3: distance = Math.Abs(Game1.player.position.X - tiles.Last().X *Game1.tileSize); maxDistance = 65; break; } if (Helper.Input.IsDown(SButton.MouseLeft)) { try { int xTile = (Game1.viewport.X + Game1.getOldMouseX()) / 64; int yTile = (Game1.viewport.Y + Game1.getOldMouseY()) / 64; bool water = Game1.player.currentLocation.waterTiles[xTile, yTile]; if (Game1.player.swimming != water) { distance = -1; } } catch { } } //Monitor.Log("Distance: " + distance); bool nextToLand = Game1.player.swimming && !Game1.player.currentLocation.isTilePassable(new Location((int)tiles.Last().X, (int)tiles.Last().Y), Game1.viewport) && !SwimUtils.IsWaterTile(tiles[tiles.Count - 2]) && distance < maxDistance; bool nextToWater = false; try { nextToWater = !Game1.player.swimming && !SwimUtils.IsTilePassable(Game1.player.currentLocation, new Location((int)tiles.Last().X, (int)tiles.Last().Y), Game1.viewport) && (Game1.player.currentLocation.waterTiles[(int)tiles.Last().X, (int)tiles.Last().Y] || SwimUtils.IsWaterTile(tiles[tiles.Count - 2])) && distance < maxDistance; } catch { //Monitor.Log($"exception trying to get next to water: {ex}"); } //Monitor.Log($"next passable {Game1.player.currentLocation.isTilePassable(new Location((int)tiles.Last().X, (int)tiles.Last().Y), Game1.viewport)} next to land: {nextToLand}, next to water: {nextToWater}"); if (Helper.Input.IsDown(Config.SwimKey) || nextToLand || nextToWater) { //Monitor.Log("okay to jump"); for (int i = 0; i < tiles.Count; i++) { Vector2 tileV = tiles[i]; bool isWater = false; bool isPassable = false; try { Tile tile = Game1.player.currentLocation.map.GetLayer("Buildings").PickTile(new Location((int)tileV.X * Game1.tileSize, (int)tileV.Y * Game1.tileSize), Game1.viewport.Size); isWater = SwimUtils.IsWaterTile(tileV); isPassable = (nextToLand && !isWater && SwimUtils.IsTilePassable(Game1.player.currentLocation, new Location((int)tileV.X, (int)tileV.Y), Game1.viewport)) || (nextToWater && isWater && (tile == null || tile.TileIndex == 76)); //Monitor.Log($"Trying {tileV} is passable {isPassable} isWater {isWater}"); if (!SwimUtils.IsTilePassable(Game1.player.currentLocation, new Location((int)tileV.X, (int)tileV.Y), Game1.viewport) && !isWater && nextToLand) { //Monitor.Log($"Nixing {tileV}"); jumpLocation = Vector2.Zero; } } catch (Exception ex) { Monitor.Log("" + ex); } if (nextToLand && !isWater && isPassable) { Monitor.Log($"Jumping to {tileV}"); jumpLocation = tileV; } if (nextToWater && isWater && isPassable) { Monitor.Log($"Jumping to {tileV}"); jumpLocation = tileV; } } } if (jumpLocation != Vector2.Zero) { lastJump = Game1.player.millisecondsPlayed; //Monitor.Log("got swim location"); if (Game1.player.swimming) { ModEntry.willSwim = false; Game1.player.swimming.Value = false; Game1.player.freezePause = Config.JumpTimeInMilliseconds; Game1.player.currentLocation.playSound("dwop", NetAudio.SoundContext.Default); Game1.player.currentLocation.playSound("waterSlosh", NetAudio.SoundContext.Default); } else { ModEntry.willSwim = true; if (!SwimUtils.IsWearingScubaGear()) { Game1.player.changeIntoSwimsuit(); } Game1.player.freezePause = Config.JumpTimeInMilliseconds; Game1.player.currentLocation.playSound("dwop", NetAudio.SoundContext.Default); } isJumping = true; startJumpLoc = Game1.player.position.Value; endJumpLoc = new Vector2(jumpLocation.X * Game1.tileSize, jumpLocation.Y * Game1.tileSize); } }
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(); }