Пример #1
0
    private void DropARandomItem()
    {
        var  valueForItemToDrop = UnityEngine.Random.Range(0, 6);
        Item droppedItem        = new Item()
        {
            itemType = Item.ItemType.Weapon, amount = 1
        };

        if (valueForItemToDrop < 3)
        {
            droppedItem = new Item()
            {
                itemType = Item.ItemType.Weapon, amount = 1
            };
        }
        else if (valueForItemToDrop > 2 && valueForItemToDrop < 5)
        {
            droppedItem = new Item()
            {
                itemType = Item.ItemType.ManaPotion, amount = 1
            };
        }
        else if (valueForItemToDrop > 4)
        {
            droppedItem = new Item()
            {
                itemType = Item.ItemType.HealtPotion, amount = 1
            };
        }

        ItemWorld.DropItem(gameObject.transform.position, droppedItem);
    }
Пример #2
0
    private void RefreshInventoryItems()
    {
        foreach (Transform child in itemSlotContainer)
        {
            if (child == itemSlotTemplate)
            {
                continue;
            }
            Destroy(child.gameObject);
        }

        int   x = 0;
        int   y = 0;
        float itemSlotCellSize = 130f;

        foreach (Item item in inventory.GetItemList())
        {
            RectTransform itemSlotRectTransform = Instantiate(itemSlotTemplate, itemSlotContainer).GetComponent <RectTransform>();
            itemSlotRectTransform.gameObject.SetActive(true);

            itemSlotRectTransform.GetComponent <Button_UI>().ClickFunc = () =>
            {
                // Use Item
                inventory.UseItem(item);
            };

            itemSlotRectTransform.GetComponent <Button_UI>().MouseRightClickFunc = () =>
            {
                // Drop item
                Item duplicateItem = new Item {
                    itemType = item.itemType, amount = item.amount
                };
                inventory.RemoveItem(item);
                ItemWorld.DropItem(Player.transform, duplicateItem);
            };

            itemSlotRectTransform.anchoredPosition = new Vector2(x * itemSlotCellSize, y * itemSlotCellSize);
            Image image = itemSlotRectTransform.Find("Icon").GetComponent <Image>();
            image.sprite = item.GetSprite();
            Text uiText = itemSlotRectTransform.Find("amountText").GetComponent <Text>();

            if (item.amount > 1)
            {
                uiText.text = item.amount.ToString();
            }
            else
            {
                uiText.text = "";
            }



            x++;
            if (x > 7)
            {
                x = 0;
                y--;
            }
        }
    }
Пример #3
0
 public void onClick(Item item)
 {
     FindObjectOfType <Sound>().ButtonSound();
     ItemWorld.DropItem(item);
     inventory.RemoveItem(new Item {
         itemType = item.itemType, amount = 1
     });
 }
Пример #4
0
    public void RefreshInventoryItems()
    {
        foreach (UnityEngine.Transform child in itemSlotContainer)
        {
            if (child == itemSlotTemplate)
            {
                continue;
            }
            Destroy(child.gameObject);
        }
        int   x       = -5;
        int   y       = 2;
        float offsetX = 30f;
        float offsetY = 20f;

        float itemSlotCellSize = 60f;

        foreach (Item item in inventory.GetItemList())
        {
            RectTransform itemSlotRectTransform = Instantiate(itemSlotTemplate, itemSlotContainer).GetComponent <RectTransform>();
            itemSlotRectTransform.gameObject.SetActive(true);
            itemSlotRectTransform.GetComponent <TooltipHolder>().item = item;
            itemSlotRectTransform.GetComponent <TooltipHolder>().SetCraft(true);

            itemSlotRectTransform.GetComponent <Button_UI>().MouseRightClickFunc = () =>
            {
                Item duplicateItem = new Item {
                    itemType = item.itemType, amount = item.amount
                };
                inventory.RemoveItem(item);
                ItemWorld.DropItem(player.GetComponent <UnityEngine.Transform>().transform.position, duplicateItem);
            };
            itemSlotRectTransform.anchoredPosition = new Vector2(x * itemSlotCellSize + offsetX, y * itemSlotCellSize + offsetY);
            Image image = itemSlotRectTransform.Find("Image").GetComponent <Image>();
            image.sprite = item.GetSprite();
            TextMeshProUGUI uiText = itemSlotRectTransform.Find("text").GetComponent <TextMeshProUGUI>();
            if (item.amount > 1)
            {
                uiText.SetText(item.amount.ToString());
            }
            else
            {
                uiText.SetText("");
            }

            x++;
            if (x > 4)
            {
                x = -5;
                y--;
            }
        }
    }
Пример #5
0
 public void DropItem()
 {
     foreach (Items item in inventory.GetItemList())
     {
         Items duplicateItem = new Items {
             itemType = item.itemType, iItemAmmount = item.iItemAmmount
         };
         inventory.RemoveItem(item);
         ItemWorld.DropItem(new Vector3(player.transform.position.x + 2,
                                        player.transform.position.y,
                                        player.transform.position.z),
                            duplicateItem);
     }
 }
    private void RefreshInventoryItems()
    {
        foreach (Transform child in itemSlotContainer)
        {
            if (child == itemSlotTemplate)
            {
                continue;
            }

            Destroy(child.gameObject);
        }
        float x = 0;
        float y = 0;
        float itemSlotCellSize = 108f;

        foreach (Item item in inventory.GetItemList())
        {
            RectTransform itemSlotRectTransform = Instantiate(itemSlotTemplate, itemSlotContainer).GetComponent <RectTransform>();
            itemSlotRectTransform.gameObject.SetActive(true);

            itemSlotRectTransform.GetComponent <Button_UI>().ClickFunc = () =>
            {
                //Use Item
                inventory.UseItem(item);
            };
            itemSlotRectTransform.GetComponent <Button_UI>().MouseRightClickFunc = () =>
            {
                //Drop Item
                inventory.RemoveItem(item);
                ItemWorld.DropItem(player.targetPosition.transform, item);

                rightClick = true;
                PlayerMovement.resumeTimer = false;
                if (ActivateFlame.activateFlame == true)
                {
                    PlayerMovement.resumeTimer       = true;
                    PlayerMovement.torchIsStillAlive = false;
                }
                player.targetPosition.tag = "Untagged";
            };
            itemSlotRectTransform.anchoredPosition = new Vector2(x * itemSlotCellSize, y);
            Image image = itemSlotRectTransform.Find("Image").GetComponent <Image>();
            image.sprite = item.GetSprite();
            x++;
            if (item.itemType == Item.ItemType.Torch)
            {
                image.tag = "Torch";
            }
        }
    }
Пример #7
0
    public void RefreshItemsInInventory()
    {
        // Delete slot of dropped item
        foreach (Transform child in itemContainer)
        {
            if (child == itemSlot)
            {
                continue;
            }
            Destroy(child.gameObject);
        }
        //---------------------------

        int   _x = 0; // column
        float _itemSlotCellSize = 100f;

        foreach (Item item in inventory.GetItemList())                                                                 //Create item slot
        {
            RectTransform itemSlotRectTransform = Instantiate(itemSlot, itemContainer).GetComponent <RectTransform>(); // Create an instance of the object
            itemSlotRectTransform.GetComponent <UI_Button>().MouseRightClickFunc = () =>                               // On clicked slot item
            {
                Item _dublicateItem = item.Clone();
                inventory.RemoveItem(item);
                ItemWorld.DropItem(playerController.GetPosition(), _dublicateItem);
            };
            itemSlotRectTransform.anchoredPosition = new Vector2(_x * _itemSlotCellSize, 0); // Set position in UI inventory column
            // Set image for item slot
            Image image = itemSlotRectTransform.Find("spriteOfItem").GetComponent <Image>();
            image.sprite = item.GetSprite();
            //------------------------
            if (item.IsStackable == true)
            {
                // Set count of item
                Text _text = itemSlotRectTransform.Find("countOfItem_Text").GetComponent <Text>();
                if (item.Amount > 1)
                {
                    _text.gameObject.SetActive(true);
                    _text.text = "" + item.Amount;
                }
                //-------------------
            }
            _x++; // spacing for new slot
        }
    }
Пример #8
0
 public void OnPointerUp(PointerEventData eventData)
 {
     foreach (Item obj in ItemDatabase.Instance.itemDatabase)
     {
         if (obj.Sprite == gameObject.transform.GetChild(1).GetComponentInChildren <Image>().sprite)
         {
             Vector3 p = Input.mousePosition;
             p.z = 10;
             Vector3 pos = Camera.main.ScreenToWorldPoint(p);
             player.inventory.RemoveItem(obj);
             if (pos.y < 0)
             {
                 pos.y = 0;
             }
             ItemWorld.DropItem(pos, obj, noiseBar);
             break;
         }
     }
 }
Пример #9
0
    public void UpdateInventoryItems()
    {
        itemSlotContainer = transform.Find("ItemSlotContainer");
        itemSlotTemplate  = itemSlotContainer.Find("ItemSlotTemplate");

        foreach (Transform child in itemSlotContainer)
        {
            if (child == itemSlotTemplate)
            {
                continue;
            }

            Destroy(child.gameObject);
        }

        int   x = 0;
        int   y = 0;
        float itemSlotCellSize = 105f;

        foreach (Item item in inventory.GetItems())
        {
            RectTransform itemSlotRectTransform = Instantiate(itemSlotTemplate, itemSlotContainer).GetComponent <RectTransform>();

            itemSlotRectTransform.gameObject.SetActive(true);
            itemSlotRectTransform.anchoredPosition = new Vector2(x * itemSlotCellSize, y * itemSlotCellSize);

            itemSlotRectTransform.GetComponent <Button_UI>().ClickFunc = () =>
            {
                inventory.UseItem(item);
                inventory.RemoveItem(item);
            };

            itemSlotRectTransform.GetComponent <Button_UI>().MouseRightClickFunc = () =>
            {
                //To have different references
                Item droppedItem = new Item {
                    amount = item.amount, itemType = item.itemType
                };
                inventory.RemoveItem(item);
                ItemWorld.DropItem(player.transform.position, droppedItem);
            };

            Image image = itemSlotRectTransform.Find("Image").GetComponent <Image>();
            image.sprite = item.GetSprite();

            TMP_Text text = itemSlotRectTransform.Find("Amount").GetComponent <TMP_Text>();
            if (item.amount == 1)
            {
                text.SetText("");
            }
            else
            {
                text.SetText(item.amount.ToString());
            }


            x++;
            if (x >= 4)
            {
                x = 0;
                y--;
            }
        }
    }
Пример #10
0
    private void RefreshInventoryItems()
    {
        foreach (Transform child in ItemSlotContainer)
        {
            if (child == ItemSlotTemplate)
            {
                continue;
            }
            Destroy(child.gameObject);
        }
        int   x = 0;
        int   y = 0;
        float itemSlotCellSize = 130f;

        //runs through every item in the inventory
        foreach (Item item in Inventory.GetItemList())
        {
            RectTransform itemSlotRectTransform = Instantiate(ItemSlotTemplate, ItemSlotContainer).GetComponent <RectTransform>();
            itemSlotRectTransform.gameObject.SetActive(true);

            //runs from Button_UI, detects if an item in inventory is left clicked and then runs a function
            itemSlotRectTransform.GetComponent <Button_UI>().ClickFunc = () =>
            {
                //use item
                player.UseItem(item);
            };
            //runs from Button_UI, detects if an item in inventory is right clicked and then runs a function
            //these might need to be further abstracted or ran through another function first for reasons such
            //as attempting to use a potion with full health, eat or drink when the meters are full, etc
            itemSlotRectTransform.GetComponent <Button_UI>().MouseRightClickFunc = () =>
            {
                //drop item
                Item duplicateItem = new Item {
                    itemType = item.itemType, amount = item.amount
                };
                Inventory.RemoveItem(item);
                ItemWorld.DropItem(player.gameObject.transform.position, duplicateItem);
            };

            //sets up image and info to be displayed etc for each item
            itemSlotRectTransform.anchoredPosition = new Vector2(x * itemSlotCellSize, y * itemSlotCellSize);
            Image image          = itemSlotRectTransform.Find("Item").GetComponent <Image>();
            Image textBackground = itemSlotRectTransform.Find("TextBackground").GetComponent <Image>();
            Text  uiText         = itemSlotRectTransform.Find("Text").GetComponent <Text>();
            textBackground.gameObject.SetActive(false);
            image.sprite = item.GetSprite();
            if (item.amount > 1)
            {
                textBackground.gameObject.SetActive(true);
                uiText.text = (item.amount).ToString();
            }
            else
            {
                uiText.text = "";
            }

            x++;
            if (x > 3)
            {
                x = 0;
                y--;
            }
        }
    }
Пример #11
0
    private void RefreshInventoryItems()
    {
        foreach (Transform child in itemSlotContainer)
        {
            if (child == itemSlotTemplate)
            {
                continue;
            }
            else
            {
                Destroy(child.gameObject);
            }
        }

        int   x = 0;
        int   y = 0;
        float itemSlotCellSize = 150f;

        foreach (Items item in inventory.GetItemList())
        {
            RectTransform itemSlotRectTransform = Instantiate(itemSlotTemplate, itemSlotContainer).GetComponent <RectTransform>();
            itemSlotRectTransform.gameObject.SetActive(true);

            itemSlotRectTransform.GetComponent <ClickableObject>().ClickFunc = () => {
                inventory.UseItem(item);
            };

            itemSlotRectTransform.GetComponent <ClickableObject>().MouseRightClickFunc = () => {
                Items duplicateItem = new Items {
                    itemType = item.itemType, iItemAmmount = item.iItemAmmount
                };
                inventory.RemoveItem(item);
                ItemWorld.DropItem(new Vector3(player.transform.position.x + 2,
                                               player.transform.position.y,
                                               player.transform.position.z),
                                   duplicateItem);
            };



            itemSlotRectTransform.anchoredPosition = new Vector2(x * itemSlotCellSize, y * itemSlotCellSize);
            Image image = itemSlotRectTransform.Find("image").GetComponent <Image>();
            image.sprite = item.GetSprite();

            TextMeshProUGUI uiText = itemSlotRectTransform.Find("itemAmmountText").GetComponent <TextMeshProUGUI>();
            if (item.iItemAmmount > 1)
            {
                uiText.SetText(item.iItemAmmount.ToString());
            }
            else
            {
                uiText.SetText("");
            }

            TextMeshProUGUI uiItemName = itemSlotRectTransform.Find("itemName").GetComponent <TextMeshProUGUI>();
            switch (item.itemType)
            {
            default:
            case Items.ItemType.SMG:
                uiItemName.SetText("SMG");
                break;

            case Items.ItemType.Shotgun:
                uiItemName.SetText("Shotgun");
                break;

            case Items.ItemType.Health:
                uiItemName.SetText("Health Potion");
                break;
            }

            x++;
            if (x > 3)
            {
                x = 0;
                y--;
            }
        }
    }
Пример #12
0
    /**
     * Inventory refreshes when an item is picked up
     * Inventory refreshes when an item is dropped
     * Inventory refreshes when an item is used/consumed
     */
    private void RefreshInventoryItems()
    {
        itemSlotContainer = transform.Find("itemSlotContainer");
        itemSlotTemplate  = itemSlotContainer.Find("itemSlotTemplate");

        foreach (Transform child in itemSlotContainer)
        {
            if (child == itemSlotTemplate)
            {
                continue;
            }
            Destroy(child.gameObject);
        }

        itemSlotContainer = transform.Find("itemSlotContainer");
        itemSlotTemplate  = itemSlotContainer.Find("itemSlotTemplate");

        // Space between each item (in inventory)
        int   x = 0;
        int   y = 0;
        float itemSlotCellSize = 100f;

        // Create an item "copy" from template for each item inside the player's inventory
        foreach (Item item in inventory.GetItemList())
        {
            // Create an item "copy" and display it
            RectTransform itemSlotRectTransform = Instantiate(itemSlotTemplate, itemSlotContainer).GetComponent <RectTransform>();
            itemSlotRectTransform.gameObject.SetActive(true);

            // When Mouse Left Click on item in inventory
            itemSlotRectTransform.GetComponent <Button_UI>().ClickFunc = () => {
                // Use item
                inventory.UseItem(item);
            };
            // When Mouse Right Click on item in inventory
            itemSlotRectTransform.GetComponent <Button_UI>().MouseRightClickFunc = () => {
                // Drop item
                Item duplicateItem = new Item {
                    itemType = item.itemType, amount = item.amount
                };
                inventory.RemoveItem(item);
                ItemWorld.DropItem(player.GetPosition(), duplicateItem);
            };

            // Space between each item (in inventory)
            itemSlotRectTransform.anchoredPosition = new Vector2((x * itemSlotCellSize) + 20, (y * itemSlotCellSize) + 50);

            // Get sprite for each item
            Image image = itemSlotRectTransform.Find("image").GetComponent <Image>();
            image.sprite = item.GetSprite();

            // Get amount for each item (if stackle)
            TextMeshProUGUI uiText = itemSlotRectTransform.Find("amountText").GetComponent <TextMeshProUGUI>();
            // If the amount is greater than 1, then display it along with the item
            if (item.amount > 1)
            {
                uiText.SetText(item.amount.ToString());
            }
            else
            {
                uiText.SetText("");
            }

            // Inventory column
            x++;

            // Inventory row
            if (x > 2)
            {
                x = 0;
                y--;
            }
        }
    }
Пример #13
0
    private void RefreshInventoryItems()
    {
        foreach (Transform child in itemSlotContainer)
        {
            if (child == itemSlotTemplate)
            {
                continue;
            }
            Destroy(child.gameObject);
        }
        int   x = 0;
        int   y = 0;
        float itemSlotCellSize = 53.5f;

        foreach (Item item in inventory.GetItemList())
        {
            RectTransform itemSlotRectTransform = Instantiate(itemSlotTemplate, itemSlotContainer).GetComponent <RectTransform>();
            itemSlotRectTransform.name = item.index.ToString() + "_" + item.itemType.ToString() + "_" + item.amount.ToString();
            itemSlotRectTransform.gameObject.SetActive(true);

            /*itemSlotRectTransform.GetComponent<Button_UI>().ClickFunc = () =>
             * {
             *  //use
             * };*/

            itemSlotRectTransform.GetComponent <Button_UI>().MouseRightClickFunc = () =>
            {
                Item None_item = new Item {
                    itemType = Item.ItemType.None, amount = 1, index = -1
                };
                if (item.itemType != None_item.itemType)
                {
                    Debug.Log("Clicked");
                    inventory.RemoveItem(item);
                    ItemWorld.DropItem(player.GetPosition(), item);
                }
                //Debug.Log("Clicked");
                //inventory.RemoveItem(item);
                //ItemWorld.DropItem(player.GetPosition(), item);
            };

            itemSlotRectTransform.anchoredPosition = new Vector2(x * itemSlotCellSize - 215f, y * itemSlotCellSize + 60f);
            Image image = itemSlotRectTransform.Find("image").GetComponent <Image>();
            image.sprite = item.GetSprite();
            TextMeshProUGUI uitext = itemSlotRectTransform.Find("text").GetComponent <TextMeshProUGUI>();

            if (image.sprite == ItemAssets.Instance.NoneSprite)
            {
                image.color = new Color32(255, 255, 225, 0);
            }

            if (item.amount > 1)
            {
                uitext.SetText(item.amount.ToString());
            }
            else
            {
                uitext.SetText("");
            }

            x++;
            if (x >= 9)
            {
                x = 0;
                y--;
            }
        }
    }
Пример #14
0
    private void RefreshInventoryItems()
    {
        foreach (Transform child in itemSlotContainer)
        {
            if (child == itemSlotTemplate)
            {
                continue;
            }
            Destroy(child.gameObject);
        }

        int   x = 0;
        int   y = 0;
        float itemSlotCellSize = 50f;

        foreach (Item item in inventory.GetItemList())
        {
            RectTransform itemSlotRectTransform = Instantiate(itemSlotTemplate, itemSlotContainer).GetComponent <RectTransform>();
            itemSlotRectTransform.gameObject.SetActive(true);

            itemSlotRectTransform.GetComponent <Button_UI>().ClickFunc = () =>
            {
                //Use Item
                inventory.UseItem(item);
                if (inventory.equipment.itemList[item.itemData.type] == item)
                {
                    RectTransform background      = (RectTransform)itemSlotRectTransform.Find("background");
                    Image         backgroundImage = background.gameObject.GetComponent <Image>();
                    backgroundImage.color = new Color32(150, 150, 150, 255);
                }
                else
                {
                    Image background      = (Image)itemSlotRectTransform.Find("background").GetComponent <Image>();
                    Image backgroundImage = background.gameObject.GetComponent <Image>();
                    backgroundImage.color = new Color32(90, 90, 90, 255);
                }
            };
            itemSlotRectTransform.GetComponent <Button_UI>().MouseRightClickFunc = () =>
            {
                //Drop Item
                Item duplicateItem = new Item(item.itemData);
                inventory.RemoveItem(item);
                inventory.equipment.UnequipItem(item);
                ItemWorld itemWorld = ItemWorld.DropItem(player.GetPosition(), duplicateItem);
                player.tile.AddItem(itemWorld);
                player.uiGroundItems.RefreshGroundItems(player.GetItemsGround());
            };

            itemSlotRectTransform.anchoredPosition = new Vector2(x * itemSlotCellSize, y * itemSlotCellSize);
            Image image = itemSlotRectTransform.Find("image").GetComponent <Image>();
            image.sprite = item.itemData.artwork;

            TextMeshProUGUI uiText = itemSlotRectTransform.Find("text").GetComponent <TextMeshProUGUI>();
            if (item.amount > 1)
            {
                uiText.SetText(item.amount.ToString());
            }
            else
            {
                uiText.SetText("");
            }

            x++;
            if (x > 3)
            {
                x = 0;
                y--;
            }
        }
    }
    private void RefreshInventoryItems()
    {
        foreach (Transform child in itemSlotContainer)
        {
            if (child == itemSlotTemplate)
            {
                continue;
            }
            Destroy(child.gameObject);
        }

        int   x = 0;
        int   y = 0;
        float itemSlotCellSize = 30f;

        foreach (Item item in inventory.GetItemList())
        {
            // Create the item slot
            RectTransform itemSlotRectTransform = Instantiate(itemSlotTemplate, itemSlotContainer).GetComponent <RectTransform>();
            itemSlotRectTransform.gameObject.SetActive(true);

            // Set the buttons
            itemSlotRectTransform.GetComponent <Button_UI>().ClickFunc = () =>
            {
                // Use item
                inventory.UseItem(item);
            };
            itemSlotRectTransform.GetComponent <Button_UI>().MouseRightClickFunc = () =>
            {
                // Drop item
                Item duplicateItem = new Item {
                    itemType = item.itemType, amount = 1
                };
                inventory.RemoveItem(item);
                ItemWorld.DropItem(player.GetPosition(), duplicateItem);
            };

            // Set the image
            itemSlotRectTransform.anchoredPosition = new Vector2(x * itemSlotCellSize, y * itemSlotCellSize);
            Image image = itemSlotRectTransform.Find("image").GetComponent <Image>();
            image.sprite = item.GetSprite();

            // Set the amount text
            TextMeshProUGUI uiText = itemSlotRectTransform.Find("text").GetComponent <TextMeshProUGUI>();
            if (item.amount > 1)
            {
                uiText.SetText(item.amount.ToString());
            }
            else
            {
                uiText.SetText("");
            }


            x++;
            // if more items than row can handle, move to next row
            if (x > 2)
            {
                x = 0;
                y--;
            }
        }
    }