diff --git a/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs b/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs index a78639b0..b33561f6 100644 --- a/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs @@ -8,6 +8,7 @@ using PyTK.CustomElementHandler; using StardustCore.Animations; using StardewValley; using StardewValley.Objects; +using Revitalize.Framework.Utilities; namespace Revitalize.Framework.Objects { @@ -109,13 +110,13 @@ namespace Revitalize.Framework.Objects { get { - + if (this.info == null) { //ModCore.log("Info was null when getting data."); this.updateInfo(); } - + return this.info.id; } } @@ -175,7 +176,7 @@ namespace Revitalize.Framework.Objects { get { - return Revitalize.ModCore.Serializer.ToJSONString(this.info)+"<"+this.guid+"<"+ModCore.Serializer.ToJSONString(this.data); + return Revitalize.ModCore.Serializer.ToJSONString(this.info) + "<" + this.guid + "<" + ModCore.Serializer.ToJSONString(this.data); } set { @@ -197,7 +198,7 @@ namespace Revitalize.Framework.Objects else { //ModCore.log("Add in new guid: " + this.guid); - ModCore.CustomObjects.Add(this.guid,this); + ModCore.CustomObjects.Add(this.guid, this); } if (ModCore.CustomObjects.ContainsKey(oldGuid) && ModCore.CustomObjects.ContainsKey(this.guid)) @@ -224,7 +225,7 @@ namespace Revitalize.Framework.Objects this.info = info; this.guid = Guid.NewGuid(); this.initializeBasics(); - + this.Stack = Stack; } @@ -236,7 +237,7 @@ namespace Revitalize.Framework.Objects this.info = info; this.guid = Guid.NewGuid(); this.initializeBasics(); - + this.Stack = Stack; } @@ -648,24 +649,15 @@ namespace Revitalize.Framework.Objects if (this.requiresUpdate()) { - this.ItemInfo = this.text; this.text = this.ItemInfo; this.info.cleanAfterUpdate(); + MultiplayerUtilities.RequestUpdateSync(this.guid); } } - public virtual void forceUpdate() + public virtual void getUpdate() { - if (this.info == null) - { - this.ItemInfo = this.text; - ModCore.log("Updated item info!"); - return; - } this.ItemInfo = this.text; - this.text = this.ItemInfo; - this.info.cleanAfterUpdate(); - this.info.forceUpdate(); } public virtual bool requiresUpdate() diff --git a/GeneralMods/Revitalize/Framework/Objects/Extras/ArcadeCabinetTile.cs b/GeneralMods/Revitalize/Framework/Objects/Extras/ArcadeCabinetTile.cs index df47002b..737c032b 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Extras/ArcadeCabinetTile.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Extras/ArcadeCabinetTile.cs @@ -9,6 +9,7 @@ using Microsoft.Xna.Framework.Input; using PyTK.CustomElementHandler; using Revitalize.Framework.Objects.Furniture; using Revitalize.Framework.Objects.InformationFiles.Furniture; +using Revitalize.Framework.Utilities; using Revitalize.Framework.Utilities.Serialization; using StardewValley; using StardewValley.Minigames; @@ -19,6 +20,86 @@ namespace Revitalize.Framework.Objects.Extras { public ArcadeCabinetInformation arcadeInfo; + + + public override string ItemInfo + { + get + { + string info = Revitalize.ModCore.Serializer.ToJSONString(this.info); + string guidStr = this.guid.ToString(); + string pyTkData = ModCore.Serializer.ToJSONString(this.data); + string offsetKey = this.offsetKey != null ? ModCore.Serializer.ToJSONString(this.offsetKey) : ""; + string container = this.containerObject != null ? this.containerObject.guid.ToString() : ""; + string furnitureInfo = ModCore.Serializer.ToJSONString(this.arcadeInfo); + return info + "<" + guidStr + "<" + pyTkData + "<" + offsetKey + "<" + container + "<" + furnitureInfo; + } + set + { + if (string.IsNullOrEmpty(value)) return; + string[] data = value.Split('<'); + string infoString = data[0]; + string guidString = data[1]; + string pyTKData = data[2]; + string offsetVec = data[3]; + string containerObject = data[4]; + string furnitureInfo = data[5]; + this.info = (BasicItemInformation)Revitalize.ModCore.Serializer.DeserializeFromJSONString(infoString, typeof(BasicItemInformation)); + this.data = Revitalize.ModCore.Serializer.DeserializeFromJSONString(pyTKData); + if (string.IsNullOrEmpty(offsetVec)) return; + if (string.IsNullOrEmpty(containerObject)) return; + this.offsetKey = ModCore.Serializer.DeserializeFromJSONString(offsetVec); + Guid oldGuid = this.guid; + this.guid = Guid.Parse(guidString); + if (ModCore.CustomObjects.ContainsKey(this.guid)) + { + //ModCore.log("Update item with guid: " + this.guid); + ModCore.CustomObjects[this.guid] = this; + } + else + { + //ModCore.log("Add in new guid: " + this.guid); + ModCore.CustomObjects.Add(this.guid, this); + } + + if (this.containerObject == null) + { + //ModCore.log(containerObject); + Guid containerGuid = Guid.Parse(containerObject); + if (ModCore.CustomObjects.ContainsKey(containerGuid)) + { + this.containerObject = (MultiTiledObject)ModCore.CustomObjects[containerGuid]; + this.containerObject.removeComponent(this.offsetKey); + this.containerObject.addComponent(this.offsetKey, this); + //ModCore.log("Set container object from existing object!"); + } + else + { + //ModCore.log("Container hasn't been synced???"); + MultiplayerUtilities.RequestGuidObject(containerGuid); + MultiplayerUtilities.RequestGuidObject_Tile(this.guid); + } + } + else + { + this.containerObject.updateInfo(); + } + + if (ModCore.CustomObjects.ContainsKey(oldGuid) && ModCore.CustomObjects.ContainsKey(this.guid)) + { + if (ModCore.CustomObjects[oldGuid] == ModCore.CustomObjects[this.guid] && oldGuid != this.guid) + { + //ModCore.CustomObjects.Remove(oldGuid); + } + } + + if (string.IsNullOrEmpty(furnitureInfo) == false) + { + this.arcadeInfo = ModCore.Serializer.DeserializeFromJSONString(furnitureInfo); + } + + } + } public ArcadeCabinetTile() : base() { diff --git a/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairTileComponent.cs b/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairTileComponent.cs index d3be7f08..a436d18d 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairTileComponent.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairTileComponent.cs @@ -8,6 +8,7 @@ using Microsoft.Xna.Framework.Graphics; using Newtonsoft.Json; using PyTK.CustomElementHandler; using Revitalize.Framework.Objects.InformationFiles.Furniture; +using Revitalize.Framework.Utilities; using StardewValley; using StardewValley.Objects; @@ -20,6 +21,86 @@ namespace Revitalize.Framework.Objects.Furniture { public ChairInformation furnitureInfo; + + + public override string ItemInfo + { + get + { + string info = Revitalize.ModCore.Serializer.ToJSONString(this.info); + string guidStr = this.guid.ToString(); + string pyTkData = ModCore.Serializer.ToJSONString(this.data); + string offsetKey = this.offsetKey != null ? ModCore.Serializer.ToJSONString(this.offsetKey) : ""; + string container = this.containerObject != null ? this.containerObject.guid.ToString() : ""; + string furnitureInfo = ModCore.Serializer.ToJSONString(this.furnitureInfo); + return info + "<" + guidStr + "<" + pyTkData + "<" + offsetKey + "<" + container + "<" + furnitureInfo; + } + set + { + if (string.IsNullOrEmpty(value)) return; + string[] data = value.Split('<'); + string infoString = data[0]; + string guidString = data[1]; + string pyTKData = data[2]; + string offsetVec = data[3]; + string containerObject = data[4]; + string furnitureInfo = data[5]; + this.info = (BasicItemInformation)Revitalize.ModCore.Serializer.DeserializeFromJSONString(infoString, typeof(BasicItemInformation)); + this.data = Revitalize.ModCore.Serializer.DeserializeFromJSONString(pyTKData); + if (string.IsNullOrEmpty(offsetVec)) return; + if (string.IsNullOrEmpty(containerObject)) return; + this.offsetKey = ModCore.Serializer.DeserializeFromJSONString(offsetVec); + Guid oldGuid = this.guid; + this.guid = Guid.Parse(guidString); + if (ModCore.CustomObjects.ContainsKey(this.guid)) + { + //ModCore.log("Update item with guid: " + this.guid); + ModCore.CustomObjects[this.guid] = this; + } + else + { + //ModCore.log("Add in new guid: " + this.guid); + ModCore.CustomObjects.Add(this.guid, this); + } + + if (this.containerObject == null) + { + //ModCore.log(containerObject); + Guid containerGuid = Guid.Parse(containerObject); + if (ModCore.CustomObjects.ContainsKey(containerGuid)) + { + this.containerObject = (MultiTiledObject)ModCore.CustomObjects[containerGuid]; + this.containerObject.removeComponent(this.offsetKey); + this.containerObject.addComponent(this.offsetKey, this); + //ModCore.log("Set container object from existing object!"); + } + else + { + //ModCore.log("Container hasn't been synced???"); + MultiplayerUtilities.RequestGuidObject(containerGuid); + MultiplayerUtilities.RequestGuidObject_Tile(this.guid); + } + } + else + { + this.containerObject.updateInfo(); + } + + if (ModCore.CustomObjects.ContainsKey(oldGuid) && ModCore.CustomObjects.ContainsKey(this.guid)) + { + if (ModCore.CustomObjects[oldGuid] == ModCore.CustomObjects[this.guid] && oldGuid != this.guid) + { + //ModCore.CustomObjects.Remove(oldGuid); + } + } + + if (string.IsNullOrEmpty(furnitureInfo) == false) + { + this.furnitureInfo = ModCore.Serializer.DeserializeFromJSONString(furnitureInfo); + } + + } + } /// /// Checks if the player can sit "on" this component. /// diff --git a/GeneralMods/Revitalize/Framework/Objects/Furniture/LampTileComponent.cs b/GeneralMods/Revitalize/Framework/Objects/Furniture/LampTileComponent.cs index cb483679..cba8113a 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Furniture/LampTileComponent.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Furniture/LampTileComponent.cs @@ -25,6 +25,7 @@ namespace Revitalize.Framework.Objects.Furniture } } + [JsonIgnore] public LightManager lightManager { get diff --git a/GeneralMods/Revitalize/Framework/Objects/Furniture/TableTileComponent.cs b/GeneralMods/Revitalize/Framework/Objects/Furniture/TableTileComponent.cs index 98303134..697d3f2b 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Furniture/TableTileComponent.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Furniture/TableTileComponent.cs @@ -9,6 +9,7 @@ using Microsoft.Xna.Framework.Input; using Newtonsoft.Json; using PyTK.CustomElementHandler; using Revitalize.Framework.Objects.InformationFiles.Furniture; +using Revitalize.Framework.Utilities; using Revitalize.Framework.Utilities.Serialization; using StardewValley; @@ -19,6 +20,85 @@ namespace Revitalize.Framework.Objects.Furniture public TableInformation furnitureInfo; + public override string ItemInfo + { + get + { + string info = Revitalize.ModCore.Serializer.ToJSONString(this.info); + string guidStr = this.guid.ToString(); + string pyTkData = ModCore.Serializer.ToJSONString(this.data); + string offsetKey = this.offsetKey != null ? ModCore.Serializer.ToJSONString(this.offsetKey) : ""; + string container = this.containerObject != null ? this.containerObject.guid.ToString() : ""; + string furnitureInfo = ModCore.Serializer.ToJSONString(this.furnitureInfo); + return info + "<" + guidStr + "<" + pyTkData + "<" + offsetKey + "<" + container + "<" + furnitureInfo; + } + set + { + if (string.IsNullOrEmpty(value)) return; + string[] data = value.Split('<'); + string infoString = data[0]; + string guidString = data[1]; + string pyTKData = data[2]; + string offsetVec = data[3]; + string containerObject = data[4]; + string furnitureInfo = data[5]; + this.info = (BasicItemInformation)Revitalize.ModCore.Serializer.DeserializeFromJSONString(infoString, typeof(BasicItemInformation)); + this.data = Revitalize.ModCore.Serializer.DeserializeFromJSONString(pyTKData); + if (string.IsNullOrEmpty(offsetVec)) return; + if (string.IsNullOrEmpty(containerObject)) return; + this.offsetKey = ModCore.Serializer.DeserializeFromJSONString(offsetVec); + Guid oldGuid = this.guid; + this.guid = Guid.Parse(guidString); + if (ModCore.CustomObjects.ContainsKey(this.guid)) + { + //ModCore.log("Update item with guid: " + this.guid); + ModCore.CustomObjects[this.guid] = this; + } + else + { + //ModCore.log("Add in new guid: " + this.guid); + ModCore.CustomObjects.Add(this.guid, this); + } + + if (this.containerObject == null) + { + //ModCore.log(containerObject); + Guid containerGuid = Guid.Parse(containerObject); + if (ModCore.CustomObjects.ContainsKey(containerGuid)) + { + this.containerObject = (MultiTiledObject)ModCore.CustomObjects[containerGuid]; + this.containerObject.removeComponent(this.offsetKey); + this.containerObject.addComponent(this.offsetKey, this); + //ModCore.log("Set container object from existing object!"); + } + else + { + //ModCore.log("Container hasn't been synced???"); + MultiplayerUtilities.RequestGuidObject(containerGuid); + MultiplayerUtilities.RequestGuidObject_Tile(this.guid); + } + } + else + { + this.containerObject.updateInfo(); + } + + if (ModCore.CustomObjects.ContainsKey(oldGuid) && ModCore.CustomObjects.ContainsKey(this.guid)) + { + if (ModCore.CustomObjects[oldGuid] == ModCore.CustomObjects[this.guid] && oldGuid != this.guid) + { + //ModCore.CustomObjects.Remove(oldGuid); + } + } + + if (string.IsNullOrEmpty(furnitureInfo) == false) + { + this.furnitureInfo = ModCore.Serializer.DeserializeFromJSONString(furnitureInfo); + } + + } + } + [JsonIgnore] public bool CanPlaceItemsHere { diff --git a/GeneralMods/Revitalize/Framework/Objects/InformationFiles/ObjectGUIDInfo.cs b/GeneralMods/Revitalize/Framework/Objects/InformationFiles/ObjectGUIDInfo.cs deleted file mode 100644 index d3b14494..00000000 --- a/GeneralMods/Revitalize/Framework/Objects/InformationFiles/ObjectGUIDInfo.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Revitalize.Framework.Objects.InformationFiles -{ - public class ObjectGUIDInfo - { - public enum ObjectType - { - Solid, - Display - } - - public ObjectGUIDInfo() - { - - } - - } -} diff --git a/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs b/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs index ece39866..dfd52595 100644 --- a/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs +++ b/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs @@ -363,9 +363,10 @@ namespace Revitalize.Framework.Objects if (this.requiresUpdate()) { - this.ItemInfo = this.text; + //this.ItemInfo = this.text; this.text = this.ItemInfo; this.info.cleanAfterUpdate(); + MultiplayerUtilities.RequestUpdateSync(this.guid); } } } diff --git a/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs b/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs index 3a4fe5a2..e4fd96d8 100644 --- a/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs @@ -499,9 +499,10 @@ namespace Revitalize.Framework.Objects if (this.requiresUpdate()) { - this.ItemInfo = this.text; + //this.ItemInfo = this.text; this.text = this.ItemInfo; this.info.cleanAfterUpdate(); + MultiplayerUtilities.RequestUpdateSync(this.guid); } } diff --git a/GeneralMods/Revitalize/Framework/Objects/ResourceManager.cs b/GeneralMods/Revitalize/Framework/Objects/ResourceManager.cs index 700d8822..6d76ef25 100644 --- a/GeneralMods/Revitalize/Framework/Objects/ResourceManager.cs +++ b/GeneralMods/Revitalize/Framework/Objects/ResourceManager.cs @@ -289,6 +289,30 @@ namespace Revitalize.Framework.Objects } } + public OreResourceInformation getOreResourceInfo(string id) + { + if (this.oreVeins.ContainsKey(id)) + { + return (OreResourceInformation)this.oreVeins[id].resourceInfo; + } + else + { + return null; + } + } + + public List getExtraDropInformationFromOres(string id) + { + if (this.oreVeins.ContainsKey(id)) + { + return (this.oreVeins[id].objects[Vector2.Zero] as OreVeinTile).extraDrops; + } + else + { + return null; + } + } + /// /// Checks to see if a resource can be spawned here. /// diff --git a/GeneralMods/Revitalize/Framework/Objects/Resources/OreVeins/OreVeinObj.cs b/GeneralMods/Revitalize/Framework/Objects/Resources/OreVeins/OreVeinObj.cs index b714f4b3..26dd84b4 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Resources/OreVeins/OreVeinObj.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Resources/OreVeins/OreVeinObj.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using Newtonsoft.Json; using PyTK.CustomElementHandler; using Revitalize.Framework.Objects.InformationFiles; using StardewValley; @@ -13,6 +14,7 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins { public class OreVeinObj:MultiTiledObject { + [JsonIgnore] public ResourceInformaton resourceInfo { get diff --git a/GeneralMods/Revitalize/Framework/Objects/Resources/OreVeins/OreVeinTile.cs b/GeneralMods/Revitalize/Framework/Objects/Resources/OreVeins/OreVeinTile.cs index d0c9c97e..b4f37016 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Resources/OreVeins/OreVeinTile.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Resources/OreVeins/OreVeinTile.cs @@ -8,6 +8,7 @@ using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using PyTK.CustomElementHandler; using Revitalize.Framework.Objects.InformationFiles; +using Revitalize.Framework.Utilities; using Revitalize.Framework.Utilities.Serialization; using StardewValley; @@ -20,7 +21,113 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins /// public OreResourceInformation resourceInfo; public List extraDrops; - public int healthValue; + + private int _healthValue; + public int healthValue + { + get + { + return this._healthValue; + } + set + { + this._healthValue = value; + if (this.info != null) + { + this.info.forceUpdate(); + } + } + } + + + public override string ItemInfo + { + get + { + string info = Revitalize.ModCore.Serializer.ToJSONString(this.info); + string guidStr = this.guid.ToString(); + string pyTkData = ModCore.Serializer.ToJSONString(this.data); + string offsetKey = this.offsetKey != null ? ModCore.Serializer.ToJSONString(this.offsetKey) : ""; + string container = this.containerObject != null ? this.containerObject.guid.ToString() : ""; + string health = this.healthValue.ToString(); + return info + "<" + guidStr + "<" + pyTkData + "<" + offsetKey + "<" + container + "<"+health; + } + set + { + if (string.IsNullOrEmpty(value)) return; + string[] data = value.Split('<'); + string infoString = data[0]; + string guidString = data[1]; + string pyTKData = data[2]; + string offsetVec = data[3]; + string containerObject = data[4]; + string health = data[5]; + this.healthValue = Convert.ToInt32(health); + + this.info = (BasicItemInformation)Revitalize.ModCore.Serializer.DeserializeFromJSONString(infoString, typeof(BasicItemInformation)); + + //Instead of serializing this info it's static pretty much always so just pull the info from the resource manager. + OreResourceInformation oreResource = ModCore.ObjectManager.resources.getOreResourceInfo(this.info.id); + List extraDrops = ModCore.ObjectManager.resources.getExtraDropInformationFromOres(this.info.id); + if (this.resourceInfo == null) + { + this.resourceInfo = oreResource; + } + if (this.extraDrops == null) + { + this.extraDrops = extraDrops; + } +; + this.data = Revitalize.ModCore.Serializer.DeserializeFromJSONString(pyTKData); + if (string.IsNullOrEmpty(offsetVec)) return; + if (string.IsNullOrEmpty(containerObject)) return; + this.offsetKey = ModCore.Serializer.DeserializeFromJSONString(offsetVec); + Guid oldGuid = this.guid; + this.guid = Guid.Parse(guidString); + if (ModCore.CustomObjects.ContainsKey(this.guid)) + { + //ModCore.log("Update item with guid: " + this.guid); + ModCore.CustomObjects[this.guid] = this; + } + else + { + //ModCore.log("Add in new guid: " + this.guid); + ModCore.CustomObjects.Add(this.guid, this); + } + + if (this.containerObject == null) + { + //ModCore.log(containerObject); + Guid containerGuid = Guid.Parse(containerObject); + if (ModCore.CustomObjects.ContainsKey(containerGuid)) + { + this.containerObject = (MultiTiledObject)ModCore.CustomObjects[containerGuid]; + this.containerObject.removeComponent(this.offsetKey); + this.containerObject.addComponent(this.offsetKey, this); + //ModCore.log("Set container object from existing object!"); + } + else + { + //ModCore.log("Container hasn't been synced???"); + MultiplayerUtilities.RequestGuidObject(containerGuid); + MultiplayerUtilities.RequestGuidObject_Tile(this.guid); + } + } + else + { + this.containerObject.updateInfo(); + } + + if (ModCore.CustomObjects.ContainsKey(oldGuid) && ModCore.CustomObjects.ContainsKey(this.guid)) + { + if (ModCore.CustomObjects[oldGuid] == ModCore.CustomObjects[this.guid] && oldGuid != this.guid) + { + //ModCore.CustomObjects.Remove(oldGuid); + } + } + + } + } public OreVeinTile() : base() @@ -120,7 +227,13 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins if (this.location != null) { this.location.playSound("hammer"); - //ModCore.log("Ore has this much health left: "+this.healthValue); + ModCore.log("Ore has this much health left and location is not null: "+this.healthValue); + this.info.shakeTimer = 200; + } + else + { + Game1.player.currentLocation.playSound("hammer"); + ModCore.log("Ore has this much health left and location is null!: "+this.healthValue); this.info.shakeTimer = 200; } return false; @@ -201,6 +314,18 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins Game1.createRadialDebris(this.location, 14, (int)this.TileLocation.X, (int)this.TileLocation.Y, Game1.random.Next(4, 10), false, -1, false, -1); this.location.removeObject(this.TileLocation, false); this.containerObject.removeComponent(this.offsetKey); + ModCore.CustomObjects.Remove(this.containerObject.guid); + ModCore.CustomObjects.Remove(this.guid); + } + else + { + Game1.player.currentLocation.playSound("stoneCrack"); + Game1.createRadialDebris(Game1.player.currentLocation, 14, (int)this.TileLocation.X, (int)this.TileLocation.Y, Game1.random.Next(4, 10), false, -1, false, -1); + Game1.player.currentLocation.removeObject(this.TileLocation, false); + this.containerObject.removeComponent(this.offsetKey); + //Remove both tile and container from sync. + ModCore.CustomObjects.Remove(this.containerObject.guid); + ModCore.CustomObjects.Remove(this.guid); } } diff --git a/GeneralMods/Revitalize/Framework/Utilities/MultiplayerUtilities.cs b/GeneralMods/Revitalize/Framework/Utilities/MultiplayerUtilities.cs index 12dcbf9d..4e6128de 100644 --- a/GeneralMods/Revitalize/Framework/Utilities/MultiplayerUtilities.cs +++ b/GeneralMods/Revitalize/Framework/Utilities/MultiplayerUtilities.cs @@ -9,6 +9,9 @@ using StardewValley; namespace Revitalize.Framework.Utilities { + /// + /// Deals with syncing objects in multiplayer. + /// public static class MultiplayerUtilities { public static string RequestGUIDMessage = "Revitalize.RequestGUIDObject"; @@ -16,6 +19,13 @@ namespace Revitalize.Framework.Utilities public static string ReceieveGUIDMessage = "Revitalize.ReceieveGUIDObject"; public static string ReceieveGUIDMessage_Tile = "Revitalize.ReceieveGUIDObject_Tile"; public static string RequestALLModObjects = "Revitalize.EndOfDayRequestAllObjects"; + public static string RequestObjectUpdateSync = "Revitalize.RequestObjectUpdateSync"; + + /// + /// Handles receiving mod messages. + /// + /// + /// public static void GetModMessage(object o, StardewModdingAPI.Events.ModMessageReceivedEventArgs e) { //ModCore.log("Get a mod message: "+e.Type); @@ -79,8 +89,22 @@ namespace Revitalize.Framework.Utilities SendGuidObject(v.Key); } } + + if (e.Type.Equals(RequestObjectUpdateSync)) + { + string guidString = e.ReadAs(); + Guid guid = Guid.Parse(guidString); + if (ModCore.CustomObjects.ContainsKey(guid)) + { + ModCore.CustomObjects[guid].getUpdate(); + } + } } + /// + /// Sends a custom object to be synced. + /// + /// public static void SendGuidObject(Guid request) { if (ModCore.CustomObjects.ContainsKey(request)) @@ -98,6 +122,10 @@ namespace Revitalize.Framework.Utilities } } + /// + /// Sends the container object from the tile component object's guid. + /// + /// public static void SendGuidObject_Tile(Guid request) { if (ModCore.CustomObjects.ContainsKey(request)) @@ -121,20 +149,40 @@ namespace Revitalize.Framework.Utilities } } + /// + /// Requests the object from the given guid. + /// + /// public static void RequestGuidObject(Guid request) { ModCore.ModHelper.Multiplayer.SendMessage(request.ToString(),RequestGUIDMessage, new string[] { ModCore.Manifest.UniqueID.ToString() }); } + /// + /// Requests a container object from tile component object's guid. + /// + /// public static void RequestGuidObject_Tile(Guid request) { ModCore.ModHelper.Multiplayer.SendMessage(request.ToString(), RequestGUIDMessage_Tile, new string[] { ModCore.Manifest.UniqueID.ToString() }); } + /// + /// Send a request to all other revitalize mods to get all of the synced guid objects that isn't held by this mod. + /// public static void RequestALLGuidObjects() { ModCore.ModHelper.Multiplayer.SendMessage(RequestALLModObjects, RequestALLModObjects,new string[] { ModCore.Manifest.UniqueID.ToString() }); } + /// + /// Sends a request to all other revitalize mods to update the given guid object. + /// + /// + public static void RequestUpdateSync(Guid request) + { + ModCore.ModHelper.Multiplayer.SendMessage(request.ToString(), RequestObjectUpdateSync, new string[] { ModCore.Manifest.UniqueID.ToString() }); + } + } } diff --git a/GeneralMods/Revitalize/Revitalize.csproj b/GeneralMods/Revitalize/Revitalize.csproj index e454010f..13eb9130 100644 --- a/GeneralMods/Revitalize/Revitalize.csproj +++ b/GeneralMods/Revitalize/Revitalize.csproj @@ -128,7 +128,6 @@ -