Either rewrite multiplayer or erase all objects before players join.

This commit is contained in:
2018-08-07 10:07:33 -07:00
parent 3af2da68fa
commit 9c070e91c5
16 changed files with 2808 additions and 346 deletions

View File

@ -51,14 +51,35 @@ namespace StardustCore
SerializationManager.initializeDefaultSuportedTypes();
TextureManager = new TextureManager();
StardewModdingAPI.Events.ControlEvents.KeyPressed += ControlEvents_KeyPressed;
StardewModdingAPI.Events.GameEvents.UpdateTick += GameEvents_UpdateTick;
}
private void GameEvents_UpdateTick(object sender, EventArgs e)
{
}
private void ControlEvents_KeyPressed(object sender, StardewModdingAPI.Events.EventArgsKeyPressed e)
{
if (e.KeyPressed == Keys.V)
{
CoreObject tile1 = new CoreObject(new Texture2DExtended(ModCore.ModHelper, Path.Combine("Content", "Graphics", "MultiTest", "Test1.png")), 3, Vector2.Zero, 9);
tile1.description = "Hello";
tile1.Name = "test";
tile1.displayName = "test";
Game1.player.addItemToInventory(tile1);
}
}
private void SaveEvents_AfterLoad(object sender, EventArgs e)
{
SerializationManager.restoreAllModObjects(SerializationManager.trackedObjectList);
List<KeyValuePair<Vector2, MultiTileComponent>> objs = new List<KeyValuePair<Vector2, MultiTileComponent>>();
/*
@ -73,7 +94,7 @@ namespace StardustCore
*/
// Game1.player.addItemToInventory(collection);
CoreObject tile1 = new CoreObject(new Texture2DExtended(ModCore.ModHelper, Path.Combine("Content", "Graphics", "MultiTest", "Test1.png")),0, Vector2.Zero,9);
CoreObject tile1 = new CoreObject(new Texture2DExtended(ModCore.ModHelper, Path.Combine("Content", "Graphics", "MultiTest", "Test1.png")),3, Vector2.Zero,9);
tile1.description = "Hello";
tile1.Name = "test";
tile1.displayName = "test";

View File

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Netcode;
namespace StardustCore.NetCode.Graphics
{
public class NetAnimation : Netcode.NetField<Animations.Animation, NetAnimation>
{
public NetRectangle sourceRect;
public NetInt frameDuration;
public NetInt frameDurationUntilNextAnimation;
public NetAnimation()
{
}
public NetAnimation(Animations.Animation animation) : base(animation)
{
}
protected override void ReadDelta(BinaryReader reader, NetVersion version)
{
sourceRect = new NetRectangle();
sourceRect.Read(reader, version);
Value.sourceRectangle = sourceRect.Value;
frameDuration = new NetInt();
frameDuration.Read(reader, version);
Value.frameDuration = frameDuration.Value;
frameDurationUntilNextAnimation = new NetInt();
frameDurationUntilNextAnimation.Read(reader, version);
Value.frameDuration = frameDuration.Value;
}
protected override void WriteDelta(BinaryWriter writer)
{
sourceRect = new NetRectangle(Value.sourceRectangle);
sourceRect.Write(writer);
frameDuration = new NetInt(Value.frameDuration);
frameDuration.Write(writer);
frameDurationUntilNextAnimation = new NetInt(Value.frameCountUntilNextAnimation);
frameDurationUntilNextAnimation.Write(writer);
}
}
}

View File

@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Netcode;
using StardewValley;
using StardewValley.Network;
namespace StardustCore.NetCode.Graphics
{
public class NetAnimationManager : Netcode.NetField<Animations.AnimationManager,NetAnimationManager>
{
public NetAnimationManager()
{
}
public NetAnimationManager(Animations.AnimationManager manager): base(manager)
{
}
public NetString currentAnimationName;
public NetInt currentAnimationListIndex;
public NetTexture2DExtended objectTexture;
public NetAnimation defaultDrawFrame;
public NetBool enabled;
public NetString animationDataString;
protected override void ReadDelta(BinaryReader reader, NetVersion version)
{
NetString currentAnimationName = new NetString();
currentAnimationName.Read(reader, version);
NetInt currentIndex = new NetInt();
currentIndex.Read(reader, version);
NetTexture2DExtended text = new NetTexture2DExtended();
text.Read(reader, version);
NetAnimation defaultAnimation = new NetAnimation();
defaultAnimation.Read(reader, version);
NetBool enabled = new NetBool();
enabled.Read(reader, version);
NetString data = new NetString();
data.Read(reader, version);
Value.setExtendedTexture(text.Value);
Value.defaultDrawFrame = defaultAnimation.Value;
Value.enabled = enabled.Value;
//Try and prevent unnecessary parsing.
if (Value.animations == null && !String.IsNullOrEmpty(Value.animationDataString))
{
Value.animations = Animations.AnimationManager.parseAnimationsFromXNB(data.Value);
}
if (!String.IsNullOrEmpty(data.Value))
{
Value.setAnimation(currentAnimationName.Value, currentIndex.Value);
}
else
{
Value.currentAnimation = defaultDrawFrame.Value;
}
}
protected override void WriteDelta(BinaryWriter writer)
{
NetString curentAnimationName = new NetString(Value.currentAnimationName);
currentAnimationName.Write(writer);
NetInt currentAnimationListIndex = new NetInt(Value.currentAnimationListIndex);
currentAnimationListIndex.Write(writer);
NetTexture2DExtended texture = new NetTexture2DExtended(Value.getExtendedTexture());
texture.Write(writer);
NetAnimation defaultDrawFrame = new NetAnimation(Value.defaultDrawFrame);
defaultDrawFrame.Write(writer);
NetBool enabled = new NetBool(Value.enabled);
enabled.Write(writer);
NetString animationData = new NetString(Value.animationDataString);
animationData.Write(writer);
}
}
}

View File

@ -0,0 +1,143 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Netcode;
using StardewValley;
using StardustCore.UIUtilities;
namespace StardustCore.NetCode.Graphics
{
/*
public class NetTexture2DExtended : Netcode.NetField<UIUtilities.Texture2DExtended, NetTexture2DExtended>
{
public string Name;
public Texture2D texture;
public string path;
public NetTexture2DExtended()
{
}
public NetTexture2DExtended(Texture2DExtended value) : base(value)
{
}
public void ReadData(BinaryReader reader,NetVersion version)
{
ReadDelta(reader, version);
}
public void WriteData(BinaryWriter writer)
{
WriteDelta(writer);
}
protected override void ReadDelta(BinaryReader reader, NetVersion version)
{
/*
int width = reader.ReadInt32();
int height = reader.ReadInt32();
Byte[] colorsOne = new byte[width*height*4];
colorsOne = reader.ReadBytes(width*height*4);
texture = new Texture2D(Game1.graphics.GraphicsDevice,width,height);
texture.SetData(colorsOne);
string Name = reader.ReadString();
string path = reader.ReadString();
string modID = reader.ReadString();
Value.Name = Name;
Value.path = path;
Value.ModID = modID;
Value.setTexture(ModCore.getTextureFromManager(Value.ModID, Value.Name).getTexture());
}
protected override void WriteDelta(BinaryWriter writer)
{
/*
int size = base.Value.getTexture().Width * base.Value.getTexture().Height * 4;
writer.Write(base.Value.getTexture().Width);
writer.Write(base.Value.getTexture().Height);
//writer.Write(size);
texture = Value.getTexture();
Byte[] colorsOne = new byte[size]; //The hard to read,1D array
texture.GetData(colorsOne);
writer.Write(colorsOne);
NetString name = new NetString(Value.Name);
name.Write(writer);
NetString path = new NetString(Value.path);
path.Write(writer);
NetString id = new NetString(Value.ModID);
id.Write(writer);
}
}*/
public class NetTexture2DExtended : Netcode.NetField<UIUtilities.Texture2DExtended, NetTexture2DExtended>
{
public string Name;
public Texture2D texture;
public string path;
public int width;
public int height;
public NetTexture2DExtended()
{
}
public NetTexture2DExtended(Texture2DExtended value) : base(value)
{
}
protected override void ReadDelta(BinaryReader reader, NetVersion version)
{
int width = reader.ReadInt32();
int height = reader.ReadInt32();
Byte[] colorsOne = new byte[width * height * 4];
colorsOne = reader.ReadBytes(width * height * 4);
texture = new Texture2D(Game1.graphics.GraphicsDevice, width, height);
texture.SetData(colorsOne);
string Name = reader.ReadString();
string path = reader.ReadString();
if (version.IsPriorityOver(this.ChangeVersion))
{
this.CleanSet(new UIUtilities.Texture2DExtended(ModCore.ModHelper,ModCore.Manifest, path), true);
}
}
protected override void WriteDelta(BinaryWriter writer)
{
int size = base.Value.getTexture().Width * base.Value.getTexture().Height * 4;
writer.Write(base.Value.getTexture().Width);
writer.Write(base.Value.getTexture().Height);
//writer.Write(size);
texture = Value.getTexture();
Byte[] colorsOne = new byte[size]; //The hard to read,1D array
texture.GetData(colorsOne);
writer.Write(colorsOne);
writer.Write(base.Value.Name);
writer.Write(base.Value.path);
}
}
}

View File

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Netcode;
namespace StardustCore.NetCode
{
public class NetAnimation : Netcode.NetField<Animations.Animation, NetAnimation>
{
public NetRectangle sourceRect;
public NetInt frameDuration;
public NetInt frameDurationUntilNextAnimation;
public NetAnimation()
{
}
public NetAnimation(Animations.Animation animation) : base(animation)
{
}
protected override void ReadDelta(BinaryReader reader, NetVersion version)
{
sourceRect = new NetRectangle();
sourceRect.Read(reader, version);
Value.sourceRectangle = sourceRect.Value;
frameDuration = new NetInt();
frameDuration.Read(reader, version);
Value.frameDuration = frameDuration.Value;
frameDurationUntilNextAnimation = new NetInt();
frameDurationUntilNextAnimation.Read(reader, version);
Value.frameDuration = frameDuration.Value;
}
protected override void WriteDelta(BinaryWriter writer)
{
sourceRect = new NetRectangle(Value.sourceRectangle);
sourceRect.Write(writer);
frameDuration = new NetInt(Value.frameDuration);
frameDuration.Write(writer);
frameDurationUntilNextAnimation = new NetInt(Value.frameCountUntilNextAnimation);
frameDurationUntilNextAnimation.Write(writer);
}
}
}

View File

@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Netcode;
using StardewValley;
using StardewValley.Network;
namespace StardustCore.NetCode
{
public class NetAnimationManager : Netcode.NetField<Animations.AnimationManager,NetAnimationManager>
{
public NetAnimationManager()
{
}
public NetAnimationManager(Animations.AnimationManager manager): base(manager)
{
}
public NetString currentAnimationName;
public NetInt currentAnimationListIndex;
public NetTexture2DExtended objectTexture;
public NetAnimation defaultDrawFrame;
public NetBool enabled;
public NetString animationDataString;
protected override void ReadDelta(BinaryReader reader, NetVersion version)
{
NetString currentAnimationName = new NetString();
currentAnimationName.Read(reader, version);
NetInt currentIndex = new NetInt();
currentIndex.Read(reader, version);
NetTexture2DExtended text = new NetTexture2DExtended();
text.Read(reader, version);
NetAnimation defaultAnimation = new NetAnimation();
defaultAnimation.Read(reader, version);
NetBool enabled = new NetBool();
enabled.Read(reader, version);
NetString data = new NetString();
data.Read(reader, version);
Value.setExtendedTexture(text.Value);
Value.defaultDrawFrame = defaultAnimation.Value;
Value.enabled = enabled.Value;
//Try and prevent unnecessary parsing.
if (Value.animations == null && !String.IsNullOrEmpty(Value.animationDataString))
{
Value.animations = Animations.AnimationManager.parseAnimationsFromXNB(data.Value);
}
if (!String.IsNullOrEmpty(data.Value))
{
Value.setAnimation(currentAnimationName.Value, currentIndex.Value);
}
else
{
Value.currentAnimation = defaultDrawFrame.Value;
}
}
protected override void WriteDelta(BinaryWriter writer)
{
NetString curentAnimationName = new NetString(Value.currentAnimationName);
currentAnimationName.Write(writer);
NetInt currentAnimationListIndex = new NetInt(Value.currentAnimationListIndex);
currentAnimationListIndex.Write(writer);
NetTexture2DExtended texture = new NetTexture2DExtended(Value.getExtendedTexture());
texture.Write(writer);
NetAnimation defaultDrawFrame = new NetAnimation(Value.defaultDrawFrame);
defaultDrawFrame.Write(writer);
NetBool enabled = new NetBool(Value.enabled);
enabled.Write(writer);
NetString animationData = new NetString(Value.animationDataString);
animationData.Write(writer);
}
}
}

View File

@ -32,8 +32,9 @@ namespace StardustCore.NetCode
protected override void ReadDelta(BinaryReader reader, NetVersion version)
{
texture = new NetTexture2DExtended();
texture.Read(reader, version);
texture.ReadFull(reader, version);
Value.setExtendedTexture(texture.Value);
which = new NetInt();
@ -55,12 +56,14 @@ namespace StardustCore.NetCode
boundingBox = new NetRectangle();
boundingBox.Read(reader, version);
Value.boundingBox.Value = boundingBox.Value;
}
protected override void WriteDelta(BinaryWriter writer)
{
texture = new NetTexture2DExtended(Value.getExtendedTexture());
texture.Write(writer);
texture.WriteFull(writer);
which = new NetInt(Value.ParentSheetIndex);
which.Write(writer);
@ -76,6 +79,7 @@ namespace StardustCore.NetCode
boundingBox = new NetRectangle(Value.boundingBox.Value);
sourceRect.Write(writer);
}
}
}

View File

@ -0,0 +1,24 @@
using Netcode;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StardustCore.NetCode
{
public class NetKeyValuePair<K, V, KField, VField> : NetField<KeyValuePair<K, V>, NetKeyValuePair<K, V, KField, VField>> where KField : NetField<K, KField>, new() where VField : NetField<V, VField>, new()
{
protected override void ReadDelta(BinaryReader reader, NetVersion version)
{
throw new NotImplementedException();
}
protected override void WriteDelta(BinaryWriter writer)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,36 @@
using Microsoft.Xna.Framework;
using Netcode;
using StardustCore.Objects;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StardustCore.NetCode.NetPairs
{
class NetVector2MultiTilePair<K,KField>: NetKeyValuePair<Vector2,MultiTileComponent,Netcode.NetVector2,NetCode.Objects.NetMultiTileComponent>
{
public NetVector2MultiTilePair()
{
}
public NetVector2MultiTilePair(KeyValuePair<Vector2,MultiTileComponent> hello)
{
this.InitialSet(Value);
}
public override void Read(BinaryReader reader, NetVersion version)
{
base.Read(reader, version);
}
public override void Write(BinaryWriter writer)
{
base.Write(writer);
}
}
}

View File

@ -15,11 +15,6 @@ namespace StardustCore.NetCode
public class NetTexture2DExtended : Netcode.NetField<UIUtilities.Texture2DExtended, NetTexture2DExtended>
{
public string Name;
public Texture2D texture;
public string path;
public int width;
public int height;
public NetTexture2DExtended()
@ -31,37 +26,99 @@ namespace StardustCore.NetCode
{
}
public void ReadData(BinaryReader reader, NetVersion version)
{
ReadDelta(reader, version);
}
public void WriteData(BinaryWriter writer)
{
WriteDelta(writer);
}
protected override void ReadDelta(BinaryReader reader, NetVersion version)
{
int width = reader.ReadInt32();
int height = reader.ReadInt32();
Byte[] colorsOne = new byte[width*height*4];
colorsOne = reader.ReadBytes(width*height*4);
texture = new Texture2D(Game1.graphics.GraphicsDevice,width,height);
texture.SetData(colorsOne);
string Name = reader.ReadString();
string path = reader.ReadString();
NetInt Width = new NetInt();
Width.Read(reader,version);
int width = Width.Value;
if (version.IsPriorityOver(this.ChangeVersion))
NetInt Height = new NetInt();
Height.Read(reader, version);
int height = Height.Value;
NetString name = new NetString();
name.Read(reader, version);
NetString path = new NetString();
path.Read(reader, version);
NetInt count = new NetInt();
count.Read(reader, version);
List<Color> bytes = new List<Color>();
//colorsOne = reader.ReadBytes();
for(int i=0; i < count.Value; i++)
{
this.CleanSet(new UIUtilities.Texture2DExtended(ModCore.ModHelper, path),true);
NetColor col = new NetColor();
col.Read(reader, version);
bytes.Add(col.Value);
}
ModCore.ModMonitor.Log("Finished length: "+bytes.Count.ToString());
ModCore.ModMonitor.Log("W: " + width.ToString());
ModCore.ModMonitor.Log("H: " + height.ToString());
//Texture2D texture = new Texture2D(Game1.graphics.GraphicsDevice,width,height);
Texture2DExtended texture = new Texture2DExtended(ModCore.ModHelper, Path.Combine("Content", "Graphics", "MultiTest", "Test1.png"));
this.Value = texture;
//texture.SetData(bytes.ToArray());
//Value.Name = name.Value;
//Value.path = path.Value;
//Value.setTexure(texture);
}
protected override void WriteDelta(BinaryWriter writer)
{
int size = base.Value.getTexture().Width * base.Value.getTexture().Height * 4;
writer.Write(base.Value.getTexture().Width);
writer.Write(base.Value.getTexture().Height);
int size = Value.getTexture().Width * Value.getTexture().Height;
NetInt Width = new NetInt(Value.getTexture().Width);
Width.Write(writer);
NetInt Height = new NetInt(Value.getTexture().Height);
Height.Write(writer);
NetString name = new NetString(Value.Name);
name.Write(writer);
NetString path = new NetString(Value.path);
path.Write(writer);
//writer.Write(size);
texture = Value.getTexture();
Byte[] colorsOne = new byte[size]; //The hard to read,1D array
Texture2D texture = Value.getTexture();
Color[] colorsOne = new Color[size]; //The hard to read,1D array
texture.GetData(colorsOne);
writer.Write(colorsOne);
writer.Write(base.Value.Name);
writer.Write(base.Value.path);
NetInt count = new NetInt(colorsOne.Length);
count.Write(writer);
ModCore.ModMonitor.Log("Color length:" + count.ToString());
foreach(var v in colorsOne)
{
NetColor col = new NetColor(v);
col.Write(writer);
}
}

View File

@ -0,0 +1,133 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
using Netcode;
using StardewValley;
using StardustCore.NetCode.Graphics;
using StardustCore.UIUtilities;
namespace StardustCore.NetCode
{
public class NetCoreObject : Netcode.NetField<CoreObject, NetCoreObject>
{
public NetInt which;
public NetVector2 tilePos;
public NetRectangle boundingBox;
public NetVector2 position;
public NetInt Decoration_type;
public NetInt rotations;
public NetInt currentRotation;
public NetInt sourceIndexOffset;
public NetVector2 drawPosition;
public NetRectangle sourceRect;
public NetRectangle defaultSourceRect;
public NetRectangle defaultBoundingBox;
public NetString description;
public NetTexture2DExtended texture;
public NetBool flipped;
public NetBool flaggedForPickup;
public NetBool lightGlowAdded;
public NetObjectList<Item> inventory;
public NetInt InventoryMaxSize;
public NetBool itemReadyForHarvest;
public NetBool lightsOn;
public NetString locationName;
public NetColor lightColor;
public NetBool removable;
public NetColor drawColor;
public NetBool useXML;
public NetString serializationName;
//Animation Manager.....
public NetAnimationManager animationManager;
public NetCoreObject()
{
}
public NetCoreObject(CoreObject value) : base(value)
{
}
protected override void ReadDelta(BinaryReader reader, NetVersion version)
{
texture = new NetTexture2DExtended();
texture.Read(reader, version);
Value.setExtendedTexture(texture.Value);
which = new NetInt();
which.Read(reader, version);
Value.ParentSheetIndex = which.Value;
tilePos = new NetVector2();
tilePos.Read(reader, version);
Value.TileLocation = tilePos.Value;
InventoryMaxSize = new NetInt();
InventoryMaxSize.Read(reader, version);
Value.inventoryMaxSize = InventoryMaxSize.Value;
sourceRect = new NetRectangle();
sourceRect.Read(reader, version);
Value.sourceRect = sourceRect.Value;
boundingBox = new NetRectangle();
boundingBox.Read(reader, version);
Value.boundingBox.Value = boundingBox.Value;
drawPosition = new NetVector2();
drawPosition.Read(reader, version);
Value.drawPosition = drawPosition.Value;
animationManager = new NetAnimationManager();
animationManager.Read(reader, version);
Value.animationManager = animationManager.Value;
}
protected override void WriteDelta(BinaryWriter writer)
{
texture = new NetTexture2DExtended(Value.getExtendedTexture());
texture.Write(writer);
which = new NetInt(Value.ParentSheetIndex);
which.Write(writer);
tilePos = new NetVector2(Value.TileLocation);
tilePos.Write(writer);
InventoryMaxSize = new NetInt(Value.inventoryMaxSize);
InventoryMaxSize.Write(writer);
sourceRect = new NetRectangle(Value.sourceRect);
sourceRect.Write(writer);
boundingBox = new NetRectangle(Value.boundingBox.Value);
sourceRect.Write(writer);
drawPosition = new NetVector2(Value.drawPosition);
drawPosition.Write(writer);
if (Value.animationManager != null)
{
animationManager = new NetAnimationManager(Value.animationManager);
animationManager.Write(writer);
}
}
}
}

View File

@ -0,0 +1,114 @@
using Netcode;
using StardustCore.NetCode.Graphics;
using StardustCore.Objects;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StardustCore.NetCode.Objects
{
class NetMultiTileComponent : Netcode.NetField<MultiTileComponent, NetMultiTileComponent>
{
private NetTexture2DExtended texture;
private NetInt which;
private NetVector2 tilePos;
private NetRectangle sourceRect;
private NetRectangle boundingBox;
private NetVector2 drawPosition;
private NetAnimationManager animationManager;
public NetMultiTileComponent()
{
}
public NetMultiTileComponent(MultiTileComponent obj): base(obj)
{
}
public NetInt InventoryMaxSize { get; private set; }
protected override void ReadDelta(BinaryReader reader, NetVersion version)
{
texture = new NetTexture2DExtended();
texture.Read(reader, version);
which = new NetInt();
which.Read(reader, version);
Value.ParentSheetIndex = which.Value;
tilePos = new NetVector2();
tilePos.Read(reader, version);
Value.TileLocation = tilePos.Value;
InventoryMaxSize = new NetInt();
InventoryMaxSize.Read(reader, version);
Value.inventoryMaxSize = InventoryMaxSize.Value;
sourceRect = new NetRectangle();
sourceRect.Read(reader, version);
Value.sourceRect = sourceRect.Value;
boundingBox = new NetRectangle();
boundingBox.Read(reader, version);
Value.boundingBox.Value = boundingBox.Value;
drawPosition = new NetVector2();
drawPosition.Read(reader, version);
Value.drawPosition = drawPosition.Value;
animationManager = new NetAnimationManager();
animationManager.Read(reader, version);
Value.animationManager = animationManager.Value;
//NetCoreObject obj = new NetCoreObject();
//obj.ReadData(reader, version);
/*
NetMultiTileObject hmm = new NetMultiTileObject();
hmm.Read(reader,version);
Value.containerObject = hmm.Value;
*/
}
protected override void WriteDelta(BinaryWriter writer)
{
//NetCoreObject obj = new NetCoreObject(Value);
//obj.WriteData(writer);
texture = new NetTexture2DExtended(Value.getExtendedTexture());
texture.Write(writer);
which = new NetInt(Value.ParentSheetIndex);
which.Write(writer);
tilePos = new NetVector2(Value.TileLocation);
tilePos.Write(writer);
InventoryMaxSize = new NetInt(Value.inventoryMaxSize);
InventoryMaxSize.Write(writer);
sourceRect = new NetRectangle(Value.sourceRect);
sourceRect.Write(writer);
boundingBox = new NetRectangle(Value.boundingBox.Value);
sourceRect.Write(writer);
drawPosition = new NetVector2(Value.drawPosition);
drawPosition.Write(writer);
if (Value.animationManager != null)
{
animationManager = new NetAnimationManager(Value.animationManager);
animationManager.Write(writer);
}
//NetMultiTileObject hmm = new NetMultiTileObject(Value.containerObject);
//hmm.Write(writer);
}
}
}

View File

@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Netcode;
using StardustCore.Objects;
namespace StardustCore.NetCode.Objects
{
class NetMultiTileObject : Netcode.NetField<MultiTileObject, NetMultiTileObject>
{
public NetMultiTileObject()
{
}
public NetMultiTileObject(MultiTileObject obj): base(obj)
{
}
protected override void ReadDelta(BinaryReader reader, NetVersion version)
{
NetCoreObject obj = new NetCoreObject();
obj.Read(reader, version);
//Values already taken care of in NetCoreObject
NetList<KeyValuePair<Vector2, MultiTileComponent>, NetKeyValuePair<Vector2, MultiTileComponent, NetVector2, NetMultiTileComponent>> netList = new NetList<KeyValuePair<Vector2, MultiTileComponent>, NetKeyValuePair<Vector2, MultiTileComponent, NetVector2, NetMultiTileComponent>>();
netList.Read(reader, version);
Value.objects = netList.ToList();
NetColor col = new NetColor();
col.Read(reader, version);
Value.categoryColor = col.Value;
NetString name = new NetString();
name.Read(reader, version);
Value.categoryName = name.Value;
}
protected override void WriteDelta(BinaryWriter writer)
{
NetCoreObject obj = new NetCoreObject(Value);
obj.Write(writer);
NetList<KeyValuePair<Vector2, MultiTileComponent>, NetKeyValuePair<Vector2, MultiTileComponent, NetVector2, NetMultiTileComponent>> netList = new NetList<KeyValuePair<Vector2, MultiTileComponent>, NetKeyValuePair<Vector2, MultiTileComponent, NetVector2, NetMultiTileComponent>>();
foreach (var v in Value.objects)
{
netList.Add(v);
}
netList.Write(writer);
NetColor col = new NetColor(Value.categoryColor);
col.Write(writer);
NetString catName = new NetString(Value.categoryName);
catName.Write(writer);
}
}
}

View File

@ -1,5 +1,6 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Netcode;
using StardewModdingAPI;
using StardewValley;
using StardewValley.Locations;
@ -104,24 +105,46 @@ namespace StardustCore
lightColor = Color.Black;
thisType = this.GetType().ToString();
base.initNetFields();
this.NetFields.AddField(new NetCode.NetCoreObject(this));
}
public CoreObject()
{
base.initNetFields();
this.updateDrawPosition();
this.NetFields.AddField(new NetCode.NetCoreObject(this));
}
public CoreObject(bool f)
{
base.initNetFields();
//does nothng
this.NetFields.AddField(new NetCode.NetCoreObject(this));
}
public CoreObject(Texture2DExtended texture,int which, Vector2 Tile, int InventoryMaxSize)
public CoreObject(Texture2DExtended texture,int which, Vector2 Tile, int InventoryMaxSize):base()
{
var ok=Game1.getAllFarmers();
foreach (var v in ok){
this.owner.Value = v.UniqueMultiplayerID;
break;
}
this.Type = "Not Sure";
this.CanBeSetDown = true;
this.CanBeGrabbed = true;
this.IsSpawnedObject = false;
this.questItem.Value = false;
this.questId.Value =0;
this.IsOn = false;
this.heldObject.Value = null;
this.Stack = 1;
InitializeBasics(InventoryMaxSize, Tile);
if (TextureSheet == null)
{
@ -169,11 +192,20 @@ namespace StardustCore
this.boundingBox.Value = new Rectangle((int)this.TileLocation.X * Game1.tileSize, (int)this.TileLocation.Y * Game1.tileSize, 1 * Game1.tileSize, 1 * Game1.tileSize);
this.defaultBoundingBox = this.boundingBox.Value;
}
this.boundingBox.Value = new Rectangle(0, 0, Game1.tileSize, Game1.tileSize);
this.updateDrawPosition();
this.rotations = Convert.ToInt32(array[4]);
this.Price = Convert.ToInt32(array[5]);
this.ParentSheetIndex = which;
this.serializationName=this.GetType().ToString();
this.drawPosition = Vector2.Zero;
this.TileLocation = tileLocation;
this.locationsName = "";
this.position = this.TileLocation * (Game1.tileSize);
this.thisLocation = null;
}
public override string getDescription()
@ -248,82 +280,6 @@ namespace StardustCore
return this.clicked(who);
}
//DONT USE THIS BASE IT IS TERRIBLE
/*
public override bool clicked(StardewValley.Farmer who)
{
// Game1.showRedMessage("THIS IS CLICKED!!!");
Game1.haltAfterCheck = false;
if (this.heldObject != null)
{
this.spillInventoryEverywhere();
return false;
}
if (this.heldObject == null && (who.ActiveObject == null || !(who.ActiveObject is CoreObject)))
{
if (Game1.player.currentLocation is FarmHouse)
{
// Game1.showRedMessage("Why2?");
// this.spillInventoryEverywhere();
if (this.heldObject != null) Util.addItemToInventoryElseDrop(this.heldObject.getOne());
this.heldObject = new CoreObject(parentSheetIndex, Vector2.Zero, this.inventoryMaxSize);
// Util.addItemToInventoryElseDrop(this.heldObject.getOne());
this.heldObject = null;
this.flaggedForPickUp = true;
thisLocation = null;
return true;
}
else
{
// return true;
this.flaggedForPickUp = true;
if (this is TV)
{
// this.heldObject = new TV(parentSheetIndex, Vector2.Zero);
}
else
{
// Util.addItemToInventoryElseDrop(this.heldObject);
var obj = new CoreObject(parentSheetIndex, Vector2.Zero, this.inventoryMaxSize);
// Util.addItemToInventoryElseDrop(obj);
// this.spillInventoryEverywhere();
if (this.heldObject != null) this.heldObject.performRemoveAction(this.tileLocation, who.currentLocation);
this.heldObject = null;
Game1.playSound("coin");
thisLocation = null;
return true;
}
}
}
if (this.heldObject != null && who.addItemToInventoryBool(this.heldObject, false))
{
// Game1.showRedMessage("Why3?");
// if(this.heldObject!=null) Game1.player.addItemByMenuIfNecessary((Item)this.heldObject);
// this.spillInventoryEverywhere();
var obj = new CoreObject(parentSheetIndex, Vector2.Zero, this.inventoryMaxSize);
// Util.addItemToInventoryElseDrop(obj);
if (this.heldObject != null) this.heldObject.performRemoveAction(this.tileLocation, who.currentLocation);
this.heldObject = null;
Game1.playSound("coin");
thisLocation = null;
return true;
}
return false;
}
*/
public virtual bool RightClicked(StardewValley.Farmer who)
{
// StardewModdingAPI.Log.AsyncC(lightColor);
@ -732,72 +688,6 @@ namespace StardustCore
return false;
}
/*
public override bool canBePlacedHere(GameLocation l, Vector2 tile)
{
if ((l is FarmHouse))
{
for (int i = 0; i < this.boundingBox.Width / Game1.tileSize; i++)
{
for (int j = 0; j < this.boundingBox.Height / Game1.tileSize; j++)
{
Vector2 vector = tile * (float)Game1.tileSize + new Vector2((float)i, (float)j) * (float)Game1.tileSize;
vector.X += (float)(Game1.tileSize / 2);
vector.Y += (float)(Game1.tileSize / 2);
foreach (KeyValuePair<Vector2, StardewValley.Object> something in l.objects)
{
StardewValley.Object obj = something.Value;
if ((obj.GetType()).ToString().Contains("CoreObject"))
{
CoreObject current = (CoreObject)obj;
if (current.Decoration_type == 11 && current.getBoundingBox(current.tileLocation).Contains((int)vector.X, (int)vector.Y) && current.heldObject == null && this.getTilesWide() == 1)
{
bool result = true;
return result;
}
if ((current.Decoration_type != 12 || this.Decoration_type == 12) && current.getBoundingBox(current.tileLocation).Contains((int)vector.X, (int)vector.Y))
{
bool result = false;
return result;
}
}
}
}
}
return Util.canBePlacedHere(this, l, tile);
}
else
{
// Game1.showRedMessage("NOT FARMHOUSE");
for (int i = 0; i < this.boundingBox.Width / Game1.tileSize; i++)
{
for (int j = 0; j < this.boundingBox.Height / Game1.tileSize; j++)
{
Vector2 vector = tile * (float)Game1.tileSize + new Vector2((float)i, (float)j) * (float)Game1.tileSize;
vector.X += (float)(Game1.tileSize / 2);
vector.Y += (float)(Game1.tileSize / 2);
/*
foreach (CoreObject current in (l as FarmHouse).CoreObject)
{
if (current.Decoration_type == 11 && current.getBoundingBox(current.tileLocation).Contains((int)vector.X, (int)vector.Y) && current.heldObject == null && this.getTilesWide() == 1)
{
bool result = true;
return result;
}
if ((current.Decoration_type != 12 || this.Decoration_type == 12) && current.getBoundingBox(current.tileLocation).Contains((int)vector.X, (int)vector.Y))
{
bool result = false;
return result;
}
}
}
}
return Util.canBePlacedHere(this, l, tile);
}
}
*/
public virtual void updateDrawPosition()
{
@ -814,174 +704,6 @@ namespace StardustCore
return this.boundingBox.Height / Game1.tileSize;
}
/*
public override bool placementAction(GameLocation location, int x, int y, StardewValley.Farmer who = null)
{
// Log.AsyncC(x);
// Log.AsyncM(y);
if (location is FarmHouse)
{
Point point = new Point(x / Game1.tileSize, y / Game1.tileSize);
List<Rectangle> walls = FarmHouse.getWalls((location as FarmHouse).upgradeLevel);
this.tileLocation = new Vector2((float)point.X, (float)point.Y);
bool flag = false;
if (this.Decoration_type == 6 || this.Decoration_type == 13 || this.parentSheetIndex == 1293)
{
int num = (this.parentSheetIndex == 1293) ? 3 : 0;
bool flag2 = false;
foreach (Rectangle current in walls)
{
if ((this.Decoration_type == 6 || this.Decoration_type == 13 || num != 0) && current.Y + num == point.Y && current.Contains(point.X, point.Y - num))
{
flag2 = true;
break;
}
}
if (!flag2)
{
Game1.showRedMessage("Must be placed on wall");
return false;
}
flag = true;
}
for (int i = point.X; i < point.X + this.getTilesWide(); i++)
{
for (int j = point.Y; j < point.Y + this.getTilesHigh(); j++)
{
if (location.doesTileHaveProperty(i, j, "NoFurniture", "Back") != null)
{
Game1.showRedMessage("Furniture can't be placed here");
return false;
}
if (!flag && Utility.pointInRectangles(walls, i, j))
{
Game1.showRedMessage("Can't place on wall");
return false;
}
if (location.getTileIndexAt(i, j, "Buildings") != -1)
{
return false;
}
}
}
this.boundingBox = new Rectangle(x, y, this.boundingBox.Width, this.boundingBox.Height);
foreach (KeyValuePair<Vector2, StardewValley.Object> c in location.objects)
{
StardewValley.Object ehh = c.Value;
if (((ehh.GetType()).ToString()).Contains("CoreObject"))
{
CoreObject current2 = (CoreObject)ehh;
if (current2.Decoration_type == 11 && current2.heldObject == null && current2.getBoundingBox(current2.tileLocation).Intersects(this.boundingBox))
{
current2.performObjectDropInAction(this, false, (who == null) ? Game1.player : who);
bool result = true;
return result;
}
}
}
foreach (StardewValley.Farmer current3 in location.getStardewValley.Farmers())
{
if (current3.GetBoundingBox().Intersects(this.boundingBox))
{
Game1.showRedMessage("Can't place on top of a person.");
bool result = false;
return result;
}
}
this.updateDrawPosition();
// Log.AsyncO(this.boundingBox);
// Log.AsyncO(x);
// Log.AsyncY(y);
for (int i = 0; i <= this.boundingBox.X / Game1.tileSize; i++)
{
base.placementAction(location, x + 1, y, who);
}
for (int i = 0; i <= this.boundingBox.Y / Game1.tileSize; i++)
{
base.placementAction(location, x, y + 1, who);
}
return true;
}
else
{
Point point = new Point(x / Game1.tileSize, y / Game1.tileSize);
// List<Rectangle> walls = FarmHouse.getWalls((location as FarmHouse).upgradeLevel);
this.tileLocation = new Vector2((float)point.X, (float)point.Y);
bool flag = false;
if (this.Decoration_type == 6 || this.Decoration_type == 13 || this.parentSheetIndex == 1293)
{
int num = (this.parentSheetIndex == 1293) ? 3 : 0;
bool flag2 = false;
/*
foreach (Rectangle current in walls)
{
if ((this.Decoration_type == 6 || this.Decoration_type == 13 || num != 0) && current.Y + num == point.Y && current.Contains(point.X, point.Y - num))
{
flag2 = true;
break;
}
}
if (!flag2)
{
Game1.showRedMessage("Must be placed on wall");
return false;
}
flag = true;
}
for (int i = point.X; i < point.X + this.getTilesWide(); i++)
{
for (int j = point.Y; j < point.Y + this.getTilesHigh(); j++)
{
if (location.doesTileHaveProperty(i, j, "NoFurniture", "Back") != null)
{
Game1.showRedMessage("Furniture can't be placed here");
return false;
}
/*
if (!flag && Utility.pointInRectangles(walls, i, j))
{
Game1.showRedMessage("Can't place on wall");
return false;
}
if (location.getTileIndexAt(i, j, "Buildings") != -1)
{
return false;
}
}
}
this.boundingBox = new Rectangle(x, y, this.boundingBox.Width, this.boundingBox.Height);
/*
foreach (Furniture current2 in (location as FarmHouse).furniture)
{
if (current2.furniture_type == 11 && current2.heldObject == null && current2.getBoundingBox(current2.tileLocation).Intersects(this.boundingBox))
{
current2.performObjectDropInAction(this, false, (who == null) ? Game1.player : who);
bool result = true;
return result;
}
}
foreach (StardewValley.Farmer current3 in location.getStardewValley.Farmers())
{
if (current3.GetBoundingBox().Intersects(this.boundingBox))
{
Game1.showRedMessage("Can't place on top of a person.");
bool result = false;
return result;
}
}
this.updateDrawPosition();
thisLocation = Game1.player.currentLocation;
return base.placementAction(location, x, y, who);
}
}
*/
public override bool placementAction(GameLocation location, int x, int y, StardewValley.Farmer who = null)
{
@ -1290,12 +1012,7 @@ namespace StardustCore
{
if (x == -1)
{
//ERROR IS HERE?!?!?!?!?
if (TextureSheet == null)
{
ModCore.ModMonitor.Log("WHY IS EX TEXT NULL?????");
}
spriteBatch.Draw(TextureSheet.getTexture(), Game1.GlobalToLocal(Game1.viewport, this.drawPosition), new Rectangle?(this.sourceRect), Color.White * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (this.Decoration_type == 12) ? 0f : ((float)(this.boundingBox.Bottom - 8) / 10000f));
spriteBatch.Draw(TextureSheet.getTexture(), Game1.GlobalToLocal(Game1.viewport, this.drawPosition), new Rectangle?(this.sourceRect), Color.White * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0f);
}
else
{

View File

@ -57,5 +57,10 @@ namespace StardustCore.UIUtilities
{
return this.texture;
}
public void setTexure(Texture2D text)
{
this.texture = text;
}
}
}

1847
da[lda Normal file

File diff suppressed because it is too large Load Diff