// -----------------------------------------------------------------------------------
    // UCE_CanUpgradePlaceableObject
    // -----------------------------------------------------------------------------------
    public bool UCE_CanUpgradePlaceableObject(UCE_PlaceableObject po)
    {
        if (po)
        {
            Entity e = po.GetComponent <Entity>();

            if (e != null)
            {
                UCE_PlaceableObjectUpgradeCost c = po.getUpgradeCost(e.level);

                if (c != null)
                {
                    if (level >= c.minLevel &&
                        gold >= c.gold &&
                        coins >= c.coins &&
                        UCE_checkHasAllItems(c)
                        )
                    {
                        return(true);
                    }
                }
            }
        }

        return(false);
    }
 // -----------------------------------------------------------------------------------
 // UCE_checkHasAllItems
 // -----------------------------------------------------------------------------------
 public bool UCE_checkHasAllItems(UCE_PlaceableObjectUpgradeCost cost)
 {
     foreach (UCE_ItemRequirement reqitem in cost.requiredItems)
     {
         if (reqitem.item == null || InventoryCount(new Item(reqitem.item)) < reqitem.amount)
             return false;
     }
     return true;
 }
    public void Cmd_UCE_FinishUpgradePlaceableObject()
    {
        // -- Revalidate in case of anything changed while upgrading
        if (UCE_myPlaceableObject)
        {
            if (UCE_CanUpgradePlaceableObject(UCE_myPlaceableObject))
            {
                Entity e = UCE_myPlaceableObject.GetComponent <Entity>();

                if (e != null)
                {
                    UCE_removeTask();

                    // -- remove Resources & Items
                    UCE_PlaceableObjectUpgradeCost cost = UCE_myPlaceableObject.getUpgradeCost(e.level);

                    gold  -= cost.gold;
                    coins -= cost.coins;

                    foreach (UCE_ItemRequirement reqitem in cost.requiredItems)
                    {
                        if (reqitem.item == null || InventoryCount(new Item(reqitem.item)) >= reqitem.amount)
                        {
                            InventoryRemove(new Item(reqitem.item), reqitem.amount);
                        }
                    }

                    // -- delete the old object
                    if (UCE_myPlaceableObject.permanent)
                    {
                        Database.singleton.UCE_DeletePlaceableObject(this.name, this.guild.name, e.level, UCE_myPlaceableObject.itemName, UCE_myPlaceableObject.id);
                    }

                    // -- upgrade the Object
                    e.level++;

                    // -- save Object to database immediately
                    if (UCE_myPlaceableObject.permanent)
                    {
                        Database.singleton.UCE_DeletePlaceableObject(this.name, this.guild.name, e.level, UCE_myPlaceableObject.itemName, UCE_myPlaceableObject.id);
                        Database.singleton.UCE_SavePlaceableObject(this.name, this.guild.name, UCE_myPlaceableObject.gameObject, e.level, UCE_myPlaceableObject.itemName, UCE_myPlaceableObject.id);
                    }

                    // -- reset the Attache (if any)
#if _iMMOATTACHE
                    Monster m = UCE_myPlaceableObject.GetComponent <Monster>();
                    if (m != null)
                    {
                        m.UCE_AttacheReset();
                    }
#endif
                }
            }
        }
    }