Created inventory management for having core objects deal with inventories.
This commit is contained in:
parent
ccdc99ab8e
commit
3fd3723117
|
@ -2,6 +2,7 @@
|
|||
using Microsoft.Xna.Framework.Graphics;
|
||||
using PyTK.CustomElementHandler;
|
||||
using Revitalize.Framework.Graphics.Animations;
|
||||
using Revitalize.Framework.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -31,6 +32,8 @@ namespace Revitalize.Framework.Objects
|
|||
|
||||
public bool ignoreBoundingBox;
|
||||
|
||||
public InventoryManager inventory;
|
||||
|
||||
public BasicItemInformation() : base()
|
||||
{
|
||||
name = "";
|
||||
|
@ -46,9 +49,10 @@ namespace Revitalize.Framework.Objects
|
|||
this.animationManager = null;
|
||||
this.drawPosition = Vector2.Zero;
|
||||
this.drawColor = Color.White;
|
||||
this.inventory = new InventoryManager();
|
||||
}
|
||||
|
||||
public BasicItemInformation(string name, string description, string categoryName, Color categoryColor,int edibility,int fragility,bool isLamp,int price, Vector2 TileLocation,bool canBeSetOutdoors,bool canBeSetIndoors,string id, string data, Texture2D texture, Color color,int tileIndex, bool bigCraftable, Type type, CraftingData craftingData, AnimationManager animationManager,Color DrawColor,bool ignoreBoundingBox):base(id,data,texture,color,tileIndex,bigCraftable,type,craftingData)
|
||||
public BasicItemInformation(string name, string description, string categoryName, Color categoryColor,int edibility,int fragility,bool isLamp,int price, Vector2 TileLocation,bool canBeSetOutdoors,bool canBeSetIndoors,string id, string data, Texture2D texture, Color color,int tileIndex, bool bigCraftable, Type type, CraftingData craftingData, AnimationManager animationManager,Color DrawColor,bool ignoreBoundingBox, InventoryManager Inventory):base(id,data,texture,color,tileIndex,bigCraftable,type,craftingData)
|
||||
{
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
|
@ -88,6 +92,14 @@ namespace Revitalize.Framework.Objects
|
|||
this.ignoreBoundingBox = ignoreBoundingBox;
|
||||
|
||||
recreateDataString();
|
||||
if (Inventory == null)
|
||||
{
|
||||
this.inventory = new InventoryManager();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.inventory = Inventory;
|
||||
}
|
||||
}
|
||||
|
||||
public void recreateDataString()
|
||||
|
|
|
@ -0,0 +1,210 @@
|
|||
using StardewValley;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Revitalize.Framework.Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles dealing with objects.
|
||||
/// </summary>
|
||||
public class InventoryManager
|
||||
{
|
||||
/// <summary>
|
||||
/// How many items the inventory can hold.
|
||||
/// </summary>
|
||||
public int capacity;
|
||||
|
||||
/// <summary>
|
||||
/// The hard uper limit in case of upgrading or resizing.
|
||||
/// </summary>
|
||||
private int maxCapacity;
|
||||
|
||||
/// <summary>
|
||||
/// The hard uper limit for # of items to be held in case of upgrading or resizing.
|
||||
/// </summary>
|
||||
public int MaxCapacity
|
||||
{
|
||||
get
|
||||
{
|
||||
return maxCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// How many items are currently stored in the inventory.
|
||||
/// </summary>
|
||||
public int ItemCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.items.Count;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The actual contents of the inventory.
|
||||
/// </summary>
|
||||
public List<Item> items;
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the inventory is full or not.
|
||||
/// </summary>
|
||||
public bool IsFull
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.ItemCount >= this.capacity;
|
||||
}
|
||||
}
|
||||
|
||||
public InventoryManager()
|
||||
{
|
||||
this.capacity = 0;
|
||||
setMaxLimit(0);
|
||||
this.items = new List<Item>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="items"></param>
|
||||
public InventoryManager(List<Item> items)
|
||||
{
|
||||
this.capacity = Int32.MaxValue;
|
||||
this.setMaxLimit(Int32.MaxValue);
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="capacity"></param>
|
||||
public InventoryManager(int capacity)
|
||||
{
|
||||
this.capacity = capacity;
|
||||
this.maxCapacity = Int32.MaxValue;
|
||||
this.items = new List<Item>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="capacity"></param>
|
||||
/// <param name="MaxCapacity"></param>
|
||||
public InventoryManager(int capacity, int MaxCapacity)
|
||||
{
|
||||
this.capacity = capacity;
|
||||
setMaxLimit(MaxCapacity);
|
||||
this.items = new List<Item>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add the item to the inventory.
|
||||
/// </summary>
|
||||
/// <param name="I"></param>
|
||||
/// <returns></returns>
|
||||
public bool addItem(Item I)
|
||||
{
|
||||
if (IsFull)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach(Item self in this.items)
|
||||
{
|
||||
if (self.canStackWith(I))
|
||||
{
|
||||
self.addToStack(I.Stack);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
this.items.Add(I);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the object IF it exists in the inventory.
|
||||
/// </summary>
|
||||
/// <param name="I"></param>
|
||||
/// <returns></returns>
|
||||
public Item getItem(Item I)
|
||||
{
|
||||
foreach(Item i in this.items)
|
||||
{
|
||||
if (I == i) return I;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the item at the specific index.
|
||||
/// </summary>
|
||||
/// <param name="Index"></param>
|
||||
/// <returns></returns>
|
||||
public Item getItemAtIndex(int Index)
|
||||
{
|
||||
return items[Index];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets only one item from the stack.
|
||||
/// </summary>
|
||||
/// <param name="I"></param>
|
||||
/// <returns></returns>
|
||||
public Item getSingleItemFromStack(Item I)
|
||||
{
|
||||
if (I.Stack == 1)
|
||||
{
|
||||
return I;
|
||||
}
|
||||
else
|
||||
{
|
||||
I.Stack = I.Stack - 1;
|
||||
return I.getOne();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Empty the inventory.
|
||||
/// </summary>
|
||||
public void clear()
|
||||
{
|
||||
this.items.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Empty the inventory.
|
||||
/// </summary>
|
||||
public void empty()
|
||||
{
|
||||
this.clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resize how many items can be held by this object.
|
||||
/// </summary>
|
||||
/// <param name="Amount"></param>
|
||||
public void resizeCapacity(int Amount)
|
||||
{
|
||||
if (this.capacity + Amount < this.maxCapacity)
|
||||
{
|
||||
this.capacity += Amount;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the upper limity of the capacity size for the inventory.
|
||||
/// </summary>
|
||||
/// <param name="amount"></param>
|
||||
public void setMaxLimit(int amount)
|
||||
{
|
||||
this.maxCapacity = amount;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -62,11 +62,11 @@ namespace Revitalize
|
|||
|
||||
private void GameLoop_SaveLoaded(object sender, StardewModdingAPI.Events.SaveLoadedEventArgs e)
|
||||
{
|
||||
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", Game1.objectSpriteSheet,Color.White,0,true,typeof(MultiTiledComponent),null,new AnimationManager(new Texture2DExtended(Game1.objectSpriteSheet),new Animation(new Rectangle(0,0,16,16))),Color.Red,true));
|
||||
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", Game1.objectSpriteSheet, Color.White, 0, true, typeof(MultiTiledComponent), null, new AnimationManager(new Texture2DExtended(Game1.objectSpriteSheet), new Animation(new Rectangle(0, 16, 16, 16))), Color.Red,false));
|
||||
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", Game1.objectSpriteSheet, Color.White, 0, true, typeof(MultiTiledComponent), null, new AnimationManager(new Texture2DExtended(Game1.objectSpriteSheet), new Animation(new Rectangle(0, 32, 16, 16))), Color.Red,false));
|
||||
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", Game1.objectSpriteSheet,Color.White,0,true,typeof(MultiTiledComponent),null,new AnimationManager(new Texture2DExtended(Game1.objectSpriteSheet),new Animation(new Rectangle(0,0,16,16))),Color.Red,true,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", Game1.objectSpriteSheet, Color.White, 0, true, typeof(MultiTiledComponent), null, new AnimationManager(new Texture2DExtended(Game1.objectSpriteSheet), new Animation(new Rectangle(0, 16, 16, 16))), Color.Red,false,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", Game1.objectSpriteSheet, Color.White, 0, true, typeof(MultiTiledComponent), null, new AnimationManager(new Texture2DExtended(Game1.objectSpriteSheet), new Animation(new Rectangle(0, 32, 16, 16))), Color.Red,false,null));
|
||||
|
||||
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", Game1.objectSpriteSheet, Color.White, 0, true, typeof(MultiTiledObject), null, new AnimationManager(), Color.White,false));
|
||||
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", Game1.objectSpriteSheet, Color.White, 0, true, typeof(MultiTiledObject), null, new AnimationManager(), Color.White,false,null));
|
||||
bigObject.addComponent(new Vector2(0, 0), obj);
|
||||
bigObject.addComponent(new Vector2(1, 0), obj2);
|
||||
bigObject.addComponent(new Vector2(2, 0), obj3);
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
<Compile Include="Framework\Objects\CustomObject.cs" />
|
||||
<Compile Include="Framework\Objects\MultiTiledComponent.cs" />
|
||||
<Compile Include="Framework\Objects\MultiTiledObject.cs" />
|
||||
<Compile Include="Framework\Utilities\InventoryManager.cs" />
|
||||
<Compile Include="ModCore.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
|
Loading…
Reference in New Issue