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
                }
            }
        }
    }
    // -----------------------------------------------------------------------------------
    // 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);
    }
    // -----------------------------------------------------------------------------------
    // SpawnRTSStructures
    // -----------------------------------------------------------------------------------
    protected IEnumerator SpawnRTSStructures()
    {
        List <List <object> > table = Database.singleton.UCE_LoadPlaceableObjects();

        foreach (List <object> row in table)
        {
            string itemName = (string)row[9];

            if (((UCE_Item_PlaceableObject)ScriptableItem.dict[itemName.GetStableHashCode()]).placementObject)
            {
                Vector3 v = new Vector3(
                    (float)row[2],
                    (float)row[3],
                    (float)row[4]);

                Quaternion rotation = Quaternion.Euler((float)row[5], (float)row[6], (float)row[7]);

                GameObject go = (GameObject)Instantiate(((UCE_Item_PlaceableObject)ScriptableItem.dict[itemName.GetStableHashCode()]).placementObject, v, rotation);

                UCE_PlaceableObject po = go.GetComponent <UCE_PlaceableObject>();

                if (po)
                {
                    po.permanent      = true;
                    po.ownerCharacter = (string)row[0];
                    po.ownerGuild     = (string)row[1];
                    po.itemName       = itemName; // row 9

#if _SQLITE
                    po.id = Convert.ToInt32((long)row[10]);
#elif _MYSQL
                    po.id = (int)row[10];
#endif

                    Entity e = po.GetComponent <Entity>();

                    if (e)
                    {
#if _SQLITE
                        e.level = Convert.ToInt32((long)row[8]);
#elif _MYSQL
                        e.level = (int)row[8];
#endif
                    }
                }

                NetworkServer.Spawn(go);
            }
        }

        yield return(new WaitForEndOfFrame());
    }
    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);
            }
        }
    }
    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);
                }
            }
        }
    }
    public void Cmd_UCE_UnspawnPlaceableObject(NetworkIdentity ni)
    {
        if (ni != null)
        {
            UCE_PlaceableObject po = ni.GetComponent<UCE_PlaceableObject>();
            Entity e = po.GetComponent<Entity>();

            if (po &&
                po.pickupable &&
                po.ownerCharacter == this.name
            )
            {
                LookAtY(po.gameObject.transform.position);

                ScriptableItem item;

                if (ScriptableItem.dict.TryGetValue(po.itemName.GetStableHashCode(), out item))
                {
                    // -- enough inventory space?

                    Item result = new Item(item);

                    if (InventoryCanAdd(result, ((UCE_Item_PlaceableObject)item).decreaseAmount))
                    {
                        // -- delete object from database
                        Database.singleton.UCE_DeletePlaceableObject(this.name, this.guild.name, e.level, po.itemName, po.id);

                        // -- add it back to the inventory again
                        InventoryAdd(new Item(item), ((UCE_Item_PlaceableObject)item).decreaseAmount);

                        // -- remove the object
                        NetworkServer.Destroy(po.gameObject);
                    }
                }
            }
        }
    }
Beispiel #7
0
    // -----------------------------------------------------------------------------------
    // SpawnRTSStructures
    // -----------------------------------------------------------------------------------
    protected IEnumerator SpawnRTSStructures()
    {
#if _SERVER
        var table = Database.singleton.UCE_LoadPlaceableObjects();

        foreach (var row in table)
        {
#if _SQLITE
            string itemName = row.item;

            if (((UCE_Item_PlaceableObject)ScriptableItem.dict[itemName.GetStableHashCode()]).placementObject)
            {
                Vector3    v        = new Vector3(row.x, row.y, row.z);
                Quaternion rotation = Quaternion.Euler(row.xRot, row.yRot, row.zRot);
#elif _MYSQL
            string itemName = (string)row[9];

            if (((UCE_Item_PlaceableObject)ScriptableItem.dict[itemName.GetStableHashCode()]).placementObject)
            {
                Vector3 v = new Vector3(
                    (float)row[2],
                    (float)row[3],
                    (float)row[4]);

                Quaternion rotation = Quaternion.Euler((float)row[5], (float)row[6], (float)row[7]);
#endif
                GameObject          go = (GameObject)Instantiate(((UCE_Item_PlaceableObject)ScriptableItem.dict[itemName.GetStableHashCode()]).placementObject, v, rotation);
                UCE_PlaceableObject po = go.GetComponent <UCE_PlaceableObject>();

                if (po)
                {
                    po.permanent = true;
                    po.itemName  = itemName; // row 9
#if _SQLITE
                    po.ownerCharacter = row.character;
                    po.ownerGuild     = row.guild;
                    po.id             = row.id;
#elif _MYSQL
                    po.ownerCharacter = (string)row[0];
                    po.ownerGuild     = (string)row[1];
                    po.id             = (int)row[10];
#endif

                    Entity e = po.GetComponent <Entity>();

                    if (e)
                    {
#if _SQLITE
                        e.level = row.level;
#elif _MYSQL
                        e.level = (int)row[8];
#endif
                    }
                }

                NetworkServer.Spawn(go);
            }
        }
#endif
        yield return(new WaitForEndOfFrame());
    }

    // -----------------------------------------------------------------------------------
}