public void getReward(string nickname, bool isWinner = false) { Reward reward = new Reward(); if (isWinner) { reward.Exp = Formulas.RndNext(245, 255); reward.Score = Formulas.RndNext(123, 133); if (Formulas.RndNext(0, 3) == 1) //drop card % winner { List <Card> clst = Card.GetAllavailableCardsByNickName(nickname); if (clst.Count > 1) { reward.NewCard = clst[Formulas.RndNext(0, clst.Count)]; } } WinGamerReward = reward; } else { reward.Exp = Formulas.RndNext(123, 133); reward.Score = Formulas.RndNext(62, 72); if (Formulas.RndNext(0, 6) == 1) //drop card % looser { List <Card> clst = Card.GetAllavailableCardsByNickName(nickname); if (clst.Count > 1) { reward.NewCard = clst[Formulas.RndNext(0, clst.Count)]; } } LooseGamerReward = reward; } }
public List <Card> BuyCard(string user, int number) { if (sqlInjection.Words.Any(word => user.IndexOf(word, StringComparison.OrdinalIgnoreCase) >= 0)) { return(null); } int char_id = -1; bool udovlet = true; List <Card> result = new List <Card>(); SqlConnection db_connection = new SqlConnection(Program.connectionString); try { db_connection.Open(); SqlCommand cmd = new SqlCommand("SELECT id, character_level, score FROM characters where account='" + user + "'", db_connection); SqlDataReader res = cmd.ExecuteReader(); if (res.Read()) { char_id = (int)res["id"]; int score = (int)res["score"]; int char_level = (int)res["character_level"]; res.Close(); if (char_level < 3 && number > 1) { udovlet = false; } if (udovlet && ((score >= 2000 && number == 1) || (score >= 4000 && number == 2) || (score >= 8000 && number == 3))) { int slot = GetFreeSlotNumberAllCards(user); List <Card> cclist; int card_id1 = -1; int card_id2 = -1; int card_id3 = -1; bool find = false; cclist = Card.GetAllavailableCards(user); if (cclist.Count > 0) { if (number == 1) { result.Add(cclist[Formulas.RndNext(0, cclist.Count)]); result.Add(cclist[Formulas.RndNext(0, cclist.Count)]); result.Add(cclist[Formulas.RndNext(0, cclist.Count)]); card_id1 = result[0].id; card_id2 = result[1].id; card_id3 = result[2].id; score -= 2000; } else if (number == 2) { find = false; while (!find) { Card cc = cclist[Formulas.RndNext(0, cclist.Count)]; if (cc.cardRarity >= 2) { result.Add(cc); find = true; } } result.Add(cclist[Formulas.RndNext(0, cclist.Count)]); result.Add(cclist[Formulas.RndNext(0, cclist.Count)]); card_id1 = result[0].id; card_id2 = result[1].id; card_id3 = result[2].id; score -= 4000; } else if (number == 3) { find = false; while (!find) { Card cc = cclist[Formulas.RndNext(0, cclist.Count)]; if (cc.cardRarity >= 2) { result.Add(cc); find = true; } } find = false; while (!find) { Card cc = cclist[Formulas.RndNext(0, cclist.Count)]; if (cc.cardRarity >= 2) { result.Add(cc); find = true; } } result.Add(cclist[Formulas.RndNext(0, cclist.Count)]); card_id1 = result[0].id; card_id2 = result[1].id; card_id3 = result[2].id; score -= 8000; } if (card_id1 != -1 && card_id2 != -1 && card_id3 != -1) { cmd = new SqlCommand("UPDATE characters SET score=" + score + " WHERE id=" + char_id, db_connection); cmd.ExecuteNonQuery(); cmd = new SqlCommand("INSERT INTO character_cards(char_id, card_id, slot) VALUES (" + char_id + ", " + card_id1 + ", " + slot + ")", db_connection); cmd.ExecuteNonQuery(); cmd = new SqlCommand("INSERT INTO character_cards(char_id, card_id, slot) VALUES (" + char_id + ", " + card_id2 + ", " + (slot + 1) + ")", db_connection); cmd.ExecuteNonQuery(); cmd = new SqlCommand("INSERT INTO character_cards(char_id, card_id, slot) VALUES (" + char_id + ", " + card_id3 + ", " + (slot + 2) + ")", db_connection); cmd.ExecuteNonQuery(); } } } } res.Close(); } catch (Exception exc) { Console.WriteLine("ERROR: " + exc.Message + "\r\n" + exc.StackTrace); Program.dumpException(exc); } db_connection.Close(); return(result); }