private void btnAttack_Click(object sender, RoutedEventArgs e) { bool secondDice = false; bonus = 0; try { amount1 = Convert.ToInt32(tbDiceAmount.Text); if (tbDiceAmount2.Text != "" && tbDiceAmount2.Text != "0") { amount2 = Convert.ToInt32(tbDiceAmount2.Text); secondDice = true; } sides1 = (int)cbDiceSides.SelectedItem; if (secondDice) { sides2 = (int)cbDiceSides2.SelectedItem; } toHit = Convert.ToInt32(tbToHit.Text); if (tbBonus.Text != "") { bonus = Convert.ToInt32(tbBonus.Text); } log.Write("Bonus: " + bonus); if (secondDice) { if ((int)cbDiceSides2.SelectedItem != 0) { log.Write("2nd Damage: " + DiceThrower.RollDamage(amount2, sides2, 0)); } } if (amount1 == 0) { log.Write("Damage: Please use the first die!"); } else { log.Write("1st Damage: " + DiceThrower.RollDamage(amount1, sides1, 0)); } log.Write("To Hit: " + DiceThrower.RollToHit(toHit)); } catch (Exception error) { MessageBox.Show("Invalid Input: " + error.ToString()); } log.InputSpace(); }
public void Attack() { string amount = string.Empty; string sides = string.Empty; string amount2 = string.Empty; string sides2 = string.Empty; int amountNumb = 0; int sidesNumb = 0; int amountNumb2 = 0; int sidesNumb2 = 0; string damage = w.GetDamage(); bool pastDice = false; bool secondDice = false; if (damage == "1") { play.log.Write("Damage: " + damage + " " + w.GetBaseDamageType()); play.log.Write("To hit: " + DiceThrower.RollToHit(toHit)); play.log.InputSpace(); } else { for (int i = 0; i < damage.Length; i++) { if (!pastDice) { if (damage[i] != 'd') { amount += damage[i]; } else { pastDice = true; } } else { sides += damage[i]; } } pastDice = false; damage = w.GetDamage2(); if (damage != "0" && damage != string.Empty && damage != null) { secondDice = true; for (int i = 0; i < damage.Length; i++) { if (!pastDice) { if (damage[i] != 'd') { amount2 += damage[i]; } else { pastDice = true; } } else { sides2 += damage[i]; } } } try { amountNumb = Convert.ToInt32(amount); sidesNumb = Convert.ToInt32(sides); if (secondDice) { amountNumb2 = Convert.ToInt32(amount2); sidesNumb2 = Convert.ToInt32(sides2); } } catch (Exception) { MessageBox.Show("Invalid damage conversion."); } string toHitMessage = DiceThrower.RollToHit(toHit); int criticalDice = 20 + toHit; // Critical hits if (toHitMessage == ("Critical " + criticalDice)) { amountNumb++; } if (w.GetBonusDamage() != 0) { play.log.Write("Bonus: " + w.GetBonusDamage() + " " + w.GetBonusDamageType()); } if (secondDice) { play.log.Write("+ " + (DiceThrower.RollDamage(amountNumb2, sidesNumb2, 0)) + " " + w.GetBaseDamage2()); } play.log.Write("Damage: " + (DiceThrower.RollDamage(amountNumb, sidesNumb, c.GetModifier(mod))) + " " + w.GetBaseDamageType()); play.log.Write("To hit: " + toHitMessage); play.log.InputSpace(); } }