FetchItemById() public method

public FetchItemById ( int id ) : Item
id int
return Item
Beispiel #1
0
    public void OnPointerEnter(PointerEventData eventData)
    {
        print("Enter Test");
        Item i1 = _item_manager.FetchItemById(4);

        _tooltip.Activate(i1, 1, true);
    }
Beispiel #2
0
    /*
     * Assuming to be adding one item at the time.
     * Takes an item id and adds an Item object into an open slot in the inventory or stacks
     * it on a slot containing the same item.
     * Updates the attributes of the Item: item, amount, and item_pos
     */
    public void AddItem(int id)
    {
        Item _item_to_add = _item_manager.FetchItemById(id);
        int  item_idx;

        if (_item_to_add.stackable && (item_idx = check_if_item_in_inventory(_item_to_add)) != -1)
        {
            ItemData data = slot_list[item_idx].transform.GetChild(0).GetComponent <ItemData>();
            if (data.amount == 0)
            {
                data.amount++;
            }
            data.amount++;
            data.transform.GetChild(0).GetComponent <Text>().text = data.amount.ToString();
        }
        else
        {
            for (int i = 0; i < inventory_item_list.Count; i++)
            {
                if (inventory_item_list[i].id == -1)
                {
                    inventory_item_list[i] = _item_to_add;
                    GameObject _item_obj = Instantiate(inventory_item);
                    _item_obj.GetComponent <ItemData>().item     = _item_to_add;
                    _item_obj.GetComponent <ItemData>().item_pos = i;
                    _item_obj.GetComponent <ItemData>().amount++;
                    _item_obj.transform.SetParent(slot_list[i].transform);
                    _item_obj.transform.position            = Vector2.zero; //centers item relative to parent
                    _item_obj.GetComponent <Image>().sprite = _item_to_add.sprite;
                    _item_obj.name = _item_to_add.title;                    //name shown in the inspector
                    break;
                }
            }
        }
    }
Beispiel #3
0
    /*-------------------------------------------------------------------------------------------------------
    *  -- FUNCTION:     AddItem
    *  -- DATE:         17/02/2016
    *  -- REVISIONS:
    *  -- DESIGNER:     Joseph Tam-Huang
    *  -- PROGRAMMER:   Joseph Tam-Huang
    *  -- INTERFACE:    public void AddItem(int id, int amt = 1)
    *  --                  int id: The item id
    *  --                  int amt: The amount to add
    *  -- RETURNS:  void
    *  -- NOTES:
    *  -- Takes an item id and the amount and adds an Item object into an open slot in the inventory or stacks
    *  -- it on a slot containing the same item.
    *  -- Updates the attributes of the Item: item, amount, and item_pos
    *  -------------------------------------------------------------------------------------------------------*/
    public void AddItem(int id, int amt = 1)
    {
        Item _item_to_add = _item_manager.FetchItemById(id);
        int  item_idx;

        if (_item_to_add.type == Constants.RESOURCE_TYPE)
        {
            GameData.MyPlayer.Resources[_item_to_add.title] += amt;
        }

        if (_item_to_add.stackable && (item_idx = check_if_item_in_inventory(_item_to_add)) != -1)
        {
            ItemData data = slot_list[item_idx].transform.GetChild(0).GetComponent <ItemData>();
            data.amount += amt;
            data.transform.GetChild(0).GetComponent <Text>().text = data.amount.ToString();
        }
        else
        {
            for (int i = 0; i < inventory_item_list.Count; i++)
            {
                if (inventory_item_list[i].id == -1)
                {
                    inventory_item_list[i] = _item_to_add;
                    GameObject _item_obj = Instantiate(inventory_item);
                    ItemData   data      = _item_obj.GetComponent <ItemData>();
                    data.item     = _item_to_add;
                    data.item_pos = i;
                    data.amount  += amt;
                    if (_item_to_add.stackable)
                    {
                        data.transform.GetChild(0).GetComponent <Text>().text = data.amount.ToString();
                    }
                    _item_obj.transform.SetParent(slot_list[i].transform);
                    // Sets scaling factor of gridlayout component to 1 to work with
                    // the unity "Scale With Screen Size" ui scale mode
                    _item_obj.transform.localScale          = new Vector3(1, 1, 1);
                    _item_obj.transform.localPosition       = Vector2.zero; //centers item relative to parent
                    _item_obj.GetComponent <Image>().sprite = _item_to_add.sprite;
                    _item_obj.name = _item_to_add.title;                    //name shown in the inspector

                    if (i == Constants.WEAPON_SLOT)
                    {
                        UpdateWeaponStats();
                    }
                    break;
                }
            }
        }
    }
Beispiel #4
0
    /*-------------------------------------------------------------------------------
     * -- FUNCTION:     CreateWorldItem
     * -- DATE:         05/03/2016
     * -- REVISIONS:
     * -- DESIGNER:     Joseph Tam-Huang
     * -- PROGRAMMER:   Joseph Tam-Huang
     * -- INTERFACE:    public GameObject CreateWorldItem(int world_item_id, int item_id,
     * --                  int amt, float pos_x, float pos_y)
     * --                  int world_item_id - the id of the world item
     * --                  int item_id - the id of the item
     * --                  int amt - the amount of the item
     * --                  float pos_x - the x coordinate on the world map
     * --                  float pos_y - the y coordinate on the world map
     * -- RETURNS:  void
     * -- NOTES:
     * -- Creates a world item
     * ---------------------------------------------------------------------------------*/
    public GameObject CreateWorldItem(int world_item_id, int item_id, int amt, float pos_x, float pos_y)
    {
        Item       item  = _item_manager.FetchItemById(item_id);
        GameObject _item = Instantiate(world_item);

        _item.GetComponent <WorldItemData>().world_item_id = world_item_id;
        _item.GetComponent <WorldItemData>().item          = item;
        _item.GetComponent <WorldItemData>().amount        = amt;
        _item.GetComponent <SpriteRenderer>().sprite       = item.world_sprite;
        _item.transform.position = new Vector3(pos_x, pos_y, -5);

        // Add gold-specific components
        if (item_id == 2)
        {
            _item.GetComponent <WorldItemData>().autolootable = true;
            _item.AddComponent <Magnetize>();
            _item.GetComponent <Magnetize>().world_item_id = world_item_id;

            // Sound component and gold drop sound
            // audioDrop = Resources.Load ("Music/Inventory/currency") as AudioClip;
            // audioSource.PlayOneShot (audioDrop);
        }
        return(_item);
    }