예제 #1
0
        protected void UseEquipment(object sender, EventArgs e)
        {
            PlayerCharacter player1 = (PlayerCharacter)Session["player1"];

            string CS = ConfigurationManager.ConnectionStrings["RPG3"].ConnectionString;

            using (SqlConnection con = new SqlConnection(CS))
            {
                SqlCommand GetEquipmentAtributes = new SqlCommand("GetEquipmentTypeID", con);
                GetEquipmentAtributes.CommandType = System.Data.CommandType.StoredProcedure;
                GetEquipmentAtributes.Parameters.AddWithValue("@ID", BackpackItems.SelectedValue);

                con.Open();
                SqlDataReader reader = GetEquipmentAtributes.ExecuteReader();
                while (reader.Read())
                {
                    Session["TypeID"] = reader["TypeID"];
                }

                switch ((int)Session["TypeID"])
                {
                case 1:
                    player1.MyWeapon      = new Weapon((string)Session["EquipmentName"], (int)Session["HPModifier"], (int)Session["AP"]);
                    UsedEquipment.Visible = true;
                    UsedEquipment.Text    = "Weapon equiped.";
                    break;

                case 2:
                    player1.MyShield      = new Shield((string)Session["EquipmentName"], (int)Session["DP"]);
                    UsedEquipment.Visible = true;
                    UsedEquipment.Text    = "Shield equiped.";
                    break;

                case 3:
                    player1.MyArmour      = new Armour((string)Session["EquipmentName"], (int)Session["DRP"]);
                    UsedEquipment.Visible = true;
                    UsedEquipment.Text    = "Armour equiped.";
                    break;

                case 4:
                    if ((int)Session["Quantity"] > 0)
                    {
                        if (player1.ActualHealthPoint < player1.MaxHealthPoint)
                        {
                            int quantity = (int)Session["Quantity"];
                            player1.Heal((int)Session["HPModifier"]);
                            quantity           -= 1;
                            Session["Quantity"] = quantity;
                            UpdateItemQuantityInSQL((int)Session["PlayerID"], Convert.ToInt32(BackpackItems.SelectedValue), quantity);
                            Session["BackPackOpenStartIndex"] = BackpackItems.SelectedIndex;
                            Session["DrunkHealingPotion"]     = 1;
                            Response.Redirect("~/BackPack.aspx");
                        }
                    }
                    break;

                case 5:
                    if ((int)Session["Quantity"] > 0)
                    {
                        int    quantity     = (int)Session["Quantity"];
                        Poison crrentPoison = new Poison((int)Session["HPModifier"], (string)Session["EquipmentName"], Convert.ToDouble(Session["goldvalue"]), Convert.ToDouble(Session["weight"]));
                        Poison.PoisonWeapon(player1, crrentPoison);
                        quantity           -= 1;
                        Session["Quantity"] = quantity;
                        UpdateItemQuantityInSQL((int)Session["PlayerID"], Convert.ToInt32(BackpackItems.SelectedValue), quantity);
                        Session["BackPackOpenStartIndex"] = BackpackItems.SelectedIndex;
                        Session["PoisonWeapon"]           = 1;
                        Response.Redirect("~/BackPack.aspx");
                    }
                    break;

                case 6:
                    break;

                default:
                    break;
                }
                Session["player1"] = player1;
            }
        }