70 lines
2.0 KiB
C#
Raw Normal View History

2021-02-26 09:04:22 +00:00
using OWML.Common;
using OWML.Utils;
using QSB.Utility;
2021-02-25 14:53:34 +00:00
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 21:24:10 +00:00
protected IQSBOWItem _socketedItem
2021-02-25 14:53:34 +00:00
{
get => ItemManager.GetObject(AttachedObject.GetValue<OWItem>("_socketedItem"));
2021-02-25 21:24:10 +00:00
set => AttachedObject.SetValue("_socketedItem", (value as IWorldObject)?.ReturnObject());
}
private IQSBOWItem _removedItem
{
get => ItemManager.GetObject(AttachedObject.GetValue<OWItem>("_removedItem"));
set => AttachedObject.SetValue("_removedItem", (value as IWorldObject).ReturnObject());
2021-02-25 14:53:34 +00:00
}
private Transform _socketTransform
{
2021-02-26 09:04:22 +00:00
get => AttachedObject.GetValue<Transform>("_socketTransform");
set => AttachedObject.SetValue("_socketTransform", value);
2021-02-25 14:53:34 +00:00
}
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)
{
2021-02-25 22:45:32 +00:00
if (!AcceptsItem(item) || _socketedItem != default)
2021-02-25 14:53:34 +00:00
{
2021-02-26 09:04:22 +00:00
DebugLog.ToConsole($"Error - Trying to place item in non-accepting socket, or already occupied socket! Item:{(item as IWorldObject).Name}, socket:{AttachedObject.name}.", MessageType.Error);
2021-02-25 14:53:34 +00:00
return false;
}
_socketedItem = item;
_socketedItem.SocketItem(_socketTransform, _sector);
_socketedItem.PlaySocketAnimation();
AttachedObject.enabled = true;
return true;
}
2021-02-25 21:24:10 +00:00
public virtual IQSBOWItem RemoveFromSocket()
{
_removedItem = _socketedItem;
2021-02-25 22:45:32 +00:00
_socketedItem = default;
2021-02-25 21:24:10 +00:00
_removedItem.PlayUnsocketAnimation();
_removedItem.SetColliderActivation(true);
AttachedObject.enabled = true;
return _removedItem;
}
2021-02-23 14:42:18 +00:00
}
}