Beispiel #1
0
        public static void CreateDialStats(List <IClick> clicks, int number)
        {
            SqlConnection connection = MageKnightDataDB.GetConnection();
            string        selectStatement
                = "SELECT Id "
                  + "FROM AllMageKnights "
                  + "WHERE [Index] = @number";
            SqlCommand selectCommand = new SqlCommand(selectStatement, connection);

            selectCommand.Parameters.AddWithValue("@number", number);

            try
            {
                connection.Open();
                MageData      data   = new MageData();
                SqlDataReader reader = selectCommand.ExecuteReader(System.Data.CommandBehavior.SingleRow);
                if (reader.Read())
                {
                    Guid id = Guid.Parse(reader["Id"].ToString());
                    InsertClickValues(clicks, id);
                    InsertClickAbilites(clicks, id);
                }

                connection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show($"something is wrong GetMageKnight:{ex.ToString()}");
            }
        }
Beispiel #2
0
        public static MageKnightData GetMageKnight(int index)
        {
            SqlConnection connection = MageKnightDataDB.GetConnection();
            string        selectStatment
                = "SELECT Id, [Index], [Set], Name, PointValue, Faction, FrontArc, Targets, Range, Rank, Rarity, ModelImage "
                  + "FROM AllMageKnights "
                  + "WHERE [Index] = @Index";
            SqlCommand selectCommand = new SqlCommand(selectStatment, connection);

            selectCommand.Parameters.AddWithValue("@Index", index);

            try
            {
                connection.Open();
                MageData       data   = new MageData();
                MageKnightData mage   = null;
                SqlDataReader  reader = selectCommand.ExecuteReader(System.Data.CommandBehavior.SingleRow);
                if (reader.Read())
                {
                    data.Id         = Guid.Parse(reader["Id"].ToString());
                    data.Index      = Int32.Parse(reader["Index"].ToString());
                    data.Name       = reader["Name"].ToString();
                    data.Faction    = reader["Faction"].ToString();
                    data.Set        = reader["Set"].ToString();
                    data.PointValue = Int32.Parse(reader["PointValue"].ToString());
                    data.Range      = Int32.Parse(reader["Range"].ToString());
                    data.FrontArc   = Int32.Parse(reader["FrontArc"].ToString());
                    data.Targets    = Int32.Parse(reader["Targets"].ToString());
                    data.Rank       = reader["Rank"].ToString();
                    data.Faction    = reader["Faction"].ToString();
                    data.ModelImage = reader["ModelImage"] as byte[];
                    data.Dial       = GetDialStats(data);
                    mage            = new MageKnightData(data);
                }

                connection.Close();

                return(mage);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"something is wrong GetMageKnight:{ex.ToString()}");
            }
            finally
            {
                connection.Close();
            }

            return(null);
        }
Beispiel #3
0
        public static List <MageKnightData> GetMageKnights()
        {
            List <MageKnightData> mageKnights = new List <MageKnightData>();

            SqlConnection connection = MageKnightDataDB.GetConnection();
            string        selectStatement
                = "SELECT Id, [Index], [Set], Name, PointValue, Faction, FrontArc, Targets, Range, Rank, Rarity, ModelImage "
                  + "FROM AllMageKnights ";
            SqlCommand selectCommand = new SqlCommand(selectStatement, connection);

            try
            {
                connection.Open();

                SqlDataReader reader = selectCommand.ExecuteReader();


                while (reader.Read())
                {
                    MageData data = new MageData();
                    data.Id         = Guid.Parse(reader["Id"].ToString());
                    data.Index      = Int32.Parse(reader["Index"].ToString());
                    data.Name       = reader["Name"].ToString();
                    data.Faction    = reader["Faction"].ToString();
                    data.Set        = reader["Set"].ToString();
                    data.PointValue = Int32.Parse(reader["PointValue"].ToString());
                    data.Range      = Int32.Parse(reader["Range"].ToString());
                    data.FrontArc   = Int32.Parse(reader["FrontArc"].ToString());
                    data.Targets    = Int32.Parse(reader["Targets"].ToString());
                    data.Rank       = reader["Rank"].ToString();
                    data.Faction    = reader["Faction"].ToString();
                    data.ModelImage = reader["ModelImage"] as byte[];
                    data.Dial       = GetDialStats(data);
                    MageKnightData mage = new MageKnightData(data);
                    mageKnights.Add(mage);
                }



                connection.Close();

                return(mageKnights);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"something is wrong GetMageKnight:{ex.ToString()}");
            }

            return(null);
        }
        public static void AddMageToInventory(Guid mageId, Guid userId)
        {
            SqlConnection connection = MKUserDataDB.GetConnection();
            string        selectStatement
                = "SELECT UserId, MageId, Quantity " +
                  "FROM UserInventory " +
                  "WHERE UserId = @UserId AND MageId = @MageId ";

            SqlCommand selectCommand = new SqlCommand(selectStatement, connection);

            selectCommand.Parameters.AddWithValue("@UserId", userId);
            selectCommand.Parameters.AddWithValue("@MageId", mageId);

            try
            {
                bool isDuplicate = false;
                connection.Open();
                UserData        user       = new UserData();
                SqlDataReader   reader     = selectCommand.ExecuteReader();
                List <MageData> duplicates = new List <MageData>();
                while (reader.Read())
                {
                    MageData data = new MageData();
                    data.Id = Guid.Parse(reader["MageId"].ToString());
                    duplicates.Add(data);
                }

                connection.Close();

                if (duplicates.Count() == 0)
                {
                    InsertNewMage(mageId, userId);
                }
                else
                {
                    UpdateMageQuantity(mageId, userId, duplicates.Count());
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
            finally
            {
                connection.Close();
            }
        }
Beispiel #5
0
        private static DialData GetDialStats(MageData data)
        {
            SqlConnection connection = MageKnightDataDB.GetConnection();
            string        selectStatement
                = "SELECT Speed, Attack, Defense, Damage, [Index] "
                  + "FROM ClickValues "
                  + "WHERE Id = @Id";
            SqlCommand selectCommand = new SqlCommand(selectStatement, connection);

            selectCommand.Parameters.AddWithValue("@Id", data.Id);
            DialData dial = new DialData(data);

            try
            {
                connection.Open();
                SqlDataReader reader = selectCommand.ExecuteReader();
                while (reader.Read())
                {
                    StatData speed   = new StatData(StatType.Speed);
                    StatData attack  = new StatData(StatType.Attack);
                    StatData defense = new StatData(StatType.Defense);
                    StatData damage  = new StatData(StatType.Damage);

                    speed.Value   = Int32.Parse(reader["Speed"].ToString());
                    attack.Value  = Int32.Parse(reader["Attack"].ToString());
                    defense.Value = Int32.Parse(reader["Defense"].ToString());
                    damage.Value  = Int32.Parse(reader["Damage"].ToString());
                    int       index = Int32.Parse(reader["Index"].ToString());
                    ClickData click = new ClickData(speed, attack, defense, damage, index);
                    dial.Clicks.Add(click);
                }

                connection.Close();
                return(FillDialSpecialAbilities(dial, data.Id));
            }
            catch (Exception ex)
            {
                MessageBox.Show($"something is wrong GetMageKnight:{ex.ToString()}");
            }

            return(null);
        }
 public MageKnightData(MageData data)
 {
     this.data = data;
 }
Beispiel #7
0
        public static MageKnightData GenerateMageKnight(MageData data)
        {
            SqlConnection connection      = MageKnightDataDB.GetConnection();
            string        insertStatement =
                "INSERT Into AllMageKnights " +
                "(Id, [Index], [Set], Name, PointValue, Faction, FrontArc, Targets, Range, Rank, Rarity, ModelImage, PriceValue)" +
                "VALUES(@Id, @Index, @Set, @Name, @PointValue, @Faction, @FrontArc, @Targets, @Range, @Rank, @Rarity, @ModelImage, @PriceValue)";

            SqlCommand insertCommand = new SqlCommand(insertStatement, connection);

            insertCommand.Parameters.AddWithValue(
                "@Id", data.Id);

            insertCommand.Parameters.AddWithValue(
                "@Index", data.Index);
            insertCommand.Parameters.AddWithValue(
                "@Set", data.Set);
            insertCommand.Parameters.AddWithValue(
                "@Name", data.Name);
            insertCommand.Parameters.AddWithValue(
                "@PointValue", data.PointValue);
            insertCommand.Parameters.AddWithValue(
                "@Faction", data.Faction);
            insertCommand.Parameters.AddWithValue(
                "@FrontArc", data.FrontArc);
            insertCommand.Parameters.AddWithValue(
                "@Targets", data.Targets);
            insertCommand.Parameters.AddWithValue(
                "@Range", data.Range);
            insertCommand.Parameters.AddWithValue(
                "@Rank", data.Rank);
            insertCommand.Parameters.AddWithValue(
                "@Rarity", data.Rarity);

            //FileStream fs = new FileStream(data.ModelImage, FileMode.Open, FileAccess.Read); //Path is image location
            //Byte[] bindata = new byte[Convert.ToInt32(fs.Length)];
            //fs.Read(bindata, 0, Convert.ToInt32(fs.Length));

            insertCommand.Parameters.AddWithValue(
                "@ModelImage", data.ModelImage);
            insertCommand.Parameters.AddWithValue(
                "@PriceValue", data.PriceValue);

            try
            {
                connection.Open();
                int count = insertCommand.ExecuteNonQuery();
                if (count < 0)
                {
                    return(null);
                }
                else
                {
                    return(GetMageKnight(data.Id));
                }
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
                throw;
            }
            finally
            {
                connection.Close();
            }
        }
Beispiel #8
0
        public static MageKnightData GetRandomMage(BoosterPack set)
        {
            int rarityFilter = RandomNumber(1, 1000);
            int rarity       = 1;

            if (rarityFilter < 250) //  %25 chance of pulling rarity 1
            {
                rarity = 1;
            }
            else if (rarityFilter >= 250 && rarityFilter < 450) //  %20 chance of pulling rarity 2
            {
                rarity = 2;
            }
            else if (rarityFilter >= 450 && rarityFilter < 620) // %17
            {
                rarity = 3;
            }
            else if (rarityFilter >= 620 && rarityFilter < 760)// %14
            {
                rarity = 4;
            }
            else if (rarityFilter >= 760 && rarityFilter < 890)//  %13
            {
                rarity = 5;
            }
            else if (rarityFilter >= 500 && rarityFilter < 980)//  %9
            {
                rarity = 6;
            }
            else if (rarityFilter >= 980 && rarityFilter <= 1000)//  %2
            {
                rarity = 7;
            }

            SqlConnection connection = MageKnightDataDB.GetConnection();
            string        selectStatement
                = "SELECT Id, [Index], [Set], Name, PointValue, Faction, FrontArc, Targets, Range, Rank, Rarity, ModelImage "
                  + "FROM AllMageKnights "
                  + "WHERE Rarity = @Rarity";

            SqlCommand selectCommand = new SqlCommand(selectStatement, connection);

            selectCommand.Parameters.AddWithValue(
                "@Rarity", rarity);

            try
            {
                connection.Open();

                SqlDataReader reader = selectCommand.ExecuteReader();

                List <MageData> mages = new List <MageData>();
                while (reader.Read())
                {
                    MageData data = new MageData();
                    data.Id         = Guid.Parse(reader["Id"].ToString());
                    data.Index      = Int32.Parse(reader["Index"].ToString());
                    data.Name       = reader["Name"].ToString();
                    data.Faction    = reader["Faction"].ToString();
                    data.Set        = reader["Set"].ToString();
                    data.PointValue = Int32.Parse(reader["PointValue"].ToString());
                    data.Range      = Int32.Parse(reader["Range"].ToString());
                    data.FrontArc   = Int32.Parse(reader["FrontArc"].ToString());
                    data.Targets    = Int32.Parse(reader["Targets"].ToString());
                    data.Rank       = reader["Rank"].ToString();
                    data.Faction    = reader["Faction"].ToString();
                    data.ModelImage = reader["ModelImage"] as byte[];
                    data.Dial       = GetDialStats(data);
                    mages.Add(data);
                }

                int randomlySelectedIndex = RandomNumber(0, mages.Count - 1);

                connection.Close();

                MageKnightData mage = new MageKnightData(mages.ElementAt(randomlySelectedIndex));
                return(mage);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"something is wrong GetMageKnight:{ex.ToString()}");
            }

            return(null);
        }