Example #1
0
    /// <summary>
    /// Adds the item with itemId. where itemId is the id which we registered with item prefab as unique.
    /// </summary>
    /// <returns>The item.</returns>
    /// <param name="itemId">Item identifier.</param>
    public BaseItemScript AddItem(int itemId, int instanceId, int posX, int posY, bool immediate, bool ownedItem)
    {
        BaseItemScript builder = null;

        Debug.LogError("CreateItemID:" + itemId);
        if (!immediate)
        {
//			builder = this.GetFreeBuilder();
//			if (builder == null)
//			{
//				Debug.Log("All builders are busy!");
//				UIManager.instance.ShowBuildersBusyWindow();
//				return null;
//			}
        }

        BaseItemScript instance = Utilities.CreateInstance(this.BaseItem, this.ItemsContainer, true).GetComponent <BaseItemScript>();

        if (instanceId == -1)
        {
            instanceId = this._GetUnusedInstanceId();
        }

        instance.instanceId = instanceId;
        this._itemInstances.Add(instanceId, instance);

        instance.SetItemData(itemId, posX, posY);
        instance.SetState(Common.State.IDLE);

        //		GroundManager.Cell freeCell = GroundManager.instance.GetRandomFreeCellForItem (instance);
        //		instance.SetPosition (GroundManager.instance.CellToPosition (freeCell));

        if (!immediate)
        {
            instance.UI.ShowProgressUI(true);

            if (!instance.itemData.configuration.isCharacter && instance.itemData.configuration.buildTime > 0)
            {
                if (builder != null)
                {
                    builder.BuilderAction(instance);
                }
            }
        }

        if (!instance.itemData.configuration.isCharacter)
        {
            GroundManager.instance.UpdateBaseItemNodes(instance, GroundManager.Action.ADD);
        }

        if (instance.itemData.name == "Wall")
        {
            this.UpdateWalls();
        }
        instance.ownedItem = ownedItem;
        return(instance);
    }