public HDDialog(Context context, string HD) : base(context) { _DieRoll = DieRoll.FromString(HD); RequestWindowFeature((int)WindowFeatures.NoTitle); SetContentView(Resource.Layout.HDDialog); SetCanceledOnTouchOutside(true); Window.SetSoftInputMode(SoftInput.StateHidden); EditText et = FindViewById <EditText>(Resource.Id.modText); et.Text = _DieRoll.mod.ToString(); et.TextChanged += (object sender, Android.Text.TextChangedEventArgs e) => { int val; if (int.TryParse(et.Text, out val)) { _DieRoll.mod = val; } }; ((Button)FindViewById(Resource.Id.cancelButton)).Click += (object sender, EventArgs e) => { Dismiss(); }; ((Button)FindViewById(Resource.Id.okButton)).Click += (object sender, EventArgs e) => { Dismiss(); FireOk(); }; SetupDice(); }
public AttackRollResult(Attack atk) { _Attack = atk; _Name = atk.Name; Rolls = new List <SingleAttackRoll>(); if (atk.Weapon != null) { _Name = atk.Weapon.Name; } int totalAttacks = atk.Count * atk.Bonus.Count; for (int atkcount = 0; atkcount < atk.Count; atkcount++) { foreach (int mod in atk.Bonus) { SingleAttackRoll sr = new SingleAttackRoll(); DieRoll roll = new DieRoll(1, 20, mod); sr.Result = roll.Roll(); sr.Damage = atk.Damage.Roll(); if (atk.Plus != null) { Regex plusRegex = new Regex("(?<die>[0-9]+d[0-9]+((\\+|-)[0-9]+)?) (?<type>[a-zA-Z]+)"); Match dm = plusRegex.Match(atk.Plus); if (dm.Success) { DieRoll bonusRoll = DieRoll.FromString(dm.Groups["die"].Value); BonusDamage bd = new BonusDamage(); bd.Damage = bonusRoll.Roll(); bd.DamageType = dm.Groups["type"].Value; sr.BonusDamage.Add(bd); } } if (sr.Result.Rolls[0].Result >= atk.CritRange) { sr.CritResult = roll.Roll(); sr.CritDamage = new RollResult(); for (int i = 1; i < atk.CritMultiplier; i++) { RollResult crit = atk.Damage.Roll(); sr.CritDamage = crit + sr.CritDamage; } } Rolls.Add(sr); } } }
public void FromStringTest() { string st = "2d8-1"; DieRoll expected = new DieRoll(2, 8, -1); DieRoll actual = DieRoll.FromString(st); Assert.AreEqual(expected.ToString(), actual.ToString()); }
void Roll() { EditText dieText = View.FindViewById <EditText>(Resource.Id.rollText); DieRoll roll = DieRoll.FromString(dieText.Text); Roll(roll); }
void RollButtonClicked(object sender, EventArgs e) { DieRoll r = DieRoll.FromString(_DieText); AddRoll(r); RenderResults(); }
protected void ButtonRoll_Click(object sender, EventArgs e) { DieRoll dr = DieRoll.FromString(TextDieRoll.Text); int rollCount; try { rollCount = Convert.ToInt32(TextRollCount.Text); } catch (Exception ex) { rollCount = 1; } if (rollCount > 0) { DieRollResults results = Roll(dr, rollCount); StringBuilder sb = new StringBuilder(); sb.Append("Minimum, Maximum, Average for "); sb.Append(dr.ToString()); sb.Append(": "); sb.Append(dr.Minimum.ToString()); sb.Append(", "); sb.Append(dr.Maximum.ToString()); sb.Append(", "); sb.Append(dr.Average.ToString()); sb.Append("<br />Roll results: "); sb.Append(results.ToString()); sb.Append("<br />Sorted: "); sb.Append(results.Sorted().ToString()); sb.Append("<br />Reversed: "); sb.Append(results.Sorted(DieRollResults.SortOrder.Descending).ToString()); sb.Append("<br />Lowest, Highest, Average rolled: "); sb.Append(results.Lowest.ToString()); sb.Append(", "); sb.Append(results.Highest.ToString()); sb.Append(", "); sb.Append(results.Average.ToString()); if (rollCount > 3) { results.KeepBest(3); sb.Append("<br />Top 3 rolls: "); sb.Append(results.ToString()); sb.Append(", total "); sb.Append(results.Total.ToString()); } LabelResult.Text = sb.ToString(); } else { LabelResult.Text = "Number of Rolls must be a positive integer."; } }
/// <summary> /// Tries to parse the string expression of Monster Hit Dice /// </summary> /// <returns>The Monster Hit Dice string expression was succesfully parsed and set to HitPoints</returns> public bool TryParseHitPoints() { DieRoll dr = DieRoll.FromString(this.monster.HitDice); if (dr != null) { this.HitPoints = dr.Roll().Total; return(true); } return(false); }
void HandleDieSwipe(UISwipeGestureRecognizer rec) { GradientButton b = _Recs[rec]; _BottomView.BringSubviewToFront(b); int value = (int)b.Tag; DieRoll r = DieRoll.FromString("1d" + value); SlideView(b, true); AddRoll(r); }
void AddDieRoll(int die) { EditText dieText = View.FindViewById <EditText>(Resource.Id.rollText); DieRoll roll = DieRoll.FromString(dieText.Text); if (roll == null) { roll = new DieRoll(1, die, 0); } else { roll.AddDie(new DieStep(1, die)); } dieText.Text = roll.Text; }
void DieClicked(object sender, EventArgs e) { DieRoll roll = DieRoll.FromString(_DieText); if (roll == null) { roll = new DieRoll(1, (int)((UIButton)sender).Tag, 0); } else { roll.AddDie(new DieStep(1, (int)((UIButton)sender).Tag)); } SlideView((UIView)sender, false); _DieText = roll.Text; _DieTextButton.SetText(_DieText); }
RollableList GetADnDTreasureTypes() { // Generate the ADnD 1E TreasureTypes list // TODO: // - read from XML or another data source; I don't think the syntax to specify some of these things exists yet // - on the other hand, this is a good demo for generating tables in code // - generate individual spells for scrolls // - incorporate gp values for gems and jewelery, and XP values for magic items; // -- this will involve creating descendant GameObject classes with these attributes; // -- add the option to hide gem names and to consolidate the values into one, e.g. "gems (50,000 gp)" // -- include a total GP and XP value for each trove, or the data for computing it on the client side RollableList List = new RollableList(); // establish session XmlProvider provider = new XmlProvider(Repository.GetCurrentRepository(), GemsPath); Repository.Connect(provider); provider.FilePath = ADnDPath; provider.Load(); // Treasure types table from AD&D 1E Monster Manual ItemList list = new ItemList(); // ****** A die roll string consisting only of a constant N should convert to 0d0+N list.Add(new ItemRoll(new GameObject("cp", "cp"), DieRoll.FromString("d6"), 1000, 25)); list.Add(new ItemRoll(new GameObject("sp", "sp"), DieRoll.FromString("d6"), 1000, 30)); list.Add(new ItemRoll(new GameObject("ep", "ep"), DieRoll.FromString("d6"), 1000, 35)); list.Add(new ItemRoll(new GameObject("gp", "gp"), DieRoll.FromString("d10"), 1000, 40)); list.Add(new ItemRoll(new GameObject("pp", "pp"), DieRoll.FromString("d4"), 100, 25)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Gems and Jewels")), DieRoll.FromString("4d10"), 1, 60)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Jewelry")), DieRoll.FromString("3d10"), 1, 50)); TableRoll tempRoll = new TableRoll(Repository.GetTable("I. Map or Magic Determination")); tempRoll.Rolls = 3; list.Add(new ItemRoll(tempRoll, DieRoll.FromString("d1"), 1, 30)); List.Add("A", list); list = new ItemList(); list.Add(new ItemRoll(new GameObject("cp", "cp"), DieRoll.FromString("d8"), 1000, 50)); list.Add(new ItemRoll(new GameObject("sp", "sp"), DieRoll.FromString("d6"), 1000, 25)); list.Add(new ItemRoll(new GameObject("ep", "ep"), DieRoll.FromString("d4"), 1000, 25)); list.Add(new ItemRoll(new GameObject("gp", "gp"), DieRoll.FromString("d3"), 1000, 25)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Gems and Jewels")), DieRoll.FromString("d8"), 1, 30)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Jewelry")), DieRoll.FromString("d4"), 1, 20)); // Sword, armor or misc. weapon: 10% // This means 10% of the time we have to pick one of three tables (Swords, Armor, and Misc. Weapons) and roll on that table. // - create a temporary RollableTable that contains TableRolls for those three tables; // - create an ItemRoll that rolls on the temp table 10% of the time; // - add the ItemRoll to the List. RollableTable tempTable = new RollableTable(); tempTable.Dice = new DieRoll("d3"); tempTable.Add(new TableRoll(Repository.GetTable("III. Swords")), 1); tempTable.Add(new TableRoll(Repository.GetTable("III. Armor and Shields")), 2); tempTable.Add(new TableRoll(Repository.GetTable("III. Miscellaneous Weapons")), 3); list.Add(new ItemRoll(new TableRoll(tempTable), DieRoll.FromString("d1"), 1, 10)); List.Add("B", list); list = new ItemList(); list.Add(new ItemRoll(new GameObject("cp", "cp"), DieRoll.FromString("d12"), 1000, 20)); list.Add(new ItemRoll(new GameObject("sp", "sp"), DieRoll.FromString("d6"), 1000, 30)); list.Add(new ItemRoll(new GameObject("ep", "ep"), DieRoll.FromString("d4"), 1000, 10)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Gems and Jewels")), DieRoll.FromString("d6"), 1, 25)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Jewelry")), DieRoll.FromString("d3"), 1, 20)); tempRoll = new TableRoll(Repository.GetTable("I. Map or Magic Determination")); tempRoll.Rolls = 2; list.Add(new ItemRoll(tempRoll, DieRoll.FromString("d1"), 1, 10)); List.Add("C", list); list = new ItemList(); list.Add(new ItemRoll(new GameObject("cp", "cp"), DieRoll.FromString("d8"), 1000, 10)); list.Add(new ItemRoll(new GameObject("sp", "sp"), DieRoll.FromString("d12"), 1000, 15)); list.Add(new ItemRoll(new GameObject("ep", "ep"), DieRoll.FromString("d8"), 1000, 15)); list.Add(new ItemRoll(new GameObject("gp", "gp"), DieRoll.FromString("d6"), 1000, 50)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Gems and Jewels")), DieRoll.FromString("d10"), 1, 30)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Jewelry")), DieRoll.FromString("d6"), 1, 25)); // Any 2 plus 1 potion: 15% // This means 15% of the time we roll 2 Maps-or-Magic results, AND we roll a potion; // - create a TableRoll that rolls twice on the Maps and Magic table // - create a TableRoll that rolls once on the Potions table // - put both TableRolls in an ItemList // - create an ItemRoll that returns the ItemList 15% of the time. tempRoll = new TableRoll(Repository.GetTable("I. Map or Magic Determination")); tempRoll.Rolls = 2; ItemList tempList = new ItemList(); tempList.Add(tempRoll); // don't need tempRoll for the potions since Rolls = 1 tempList.Add(new TableRoll(Repository.GetTable("III. Potions"))); list.Add(new ItemRoll(tempList, DieRoll.FromString("d1"), 1, 15)); List.Add("D", list); list = new ItemList(); list.Add(new ItemRoll(new GameObject("cp", "cp"), DieRoll.FromString("d10"), 1000, 5)); list.Add(new ItemRoll(new GameObject("sp", "sp"), DieRoll.FromString("d12"), 1000, 25)); list.Add(new ItemRoll(new GameObject("ep", "ep"), DieRoll.FromString("d6"), 1000, 25)); list.Add(new ItemRoll(new GameObject("gp", "gp"), DieRoll.FromString("d8"), 1000, 25)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Gems and Jewels")), DieRoll.FromString("d12"), 1, 15)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Jewelry")), DieRoll.FromString("d8"), 1, 10)); // Any 3 plus 1 scroll: 25% -- same pattern as D tempRoll = new TableRoll(Repository.GetTable("I. Map or Magic Determination")); tempRoll.Rolls = 3; tempList = new ItemList(); tempList.Add(tempRoll); tempList.Add(new TableRoll(Repository.GetTable("III. Scrolls"))); list.Add(new ItemRoll(tempList, DieRoll.FromString("d1"), 1, 25)); List.Add("E", list); list = new ItemList(); list.Add(new ItemRoll(new GameObject("sp", "sp"), DieRoll.FromString("d20"), 1000, 10)); list.Add(new ItemRoll(new GameObject("ep", "ep"), DieRoll.FromString("d12"), 1000, 15)); list.Add(new ItemRoll(new GameObject("gp", "gp"), DieRoll.FromString("d10"), 1000, 40)); list.Add(new ItemRoll(new GameObject("pp", "pp"), DieRoll.FromString("d8"), 100, 35)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Gems and Jewels")), DieRoll.FromString("3d10"), 1, 20)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Jewelry")), DieRoll.FromString("d10"), 1, 10)); // Any 3 except swords or misc. weapons, plus 1 potion and 1 scroll: 30% // To exclude swords or misc. weapons we can ignore results above 75 on the Magic Items table. // This requires a modified version the Map or Magic Determination table. tempTable = new RollableTable(); tempTable.Dice = new DieRoll("d100"); tempTable.Add(new TableRoll(Repository.GetTable("II. Map Table")), 10); tempRoll = new TableRoll(Repository.GetTable("III. Magic Items")); tempRoll.IgnoreAbove = 75; tempTable.Add(tempRoll, 100); // create a TableRoll to roll 3 times on the temp table tempRoll = new TableRoll(tempTable); tempRoll.Rolls = 3; // create an ItemList and add the tempRoll and the potion and scroll rolls tempList = new ItemList(); tempList.Add(tempRoll); tempList.Add(new TableRoll(Repository.GetTable("III. Potions"))); tempList.Add(new TableRoll(Repository.GetTable("III. Scrolls"))); list.Add(new ItemRoll(tempList, DieRoll.FromString("d1"), 1, 30)); List.Add("F", list); list = new ItemList(); list.Add(new ItemRoll(new GameObject("gp", "gp"), DieRoll.FromString("10d4"), 1000, 50)); list.Add(new ItemRoll(new GameObject("pp", "pp"), DieRoll.FromString("d20"), 100, 50)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Gems and Jewels")), DieRoll.FromString("5d4"), 1, 30)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Jewelry")), DieRoll.FromString("d10"), 1, 25)); // Any 4 plus 1 scroll: 35% -- same pattern as E tempRoll = new TableRoll(Repository.GetTable("I. Map or Magic Determination")); tempRoll.Rolls = 4; tempList = new ItemList(); tempList.Add(tempRoll); tempList.Add(new TableRoll(Repository.GetTable("III. Scrolls"))); list.Add(new ItemRoll(tempList, DieRoll.FromString("d1"), 1, 35)); List.Add("G", list); list = new ItemList(); list.Add(new ItemRoll(new GameObject("cp", "cp"), DieRoll.FromString("5d6"), 1000, 25)); list.Add(new ItemRoll(new GameObject("sp", "sp"), DieRoll.FromString("d100"), 1000, 40)); list.Add(new ItemRoll(new GameObject("ep", "ep"), DieRoll.FromString("10d4"), 1000, 40)); list.Add(new ItemRoll(new GameObject("gp", "gp"), DieRoll.FromString("10d6"), 1000, 55)); list.Add(new ItemRoll(new GameObject("pp", "pp"), DieRoll.FromString("5d10"), 100, 25)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Gems and Jewels")), DieRoll.FromString("d100"), 1, 50)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Jewelry")), DieRoll.FromString("10d4"), 1, 50)); // Any 4 plus 1 scroll: 35% -- same pattern as E tempRoll = new TableRoll(Repository.GetTable("I. Map or Magic Determination")); tempRoll.Rolls = 4; tempList = new ItemList(); tempList.Add(tempRoll); tempList.Add(new TableRoll(Repository.GetTable("III. Potions"))); tempList.Add(new TableRoll(Repository.GetTable("III. Scrolls"))); list.Add(new ItemRoll(tempList, DieRoll.FromString("d1"), 1, 15)); List.Add("H", list); list = new ItemList(); list.Add(new ItemRoll(new GameObject("pp", "pp"), DieRoll.FromString("3d6"), 100, 30)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Gems and Jewels")), DieRoll.FromString("2d10"), 1, 55)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Jewelry")), DieRoll.FromString("d12"), 1, 50)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("I. Map or Magic Determination")), DieRoll.FromString("d1"), 1, 15)); List.Add("I", list); list = new ItemList(); list.Add(new ItemRoll(new GameObject("cp", "cp"), DieRoll.FromString("3d8"))); List.Add("J", list); list = new ItemList(); list.Add(new ItemRoll(new GameObject("sp", "sp"), DieRoll.FromString("3d6"))); List.Add("K", list); list = new ItemList(); list.Add(new ItemRoll(new GameObject("gp", "gp"), DieRoll.FromString("2d6"))); List.Add("L", list); list = new ItemList(); list.Add(new ItemRoll(new GameObject("ep", "ep"), DieRoll.FromString("2d4"))); List.Add("M", list); list = new ItemList(); list.Add(new ItemRoll(new GameObject("pp", "pp"), DieRoll.FromString("d6"))); List.Add("N", list); list = new ItemList(); list.Add(new ItemRoll(new GameObject("cp", "cp"), DieRoll.FromString("d4"), 1000, 25)); list.Add(new ItemRoll(new GameObject("sp", "sp"), DieRoll.FromString("d3"), 1000, 20)); List.Add("O", list); list = new ItemList(); list.Add(new ItemRoll(new GameObject("sp", "sp"), DieRoll.FromString("d6"), 1000, 30)); list.Add(new ItemRoll(new GameObject("ep", "ep"), DieRoll.FromString("d2"), 1000, 25)); List.Add("P", list); list = new ItemList(); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Gems and Jewels")), DieRoll.FromString("d4"), 1, 50)); List.Add("Q", list); list = new ItemList(); list.Add(new ItemRoll(new GameObject("gp", "gp"), DieRoll.FromString("2d4"), 1000, 40)); list.Add(new ItemRoll(new GameObject("pp", "pp"), DieRoll.FromString("10d6"), 100, 50)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Gems and Jewels")), DieRoll.FromString("4d8"), 1, 55)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Jewelry")), DieRoll.FromString("d12"), 1, 45)); List.Add("R", list); list = new ItemList(); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("III. Potions")), DieRoll.FromString("2d4"), 1, 40)); List.Add("S", list); list = new ItemList(); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("III. Scrolls")), DieRoll.FromString("d4"), 1, 50)); List.Add("T", list); list = new ItemList(); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Gems and Jewels")), DieRoll.FromString("10d8"), 1, 90)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Jewelry")), DieRoll.FromString("5d6"), 1, 80)); // 1 roll on each magic item table excluding potions and scrolls: 70% tempList = new ItemList(); tempList.Add(new TableRoll(Repository.GetTable("III. Rings"))); tempList.Add(new TableRoll(Repository.GetTable("III. Rods, Staves and Wands"))); tempList.Add(new TableRoll(Repository.GetTable("III. Miscellaneous Magic"))); tempList.Add(new TableRoll(Repository.GetTable("III. Armor and Shields"))); tempList.Add(new TableRoll(Repository.GetTable("III. Swords"))); tempList.Add(new TableRoll(Repository.GetTable("III. Miscellaneous Weapons"))); list.Add(new ItemRoll(tempList, new DieRoll("d1"), 1, 70)); List.Add("U", list); list = new ItemList(); // 2 rolls on each magic item table excluding potions and scrolls: 85% // Just reuse the temp list from "U" but resolve it twice list.Add(new ItemRoll(tempList, new DieRoll("2d1"), 1, 85)); List.Add("V", list); list = new ItemList(); list.Add(new ItemRoll(new GameObject("gp", "gp"), DieRoll.FromString("5d6"), 1000, 60)); list.Add(new ItemRoll(new GameObject("pp", "pp"), DieRoll.FromString("d8"), 100, 15)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Gems and Jewels")), DieRoll.FromString("10d8"), 1, 60)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Jewelry")), DieRoll.FromString("5d8"), 1, 50)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("II. Map Table")), DieRoll.FromString("d1"), 1, 55)); List.Add("W", list); list = new ItemList(); tempList = new ItemList(); tempList.Add(new TableRoll(Repository.GetTable("III. Miscellaneous Magic"))); tempList.Add(new TableRoll(Repository.GetTable("III. Potions"))); list.Add(new ItemRoll(tempList, new DieRoll("d1"), 1, 60)); List.Add("X", list); list = new ItemList(); list.Add(new ItemRoll(new GameObject("gp", "gp"), DieRoll.FromString("2d6"), 1000, 70)); List.Add("Y", list); list = new ItemList(); list.Add(new ItemRoll(new GameObject("cp", "cp"), DieRoll.FromString("d3"), 1000, 20)); list.Add(new ItemRoll(new GameObject("sp", "sp"), DieRoll.FromString("d4"), 1000, 25)); list.Add(new ItemRoll(new GameObject("ep", "ep"), DieRoll.FromString("d4"), 1000, 25)); list.Add(new ItemRoll(new GameObject("gp", "gp"), DieRoll.FromString("d4"), 1000, 30)); list.Add(new ItemRoll(new GameObject("pp", "pp"), DieRoll.FromString("d6"), 100, 30)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Gems and Jewels")), DieRoll.FromString("10d6"), 1, 55)); list.Add(new ItemRoll(new TableRoll(Repository.GetTable("Jewelry")), DieRoll.FromString("5d6"), 1, 50)); tempRoll = new TableRoll(Repository.GetTable("III. Magic Items")); tempRoll.Rolls = 3; list.Add(new ItemRoll(tempRoll, DieRoll.FromString("d1"), 1, 50)); List.Add("Z", list); return(List); }