Пример #1
0
        public static void DiveTo(DiveLocation diveLocation, Farmer farmer)
        {
            DivePosition dp = diveLocation.OtherMapPos;

            if (dp == null)
            {
                Monitor.Log($"Diving to existing tile position");
                Point pos = farmer.getTileLocationPoint();
                dp = new DivePosition()
                {
                    X = pos.X,
                    Y = pos.Y
                };
            }
            if (!IsMapUnderwater(farmer.currentLocation.Name))
            {
                ModEntry.bubbles.Clear();
            }
            else
            {
            }

            Game1.playSound("pullItemFromWater");
            Game1.warpFarmer(diveLocation.OtherMapName, dp.X, dp.Y, false);
        }
Пример #2
0
        public static void DiveTo(DiveLocation diveLocation)
        {
            DivePosition dp = diveLocation.OtherMapPos;

            if (dp == null)
            {
                Monitor.Log($"Diving to existing tile position");
                Point pos = Game1.player.getTileLocationPoint();
                dp = new DivePosition()
                {
                    X = pos.X,
                    Y = pos.Y
                };
            }
            if (!IsMapUnderwater(Game1.player.currentLocation.Name))
            {
                ModEntry.bubbles.Value.Clear();
            }
            else
            {
                Game1.changeMusicTrack("none", false, Game1.MusicContext.Default);
            }

            Game1.playSound("pullItemFromWater");
            Game1.warpFarmer(diveLocation.OtherMapName, dp.X, dp.Y, false);
        }
Пример #3
0
        public static void GameLocation_sinkDebris_Postfix(GameLocation __instance, bool __result, Debris debris, Vector2 chunkTile, Vector2 chunkPosition)
        {
            try
            {
                if (__result == false || !Game1.IsMasterGame || !SwimUtils.DebrisIsAnItem(debris))
                {
                    return;
                }

                if (ModEntry.diveMaps.ContainsKey(__instance.Name) && ModEntry.diveMaps[__instance.Name].DiveLocations.Count > 0)
                {
                    Point    pos = new Point((int)chunkTile.X, (int)chunkTile.Y);
                    Location loc = new Location(pos.X, pos.Y);

                    DiveMap      dm           = ModEntry.diveMaps[__instance.Name];
                    DiveLocation diveLocation = null;
                    foreach (DiveLocation dl in dm.DiveLocations)
                    {
                        if (dl.GetRectangle().X == -1 || dl.GetRectangle().Contains(loc))
                        {
                            diveLocation = dl;
                            break;
                        }
                    }

                    if (diveLocation == null)
                    {
                        Monitor.Log($"sink debris: No dive destination for this point on this map");
                        return;
                    }

                    if (Game1.getLocationFromName(diveLocation.OtherMapName) == null)
                    {
                        Monitor.Log($"sink debris: Can't find destination map named {diveLocation.OtherMapName}", LogLevel.Warn);
                        return;
                    }


                    foreach (Chunk chunk in debris.Chunks)
                    {
                        if (chunk.position == chunkPosition)
                        {
                            Monitor.Log($"sink debris: creating copy of debris {debris.debrisType} chunk {chunk.debrisType} item {debris.item != null} on {diveLocation.OtherMapName}");

                            if (debris.debrisType != Debris.DebrisType.ARCHAEOLOGY && debris.debrisType != Debris.DebrisType.OBJECT && chunk.debrisType % 2 != 0)
                            {
                                Monitor.Log($"sink debris: non-item debris");
                                break;
                            }

                            Debris  newDebris;
                            Vector2 newTile = diveLocation.OtherMapPos == null ? chunkTile : new Vector2(diveLocation.OtherMapPos.X, diveLocation.OtherMapPos.Y);
                            Vector2 newPos  = new Vector2(newTile.X * Game1.tileSize, newTile.Y * Game1.tileSize);
                            if (debris.item != null)
                            {
                                newDebris = Game1.createItemDebris(debris.item, newPos, Game1.random.Next(4));
                                Game1.getLocationFromName(diveLocation.OtherMapName).debris.Add(newDebris);
                            }
                            else
                            {
                                Game1.createItemDebris(new StardewValley.Object(chunk.debrisType, 1), newPos, Game1.random.Next(4), Game1.getLocationFromName(diveLocation.OtherMapName));
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Monitor.Log($"Failed in {nameof(GameLocation_sinkDebris_Postfix)}:\n{ex}", LogLevel.Error);
            }
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        public static void Input_ButtonPressed(object sender, ButtonPressedEventArgs e)
        {
            if (Game1.player == null || Game1.player.currentLocation == null)
            {
                ModEntry.myButtonDown = false;
                return;
            }

            if (false && e.Button == SButton.Q)
            {
                SwimUtils.SeaMonsterSay("The quick brown fox jumped over the slow lazy dog.");
            }

            if (Game1.activeClickableMenu != null && Game1.player.currentLocation.Name == "ScubaCrystalCave" && Game1.player.currentLocation.lastQuestionKey.StartsWith("SwimMod_Mariner_"))
            {
                IClickableMenu menu = Game1.activeClickableMenu;
                if (menu == null || menu.GetType() != typeof(DialogueBox))
                {
                    return;
                }
                int             resp  = (int)typeof(DialogueBox).GetField("selectedResponse", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(menu);
                List <Response> resps = (List <Response>) typeof(DialogueBox).GetField("responses", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(menu);

                if (resp < 0 || resps == null || resp >= resps.Count || resps[resp] == null)
                {
                    return;
                }
                Game1.player.currentLocation.lastQuestionKey = "";

                SwimDialog.OldMarinerDialogue(resps[resp].responseKey);
                return;
            }

            if (false && e.Button == SButton.Q)
            {
                var v1 = Game1.game1;
                return;
                //Game1.player.currentLocation.overlayObjects[Game1.player.getTileLocation() + new Vector2(0, 1)] = new Chest(0, new List<Item>() { Helper.Input.IsDown(SButton.LeftShift) ? (Item)(new StardewValley.Object(434, 1)) : (new Hat(ModEntry.scubaMaskID)) }, Game1.player.getTileLocation() + new Vector2(0, 1), false, 0);
            }

            if (e.Button == Config.DiveKey && ModEntry.diveMaps.ContainsKey(Game1.player.currentLocation.Name) && ModEntry.diveMaps[Game1.player.currentLocation.Name].DiveLocations.Count > 0)
            {
                Point    pos = Game1.player.getTileLocationPoint();
                Location loc = new Location(pos.X, pos.Y);

                if (!SwimUtils.IsInWater())
                {
                    return;
                }

                DiveMap      dm           = ModEntry.diveMaps[Game1.player.currentLocation.Name];
                DiveLocation diveLocation = null;
                foreach (DiveLocation dl in dm.DiveLocations)
                {
                    if (dl.GetRectangle().X == -1 || dl.GetRectangle().Contains(loc))
                    {
                        diveLocation = dl;
                        break;
                    }
                }

                if (diveLocation == null)
                {
                    Monitor.Log($"No dive destination for this point on this map", LogLevel.Debug);
                    return;
                }

                if (Game1.getLocationFromName(diveLocation.OtherMapName) == null)
                {
                    Monitor.Log($"Can't find destination map named {diveLocation.OtherMapName}", LogLevel.Warn);
                    return;
                }

                Monitor.Log($"warping to {diveLocation.OtherMapName}", LogLevel.Debug);
                SwimUtils.DiveTo(diveLocation);
                return;
            }

            if (e.Button == Config.SwimKey && (!Game1.player.swimming || !Config.ReadyToSwim) && !isJumping)
            {
                Config.ReadyToSwim = !Config.ReadyToSwim;
                Helper.WriteConfig <ModConfig>(Config);
                Monitor.Log($"Ready to swim: {Config.ReadyToSwim}");
                return;
            }

            if (e.Button == Config.SwimSuitKey)
            {
                Config.SwimSuitAlways = !Config.SwimSuitAlways;
                Helper.WriteConfig <ModConfig>(Config);
                if (!Game1.player.swimming)
                {
                    if (!Config.SwimSuitAlways)
                    {
                        Game1.player.changeOutOfSwimSuit();
                    }
                    else
                    {
                        Game1.player.changeIntoSwimsuit();
                    }
                }
                return;
            }
        }