Skip to content

Commit 8c1d3e1

Browse files
author
CoronaSophium
committed
Add support for town sewer gate and mine transports
- Bump version up to v2.2.0 - Add config to enable automatic interactions with ladders going down in mines (disabled by default) - Add support for automatic interaction with mine elevators and exit ladders
1 parent a2ea489 commit 8c1d3e1

3 files changed

Lines changed: 45 additions & 17 deletions

File tree

Passage/Passage.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using StardewValley;
88
using StardewModdingAPI;
99
using StardewModdingAPI.Events;
10-
using StardewValley.Locations;
1110

1211
namespace Passage
1312
{
@@ -29,7 +28,7 @@ private void InteractWithObjectAhead(object Sender, EventArgs e)
2928
if (!Context.IsWorldReady || !Context.CanPlayerMove) return;
3029
if (!Game1.player.isMoving()) return;
3130

32-
Point pointAhead = Utility.GetPointAheadPlayer(Game1.player, Game1.tileSize);
31+
Point pointAhead = Utility.GetPointAheadPlayer();
3332
Point tileAhead = new Point(pointAhead.X / Game1.tileSize, pointAhead.Y / Game1.tileSize);
3433
StardewValley.Object objectAhead = (
3534
Game1.currentLocation.isObjectAt(pointAhead.X, pointAhead.Y) ? (
@@ -52,9 +51,13 @@ private void InteractWithObjectAhead(object Sender, EventArgs e)
5251
return;
5352
}
5453

55-
if (this.config.EnableAutoDoorInteract && !Convert.ToBoolean(Utility.GetDoorType(tileAhead, Game1.currentLocation)))
54+
int transportAhead = Utility.GetDoorType(tileAhead);
55+
if (this.config.EnableAutoTransport && Convert.ToBoolean(transportAhead))
5656
{
57-
// Interact with door tile ahead
57+
// If transportAhead is a ladder going down in the mines, check config to handle or not
58+
if (transportAhead == 8 && !this.config.EnableAutoMineDownLadder) return;
59+
60+
// Interact with transport tile ahead
5861
Game1.currentLocation.checkAction(new Location(tileAhead.X, tileAhead.Y), Game1.viewport, Game1.player);
5962

6063
return;

Passage/Utility.cs

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
using Microsoft.Xna.Framework;
2+
using xTile.Dimensions;
3+
using xTile.Tiles;
24

35
using StardewValley;
46
using StardewValley.Locations;
57
using StardewValley.Buildings;
6-
using StardewModdingAPI;
78

89
namespace Passage
910
{
1011
class Utility
1112
{
12-
public static Point GetPointAheadPlayer(StardewValley.Farmer player, int tileSize)
13+
public static Point GetPointAheadPlayer()
1314
{
14-
int tileAheadPlayerX = player.getTileX();
15-
int tileAheadPlayerY = player.getTileY();
15+
int tileAheadPlayerX = Game1.player.getTileX();
16+
int tileAheadPlayerY = Game1.player.getTileY();
1617

1718
// Get tile directly ahead of player based on facing
18-
switch (player.facingDirection)
19+
switch (Game1.player.facingDirection)
1920
{
2021
case 0:
2122
tileAheadPlayerY -= 1;
@@ -38,30 +39,54 @@ public static Point GetPointAheadPlayer(StardewValley.Farmer player, int tileSiz
3839
}
3940

4041
// Transform tile coords into absolute coords prior to returning
41-
return new Point(tileAheadPlayerX * tileSize, tileAheadPlayerY * tileSize);
42+
return new Point(tileAheadPlayerX * Game1.tileSize, tileAheadPlayerY * Game1.tileSize);
4243
}
4344

44-
public static int GetDoorType(Point tile, GameLocation currentLocation)
45+
public static int GetDoorType(Point tile)
4546
{
46-
if (currentLocation.doors.ContainsKey(tile)) return 1;
47-
if (currentLocation.doesTileHaveProperty(tile.X, tile.Y, "Action", "Buildings")?.Split(' ')?[0] == "Door") return 2;
48-
if (currentLocation is BuildableGameLocation)
47+
if (Game1.currentLocation.doors.ContainsKey(tile)) return 1;
48+
if (Game1.currentLocation.doesTileHaveProperty(tile.X, tile.Y, "Action", "Buildings")?.Split(' ')?[0] == "Door") return 2;
49+
if (Game1.currentLocation is BuildableGameLocation)
4950
{
50-
foreach (Building building in (currentLocation as BuildableGameLocation).buildings)
51+
foreach (Building building in (Game1.currentLocation as BuildableGameLocation).buildings)
5152
{
5253
if (building.indoors == null) continue;
5354
if (tile != new Point(building.tileX + building.humanDoor.X, building.tileY + building.humanDoor.Y)) continue;
5455
return 3;
5556
}
5657
}
58+
if (Game1.currentLocation.doesTileHaveProperty(tile.X, tile.Y, "Action", "Buildings") == "EnterSewer") return 4;
59+
// TODO: return 5 for Sewer entrance in the forest maybe?
60+
if (Game1.currentLocation.name == "Mine" || Game1.currentLocation is MineShaft)
61+
{
62+
Tile trueTile = Game1.currentLocation.map.GetLayer("Buildings").PickTile(new Location(tile.X * Game1.tileSize, tile.Y * Game1.tileSize), Game1.viewport.Size);
63+
if (trueTile != null)
64+
{
65+
switch (trueTile.TileIndex)
66+
{
67+
// Elevator
68+
case 112:
69+
return 6;
70+
71+
// Ladder (up)
72+
case 115:
73+
return 7;
74+
75+
// Ladder (down)
76+
case 173:
77+
return 8;
78+
}
79+
}
80+
}
5781

5882
return 0;
5983
}
6084
}
6185

6286
class ModConfig
6387
{
64-
public bool EnableAutoDoorInteract { get; set; } = true;
88+
public bool EnableAutoTransport { get; set; } = true;
89+
public bool EnableAutoMineDownLadder { get; set; } = false;
6590
public bool EnableAutoFenceGateManagement { get; set; } = true;
6691
public bool OnlyOpenFenceGateWhileRidingHorse { get; set; } = false;
6792
public float MaxDistanceToKeepFenceGateOpen { get; set; } = 1.1f;

Passage/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Name": "Passage",
33
"Author": "Manpreet \"Mannie\" Singh",
4-
"Version": "2.1.1",
4+
"Version": "2.2.0",
55
"Description": "Auto-interact with doors, and add proximity sensing to fence gates",
66
"UniqueID": "CoronaSophium.Passage",
77
"EntryDLL": "Passage.dll",

0 commit comments

Comments
 (0)