/// <summary> /// General function to try to equip the item in the active hand /// </summary> public void Equip() { // Is the player allowed to interact? (not a ghost) if (!isValidPlayer()) { return; } // Is there an item to equip? if (!CurrentSlot.IsFull) { return; } //This checks which UI slot the item can be equiped to and swaps it there UI_ItemSlot itemSlot = InventorySlotCache.GetSlotByItemType(CurrentSlot.Item); if (itemSlot != null) { // If we couldn't equip item into pocket, let's try the other pocket! if (!SwapItem(itemSlot) && itemSlot.eventName == "storage02") { SwapItem(InventorySlotCache.GetSlotByEvent("storage01")); } } else { Logger.LogError("No slot type was found for this object for auto equip", Category.UI); } }
/// <summary> /// rather direct method that doesn't check anything. /// probably should check if you CanPutItemToSlot before using it /// </summary> public static void UpdateSlot(UISlotObject slotInfo) { if (string.IsNullOrEmpty(slotInfo.SlotUUID) && !string.IsNullOrEmpty(slotInfo.FromSlotUUID)) { //Dropping updates: var _fromSlot = InventorySlotCache.GetSlotByUUID(slotInfo.FromSlotUUID); if (_fromSlot != null) { CheckStorageHandlerOnMove(_fromSlot.Item); _fromSlot.Clear(); return; } } //Logger.LogTraceFormat("Updating slots: {0}", Category.UI, slotInfo); // InputTrigger.Touch(slotInfo.SlotContents); var slot = InventorySlotCache.GetSlotByUUID(slotInfo.SlotUUID); if (slot != null) { slot.SetItem(slotInfo.SlotContents); } var fromSlot = InventorySlotCache.GetSlotByUUID(slotInfo.FromSlotUUID); bool fromS = fromSlot != null; bool fromSI = fromSlot?.Item != null; if (fromSlot && (fromSlot.image.enabled || fromSlot?.Item == slotInfo.SlotContents)) { CheckStorageHandlerOnMove(fromSlot.Item); fromSlot.Clear(); } }
private void PopulateInventorySlots() { if (localSlotCache.Count == storageCache.storageSlots.inventorySlots.Count) { return; } for (int i = 0; i < storageCache.storageSlots.inventorySlots.Count; i++) { GameObject newSlot = Instantiate(inventorySlotPrefab, Vector3.zero, Quaternion.identity); newSlot.transform.parent = transform; newSlot.transform.localScale = Vector3.one; var itemSlot = newSlot.GetComponentInChildren <UI_ItemSlot>(); itemSlot.eventName = "inventory" + i; itemSlot.maxItemSize = storageCache.maxItemSize; itemSlot.inventorySlot = storageCache.storageSlots.inventorySlots[i]; storageCache.storageSlots.inventorySlots[i].SlotName = itemSlot.eventName; localSlotCache.Add(itemSlot); InventorySlotCache.Add(itemSlot); if (itemSlot.Item != null) { itemSlot.SetItem(itemSlot.Item); } } }
public bool Interact(InventoryApply interaction) { if (interaction.TargetObject != gameObject) { //backpack can't be "applied" to something else in inventory return(false); } if (interaction.HandObject != null) { //Put item in back without opening it //Check if it is a storage obj: if (storageObj.NextSpareSlot() != null) { UIManager.TryUpdateSlot(new UISlotObject(storageObj.NextSpareSlot().UUID, interaction.HandObject, InventorySlotCache.GetSlotByItem(interaction.HandObject)?.inventorySlot.UUID)); SoundManager.PlayAtPosition("Rustle0" + UnityEngine.Random.Range(1, 6).ToString(), PlayerManager.LocalPlayer.transform.position); ObjectBehaviour itemObj = interaction.HandObject.GetComponent <ObjectBehaviour>(); itemObj.parentContainer = objectBehaviour; } } else { //nothing in hand, just open / close the backpack (note that this means backpack can only be moved in inventory //by dragging and dropping) return(Interact(HandActivate.ByLocalPlayer())); } return(false); }
/// <summary> /// General function to try to equip the item in the active hand /// </summary> public void Equip() { // Is the player allowed to interact? (not a ghost) if (!isValidPlayer()) { return; } // Is there an item to equip? if (!CurrentSlot.IsFull) { return; } //This checks which UI slot the item can be equiped to and swaps it there ItemType type = Slots.GetItemType(CurrentSlot.Item); SpriteType masterType = Slots.GetItemMasterType(CurrentSlot.Item); UI_ItemSlot itemSlot = InventorySlotCache.GetSlotByItemType(CurrentSlot.Item); if (itemSlot != null) { SwapItem(itemSlot); } else { Logger.LogError("No slot type was found for this object for auto equip", Category.UI); } }
public override void UI_InteractOtherSlot(GameObject originator, GameObject item) { if (item != null) { //Put item in back without opening it //Check if it is a storage obj: if (storageObj.NextSpareSlot() != null) { UIManager.TryUpdateSlot(new UISlotObject(storageObj.NextSpareSlot().UUID, item, InventorySlotCache.GetSlotByItem(item)?.inventorySlot.UUID)); SoundManager.PlayAtPosition("Rustle0" + UnityEngine.Random.Range(1, 6).ToString(), PlayerManager.LocalPlayer.transform.position); } } else { if (UIManager.StorageHandler.storageCache != storageObj) { UIManager.StorageHandler.OpenStorageUI(storageObj); } else { UIManager.StorageHandler.CloseStorageUI(); } } }
public static void ClientEquipInInvSlot(PlayerNetworkActions pna, GameObject item, EquipSlot equipSlot) { var inventorySlot = pna.Inventory[equipSlot]; inventorySlot.Item = item; var UIitemSlot = InventorySlotCache.GetSlotByEvent(inventorySlot.equipSlot); UIitemSlot.SetItem(item); }
public static void ClientClearInvSlot(PlayerNetworkActions pna, EquipSlot equipSlot) { var inventorySlot = pna.Inventory[equipSlot]; inventorySlot.Item = null; var UIitemSlot = InventorySlotCache.GetSlotByEvent(inventorySlot.equipSlot); UIitemSlot.Clear(); }
public void CloseStorageUI() { storageCache.clientUpdatedDelegate -= StorageUpdatedEvent; storageCache = null; for (int i = localSlotCache.Count - 1; i >= 0; i--) { InventorySlotCache.Remove(localSlotCache[i]); Destroy(localSlotCache[i].transform.parent.gameObject); } localSlotCache.Clear(); }
public void CloseStorageUI() { SoundManager.PlayAtPosition("Rustle0" + UnityEngine.Random.Range(1, 6).ToString(), PlayerManager.LocalPlayer.transform.position); storageCache.clientUpdatedDelegate -= StorageUpdatedEvent; storageCache = null; for (int i = localSlotCache.Count - 1; i >= 0; i--) { InventorySlotCache.Remove(localSlotCache[i]); Destroy(localSlotCache[i].transform.parent.gameObject); } localSlotCache.Clear(); }
public override IEnumerator Process() { yield return(WaitFor(Recipient)); var playerScript = NetworkObject.GetComponent <PlayerScript>(); var SlotsList = JsonUtility.FromJson <SyncPlayerInventoryList>(Data); if (InventoryManager.AllClientInventorySlots == null) { yield break; } InventorySlotCache.SyncGUID(SlotsList); }
public static bool CanPutItemToSlot(UISlotObject proposedSlotInfo) { if (proposedSlotInfo.IsEmpty() || !SendUpdateAllowed(proposedSlotInfo.SlotContents)) { return(false); } InventorySlot invSlot = InventoryManager.GetSlotFromUUID(proposedSlotInfo.SlotUUID, false); PlayerScript lps = PlayerManager.LocalPlayerScript; if (!lps || lps.canNotInteract() || invSlot.Item != null) { return(false); } UI_ItemSlot uiItemSlot = InventorySlotCache.GetSlotByUUID(invSlot.UUID); if (uiItemSlot == null) { //Could it be a storage obj that is closed? ItemSize checkMaxSizeOfStorage; if (SlotIsFromClosedBag(invSlot, out checkMaxSizeOfStorage)) { var itemAtts = proposedSlotInfo.SlotContents.GetComponent <ItemAttributes>(); if (itemAtts != null) { if (itemAtts.size <= checkMaxSizeOfStorage) { return(true); } } } return(false); } if (!uiItemSlot.CheckItemFit(proposedSlotInfo.SlotContents)) { return(false); } return(true); }
public void Use() { if (PlayerManager.LocalPlayerScript != null) { if (!PlayerManager.LocalPlayerScript.playerMove.allowInput || PlayerManager.LocalPlayerScript.playerMove.isGhost) { return; } } if (!CurrentSlot.IsFull) { return; } //Is the item edible? if (CheckEdible()) { return; } //This checks which UI slot the item can be equiped too and swaps it there ItemType type = Slots.GetItemType(CurrentSlot.Item); SpriteType masterType = Slots.GetItemMasterType(CurrentSlot.Item); switch (masterType) { case SpriteType.Clothing: UI_ItemSlot slot = InventorySlotCache.GetSlotByItemType(CurrentSlot.Item); SwapItem(slot); break; case SpriteType.Items: UI_ItemSlot itemSlot = InventorySlotCache.GetSlotByItemType(CurrentSlot.Item); SwapItem(itemSlot); break; case SpriteType.Guns: break; } }
/// <summary> /// General function to try to equip the item in the active hand /// </summary> public void Equip() { // Is the player allowed to interact? (not a ghost) if (!isValidPlayer()) { return; } // Is there an item to equip? if (CurrentSlot.Item == null) { Logger.Log("!CurrentSlot.IsFull"); return; } //This checks which UI slot the item can be equiped to and swaps it there UI_ItemSlot itemSlot = InventorySlotCache.GetSlotByItemType(CurrentSlot.Item); if (itemSlot != null) { //Try to equip the item into the appropriate slot if (!SwapItem(itemSlot)) { //If we couldn't equip the item into it's primary slot, try the pockets! if (!SwapItem(InventorySlotCache.GetSlotByEvent(EquipSlot.storage01))) { //We couldn't equip the item in pocket 1. Try pocket2! //This swap fails if both pockets are full, do nothing if fail SwapItem(InventorySlotCache.GetSlotByEvent(EquipSlot.storage02)); } } } else { Logger.LogError("No slot type was found for this object for auto equip", Category.UI); } }
public void Use() { if (PlayerManager.LocalPlayerScript != null) { if (!PlayerManager.LocalPlayerScript.playerMove.allowInput || PlayerManager.LocalPlayerScript.playerMove.isGhost) { return; } } if (!CurrentSlot.IsFull) { return; } //Is the item edible? if (CheckEdible()) { return; } //This checks which UI slot the item can be equiped too and swaps it there ItemType type = Slots.GetItemType(CurrentSlot.Item); SpriteType masterType = Slots.GetItemMasterType(CurrentSlot.Item); UI_ItemSlot itemSlot = InventorySlotCache.GetSlotByItemType(CurrentSlot.Item); if (itemSlot != null) { SwapItem(itemSlot); } else { Logger.LogError("No slot type was found for this object for auto equip", Category.UI); } }
public override void UI_InteractOtherSlot(GameObject originator, GameObject item) { if (item != null) { //Put item in back without opening it //Check if it is a storage obj: if (storageObj.NextSpareSlot() != null) { UIManager.TryUpdateSlot(new UISlotObject(storageObj.NextSpareSlot().UUID, item, InventorySlotCache.GetSlotByItem(item)?.inventorySlot.UUID)); } } else { if (UIManager.StorageHandler.storageCache != storageObj) { UIManager.StorageHandler.OpenStorageUI(storageObj); } else { UIManager.StorageHandler.CloseStorageUI(); } } }