using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Revitalize.Framework.Objects;
using StardewValley;
using StardewValley.BellsAndWhistles;
using StardewValley.Menus;
namespace Revitalize.Framework.Hacks
{
///
/// Deals with hijacking menus for custom logic.
///
public class MenuHacks
{
///
/// Checks to see if the mod has had it's custom object processed at the end of the day.
///
public static bool EndOfDay_HasProcessedModdedItems;
///
/// Checks to see if the end of day menus are up and running.
///
///
public static bool EndOfDay_IsShowingEndOfNightMenus()
{
return Game1.showingEndOfNightStuff;
}
///
/// Checks to see if the current end of day menu is the shippping menu.
///
///
public static bool EndOfDay_IsEndOfDayMenuShippingMenu()
{
if (EndOfDay_IsShowingEndOfNightMenus())
{
if (Game1.activeClickableMenu.GetType() == typeof(StardewValley.Menus.ShippingMenu)) return true;
if (Game1.endOfNightMenus.Count == 0 && Game1.activeClickableMenu==null) return false;
if (Game1.endOfNightMenus.Peek().GetType() == typeof(StardewValley.Menus.ShippingMenu))
{
return true;
}
else
{
return false;
}
}
else return false;
}
///
/// Gets the shipping menu from the end of day menus.
///
///
public static ShippingMenu EndOfDay_GetShippingMenu()
{
if (EndOfDay_IsEndOfDayMenuShippingMenu())
{
if (Game1.activeClickableMenu.GetType() == typeof(StardewValley.Menus.ShippingMenu))
{
return (ShippingMenu)Game1.activeClickableMenu;
}
return (ShippingMenu)Game1.endOfNightMenus.Peek();
}
return null;
}
///
/// Hijacks the shipping menu to process modded items.
///
public static void EndOfDay_HackShipping()
{
if (EndOfDay_GetShippingMenu() != null)
{
//ModCore.log("Hooked shipping menu!");
ShippingMenu menu = EndOfDay_GetShippingMenu();
List categoryTotals = new List();
List categoryDials = new List();
List> categoryItems = new List>();
var CT_R=ModCore.ModHelper.Reflection.GetField>(menu, "categoryTotals", true);
var CD_R= ModCore.ModHelper.Reflection.GetField>(menu, "categoryDials", true);
var CI_R= ModCore.ModHelper.Reflection.GetField>>(menu, "categoryItems", true);
categoryTotals = CT_R.GetValue();
categoryDials = CD_R.GetValue();
categoryItems = CI_R.GetValue();
//Recalculate other category.
foreach (CustomObject obj in categoryItems[4])
{
ModCore.log(obj.Name);
if (obj is StardewValley.Object)
{
ModCore.log(obj.sellToStorePrice());
categoryTotals[4] += obj.sellToStorePrice() * obj.Stack;
Game1.stats.itemsShipped += (uint)obj.Stack;
/*
if (o.Category == -75 || o.Category == -79)
Game1.stats.CropsShipped += (uint)o.Stack;
if (o.countsForShippedCollection())
Game1.player.shippedBasic((int)((NetFieldBase)o.parentSheetIndex), (int)((NetFieldBase)o.stack));
*/
}
}
categoryTotals[5] = 0;
for (int index = 0; index < 5; ++index)
{
categoryTotals[5] += categoryTotals[index];
categoryItems[5].AddRange((IEnumerable- )categoryItems[index]);
categoryDials[index].currentValue = categoryTotals[index];
categoryDials[index].previousTargetValue = categoryDials[index].currentValue;
}
categoryDials[5].currentValue = categoryTotals[5];
if (Game1.IsMasterGame)
Game1.player.Money += categoryTotals[5];
Game1.setRichPresence("earnings", (object)categoryTotals[5]);
}
}
///
/// Triggers
///
///
///
public static void EndOfDay_RenderCheck(object o, StardewModdingAPI.Events.RenderedEventArgs sender)
{
if (EndOfDay_IsShowingEndOfNightMenus() && EndOfDay_HasProcessedModdedItems==false)
{
EndOfDay_HackShipping();
EndOfDay_HasProcessedModdedItems = true;
}
}
public static void EndOfDay_CleanupForNewDay(object o, StardewModdingAPI.Events.SavedEventArgs sender)
{
EndOfDay_HasProcessedModdedItems = false;
}
}
}