Adding buildlist command to list all the buildings on the farm for the preferred action

master
Mohammad Shoaib 2022-02-03 16:09:30 +05:30
parent d18fe74885
commit 547f6290c4
7 changed files with 211 additions and 141 deletions

View File

@ -2,6 +2,8 @@
using stardew_access.Patches;
using StardewModdingAPI;
using StardewValley;
using StardewValley.Buildings;
using StardewValley.Menus;
namespace stardew_access
{
@ -328,6 +330,32 @@ namespace stardew_access
else
MainClass.monitor.Log($"Marked positions:\t{toPrint}", LogLevel.Info);
});
helper.ConsoleCommands.Add("buildlist", "List all buildings for selection for upgrading/demolishing/painting", (string commmand, string[] args) =>
{
if (Game1.activeClickableMenu is not CarpenterMenu || !BuildingNAnimalMenuPatches.isOnFarm)
{
MainClass.monitor.Log($"Cannot list buildings.", LogLevel.Info);
return;
}
string toPrint = "";
Farm farm = (Farm)Game1.getLocationFromName("Farm");
Netcode.NetCollection<Building> buildings = farm.buildings;
for (int i = 0; i < buildings.Count; i++)
{
toPrint = $"{toPrint},\t{buildings[i].nameOfIndoorsWithoutUnique}: At {buildings[i].tileX}x and {buildings[i].tileY}y";
}
if (toPrint == "")
{
MainClass.monitor.Log("No appropriate buildings to list", LogLevel.Info);
}
else
{
MainClass.monitor.Log($"Available buildings: {toPrint}", LogLevel.Info);
}
});
#endregion
helper.ConsoleCommands.Add("refsr", "Refresh screen reader", (string commmand, string[] args) =>

View File

@ -191,7 +191,7 @@ namespace stardew_access.Game
// Check for animals
else if (ReadTile.getFarmAnimalAt(Game1.currentLocation, (int)position.X, (int)position.Y) != null)
{
string? name = ReadTile.getFarmAnimalAt(Game1.currentLocation, (int)position.X, (int)position.Y, onlyName: true);
string name = $"{ReadTile.getFarmAnimalAt(Game1.currentLocation, (int)position.X, (int)position.Y, onlyName: true)}";
PlaySoundAt(position, name, CATEGORY.FarmAnimals);
}
// Check for water
@ -211,9 +211,9 @@ namespace stardew_access.Game
if (obj is Furniture)
{
if (!furnitures.Contains(obj as Furniture))
if (!furnitures.Contains((Furniture)obj))
{
furnitures.Add(obj as Furniture);
furnitures.Add((Furniture)obj);
PlaySoundAt(position, objectName, CATEGORY.Furnitures);
}
}
@ -323,7 +323,7 @@ namespace stardew_access.Game
}
}
public void PlaySoundAt(Vector2 position, String searchQuery, CATEGORY category)
public void PlaySoundAt(Vector2 position, string searchQuery, CATEGORY category)
{
#region Check whether to skip the object or not

View File

@ -41,7 +41,7 @@ namespace stardew_access.Game
bool isColliding = isCollidingAtTile(x, y);
Dictionary<Vector2, Netcode.NetRef<TerrainFeature>> terrainFeature = Game1.currentLocation.terrainFeatures.FieldDict;
string toSpeak = " ";
string? toSpeak = " ";
#region Get objects, crops, resource clumps, etc.
if (Game1.currentLocation.isCharacterAtTile(gt) != null)

View File

@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using StardewModdingAPI;
using StardewValley;
using StardewValley.Menus;
@ -10,144 +11,171 @@ namespace stardew_access.Patches
internal static string carpenterMenuQuery = "";
internal static bool isSayingBlueprintInfo = false;
internal static string prevBlueprintInfo = "";
internal static void CarpenterMenuPatch(CarpenterMenu __instance, bool ___onFarm, List<Item> ___ingredients, int ___price, List<BluePrint> ___blueprints, int ___currentBlueprintIndex)
internal static bool isOnFarm = false, isUpgrading = false, isDemolishing = false, isPainting = false, isConstructing = false, isMoving = false;
internal static void CarpenterMenuPatch(
CarpenterMenu __instance, bool ___onFarm, List<Item> ___ingredients, int ___price,
List<BluePrint> ___blueprints, int ___currentBlueprintIndex, bool ___upgrading, bool ___demolishing, bool ___moving,
bool ___painting)
{
if (!___onFarm)
try
{
#region The blueprint menu
BluePrint currentBluprint = __instance.CurrentBlueprint;
if (currentBluprint == null)
return;
int x = Game1.getMouseX(), y = Game1.getMouseY(); // Mouse x and y position
bool isBPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.B);
string ingredients = "";
string name = currentBluprint.displayName;
string upgradeName = currentBluprint.nameOfBuildingToUpgrade;
string description = currentBluprint.description;
string price = $"{___price}g";
string blueprintInfo;
#region Get ingredients
for (int i = 0; i < ___ingredients.Count; i++)
isOnFarm = ___onFarm;
if (!___onFarm)
{
string itemName = ___ingredients[i].DisplayName;
int itemStack = ___ingredients[i].Stack;
string itemQuality = "";
isUpgrading = false;
isDemolishing = false;
isPainting = false;
isMoving = false;
isConstructing = false;
int qualityValue = (___ingredients[i] as StardewValley.Object).quality;
if (qualityValue == 1)
#region The blueprint menu
BluePrint currentBluprint = __instance.CurrentBlueprint;
if (currentBluprint == null)
return;
int x = Game1.getMouseX(), y = Game1.getMouseY(); // Mouse x and y position
bool isBPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.B);
string ingredients = "";
string name = currentBluprint.displayName;
string upgradeName = currentBluprint.nameOfBuildingToUpgrade;
string description = currentBluprint.description;
string price = $"{___price}g";
string blueprintInfo;
#region Get ingredients
for (int i = 0; i < ___ingredients.Count; i++)
{
itemQuality = "Silver quality";
string itemName = ___ingredients[i].DisplayName;
int itemStack = ___ingredients[i].Stack;
string itemQuality = "";
int qualityValue = ((StardewValley.Object)___ingredients[i]).quality;
if (qualityValue == 1)
{
itemQuality = "Silver quality";
}
else if (qualityValue == 2 || qualityValue == 3)
{
itemQuality = "Gold quality";
}
else if (qualityValue >= 4)
{
itemQuality = "Iridium quality";
}
ingredients = $"{ingredients}, {itemStack} {itemName} {itemQuality}";
}
else if (qualityValue == 2 || qualityValue == 3)
#endregion
blueprintInfo = $"{name}, Price: {price}, Ingredients: {ingredients}, Description: {description}";
if (isBPressed && !isSayingBlueprintInfo)
{
itemQuality = "Gold quality";
SayBlueprintInfo(blueprintInfo);
}
else if (qualityValue >= 4)
else if (prevBlueprintInfo != blueprintInfo)
{
itemQuality = "Iridium quality";
prevBlueprintInfo = blueprintInfo;
SayBlueprintInfo(blueprintInfo);
}
else
{
if (__instance.backButton != null && __instance.backButton.containsPoint(x, y))
{
string toSpeak = "Previous Blueprint";
if (carpenterMenuQuery != toSpeak)
{
carpenterMenuQuery = toSpeak;
MainClass.screenReader.Say(toSpeak, true);
}
return;
}
ingredients = $"{ingredients}, {itemStack} {itemName} {itemQuality}";
}
#endregion
if (__instance.forwardButton != null && __instance.forwardButton.containsPoint(x, y))
{
string toSpeak = "Next Blueprint";
if (carpenterMenuQuery != toSpeak)
{
carpenterMenuQuery = toSpeak;
MainClass.screenReader.Say(toSpeak, true);
}
return;
}
blueprintInfo = $"{name}, Price: {price}, Ingredients: {ingredients}, Description: {description}";
if (__instance.demolishButton != null && __instance.demolishButton.containsPoint(x, y))
{
string toSpeak = $"Demolish Building" + (__instance.CanDemolishThis(___blueprints[___currentBlueprintIndex]) ? "" : ", cannot demolish building");
if (carpenterMenuQuery != toSpeak)
{
carpenterMenuQuery = toSpeak;
MainClass.screenReader.Say(toSpeak, true);
}
return;
}
if (isBPressed && !isSayingBlueprintInfo)
{
SayBlueprintInfo(blueprintInfo);
}
else if (prevBlueprintInfo != blueprintInfo)
{
prevBlueprintInfo = blueprintInfo;
SayBlueprintInfo(blueprintInfo);
if (__instance.okButton != null && __instance.okButton.containsPoint(x, y))
{
string toSpeak = "Cunstruct Building" + (___blueprints[___currentBlueprintIndex].doesFarmerHaveEnoughResourcesToBuild() ? "" : ", cannot cunstrut building, not enough resources to build.");
if (carpenterMenuQuery != toSpeak)
{
carpenterMenuQuery = toSpeak;
MainClass.screenReader.Say(toSpeak, true);
}
return;
}
if (__instance.moveButton != null && __instance.moveButton.containsPoint(x, y))
{
string toSpeak = "Move Building";
if (carpenterMenuQuery != toSpeak)
{
carpenterMenuQuery = toSpeak;
MainClass.screenReader.Say(toSpeak, true);
}
return;
}
if (__instance.paintButton != null && __instance.paintButton.containsPoint(x, y))
{
string toSpeak = "Paint Building";
if (carpenterMenuQuery != toSpeak)
{
carpenterMenuQuery = toSpeak;
MainClass.screenReader.Say(toSpeak, true);
}
return;
}
if (__instance.cancelButton != null && __instance.cancelButton.containsPoint(x, y))
{
string toSpeak = "Cancel Button";
if (carpenterMenuQuery != toSpeak)
{
carpenterMenuQuery = toSpeak;
MainClass.screenReader.Say(toSpeak, true);
}
return;
}
}
#endregion
}
else
{
if (__instance.backButton != null && __instance.backButton.containsPoint(x, y))
{
string toSpeak = "Previous Blueprint";
if (carpenterMenuQuery != toSpeak)
{
carpenterMenuQuery = toSpeak;
MainClass.screenReader.Say(toSpeak, true);
}
return;
}
if (__instance.forwardButton != null && __instance.forwardButton.containsPoint(x, y))
{
string toSpeak = "Next Blueprint";
if (carpenterMenuQuery != toSpeak)
{
carpenterMenuQuery = toSpeak;
MainClass.screenReader.Say(toSpeak, true);
}
return;
}
if (__instance.demolishButton != null && __instance.demolishButton.containsPoint(x, y))
{
string toSpeak = $"Demolish Building" + (__instance.CanDemolishThis(___blueprints[___currentBlueprintIndex]) ? "" : ", cannot demolish building");
if (carpenterMenuQuery != toSpeak)
{
carpenterMenuQuery = toSpeak;
MainClass.screenReader.Say(toSpeak, true);
}
return;
}
if (__instance.okButton != null && __instance.okButton.containsPoint(x, y))
{
string toSpeak = "Cunstruct Building" + (___blueprints[___currentBlueprintIndex].doesFarmerHaveEnoughResourcesToBuild() ? "" : ", cannot cunstrut building, not enough resources to build.");
if (carpenterMenuQuery != toSpeak)
{
carpenterMenuQuery = toSpeak;
MainClass.screenReader.Say(toSpeak, true);
}
return;
}
if (__instance.moveButton != null && __instance.moveButton.containsPoint(x, y))
{
string toSpeak = "Move Building";
if (carpenterMenuQuery != toSpeak)
{
carpenterMenuQuery = toSpeak;
MainClass.screenReader.Say(toSpeak, true);
}
return;
}
if (__instance.paintButton != null && __instance.paintButton.containsPoint(x, y))
{
string toSpeak = "Paint Building";
if (carpenterMenuQuery != toSpeak)
{
carpenterMenuQuery = toSpeak;
MainClass.screenReader.Say(toSpeak, true);
}
return;
}
if (__instance.cancelButton != null && __instance.cancelButton.containsPoint(x, y))
{
string toSpeak = "Cancel Button";
if (carpenterMenuQuery != toSpeak)
{
carpenterMenuQuery = toSpeak;
MainClass.screenReader.Say(toSpeak, true);
}
return;
}
if (___demolishing)
isDemolishing = true;
else if (___upgrading)
isUpgrading = true;
else if (___painting)
isPainting = true;
else if (___moving)
isMoving = true;
else
isConstructing = true;
}
#endregion
}
else
catch (Exception e)
{
MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error);
}
}
private static async void SayBlueprintInfo(string info)

View File

@ -113,7 +113,7 @@ namespace stardew_access.Patches
try
{
#region Skip narrating hover text for certain menus
if (Game1.activeClickableMenu is TitleMenu && !((Game1.activeClickableMenu as TitleMenu).GetChildMenu() is CharacterCustomization))
if (Game1.activeClickableMenu is TitleMenu && !(((TitleMenu)Game1.activeClickableMenu).GetChildMenu() is CharacterCustomization))
return;
if (Game1.activeClickableMenu is LetterViewerMenu || Game1.activeClickableMenu is QuestLog)
@ -125,19 +125,19 @@ namespace stardew_access.Patches
if (Game1.activeClickableMenu is GeodeMenu)
return;
if (Game1.activeClickableMenu is GameMenu && (Game1.activeClickableMenu as GameMenu).GetCurrentPage() is InventoryPage)
if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is InventoryPage)
return;
if (Game1.activeClickableMenu is GameMenu && (Game1.activeClickableMenu as GameMenu).GetCurrentPage() is CraftingPage)
if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is CraftingPage)
return;
if (Game1.activeClickableMenu is GameMenu && (Game1.activeClickableMenu as GameMenu).GetCurrentPage() is OptionsPage)
if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is OptionsPage)
return;
if (Game1.activeClickableMenu is GameMenu && (Game1.activeClickableMenu as GameMenu).GetCurrentPage() is ExitPage)
if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is ExitPage)
return;
if (Game1.activeClickableMenu is GameMenu && (Game1.activeClickableMenu as GameMenu).GetCurrentPage() is SocialPage)
if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is SocialPage)
return;
if (Game1.activeClickableMenu is ItemGrabMenu)
@ -173,9 +173,9 @@ namespace stardew_access.Patches
#endregion
#region Add quality of item
if (hoveredItem is StardewValley.Object && (hoveredItem as StardewValley.Object).quality > 0)
if (hoveredItem is StardewValley.Object && ((StardewValley.Object)hoveredItem).quality > 0)
{
int quality = (hoveredItem as StardewValley.Object).quality;
int quality = ((StardewValley.Object)hoveredItem).quality;
if (quality == 1)
{
toSpeak.Append("Silver quality");
@ -230,13 +230,13 @@ namespace stardew_access.Patches
#endregion
#region Add health & stamina
if (hoveredItem is StardewValley.Object && (hoveredItem as StardewValley.Object).Edibility != -300)
if (hoveredItem is StardewValley.Object && ((StardewValley.Object)hoveredItem).Edibility != -300)
{
int stamina_recovery = (hoveredItem as StardewValley.Object).staminaRecoveredOnConsumption();
int stamina_recovery = ((StardewValley.Object)hoveredItem).staminaRecoveredOnConsumption();
toSpeak.Append($"{stamina_recovery} Energy\n");
if (stamina_recovery >= 0)
{
int health_recovery = (hoveredItem as StardewValley.Object).healthRecoveredOnConsumption();
int health_recovery = ((StardewValley.Object)hoveredItem).healthRecoveredOnConsumption();
toSpeak.Append($"{health_recovery} Health");
}
}

View File

@ -259,7 +259,7 @@ namespace stardew_access.Patches
if ((item as StardewValley.Object) != null)
{
int quality = (item as StardewValley.Object).quality;
int quality = ((StardewValley.Object)item).quality;
if (quality == 1)
{
toSpeak = $"Silver quality {toSpeak}";
@ -1026,19 +1026,22 @@ namespace stardew_access.Patches
#region Health & stamina and buff items (effects like +1 walking speed)
Item producesItem = ___hoverRecipe.createItem();
if (producesItem is StardewValley.Object && (producesItem as StardewValley.Object).Edibility != -300)
if (producesItem is StardewValley.Object && ((StardewValley.Object)producesItem).Edibility != -300)
{
int stamina_recovery = (producesItem as StardewValley.Object).staminaRecoveredOnConsumption();
int stamina_recovery = ((StardewValley.Object)producesItem).staminaRecoveredOnConsumption();
buffs += $"{stamina_recovery} Energy";
if (stamina_recovery >= 0)
{
int health_recovery = (producesItem as StardewValley.Object).healthRecoveredOnConsumption();
int health_recovery = ((StardewValley.Object)producesItem).healthRecoveredOnConsumption();
buffs += $"\n{health_recovery} Health";
}
}
// These variables are taken from the game's code itself (IClickableMenu.cs -> 1016 line)
bool edibleItem = producesItem != null && producesItem is StardewValley.Object && (int)(producesItem as StardewValley.Object).edibility != -300;
string[] buffIconsToDisplay = (edibleItem && Game1.objectInformation[(producesItem as StardewValley.Object).parentSheetIndex].Split('/').Length > 7) ? producesItem.ModifyItemBuffs(Game1.objectInformation[(producesItem as StardewValley.Object).parentSheetIndex].Split('/')[7].Split(' ')) : null;
bool edibleItem = producesItem != null && producesItem is StardewValley.Object && (int)((StardewValley.Object)producesItem).edibility != -300;
string[]? buffIconsToDisplay = (edibleItem && Game1.objectInformation[((StardewValley.Object)producesItem).parentSheetIndex].Split('/').Length > 7)
? producesItem.ModifyItemBuffs(Game1.objectInformation[((StardewValley.Object)producesItem).parentSheetIndex].Split('/')[7].Split(' '))
: null;
if (buffIconsToDisplay != null)
{
for (int j = 0; j < buffIconsToDisplay.Length; j++)

View File

@ -352,6 +352,17 @@ namespace stardew_access.Patches
GameMenuPatches.shopMenuQueryKey = "";
}
if (__instance is CarpenterMenu)
{
MainClass.monitor.Log($"Here", LogLevel.Info);
BuildingNAnimalMenuPatches.isOnFarm = false;
BuildingNAnimalMenuPatches.isUpgrading = false;
BuildingNAnimalMenuPatches.isDemolishing = false;
BuildingNAnimalMenuPatches.isPainting = false;
BuildingNAnimalMenuPatches.isMoving = false;
BuildingNAnimalMenuPatches.isConstructing = false;
}
GameMenuPatches.hoveredItemQueryKey = "";
}
catch (Exception e)