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}"); } }
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)); } }
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()); }
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++; }
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; } }
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); }
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(); } }
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}"); } }
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()); } } }
public void TestPlus() { SQLiteBD.ExecuteQueryWithoutAnswer("UPDATE Players SET sawmillLVL = (sawmillLVL+1) WHERE id = 1"); }
public void TestInsert() { SQLiteBD.ExecuteQueryWithoutAnswer("Insert Into Items (itemCount,nameItem,ItemRarityID,ItemType)" + "VALUES (20,'Medium Rock',1,3)"); Debug.Log("Success"); }
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); } } }
public void DeleteOrder() { SQLiteBD.ExecuteQueryWithoutAnswer($"UPDATE orders SET textOrder = NULL, timeToNewOrder = '{DateTime.UtcNow.AddMinutes(5).ToString("u")}' WHERE OrderID = {GameController.activeOrderID}"); GenerateOrders(); }
public void TestDeleteQuery() { SQLiteBD.ExecuteQueryWithoutAnswer("Delete from items where itemid = 3"); Debug.Log("Success"); }