Got farmhand inventory to be reconstructed even when farmhand is offline.

This commit is contained in:
JoshuaNavarro 2019-08-31 18:23:47 -07:00
parent a3c0e4f8a0
commit 0d760f5cfe
4 changed files with 208 additions and 56 deletions

View File

@ -87,6 +87,8 @@ namespace Revitalize.Framework.Objects
this.resources = new ResourceManager();
this.ItemsByName = new Dictionary<string, CustomObject>();
ChairMultiTiledObject s = new ChairMultiTiledObject();
}
/// <summary>
@ -268,7 +270,104 @@ namespace Revitalize.Framework.Objects
{
}
/// <summary>
/// Scans all mod items to try to find a match.
/// </summary>
/// <param name="ID"></param>
/// <param name="T"></param>
/// <returns></returns>
public Item getItemByIDAndType(string ID,Type T)
{
foreach(var v in this.chairs)
{
if(v.Value.GetType()==T && v.Value.info.id == ID)
{
Item I= v.Value.getOne();
return I;
}
}
foreach(var v in this.furnitureStorage)
{
if (v.Value.GetType() == T && v.Value.info.id == ID)
{
Item I = v.Value.getOne();
return I;
}
}
foreach(var v in this.generic)
{
if (v.Value.GetType() == T && v.Value.info.id == ID)
{
Item I = v.Value.getOne();
return I;
}
}
foreach(var v in this.ItemsByName)
{
if (v.Value.GetType() == T && v.Value.info.id == ID)
{
Item I = v.Value.getOne();
return I;
}
}
foreach(var v in this.lamps)
{
if (v.Value.GetType() == T && v.Value.info.id == ID)
{
Item I = v.Value.getOne();
return I;
}
}
foreach(var v in this.miscellaneous)
{
if (v.Value.GetType() == T && v.Value.info.id == ID)
{
Item I = v.Value.getOne();
return I;
}
}
foreach(var v in this.rugs)
{
if (v.Value.GetType() == T && v.Value.info.id == ID)
{
Item I = v.Value.getOne();
return I;
}
}
foreach(var v in this.tables)
{
if (v.Value.GetType() == T && v.Value.info.id == ID)
{
Item I = v.Value.getOne();
return I;
}
}
foreach(var v in this.resources.ores)
{
if (v.Value.GetType() == T && v.Value.info.id == ID)
{
Item I = v.Value.getOne();
return I;
}
}
foreach(var v in this.resources.oreVeins)
{
if (v.Value.GetType() == T && v.Value.info.id == ID)
{
Item I = v.Value.getOne();
return I;
}
}
return null;
}
}
}

View File

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Newtonsoft.Json;
using PyTK.CustomElementHandler;
using Revitalize.Framework.Objects.InformationFiles;
using Revitalize.Framework.Utilities;
@ -40,6 +41,7 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins
}
[JsonIgnore]
public override string ItemInfo
{
get

View File

@ -5,6 +5,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using PyTK.CustomElementHandler;
using Revitalize.Framework.Objects;
using Revitalize.Framework.Objects.Furniture;
using Revitalize.Framework.Utilities.Serialization.ContractResolvers;
@ -305,6 +306,39 @@ namespace Revitalize.Framework.Utilities
return I;
}
public Item DeserializeFromFarmhandInventory(string JsonName)
{
//ModCore.log("Found a custom object in a chest!");
string jsonString = JsonName;
//ModCore.log(JsonName);
string dataSplit = jsonString.Split(new string[] { "<" }, StringSplitOptions.None)[2];
string backUpGUID = dataSplit.Split('|')[0];
string[] guidArr = jsonString.Split(new string[] { "|" }, StringSplitOptions.None);
string infoStr = jsonString.Split(new string[] { "<" }, StringSplitOptions.None)[0];
string guidStr= jsonString.Split(new string[] { "<" }, StringSplitOptions.None)[1];
CustomObjectData pyTkData = ModCore.Serializer.DeserializeFromJSONString<CustomObjectData>(dataSplit);
Type t = Type.GetType(pyTkData.type);
string id = pyTkData.id;
//Need Item info
string guidName = backUpGUID;
string infoSplit = infoStr.Split('|')[3];
infoSplit = infoSplit.Substring(3);
BasicItemInformation info = ModCore.Serializer.DeserializeFromJSONString<BasicItemInformation>(infoSplit);
CustomObject clone = (CustomObject)ModCore.ObjectManager.getItemByIDAndType(id, t);
if (clone != null)
{
clone.info = info;
ModCore.log("Guid is????:"+guidStr);
clone.guid = Guid.Parse(guidStr);
return clone;
}
return null;
}
public void returnToTitle()
{
//this.gatherAllFilesForCleanup();

View File

@ -24,17 +24,18 @@ using Revitalize.Framework.Minigame.SeasideScrambleMinigame;
using Revitalize.Framework.Objects.Items.Resources;
using Revitalize.Framework.Hacks;
using Revitalize.Framework.Configs;
using StardewValley.Locations;
using System.Linq;
namespace Revitalize
{
//Bugs:
// -Chair tops cut off objects
// -load content MUST be enabled for the table to be placed?????? WTF
// -load content MUST be enabled for the table to be placed??????
// TODO:
/* Add in crafting menu.
* Add in crafting table.
* Find way to hack vanilla furnace for more recipes.
*
*
// -Make this mod able to load content packs for easier future modding
@ -85,15 +86,17 @@ namespace Revitalize
// -Auto Preserves
// -Auto Keg
// -Auto Cask
// -Calcinator (oil+stone)
// -Calcinator (oil+stone: produces titanum?)
// -Materials
// -Tin/Bronze/Alluminum/Silver?Platinum/Etc
// -Tin/Bronze/Alluminum/Silver?Platinum/Etc (all but platinum: may add in at a later date)
-titanium
-Alloys!
-Brass
-Electrum
-Brass (done)
-Electrum (done)
-Steel (done)
-Bronze (done)
-Mythrill
-Steel
-Star Metal
-Star Steel
-Cobalt
@ -189,7 +192,7 @@ namespace Revitalize
Accessories
(recover hp/stamina,max hp,more friendship ,run faster, take less damage, etc)
-NEckalces
-Neckalces
-Broaches
-Earings
-Pendants
@ -261,33 +264,79 @@ namespace Revitalize
ModHelper.Events.GameLoop.DayEnding += this.GameLoop_DayEnding;
ModHelper.Events.GameLoop.Saving += this.GameLoop_Saving;
//Adds in recipes to the mod.
VanillaRecipeBook = new VanillaRecipeBook();
/*
foreach(var v in Game1.objectInformation)
{
string name = v.Value.Split('/')[0];
ModCore.log(name + "="+v.Key+","+Environment.NewLine,false);
}
*/
ModHelper.Events.Display.MenuChanged += this.Display_MenuChanged;
}
private void Display_MenuChanged(object sender, StardewModdingAPI.Events.MenuChangedEventArgs e)
{
if (e.NewMenu != null)
{
ModCore.log(e.NewMenu.GetType());
if (e.NewMenu.GetType() == typeof(StardewValley.Menus.ItemGrabMenu))
{
if (Game1.player.currentLocation is Cabin)
{
ModCore.log("Let's get processing!");
List<KeyValuePair<int,Item>> addition = new List<KeyValuePair<int,Item>>();
for (int i = 0; i < (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.actualInventory.Count; i++)
{
Item I = (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.actualInventory[i];
if (I is Chest && I.Name != "Chest")
{
ModCore.log("Found a custom object!");
Item cObj= ModCore.Serializer.DeserializeFromFarmhandInventory(I.Name);
if (cObj == null)
{
ModCore.log("NULL OBJ");
}
else
{
ModCore.log("Not null!");
}
if (cObj == null) continue;
addition.Add(new KeyValuePair<int, Item>(i,cObj));
}
}
/*
for(int I=0; I< (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.actualInventory.Count; I++)
{
if((Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.actualInventory[I] == null)
{
if (addition.Count > 0) {
(Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.actualInventory[I] = addition[0].Value;
addition.RemoveAt(0);
}
}
}
*/
foreach(KeyValuePair<int,Item> pair in addition)
{
(Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.actualInventory[pair.Key] = pair.Value;
}
(Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu = new InventoryMenu((Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.xPositionOnScreen, (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.yPositionOnScreen, true, (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.actualInventory, (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.highlightMethod, (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.capacity, (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.rows, (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.horizontalGap, (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.verticalGap, (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.drawSlots);
(Game1.activeClickableMenu as ItemGrabMenu).populateClickableComponentList();
(Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.populateClickableComponentList();
}
}
}
}
private void GameLoop_Saving(object sender, StardewModdingAPI.Events.SavingEventArgs e)
{
/*
foreach(var v in CustomObjects)
{
v.Value.updateInfo();
}
*/
}
private void GameLoop_DayEnding(object sender, StardewModdingAPI.Events.DayEndingEventArgs e)
{
//MultiplayerUtilities.RequestALLGuidObjects();
}
/// <summary>
@ -437,13 +486,6 @@ namespace Revitalize
private void GameLoop_SaveLoaded(object sender, StardewModdingAPI.Events.SaveLoadedEventArgs e)
{
this.loadContent();
/*
if (Game1.IsServer || Game1.IsMultiplayer || Game1.IsClient)
{
throw new Exception("Can't run Revitalize in multiplayer due to lack of current support!");
}
*/
Serializer.afterLoad();
ShopHacks.AddOreToClintsShop();
ObjectInteractionHacks.AfterLoad_RestoreTrackedMachines();
@ -463,32 +505,7 @@ namespace Revitalize
axe =(StardewValley.Tools.Axe)Serializer.Deserialize(Path.Combine(this.Helper.DirectoryPath, "AXE.json"),typeof(StardewValley.Tools.Axe));
//Game1.player.addItemToInventory(axe);
*/
//Game1.player.addItemToInventory(ObjectManager.resources.ores["Test"].getOne());
//Game1.player.addItemToInventory(ObjectManager.resources.getOre("Tin", 19));
//Ore tin = ObjectManager.resources.getOre("Tin", 19);
//Game1.player.addItemToInventory(ObjectManager.GetItem("TinIngot", 1));
//Game1.player.addItemToInventory(new StardewValley.Object(388, 100));
/*
Game1.player.addItemsByMenuIfNecessary(new List<Item>()
{
new StardewValley.Object(Vector2.Zero, (int)Enums.SDVBigCraftable.Furnace),
new StardewValley.Object((int)Enums.SDVObject.Coal,10),
new StardewValley.Object((int)Enums.SDVObject.PrismaticShard,5),
new StardewValley.Object((int)Enums.SDVObject.Emerald,1),
new StardewValley.Object((int)Enums.SDVObject.Aquamarine,1),
new StardewValley.Object((int)Enums.SDVObject.Ruby,1),
new StardewValley.Object((int)Enums.SDVObject.Amethyst,1),
new StardewValley.Object((int)Enums.SDVObject.Topaz,1),
new StardewValley.Object((int)Enums.SDVObject.Jade,1),
new StardewValley.Object((int)Enums.SDVObject.Diamond,1),
new StardewValley.Object((int)Enums.SDVObject.IronBar,1),
});
*/
//ModCore.log("Tin sells for: " + tin.sellToStorePrice());
//ObjectManager.resources.spawnOreVein("Omegasis.Revitalize.Resources.Ore.Test", new Vector2(8, 7));
}
/*