2019-08-23 04:43:11 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
2019-09-12 05:40:22 +08:00
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
using Revitalize.Framework.Objects;
|
2019-08-23 04:43:11 +08:00
|
|
|
|
|
|
|
namespace Revitalize.Framework.Utilities
|
|
|
|
{
|
|
|
|
public class ObjectUtilities
|
|
|
|
{
|
|
|
|
public static bool IsObjectHoldingItem(StardewValley.Object obj)
|
|
|
|
{
|
|
|
|
if (obj.heldObject.Value != null) return true;
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Checks to see if the given object is a SDV vanilla furnace.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="obj"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static bool IsObjectFurnace(StardewValley.Object obj)
|
|
|
|
{
|
|
|
|
if (obj.ParentSheetIndex == 13 && obj.bigCraftable.Value && obj.Category == -9 && obj.Name == "Furnace")
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
2019-09-03 10:02:58 +08:00
|
|
|
public static bool IsSameOrSubclass(Type potentialBase, Type potentialDescendant)
|
|
|
|
{
|
|
|
|
return potentialDescendant.IsSubclassOf(potentialBase)
|
|
|
|
|| potentialDescendant == potentialBase;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool IsSameType(Type potentialBase, Type potentialDescendant)
|
|
|
|
{
|
|
|
|
return potentialDescendant == potentialBase;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool IsSubclass(Type potentialBase, Type potentialDescendant)
|
|
|
|
{
|
|
|
|
return potentialDescendant.IsSubclassOf(potentialBase);
|
|
|
|
}
|
|
|
|
|
2019-09-12 05:40:22 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Gets a dimension offset depending on the size of the object passed in.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="obj"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static Vector2 GetDimensionOffsetFromItem(StardewValley.Object obj)
|
|
|
|
{
|
|
|
|
if (ObjectUtilities.IsSameType(typeof(StardewValley.Object), obj.GetType()))
|
|
|
|
{
|
|
|
|
return new Vector2(64f, 64f);
|
|
|
|
}
|
|
|
|
if (ObjectUtilities.IsSameType(typeof(Revitalize.Framework.Objects.MultiTiledObject), obj.GetType()))
|
|
|
|
{
|
|
|
|
return new Vector2(64f * (obj as MultiTiledObject).Width, 64f * (obj as MultiTiledObject).Height);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Vector2(64f, 64f);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the height of an object.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="obj"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static float GetHeightOffsetFromItem(StardewValley.Object obj)
|
|
|
|
{
|
|
|
|
return GetDimensionOffsetFromItem(obj).Y;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the width of an item.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="obj"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static float GetWidthOffsetFromItem(StardewValley.Object obj)
|
|
|
|
{
|
|
|
|
return GetDimensionOffsetFromItem(obj).X;
|
|
|
|
}
|
2019-08-23 04:43:11 +08:00
|
|
|
}
|
|
|
|
}
|