public void gainedItem(IDroppableItem item, IItemDropTarget slotTarget) { //See wheter the item has our Component. Accept if it does otherwise return it to it's old Position T inventoryComponent = item.holdingObject.GetComponent <T>(); if (inventoryComponent != null) { //check if this item is a new Item or already registered in the inventory and just changed Slots if (!itemExists(inventoryComponent.GetInstanceID())) { if (item.previousParent != null) { ExecuteEvents.ExecuteHierarchy <IlostItem>(item.previousParent, null, (x, y) => { x.lostItem(item); }); } registerItem(inventoryComponent); addedNewItem(inventoryComponent); } slotTarget.MoveToSlot(item); } else { item.returnToPrevious(); } }
public static bool ItemTool_DropItem(ItemTool __instance, RaycastHit hit, OWRigidbody targetRigidbody, IItemDropTarget customDropTarget) { Locator.GetPlayerAudioController().PlayDropItem(__instance._heldItem.GetItemType()); var hitGameObject = hit.collider.gameObject; var gameObject2 = hitGameObject; var sectorGroup = gameObject2.GetComponent <ISectorGroup>(); Sector sector = null; while (sectorGroup == null && gameObject2.transform.parent != null) { gameObject2 = gameObject2.transform.parent.gameObject; sectorGroup = gameObject2.GetComponent <ISectorGroup>(); } if (sectorGroup != null) { sector = sectorGroup.GetSector(); if (sector == null && sectorGroup is SectorCullGroup sectorCullGroup) { var controllingProxy = sectorCullGroup.GetControllingProxy(); if (controllingProxy != null) { sector = controllingProxy.GetSector(); } } } var parent = (customDropTarget == null) ? targetRigidbody.transform : customDropTarget.GetItemDropTargetTransform(hit.collider.gameObject); var IQSBItem = __instance._heldItem.GetWorldObject <IQSBItem>(); __instance._heldItem.DropItem(hit.point, hit.normal, parent, sector, customDropTarget); __instance._heldItem = null; QSBPlayerManager.LocalPlayer.HeldItem = null; Locator.GetToolModeSwapper().UnequipTool(); var parentSector = parent.GetComponentInChildren <Sector>(); if (parentSector != null) { var localPos = parentSector.transform.InverseTransformPoint(hit.point); IQSBItem.SendMessage(new DropItemMessage(localPos, hit.normal, parentSector)); return(false); } DebugLog.ToConsole($"Error - No sector found for rigidbody {targetRigidbody.name}!.", MessageType.Error); return(false); }