Updated all furniture and objects to sync additional data. Got items to sync better with less issues, and ore seems to not cause as many problems as I thought.

This commit is contained in:
JoshuaNavarro 2019-08-28 12:29:51 -07:00
parent acca21e511
commit 288912d046
13 changed files with 457 additions and 45 deletions

View File

@ -8,6 +8,7 @@ using PyTK.CustomElementHandler;
using StardustCore.Animations;
using StardewValley;
using StardewValley.Objects;
using Revitalize.Framework.Utilities;
namespace Revitalize.Framework.Objects
{
@ -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()
{
if (this.info == null)
public virtual void getUpdate()
{
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()

View File

@ -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<CustomObjectData>(pyTKData);
if (string.IsNullOrEmpty(offsetVec)) return;
if (string.IsNullOrEmpty(containerObject)) return;
this.offsetKey = ModCore.Serializer.DeserializeFromJSONString<Vector2>(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<ArcadeCabinetInformation>(furnitureInfo);
}
}
}
public ArcadeCabinetTile() : base()
{

View File

@ -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<CustomObjectData>(pyTKData);
if (string.IsNullOrEmpty(offsetVec)) return;
if (string.IsNullOrEmpty(containerObject)) return;
this.offsetKey = ModCore.Serializer.DeserializeFromJSONString<Vector2>(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<ChairInformation>(furnitureInfo);
}
}
}
/// <summary>
/// Checks if the player can sit "on" this component.
/// </summary>

View File

@ -25,6 +25,7 @@ namespace Revitalize.Framework.Objects.Furniture
}
}
[JsonIgnore]
public LightManager lightManager
{
get

View File

@ -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<CustomObjectData>(pyTKData);
if (string.IsNullOrEmpty(offsetVec)) return;
if (string.IsNullOrEmpty(containerObject)) return;
this.offsetKey = ModCore.Serializer.DeserializeFromJSONString<Vector2>(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<TableInformation>(furnitureInfo);
}
}
}
[JsonIgnore]
public bool CanPlaceItemsHere
{

View File

@ -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()
{
}
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}

View File

@ -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<ResourceInformaton> getExtraDropInformationFromOres(string id)
{
if (this.oreVeins.ContainsKey(id))
{
return (this.oreVeins[id].objects[Vector2.Zero] as OreVeinTile).extraDrops;
}
else
{
return null;
}
}
/// <summary>
/// Checks to see if a resource can be spawned here.
/// </summary>

View File

@ -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

View File

@ -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
/// </summary>
public OreResourceInformation resourceInfo;
public List<ResourceInformaton> 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<ResourceInformaton> 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<CustomObjectData>(pyTKData);
if (string.IsNullOrEmpty(offsetVec)) return;
if (string.IsNullOrEmpty(containerObject)) return;
this.offsetKey = ModCore.Serializer.DeserializeFromJSONString<Vector2>(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);
}
}

View File

@ -9,6 +9,9 @@ using StardewValley;
namespace Revitalize.Framework.Utilities
{
/// <summary>
/// Deals with syncing objects in multiplayer.
/// </summary>
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";
/// <summary>
/// Handles receiving mod messages.
/// </summary>
/// <param name="o"></param>
/// <param name="e"></param>
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<string>();
Guid guid = Guid.Parse(guidString);
if (ModCore.CustomObjects.ContainsKey(guid))
{
ModCore.CustomObjects[guid].getUpdate();
}
}
}
/// <summary>
/// Sends a custom object to be synced.
/// </summary>
/// <param name="request"></param>
public static void SendGuidObject(Guid request)
{
if (ModCore.CustomObjects.ContainsKey(request))
@ -98,6 +122,10 @@ namespace Revitalize.Framework.Utilities
}
}
/// <summary>
/// Sends the container object from the tile component object's guid.
/// </summary>
/// <param name="request"></param>
public static void SendGuidObject_Tile(Guid request)
{
if (ModCore.CustomObjects.ContainsKey(request))
@ -121,20 +149,40 @@ namespace Revitalize.Framework.Utilities
}
}
/// <summary>
/// Requests the object from the given guid.
/// </summary>
/// <param name="request"></param>
public static void RequestGuidObject(Guid request)
{
ModCore.ModHelper.Multiplayer.SendMessage<string>(request.ToString(),RequestGUIDMessage, new string[] { ModCore.Manifest.UniqueID.ToString() });
}
/// <summary>
/// Requests a container object from tile component object's guid.
/// </summary>
/// <param name="request"></param>
public static void RequestGuidObject_Tile(Guid request)
{
ModCore.ModHelper.Multiplayer.SendMessage<string>(request.ToString(), RequestGUIDMessage_Tile, new string[] { ModCore.Manifest.UniqueID.ToString() });
}
/// <summary>
/// Send a request to all other revitalize mods to get all of the synced guid objects that isn't held by this mod.
/// </summary>
public static void RequestALLGuidObjects()
{
ModCore.ModHelper.Multiplayer.SendMessage<string>(RequestALLModObjects, RequestALLModObjects,new string[] { ModCore.Manifest.UniqueID.ToString() });
}
/// <summary>
/// Sends a request to all other revitalize mods to update the given guid object.
/// </summary>
/// <param name="request"></param>
public static void RequestUpdateSync(Guid request)
{
ModCore.ModHelper.Multiplayer.SendMessage<string>(request.ToString(), RequestObjectUpdateSync, new string[] { ModCore.Manifest.UniqueID.ToString() });
}
}
}

View File

@ -128,7 +128,6 @@
<Compile Include="Framework\Objects\InformationFiles\Furniture\ArcadeCabinetInformation.cs" />
<Compile Include="Framework\Objects\InformationFiles\Furniture\ChairInformation.cs" />
<Compile Include="Framework\Objects\InformationFiles\Furniture\TableInformation.cs" />
<Compile Include="Framework\Objects\InformationFiles\ObjectGUIDInfo.cs" />
<Compile Include="Framework\Objects\InformationFiles\ResourceInformaton.cs" />
<Compile Include="Framework\Objects\Items\Resources\Ore.cs" />
<Compile Include="Framework\Objects\MultiTiledComponent.cs" />