Example #1
0
        public static List <MonType> GetAllMonTypes()
        {
            List <MonType> allMonTypes = new List <MonType> {
            };
            MySqlConnection conn       = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM monTypes;";
            var rdr = cmd.ExecuteReader() as MySqlDataReader;

            while (rdr.Read())
            {
                int     MonTypeId   = rdr.GetInt32(0);
                string  MonTypeName = rdr.GetString(1);
                MonType newMonType  = new MonType(MonTypeName, MonTypeId);
                allMonTypes.Add(newMonType);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(allMonTypes);
            // return new List<MonType>{};
        }
Example #2
0
        public static MonType Find(int id)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM monTypes WHERE id = (@searchId);";

            cmd.Parameters.Add(new MySqlParameter("@searchId", id));

            var    rdr         = cmd.ExecuteReader() as MySqlDataReader;
            int    MonTypeId   = 0;
            string MonTypeName = "";

            while (rdr.Read())
            {
                MonTypeId   = rdr.GetInt32(0);
                MonTypeName = rdr.GetString(1);
            }
            MonType newMonType = new MonType(MonTypeName, MonTypeId);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            // return new MonType("", "", 0);
            return(newMonType);
        }
Example #3
0
        public static double TypeMultiplier(Mon defendingMon, Move attackingMove)
        {
            Dictionary <int, double> multiplier = new Dictionary <int, double>()
            {
                { 0, 1 },
                { 1, 2 },
                { 2, 0.5 },
                { 3, 0 }
            };
            MonType attackType = attackingMove.GetMonType();

            List <MonType> types    = defendingMon.GetMonTypes();
            double         multiply = 1;

            foreach (MonType type in types)
            {
                Dictionary <string, int> typeCompare = new Dictionary <string, int>()
                {
                    { "fairy", type.GetFairy() },
                    { "steel", type.GetSteel() },
                    { "dark", type.GetDark() },
                    { "dragon", type.GetDragon() },
                    { "ghost", type.GetGhost() },
                    { "rock", type.GetRock() },
                    { "bug", type.GetBug() },
                    { "psychic", type.GetPsychic() },
                    { "flying", type.GetFlying() },
                    { "ground", type.GetGround() },
                    { "poison", type.GetPoison() },
                    { "fighting", type.GetFighting() },
                    { "ice", type.GetIce() },
                    { "grass", type.GetGrass() },
                    { "electric", type.GetElectric() },
                    { "water", type.GetWater() },
                    { "fire", type.GetFire() },
                    { "normal", type.GetNormal() },
                };
                double newMultiplier = multiplier[typeCompare[attackType.GetMonTypeName()]];
                multiply = multiply * newMultiplier;
            }
            if (multiply > 1)
            {
                Message newMessage = new Message("<span class='animated jackInTheBox'>It's Super Effective!</span>");
                newMessage.Save();
            }
            else if (multiply < 1)
            {
                Message newMessage = new Message("<span class='animated slideInDown'>It's Not Very Effective...</span>");
                newMessage.Save();
            }
            return(multiply);
        }
Example #4
0
        public List <MonType> GetMonTypes()
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            MySqlCommand cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT types.* FROM mons
      JOIN mons_types ON (mons.id = mons_types.mons_id)
      JOIN types ON (mons_types.types_id = types.id)
      WHERE mons.id = @MonId;";

            cmd.Parameters.Add(new MySqlParameter("@MonId", _monId));

            MySqlDataReader rdr      = cmd.ExecuteReader() as MySqlDataReader;
            List <MonType>  monTypes = new List <MonType> {
            };

            while (rdr.Read())
            {
                int     typesId    = rdr.GetInt32(0);
                string  typesName  = rdr.GetString(1);
                int     fairy      = rdr.GetInt32(2);
                int     steel      = rdr.GetInt32(3);
                int     dark       = rdr.GetInt32(4);
                int     dragon     = rdr.GetInt32(5);
                int     ghost      = rdr.GetInt32(6);
                int     rock       = rdr.GetInt32(7);
                int     bug        = rdr.GetInt32(8);
                int     psychic    = rdr.GetInt32(9);
                int     flying     = rdr.GetInt32(10);
                int     ground     = rdr.GetInt32(11);
                int     poison     = rdr.GetInt32(12);
                int     fighting   = rdr.GetInt32(13);
                int     ice        = rdr.GetInt32(14);
                int     grass      = rdr.GetInt32(15);
                int     electric   = rdr.GetInt32(16);
                int     water      = rdr.GetInt32(17);
                int     fire       = rdr.GetInt32(18);
                int     normal     = rdr.GetInt32(19);
                MonType newMonType = new MonType(typesName, fairy, steel, dark, dragon, ghost, rock, bug, psychic, flying, ground, poison, fighting, ice, grass, electric, water, fire, normal, typesId);
                monTypes.Add(newMonType);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(monTypes);
            // return new List<MonType>{};
        }
Example #5
0
 public override bool Equals(System.Object otherMonType)
 {
     if (!(otherMonType is MonType))
     {
         return(false);
     }
     else
     {
         MonType newMonType   = (MonType)otherMonType;
         bool    idEquality   = this.GetMonTypeId().Equals(newMonType.GetMonTypeId());
         bool    nameEquality = this.GetMonTypeName().Equals(newMonType.GetMonTypeName());
         return(idEquality && nameEquality);
     }
 }
Example #6
0
        public static double STABMultiplier(Mon attackingMon, Move attackingMove)
        {
            List <MonType> monType    = attackingMon.GetMonTypes();
            MonType        attackType = attackingMove.GetMonType();
            double         multiply   = 1;

            foreach (MonType type in monType)
            {
                if (type.GetMonTypeName().Equals(attackType.GetMonTypeName()))
                {
                    multiply = multiply * 1.5;
                }
            }
            return(multiply);
        }
Example #7
0
        public void AddMonType(MonType newMonType)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"INSERT INTO mons_types (mons_id, types_id) VALUES (@MonId, @TypeId);";

            cmd.Parameters.Add(new MySqlParameter("@MonId", _monId));
            cmd.Parameters.Add(new MySqlParameter("@TypeId", newMonType.GetMonTypeId()));

            cmd.ExecuteNonQuery();
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
        }
Example #8
0
        public static void Sequence(int id)
        {
            Battle      player        = Battle.FindPlayer();
            Battle      computer      = Battle.FindComputer();
            Mon         playerMon     = Mon.Find(player.GetMon_Id());
            Mon         computerMon   = Mon.Find(computer.GetMon_Id());
            Move        playerMove    = Move.Find(id);
            List <Move> computerMoves = Mon.Find(computer.GetMon_Id()).GetMoves();
            Random      move          = new Random();
            Move        computerMove  = computerMoves[move.Next(computerMoves.Count)];

            //Speed Check
            int tie = 0;

            if (computer.GetSpeed() == player.GetSpeed())
            {
                Random speedTie = new Random();
                tie = speedTie.Next(1, 3);
            }
            if (player.GetSpeed() > computer.GetSpeed() || tie == 1)
            {
                double newHP   = (double)computer.GetHitpoints() - (double)Battle.BaseDamage(player.GetBattleId(), playerMove) * (double)MonType.TypeMultiplier(computerMon, playerMove) * (double)MonType.STABMultiplier(playerMon, playerMove) * (double)playerMove.AccuracyMultiplier() * (double)Battle.CritMultiplier();
                int    roundHP = (int)newHP;
                if (roundHP > 0)
                {
                    computer.SetNewHP(roundHP);
                    double otherHP      = (double)player.GetHitpoints() - (double)Battle.BaseDamage(player.GetBattleId(), computerMove) * (double)MonType.TypeMultiplier(playerMon, computerMove) * (double)MonType.STABMultiplier(computerMon, computerMove) * (double)computerMove.AccuracyMultiplier() * (double)Battle.CritMultiplier();
                    int    roundOtherHP = (int)otherHP;

                    if (roundOtherHP > 0)
                    {
                        player.SetNewHP(roundOtherHP);
                    }
                    else
                    {
                        player.SetNewHP(0);
                    }
                }
                else
                {
                    computer.SetNewHP(0);
                }
            }
            else if (player.GetSpeed() < computer.GetSpeed() || tie == 2)
            {
                double otherHP      = (double)player.GetHitpoints() - (double)Battle.BaseDamage(computer.GetBattleId(), computerMove) * (double)MonType.TypeMultiplier(playerMon, computerMove) * (double)MonType.STABMultiplier(playerMon, playerMove) * (double)playerMove.AccuracyMultiplier() * (double)Battle.CritMultiplier();
                int    roundOtherHP = (int)otherHP;

                if (roundOtherHP > 0)
                {
                    player.SetNewHP(roundOtherHP);
                    double newHP   = (double)computer.GetHitpoints() - (double)Battle.BaseDamage(player.GetBattleId(), playerMove) * (double)MonType.TypeMultiplier(computerMon, playerMove) * (double)MonType.STABMultiplier(computerMon, computerMove) * (double)computerMove.AccuracyMultiplier();
                    int    roundHP = (int)newHP;
                    if (roundHP > 0)
                    {
                        computer.SetNewHP(roundHP);
                    }
                    else
                    {
                        computer.SetNewHP(0);
                    }
                }
                else
                {
                    player.SetNewHP(0);
                }
            }
        }
Example #9
0
        public static int Damage(Move usedMove, Battle attacker, Mon attackerMon, Mon defenderMon)
        {
            double damage = (double)Battle.BaseDamage(attacker.GetBattleId(), usedMove) * (double)Battle.CritMultiplier() * (double)MonType.STABMultiplier(attackerMon, usedMove) * (double)usedMove.AccuracyMultiplier();

            return((int)damage);
            // (double)MonType.TypeMultiplier(defenderMon, usedMove)
        }
Example #10
0
        public static MonType Find(string monTypeName)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM types WHERE name = (@typeName);";

            cmd.Parameters.Add(new MySqlParameter("@typeName", monTypeName));

            var    rdr         = cmd.ExecuteReader() as MySqlDataReader;
            int    MonTypeId   = 0;
            string MonTypeName = "";
            int    fairy       = 0;
            int    steel       = 0;
            int    dark        = 0;
            int    dragon      = 0;
            int    ghost       = 0;
            int    rock        = 0;
            int    bug         = 0;
            int    psychic     = 0;
            int    flying      = 0;
            int    ground      = 0;
            int    poison      = 0;
            int    fighting    = 0;
            int    ice         = 0;
            int    grass       = 0;
            int    electric    = 0;
            int    water       = 0;
            int    fire        = 0;
            int    normal      = 0;

            while (rdr.Read())
            {
                MonTypeId   = rdr.GetInt32(0);
                MonTypeName = rdr.GetString(1);
                fairy       = rdr.GetInt32(2);
                steel       = rdr.GetInt32(3);
                dark        = rdr.GetInt32(4);
                dragon      = rdr.GetInt32(5);
                ghost       = rdr.GetInt32(6);
                rock        = rdr.GetInt32(7);
                bug         = rdr.GetInt32(8);
                psychic     = rdr.GetInt32(9);
                flying      = rdr.GetInt32(10);
                ground      = rdr.GetInt32(11);
                poison      = rdr.GetInt32(12);
                fighting    = rdr.GetInt32(13);
                ice         = rdr.GetInt32(14);
                grass       = rdr.GetInt32(15);
                electric    = rdr.GetInt32(16);
                water       = rdr.GetInt32(17);
                fire        = rdr.GetInt32(18);
                normal      = rdr.GetInt32(19);
            }
            MonType newMonType = new MonType(MonTypeName, fairy, steel, dark, dragon, ghost, rock, bug, psychic, flying, ground, poison, fighting, ice, grass, electric, water, fire, normal, MonTypeId);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            // return new MonType("", "", 0);
            return(newMonType);
        }