コード例 #1
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);
                }
            }
        }
コード例 #2
0
        public static int BaseDamage(int attackerId, Move usedMove)
        {
            List <Battle> twoBattles = new List <Battle> {
            };
            MySqlConnection conn     = DB.Connection();

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

            cmd.CommandText = @"SELECT * FROM battle WHERE isactive = @isActive;";
            cmd.Parameters.Add(new MySqlParameter("@isActive", true));
            var rdr = cmd.ExecuteReader() as MySqlDataReader;

            while (rdr.Read())
            {
                int    BattleId       = rdr.GetInt32(0);
                int    Mon_Id         = rdr.GetInt32(1);
                string BattleName     = rdr.GetString(2);
                int    Level          = rdr.GetInt32(3);
                int    TotalHitpoints = rdr.GetInt32(4);
                int    LastHitpoints  = rdr.GetInt32(5);
                int    Hitpoints      = rdr.GetInt32(6);
                int    Attack         = rdr.GetInt32(7);
                int    Defense        = rdr.GetInt32(8);
                int    Specialattack  = rdr.GetInt32(9);
                int    Specialdefense = rdr.GetInt32(10);
                int    Speed          = rdr.GetInt32(11);
                int    Move1pp        = rdr.GetInt32(12);
                int    Move2pp        = rdr.GetInt32(13);
                int    Move3pp        = rdr.GetInt32(14);
                int    Move4pp        = rdr.GetInt32(15);
                bool   IsPlayer       = rdr.GetBoolean(16);
                bool   IsComputer     = rdr.GetBoolean(17);
                bool   IsActive       = rdr.GetBoolean(18);

                Battle newBattle = new Battle(Mon_Id, BattleName, Level, TotalHitpoints, LastHitpoints, Hitpoints, Attack, Defense, Specialattack, Specialdefense, Speed, Move1pp, Move2pp, Move3pp, Move4pp, IsPlayer, IsComputer, IsActive, BattleId);
                twoBattles.Add(newBattle);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            //Player Attack
            if (attackerId == twoBattles[0].GetBattleId() && twoBattles[0].GetIsPlayer())
            {
                if (usedMove.GetAttackStyle().Equals("physical"))
                {
                    float baseDamage = (((((2 * (float)twoBattles[0].GetLevel()) / 5) + 2) * (float)usedMove.GetBasePower() * ((float)twoBattles[0].GetAttack() / (float)twoBattles[1].GetDefense())) / 50) + 2;
                    int   rounded    = (int)baseDamage;
                    return(rounded);
                }
                else if (usedMove.GetAttackStyle().Equals("special"))
                {
                    float baseDamage = (((((2 * (float)twoBattles[0].GetLevel()) / 5) + 2) * (float)usedMove.GetBasePower() * ((float)twoBattles[0].GetSpecialattack() / (float)twoBattles[1].GetSpecialdefense())) / 50) + 2;
                    int   rounded    = (int)baseDamage;
                    return(rounded);
                }
            }
            else if (attackerId == twoBattles[1].GetBattleId() && twoBattles[1].GetIsPlayer())
            {
                if (usedMove.GetAttackStyle().Equals("physical"))
                {
                    float baseDamage = (((((2 * (float)twoBattles[1].GetLevel()) / 5) + 2) * (float)usedMove.GetBasePower() * ((float)twoBattles[1].GetAttack() / (float)twoBattles[0].GetDefense())) / 50) + 2;
                    int   rounded    = (int)baseDamage;
                    return(rounded);
                }
                else if (usedMove.GetAttackStyle().Equals("special"))
                {
                    float baseDamage = (((((2 * (float)twoBattles[1].GetLevel()) / 5) + 2) * (float)usedMove.GetBasePower() * ((float)twoBattles[1].GetSpecialattack() / (float)twoBattles[0].GetSpecialdefense())) / 50) + 2;
                    int   rounded    = (int)baseDamage;
                    return(rounded);
                }
            }
            //Computer Attack
            else if (attackerId == twoBattles[0].GetBattleId() && twoBattles[0].GetIsComputer())
            {
                if (usedMove.GetAttackStyle().Equals("physical"))
                {
                    float baseDamage = (((((2 * (float)twoBattles[0].GetLevel()) / 5) + 2) * (float)usedMove.GetBasePower() * ((float)twoBattles[0].GetAttack() / (float)twoBattles[1].GetDefense())) / 50) + 2;
                    int   rounded    = (int)baseDamage;
                    return(rounded);
                }
                else if (usedMove.GetAttackStyle().Equals("special"))
                {
                    float baseDamage = (((((2 * (float)twoBattles[0].GetLevel()) / 5) + 2) * (float)usedMove.GetBasePower() * ((float)twoBattles[0].GetSpecialattack() / (float)twoBattles[1].GetSpecialdefense())) / 50) + 2;
                    int   rounded    = (int)baseDamage;
                    return(rounded);
                    // return (((((2 * twoBattles[0].GetLevel()) / 5) + 2) * usedMove.GetBasePower() * (twoBattles[0].GetSpecialattack()/twoBattles[1].GetSpecialdefense())) / 50) + 2;
                }
            }
            else if (attackerId == twoBattles[1].GetBattleId() && twoBattles[1].GetIsComputer())
            {
                if (usedMove.GetAttackStyle().Equals("physical"))
                {
                    float baseDamage = (((((2 * (float)twoBattles[1].GetLevel()) / 5) + 2) * (float)usedMove.GetBasePower() * ((float)twoBattles[1].GetAttack() / (float)twoBattles[0].GetDefense())) / 50) + 2;
                    int   rounded    = (int)baseDamage;
                    return(rounded);
                }
                else if (usedMove.GetAttackStyle().Equals("special"))
                {
                    float baseDamage = (((((2 * (float)twoBattles[1].GetLevel()) / 5) + 2) * (float)usedMove.GetBasePower() * ((float)twoBattles[1].GetSpecialattack() / (float)twoBattles[0].GetSpecialdefense())) / 50) + 2;
                    int   rounded    = (int)baseDamage;
                    return(rounded);
                }
            }
            return(0);
        }
コード例 #3
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)
        }
コード例 #4
0
        public static Battle FindComputer()
        {
            MySqlConnection conn = DB.Connection();

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

            cmd.CommandText = @"SELECT * FROM battle WHERE iscomputer = @IsComputer AND isactive = @IsActive;";

            cmd.Parameters.Add(new MySqlParameter("@IsComputer", true));
            cmd.Parameters.Add(new MySqlParameter("@IsActive", true));


            var    rdr            = cmd.ExecuteReader() as MySqlDataReader;
            int    BattleId       = 0;
            int    Mon_Id         = 0;
            string BattleName     = "";
            int    Level          = 0;
            int    TotalHitpoints = 0;
            int    LastHitpoints  = 0;
            int    Hitpoints      = 0;
            int    Attack         = 0;
            int    Defense        = 0;
            int    Specialattack  = 0;
            int    Specialdefense = 0;
            int    Speed          = 0;
            int    Move1pp        = 0;
            int    Move2pp        = 0;
            int    Move3pp        = 0;
            int    Move4pp        = 0;
            bool   IsPlayer       = false;
            bool   IsComputer     = false;
            bool   IsActive       = false;

            while (rdr.Read())
            {
                BattleId       = rdr.GetInt32(0);
                Mon_Id         = rdr.GetInt32(1);
                BattleName     = rdr.GetString(2);
                Level          = rdr.GetInt32(3);
                TotalHitpoints = rdr.GetInt32(4);
                LastHitpoints  = rdr.GetInt32(5);
                Hitpoints      = rdr.GetInt32(6);
                Attack         = rdr.GetInt32(7);
                Defense        = rdr.GetInt32(8);
                Specialattack  = rdr.GetInt32(9);
                Specialdefense = rdr.GetInt32(10);
                Speed          = rdr.GetInt32(11);
                Move1pp        = rdr.GetInt32(12);
                Move2pp        = rdr.GetInt32(13);
                Move3pp        = rdr.GetInt32(14);
                Move4pp        = rdr.GetInt32(15);
                IsPlayer       = rdr.GetBoolean(16);
                IsComputer     = rdr.GetBoolean(17);
                IsActive       = rdr.GetBoolean(18);
            }
            Battle newBattle = new Battle(Mon_Id, BattleName, Level, TotalHitpoints, LastHitpoints, Hitpoints, Attack, Defense, Specialattack, Specialdefense, Speed, Move1pp, Move2pp, Move3pp, Move4pp, IsPlayer, IsComputer, IsActive, BattleId);

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