Exemple #1
0
    public void DropItem(Item itemToDrop)
    {
        GameObject dropObj = world.SpawnObject("P_DroppedItem", transform.position);

        if (dropObj == null || itemToDrop == null)
        {
            return;
        }

        DroppedItem itemContainer = dropObj.GetComponent <DroppedItem>();

        if (itemContainer == null)
        {
            return;
        }

        if (itemToDrop.GetType() == typeof(CraftingItem))
        {
            itemContainer.DropCraftingItem(this, (CraftingItem)itemToDrop);
        }
        else
        {
            itemContainer.Drop(this, itemToDrop.GetType());
        }
    }
Exemple #2
0
    // Spawns an item from the bots drop list, returns the item dropped
    protected void DropItemFromList()
    {
        if (dropList == null)
        {
            return;
        }
        if (dropList.Length == 0)
        {
            return;
        }

        // Decide on the item type
        int dropIdx = Random.Range(0, dropList.Length - 1);

        // Crafting items only get dropped some percentage of the time, based on their rarity score
        if (dropList[dropIdx].GetType() == typeof(CraftingItem))
        {
            CraftingItem craftingItem = (CraftingItem)dropList[dropIdx];

            int randDropProb = Random.Range(0, 100);
            if (randDropProb > craftingItem.rarityScore)
            {
                return;
            }
        }

        // Spawn the container object
        GameObject dropObj = world.SpawnObject("P_DroppedItem", transform.position);

        if (dropObj == null)
        {
            Debug.Log("ERROR! Failed to spawn a DroppedItem container from " + name);
            return;
        }

        DroppedItem droppedContainter = dropObj.GetComponent <DroppedItem>();

        if (droppedContainter == null)
        {
            Debug.Log("ERROR! DroppedItem object " + dropObj.name + " doesn't have a DroppedItem component!");
            return;
        }

        if (dropList[dropIdx].GetType() == typeof(CraftingItem))
        {
            droppedContainter.DropCraftingItem(this, (CraftingItem)dropList[dropIdx]);
        }
        else
        {
            droppedContainter.Drop(this, dropList[dropIdx].GetType());
        }
    }