Exemple #1
0
 public void clearStatValues()
 {
     foreach (StatPair statPair in stats)
     {
         if (StatContainer.contains(statPair.stat.dbID))
         {
             statPair.value = 0;
         }
     }
 }
Exemple #2
0
        public static Item fetch(uint entry)
        {
            string conString = DBHelper.getConString();

            try
            {
                MySqlConnection con = new MySqlConnection();
                con.ConnectionString = conString;
                con.Open();

                string          query  = $"SELECT * FROM item_template WHERE entry={entry};";
                MySqlCommand    cmd    = new MySqlCommand(query, con);
                MySqlDataReader reader = cmd.ExecuteReader();

                reader.Read();

                Item item = new Item();

                item.entry      = uint.Parse(reader["entry"].ToString());
                item.statsCount = uint.Parse(reader["statscount"].ToString());

                Stat stat;
                int  value;

                stat  = StatContainer.getFromDBID(int.Parse(reader["stat_Type1"].ToString()));
                value = int.Parse(reader["stat_Value1"].ToString());
                if (value > 0 && StatContainer.contains(int.Parse(reader["stat_Type1"].ToString())))
                {
                    item.stats.Add(new StatPair(stat, value, 1));
                }

                stat  = StatContainer.getFromDBID(int.Parse(reader["stat_Type2"].ToString()));
                value = int.Parse(reader["stat_Value2"].ToString());
                if (value > 0 && StatContainer.contains(int.Parse(reader["stat_Type2"].ToString())))
                {
                    item.stats.Add(new StatPair(stat, value, 2));
                }

                stat  = StatContainer.getFromDBID(int.Parse(reader["stat_Type3"].ToString()));
                value = int.Parse(reader["stat_Value3"].ToString());
                if (value > 0 && StatContainer.contains(int.Parse(reader["stat_Type3"].ToString())))
                {
                    item.stats.Add(new StatPair(stat, value, 3));
                }

                con.Close();
                return(item);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            return(null);
        }
Exemple #3
0
        public static float calculate(Item item)
        {
            float budget = 0;

            foreach (StatPair pair in item.stats)
            {
                Stat stat = pair.stat;
                if (StatContainer.contains(stat.dbID))
                {
                    budget += stat.cost * pair.value;
                }
            }

            return(budget);
        }