mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-05 15:39:51 +00:00
add socket stuff
This commit is contained in:
parent
d34eeda44d
commit
506f040b97
@ -6,5 +6,9 @@ namespace QSB.ItemSync.WorldObjects
|
||||
public interface IQSBOWItem : IWorldObjectTypeSubset
|
||||
{
|
||||
void DropItem(Vector3 position, Vector3 normal, Sector sector);
|
||||
|
||||
ItemType GetItemType();
|
||||
void SocketItem(Transform socketTransform, Sector sector);
|
||||
void PlaySocketAnimation();
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,17 @@ namespace QSB.ItemSync.WorldObjects
|
||||
internal class QSBOWItem<T> : WorldObject<T>, IQSBOWItem
|
||||
where T : OWItem
|
||||
{
|
||||
private ItemType _type
|
||||
{
|
||||
get => AttachedObject.GetValue<ItemType>("_type");
|
||||
set => AttachedObject.SetValue("_type", value);
|
||||
}
|
||||
|
||||
public override void Init(T attachedObject, int id) { }
|
||||
|
||||
public ItemType GetItemType()
|
||||
=> _type;
|
||||
|
||||
public virtual void DropItem(Vector3 position, Vector3 normal, Sector sector)
|
||||
{
|
||||
AttachedObject.transform.SetParent(sector.transform);
|
||||
@ -21,5 +30,10 @@ namespace QSB.ItemSync.WorldObjects
|
||||
AttachedObject.SetSector(sector);
|
||||
AttachedObject.SetColliderActivation(true);
|
||||
}
|
||||
|
||||
public virtual void SocketItem(Transform socketTransform, Sector sector)
|
||||
=> AttachedObject.SocketItem(socketTransform, sector);
|
||||
|
||||
public virtual void PlaySocketAnimation() { }
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using QSB.WorldSync;
|
||||
using OWML.Utils;
|
||||
using QSB.WorldSync;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.ItemSync.WorldObjects
|
||||
@ -6,6 +7,44 @@ namespace QSB.ItemSync.WorldObjects
|
||||
internal class QSBOWItemSocket<T> : WorldObject<T>, IQSBOWItemSocket
|
||||
where T : MonoBehaviour
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
public override void Init(T attachedObject, int id) { }
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,5 +6,6 @@
|
||||
string Name { get; }
|
||||
|
||||
void OnRemoval();
|
||||
object ReturnObject();
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using OWML.Common;
|
||||
using QSB.ItemSync.WorldObjects;
|
||||
using QSB.OrbSync.WorldObjects;
|
||||
using QSB.TransformSync;
|
||||
using QSB.Utility;
|
||||
|
@ -11,5 +11,6 @@ namespace QSB.WorldSync
|
||||
|
||||
public abstract void Init(T attachedObject, int id);
|
||||
public virtual void OnRemoval() { }
|
||||
public object ReturnObject() => AttachedObject;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user