Player stops auto walking if WASD is pressed

master
Mohammad Shoaib 2022-05-15 11:47:48 +05:30
parent c8b274347e
commit cb49832b5a
2 changed files with 49 additions and 18 deletions

View File

@ -20,9 +20,10 @@ namespace stardew_access.Features
private Vector2 relativeOffsetLockPosition = Vector2.Zero;
private Boolean relativeOffsetLock = false;
private Vector2 prevPlayerPosition = Vector2.Zero, prevFacing = Vector2.Zero;
private Boolean isAutoWalking = false;
private Vector2 finalTile = Vector2.Zero;
public Boolean isAutoWalking = false;
private Vector2 PlayerFacingVector
{
get
@ -133,22 +134,40 @@ namespace stardew_access.Features
}
else if (MainClass.Config.AutoWalkToTile.JustPressed() && StardewModdingAPI.Context.IsPlayerFree)
{
PathFindController controller = new PathFindController(Game1.player, Game1.currentLocation, this.GetViewingTile().ToPoint(), Game1.player.FacingDirection);
controller.allowPlayerPathingInEvent = true;
if (controller.pathToEndPoint != null && controller.pathToEndPoint.Count > 0)
{
Game1.player.controller = controller;
this.isAutoWalking = true;
this.finalTile = this.GetViewingTile();
MainClass.ScreenReader.Say($"Moving to {this.finalTile.X}x {this.finalTile.Y}y", true);
}
else
{
MainClass.ScreenReader.Say($"Cannot move to {this.finalTile.X}x {this.finalTile.Y}y", true);
}
this.startAutoWalking();
}
}
private void startAutoWalking()
{
PathFindController controller = new PathFindController(Game1.player, Game1.currentLocation, this.GetViewingTile().ToPoint(), Game1.player.FacingDirection);
controller.allowPlayerPathingInEvent = true;
if (controller.pathToEndPoint != null && controller.pathToEndPoint.Count > 0)
{
Game1.player.controller = controller;
this.isAutoWalking = true;
this.finalTile = this.GetViewingTile();
MainClass.ScreenReader.Say($"Moving to {this.finalTile.X}x {this.finalTile.Y}y", true);
}
else
{
MainClass.ScreenReader.Say($"Cannot move to {this.finalTile.X}x {this.finalTile.Y}y", true);
}
}
/// <summary>
/// Stop the auto walk controller and reset variables
/// </summary>
/// <param name="wasForced">Narrates a message if set to true.</param>
public void stopAutoWalking(bool wasForced = false)
{
this.finalTile = Vector2.Zero;
this.isAutoWalking = false;
Game1.player.controller = null;
if (wasForced)
MainClass.ScreenReader.Say("Stopped moving", true);
}
private void cursorMoveInput(Vector2 delta, Boolean precise = false)
{
if (!tryMoveTileView(delta)) return;
@ -219,11 +238,13 @@ namespace stardew_access.Features
if (MainClass.Config.SnapMouse)
this.SnapMouseToPlayer();
if (this.isAutoWalking && this.finalTile != Vector2.Zero && this.finalTile == CurrentPlayer.Position)
if (this.isAutoWalking)
{
MainClass.ScreenReader.Say("Reached destination", true);
this.finalTile = Vector2.Zero;
this.isAutoWalking = false;
if (this.finalTile != Vector2.Zero && this.finalTile == CurrentPlayer.Position)
{
MainClass.ScreenReader.Say("Reached destination", true);
this.stopAutoWalking();
}
}
}

View File

@ -226,6 +226,16 @@ namespace stardew_access
if (!Context.IsPlayerFree)
return;
// Stops the auto walk controller if any movement key(WASD) is pressed
if (TileViewerFeature.isAutoWalking &&
(e.Button.Equals(SButtonExtensions.ToSButton(Game1.options.moveUpButton[0]))
|| e.Button.Equals(SButtonExtensions.ToSButton(Game1.options.moveDownButton[0]))
|| e.Button.Equals(SButtonExtensions.ToSButton(Game1.options.moveLeftButton[0]))
|| e.Button.Equals(SButtonExtensions.ToSButton(Game1.options.moveRightButton[0]))))
{
TileViewerFeature.stopAutoWalking(wasForced: true);
}
// Narrate Current Location
if (Config.LocationKey.JustPressed())
{