Exemplo n.º 1
0
    private void MinusResources()
    {
        int count = 0;

        if (recipe.CurrentUpgradeRecipe != null)
        {
            count = recipe.CurrentUpgradeRecipe.RecipesItemsID.Length;
        }
        else
        {
            count = recipe.CurrentItemRecipe.RecipesItemsID.Length;
        }

        for (int i = 0; i < count; i++)
        {
            int recipeResources = 0;
            int itemID          = 0;
            if (recipe.CurrentUpgradeRecipe != null)
            {
                recipeResources = recipe.CurrentUpgradeRecipe.RecipesCountItems[i];
                itemID          = recipe.CurrentUpgradeRecipe.RecipesItemsID[i];
            }
            else
            {
                recipeResources = recipe.CurrentItemRecipe.RecipesCountItems[i];
                itemID          = recipe.CurrentItemRecipe.RecipesItemsID[i];
            }
            SQLiteBD.ExecuteQueryWithoutAnswer($"UPDATE PlayersItems SET itemCount = (itemCount-{recipeResources}) WHERE playerID = {GameController.PlayerID} AND itemId = {itemID}");
        }
    }
Exemplo n.º 2
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
    }
Exemplo n.º 3
0
 private void AddItem(int itemID, DateTime timeToCraft)
 {
     if (ItemScript != null)
     {
         maxCratID++;
         SQLiteBD.ExecuteQueryWithoutAnswer($"INSERT INTO CraftItems (CraftID,ItemId,playerID,TimeToCraft) VALUES ({maxCratID},{itemID},{GameController.PlayerID},'{timeToCraft.ToString("u",CultureInfo.InvariantCulture)}')");
         ItemScript.CreateItemFunction(itemID, maxCratID, new TimeSpan(0, 0, recipe.SecondToCraft));
     }
 }
Exemplo n.º 4
0
    public static bool GetTokenInDB()
    {
        var DBtoken = SQLiteBD.ExecuteQueryWithAnswer($"SELECT token FROM players where id = {GameController.PlayerID}");

        if (!(DBtoken == string.Empty || DBtoken == null))
        {
            token = DBtoken;
            return(true);
        }
        return(false);
    }
    private IEnumerator UpdateCountResources()
    {
        yield return(new WaitForSeconds(1f));

        if (allgrindresources > 0)
        {
            SQLiteBD.ExecuteQueryWithoutAnswer($"UPDATE PlayersItems SET itemCount = (itemCount+{allgrindresources}) WHERE playerId = {GameController.PlayerID} AND itemId = {itemResourceId}");
        }
        //generalResources.text = (Convert.ToInt32(generalResources.text) + allgrindresources).ToString();
        StartCoroutine(UpdateCountResources());
    }
Exemplo n.º 6
0
    private IEnumerator GetStatsInBD()
    {
        //      new Thread(new ThreadStart(() =>
        //           {
        statsText.text = SQLiteBD.ExecuteQueryWithAnswer($"SELECT itemCount FROM PlayersItems WHERE itemId = {itemId} AND playerId = {GameController.PlayerID}");
        //           })).Start();
        //Debug.Log(statsText.text);
        yield return(new WaitForSeconds(1.0f));

        StartCoroutine(GetStatsInBD());
    }
Exemplo n.º 7
0
    public void UpgradeUnit()
    {
        string unitType = "";

        if (isChopper)
        {
            unitType = "1";
        }
        else
        {
            unitType = "2";
        }
        SQLiteBD.ExecuteQueryWithoutAnswer($"INSERT INTO Units (UnitID,UnitType,playerId) VALUES ({maxUnitID},{unitType},{GameController.PlayerID})");
        AddUnitInDB(0, 1.0f, 4, maxUnitID);
        maxUnitID++;
    }
Exemplo n.º 8
0
    public static async Task <AuthCode> PostToken(string login, string password)
    {
        try
        {
            using (HttpClient client = new HttpClient {
                Timeout = TimeSpan.FromSeconds(30)
            })
            {
                Uri uri     = new Uri(AuthServerUri, "connect/token");
                var request = new HttpRequestMessage(HttpMethod.Post, uri);

                Dictionary <string, string> values = new Dictionary <string, string>();

                values = new Dictionary <string, string>
                {
                    { "client_id", "company-employee" },
                    { "client_secret", "codemazesecret" },
                    { "grant_type", "password" },
                    { "username", login },
                    { "password", password }
                };
                request.Content = new FormUrlEncodedContent(values);
                request.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/x-www-form-urlencoded");
                HttpResponseMessage responce = await client.PostAsync(uri, request.Content);

                if (responce.IsSuccessStatusCode)
                {
                    byte[] result = await responce.Content.ReadAsByteArrayAsync();

                    token = JsonConvert.DeserializeObject
                            <Token>(Encoding.ASCII.GetString(result))
                            .access_token;
                    SQLiteBD.ExecuteQueryWithoutAnswer($"UPDATE players SET token = '{token}' WHERE id = {GameController.PlayerID}");
                    return(AuthCode.Sucsess);
                }
                return(AuthCode.ErrorLoginAndPass);
            }
        }
        catch (System.Exception ex)
        {
            Debug.LogError(ex.Message);
            return(AuthCode.NotConnect);

            throw;
        }
    }
Exemplo n.º 9
0
 private void Start()
 {
     try
     {
         maxCratID = int.Parse(SQLiteBD.ExecuteQueryWithAnswer("SELECT MAX(craftID) FROM CraftItems"));
     }
     catch (FormatException)
     {
         Debug.LogError("FormatE");
         maxCratID = 0;
     }
     catch (ArgumentNullException)
     {
         Debug.LogError("ArgNULL");
         maxCratID = 0;
     }
 }
Exemplo n.º 10
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);
        }
    }
Exemplo n.º 11
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})"));
    }
Exemplo n.º 12
0
    void Start()
    {
        _deltaX = 1.3f;
        _deltaY = -1.3f;
        int workshopLVL = int.Parse(SQLiteBD.ExecuteQueryWithAnswer($"SELECT workshopLVL FROM players WHERE selectedPlayer = 1"));

        int x = 0;
        int y = 0;

        for (int i = 0; i < itemsRecipes.Length; i++)
        {
            if (itemsRecipes[i].AccessLevel <= workshopLVL)
            {
                var newItem = Instantiate(itemPrefab,
                                          new Vector3(startPos.x + _deltaX * x,
                                                      startPos.y + _deltaY * y,
                                                      transform.position.z),
                                          Quaternion.identity,
                                          transform);
                newItem.name = $"{itemPrefab.name} {transform.childCount}";
                StartCoroutine(GetComponent <LoadItem>().LoadIemIconFromWorkshop(
                                   itemsRecipes[i].ItemID,
                                   newItem));
                newItem.GetComponent <ClickToItem>().recipe = itemsRecipes[i];
                //newItem.GetComponent<LoadItemRecipeOnBoard>().Recipe = itemsRecipes[i];
                x++;
                if (x > 2)
                {
                    x = 0;
                    y++;
                }
            }
        }

        if (y > 3)
        {
            RectTransform contentRect = GetComponent <RectTransform>();
            contentRect.sizeDelta = new Vector2(contentRect.sizeDelta.x,
                                                //distance between 2 item * rows.count * yOffset
                                                60 * y + 40);
            //RectTransform contentRect = GetComponent<RectTransform>();
            //contentRect.offsetMax += new Vector2(0, -50);
            //contentRect.offsetMin -= new Vector2(0, 50);
        }
    }
Exemplo n.º 13
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}");
    }
Exemplo n.º 14
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);
    }
Exemplo n.º 15
0
    public void _MinusPlayerResources(bool isSawmill)
    {
        recipe = GetComponent <AddRecipeOnScript>();
        if (recipe.CurrentUpgradeRecipe.RecipesItemsID.Length > 0)
        {
            MinusResources();

            string buildType = "";
            if (isSawmill)
            {
                buildType = "sawmillLVL";
            }
            else
            {
                buildType = "mineLVL";
            }
            SQLiteBD.ExecuteQueryWithoutAnswer($"UPDATE Players SET {buildType} = ({buildType}+1) WHERE id = {GameController.PlayerID}");
            //recipe.RecipreController.UpdateLVL();
        }
    }
Exemplo n.º 16
0
    private void MinusResourcesFromOrder()
    {
        for (int i = 0; i < order.items.Count + 1; i++)
        {
            int    itemId          = 0;
            string recousrcesCount = "";
            if (i == order.items.Count)
            {
                itemId          = 1;
                recousrcesCount = $"+{order.orderCost}";
            }
            else
            {
                itemId          = order.items[i].itemId;
                recousrcesCount = $"-{order.items[i].count}";
            }

            SQLiteBD.ExecuteQueryWithoutAnswer($"UPDATE PlayersItems SET itemCount = (itemCount{recousrcesCount}) WHERE playerID = {GameController.PlayerID} AND itemId = {itemId}");
        }
    }
Exemplo n.º 17
0
 private void OnMouseDown()
 {
     if (!_startWork)
     {
         _startWork = true;
         SQLiteBD.ExecuteQueryWithoutAnswer($"UPDATE Units SET timeToEnd = '{System.DateTime.UtcNow.ToString("u")}' WHERE unitID = {unitID}");
         StartCoroutine(StartStopWorking());
     }
     else
     {
         if (!_boost)
         {
             speedBoost = StartCoroutine(SpeedBoost());
         }
         else
         {
             StopCoroutine(speedBoost);
             speedBoost = StartCoroutine(SpeedBoost());
         }
     }
 }
Exemplo n.º 18
0
    public void UpdateLVL()
    {
        int sawmillLVL = int.Parse(SQLiteBD.ExecuteQueryWithAnswer($"SELECT sawmillLVL FROM Players WHERE id = {GameController.PlayerID}"));
        int mineLVL    = int.Parse(SQLiteBD.ExecuteQueryWithAnswer($"SELECT mineLVL FROM Players WHERE id = {GameController.PlayerID}"));

        if (ChoppersRecipes.Length < sawmillLVL)
        {
            ChoppersRecipes = new UpgradeRecipes[0];
        }
        else if (sawmillLVL > 1)
        {
            ChoppersRecipes = RemoveItems(ChoppersRecipes, ChoppersRecipes.Length - (sawmillLVL - 1), sawmillLVL - 1);
        }
        if (MinersRecipes.Length < mineLVL)
        {
            MinersRecipes = new UpgradeRecipes[0];
        }
        else if (mineLVL > 1)
        {
            MinersRecipes = RemoveItems(MinersRecipes, MinersRecipes.Length - (mineLVL - 1), mineLVL - 1);
        }
    }
Exemplo n.º 19
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())
                            );
            }
        }
    }
Exemplo n.º 20
0
 private void Awake()
 {
     GameController.PlayerID = int.Parse(SQLiteBD.ExecuteQueryWithAnswer("SELECT id FROM Players WHERE selectedPlayer = 1"));
 }
Exemplo n.º 21
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);
            }
        }
    }
Exemplo n.º 22
0
 public void DeleteOrder()
 {
     SQLiteBD.ExecuteQueryWithoutAnswer($"UPDATE orders SET textOrder = NULL, timeToNewOrder = '{DateTime.UtcNow.AddMinutes(5).ToString("u")}' WHERE OrderID = {GameController.activeOrderID}");
     GenerateOrders();
 }
Exemplo n.º 23
0
 public void TestDeleteQuery()
 {
     SQLiteBD.ExecuteQueryWithoutAnswer("Delete from items where itemid = 3");
     Debug.Log("Success");
 }
Exemplo n.º 24
0
 public void TestPlus()
 {
     SQLiteBD.ExecuteQueryWithoutAnswer("UPDATE Players SET sawmillLVL = (sawmillLVL+1) WHERE id = 1");
 }
Exemplo n.º 25
0
    public IEnumerator LoadIemIconFromWorkshop(int itemID, GameObject go)
    {
        if (itemID > 0 && go != null)
        {
            using (UnityWebRequest webRequest = UnityWebRequestTexture.GetTexture($"{Application.streamingAssetsPath + "/ItemsIcons"}" +
                                                                                  $"/{SQLiteBD.ExecuteQueryWithAnswer($"SELECT pathToSprite FROM Items WHERE itemID = {itemID}")}"))
            {
                yield return(webRequest.SendWebRequest());

                if (webRequest.isNetworkError)
                {
                    Debug.Log("Error: " + webRequest.error);
                }
                else
                {
                    //Debug.Log("Received: " + webRequest.downloadHandler);
                    Texture2D texture = DownloadHandlerTexture.GetContent(webRequest);
                    go.transform.GetChild(1).GetComponent <Image>().sprite =
                        Sprite.Create(
                            texture,
                            new Rect(0, 0, texture.width, texture.height),
                            new Vector2(0.5f, 0.5f));
                }
            }
        }
        else
        {
            Debug.LogError("Error: Load Item Sprite");
        }
        yield break;
    }
Exemplo n.º 26
0
 public void TestInsert()
 {
     SQLiteBD.ExecuteQueryWithoutAnswer("Insert Into Items (itemCount,nameItem,ItemRarityID,ItemType)" +
                                        "VALUES (20,'Medium Rock',1,3)");
     Debug.Log("Success");
 }
    IEnumerator LoadItemIcon(string uri, int childNumber, int currentID)
    {
        using (UnityWebRequest webRequest = UnityWebRequestTexture.GetTexture($"{uri}/{SQLiteBD.ExecuteQueryWithAnswer($"SELECT pathToSprite FROM Items WHERE itemID = {currentID}")}"))
        {
            yield return(webRequest.SendWebRequest());

            if (webRequest.isNetworkError)
            {
                Debug.Log("Error: " + webRequest.error);
            }
            else
            {
                //Debug.Log("Received: " + webRequest.downloadHandler);
                Texture2D texture = DownloadHandlerTexture.GetContent(webRequest);
                transform.GetChild(childNumber).GetChild(0).GetComponent <Image>().sprite = Sprite.Create(
                    texture,
                    new Rect(0, 0, texture.width, texture.height),
                    new Vector2(0.5f, 0.5f));
            }
        }
        yield break;
    }
    //[SerializeField] private UpgradeRecipes currentRecipe;
    private void OnEnable()
    {
        UpgradeRecipes currentRecipe = GetComponent <AddRecipeOnScript>().CurrentUpgradeRecipe;

        if (currentRecipe == null)
        {
            currentRecipe = GetComponent <AddRecipeOnScript>().CurrentItemRecipe;
        }
        bool allResourcesAvailable = false;

        if (currentRecipe != null)
        {
            byte countAvailable = 0;
            for (int i = 0; i < currentRecipe.RecipesItemsID.Length; i++)
            {
                var child     = transform.GetChild(i);
                var currentID = currentRecipe.RecipesItemsID[i];
                //set sprite
#if UNITY_EDITOR
                DirectoryInfo directoryInfo = new DirectoryInfo(Application.streamingAssetsPath + "/ItemsIcons");
                print(directoryInfo);
                FileInfo[] allFiles = directoryInfo.GetFiles("*.*");

                foreach (var file in allFiles)
                {
                    if (file.Name.Contains(SQLiteBD.ExecuteQueryWithAnswer($"SELECT pathToSprite FROM Items WHERE itemID = {currentID}")))
                    {
                        StartCoroutine(LoadItemIcon(file, i));
                    }
                }
#endif
#if UNITY_ANDROID
                //DirectoryInfo direcrotyInfo = new DirectoryInfo(Application.persistentDataPath);
                //DirectoryInfo direcrotyInfo = new DirectoryInfo()
                StartCoroutine(LoadItemIcon(Application.streamingAssetsPath + "/ItemsIcons", i, currentID));
#endif

                int             playerCount = int.Parse(SQLiteBD.ExecuteQueryWithAnswer($"SELECT ItemCount FROM PlayersItems WHERE itemId = {currentID} AND playerId = {GameController.PlayerID}"));
                TextMeshProUGUI childTMP    = child.GetChild(1).GetComponent <TextMeshProUGUI>();

                //set text color
                if (playerCount >= currentRecipe.RecipesCountItems[i])
                {
                    Debug.Log($"{gameObject.name} {countAvailable}//{currentRecipe.RecipesItemsID.Length}");
                    childTMP.color = Color.green;
                    countAvailable++;
                }
                else
                {
                    childTMP.color = Color.red;
                }
                if (countAvailable >= currentRecipe.RecipesItemsID.Length)
                {
                    allResourcesAvailable = true;
                }
                //Debug.Log($"{gameObject.name} {allResourcesAvailable}//{countAvailable}");

                childTMP.text = $"" +
                                $"{playerCount}" +
                                $"/{currentRecipe.RecipesCountItems[i]}";
                child.gameObject.SetActive(true);
            }
        }
        else
        {
            Debug.LogError("Not have a recipe");
        }
        if (allResourcesAvailable)
        {
            transform.GetChild(6).GetComponent <Button>().interactable = true;
        }
        else
        {
            transform.GetChild(6).GetComponent <Button>().interactable = false;
        }
    }