Merge branch 'dev' into eote-ghost-lanterns

This commit is contained in:
Mister_Nebula 2022-03-25 08:36:12 +00:00
commit 87e1878c23
4 changed files with 21 additions and 17 deletions

View File

@ -9,6 +9,8 @@ internal class MoveToCarryMessage : QSBWorldObjectMessage<IQSBItem>
{
public override void OnReceiveRemote()
{
WorldObject.StoreLocation();
var player = QSBPlayerManager.GetPlayer(From);
var itemType = WorldObject.GetItemType();

View File

@ -44,6 +44,8 @@ internal class SocketItemMessage : QSBMessage<(SocketMessageType Type, int Socke
return;
}
qsbItem.StoreLocation();
var player = QSBPlayerManager.GetPlayer(From);
player.HeldItem = qsbItem;

View File

@ -9,4 +9,10 @@ public interface IQSBItem : IWorldObject
void PickUpItem(Transform itemSocket);
void DropItem(Vector3 position, Vector3 normal, Sector sector);
void OnCompleteUnsocket();
/// <summary>
/// store the last location when a remote player picks up/unsockets an item
/// so we can drop/socket it if they leave while still holding it
/// </summary>
void StoreLocation();
}

View File

@ -29,11 +29,7 @@ public class QSBItem<T> : WorldObject<T>, IQSBItem
public override void OnRemoval() => QSBPlayerManager.OnRemovePlayer -= OnPlayerLeave;
/// <summary>
/// store the last location when a remote player picks up an item
/// so we can use it if they leave while still holding it
/// </summary>
private void StoreLocation()
public void StoreLocation()
{
_lastParent = AttachedObject.transform.parent;
_lastPosition = AttachedObject.transform.localPosition;
@ -62,15 +58,16 @@ public class QSBItem<T> : WorldObject<T>, IQSBItem
if (_lastSocket != null)
{
QSBPatch.RemoteCall(() => _lastSocket.PlaceIntoSocket(this));
return;
}
AttachedObject.transform.parent = _lastParent;
AttachedObject.transform.localPosition = _lastPosition;
AttachedObject.transform.localRotation = _lastRotation;
AttachedObject.transform.localScale = Vector3.one;
AttachedObject.SetSector(_lastSector?.AttachedObject);
AttachedObject.SetColliderActivation(true);
else
{
AttachedObject.transform.parent = _lastParent;
AttachedObject.transform.localPosition = _lastPosition;
AttachedObject.transform.localRotation = _lastRotation;
AttachedObject.transform.localScale = Vector3.one;
AttachedObject.SetSector(_lastSector?.AttachedObject);
AttachedObject.SetColliderActivation(true);
}
}
public override void SendInitialState(uint to)
@ -80,11 +77,8 @@ public class QSBItem<T> : WorldObject<T>, IQSBItem
public ItemType GetItemType() => AttachedObject.GetItemType();
public void PickUpItem(Transform holdTransform)
{
StoreLocation();
public void PickUpItem(Transform holdTransform) =>
QSBPatch.RemoteCall(() => AttachedObject.PickUpItem(holdTransform));
}
public void DropItem(Vector3 position, Vector3 normal, Sector sector) =>
QSBPatch.RemoteCall(() => AttachedObject.DropItem(position, normal, sector.transform, sector, null));