public void Target_UCE_StartUpgradePlaceableObjectClient(NetworkConnection target, NetworkIdentity ni)
    {
        if (ni != null)
        {
            UCE_PlaceableObject po = ni.GetComponent<UCE_PlaceableObject>();
            Entity e = po.GetComponent<Entity>();

            if (e != null)
            {
                LookAtY(po.gameObject.transform.position);
                UCE_myPlaceableObject = po;
                UCE_setTimer(po.getUpgradeCost(e.level).duration);
                UCE_CastbarShow(UCE_MSG_PLACEABLEOBJECT_UPGRADE, po.getUpgradeCost(e.level).duration);
            }
        }
    }
    // -----------------------------------------------------------------------------------
    // 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);
    }
    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
                }
            }
        }
    }
    public void Cmd_UCE_StartUpgradePlaceableObject(NetworkIdentity ni)
    {
        if (ni != null)
        {
            UCE_PlaceableObject po = ni.GetComponent<UCE_PlaceableObject>();

            if (UCE_CanUpgradePlaceableObject(po))
            {
                Entity e = po.GetComponent<Entity>();

                if (e != null)
                {
                    UCE_addTask();
                    UCE_myPlaceableObject = po;
                    UCE_setTimer(po.getUpgradeCost(e.level).duration);
                    Target_UCE_StartUpgradePlaceableObjectClient(connectionToClient, ni);
                }
            }
        }
    }