51 lines
1.3 KiB
C#
Raw Normal View History

2021-02-25 14:53:34 +00:00
using OWML.Utils;
using QSB.WorldSync;
2021-02-23 14:42:18 +00:00
using UnityEngine;
namespace QSB.ItemSync.WorldObjects
{
2021-02-24 10:45:25 +00:00
internal class QSBOWItemSocket<T> : WorldObject<T>, IQSBOWItemSocket
2021-02-23 14:42:18 +00:00
where T : MonoBehaviour
{
2021-02-25 14:53:34 +00:00
private IQSBOWItem _socketedItem
{
get => ItemManager.GetObject(AttachedObject.GetValue<OWItem>("_socketedItem"));
set => AttachedObject.SetValue("_socketedItem", (value as IWorldObject).ReturnObject());
}
private Transform _socketTransform
{
get => AttachedObject.GetValue<Transform>("_socketedTransform");
set => AttachedObject.SetValue("_socketedTransform", value);
}
private Sector _sector
{
get => AttachedObject.GetValue<Sector>("_sector");
set => AttachedObject.SetValue("_sector", value);
}
2021-02-23 14:42:18 +00:00
public override void Init(T attachedObject, int id) { }
2021-02-25 14:53:34 +00:00
public virtual bool AcceptsItem(IQSBOWItem item)
{
var itemType = item.GetItemType();
var acceptableType = AttachedObject.GetValue<ItemType>("_acceptableType");
return (itemType & acceptableType) == itemType;
}
public virtual bool PlaceIntoSocket(IQSBOWItem item)
{
if (!AcceptsItem(item) || _socketedItem != null)
{
return false;
}
_socketedItem = item;
_socketedItem.SocketItem(_socketTransform, _sector);
_socketedItem.PlaySocketAnimation();
AttachedObject.enabled = true;
return true;
}
2021-02-23 14:42:18 +00:00
}
}