Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Swim] Update to 1.6 #133

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Overhaul manual swim logic
Previously, when using manual swim, the game would only check in the direction the player was facing, and if they were clicking, would only do that if they were clicking on the opposite of their current terrain i.e. if they were in water, would only attempt to leave if they were clicking on land.
Now when using manual swim, it checks the direction in which the player is clicking (or rather, the direction of the mouse relative to the player) and then the direction in which they're facing (in that order). Also, adds a config option to allow the player to choose whether they should be required to click on the opposite terrain.
FlyingTNT committed Mar 27, 2024
commit 47231e8f1498fc12ea014b4d04aa7e58d93c7ea0
2 changes: 2 additions & 0 deletions Swim/ModConfig.cs
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ public class ModConfig
public bool AddCrabs { get; set; }
public bool BreatheSound { get; set; }
public bool EnableClickToSwim { get; set; }
public bool MustClickOnOppositeTerrain { get; set; } // In click to swim, whether you must click on land to leave water (and vice versa) or can just click in the direction of land.
public int MineralPerThousandMin { get; set; }
public int MineralPerThousandMax { get; set; }
public int CrabsPerThousandMin { get; set; }
@@ -56,6 +57,7 @@ public ModConfig()
ShowOxygenBar = true;
SwimSuitAlways = false;
EnableClickToSwim = true;
MustClickOnOppositeTerrain = false;
BreatheSound = true;
SwimRestoresVitals = false;

108 changes: 85 additions & 23 deletions Swim/SwimHelperEvents.cs
Original file line number Diff line number Diff line change
@@ -371,7 +371,7 @@ public static void GameLoop_GameLaunched(object sender, GameLaunchedEventArgs e)
configMenu.AddBoolOption(
mod: ModEntry.context.ModManifest,
name: () => "NoAutoSwimSuit",
tooltip: () => "If set's false, character will NOT wear a swimsuit automatically, when you enter the water.",
tooltip: () => "If set's false, character will NOT wear a swimsuit automatically when you enter the water.",
getValue: () => Config.NoAutoSwimSuit,
setValue: value => Config.NoAutoSwimSuit = value
);
@@ -396,6 +396,13 @@ public static void GameLoop_GameLaunched(object sender, GameLaunchedEventArgs e)
getValue: () => Config.EnableClickToSwim,
setValue: value => Config.EnableClickToSwim = value
);
configMenu.AddBoolOption(
mod: ModEntry.context.ModManifest,
name: () => "MustClickOnOppositeTerrain",
tooltip: () => "Whether you must click on land to leave the water (or vice versa) or can just click in the direction of land (when using click to swim).",
getValue: () => Config.MustClickOnOppositeTerrain,
setValue: value => Config.MustClickOnOppositeTerrain = value
);
configMenu.AddBoolOption(
mod: ModEntry.context.ModManifest,
name: () => "SwimRestoresVitals",
@@ -1025,8 +1032,8 @@ public static void GameLoop_UpdateTicked(object sender, UpdateTickedEventArgs e)
if (buff == null)
{
BuffsDisplay buffsDisplay = Game1.buffsDisplay;
Buff buff2 = new Buff("42883167", "Scuba Fins", Helper.Translation.Get("scuba-fins"));
Buff buff2 = new Buff("42883167", "Scuba Fins", Helper.Translation.Get("scuba-fins"));

buff = buff2;
buffsDisplay.updatedIDs.Add(buff2.id);
}
@@ -1041,15 +1048,83 @@ public static void GameLoop_UpdateTicked(object sender, UpdateTickedEventArgs e)

// !IMP: Conditions with hand tools (i.e. rods), must be placed here.
if ((Helper.Input.IsDown(SButton.MouseLeft) && !Game1.player.swimming.Value && (Game1.player.CurrentTool is WateringCan || Game1.player.CurrentTool is FishingRod)) ||
(Helper.Input.IsDown(SButton.MouseRight) && !Game1.player.swimming.Value && Game1.player.CurrentTool is MeleeWeapon))
(Helper.Input.IsDown(SButton.MouseRight) && !Game1.player.swimming.Value && (Game1.player.CurrentTool is MeleeWeapon || Game1.player.CurrentTool is WateringCan)))
return;

List<Vector2> tiles = SwimUtils.GetTilesInDirection(5);
Vector2 jumpLocation = Vector2.Zero;
int direction = Game1.player.FacingDirection;

if (Helper.Input.IsDown(Config.ManualJumpButton) && Config.EnableClickToSwim)
{
try
{
int xTile = (int)Math.Round((Game1.viewport.X + Game1.getOldMouseX()) / 64f);
int yTile = (int)Math.Round((Game1.viewport.Y + Game1.getOldMouseY()) / 64f);
//Monitor.Log($"Click tile: ({xTile}, {yTile}), Player tile: ({Game1.player.TilePoint.X}, {Game1.player.TilePoint.Y})");
bool clickTileIsWater = Game1.player.currentLocation.waterTiles[xTile, yTile];
bool isClickingOnOppositeTerrain = clickTileIsWater != Game1.player.swimming.Value;
if (isClickingOnOppositeTerrain || !Config.MustClickOnOppositeTerrain)
{
// Set the direction to the direction of the cursor relative to the player.
if (Math.Abs(xTile - Game1.player.TilePoint.X) > Math.Abs(yTile - Game1.player.TilePoint.Y))
{
if (xTile - Game1.player.TilePoint.X > 0)
{
//Monitor.Log("Clicking right");
direction = 1;
}
else
{
//Monitor.Log("Clicking left");
direction = 3;
}
}
else
{
if (yTile - Game1.player.TilePoint.Y > 0)
{
//Monitor.Log("Clicking down");
direction = 2;
}
else
{
//Monitor.Log("Clicking up");
direction = 0;
}
}
}
else // If the player is pressing the manual swim button, manual swim is on, they are not clicking on the opposite terrain, and mustClickOnOppositeTerrain is true
{
return;
}
}
catch
{
// Assiming this happens when the game can't get the mouse position
Monitor.Log("Error in manual direction calculation!");
}
}

// At this point, direction will either be the direction the mouse is being clicked in, or the direction the player is facing, with the former prioritizing the latter

bool didJump = tryToJumpInDirection(direction);

// If we just tried to jump in the direction the player is facing, we don't want to try again. Additionally, if we jumped in the click direction, the player will now be facing that direction
// So this will only be run if we just tried to jump in the direction the player is clicking and failed.
if (!didJump && direction != Game1.player.FacingDirection)
{
tryToJumpInDirection(Game1.player.FacingDirection);
}
}

public static bool tryToJumpInDirection(int direction) // Returns whether or not it is jumping
{
double distance = -1;
int maxDistance = 0;
switch (Game1.player.FacingDirection)

List<Vector2> tiles = SwimUtils.GetTilesInDirection(5, direction);
Vector2 jumpLocation = Vector2.Zero;

switch (direction)
{
case 0:
distance = Math.Abs(Game1.player.position.Y - tiles.Last().Y * Game1.tileSize);
@@ -1068,23 +1143,7 @@ public static void GameLoop_UpdateTicked(object sender, UpdateTickedEventArgs e)
maxDistance = (int)Math.Round(Config.TriggerDistanceLeft * Config.TriggerDistanceMult);
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.Value != water)
{
distance = -1;
}
}
catch
{

}
}
//Monitor.Log("Distance: " + distance);

bool nextToLand = Game1.player.swimming.Value && !SwimUtils.IsWaterTile(tiles[tiles.Count - 2]) && distance < maxDistance;
@@ -1152,6 +1211,7 @@ public static void GameLoop_UpdateTicked(object sender, UpdateTickedEventArgs e)

if (jumpLocation != Vector2.Zero)
{
Game1.player.faceDirection(direction);
lastJump.Value = Game1.player.millisecondsPlayed;
//Monitor.Value.Log("got swim location");
if (Game1.player.swimming.Value)
@@ -1174,8 +1234,10 @@ public static void GameLoop_UpdateTicked(object sender, UpdateTickedEventArgs e)
isJumping.Value = true;
startJumpLoc.Value = Game1.player.position.Value;
endJumpLoc.Value = new Vector2(jumpLocation.X * Game1.tileSize, jumpLocation.Y * Game1.tileSize);
return true;
}

return false;
}

public static void AbigailCaveTick()
11 changes: 5 additions & 6 deletions Swim/SwimUtils.cs
Original file line number Diff line number Diff line change
@@ -298,11 +298,10 @@ public static bool IsInWater()
return output;
}

public static List<Vector2> GetTilesInDirection(int count)
public static List<Vector2> GetTilesInDirection(int count, int direction)
{
List<Vector2> tiles = new List<Vector2>();
int dir = Game1.player.FacingDirection;
if (dir == 1)
if (direction == 1)
{

for (int i = count; i > 0; i--)
@@ -312,7 +311,7 @@ public static List<Vector2> GetTilesInDirection(int count)

}

if (dir == 2)
if (direction == 2)
{

for (int i = count; i > 0; i--)
@@ -322,7 +321,7 @@ public static List<Vector2> GetTilesInDirection(int count)

}

if (dir == 3)
if (direction == 3)
{

for (int i = count; i > 0; i--)
@@ -332,7 +331,7 @@ public static List<Vector2> GetTilesInDirection(int count)

}

if (dir == 0)
if (direction == 0)
{

for (int i = count; i > 0; i--)
2 changes: 0 additions & 2 deletions Swim/assets/json-assets/Hats/Scuba Mask/hat.json
Original file line number Diff line number Diff line change
@@ -4,8 +4,6 @@
"PurchasePrice": "50000",
"ShowHair": true,
"IgnoreHairstyleOffset": true,
"CanPurchase": false,
"PurchaseFrom": "",
"NameLocalization":
{
// "es": "",