2018-12-30 18:00:05 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using Microsoft.Xna.Framework;
|
2018-12-23 16:53:43 +08:00
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
using PyTK.CustomElementHandler;
|
|
|
|
using StardewValley;
|
|
|
|
using StardewValley.Objects;
|
|
|
|
|
|
|
|
namespace Revitalize.Framework.Objects
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
public class MultiTiledObject : CustomObject
|
2018-12-23 16:53:43 +08:00
|
|
|
{
|
|
|
|
public Dictionary<Vector2, MultiTiledComponent> objects;
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
public MultiTiledObject()
|
2018-12-23 16:53:43 +08:00
|
|
|
{
|
|
|
|
this.objects = new Dictionary<Vector2, MultiTiledComponent>();
|
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
public MultiTiledObject(BasicItemInformation info)
|
|
|
|
: base(info)
|
2018-12-23 16:53:43 +08:00
|
|
|
{
|
|
|
|
this.objects = new Dictionary<Vector2, MultiTiledComponent>();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
this.objects = new Dictionary<Vector2, MultiTiledComponent>();
|
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation, Dictionary<Vector2, MultiTiledComponent> ObjectsList)
|
|
|
|
: base(info, TileLocation)
|
2018-12-23 16:53:43 +08:00
|
|
|
{
|
|
|
|
this.objects = new Dictionary<Vector2, MultiTiledComponent>();
|
2018-12-30 18:00:05 +08:00
|
|
|
foreach (var v in ObjectsList)
|
2018-12-23 16:53:43 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
MultiTiledComponent component = (MultiTiledComponent)v.Value.getOne();
|
2018-12-23 16:53:43 +08:00
|
|
|
this.addComponent(v.Key, component);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool addComponent(Vector2 key, MultiTiledComponent obj)
|
|
|
|
{
|
|
|
|
if (this.objects.ContainsKey(key))
|
|
|
|
return false;
|
2018-12-30 18:00:05 +08:00
|
|
|
|
|
|
|
this.objects.Add(key, obj);
|
|
|
|
obj.containerObject = this;
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
foreach (KeyValuePair<Vector2, MultiTiledComponent> pair in this.objects)
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
foreach (KeyValuePair<Vector2, MultiTiledComponent> 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)
|
|
|
|
{
|
|
|
|
foreach (KeyValuePair<Vector2, MultiTiledComponent> 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)
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
foreach (KeyValuePair<Vector2, MultiTiledComponent> 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
//IMPLEMENT THESE!
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
foreach (KeyValuePair<Vector2, MultiTiledComponent> pair in this.objects)
|
2018-12-30 18:00:05 +08:00
|
|
|
pair.Value.removeFromLocation(pair.Value.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)
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
foreach (KeyValuePair<Vector2, MultiTiledComponent> pair in this.objects)
|
|
|
|
{
|
|
|
|
pair.Value.placementAction(location, x + (int)pair.Key.X * Game1.tileSize, y + (int)pair.Key.Y * Game1.tileSize, who);
|
|
|
|
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)
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
foreach (KeyValuePair<Vector2, MultiTiledComponent> 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
|
|
|
ModCore.log("WTF IS HAPPENING???");
|
|
|
|
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()
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
return new MultiTiledObject(this.info, this.TileLocation, this.objects);
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override ICustomObject recreate(Dictionary<string, string> additionalSaveData, object replacement)
|
|
|
|
{
|
|
|
|
BasicItemInformation data = (BasicItemInformation)CustomObjectData.collection[additionalSaveData["id"]];
|
2018-12-30 18:00:05 +08:00
|
|
|
return new MultiTiledObject(data, (replacement as Chest).TileLocation, this.objects);
|
2018-12-23 16:53:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|