public bool TryOpenDoor(DoorOpenCloseTogglingInfo doorInfo, PlayerInfoForOpeningDoors playerInfo) { Point tileCoordsForToggling = doorInfo.tileCoordsForToggling; Rectangle rectangle = new Rectangle(doorInfo.tileCoordsForToggling.X * 16, doorInfo.tileCoordsForToggling.Y * 16, 16, 80); switch (playerInfo.playerGravityDirection) { case 1: rectangle.Height += 16; break; case -1: rectangle.Y -= 16; rectangle.Height += 16; break; } if (!rectangle.Intersects(playerInfo.hitboxToOpenDoor)) { return(false); } if (playerInfo.hitboxToOpenDoor.Top < rectangle.Top || playerInfo.hitboxToOpenDoor.Bottom > rectangle.Bottom) { return(false); } bool flag = false; if (WorldGen.ShiftTallGate(tileCoordsForToggling.X, tileCoordsForToggling.Y, flag)) { NetMessage.SendData(19, -1, -1, null, 4 + flag.ToInt(), tileCoordsForToggling.X, tileCoordsForToggling.Y); return(true); } return(false); }
private void TryAutoOpeningDoor(Point tileCoords, PlayerInfoForOpeningDoors playerInfo) { if (TryGetHandler(tileCoords, out DoorAutoHandler infoProvider)) { DoorOpenCloseTogglingInfo doorOpenCloseTogglingInfo = infoProvider.ProvideInfo(tileCoords); if (infoProvider.TryOpenDoor(doorOpenCloseTogglingInfo, playerInfo)) { _ongoingOpenDoors.Add(doorOpenCloseTogglingInfo); } } }
public void LookForDoorsToOpen(Player player) { PlayerInfoForOpeningDoors playerInfoForOpeningDoor = GetPlayerInfoForOpeningDoor(player); if (playerInfoForOpeningDoor.intendedOpeningDirection == 0 && player.velocity.X == 0f) { return; } Point tileCoords = default(Point); for (int i = playerInfoForOpeningDoor.tileCoordSpaceForCheckingForDoors.Left; i <= playerInfoForOpeningDoor.tileCoordSpaceForCheckingForDoors.Right; i++) { for (int j = playerInfoForOpeningDoor.tileCoordSpaceForCheckingForDoors.Top; j <= playerInfoForOpeningDoor.tileCoordSpaceForCheckingForDoors.Bottom; j++) { tileCoords.X = i; tileCoords.Y = j; TryAutoOpeningDoor(tileCoords, playerInfoForOpeningDoor); } } }
public bool TryOpenDoor(DoorOpenCloseTogglingInfo doorInfo, PlayerInfoForOpeningDoors playerInfo) { Point tileCoordsForToggling = doorInfo.tileCoordsForToggling; int intendedOpeningDirection = playerInfo.intendedOpeningDirection; Rectangle rectangle = new Rectangle(doorInfo.tileCoordsForToggling.X * 16, doorInfo.tileCoordsForToggling.Y * 16, 16, 48); switch (playerInfo.playerGravityDirection) { case 1: rectangle.Height += 16; break; case -1: rectangle.Y -= 16; rectangle.Height += 16; break; } if (!rectangle.Intersects(playerInfo.hitboxToOpenDoor)) { return(false); } if (playerInfo.hitboxToOpenDoor.Top < rectangle.Top || playerInfo.hitboxToOpenDoor.Bottom > rectangle.Bottom) { return(false); } WorldGen.OpenDoor(tileCoordsForToggling.X, tileCoordsForToggling.Y, intendedOpeningDirection); if (Main.tile[tileCoordsForToggling.X, tileCoordsForToggling.Y].type != 10) { NetMessage.SendData(19, -1, -1, null, 0, tileCoordsForToggling.X, tileCoordsForToggling.Y, intendedOpeningDirection); return(true); } WorldGen.OpenDoor(tileCoordsForToggling.X, tileCoordsForToggling.Y, -intendedOpeningDirection); if (Main.tile[tileCoordsForToggling.X, tileCoordsForToggling.Y].type != 10) { NetMessage.SendData(19, -1, -1, null, 0, tileCoordsForToggling.X, tileCoordsForToggling.Y, -intendedOpeningDirection); return(true); } return(false); }
private PlayerInfoForOpeningDoors GetPlayerInfoForOpeningDoor(Player player) { int num = player.controlRight.ToInt() - player.controlLeft.ToInt(); int playerGravityDirection = (int)player.gravDir; Rectangle hitbox = player.Hitbox; hitbox.Y -= -1; hitbox.Height += -2; float num2 = player.velocity.X; if (num == 0 && _timeWeCanOpenDoorsUsingVelocityAlone == 0) { num2 = 0f; } float value = (float)num + num2; int num3 = Math.Sign(value) * (int)Math.Ceiling(Math.Abs(value)); hitbox.X += num3; if (num == 0) { num = Math.Sign(value); } Rectangle hitbox2; Rectangle value2 = hitbox2 = player.Hitbox; hitbox2.X += num3; Rectangle r = Rectangle.Union(value2, hitbox2); Point point = r.TopLeft().ToTileCoordinates(); Point point2 = r.BottomRight().ToTileCoordinates(); Rectangle tileCoordSpaceForCheckingForDoors = new Rectangle(point.X, point.Y, point2.X - point.X, point2.Y - point.Y); PlayerInfoForOpeningDoors result = default(PlayerInfoForOpeningDoors); result.hitboxToOpenDoor = hitbox; result.intendedOpeningDirection = num; result.playerGravityDirection = playerGravityDirection; result.tileCoordSpaceForCheckingForDoors = tileCoordSpaceForCheckingForDoors; return(result); }