예제 #1
0
    private void SetItemQuantityUI()
    {
        //Check if the Slot item is an inventory item
        if (SlotItem is InventoryItem inventoryItem)
        {
            //If the inventory has the item
            if (inventory.HasItem(inventoryItem))
            {
                //Get the total quantity of the inventory item in the inventory
                int quantity = inventory.GetTotalQuantity(inventoryItem);

                //Set the quantity text to the quantity, leave empty if quantity is 1
                itemQuantityText.text = quantity > 1 ? quantity.ToString() : "";
            }
            else
            {
                //Set the SlotItem to null
                SlotItem = null;
            }
        }
        else
        {
            //Disable the quantity text
            itemQuantityText.enabled = false;
        }
    }
예제 #2
0
    public override void OnDrop(PointerEventData eventData)
    {
        ItemDragHandler itemDragHandler = eventData.pointerDrag.GetComponent <ItemDragHandler>();

        if (itemDragHandler == null)
        {
            return;
        }

        InventorySlot inventorySlot = itemDragHandler.ItemSlotUI as InventorySlot;

        if (inventorySlot != null)
        {
            SlotItem = inventorySlot.ItemSlot.item;
            return;
        }
        HotbarSlot hotbarSlot = itemDragHandler.ItemSlotUI as HotbarSlot;

        if (hotbarSlot != null)
        {
            HotbarItem oldItem = SlotItem;
            SlotItem            = hotbarSlot.SlotItem;
            hotbarSlot.SlotItem = oldItem;
            return;
        }
    }
 /// <summary>
 /// Recreates the hotbar with new items.
 /// </summary>
 /// <param name="items"></param>
 void RecreateHotbar(ICanHotbar[] items)
 {
     ItemsInHotbar = new HotbarItem[ItemsInHotbar.Length];
     foreach (Transform child in gameObject.transform)
     {
         Destroy(child.gameObject);
     }
     if (Player.Inventory.ActiveItem == null)
     {
         Active = null;
     }
     for (int i = 0; i < items.Length; i++)
     {
         ItemsInHotbar[i]             = Instantiate(ItemPrefab, transform).GetComponent <HotbarItem>();
         ItemsInHotbar[i].Hotkey      = i + 1;
         ItemsInHotbar[i].Item        = items[i];
         ItemsInHotbar[i].Icon.sprite = items[i].Icon == null ? items[i].SpriteRenderer.sprite : items[i].Icon;
         ItemsInHotbar[i].Icon.color  = items[i].SpriteRenderer.color;
         ItemsInHotbar[i].Icon.color -= new Color(0, 0, 0, 0.8f);
         if (Player.Inventory.ActiveItem == (Item)items[i])
         {
             SetActiveItem(ItemsInHotbar[i]);
         }
     }
 }
예제 #4
0
 public bool AddItem(HotbarItem itemToAdd)
 {
     if (slotItem != null)
     {
         return(false);
     }
     SlotItem = itemToAdd;
     return(true);
 }
예제 #5
0
 public bool AddItem(EquipmentItem itemToAdd)
 {
     if (SlotItem != null)
     {
         return(false);
     }
     SlotItem = itemToAdd;
     return(true);
 }
예제 #6
0
 public void Add(HotbarItem itemToAdd)
 {
     foreach (HotbarSlot hotbarSlot in hotbarSlots)
     {
         if (hotbarSlot.AddItem(itemToAdd))
         {
             return;
         }
     }
 }
예제 #7
0
    public void DisplayInfo(HotbarItem infoItem)
    {
        StringBuilder builder = new StringBuilder();

        builder.Append("<size=35>").Append(infoItem.ColouredName).Append("</size>\n");
        builder.Append(infoItem.GetInfoDisplayText());

        infoText.text = builder.ToString();

        popupCanvasObject.SetActive(true);

        LayoutRebuilder.ForceRebuildLayoutImmediate(popupObject);
    }
예제 #8
0
    private bool hotbarDisabled = false;    //is the hotbar disabled

    public void Add(HotbarItem itemToAdd)
    {
        //Loop through all hotbar items
        foreach (HotbarSlot hotbarSlot in hotbarSlots)
        {
            //If successsfully add the item to the slot
            if (hotbarSlot.AddItem(itemToAdd))
            {
                //Exit the loop
                return;
            }
        }
    }
 /// <summary>
 /// Sets active item
 /// </summary>
 /// <param name="item">Item that will be set as active</param>
 void SetActiveItem(HotbarItem item)
 {
     if (Active != null)
     {
         Active.Icon.color -= new Color(0, 0, 0, 0.8f);
     }
     Active           = item;
     item.Icon.color += new Color(0, 0, 0, 0.8f);
     if (item.Item is Item _item)
     {
         Player.Inventory.ActiveItem = _item;
     }
 }
예제 #10
0
    public bool AddItem(HotbarItem itemToAdd)
    {
        //If there is an item in the slot
        if (SlotItem != null)
        {
            //Don't addd the item and exit the function
            return(false);
        }

        //Set the slot item to be the item to add
        SlotItem = itemToAdd;

        //Item was added
        return(true);
    }
예제 #11
0
        public void DisplayInfo(HotbarItem infoItem)
        {
            //Create a string builder instance.
            StringBuilder builder = new StringBuilder();

            //Get the item's custom display text.
            builder.Append("<size=35>").Append(infoItem.ColouredName).Append("</size>\n");
            builder.Append(infoItem.GetInfoDisplayText());

            //Set info text to be displayed.
            infoText.text = builder.ToString();

            //Activate UI canvas object.
            popupCanvasObject.SetActive(true);

            //Fixes resize problem.
            LayoutRebuilder.ForceRebuildLayoutImmediate(popupObject);
        }
예제 #12
0
    public void TryEquipItem(EquipSlot equipSlot, HotbarItem item, bool isLoadingfromSave)
    {
        if (equipSlot == item.GetEquipSlot())
        {
            // Item matches this EquipSlot
            switch (equipSlot)
            {
            default:
            case EquipSlot.Chest: SetChestItem(item); break;

            case EquipSlot.Head: SetHeadItem(item); break;

            case EquipSlot.Legs: SetLegsItem(item); break;

            case EquipSlot.Weapon: SetWeaponItem(item, isLoadingfromSave); break;
            }
        }
    }
예제 #13
0
    public override void OnDrop(PointerEventData eventData)
    {
        //Get the item drag handler
        ItemDragHandler itemDragHandler = eventData.pointerDrag.GetComponent <ItemDragHandler>();

        //If the item drag handler is null
        if (itemDragHandler == null)
        {
            //Ignore the rest of the function
            return;
        }

        //Check if the item you dropped is an inventory item
        InventorySlot inventorySlot = itemDragHandler.ItemSlotUI as InventorySlot;

        //If the item is an inventory slot
        if (inventorySlot != null)
        {
            //Set the slot item to be the inventory item
            SlotItem = inventorySlot.ItemSlot.inventoryItem;

            //Exit the function
            return;
        }

        //Check if the item you dropped is a Hotbar item
        HotbarSlot hotbarSlot = itemDragHandler.ItemSlotUI as HotbarSlot;

        //If the item is a hotbar slot
        if (hotbarSlot != null)
        {
            //Store the old item
            HotbarItem oldItem = SlotItem;

            //Set the slot as the new item
            SlotItem = hotbarSlot.SlotItem;

            //Set the hotbar slot item to the old item
            hotbarSlot.SlotItem = oldItem;

            //Exit the function
            return;
        }
    }
예제 #14
0
 private void SetItemQuantityUI()
 {
     if (slotItem is InventoryItem inventoryItem)
     {
         if (inventory.ItemContainer.HasItem(inventoryItem))
         {
             int quantityCount = inventory.ItemContainer.GetTotalQuantity(inventoryItem);
             itemQuantityText.text = quantityCount > 1 ? quantityCount.ToString() : "";
         }
         else
         {
             SlotItem = null;
         }
     }
     else
     {
         itemQuantityText.enabled = false;
     }
 }
예제 #15
0
    //Function to display info based on the hotbar item
    public void DisplayInfo(HotbarItem infoItem)
    {
        //Create a new string builder
        StringBuilder builder = new StringBuilder();

        //Get the colored text of the item
        builder.Append("<size=35>").Append(infoItem.ColouredName).Append("</size>\n");

        //Get the display text from the item
        builder.Append(infoItem.GetInfoDisplayText());

        //Set the text based on the built text
        infoText.text = builder.ToString();

        //Activate the popup object
        popupCanvasObject.SetActive(true);

        //Rebuild the layout of the window
        LayoutRebuilder.ForceRebuildLayoutImmediate(popupObject);
    }
예제 #16
0
 public void UseSlot(int index)
 {
     Debug.Log(SlotIndex);
     if (index != SlotIndex)
     {
         Debug.Log("Can't find inventory slot"); return;
     }
     //Use Item
     // When key is pressed, loop through inventory slots
     if (slotItem is InventoryItem inventoryItem && slotItem is ConsumableItem consumableItem)
     {
         if (inventory.ItemContainer.HasItem(inventoryItem))
         {
             inventory.ItemContainer.UseItem(inventoryItem);
             consumableItem.Use();
         }
         else
         {
             SlotItem = null;
         }
     }
 }
예제 #17
0
    public override void OnDrop(PointerEventData eventData)
    {
        ItemDragHandler itemDragHandler = eventData.pointerDrag.GetComponent <ItemDragHandler>();

        if (itemDragHandler == null)
        {
            return;  Debug.Log("No inventory detected");
        }

        InventorySlot inventorySlot = itemDragHandler.ItemSlotUI as InventorySlot;

        if (inventorySlot != null && inventorySlot.SlotItem.IsEquipment == true)
        {
            SlotItem = inventorySlot.ItemSlot.item;
            return;
        }
        EquipmentSlot equipmentSlot = itemDragHandler.ItemSlotUI as EquipmentSlot;

        if ((itemDragHandler.ItemSlotUI as EquipmentSlot) != null)
        {
            Debug.Log("first Swapping Initiated");
            inventory.ItemContainer.Swap(itemDragHandler.ItemSlotUI.SlotIndex, SlotIndex);
        }
        if (equipmentSlot == null)
        {
            Debug.Log("second Swapping Initiated");
            inventory.ItemContainer.Swap(itemDragHandler.ItemSlotUI.SlotIndex, SlotIndex);
            return;
        }

        /*
         * EquipmentSlot equipmentSlot = itemDragHandler.ItemSlotUI as EquipmentSlot;
         * if (inventorySlot != null)
         * {
         *  // Swapping
         *  return;
         * } */
    }
예제 #18
0
    private void SetWeaponItem(HotbarItem weaponItem, bool isLoadingfromSave)
    {
        this.weaponItem = weaponItem;
        //Debug.Log("Weapon Slot: Currently Equiped " + weaponItem.name);

        if (LoadedWeapon)
        {
            PhotonNetwork.Destroy(LoadedWeapon);
        }

        if (isLoadingfromSave)
        {
            ItemContainerSaveData savedSlots = ItemSaveIO.LoadItems("Inventory");
            if (savedSlots.SavedSlots[17] != null)
            {
                CurrentPlayer = PhotonNetwork.LocalPlayer.TagObject as GameObject;
                LoadedWeapon  = PhotonNetwork.Instantiate((Path.Combine("PhotonPrefabs/Items", savedSlots.SavedSlots[17].ItemID)), Vector3.up, Quaternion.identity) as GameObject;
                LoadedWeapon.transform.position = CurrentPlayer.transform.GetChild(1).GetChild(0).position;
                LoadedWeapon.transform.rotation = CurrentPlayer.transform.GetChild(1).GetChild(0).rotation;

                // if(PV.IsMine)
                //     PV.RPC("TransformLoadedWeapon", RpcTarget.All);
                TransformLoadedWeapon();
                //LoadedWeapon.transform.SetParent(CurrentPlayer.transform.GetChild(1).GetChild(0));
                //LoadedWeapon.transform.parent = CurrentPlayer.transform.GetChild(1).GetChild(0);

                LoadedWeapon.GetComponent <WeaponStats>().item_value    = savedSlots.SavedSlots[17].itemData.item_value;
                LoadedWeapon.GetComponent <WeaponStats>().attack        = savedSlots.SavedSlots[17].itemData.attack;
                LoadedWeapon.GetComponent <WeaponStats>().attack_speed  = savedSlots.SavedSlots[17].itemData.attack_speed;
                LoadedWeapon.GetComponent <WeaponStats>().crit_chance   = savedSlots.SavedSlots[17].itemData.crit_chance;
                LoadedWeapon.GetComponent <WeaponStats>().bleed_chance  = savedSlots.SavedSlots[17].itemData.bleed_chance;
                LoadedWeapon.GetComponent <WeaponStats>().range         = savedSlots.SavedSlots[17].itemData.range;
                LoadedWeapon.GetComponent <WeaponStats>().defense       = savedSlots.SavedSlots[17].itemData.defense;
                LoadedWeapon.GetComponent <WeaponStats>().magic_defense = savedSlots.SavedSlots[17].itemData.magic_defense;
                LoadedWeapon.GetComponent <WeaponStats>().move_speed    = savedSlots.SavedSlots[17].itemData.move_speed;
                LoadedWeapon.GetComponent <WeaponStats>().item_type     = savedSlots.SavedSlots[17].itemData.item_type;
            }
        }
        else
        {
            CurrentPlayer = PhotonNetwork.LocalPlayer.TagObject as GameObject;
            LoadedWeapon  = PhotonNetwork.Instantiate((Path.Combine("PhotonPrefabs/Items", weaponItem.Name)), Vector3.up, Quaternion.identity) as GameObject;
            LoadedWeapon.transform.position = CurrentPlayer.transform.GetChild(1).GetChild(0).position;
            LoadedWeapon.transform.rotation = CurrentPlayer.transform.GetChild(1).GetChild(0).rotation;

            // if(PV.IsMine)
            //     PV.RPC("TransformLoadedWeapon", RpcTarget.All); // RpcTarget.all
            TransformLoadedWeapon();
            //LoadedWeapon.transform.SetParent(CurrentPlayer.transform.GetChild(1).GetChild(0));
            //LoadedWeapon.transform.parent = CurrentPlayer.transform.GetChild(1).GetChild(0);

            equipmentItem = playerInventory.ItemContainer.itemSlots[17].item as EquipmentItem;

            LoadedWeapon.GetComponent <WeaponStats>().item_value    = (playerInventory.ItemContainer.itemSlots[17].item as EquipmentItem).itemData.item_value;
            LoadedWeapon.GetComponent <WeaponStats>().attack        = (playerInventory.ItemContainer.itemSlots[17].item as EquipmentItem).itemData.attack;
            LoadedWeapon.GetComponent <WeaponStats>().attack_speed  = (playerInventory.ItemContainer.itemSlots[17].item as EquipmentItem).itemData.attack_speed;
            LoadedWeapon.GetComponent <WeaponStats>().crit_chance   = (playerInventory.ItemContainer.itemSlots[17].item as EquipmentItem).itemData.crit_chance;
            LoadedWeapon.GetComponent <WeaponStats>().bleed_chance  = (playerInventory.ItemContainer.itemSlots[17].item as EquipmentItem).itemData.bleed_chance;
            LoadedWeapon.GetComponent <WeaponStats>().range         = (playerInventory.ItemContainer.itemSlots[17].item as EquipmentItem).itemData.range;
            LoadedWeapon.GetComponent <WeaponStats>().defense       = (playerInventory.ItemContainer.itemSlots[17].item as EquipmentItem).itemData.defense;
            LoadedWeapon.GetComponent <WeaponStats>().magic_defense = (playerInventory.ItemContainer.itemSlots[17].item as EquipmentItem).itemData.magic_defense;
            LoadedWeapon.GetComponent <WeaponStats>().move_speed    = (playerInventory.ItemContainer.itemSlots[17].item as EquipmentItem).itemData.move_speed;
            LoadedWeapon.GetComponent <WeaponStats>().item_type     = (playerInventory.ItemContainer.itemSlots[17].item as EquipmentItem).itemData.item_type;
        }

        //LoadIntoHand(weaponItem, isLoadingfromSave);
    }
예제 #19
0
 public void DisplayScannerIcon(HotbarItem hotbarItem)
 {
     //Set the scanner image sprite to be the scanner icon
     scannerImage.sprite = hotbarItem.ScannerIcon;
 }
예제 #20
0
 private void SetLegsItem(HotbarItem legsItem)
 {
     this.legsItem = legsItem;
 }
예제 #21
0
 private void SetChestItem(HotbarItem chestItem)
 {
     this.chestItem = chestItem;
 }
예제 #22
0
 private void SetHeadItem(HotbarItem headItem)
 {
     this.headItem = headItem;
 }
예제 #23
0
    public override void OnDrop(PointerEventData eventData)
    {
        ItemDragHandler itemDragHandler = eventData.pointerDrag.GetComponent <ItemDragHandler>();

        if (itemDragHandler == null)
        {
            return;
        }

        InventorySlot inventorySlot = itemDragHandler.ItemSlotUI as InventorySlot;

        // If item is an equipment
        if (inventorySlot != null && inventorySlot.SlotItem.IsEquipment == true)
        {
            // Check if inventory slot is a chest slot and the item dropped is also a chest slot.
            if (inventorySlotType == InventorySlotType.Chest && inventorySlot.SlotItem.equipmentType == HotbarItem.EquipmentType.Chest)
            {
                Debug.Log("Testing chest slot");
                slotItem = inventorySlot.ItemSlot.item;
                OnItemDropped?.Invoke(this, new OnItemDroppedEventArgs {
                    item = slotItem
                });
                inventory.ItemContainer.SwapEquip(itemDragHandler.ItemSlotUI.SlotIndex, SlotIndex);
                Debug.Log(slotItem.name);
                return;
            }
            // Check if inventory slot is a Head slot and the item dropped is also a Head slot.
            else if (inventorySlotType == InventorySlotType.Head && inventorySlot.SlotItem.equipmentType == HotbarItem.EquipmentType.Head)
            {
                slotItem = inventorySlot.ItemSlot.item;
                OnItemDropped?.Invoke(this, new OnItemDroppedEventArgs {
                    item = slotItem
                });
                inventory.ItemContainer.SwapEquip(itemDragHandler.ItemSlotUI.SlotIndex, SlotIndex);
                Debug.Log(slotItem.name);
                return;
            }
            // Check if inventory slot is a legs slot and the item dropped is also a legs slot.
            else if (inventorySlotType == InventorySlotType.Legs && inventorySlot.SlotItem.equipmentType == HotbarItem.EquipmentType.Legs)
            {
                slotItem = inventorySlot.ItemSlot.item;
                OnItemDropped?.Invoke(this, new OnItemDroppedEventArgs {
                    item = slotItem
                });
                inventory.ItemContainer.SwapEquip(itemDragHandler.ItemSlotUI.SlotIndex, SlotIndex);
                Debug.Log(slotItem.name);
                return;
            }
            // Check if inventory slot is a weapon slot and the item dropped is also a weapon slot.
            else if (inventorySlotType == InventorySlotType.Weapon && inventorySlot.SlotItem.equipmentType == HotbarItem.EquipmentType.Weapon)
            {
                slotItem = inventorySlot.ItemSlot.item;
                OnItemDropped?.Invoke(this, new OnItemDroppedEventArgs {
                    item = slotItem
                });
                inventory.ItemContainer.SwapEquip(itemDragHandler.ItemSlotUI.SlotIndex, SlotIndex);
                Debug.Log(slotItem.name);
                return;
            }
            else if (inventorySlotType == InventorySlotType.Inventory)
            {
                Debug.Log("Inventory slot: inventory");
                inventory.ItemContainer.SwapEquip(itemDragHandler.ItemSlotUI.SlotIndex, SlotIndex);
                //inventory.playerEquipment.removeDisplayedEquipment();
                return;
            }
            else
            {
                return;
            }

            //return;
        }
        if ((itemDragHandler.ItemSlotUI as InventorySlot) != null & !CheckIfEquipmentSlot(inventorySlotType))
        {
            inventory.ItemContainer.Swap(itemDragHandler.ItemSlotUI.SlotIndex, SlotIndex);
            //return;
        }

        // If inventory slot && item is Equipment
        // if: Compare Head
        // Do something
        // if: Compare Chest
        // Do Something
        // if: Compare Legs
        // Do something
        // if: Compare Weapon
        // Do Something
    }