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,10 +11,23 @@ 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)
{
try
{
isOnFarm = ___onFarm;
if (!___onFarm)
{
isUpgrading = false;
isDemolishing = false;
isPainting = false;
isMoving = false;
isConstructing = false;
#region The blueprint menu
BluePrint currentBluprint = __instance.CurrentBlueprint;
if (currentBluprint == null)
@ -35,7 +49,7 @@ namespace stardew_access.Patches
int itemStack = ___ingredients[i].Stack;
string itemQuality = "";
int qualityValue = (___ingredients[i] as StardewValley.Object).quality;
int qualityValue = ((StardewValley.Object)___ingredients[i]).quality;
if (qualityValue == 1)
{
itemQuality = "Silver quality";
@ -147,7 +161,21 @@ namespace stardew_access.Patches
}
else
{
if (___demolishing)
isDemolishing = true;
else if (___upgrading)
isUpgrading = true;
else if (___painting)
isPainting = true;
else if (___moving)
isMoving = true;
else
isConstructing = true;
}
}
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)