public bool AddItemToShop(Item ItemToAdd)//bool to check if an item can be added or no
    {
        int TheIndexOfMe = TakeIndexOfPos();

        if (TheIndexOfMe > PositionsAndOccupation.Count)
        {
            Debug.Log("NO ENOUGH SPACE IN SHOP");
            return(false);
        }

        GameObject NewItem = GameObject.Instantiate(ItemGoPrefab, ItemsParent);

        NewItem.transform.position = PositionsAndOccupation[TheIndexOfMe].aPos;
        ItemProps AccIP = NewItem.GetComponent <ItemProps>();

        AccIP.TakeInfo(ItemToAdd, TheIndexOfMe, ItemHome.PlayerBuyTab);
        CustomItemAndGo ItemAndGo = new CustomItemAndGo(ItemToAdd, NewItem);

        if (PlayerBuyInventory.ContainsKey(TheIndexOfMe))
        {
            PlayerBuyInventory[TheIndexOfMe] = ItemAndGo;
        }
        else
        {
            PlayerBuyInventory.Add(TheIndexOfMe, ItemAndGo);
        }

        return(true);
    }
Beispiel #2
0
    public bool AddItemToEquipmentInventory(ItemProps TheItemToAdd)
    {
        Transform itemParent = null;

        if (AccInv != null)
        {
            foreach (KeyValuePair <GearMainType, Transform> eq in EquipmentSlots)
            {
                if (eq.Key == TheItemToAdd.MyItem.gearMainType)
                {
                    itemParent = eq.Value;
                }
            }

            if (itemParent == null)
            {
                return(false);
            }
            //codes for adding item to the equipment inventory
            GameObject NewItem = GameObject.Instantiate(ItemGoPrefab, itemParent);
            NewItem.transform.localPosition = new Vector2(0, 0);
            ItemProps AccIP = NewItem.GetComponent <ItemProps>();
            AccIP.TakeInfo(TheItemToAdd.MyItem, 0, ItemHome.Equiped);

            CustomItemAndGo ItemAndGo = new CustomItemAndGo(TheItemToAdd.MyItem, NewItem);
            AccInv.RemoveItemFromInventory(TheItemToAdd.MyPlaceInHome);

            if (EquipmentInventory.ContainsKey(TheItemToAdd.MyItem.gearMainType))
            {
                AccInv.AddItemToInventory(EquipmentInventory[TheItemToAdd.MyItem.gearMainType].TheItem);
                RemoveItemFromEquipmentInventory(TheItemToAdd.MyItem.gearMainType);
                EquipmentInventory.Add(TheItemToAdd.MyItem.gearMainType, ItemAndGo);
            }
            else
            {
                EquipmentInventory.Add(TheItemToAdd.MyItem.gearMainType, ItemAndGo);
            }
            return(true);
        }
        else
        {
            Debug.Log("No Inventory");
            return(false);
        }
    }
    public bool AddItemToInventory(Item ItemToAdd)//bool to check can this item be added to the inventory or no
    {
        if (ItemToAdd.IsStackable)
        {
            for (int i = 0; i < ListOfStackables.Count; i++)
            {
                if (ListOfStackables[i].TheItem.itemName == ItemToAdd.itemName && ListOfStackables[i].ItemStacks < MaxNumberOfStacks)
                {
                    ListOfStackables[i].ItemStacks++;
                    Inventory[ListOfStackables[i].ItemNumberInInventory].TheGameObject.GetComponent <ItemProps>().ChangeStacks(ListOfStackables[i].ItemStacks);
                    return(true);
                }
            }
        }
        int TheIndexOfMe = TakeIndexOfPos();

        if (TheIndexOfMe > PositionsAndOccupation.Count)//in case the index is more than the slots numbers
        {
            ErrorMessageText.instance.ShowMessage("No Enough space in inventory");
            return(false);
        }
        GameObject NewItem = GameObject.Instantiate(ItemGoPrefab, ItemsParent);

        NewItem.transform.position = PositionsAndOccupation[TheIndexOfMe].aPos;
        ItemProps AccIP = NewItem.GetComponent <ItemProps>();

        AccIP.TakeInfo(ItemToAdd, TheIndexOfMe, ItemHome.Inventory);

        CustomItemAndGo ItemAndGo = new CustomItemAndGo(ItemToAdd, NewItem);

        if (Inventory.ContainsKey(TheIndexOfMe))
        {
            Inventory[TheIndexOfMe] = ItemAndGo;
        }
        else
        {
            Inventory.Add(TheIndexOfMe, ItemAndGo);
        }
        if (ItemToAdd.IsStackable)
        {
            ListOfStackables.Add(new CustomItemIntInt(ItemToAdd, 1, TheIndexOfMe));
        }
        return(true);
    }