2019-01-10 18:31:23 +08:00
|
|
|
using System;
|
2018-12-30 18:00:05 +08:00
|
|
|
using System.Collections.Generic;
|
2019-01-11 03:09:51 +08:00
|
|
|
using System.IO;
|
2019-01-11 04:44:10 +08:00
|
|
|
using System.Text;
|
2018-12-30 18:00:05 +08:00
|
|
|
using Microsoft.Xna.Framework;
|
2018-12-23 16:53:43 +08:00
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
2019-01-10 18:31:23 +08:00
|
|
|
using Newtonsoft.Json;
|
2018-12-23 16:53:43 +08:00
|
|
|
using PyTK.CustomElementHandler;
|
2019-09-19 08:33:45 +08:00
|
|
|
using Revitalize.Framework.Illuminate;
|
2019-08-28 15:31:14 +08:00
|
|
|
using Revitalize.Framework.Utilities;
|
2018-12-23 16:53:43 +08:00
|
|
|
using StardewValley;
|
2019-01-14 06:46:31 +08:00
|
|
|
using StardewValley.Objects;
|
2018-12-23 16:53:43 +08:00
|
|
|
|
|
|
|
namespace Revitalize.Framework.Objects
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
public class MultiTiledObject : CustomObject
|
2018-12-23 16:53:43 +08:00
|
|
|
{
|
2019-08-28 06:10:56 +08:00
|
|
|
[JsonIgnore]
|
|
|
|
public override string ItemInfo
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
string infoStr = Revitalize.ModCore.Serializer.ToJSONString(this.info);
|
|
|
|
string guidStr = this.guid.ToString();
|
2019-08-28 15:31:14 +08:00
|
|
|
string pytkData = ModCore.Serializer.ToJSONString(this.data);
|
|
|
|
string dictStr = ModCore.Serializer.ToJSONString(this.childrenGuids);
|
|
|
|
if (this.objects != null)
|
|
|
|
{
|
|
|
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
|
|
|
{
|
|
|
|
if (pair.Value == null) continue;
|
|
|
|
if ((pair.Value as CustomObject) == null) continue;
|
|
|
|
if((pair.Value as CustomObject).guid==null) continue;
|
|
|
|
if(ModCore.CustomObjects.ContainsKey( (pair.Value as CustomObject).guid))
|
|
|
|
{
|
|
|
|
ModCore.CustomObjects[(pair.Value as CustomObject).guid] = (CustomObject)pair.Value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ModCore.CustomObjects.Add((pair.Value as CustomObject).guid, (pair.Value as CustomObject));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//ModCore.log("Serializing dict:" + dictStr);
|
|
|
|
return infoStr + "<" + guidStr + "<" + pytkData+"<"+dictStr;
|
2019-08-28 06:10:56 +08:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(value)) return;
|
|
|
|
string[] data = value.Split('<');
|
|
|
|
string infoString = data[0];
|
|
|
|
string guidString = data[1];
|
2019-08-28 15:31:14 +08:00
|
|
|
string pytkData = data[2];
|
|
|
|
string dictStr = data[3];
|
|
|
|
//ModCore.log("Getting dictStr:" + dictStr);
|
2019-08-28 06:10:56 +08:00
|
|
|
|
|
|
|
this.info = (BasicItemInformation)Revitalize.ModCore.Serializer.DeserializeFromJSONString(infoString, typeof(BasicItemInformation));
|
2019-08-28 15:31:14 +08:00
|
|
|
this.data = Revitalize.ModCore.Serializer.DeserializeFromJSONString<CustomObjectData>(pytkData);
|
2019-08-28 06:10:56 +08:00
|
|
|
Guid oldGuid = this.guid;
|
|
|
|
this.guid = Guid.Parse(guidString);
|
2019-08-28 15:31:14 +08:00
|
|
|
|
|
|
|
//this.childrenGuids = ModCore.Serializer.DeserializeFromJSONString<Dictionary<Vector2, Guid>>(dictStr);
|
2019-08-28 06:10:56 +08:00
|
|
|
if (ModCore.CustomObjects.ContainsKey(this.guid))
|
|
|
|
{
|
|
|
|
ModCore.CustomObjects[this.guid] = this;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ModCore.CustomObjects.Add(this.guid, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2019-08-28 15:31:14 +08:00
|
|
|
|
|
|
|
Dictionary<Vector2, Guid> dict = ModCore.Serializer.DeserializeFromJSONString<Dictionary<Vector2, Guid>>(dictStr);
|
|
|
|
if (dict == null) return;
|
|
|
|
if (dict.Count == 0) return;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//ModCore.log("Children dicts are updated!");
|
|
|
|
this.childrenGuids = dict;
|
|
|
|
foreach(KeyValuePair<Vector2,Guid> pair in dict)
|
|
|
|
{
|
|
|
|
if (ModCore.CustomObjects.ContainsKey(pair.Value))
|
|
|
|
{
|
|
|
|
this.removeComponent(pair.Key);
|
|
|
|
this.addComponent(pair.Key, (MultiTiledComponent)ModCore.CustomObjects[pair.Value]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MultiplayerUtilities.RequestGuidObject(pair.Value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-28 06:10:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-11 04:44:10 +08:00
|
|
|
[JsonIgnore]
|
|
|
|
public Dictionary<Vector2, StardewValley.Object> objects;
|
2019-01-09 14:15:58 +08:00
|
|
|
|
2019-05-18 00:43:50 +08:00
|
|
|
public Dictionary<Vector2, Guid> childrenGuids;
|
2019-01-10 18:31:23 +08:00
|
|
|
|
2019-01-09 14:15:58 +08:00
|
|
|
private int width;
|
|
|
|
private int height;
|
|
|
|
public int Width
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2019-05-18 00:43:50 +08:00
|
|
|
return this.width + 1;
|
2019-01-09 14:15:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
public int Height
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2019-05-18 00:43:50 +08:00
|
|
|
return this.height + 1;
|
2019-01-09 14:15:58 +08:00
|
|
|
}
|
|
|
|
}
|
2018-12-23 16:53:43 +08:00
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
public MultiTiledObject()
|
2018-12-23 16:53:43 +08:00
|
|
|
{
|
2019-01-11 04:44:10 +08:00
|
|
|
this.objects = new Dictionary<Vector2, StardewValley.Object>();
|
|
|
|
this.childrenGuids = new Dictionary<Vector2, Guid>();
|
2019-05-18 00:43:50 +08:00
|
|
|
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
|
|
|
|
2019-08-28 15:31:14 +08:00
|
|
|
public MultiTiledObject(CustomObjectData PyTKData, BasicItemInformation info)
|
|
|
|
: base(PyTKData, info)
|
2018-12-23 16:53:43 +08:00
|
|
|
{
|
2019-01-11 04:44:10 +08:00
|
|
|
this.objects = new Dictionary<Vector2, StardewValley.Object>();
|
|
|
|
this.childrenGuids = new Dictionary<Vector2, Guid>();
|
2019-05-18 00:43:50 +08:00
|
|
|
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
|
|
|
|
2019-07-16 17:09:42 +08:00
|
|
|
public MultiTiledObject(CustomObjectData PyTKData, BasicItemInformation info, Vector2 TileLocation)
|
2019-08-28 15:31:14 +08:00
|
|
|
: base(PyTKData, info, TileLocation)
|
2018-12-23 16:53:43 +08:00
|
|
|
{
|
2019-01-11 04:44:10 +08:00
|
|
|
this.objects = new Dictionary<Vector2, StardewValley.Object>();
|
|
|
|
this.childrenGuids = new Dictionary<Vector2, Guid>();
|
2019-05-18 00:43:50 +08:00
|
|
|
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
|
|
|
|
2019-07-16 17:09:42 +08:00
|
|
|
public MultiTiledObject(CustomObjectData PyTKData, BasicItemInformation info, Vector2 TileLocation, Dictionary<Vector2, MultiTiledComponent> ObjectsList)
|
2019-08-28 15:31:14 +08:00
|
|
|
: base(PyTKData, info, TileLocation)
|
2018-12-23 16:53:43 +08:00
|
|
|
{
|
2019-01-11 04:44:10 +08:00
|
|
|
this.objects = new Dictionary<Vector2, StardewValley.Object>();
|
|
|
|
this.childrenGuids = new Dictionary<Vector2, Guid>();
|
2018-12-30 18:00:05 +08:00
|
|
|
foreach (var v in ObjectsList)
|
2018-12-23 16:53:43 +08:00
|
|
|
{
|
2019-05-18 00:43:50 +08:00
|
|
|
MultiTiledComponent component = (MultiTiledComponent)v.Value.getOne();
|
2019-05-17 04:00:43 +08:00
|
|
|
this.addComponent(v.Key, component);
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
2019-05-18 00:43:50 +08:00
|
|
|
|
2019-01-09 14:15:58 +08:00
|
|
|
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool addComponent(Vector2 key, MultiTiledComponent obj)
|
|
|
|
{
|
|
|
|
if (this.objects.ContainsKey(key))
|
2019-05-17 04:00:43 +08:00
|
|
|
{
|
|
|
|
ModCore.log("Bad DATA");
|
2018-12-23 16:53:43 +08:00
|
|
|
return false;
|
2019-05-17 04:00:43 +08:00
|
|
|
}
|
2018-12-30 18:00:05 +08:00
|
|
|
|
2019-01-11 03:09:51 +08:00
|
|
|
this.objects.Add(key, obj);
|
2019-08-28 15:31:14 +08:00
|
|
|
if (this.childrenGuids.ContainsKey(key) == false)
|
2019-08-22 10:06:17 +08:00
|
|
|
{
|
|
|
|
this.childrenGuids.Add(key, obj.guid);
|
|
|
|
}
|
|
|
|
|
2019-01-11 04:44:10 +08:00
|
|
|
|
2019-01-09 14:15:58 +08:00
|
|
|
if (key.X > this.width) this.width = (int)key.X;
|
|
|
|
if (key.Y > this.height) this.height = (int)key.Y;
|
2019-01-11 01:14:16 +08:00
|
|
|
(obj as MultiTiledComponent).containerObject = this;
|
|
|
|
(obj as MultiTiledComponent).offsetKey = key;
|
2019-08-28 15:31:14 +08:00
|
|
|
this.info.forceUpdate();
|
2018-12-30 18:00:05 +08:00
|
|
|
return true;
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
|
|
|
public bool removeComponent(Vector2 key)
|
|
|
|
{
|
|
|
|
if (!this.objects.ContainsKey(key))
|
|
|
|
return false;
|
2018-12-30 18:00:05 +08:00
|
|
|
this.objects.Remove(key);
|
|
|
|
return true;
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1)
|
|
|
|
{
|
2019-08-28 06:10:56 +08:00
|
|
|
this.updateInfo();
|
2019-01-11 04:44:10 +08:00
|
|
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
2019-01-21 15:34:11 +08:00
|
|
|
{
|
|
|
|
(pair.Value as MultiTiledComponent).draw(spriteBatch, x + ((int)pair.Key.X), y + ((int)pair.Key.Y), alpha);
|
|
|
|
}
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void draw(SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1)
|
|
|
|
{
|
2019-08-28 06:10:56 +08:00
|
|
|
this.updateInfo();
|
2019-01-11 04:44:10 +08:00
|
|
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
2019-01-21 15:34:11 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
pair.Value.draw(spriteBatch, xNonTile + (int)pair.Key.X * Game1.tileSize, yNonTile + (int)pair.Key.Y * Game1.tileSize, layerDepth, alpha);
|
2019-01-21 15:34:11 +08:00
|
|
|
}
|
2018-12-23 16:53:43 +08:00
|
|
|
|
|
|
|
//base.draw(spriteBatch, xNonTile, yNonTile, layerDepth, alpha);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber, Color c, bool drawShadow)
|
|
|
|
{
|
2019-08-28 06:10:56 +08:00
|
|
|
this.updateInfo();
|
2019-01-11 04:44:10 +08:00
|
|
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
2019-09-12 13:48:38 +08:00
|
|
|
{
|
|
|
|
//ModCore.log(location + (pair.Key * 16) + new Vector2(32, 32));
|
|
|
|
pair.Value.drawInMenu(spriteBatch, location + (pair.Key * 16) + new Vector2(32, 32), 1.0f, transparency, layerDepth, drawStackNumber, c, drawShadow);
|
|
|
|
}
|
2018-12-30 18:00:05 +08:00
|
|
|
//base.drawInMenu(spriteBatch, location, scaleSize, transparency, layerDepth, drawStackNumber, c, drawShadow);
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void drawWhenHeld(SpriteBatch spriteBatch, Vector2 objectPosition, Farmer f)
|
|
|
|
{
|
2019-08-28 06:10:56 +08:00
|
|
|
this.updateInfo();
|
2019-01-11 04:44:10 +08:00
|
|
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
2018-12-23 16:53:43 +08:00
|
|
|
pair.Value.drawWhenHeld(spriteBatch, objectPosition + (pair.Key * Game1.tileSize), f);
|
|
|
|
//base.drawWhenHeld(spriteBatch, objectPosition, f);
|
|
|
|
}
|
|
|
|
|
2019-05-18 00:43:50 +08:00
|
|
|
|
2019-01-14 06:46:31 +08:00
|
|
|
public override void drawPlacementBounds(SpriteBatch spriteBatch, GameLocation location)
|
|
|
|
{
|
2019-08-28 06:10:56 +08:00
|
|
|
this.updateInfo();
|
2019-01-14 06:46:31 +08:00
|
|
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
|
|
|
{
|
|
|
|
if (!this.isPlaceable())
|
|
|
|
return;
|
2019-05-18 00:43:50 +08:00
|
|
|
int x = Game1.getOldMouseX() + Game1.viewport.X + (int)((pair.Value as MultiTiledComponent).offsetKey.X * Game1.tileSize);
|
|
|
|
int y = Game1.getOldMouseY() + Game1.viewport.Y + (int)((pair.Value as MultiTiledComponent).offsetKey.Y * Game1.tileSize);
|
2019-01-14 06:46:31 +08:00
|
|
|
if ((double)Game1.mouseCursorTransparency == 0.0)
|
|
|
|
{
|
2019-05-18 00:43:50 +08:00
|
|
|
x = ((int)Game1.player.GetGrabTile().X + (int)((pair.Value as MultiTiledComponent).offsetKey.X)) * 64;
|
2019-01-14 06:46:31 +08:00
|
|
|
y = ((int)Game1.player.GetGrabTile().Y + (int)((pair.Value as MultiTiledComponent).offsetKey.Y)) * 64;
|
|
|
|
}
|
|
|
|
if (Game1.player.GetGrabTile().Equals(Game1.player.getTileLocation()) && (double)Game1.mouseCursorTransparency == 0.0)
|
|
|
|
{
|
|
|
|
Vector2 translatedVector2 = Utility.getTranslatedVector2(Game1.player.GetGrabTile(), Game1.player.FacingDirection, 1f);
|
|
|
|
translatedVector2 += (pair.Value as MultiTiledComponent).offsetKey;
|
|
|
|
x = (int)translatedVector2.X * 64;
|
|
|
|
y = (int)translatedVector2.Y * 64;
|
|
|
|
}
|
2019-05-18 00:43:50 +08:00
|
|
|
bool flag = (pair.Value as MultiTiledComponent).canBePlacedHere(location, new Vector2(x / Game1.tileSize, y / Game1.tileSize));
|
2019-01-14 06:46:31 +08:00
|
|
|
spriteBatch.Draw(Game1.mouseCursors, new Vector2((float)(x / 64 * 64 - Game1.viewport.X), (float)(y / 64 * 64 - Game1.viewport.Y)), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(flag ? 194 : 210, 388, 16, 16)), Color.White, 0.0f, Vector2.Zero, 4f, SpriteEffects.None, 0.01f);
|
2019-01-21 15:34:11 +08:00
|
|
|
|
|
|
|
//Revitalize.ModCore.log(new Vector2(x + ((int)pair.Key.X), y + ((int)pair.Key.Y)));
|
2019-05-18 00:43:50 +08:00
|
|
|
if ((pair.Value as MultiTiledComponent).info.ignoreBoundingBox)
|
2019-01-21 15:34:11 +08:00
|
|
|
{
|
|
|
|
x *= -1;
|
|
|
|
y *= -1;
|
|
|
|
}
|
2019-05-18 00:43:50 +08:00
|
|
|
(pair.Value as MultiTiledComponent).draw(spriteBatch, x / Game1.tileSize, y / Game1.tileSize, 0.5f);
|
2019-01-21 15:34:11 +08:00
|
|
|
//break;
|
|
|
|
//this.draw(spriteBatch, x / 64, y / 64, 0.5f);
|
2019-01-14 06:46:31 +08:00
|
|
|
}
|
|
|
|
}
|
2019-05-18 00:43:50 +08:00
|
|
|
|
2019-09-12 05:40:22 +08:00
|
|
|
public override void drawFullyInMenu(SpriteBatch spriteBatch, Vector2 objectPosition, float Depth)
|
|
|
|
{
|
|
|
|
this.updateInfo();
|
2018-12-23 16:53:43 +08:00
|
|
|
|
2019-09-12 05:40:22 +08:00
|
|
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
|
|
|
(pair.Value as CustomObject).drawFullyInMenu(spriteBatch, objectPosition + (pair.Key * Game1.tileSize),Depth);
|
|
|
|
}
|
2018-12-23 16:53:43 +08:00
|
|
|
|
2019-08-28 06:10:56 +08:00
|
|
|
public virtual void pickUp(Farmer who)
|
2018-12-23 16:53:43 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
bool canPickUp = this.removeAndAddToPlayersInventory();
|
2018-12-23 16:53:43 +08:00
|
|
|
if (canPickUp)
|
|
|
|
{
|
2019-01-11 04:44:10 +08:00
|
|
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
2019-05-18 00:43:50 +08:00
|
|
|
{
|
|
|
|
if ((pair.Value as MultiTiledComponent).info.lightManager != null)
|
|
|
|
{
|
|
|
|
ModCore.log("Let there be light.");
|
|
|
|
if ((pair.Value as MultiTiledComponent).info.lightManager.lightsOn == true)
|
|
|
|
{
|
|
|
|
ModCore.log("Got a light???");
|
|
|
|
}
|
|
|
|
}
|
2019-08-28 06:10:56 +08:00
|
|
|
(pair.Value as MultiTiledComponent).removeFromLocation(who.currentLocation, pair.Key);
|
2019-05-18 00:43:50 +08:00
|
|
|
|
|
|
|
}
|
2018-12-23 16:53:43 +08:00
|
|
|
this.location = null;
|
|
|
|
}
|
|
|
|
else
|
2019-09-20 05:44:46 +08:00
|
|
|
Game1.showRedMessage("Can't pickup item for some reason.");
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override bool removeAndAddToPlayersInventory()
|
|
|
|
{
|
2019-09-20 05:44:46 +08:00
|
|
|
bool f = Game1.player.addItemToInventoryBool(this, false);
|
|
|
|
return f;
|
2018-12-23 16:53:43 +08:00
|
|
|
if (Game1.player.isInventoryFull())
|
|
|
|
{
|
|
|
|
Game1.showRedMessage("Inventory full.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Game1.player.addItemToInventory(this);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool placementAction(GameLocation location, int x, int y, Farmer who = null)
|
|
|
|
{
|
2019-08-28 06:10:56 +08:00
|
|
|
this.updateInfo();
|
2019-01-11 04:44:10 +08:00
|
|
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
2018-12-30 18:00:05 +08:00
|
|
|
{
|
2019-05-16 05:27:33 +08:00
|
|
|
/*
|
2019-01-21 15:34:11 +08:00
|
|
|
if ((pair.Value as CustomObject).info.ignoreBoundingBox)
|
|
|
|
{
|
|
|
|
pair.Value.placementAction(location, -1 * (x + (int)pair.Key.X * Game1.tileSize), -1 * (y + (int)pair.Key.Y * Game1.tileSize), who);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pair.Value.placementAction(location, x + (int)pair.Key.X * Game1.tileSize, y + (int)pair.Key.Y * Game1.tileSize, who);
|
2019-05-16 05:27:33 +08:00
|
|
|
}*/
|
2019-05-17 04:00:43 +08:00
|
|
|
(pair.Value as MultiTiledComponent).placementAction(location, x + (int)pair.Key.X * Game1.tileSize, y + (int)pair.Key.Y * Game1.tileSize, who);
|
2019-01-11 01:14:16 +08:00
|
|
|
//ModCore.log(pair.Value.TileLocation);
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
|
|
|
this.location = location;
|
|
|
|
return true;
|
|
|
|
//return base.placementAction(location, x, y, who);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool canBePlacedHere(GameLocation l, Vector2 tile)
|
|
|
|
{
|
2019-01-11 04:44:10 +08:00
|
|
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
2018-12-23 16:53:43 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
if (!pair.Value.canBePlacedHere(l, tile + pair.Key))
|
|
|
|
return false;
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
public override bool clicked(Farmer who)
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
bool cleanUp = this.clicked(who);
|
2018-12-23 16:53:43 +08:00
|
|
|
if (cleanUp)
|
2019-08-28 06:10:56 +08:00
|
|
|
this.pickUp(who);
|
2018-12-23 16:53:43 +08:00
|
|
|
return cleanUp;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool rightClicked(Farmer who)
|
|
|
|
{
|
|
|
|
return base.rightClicked(who);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool shiftRightClicked(Farmer who)
|
|
|
|
{
|
|
|
|
return base.shiftRightClicked(who);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool checkForAction(Farmer who, bool justCheckingForActivity = false)
|
|
|
|
{
|
|
|
|
|
|
|
|
return base.checkForAction(who, justCheckingForActivity);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override Item getOne()
|
|
|
|
{
|
2019-01-11 04:44:10 +08:00
|
|
|
Dictionary<Vector2, MultiTiledComponent> objs = new Dictionary<Vector2, MultiTiledComponent>();
|
|
|
|
foreach (var pair in this.objects)
|
|
|
|
{
|
2019-09-12 13:48:38 +08:00
|
|
|
objs.Add(pair.Key, (MultiTiledComponent)pair.Value.getOne());
|
2019-01-11 04:44:10 +08:00
|
|
|
}
|
2019-08-28 15:31:14 +08:00
|
|
|
return new MultiTiledObject(this.data, this.info.Copy(), this.TileLocation, objs);
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override ICustomObject recreate(Dictionary<string, string> additionalSaveData, object replacement)
|
|
|
|
{
|
2019-01-11 15:24:55 +08:00
|
|
|
MultiTiledObject obj = (MultiTiledObject)Revitalize.ModCore.Serializer.DeserializeGUID<MultiTiledObject>(additionalSaveData["GUID"]);
|
2019-01-13 03:25:45 +08:00
|
|
|
if (obj == null)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2019-01-11 04:44:10 +08:00
|
|
|
|
|
|
|
Dictionary<Vector2, Guid> guids = new Dictionary<Vector2, Guid>();
|
|
|
|
|
2019-05-18 00:43:50 +08:00
|
|
|
foreach (KeyValuePair<Vector2, Guid> pair in obj.childrenGuids)
|
2019-01-11 03:09:51 +08:00
|
|
|
{
|
2019-01-11 04:44:10 +08:00
|
|
|
guids.Add(pair.Key, pair.Value);
|
2019-01-11 03:09:51 +08:00
|
|
|
}
|
2019-01-10 18:31:23 +08:00
|
|
|
|
2019-05-18 00:43:50 +08:00
|
|
|
foreach (KeyValuePair<Vector2, Guid> pair in guids)
|
2019-01-11 04:44:10 +08:00
|
|
|
{
|
2019-05-18 00:43:50 +08:00
|
|
|
obj.childrenGuids.Remove(pair.Key);
|
|
|
|
MultiTiledComponent component = Revitalize.ModCore.Serializer.DeserializeGUID<MultiTiledComponent>(pair.Value.ToString());
|
2019-08-27 07:34:03 +08:00
|
|
|
component.InitNetFields();
|
2019-08-22 11:03:16 +08:00
|
|
|
obj.removeComponent(pair.Key);
|
2019-01-11 05:37:35 +08:00
|
|
|
obj.addComponent(pair.Key, component);
|
2019-05-18 00:43:50 +08:00
|
|
|
|
|
|
|
|
2019-01-11 04:44:10 +08:00
|
|
|
}
|
2019-08-27 07:34:03 +08:00
|
|
|
obj.InitNetFields();
|
2019-01-11 04:44:10 +08:00
|
|
|
|
2019-01-10 18:31:23 +08:00
|
|
|
if (!Revitalize.ModCore.ObjectGroups.ContainsKey(additionalSaveData["GUID"]))
|
|
|
|
{
|
2019-01-11 03:09:51 +08:00
|
|
|
Revitalize.ModCore.ObjectGroups.Add(additionalSaveData["GUID"], obj);
|
|
|
|
return obj;
|
2019-01-10 18:31:23 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return Revitalize.ModCore.ObjectGroups[additionalSaveData["GUID"]];
|
|
|
|
}
|
|
|
|
|
2019-05-18 00:43:50 +08:00
|
|
|
|
2019-01-10 18:31:23 +08:00
|
|
|
}
|
|
|
|
|
2019-08-22 11:03:16 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Recreate the data from data already stored on the object.
|
|
|
|
/// </summary>
|
|
|
|
public virtual void recreate()
|
2019-01-10 18:31:23 +08:00
|
|
|
{
|
2019-08-22 11:03:16 +08:00
|
|
|
Dictionary<Vector2, Guid> guids = new Dictionary<Vector2, Guid>();
|
2019-01-13 03:39:24 +08:00
|
|
|
|
2019-08-22 11:03:16 +08:00
|
|
|
foreach (KeyValuePair<Vector2, Guid> pair in this.childrenGuids)
|
|
|
|
{
|
|
|
|
guids.Add(pair.Key, pair.Value);
|
|
|
|
}
|
2019-01-13 03:39:24 +08:00
|
|
|
|
2019-08-22 11:03:16 +08:00
|
|
|
foreach (KeyValuePair<Vector2, Guid> pair in guids)
|
|
|
|
{
|
|
|
|
this.childrenGuids.Remove(pair.Key);
|
|
|
|
MultiTiledComponent component = Revitalize.ModCore.Serializer.DeserializeGUID<MultiTiledComponent>(pair.Value.ToString());
|
2019-08-27 07:34:03 +08:00
|
|
|
component.InitNetFields();
|
2019-08-22 11:03:16 +08:00
|
|
|
this.removeComponent(pair.Key);
|
|
|
|
this.addComponent(pair.Key, component);
|
2019-01-11 04:44:10 +08:00
|
|
|
|
2019-08-22 11:03:16 +08:00
|
|
|
|
|
|
|
}
|
2019-08-27 07:34:03 +08:00
|
|
|
this.InitNetFields();
|
2019-08-22 11:03:16 +08:00
|
|
|
|
|
|
|
if (!Revitalize.ModCore.ObjectGroups.ContainsKey(this.guid.ToString()))
|
|
|
|
{
|
|
|
|
Revitalize.ModCore.ObjectGroups.Add(this.guid.ToString(), this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override Dictionary<string, string> getAdditionalSaveData()
|
|
|
|
{
|
|
|
|
Dictionary<string, string> saveData = base.getAdditionalSaveData();
|
|
|
|
saveData.Add("GUID", this.guid.ToString());
|
2019-09-22 09:48:21 +08:00
|
|
|
//Revitalize.ModCore.Serializer.SerializeGUID(this.guid.ToString(), this);
|
2019-01-10 18:31:23 +08:00
|
|
|
return saveData;
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
2019-01-09 14:15:58 +08:00
|
|
|
|
|
|
|
public void setAllAnimationsToDefault()
|
|
|
|
{
|
2019-05-18 00:43:50 +08:00
|
|
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
2019-01-09 14:15:58 +08:00
|
|
|
{
|
2019-05-18 00:43:50 +08:00
|
|
|
string animationKey = (pair.Value as MultiTiledComponent).generateDefaultRotationalAnimationKey();
|
2019-01-10 03:41:40 +08:00
|
|
|
if ((pair.Value as MultiTiledComponent).animationManager.animations.ContainsKey(animationKey))
|
2019-01-09 14:15:58 +08:00
|
|
|
{
|
2019-01-10 03:41:40 +08:00
|
|
|
(pair.Value as MultiTiledComponent).animationManager.setAnimation(animationKey);
|
2019-01-09 14:15:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-14 06:46:31 +08:00
|
|
|
|
2019-01-11 01:14:16 +08:00
|
|
|
public override bool canStackWith(Item other)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override int maximumStackSize()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-08-28 06:10:56 +08:00
|
|
|
public override void updateInfo()
|
|
|
|
{
|
2019-08-28 15:31:14 +08:00
|
|
|
//this.recreateComponents();
|
2019-08-28 06:10:56 +08:00
|
|
|
if (this.info == null)
|
|
|
|
{
|
|
|
|
this.ItemInfo = this.text;
|
2019-09-05 05:20:05 +08:00
|
|
|
//ModCore.log("Updated item info for container!");
|
2019-08-28 06:10:56 +08:00
|
|
|
return;
|
|
|
|
}
|
2019-08-28 15:31:14 +08:00
|
|
|
if (this.objects != null)
|
|
|
|
{
|
|
|
|
if (this.childrenGuids != null)
|
|
|
|
{
|
|
|
|
if (this.objects.Count == 0 || this.objects.Count != this.childrenGuids.Count)
|
|
|
|
{
|
|
|
|
this.ItemInfo = this.text;
|
|
|
|
//ModCore.log("Updated item info for container!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (this.objects.Count == 0)
|
|
|
|
{
|
|
|
|
this.ItemInfo = this.text;
|
|
|
|
//ModCore.log("Updated item info for container!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2019-08-28 06:10:56 +08:00
|
|
|
|
2019-08-28 07:47:22 +08:00
|
|
|
if (this.requiresUpdate())
|
2019-08-28 06:10:56 +08:00
|
|
|
{
|
2019-08-29 03:29:51 +08:00
|
|
|
//this.ItemInfo = this.text;
|
2019-08-28 07:47:22 +08:00
|
|
|
this.text = this.ItemInfo;
|
|
|
|
this.info.cleanAfterUpdate();
|
2019-08-29 03:29:51 +08:00
|
|
|
MultiplayerUtilities.RequestUpdateSync(this.guid);
|
2019-08-28 06:10:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-28 15:31:14 +08:00
|
|
|
public virtual void recreateComponents()
|
|
|
|
{
|
|
|
|
|
|
|
|
if (ModCore.CustomObjects.ContainsKey(this.guid))
|
|
|
|
{
|
|
|
|
if ((ModCore.CustomObjects[this.guid] as MultiTiledObject).objects.Count > 0)
|
|
|
|
{
|
|
|
|
this.objects = (ModCore.CustomObjects[this.guid] as MultiTiledObject).objects;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
if((ModCore.CustomObjects[this.guid] as MultiTiledObject).childrenGuids.Count > 0)
|
|
|
|
{
|
|
|
|
this.childrenGuids = (ModCore.CustomObjects[this.guid] as MultiTiledObject).childrenGuids;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MultiplayerUtilities.RequestGuidObject(this.guid);
|
|
|
|
MultiplayerUtilities.RequestGuidObject_Tile(this.guid);
|
|
|
|
}
|
|
|
|
if (this.objects == null || this.childrenGuids == null)
|
|
|
|
{
|
2019-09-05 05:20:05 +08:00
|
|
|
//ModCore.log("Either objects or children guids are null");
|
2019-08-28 15:31:14 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-05 05:20:05 +08:00
|
|
|
//ModCore.log("Recreate children components");
|
2019-08-28 15:31:14 +08:00
|
|
|
if (this.objects.Count < this.childrenGuids.Count)
|
|
|
|
{
|
|
|
|
foreach (KeyValuePair<Vector2, Guid> pair in this.childrenGuids)
|
|
|
|
{
|
|
|
|
if (ModCore.CustomObjects.ContainsKey(pair.Value))
|
|
|
|
{
|
|
|
|
this.removeComponent(pair.Key);
|
|
|
|
this.addComponent(pair.Key,(MultiTiledComponent)ModCore.CustomObjects[pair.Value]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MultiplayerUtilities.RequestGuidObject(pair.Value);
|
|
|
|
MultiplayerUtilities.RequestGuidObject_Tile(pair.Value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-05 05:20:05 +08:00
|
|
|
//ModCore.log("Count is exactly the same!");
|
|
|
|
//ModCore.log("Count is: " + this.objects.Count+" : and " + this.childrenGuids.Count);
|
2019-08-28 15:31:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-19 08:33:45 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="DyeColor"></param>
|
|
|
|
public override void dyeColor(NamedColor DyeColor)
|
|
|
|
{
|
|
|
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
|
|
|
{
|
|
|
|
(pair.Value as CustomObject).dyeColor(DyeColor);
|
|
|
|
}
|
|
|
|
this.info.DyedColor = DyeColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void eraseDye()
|
|
|
|
{
|
|
|
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
|
|
|
{
|
|
|
|
(pair.Value as CustomObject).eraseDye();
|
|
|
|
}
|
|
|
|
this.info.DyedColor = new NamedColor("", new Color(0, 0, 0, 0));
|
|
|
|
}
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
|
|
|
}
|