Ejemplo n.º 1
0
    private void AddItems()
    {
        int x = 0;
        int y = 0;

        var data = SQLiteBD.GetTable($"SELECT itemId,itemCount FROM PlayersItems" +
                                     $" WHERE playerId = 1 AND itemId IN (SELECT itemID From Items WHERE itemType NOT IN (4))");

        for (int i = 0; i < data.Rows.Count; i++)
        {
            int childCount = transform.childCount;

            var newItem = Instantiate(inventoryItemPrefab,
                                      new Vector3(startPos.x + _xOffset * x,
                                                  startPos.y + _yOffset * y,
                                                  transform.position.z),
                                      Quaternion.identity,
                                      transform);
            newItem.name = $"{inventoryItemPrefab.name} {transform.childCount}";
            StartCoroutine(GetComponent <LoadItem>().LoadIemIconFromWorkshop(
                               int.Parse(data.Rows[i][0].ToString()),
                               newItem));

            newItem.GetComponentInChildren <TMPro.TextMeshProUGUI>().text = data.Rows[i][1].ToString();

            x++;
            if (x > 2)
            {
                x = 0;
                y++;
            }
        }
        //todo height content
    }
Ejemplo n.º 2
0
    public static System.Data.DataTable GetOrderTable(Order order)
    {
        StringBuilder itemsIDStr = new StringBuilder();

        for (int i = 0; i < order.items.Count; i++)
        {
            if (itemsIDStr.Length > 0)
            {
                itemsIDStr.Append(',');
            }
            itemsIDStr.Append(order.items[i].itemId.ToString());
        }
        Debug.Log(itemsIDStr);
        return(SQLiteBD.GetTable($"SELECT PlayersItems.itemID,itemCount,Items.itemCost FROM PlayersItems " +
                                 $"INNER JOIN Items ON Items.ItemID = PlayersItems.ItemID " +
                                 $"WHERE playerID = {PlayerID} AND Playersitems.itemID IN ({itemsIDStr})"));
    }
Ejemplo n.º 3
0
    private void Start()
    {
        var data = SQLiteBD.GetTable($"SELECT itemID,TimeToCraft,craftID FROM CraftItems WHERE playerID = {GameController.PlayerID}");

        for (int i = 0; i < data.Rows.Count; i++)
        {
            TimeSpan craftTime = DateTime.Parse(data.Rows[i][1].ToString()) - DateTime.UtcNow.AddHours(8);
            if (craftTime.TotalSeconds <= 0)
            {
                craftTime = new TimeSpan(0, 0, 0);
            }
            CreateItemFunction(
                int.Parse(data.Rows[i][0].ToString()),
                int.Parse(data.Rows[i][2].ToString()),
                craftTime);
        }
    }
Ejemplo n.º 4
0
    private void OnMouseDown()
    {
        var craftItemInfo = GetComponent <CraftItemInfo>();
        var data          = SQLiteBD.GetTable($"SELECT * FROM PlayersItems WHERE playerID = {GameController.PlayerID} AND itemID = {craftItemInfo.ItemID}");

        if (data.Rows.Count > 0)
        {
            SQLiteBD.ExecuteQueryWithoutAnswer($"UPDATE playersItems SET itemCount = (itemCount + 1) WHERE playerID = {GameController.PlayerID} AND itemID = {craftItemInfo.ItemID}");
        }
        else
        {
            SQLiteBD.ExecuteQueryWithoutAnswer($"INSERT INTO PlayersItems VALUES ({GameController.PlayerID},{craftItemInfo.ItemID},1)");
        }

        SQLiteBD.ExecuteQueryWithoutAnswer($"DELETE FROM CraftItems WHERE craftID = {craftItemInfo.CraftID}");
        GetComponentInParent <CreateItem>().ItemUpdate();
        Destroy(gameObject);
    }
Ejemplo n.º 5
0
    public void TestSelect()
    {
        DataTable test = SQLiteBD.GetTable("SELECT itemId, nameItem, ItemsType.name FROM Items " +
                                           "INNER JOIN ItemsType ON Items.itemType = ItemsType.idItemsType;");

        //int idCountFirstItem = int.Parse(test.Rows[0][1].ToString());
        for (int i = 0; i < test.Rows.Count; i++)
        {
            string gg = "";
            for (int j = 0; j < test.Columns.Count; j++)
            {
                gg += test.Rows[i][j] + " /";
            }
            Debug.Log("Select:  " + gg);
        }

        //Debug.Log($"Test Query = {idCountFirstItem}");
    }
Ejemplo n.º 6
0
    private void Start()
    {
        string unitType = "";

        if (isChopper)
        {
            unitType = "1";
        }
        else
        {
            unitType = "2";
        }
        DataTable data =
            SQLiteBD.GetTable($"SELECT TimeToEnd,speed,effectivity,unitID FROM Units WHERE playerId = {GameController.PlayerID} AND unitType = {unitType} ORDER BY unitID");

        maxUnitID = int.Parse(SQLiteBD.ExecuteQueryWithAnswer($"SELECT MAX(unitID) FROM Units")) + 1;
        if (data.Rows.Count > 0)
        {
            for (int i = 0; i < data.Rows.Count; i++)
            {
                TimeSpan second;
                DateTime unitTime = DateTime.ParseExact(data.Rows[i][0].ToString(), "u", CultureInfo.InvariantCulture).AddHours(2);
                if (unitTime > DateTime.UtcNow)
                {
                    second = unitTime - System.DateTime.UtcNow;
                }
                else
                {
                    second = TimeSpan.Zero;
                }
                AddUnitInDB(Mathf.RoundToInt(float.Parse(second.TotalSeconds.ToString())), //seconds
                            float.Parse(data.Rows[i][1].ToString()),                       // speed
                            int.Parse(data.Rows[i][2].ToString()),                         // effectivity
                            int.Parse(data.Rows[i][3].ToString())
                            );
            }
        }
    }
Ejemplo n.º 7
0
    private void GenerateOrders()
    {
        //взять текущие заказы из базы данных
        data = SQLiteBD.GetTable($"SELECT TextOrder,orderID,TimeTonewOrder FROM orders WHERE playerID = {GameController.PlayerID}");

        for (int i = 0; i < data.Rows.Count; i++)
        {
            cashOrder       = new Order();
            cashOrder.items = new List <Item>();
            string JSON = data.Rows[i][0].ToString();
            if (JSON == "")
            {
                // кеширование текущих предметов
                if (itemsIDArray == null)
                {
                    var itemData = SQLiteBD.GetTable("SELECT itemID FROM Items WHERE Itemtype NOT IN (4)");
                    itemsIDArray = new int[itemData.Rows.Count];
                    for (int j = 0; j < itemData.Rows.Count; j++)
                    {
                        itemsIDArray[j] = int.Parse(itemData.Rows[j][0].ToString());
                    }
                }

                foreach (var item in itemsIDArray)
                {
                    itemsIDList.Add(item);
                }

                //поставить новому заказу случайную длину от 1 до 4
                int orderLeght = Random.Range(1, 5);

                for (int j = 0; j < orderLeght; j++)
                {
                    //выбор случайного предмета
                    int itemID = itemsIDList[Random.Range(0, itemsIDList.Count)];
                    //удаление предмета из кеширивания
                    itemsIDList.Remove(itemID);
                    cashOrder.items.Add(new Item
                    {
                        itemId = itemID,
                        count  = Random.Range(1, 4)
                    });
                    Debug.Log($"ItemID: {cashOrder.items[j].itemId} count: {cashOrder.items[j].count}");
                }
                itemsIDList.Clear();
                cashOrder.orderCost = cashOrder.CalculatinTheOrderCost(cashOrder);

                SQLiteBD.ExecuteQueryWithoutAnswer($"UPDATE orders SET textOrder = '{JsonUtility.ToJson(cashOrder)}' WHERE orderID = {i + 1}");
            }
            else
            {
                cashOrder = JsonUtility.FromJson <Order>(JSON);
            }
            var child = transform.GetChild(i).GetComponent <SetActiveOrder>();
            child.order   = cashOrder;
            child.orderID = int.Parse(data.Rows[i][1].ToString());

            string timeToNewOrder = data.Rows[i][2].ToString();

            if (timeToNewOrder != "")
            {
                child.SetTimeOrder(DateTime.Parse(timeToNewOrder) - DateTime.UtcNow.AddHours(8));
            }
            else
            {
                child.SetTimeOrder(TimeSpan.Zero);
            }
        }
    }