public static void Create_Default_Attacks(int user_id, string creature_name)
    {
        string    e;
        Creatures creature = Creatures_Query.Get_Creature(out e, creature_name, user_id);

        switch (creature.Creature_name)
        {
        case "Akata":
            Create_Default_Attack(user_id, creature.Creature_id, "bite", "1d6+1", 20, 2, 2);
            Create_Default_Attack(user_id, creature.Creature_id, "tentacle", "1d3+0", 20, 2, -3);
            Create_Default_Attack(user_id, creature.Creature_id, "tentacle", "1d3+0", 20, 2, -3);
            break;

        case "Carbuncle":
            Create_Default_Attack(user_id, creature.Creature_id, "bite", "1d3-3", 20, 2, 1);
            break;

        case "Elk":
            Create_Default_Attack(user_id, creature.Creature_id, "gore", "1d6+2", 20, 2, 3);
            Create_Default_Attack(user_id, creature.Creature_id, "hoof", "1d3+1", 20, 2, -2);
            Create_Default_Attack(user_id, creature.Creature_id, "hoof", "1d3+1", 20, 2, -2);
            break;

        case "Chupacabra":
            Create_Default_Attack(user_id, creature.Creature_id, "bite", "1d4+1", 20, 2, 6);
            Create_Default_Attack(user_id, creature.Creature_id, "claw", "1d3+1", 20, 2, 6);
            Create_Default_Attack(user_id, creature.Creature_id, "claw", "1d3+1", 20, 2, 6);
            break;

        case "Havero":
            Create_Default_Attack(user_id, creature.Creature_id, "tentacle", "2d6+14", 20, 2, 31);
            Create_Default_Attack(user_id, creature.Creature_id, "claw", "2d6+14", 18, 2, 31);
            Create_Default_Attack(user_id, creature.Creature_id, "sting", "2d6+14", 20, 2, 31);
            Create_Default_Attack(user_id, creature.Creature_id, "pincer", "4d6+14", 19, 2, 31);
            break;
        }
    }
Ejemplo n.º 2
0
    protected void Fight_Click(object sender, EventArgs e)
    {
        // SQL Var
        Creatures      creature1             = null;
        Creatures      creature2             = null;
        List <Attacks> Attack_list_1         = new List <Attacks>();
        List <Attacks> Attack_list_2         = new List <Attacks>();
        string         error_msg_creatures_1 = "";
        string         error_msg_creatures_2 = "";
        string         error_msg_attacks_1   = "";
        string         error_msg_attacks_2   = "";

        //Fight Simulation Var
        Random random = new Random(DateTime.Now.Millisecond);
        int    number_of_fights_total;

        if (tbNumFights.Text.Equals(""))
        {
            number_of_fights_total = 10000;
            lAutoNumFights.Visible = true;
        }
        else
        {
            number_of_fights_total = Int32.Parse(tbNumFights.Text);
        }
        int  number_of_fights_count = number_of_fights_total;
        bool creature_1_goes_first  = true;

        float[]      stats = { 0.0F, 0.0F };
        List <float> creature_1_hit_rate_list    = new List <float>();
        List <float> creature_2_hit_rate_list    = new List <float>();
        List <float> creature_1_damage_rate_list = new List <float>();
        List <float> creature_2_damage_rate_list = new List <float>();
        float        creature_1_hit_rate         = 0.0F;
        float        creature_2_hit_rate         = 0.0F;
        float        creature_1_damage_rate      = 0.0F;
        float        creature_2_damage_rate      = 0.0F;
        float        creature_1_win_rate         = 0.0F;
        float        creature_2_win_rate         = 0.0F;

        //Get Creatures
        creature1 = Creatures_Query.Get_Creature(out error_msg_creatures_1, DropDownList1.SelectedItem.Text, ((int)Session["User_id"]));
        creature2 = Creatures_Query.Get_Creature(out error_msg_creatures_2, DropDownList2.SelectedItem.Text, ((int)Session["User_id"]));

        //Get their Attacks
        Attack_list_1 = Attacks_Query.Get_Attacks_Of_Creature(out error_msg_attacks_1, creature1.Creature_id, creature1.User_id);
        Attack_list_2 = Attacks_Query.Get_Attacks_Of_Creature(out error_msg_attacks_2, creature2.Creature_id, creature2.User_id);

        //Simulate Fights
        while (number_of_fights_count > 0)
        {
            // Setup temp creatures hp for fight
            int temp_creature1_hp = creature1.Hit_points;
            int temp_creature2_hp = creature2.Hit_points;
            int round_count       = 0;
            int creature_1_turns  = 0;
            int creature_2_turns  = 0;

            //Roll initaive
            creature_1_goes_first = Roll_Initative(creature1, creature2, random);

            // Start Fight
            while (temp_creature1_hp > 0 && temp_creature2_hp > 0)
            {
                // if creature 1 goes first
                if (creature_1_goes_first)
                {
                    stats = Attack(creature1, Attack_list_1, creature2, ref temp_creature2_hp, random);
                    creature_1_turns++;
                    creature_1_hit_rate    += stats[0];
                    creature_1_damage_rate += stats[1];

                    if (temp_creature2_hp > 0)
                    {
                        stats = Attack(creature2, Attack_list_2, creature1, ref temp_creature1_hp, random);
                        creature_2_turns++;
                        creature_2_hit_rate    += stats[0];
                        creature_2_damage_rate += stats[1];
                    }
                }

                // if creature 2 goes first
                else if (!creature_1_goes_first)
                {
                    stats = Attack(creature2, Attack_list_2, creature1, ref temp_creature1_hp, random);
                    creature_2_turns++;
                    creature_2_hit_rate    += stats[0];
                    creature_2_damage_rate += stats[1];

                    if (temp_creature1_hp > 0)
                    {
                        stats = Attack(creature1, Attack_list_1, creature2, ref temp_creature2_hp, random);
                        creature_1_turns++;
                        creature_1_hit_rate    += stats[0];
                        creature_1_damage_rate += stats[1];
                    }
                }

                // increment round
                round_count++;
            }

            //Finalize Stats for Fight
            if (creature_1_turns > 0)
            {
                creature_1_hit_rate_list.Add(creature_1_hit_rate / creature_1_turns);
                creature_1_hit_rate = 0.0F;
                creature_1_damage_rate_list.Add(creature_1_damage_rate / creature_1_turns);
                creature_1_damage_rate = 0.0F;
            }

            if (creature_2_turns > 0)
            {
                creature_2_hit_rate_list.Add(creature_2_hit_rate / creature_2_turns);
                creature_2_hit_rate = 0.0F;
                creature_2_damage_rate_list.Add(creature_2_damage_rate / creature_2_turns);
                creature_2_damage_rate = 0.0F;
            }


            //Declarge Fight Winner
            if (temp_creature1_hp <= 0)
            {
                creature_2_win_rate++;
            }
            else if (temp_creature2_hp <= 0)
            {
                creature_1_win_rate++;
            }

            // End Fight
            number_of_fights_count--;
        }

        //Finalize win rate
        decimal final_creature_1_win_rate = (Math.Round((decimal)(creature_1_win_rate / number_of_fights_total), 2) * 100);
        decimal final_creature_2_win_rate = (Math.Round((decimal)(creature_2_win_rate / number_of_fights_total), 2) * 100);

        Win_Rate_1.Text = final_creature_1_win_rate.ToString() + "%";
        Win_Rate_2.Text = final_creature_2_win_rate.ToString() + "%";

        creature_1_hit_rate    = 0.0F;
        creature_2_hit_rate    = 0.0F;
        creature_1_damage_rate = 0.0F;
        creature_2_damage_rate = 0.0F;

        foreach (float k in creature_1_hit_rate_list)
        {
            creature_1_hit_rate += k;
        }
        foreach (float j in creature_2_hit_rate_list)
        {
            creature_2_hit_rate += j;
        }
        foreach (float h in creature_1_damage_rate_list)
        {
            creature_1_damage_rate += h;
        }
        foreach (float i in creature_2_damage_rate_list)
        {
            creature_2_damage_rate += i;
        }

        Decimal final_creature_1_hit_rate = (Math.Round((decimal)(creature_1_hit_rate / creature_1_hit_rate_list.Count()), 2) * 100);

        Accuracy_1.Text = final_creature_1_hit_rate.ToString() + "%";

        Decimal final_creature_2_hit_rate = (Math.Round((decimal)(creature_2_hit_rate / creature_2_hit_rate_list.Count()), 2) * 100);

        Accuracy_2.Text = final_creature_2_hit_rate.ToString() + "%";

        Decimal final_creature_1_damage_rate = (Math.Round((decimal)(creature_1_damage_rate / creature_1_damage_rate_list.Count()), 2));

        Damage_1.Text = final_creature_1_damage_rate.ToString();

        Decimal final_creature_2_damage_rate = (Math.Round((decimal)(creature_2_damage_rate / creature_2_damage_rate_list.Count()), 2));

        Damage_2.Text = final_creature_2_damage_rate.ToString();

        History_Query.Record_Combat_Results((int)Session["User_id"], creature1.Creature_id, creature2.Creature_id, final_creature_1_hit_rate, final_creature_2_hit_rate, final_creature_1_damage_rate, final_creature_2_damage_rate, final_creature_1_win_rate, final_creature_2_win_rate);
    }