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;
|
|
|
|
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-01-11 04:44:10 +08:00
|
|
|
[JsonIgnore]
|
|
|
|
public Dictionary<Vector2, StardewValley.Object> objects;
|
2019-01-09 14:15:58 +08:00
|
|
|
|
2019-01-11 04:44:10 +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
|
|
|
|
{
|
|
|
|
return this.width+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public int Height
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.height+1;
|
|
|
|
}
|
|
|
|
}
|
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-01-10 18:31:23 +08:00
|
|
|
this.guid = Guid.NewGuid();
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
public MultiTiledObject(BasicItemInformation info)
|
|
|
|
: base(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-01-10 18:31:23 +08:00
|
|
|
this.guid = Guid.NewGuid();
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation)
|
|
|
|
: base(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-01-10 18:31:23 +08:00
|
|
|
this.guid = Guid.NewGuid();
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
|
|
|
|
2019-01-11 01:14:16 +08:00
|
|
|
public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation, Dictionary<Vector2, MultiTiledComponent> ObjectsList)
|
2018-12-30 18:00:05 +08:00
|
|
|
: base(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-01-11 01:14:16 +08:00
|
|
|
MultiTiledComponent component =(MultiTiledComponent) v.Value.getOne();
|
|
|
|
this.addComponent(v.Key, (component as MultiTiledComponent));
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
2019-01-10 18:31:23 +08:00
|
|
|
this.guid = Guid.NewGuid();
|
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))
|
|
|
|
return false;
|
2018-12-30 18:00:05 +08:00
|
|
|
|
2019-01-11 03:09:51 +08:00
|
|
|
this.objects.Add(key, obj);
|
2019-01-11 04:44:10 +08:00
|
|
|
this.childrenGuids.Add(key, Guid.NewGuid());
|
|
|
|
|
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;
|
2018-12-30 18:00:05 +08:00
|
|
|
return true;
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool removeComponent(Vector2 key)
|
|
|
|
{
|
2019-01-14 06:46:31 +08:00
|
|
|
|
|
|
|
|
2018-12-23 16:53:43 +08:00
|
|
|
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-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.draw(spriteBatch, x + (int)pair.Key.X * Game1.tileSize, y + (int)pair.Key.Y * Game1.tileSize, alpha);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void draw(SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1)
|
|
|
|
{
|
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
|
|
|
pair.Value.draw(spriteBatch, xNonTile + (int)pair.Key.X * Game1.tileSize, yNonTile + (int)pair.Key.Y * Game1.tileSize, layerDepth, alpha);
|
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-01-11 04:44:10 +08:00
|
|
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
2018-12-30 18:00:05 +08:00
|
|
|
pair.Value.drawInMenu(spriteBatch, location + (pair.Key * 16), 1.0f, transparency, layerDepth, drawStackNumber, c, drawShadow);
|
|
|
|
//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-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-01-14 06:46:31 +08:00
|
|
|
|
|
|
|
public override void drawPlacementBounds(SpriteBatch spriteBatch, GameLocation location)
|
|
|
|
{
|
|
|
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
|
|
|
{
|
|
|
|
if (!this.isPlaceable())
|
|
|
|
return;
|
|
|
|
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);
|
|
|
|
if ((double)Game1.mouseCursorTransparency == 0.0)
|
|
|
|
{
|
|
|
|
x = ((int)Game1.player.GetGrabTile().X+ (int)((pair.Value as MultiTiledComponent).offsetKey.X)) * 64;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
bool flag = Utility.playerCanPlaceItemHere(location, (Item)pair.Value, x, y, Game1.player);
|
|
|
|
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);
|
|
|
|
this.draw(spriteBatch, x / 64, y / 64, 0.5f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-23 16:53:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
public virtual void pickUp()
|
|
|
|
{
|
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-01-10 03:41:40 +08:00
|
|
|
(pair.Value as MultiTiledComponent).removeFromLocation((pair.Value as MultiTiledComponent).location, pair.Key);
|
2018-12-23 16:53:43 +08:00
|
|
|
this.location = null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Game1.showRedMessage("NOOOOOOOO");
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool removeAndAddToPlayersInventory()
|
|
|
|
{
|
|
|
|
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-01-11 04:44:10 +08:00
|
|
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
2018-12-30 18:00:05 +08:00
|
|
|
{
|
|
|
|
pair.Value.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)
|
2018-12-30 18:00:05 +08:00
|
|
|
this.pickUp();
|
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)
|
|
|
|
{
|
|
|
|
objs.Add(pair.Key, (MultiTiledComponent)pair.Value);
|
|
|
|
}
|
|
|
|
return new MultiTiledObject(this.info, 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>();
|
|
|
|
|
|
|
|
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-01-11 04:44:10 +08:00
|
|
|
foreach(KeyValuePair<Vector2,Guid> pair in guids)
|
|
|
|
{
|
|
|
|
obj.childrenGuids.Remove(pair.Key);
|
2019-01-11 15:24:55 +08:00
|
|
|
//Revitalize.ModCore.log("DESERIALIZE: " + pair.Value.ToString());
|
|
|
|
MultiTiledComponent component= Revitalize.ModCore.Serializer.DeserializeGUID<MultiTiledComponent>(pair.Value.ToString());
|
2019-01-11 05:37:35 +08:00
|
|
|
component.InitNetFields();
|
|
|
|
|
|
|
|
obj.addComponent(pair.Key, component);
|
2019-01-11 04:44:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
}
|
2019-01-11 05:37:35 +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"]];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public override Dictionary<string, string> getAdditionalSaveData()
|
|
|
|
{
|
|
|
|
Dictionary<string,string> saveData= base.getAdditionalSaveData();
|
2019-01-13 03:39:24 +08:00
|
|
|
|
|
|
|
Revitalize.ModCore.log("Serialize: " + this.guid.ToString());
|
|
|
|
|
2019-01-10 18:31:23 +08:00
|
|
|
saveData.Add("GUID", this.guid.ToString());
|
2019-01-11 04:44:10 +08:00
|
|
|
|
2019-01-11 15:24:55 +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-01-11 04:44:10 +08:00
|
|
|
foreach(KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
2019-01-09 14:15:58 +08:00
|
|
|
{
|
2019-01-10 03:41:40 +08:00
|
|
|
string animationKey = (pair.Value as MultiTiledComponent) .generateDefaultRotationalAnimationKey();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
|
|
|
}
|