addItemToInventory() 공개 메소드

public addItemToInventory ( int id, UInt64 itemUUID, int value ) : GameObject
id int
itemUUID UInt64
value int
리턴 GameObject
예제 #1
0
    public void clickInventoryItem(int slotnumber, Inventory toInventory)
    {
        // TRANSFER TO BUILDING INVENTORY
        if (gameManager.getBuildingCatalog().getBuildingLastClicked() != null)
        {
            if (gameManager.GetUI().getBuildingInventoryOpen() && this.getInventorySlot(slotnumber).currentAmountInSlot != 0)
            {
                if (gameManager.getBuildingCatalog().getBuildingLastClickedAttributes().getPlayerEnteredBuilding())
                {
                    int amountToRemove = toInventory.addItemToInventory(this.getInventorySlot(slotnumber).getItemInSlot(), this.getInventorySlot(slotnumber).getCurrentAmountInSlot());
                    removeAmountFromSpecificSlot(this.getInventorySlot(slotnumber), this.getInventorySlot(slotnumber).getCurrentAmountInSlot() - amountToRemove);
                    updateInventoryInterface();
                }
                else
                {
                    gameManager.getMessageLogText().addMessageToLog("The player needs to be inside the building in order to transfer items to building inventory");
                }
            }
        }

        // TRANSFER TO UNFINISHED BUILDING
        if (gameManager.getBuildingCatalog().getUnfinishedBuildingSelected() != null)
        {
            if (gameManager.GetUI().getUnfinishedBuildingOpen() && this.getInventorySlot(slotnumber).currentAmountInSlot != 0)
            {
                // TODO: if statement that prohbit player from transfering if to far away
                int amountToRemove = toInventory.addItemToInventory(this.getInventorySlot(slotnumber).getItemInSlot(), this.getInventorySlot(slotnumber).getCurrentAmountInSlot());
                removeAmountFromSpecificSlot(this.getInventorySlot(slotnumber), this.getInventorySlot(slotnumber).getCurrentAmountInSlot() - amountToRemove);
                updateInventoryInterface();
            }
        }

        // TRANSFER TO CITIZEN
        if (gameManager.getCitizenCatalog().getSelectedCitizen() != null)
        {
            if (gameManager.GetUI().getCitizenInventoryOpen() && this.getInventorySlot(slotnumber).currentAmountInSlot != 0)
            {
                // TODO: if statement that prohbit player from transfering if to far away
                int amountToRemove = toInventory.addItemToInventory(this.getInventorySlot(slotnumber).getItemInSlot(), this.getInventorySlot(slotnumber).getCurrentAmountInSlot());
                removeAmountFromSpecificSlot(this.getInventorySlot(slotnumber), this.getInventorySlot(slotnumber).getCurrentAmountInSlot() - amountToRemove);
                updateInventoryInterface();
            }
        }

        // TRANSFER TO TOOLBAR
        if (!gameManager.GetUI().getCitizenInventoryOpen() && !gameManager.GetUI().getUnfinishedBuildingOpen() && !gameManager.GetUI().getBuildingInventoryOpen() && this.getInventorySlot(slotnumber).currentAmountInSlot != 0)
        {
            //if(gameManager.getPlayerBehavior().getPerkattributes().getPerksByName(this.getInventorySlot(slotnumber).getItemInSlot()) != null){
            gameManager.getPlayerBehavior().getToolbelt().addToSlot(this.getInventorySlot(slotnumber));
            updateInventoryInterface();
            //} else {
            //Debug.Log("Dont have the perk associated with that item");
            //}
        }
        if (gameManager.GetUI().getInventoryOpen() && gameManager.GetUI().getEquipmentOpen() && this.getInventorySlot(slotnumber).currentAmountInSlot != 0)
        {
            gameManager.getPlayerBehavior().getToolbelt().addToSlot(this.getInventorySlot(slotnumber));
            updateInventoryInterface();
        }
    }
예제 #2
0
 // Update is called once per frame
 void Update()
 {
     if (_inventory != null && UserControl.PickupItem)
     {
         float distance = Vector2.Distance(new Vector2(this.gameObject.transform.position.x, this.gameObject.transform.position.y), new Vector2(_player.transform.position.x, _player.transform.position.y));
         print("distance: " + distance);
         if (distance <= 1.3)
         {
             sceneManager.GetComponent <MySceneManager>().removeFromGearList(this.gameObject);
             bool check = _inventory.checkIfItemAllreadyExist(item.itemID, item.itemValue);
             if (check)
             {
                 Destroy(this.gameObject);
             }
             else if (_inventory.ItemsInInventory.Count < (_inventory.width * _inventory.height))
             {
                 _inventory.addItemToInventory(item.itemID, item.itemValue);
                 _inventory.updateItemList();
                 _inventory.stackableSettings();
                 Destroy(this.gameObject);
             }
         }
     }
     if (_inventory != null && UserControl.GetGearsBack)
     {
         addItemToInv(item.itemID, item.itemValue);
     }
 }
예제 #3
0
 public bool sendItemFromThisToOther(Inventory inv2, string itemName, int amount)
 {
     if (inv2.checkIfInventoryHasSpaceForItem(itemName, amount))
     {
         if (this.getAmountOfSpecificItem(itemName) != 0)
         {
             if (this.getAmountOfSpecificItem(itemName) >= amount)
             {
                 inv2.addItemToInventory(itemName, amount);
                 this.removeItemFromInventory(itemName, amount);
                 return(true);
             }
             else
             {
                 inv2.addItemToInventory(itemName, this.getAmountOfSpecificItem(itemName));
                 this.removeItemFromInventory(itemName, this.getAmountOfSpecificItem(itemName));
                 Debug.Log(itemName + " " + this.getAmountOfSpecificItem(itemName) + " " + this.transform.name + " " + inv2.transform.name);
                 Debug.Log("Didnt have the full amount to transfer, so sent what the inventory had of that item");
             }
         }
         else
         {
             Debug.Log("Inventory didnt have " + itemName + ". No transfer was made.");
         }
     }
     else
     {
         gameManager.getMessageLogText().addMessageToLog("Could not transfer item to inventory, since its not enough space");
     }
     return(false);
 }
예제 #4
0
 public void pickUp_re(ITEM_INFO itemInfo)
 {
     if (itemInventory == null)
     {
         itemInventory = this.transform.GetComponent <PlayerInventory>().inventory.GetComponent <Inventory>();
     }
     if (itemInventory != null)
     {
         itemInventory.addItemToInventory(itemInfo.itemId, itemInfo.UUID, (int)itemInfo.itemCount, itemInfo.itemIndex);
         itemInventory.updateItemList();
         itemInventory.stackableSettings();
     }
 }
예제 #5
0
 public void pickUp_re(Dictionary <string, object> itemInfo)
 {
     if (itemInventory == null)
     {
         itemInventory = this.transform.GetComponent <PlayerInventory>().inventory.GetComponent <Inventory>();
     }
     if (itemInventory != null)
     {
         itemInventory.addItemToInventory((Int32)itemInfo["itemId"], (UInt64)itemInfo["UUID"], (int)(UInt32)itemInfo["itemCount"], (Int32)itemInfo["itemIndex"]);
         itemInventory.updateItemList();
         itemInventory.stackableSettings();
     }
 }
예제 #6
0
    void addItemGUI()                                                                                                       //add a item to the inventory through the inspector
    {
        if (!inv.characterSystem())
        {
            GUILayout.Label("Add an item:");
            inv.setImportantVariables();                                                                                      //space to the top gui element
            EditorGUILayout.BeginHorizontal();                                                                                //starting horizontal GUI elements
            ItemDataBaseList inventoryItemList = (ItemDataBaseList)Resources.Load("ItemDatabase");                            //loading the itemdatabase
            string[]         items             = new string[inventoryItemList.itemList.Count];                                //create a string array in length of the itemcount
            for (int i = 1; i < items.Length; i++)                                                                            //go through the item array
            {
                items[i] = inventoryItemList.itemList[i].itemName;                                                            //and paste all names into the array
            }
            itemID    = EditorGUILayout.Popup("", itemID, items, EditorStyles.popup);                                         //create a popout with all itemnames in it and save the itemID of it
            itemValue = EditorGUILayout.IntField("", itemValue, GUILayout.Width(40));
            GUI.color = Color.green;                                                                                          //set the color of all following guielements to green
            if (GUILayout.Button("Add Item"))                                                                                 //creating button with name "AddItem"
            {
                inv.addItemToInventory(itemID, itemValue);                                                                    //and set the settings for possible stackedItems
                inv.stackableSettings();
            }
            inv.OnUpdateItemList();

            EditorGUILayout.EndHorizontal();                                                                                    //end the horizontal gui layout
        }
    }
예제 #7
0
    public void updateQuest()
    {
        /*for (int i = 0; i < questTracker.questList.Count; i++)
         * {
         *  if (questTracker.questList[i].itemID == 1)
         *  {
         *      if (questTracker.questList[i].itemValue < questTracker.questList[i].itemAttributes[0].attributeValue)
         *          questTracker.questList[i].itemValue += 1;
         *      else
         *          questTracker.questList[i].itemIcon = Resources.Load("Sprites/HUD/Check-sprite-ltr-1.svg", typeof(Sprite)) as Sprite;
         *  }
         *
         * }*/

        for (int j = 0; j < questManager.ItemsInInventory.Count; j++)
        {
            if (questManager.ItemsInInventory[j].itemID == 2)
            {
                if (questManager.ItemsInInventory[j].itemValue < questManager.ItemsInInventory[j].itemAttributes[0].attributeValue)
                {
                    questManager.ItemsInInventory[j].itemValue += 1;
                    if (questManager.ItemsInInventory[j].itemValue == questManager.ItemsInInventory[j].itemAttributes[0].attributeValue)
                    {
                        questManager.ItemsInInventory[j].itemIcon = Resources.Load("Sprites/HUD/Check-sprite-ltr-1.svg", typeof(Sprite)) as Sprite;
                        playerInv.addItemToInventory(40);
                    }
                }
                else
                {
                    return;
                }
            }
        }
    }
예제 #8
0
    void buyItem(Item finalItem)
    {
        amountSlots     = inventoryPlayer.transform.GetChild(1).childCount;
        transactionDone = false;
        slotsChecked    = 0;

        foreach (Transform child in inventoryPlayer.transform.GetChild(1))
        {
            if (child.childCount == 0)
            {
                if (playerinv.goldCoins >= finalItem.itemValue)
                {
                    inventoryPlayer.addItemToInventory(finalItem.itemID);
                    playerinv.goldCoins -= finalItem.itemValue;
                    transactionDone      = true;
                    print("Le joueur a acheté l'objet : " + finalItem.itemName);
                    break;
                }
                else
                {
                    print("Transaction refusée, le joueur n'a pas assez d'argent.");
                }
            }
            slotsChecked++;
        }

        if (slotsChecked == amountSlots && transactionDone == false)
        {
            print("Transaction annulée, pas de place dans l'inventaire.");
        }
    }
예제 #9
0
    private bool pressingButtonToSplit; //bool for pressing a item to split it

    #endregion Fields

    #region Methods

    //splitting the item now
    public void OnPointerDown(PointerEventData data)
    {
        inv = transform.parent.parent.parent.GetComponent<Inventory>();
        if (transform.parent.parent.parent.GetComponent<Hotbar>() == null && data.button == PointerEventData.InputButton.Left && pressingButtonToSplit && inv.stackable && (inv.ItemsInInventory.Count < (inv.height * inv.width))) //if you press leftclick and and keycode
        {
            ItemOnObject itemOnObject = GetComponent<ItemOnObject>();                                                   //we take the ItemOnObject script of the item in the slot

            if (itemOnObject.item.itemValue > 1)                                                                         //we split the item only when we have more than 1 in the stack
            {
                int splitPart = itemOnObject.item.itemValue;                                                           //we take the value and store it in there
                itemOnObject.item.itemValue = (int)itemOnObject.item.itemValue / 2;                                     //calculate the new value for the splitted item
                splitPart = splitPart - itemOnObject.item.itemValue;                                                   //take the different

                inv.addItemToInventory(itemOnObject.item.itemID, splitPart);                                            //and add a new item to the inventory
                inv.stackableSettings();

                if (GetComponent<ConsumeItem>().duplication != null)
                {
                    GameObject dup = GetComponent<ConsumeItem>().duplication;
                    dup.GetComponent<ItemOnObject>().item.itemValue = itemOnObject.item.itemValue;
                    dup.GetComponent<SplitItem>().inv.stackableSettings();
                }
                inv.updateItemList();

            }
        }
    }
예제 #10
0
    public void equipItemRequest_re(Dictionary <string, object> itemInfo, Dictionary <string, object> equipItemInfo)
    {
        Int32  itemIndex      = (Int32)itemInfo["itemIndex"];
        Int32  equipItemIndex = (Int32)equipItemInfo["itemIndex"];
        UInt64 itemUUid       = (UInt64)itemInfo["UUID"];
        UInt64 equipItemUUid  = (UInt64)equipItemInfo["UUID"];

        if (itemUUid > 0)
        {
            itemInventory.addItemToInventory((Int32)itemInfo["itemId"], (UInt64)itemInfo["UUID"], 1, (Int32)itemInfo["itemIndex"]);
        }
        else
        {
            itemInventory.deleteItemByIndex(itemIndex);
        }

        if (equipItemUUid > 0)
        {
            equipInventory.addItemToInventory((Int32)equipItemInfo["itemId"], (UInt64)equipItemInfo["UUID"], 1, (Int32)equipItemInfo["itemIndex"]);
        }
        else
        {
            equipInventory.deleteItemByIndex(equipItemIndex);
        }

        itemInventory.updateItemList();
        itemInventory.stackableSettings();
        equipInventory.updateItemList();
        equipInventory.stackableSettings();
    }
예제 #11
0
    // Update is called once per frame
    void Update()
    {
        if (inventory != null)
        {
            float distance1 = Vector3.Distance(this.gameObject.transform.position, player1.transform.position);
            float distance2 = Vector3.Distance(this.gameObject.transform.position, player2.transform.position);

            if (distance1 <= 2 || distance2 <= 2)
            {
                bool check = inventory.checkIfItemAllreadyExist(item.itemID, item.itemValue);
                if (check)
                {
                    Destroy(this.gameObject);
                }
                else if (inventory.ItemsInInventory.Count < (inventory.width * inventory.height))
                {
                    inventory.addItemToInventory(item.itemID, item.itemValue);
                    ThisScene.AddItemToPersistedInventory(item.itemID);
                    Destroy(this.gameObject);
                    if (pickUpFX != null)
                    {
                        AudioSource.PlayClipAtPoint(pickUpFX, transform.position);
                    }
                }
            }
        }
    }
예제 #12
0
    void buyItem(Item finalItem)
    {
        amountSlots     = inventoryPlayer.transform.GetChild(1).childCount;
        transactionDone = false;
        slotsChecked    = 0;

        foreach (Transform child in inventoryPlayer.transform.GetChild(1))
        {
            if (child.childCount == 0)
            {
                if (playerInv.currentMoney >= finalItem.itemValue)
                {
                    inventoryPlayer.addItemToInventory(finalItem.itemID);
                    playerInv.currentMoney -= finalItem.itemValue;
                    transactionDone         = true;
                    print("Player bought: " + finalItem.itemName);
                    break;
                }
                else
                {
                    print("Not enought money");
                }
            }
            slotsChecked++;
        }
        if (slotsChecked == amountSlots && transactionDone == false)
        {
            print("No more room in the inventory");
        }
    }
예제 #13
0
    public void OnPointerDown(PointerEventData data)                    //splitting the item now
    {
        inv = transform.parent.parent.parent.GetComponent <Inventory>();
        if (transform.parent.parent.parent.GetComponent <Hotbar>() == null && data.button == PointerEventData.InputButton.Left && pressingButtonToSplit && inv.stackable && (inv.ItemsInInventory.Count < (inv.height * inv.width))) //if you press leftclick and and keycode
        {
            ItemOnObject itemOnObject = GetComponent <ItemOnObject>();                                                                                                                                                               //we take the ItemOnObject script of the item in the slot

            if (itemOnObject.item.itemValue > 1)                                                                                                                                                                                     //we split the item only when we have more than 1 in the stack
            {
                int splitPart = itemOnObject.item.itemValue;                                                                                                                                                                         //we take the value and store it in there
                itemOnObject.item.itemValue = (int)itemOnObject.item.itemValue / 2;                                                                                                                                                  //calculate the new value for the splitted item
                splitPart = splitPart - itemOnObject.item.itemValue;                                                                                                                                                                 //take the different

                inv.addItemToInventory(itemOnObject.item.itemID, splitPart);                                                                                                                                                         //and add a new item to the inventory
                inv.stackableSettings();

                if (GetComponent <ConsumeItem>().duplication != null)
                {
                    GameObject dup = GetComponent <ConsumeItem>().duplication;
                    dup.GetComponent <ItemOnObject>().item.itemValue = itemOnObject.item.itemValue;
                    dup.GetComponent <SplitItem>().inv.stackableSettings();
                }
                inv.updateItemList();
            }
        }
    }
예제 #14
0
 // Update is called once per frame
 void Update()
 {
     if (_inventory != null && Input.GetKeyDown(KeyCode.E))
     {
         RaycastHit hit;
         if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, 3f))
         {
             if (!hit.transform.gameObject.GetComponent <PickUpItem>())
             {
                 return;
             }
             bool check = _inventory.checkIfItemAllreadyExist(item.itemID, item.itemValue);
             if (check)
             {
                 Destroy(this.gameObject);
             }
             else if (_inventory.ItemsInInventory.Count < (_inventory.width * _inventory.height))
             {
                 _inventory.addItemToInventory(item.itemID, item.itemValue);
                 _inventory.updateItemList();
                 _inventory.stackableSettings();
                 Destroy(this.gameObject);
             }
         }
     }
 }
예제 #15
0
    public void OnPointerDown(PointerEventData data)
    {
        inv = transform.parent.parent.parent.GetComponent<Inventory>();
        if (transform.parent.parent.parent.GetComponent<Hotbar>() == null && data.button == PointerEventData.InputButton.Left && pressingButtonToSplit && inv.stackable && (inv.ItemsInInventory.Count < (inv.height * inv.width)))
        {
            ItemOnObject itemOnObject = GetComponent<ItemOnObject>();

            if (itemOnObject.item.itemValue > 1)
            {
                int splitPart = itemOnObject.item.itemValue;
                itemOnObject.item.itemValue = (int)itemOnObject.item.itemValue / 2;
                splitPart = splitPart - itemOnObject.item.itemValue;

                inv.addItemToInventory(itemOnObject.item.itemID, splitPart);
                inv.stackableSettings();

                if (GetComponent<ConsumeItem>().duplication != null)
                {
                    GameObject dup = GetComponent<ConsumeItem>().duplication;
                    dup.GetComponent<ItemOnObject>().item.itemValue = itemOnObject.item.itemValue;
                    dup.GetComponent<SplitItem>().inv.stackableSettings();
                }
                inv.updateItemList();

            }
        }
    }
예제 #16
0
    public void equipItemRequest_re(ITEM_INFO itemInfo, ITEM_INFO equipItemInfo)
    {
        Int32  itemIndex      = itemInfo.itemIndex;
        Int32  equipItemIndex = equipItemInfo.itemIndex;
        UInt64 itemUUid       = itemInfo.UUID;
        UInt64 equipItemUUid  = equipItemInfo.UUID;

        if (itemUUid > 0)
        {
            itemInventory.addItemToInventory(itemInfo.itemId, itemInfo.UUID, 1, itemInfo.itemIndex);
        }
        else
        {
            itemInventory.deleteItemByIndex(itemIndex);
        }

        if (equipItemUUid > 0)
        {
            equipInventory.addItemToInventory(equipItemInfo.itemId, equipItemInfo.UUID, 1, equipItemInfo.itemIndex);
        }
        else
        {
            equipInventory.deleteItemByIndex(equipItemIndex);
        }

        itemInventory.updateItemList();
        itemInventory.stackableSettings();
        equipInventory.updateItemList();
        equipInventory.stackableSettings();
    }
예제 #17
0
    // Update is called once per frame
    void Update()
    {
        Vector3 newPos = this.gameObject.transform.position;
        // characPos = center of the player;
        Vector3 characPos = _player.transform.position;

        characPos.y += _player.transform.localScale.y / 2;
        float distance = Vector3.Distance(this.gameObject.transform.position, characPos);

        speedMultiplier = distance * 0.05f;

        if (distance <= 1)
        {
            pi.brokenItemID = this.gameObject.GetComponent <PickUpItem>().item.itemID;
            if (!pi.FullInventory())
            {
                // moving the item to the player
                if (newPos.x - characPos.x < 0)
                {
                    newPos.x += speedMultiplier;
                }
                else if (newPos.x - characPos.x > 0)
                {
                    newPos.x -= speedMultiplier;
                }

                if (newPos.y - characPos.y < 0)
                {
                    newPos.y += speedMultiplier;
                }
                else if (newPos.y - characPos.y > 0)
                {
                    newPos.y -= speedMultiplier;
                }
                this.gameObject.transform.position = newPos;

                // picking up the item
                if (_inventory != null && Mathf.Abs(this.gameObject.transform.position.x - characPos.x) <= 0.3f &&
                    Mathf.Abs(this.gameObject.transform.position.y - characPos.y) <= 0.3f * (_player.GetComponent <CapsuleCollider2D>().offset.y / _player.GetComponent <CapsuleCollider2D>().offset.x))
                {
                    bool check = _inventory.checkIfItemAllreadyExist(item.itemID, item.itemValue);
                    if (check)
                    {
                        Destroy(this.gameObject);
                    }
                    else if (_inventory.ItemsInInventory.Count < (_inventory.width * _inventory.height))
                    {
                        _inventory.addItemToInventory(item.itemID, item.itemValue);
                        _inventory.updateItemList();
                        _inventory.stackableSettings();
                        Destroy(this.gameObject);
                    }
                    if (!pi.currentLevel.Equals(pi.maxLevel))
                    {
                        pi.GainExp(item.expToGain);
                    }
                }
            }
        }
    }
예제 #18
0
    // Update is called once per frame
    void Update()
    {
        if (_inventory != null && Input.GetKeyDown(KeyCode.E))
        {
            float distance = Vector3.Distance(this.gameObject.transform.position, _player.transform.position);

            if (distance <= 3)
            {
                if (playerIO.isNetwork)
                {
                    menuManager.Debuglog("Собранно " + item.itemName + " колличество " + item.itemValue);
                    //MenuManager.instance.Debuglog();
                    GameObject.Find("NetworkManager").GetComponent <NetworkLayerClient>().HarwestWood(item.itemID, item.itemValue);
                    Destroy(this.gameObject);
                }
                else
                {
                    Debug.Log("Собранно " + item.itemName + " колличество " + item.itemValue);
                    bool check = _inventory.checkIfItemAllreadyExist(item.itemID, item.itemValue);
                    if (check)
                    {
                        Destroy(this.gameObject);
                    }
                    else if (_inventory.ItemsInInventory.Count < (_inventory.width * _inventory.height))
                    {
                        _inventory.addItemToInventory(item.itemID, item.itemValue);
                        _inventory.updateItemList();
                        _inventory.stackableSettings();
                        Destroy(this.gameObject);
                    }
                }
            }
        }
    }
예제 #19
0
        public void TestInventoryShouldAddElementToItemsWhenItemGiven()
        {
            MockItem  mockItem  = new MockItem();
            Inventory inventory = new Inventory();

            inventory.addItemToInventory(mockItem);
            Assert.AreEqual(1, inventory.items.Count);
        }
예제 #20
0
        public void TestInventoryShouldAddElementToWeaponsWhenWeaponGiven()
        {
            MockWeapon mockWeapon = new MockWeapon();
            Inventory  inventory  = new Inventory();

            inventory.addItemToInventory(mockWeapon);
            Assert.AreEqual(1, inventory.weapons.Count);
        }
예제 #21
0
        public void TestInventoryShouldAddElementToArmorsWhenArmorGiven()
        {
            MockArmor mockArmor = new MockArmor();
            Inventory inventory = new Inventory();

            inventory.addItemToInventory(mockArmor);
            Assert.AreEqual(1, inventory.armors.Count);
        }
 void OnTriggerEnter2D(Collider2D other)
 {
     Debug.Log("Touching " + other.name);
     if (other.CompareTag("Pickup"))
     {
         inventory.addItemToInventory(other.GetComponent <ItemMB>().item);
         other.gameObject.SetActive(false);
     }
 }
예제 #23
0
    private void OnCollisionEnter(Collision collision)
    {
        Inventory inventory = collision.transform.GetComponent <Inventory>();

        if (inventory)
        {
            inventory.addItemToInventory(item, amount);
            Destroy(this.gameObject);
        }
    }
예제 #24
0
파일: Inventory.cs 프로젝트: vosiz/Unity3D
    // Tries to add an item to inventory
    static public int addItem(GameItem item)
    {
        // Check if can be picked up
        if (!canPickup(item))
        {
            return(0);
        }

        return(Inventory.addItemToInventory(item));
    }
예제 #25
0
    void addItemsToInventory()
    {
        Inventory iV = inventory.GetComponent <Inventory>();

        for (int i = 0; i < storageItems.Count; i++)
        {
            iV.addItemToInventory(storageItems[i].itemID, storageItems[i].itemValue);
        }
        iV.stackableSettings();
    }
예제 #26
0
    public void addItemToInventory(int id, int value = 1)
    {
        if (mainInventory == null)
        {
            mainInventory = inventory.GetComponent <Inventory>();
        }

        if (!mainInventory.checkIfItemAllreadyExist(id, value))
        {
            mainInventory.addItemToInventory(id, value);
        }
    }
예제 #27
0
 public bool transferItemIntoInventory(Equippable item)
 {
     if (weaponGameObjectList.Contains(item))
     {
         if (inventory.addItemToInventory(item.getScripatbleObject(), 1))
         {
             Destroy(item.gameObject);
             weaponGameObjectList.Remove(item);
             return(true);
         }
     }
     return(false);
 }
    public override void OnOptionSelect()
    {
        foreach (string st in itemsToAdd)
        {
            GameObject g = ItemDatabase.me.getItem(st);
            if (g == null)
            {
                continue;
            }

            GameObject item       = (GameObject)Instantiate(g, CommonObjectsStore.player.transform.position, Quaternion.Euler(Vector3.zero));
            Item       itemScript = item.GetComponent <Item> ();
            Inventory  i          = CommonObjectsStore.player.GetComponent <Inventory> ();
            i.addItemToInventory(itemScript);
        }
    }
예제 #29
0
    void Start()
    {
        itemDatabase = (ItemDataBaseList)Resources.Load("ItemDatabase");
        debugingame  = GameObject.Find("Debug_game").GetComponent <Text>();
        txmoney      = GameObject.Find("PlayerGui").transform.Find("Txmoney").gameObject;
        txcitycount  = GameObject.Find("PlayerGui").transform.Find("Txmanount").gameObject;
        //  CitySaveAsset save = (CitySaveAsset)Resources.Load("CitySaveAsset");
        if (File.Exists(gamefile))
        {
            // itemList = ReadFromXmlFile<List<ItemStore>>(gamefile);

            //itemList = ReadFromBinaryFile<List<ItemStore>>("game.save");

            //  loadGame();
        }
        if (File.Exists(playerfile))
        {
            //  playerSetting = ReadFromXmlFile<PlayerGameSetting>(playerfile);
            playerSetting = ReadFromBinaryFile <PlayerGameSetting>(playerfile);
            PlayerMoney   = playerSetting.money;
            Inventory invent = GameObject.Find("PlayerGui").transform.GetChild(1).GetComponent <Inventory>();
            int       i;
            for (i = 0; i < playerSetting.ItemsInInventory.Count; i++)
            {
                invent.addItemToInventory(playerSetting.ItemsInInventory[i].ItemID, playerSetting.ItemsInInventory[i].cout);
            }

            //GameObject.Find("PlayerGui").transform.GetChild(1).GetComponent<Inventory>().ItemsInInventory;
        }
        if (File.Exists(citysave))
        {
            city = ReadFromBinaryFile <City>(citysave);
            loadGame();
        }
        else
        {
            city = new City();
        }

        //meshSurface.AddData();
        // NavMeshSurface meshSurface = new NavMeshSurface();

        //NavMeshData navdata = new NavMeshData();
        // meshSurface.BuildNavMesh();
    }
예제 #30
0
    public override void Interact()
    {
        base.Interact();
        bool check = _inventory.checkIfItemAllreadyExist(item.itemID, item.itemValue);

        if (check)
        {
            Destroy(this.gameObject);
        }
        else if (_inventory.ItemsInInventory.Count < (_inventory.width * _inventory.height))
        {
            _inventory.addItemToInventory(item.itemID, item.itemValue);
            _inventory.updateIconSize();
            _inventory.updateItemList();
            _inventory.stackableSettings();
            Destroy(this.gameObject);
            GameManager.NotifyPickedUpItem(item);
        }
    }
예제 #31
0
        public IActionResult Purchase(int gameId, int itemId, int characterId)
        {
            List <Inventory> playersInventory = Inventory.getPlayersInventory(_context, characterId);

            int characterBalance = playersInventory.Find(item => item.inventoryItemId == 6).quantity;

            int itemPrice = _context.inventoryitems.ToList().Find(item => item.id == itemId).monetaryValue;

            if (characterBalance < itemPrice)
            {
                TempData["FlashMessage"] = "Merchant: 'You cannot afford that, peasant!'";
            }
            else
            {
                Inventory.RemoveItemFromInventory(_context, characterId, 6, itemPrice);

                Inventory.addItemToInventory(_context, characterId, itemId, 1);
            }

            return(Redirect($"View/{gameId}"));
        }
예제 #32
0
    public void onReqItemList(Dictionary <UInt64, ITEM_INFO> itemList, Dictionary <UInt64, ITEM_INFO> equipItemDict)
    {
        UnityEngine.GameObject _player = UnityEngine.GameObject.FindGameObjectWithTag("Player");
        Inventory _inventory           = null;
        Inventory _equipInventory      = null;

        if (_player != null)
        {
            _inventory      = _player.GetComponent <PlayerInventory>().inventory.GetComponent <Inventory>();
            _equipInventory = _player.GetComponent <PlayerInventory>().characterSystem.GetComponent <Inventory>();
        }
        if (_inventory != null)
        {
            foreach (UInt64 dbid in itemList.Keys)
            {
                ITEM_INFO info  = itemList[dbid];
                Int32     id    = info.itemId;
                UInt64    uid   = info.UUID;
                Int32     index = info.itemIndex;
                UInt32    count = info.itemCount;
                _inventory.addItemToInventory(id, uid, (int)count, index);
                _inventory.updateItemList();
                _inventory.stackableSettings();
            }
        }
        if (_equipInventory != null)
        {
            foreach (UInt64 dbid in equipItemDict.Keys)
            {
                ITEM_INFO info  = equipItemDict[dbid];
                Int32     id    = info.itemId;
                UInt64    uid   = info.UUID;
                Int32     index = info.itemIndex;
                _equipInventory.addItemToInventory(id, uid, 1, index);
                _equipInventory.updateItemList();
                _equipInventory.stackableSettings();
            }
        }
    }