Fixed tables not removing items on clean up.

This commit is contained in:
JoshuaNavarro 2019-05-16 13:00:43 -07:00
parent 42f8d2595b
commit 05aeabed12
7 changed files with 147 additions and 166 deletions

View File

@ -61,7 +61,9 @@ namespace Revitalize.Framework.Objects
/// <summary>Empty constructor.</summary>
public CustomObject() {
this.guid = Guid.NewGuid();
ModCore.log("Created new obj with guid: " + this.guid);
this.InitNetFields();
ModCore.log(System.Environment.StackTrace);
}
/// <summary>Construct an instance.</summary>
@ -71,6 +73,8 @@ namespace Revitalize.Framework.Objects
this.info = info;
this.initializeBasics();
this.guid = Guid.NewGuid();
ModCore.log("Created new obj with guid: " + this.guid);
ModCore.log(System.Environment.StackTrace);
}
/// <summary>Construct an instance.</summary>
@ -80,6 +84,8 @@ namespace Revitalize.Framework.Objects
this.info = info;
this.initializeBasics();
this.guid = Guid.NewGuid();
ModCore.log("Created new obj with guid: " + this.guid);
ModCore.log(System.Environment.StackTrace);
}
/// <summary>Sets some basic information up.</summary>

View File

@ -48,7 +48,7 @@ namespace Revitalize.Framework.Objects.Furniture
}
return new TableMultiTiledObject(this.info, this.TileLocation, objs);
return new TableMultiTiledObject(this.info, this.TileLocation,objs);
}
@ -137,8 +137,8 @@ namespace Revitalize.Framework.Objects.Furniture
{
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
{
(pair.Value as TableTileComponent).clearHeldObject();
(pair.Value as TableTileComponent).removeFromLocation((pair.Value as TableTileComponent).location, pair.Key);
(pair.Value as TableTileComponent).pickUpItem(true);
}
this.location = null;
}
@ -146,5 +146,7 @@ namespace Revitalize.Framework.Objects.Furniture
Game1.showRedMessage("NOOOOOOOO");
}
}
}

View File

@ -17,17 +17,6 @@ namespace Revitalize.Framework.Objects.Furniture
{
public TableInformation furnitureInfo;
public StardewValley.Object heldItem
{
get
{
return this.heldObject.Value;
}
set
{
this.heldObject.Value = value;
}
}
public bool CanPlaceItemsHere
{
@ -59,165 +48,95 @@ namespace Revitalize.Framework.Objects.Furniture
this.furnitureInfo = FurnitureInfo;
}
public PickUpState pickUpItem(bool forCleanUp = false)
/// <summary>
/// Forcefully clears the held object without much fuss.
/// </summary>
public void clearHeldObject()
{
//ModCore.log("Pick up!");
if (this.CanPlaceItemsHere == false) return PickUpState.DoNothing;
if (forCleanUp == true)
if (this.heldObject.Value != null)
{
ModCore.log("Clean up: " + this.TileLocation);
if (this.heldItem != null)
ModCore.log("Help the held object!");
if (Game1.player.isInventoryFull() == false)
{
if (Game1.player.isInventoryFull() == true)
{
Game1.createItemDebris(this.heldItem.getOne(), Vector2.Zero, 0, this.location);
this.heldItem = null;
return PickUpState.DoNothing;
}
else
{
Game1.player.addItemToInventoryBool(this.heldItem);
this.heldItem = null;
return PickUpState.DoNothing;
}
Game1.player.addItemToInventoryBool(this.heldObject.Value, false);
this.heldObject.Value = null;
ModCore.log("Recover item");
return;
}
else
{
ModCore.log("Nothing here...");
return PickUpState.DoNothing;
Game1.createItemDebris(this.heldObject.Value, Vector2.Zero, 0);
}
}
if (this.heldItem == null)
else
{
if (this.CanPlaceItemsHere == true && this.heldItem == null && Game1.player.ActiveObject != null)
{
//ModCore.log("Hello1");
this.heldItem = (StardewValley.Object)Game1.player.ActiveObject.getOne();
Game1.player.reduceActiveItemByOne();
return PickUpState.DoNothing;
}
else if (this.CanPlaceItemsHere == true && this.heldItem == null && Game1.player.ActiveObject == null)
{
ModCore.log("Hello1Pickup");
return PickUpState.RemoveContainer;
}
return PickUpState.DoNothing;
ModCore.log("Why is there no held object here???");
}
else if(this.heldItem!=null)
{
if (this.CanPlaceItemsHere == true && this.heldItem != null && Game1.player.ActiveObject == null)
{
//ModCore.log("Hello2");
if (Game1.player.isInventoryFull() == false)
{
Game1.player.addItemToInventoryBool(this.heldItem);
this.heldItem = null;
//ModCore.log("Get rid of it11111");
return PickUpState.DoNothing;
}
else
{
ModCore.log("I'm not sure....");
//do nothing.
return PickUpState.DoNothing;
}
}
else if (this.CanPlaceItemsHere == true && this.heldItem != null && Game1.player.ActiveObject != null)
{
ModCore.log("Hello3");
if (Game1.player.isInventoryFull() == false)
{
Game1.player.addItemToInventoryBool(this.heldItem);
this.heldItem = null;
//ModCore.log("Get rid of it222222");
//ModCore.log(System.Environment.StackTrace);
return PickUpState.DoNothing;
}
else
{
ModCore.log("I'm not sure....");
//do nothing.
return PickUpState.DoNothing;
}
}
}
return PickUpState.DoNothing;
}
public PickUpState pickUpItemCheck(bool forCleanUp = false)
/// <summary>
/// Picks up the held item from this tile.
/// </summary>
/// <param name="justChecking"></param>
/// <returns></returns>
public PickUpState pickUpItem(bool justChecking = true)
{
//ModCore.log("Pick up!");
if (this.CanPlaceItemsHere == false) return PickUpState.DoNothing;
if (this.heldItem == null)
if (this.heldObject.Value == null && Game1.player.ActiveObject != null)
{
if (this.CanPlaceItemsHere == true && this.heldItem == null && Game1.player.ActiveObject != null)
if (justChecking == false)
{
this.heldObject.Value = (StardewValley.Object)Game1.player.ActiveObject.getOne();
Game1.player.reduceActiveItemByOne();
ModCore.log("My guid: "+this.guid);
ModCore.log("Container guid: " + this.containerObject.guid);
foreach (var v in this.containerObject.objects)
{
if (v.Value.heldObject.Value != null) ModCore.log("Found a keeper to put down!");
else
{
ModCore.log("Nothing here seriously");
}
if (v.Value == this) ModCore.log("I AM PRESENT!");
ModCore.log("Other guid: " + (v.Value as TableTileComponent).guid);
}
//ModCore.log("Hello1");
//this.heldItem = (StardewValley.Object)Game1.player.ActiveObject.getOne();
//Game1.player.reduceActiveItemByOne();
return PickUpState.DoNothing;
}
else if (this.CanPlaceItemsHere == true && this.heldItem == null && Game1.player.ActiveObject == null)
{
ModCore.log("Hello1Pickup");
return PickUpState.RemoveContainer;
}
return PickUpState.DoNothing;
}
else if (this.heldItem != null)
else if (this.heldObject.Value != null)
{
if (this.CanPlaceItemsHere == true && this.heldItem != null && Game1.player.ActiveObject == null)
if (justChecking == false)
{
//ModCore.log("Hello2");
if (Game1.player.isInventoryFull() == false)
{
//Game1.player.addItemToInventoryBool(this.heldItem);
//this.heldItem = null;
//ModCore.log("Get rid of it11111");
return PickUpState.DoNothing;
Game1.player.addItemToInventoryBool(this.heldObject.Value, false);
this.heldObject.Value = null;
}
else
{
ModCore.log("I'm not sure....");
//do nothing.
return PickUpState.DoNothing;
}
}
else if (this.CanPlaceItemsHere == true && this.heldItem != null && Game1.player.ActiveObject != null)
{
ModCore.log("Hello3");
if (Game1.player.isInventoryFull() == false)
{
//Game1.player.addItemToInventoryBool(this.heldItem);
//ModCore.log("Get rid of it222222");
//ModCore.log(System.Environment.StackTrace);
return PickUpState.DoNothing;
}
else
{
ModCore.log("I'm not sure....");
//do nothing.
return PickUpState.DoNothing;
Game1.createItemDebris(this.heldObject.Value, Vector2.Zero, 0);
}
}
return PickUpState.DoNothing;
}
else if (this.heldObject.Value == null && Game1.player.ActiveObject == null)
{
return PickUpState.RemoveContainer;
}
return PickUpState.DoNothing;
}
public override bool performObjectDropInAction(Item dropInItem, bool probe, Farmer who)
{
ModCore.log("Drop In");
return false; //this.pickUpItem()==PickUpState.DoNothing;
//return base.performObjectDropInAction(dropInItem, probe, who);
}
@ -227,6 +146,7 @@ namespace Revitalize.Framework.Objects.Furniture
return base.performDropDownAction(who);
}
//Checks for any sort of interaction IF and only IF there is a held object on this tile.
public override bool checkForAction(Farmer who, bool justCheckingForActivity = false)
{
MouseState mState = Mouse.GetState();
@ -234,7 +154,6 @@ namespace Revitalize.Framework.Objects.Furniture
if (mState.RightButton == ButtonState.Pressed && (keyboardState.IsKeyDown(Keys.LeftShift) || !keyboardState.IsKeyDown(Keys.RightShift)))
{
ModCore.log("Right clicked!");
return this.rightClicked(who);
}
@ -246,6 +165,8 @@ namespace Revitalize.Framework.Objects.Furniture
if (justCheckingForActivity)
return true;
ModCore.log("Check for action");
this.pickUpItem(false);
return true;
@ -253,16 +174,36 @@ namespace Revitalize.Framework.Objects.Furniture
//return false;
}
public override bool performToolAction(Tool t, GameLocation location)
{
ModCore.log("Perform tool action");
return base.performToolAction(t, location);
}
public override bool performUseAction(GameLocation location)
{
ModCore.log("Perform use action");
return base.performUseAction(location);
}
/// <summary>
/// Gets called when there is no actively held item on the tile.
/// </summary>
/// <param name="who"></param>
/// <returns></returns>
public override bool clicked(Farmer who)
{
ModCore.log("Click a table");
if (this.pickUpItemCheck() == PickUpState.DoNothing) return false;
else
if (this.pickUpItem() == PickUpState.DoNothing) return false;
ModCore.log("Clicked!");
foreach(var v in this.containerObject.objects)
{
return base.clicked(who);
if (v.Value.heldObject.Value != null) ModCore.log("Found a keeper!");
else
{
ModCore.log("Already null!");
}
}
///Not sure.
return base.clicked(who);
//return base.rightClicked(who);
@ -376,7 +317,7 @@ namespace Revitalize.Framework.Objects.Furniture
{
ModCore.ModMonitor.Log(err.ToString());
}
if (this.heldItem != null) SpriteBatchUtilities.Draw(spriteBatch, this, this.heldItem, alpha, -1f);
if (this.heldObject.Value != null) SpriteBatchUtilities.Draw(spriteBatch, this, this.heldObject.Value, alpha, addedDepth);
}
// spriteBatch.Draw(Game1.mouseCursors, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)((double)tileLocation.X * (double)Game1.tileSize + (((double)tileLocation.X * 11.0 + (double)tileLocation.Y * 7.0) % 10.0 - 5.0)) + (float)(Game1.tileSize / 2), (float)((double)tileLocation.Y * (double)Game1.tileSize + (((double)tileLocation.Y * 11.0 + (double)tileLocation.X * 7.0) % 10.0 - 5.0)) + (float)(Game1.tileSize / 2))), new Rectangle?(new Rectangle((int)((double)tileLocation.X * 51.0 + (double)tileLocation.Y * 77.0) % 3 * 16, 128 + this.whichForageCrop * 16, 16, 16)), Color.White, 0.0f, new Vector2(8f, 8f), (float)Game1.pixelZoom, SpriteEffects.None, (float)(((double)tileLocation.Y * (double)Game1.tileSize + (double)(Game1.tileSize / 2) + (((double)tileLocation.Y * 11.0 + (double)tileLocation.X * 7.0) % 10.0 - 5.0)) / 10000.0));

View File

@ -82,8 +82,15 @@ namespace Revitalize.Framework.Objects
if (this.location == null) this.location = Game1.player.currentLocation;
this.TileLocation = new Vector2((int)(x / Game1.tileSize), (int)(y / Game1.tileSize));
/*
return base.placementAction(location, x, y, who);
*/
this.performDropDownAction(who);
location.objects.Add(this.TileLocation, this);
return true;
}
public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber, Color c, bool drawShadow)

View File

@ -39,7 +39,7 @@ namespace Revitalize.Framework.Objects
{
this.objects = new Dictionary<Vector2, StardewValley.Object>();
this.childrenGuids = new Dictionary<Vector2, Guid>();
this.guid = Guid.NewGuid();
}
public MultiTiledObject(BasicItemInformation info)
@ -47,7 +47,7 @@ namespace Revitalize.Framework.Objects
{
this.objects = new Dictionary<Vector2, StardewValley.Object>();
this.childrenGuids = new Dictionary<Vector2, Guid>();
this.guid = Guid.NewGuid();
}
public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation)
@ -55,7 +55,7 @@ namespace Revitalize.Framework.Objects
{
this.objects = new Dictionary<Vector2, StardewValley.Object>();
this.childrenGuids = new Dictionary<Vector2, Guid>();
this.guid = Guid.NewGuid();
}
public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation, Dictionary<Vector2, MultiTiledComponent> ObjectsList)
@ -65,20 +65,25 @@ namespace Revitalize.Framework.Objects
this.childrenGuids = new Dictionary<Vector2, Guid>();
foreach (var v in ObjectsList)
{
ModCore.log("Original GUID: "+(v.Value as CustomObject).guid);
MultiTiledComponent component =(MultiTiledComponent) v.Value.getOne();
this.addComponent(v.Key, (component as MultiTiledComponent));
ModCore.log("Altered GUID: " + component.guid);
this.addComponent(v.Key, component);
}
this.guid = Guid.NewGuid();
}
public bool addComponent(Vector2 key, MultiTiledComponent obj)
{
if (this.objects.ContainsKey(key))
{
ModCore.log("Bad DATA");
return false;
}
this.objects.Add(key, obj);
this.childrenGuids.Add(key, Guid.NewGuid());
this.childrenGuids.Add(key, new Guid());
if (key.X > this.width) this.width = (int)key.X;
if (key.Y > this.height) this.height = (int)key.Y;
@ -205,7 +210,7 @@ namespace Revitalize.Framework.Objects
{
pair.Value.placementAction(location, x + (int)pair.Key.X * Game1.tileSize, y + (int)pair.Key.Y * Game1.tileSize, who);
}*/
pair.Value.placementAction(location, x + (int)pair.Key.X * Game1.tileSize, y + (int)pair.Key.Y * Game1.tileSize, who);
(pair.Value as MultiTiledComponent).placementAction(location, x + (int)pair.Key.X * Game1.tileSize, y + (int)pair.Key.Y * Game1.tileSize, who);
//ModCore.log(pair.Value.TileLocation);
}
this.location = location;

View File

@ -32,11 +32,12 @@ namespace Revitalize.Framework.Utilities.Serialization
spriteBatch1.Draw(shadowTexture, position, sourceRectangle, color, 0.0f, origin, 4f, SpriteEffects.None, (float)num);
spriteBatch.Draw(Game1.objectSpriteSheet, Game1.GlobalToLocal(Game1.viewport, obj.TileLocation*Game1.tileSize), Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet,itemToDraw.ParentSheetIndex,16,16), Color.White * alpha, 0.0f, Vector2.Zero, 4f, SpriteEffects.None, ((float)(obj.boundingBox.Bottom + 1) / 10000f)+ addedDepth);
(itemToDraw as StardewValley.Object).draw(spriteBatch, (int)obj.TileLocation.X, (int)obj.TileLocation.Y);
(itemToDraw as StardewValley.Object).draw(spriteBatch, (int)obj.TileLocation.X*Game1.tileSize, (int)obj.TileLocation.Y*Game1.tileSize, Math.Max(0f, (float)(((obj.TileLocation.Y+1) + addedDepth) * Game1.tileSize) / 10000f) + .0001f, alpha);
}
if (ModCore.Serializer.IsSameOrSubclass(typeof(CustomObject),itemToDraw.GetType()))
{
(itemToDraw as CustomObject).draw(spriteBatch,(int)obj.TileLocation.X, (int)obj.TileLocation.Y);
//(itemToDraw as CustomObject).draw(spriteBatch, (int)obj.TileLocation.X*Game1.tileSize, (int)obj.TileLocation.Y*Game1.tileSize,addedDepth,alpha);
}
}

View File

@ -12,6 +12,7 @@ using Revitalize.Framework.Graphics;
using Revitalize.Framework.Graphics.Animations;
using Revitalize.Framework.Illuminate;
using Revitalize.Framework.Objects;
using Revitalize.Framework.Objects.Furniture;
using Revitalize.Framework.Player;
using Revitalize.Framework.Utilities;
using StardewModdingAPI;
@ -25,7 +26,8 @@ namespace Revitalize
// -Chair tops cut off objects
// -ignoring bounding box cuts off objects
// -Tables don't draw their held objects
// -load content MUST be enabled for the table to be placed?????? WTF
// -multitiledobject cs 213 in placementAction must have special logic so that new components aren't being placed
// TODO:
//
//
@ -155,21 +157,24 @@ namespace Revitalize
{
Serializer.returnToTitle();
}
/// <summary>
/// Must be enabled for the tabled to be placed????
/// </summary>
private void loadContent()
{
MultiTiledComponent obj = new MultiTiledComponent(new BasicItemInformation("CoreObjectTest", "YAY FUN!", "Omegasis.Revitalize.MultiTiledComponent", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.TEST1", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Chair").texture, Color.White, 0, true, typeof(MultiTiledComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Chair"), new Animation(new Rectangle(0, 0, 16, 16))), Color.Red, true, null, null));
MultiTiledComponent obj2 = new MultiTiledComponent(new BasicItemInformation("CoreObjectTest2", "SomeFun", "Omegasis.Revitalize.MultiTiledComponent", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.TEST1", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Chair").texture, Color.White, 0, true, typeof(MultiTiledComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Chair"), new Animation(new Rectangle(0, 16, 16, 16))), Color.Red, false, null, null));
MultiTiledComponent obj3 = new MultiTiledComponent(new BasicItemInformation("CoreObjectTest3", "NoFun", "Omegasis.Revitalize.MultiTiledComponent", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.TEST1", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Chair").texture, Color.White, 0, true, typeof(MultiTiledComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Chair"), new Animation(new Rectangle(0, 32, 16, 16))), Color.Red, false, null, null));
obj.info.lightManager.addLight(new Vector2(Game1.tileSize), new LightSource(4, new Vector2(0, 0), 2.5f, Color.Orange.Invert()), obj);
//obj.info.lightManager.addLight(new Vector2(Game1.tileSize), new LightSource(4, new Vector2(0, 0), 2.5f, Color.Orange.Invert()), obj);
MultiTiledObject bigObject = new MultiTiledObject(new BasicItemInformation("MultiTest", "A really big object", "Omegasis.Revitalize.MultiTiledObject", Color.Blue, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.BigTiledTest", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Chair").texture, Color.White, 0, true, typeof(MultiTiledObject), null, new AnimationManager(), Color.White, false, null, null));
bigObject.addComponent(new Vector2(0, 0), obj);
bigObject.addComponent(new Vector2(1, 0), obj2);
bigObject.addComponent(new Vector2(2, 0), obj3);
//bigObject.addComponent(new Vector2(0, 0), obj);
//bigObject.addComponent(new Vector2(1, 0), obj2);
//bigObject.addComponent(new Vector2(2, 0), obj3);
Recipe pie = new Recipe(new Dictionary<Item, int>()
{
[bigObject] = 1
@ -177,7 +182,7 @@ namespace Revitalize
customObjects.Add("Omegasis.BigTiledTest", bigObject);
Framework.Objects.Furniture.RugTileComponent rug1 = new Framework.Objects.Furniture.RugTileComponent(new BasicItemInformation("BasicRugTile", "A basic rug", "Rug", Color.Brown, -300, 0, false, 100, new Vector2(0, 0), true, true, "Omegasis.Revitalize.Furniture.Basic.Rugs.TestRug", generatePlaceholderString(), TextureManager.TextureManagers["Furniture"].getTexture("Oak Chair").texture, Color.White, 0,true, typeof(Framework.Objects.Furniture.RugTileComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Chair"), new Animation(new Rectangle(0, 0, 16, 16))), Color.White, true, null, null));
Framework.Objects.Furniture.RugMultiTiledObject rug = new Framework.Objects.Furniture.RugMultiTiledObject(new BasicItemInformation("BasicRugTile", "A basic rug", "Rug", Color.Brown, -300, 0, false, 100, new Vector2(0, 0), true, true, "Omegasis.Revitalize.Furniture.Basic.Rugs.TestRug", generatePlaceholderString(), TextureManager.TextureManagers["Furniture"].getTexture("Oak Chair").texture, Color.White, 0, true, typeof(Framework.Objects.Furniture.RugMultiTiledObject), null, new AnimationManager(), Color.White, true, null, null));
rug.addComponent(new Vector2(0, 0), rug1);
@ -227,8 +232,8 @@ namespace Revitalize
throw new Exception("Can't run Revitalize in multiplayer due to lack of current support!");
}
//Game1.player.addItemToInventory(customObjects["Omegasis.BigTiledTest"].getOne());
Game1.player.addItemToInventory(GetObjectFromPool("Omegasis.Revitalize.Furniture.Chairs.OakChair"));
Game1.player.addItemToInventory(GetObjectFromPool("Omegasis.Revitalize.Furniture.Rugs.RugTest"));
//Game1.player.addItemToInventory(GetObjectFromPool("Omegasis.Revitalize.Furniture.Chairs.OakChair"));
//Game1.player.addItemToInventory(GetObjectFromPool("Omegasis.Revitalize.Furniture.Rugs.RugTest"));
Game1.player.addItemToInventory(GetObjectFromPool("Omegasis.Revitalize.Furniture.Tables.OakTable"));
/*
StardewValley.Tools.Axe axe = new StardewValley.Tools.Axe();
@ -243,7 +248,21 @@ namespace Revitalize
{
if (customObjects.ContainsKey(objName))
{
return customObjects[objName];
TableMultiTiledObject old = (TableMultiTiledObject)customObjects[objName];
ModCore.log("Old GUID:" + old.guid);
foreach (var v in old.objects)
{
log("OLD GUID PART: "+(v.Value as TableTileComponent).guid);
}
TableMultiTiledObject i =(TableMultiTiledObject)customObjects[objName].getOne();
foreach (var v in i.objects)
{
log("OLD GUID PART: " + (v.Value as TableTileComponent).guid);
}
ModCore.log("New GUID:" + i.guid);
return i;
}
else
{