private void DiceGenerator_Shown(object sender, EventArgs e) { this.Location = new Point(passedTextBoxLoc.X - passedTextBox.Width - 23, passedTextBoxLoc.Y - this.Height + 8); if (passedTextBox.Text == "") { numericUpDown1.Value = 0; numericUpDown2.Value = 0; numericUpDown3.Value = 0; diceStringLabel.Text = "Gold is set to NULL"; allowGeneration = true; } else { if (Dice.isValidDiceString(passedTextBox.Text)) { try { int[] result = Dice.parseDiceString(passedTextBox.Text); /* * if (result[1] < 0) * { * MessageBox.Show("It's not a valid die string! Minimum can't be lower than 0! Setting it to 0!"); * result[1] = 0; * } */ if (result[0] > 16) { MessageBox.Show("This dice string will take too many iterations, generating new one!"); string res = Dice.generateDiceString(result[1], result[2]); passedTextBox.Text = res; result = Dice.parseDiceString(res); } numericUpDown1.Value = result[0]; numericUpDown2.Value = result[1]; numericUpDown3.Value = result[2]; diceStringLabel.Text = "Die string: " + passedTextBox.Text; allowGeneration = true; } catch { MessageBox.Show("Something went wrong while calculating min-max! Generating new dice string!"); allowGeneration = true; doGeneration(); } } else { MessageBox.Show("It's not a valid dice string, generating new one!"); allowGeneration = true; doGeneration(); } } }
private void doGeneration() { if (allowGeneration) { string result = Dice.generateDiceString(int.Parse(numericUpDown2.Value.ToString()), int.Parse(numericUpDown3.Value.ToString())); if (Dice.isValidDiceString(result)) { int[] intRes = Dice.parseDiceString(result); numericUpDown1.Value = intRes[0]; numericUpDown2.Value = intRes[1]; numericUpDown3.Value = intRes[2]; passedTextBox.Text = result; diceStringLabel.Text = "Dice string: " + result; } else { if (result.Contains("NULL")) { passedTextBox.Text = ""; } diceStringLabel.Text = result; } } }
private static void MakeItemOutOfGroup(string itemGroup, string dice, int chance, bool lockedChest) { if (!Dice.isValidDiceString(dice)) { _warnings.Add("Dice string on " + itemGroup + " is invalid"); return; } int literalAmount = Dice.Roll(dice); // limit it to 100 items out of group if (literalAmount > 100) { literalAmount = 100; } ItemGroup group = getItemGroupByName(itemGroup); if (group == null) { _warnings.Add("Random: Could not find item group of '" + itemGroup + "'"); return; } for (int i = 1; i <= literalAmount; i++) { // random starts from 0 here, since arrays in c# start from location [0] and minus 1 since Count sum of literal Count // and due array starts from 0 we'll get number shift of 1 int itemOutOfGroup = Dice.getRandom(0, group.Items.Count() - 1); if (Dice.getRandom(1, 100) <= chance) { if (!isValidItem(group.Items[itemOutOfGroup])) { if (_debug) { if (MessageBox.Show("Will we debug '" + group.Items[itemOutOfGroup] + "'?", "Alert", MessageBoxButtons.YesNo) == DialogResult.Yes) { string debug = "// Debug -- itemgroup\r\n{\r\n"; foreach (char c in group.Items[itemOutOfGroup]) { debug += string.Format("\tint({0}) char('{1}')", (int)c, c) + "\r\n"; } debug += string.Format("\t len({0}) indexInGroup({1})\r\n", group.Items[itemOutOfGroup].Length, itemOutOfGroup); debug += "}"; Clipboard.SetText(debug); } } _warnings.Add(string.Format("Item '{0}' in group '{1}' is not valid!", group.Items[itemOutOfGroup], group.Name)); } else { addToBag(group.Items[itemOutOfGroup], 1); } } } }
private static void MakeSpecifiedLoot(string objName, string amount, int chance, bool limitedToTwenty) { if (!isValidItem(objName)) { if (limitedToTwenty) { _warnings.Add(string.Format("Item '{0}' is not valid!'", objName)); } else { _warnings.Add(string.Format("CutUp '{0}' is not valid!'", objName.Trim())); } return; } if (Dice.isValidDiceString(amount)) { int literalAmount = Dice.Roll(amount); if (limitedToTwenty) { // Stupid clause imo... if (literalAmount > 20) { literalAmount = 20; } } // Drop chance is per 1 item dropped, so it goes trough them one-by-one for (int i = 1; i <= literalAmount; i++) { if (Dice.getRandom(1, 100) <= chance) { // atm i know that specified item in drop is limited to 20, while cut action does not // have item amount restriction if (limitedToTwenty) { addToBag(objName, 1); } else { addToCutBag(objName, 1); } } } } else { _warnings.Add("Dice string on " + objName + " is invalid"); } }
public static void MakeLoot(Loot template, List <ItemGroup> itemGroups = null, List <Item> items = null) { ///////// Reset loot drop ////////// _bag.Clear(); _cutBag.Clear(); _warnings.Clear(); // Save template name _lootTemplate = template; ///////// Populate items ////////// if (items == null) { _warnings.Add("No items loaded, so no validation check."); } else { _items = items; } if (itemGroups != null) { // Populate global itemgroups _itemGroups = itemGroups; } else { _warnings.Add("Item Groups are not loaded!"); } ///////// Let's generate gold //////////// if (!string.IsNullOrWhiteSpace(template.Gold) && Dice.isValidDiceString(template.Gold)) { int goldSum = Dice.Roll(template.Gold); int goldDung = Convert.ToInt32(GOLD_MULTIPLIER_DUNG * goldSum); int goldOut = Convert.ToInt32(GOLD_MULTIPLIER_OUT * goldSum); addToBag(string.Format("{0}", "Gold Dungeon: ", goldDung), goldDung); addToBag(string.Format("{0}", "Gold Outside: "), goldOut); } ///////// Done with gold ///////// //////// Do we make locked chest? ///////// if (template.ChestQuality > 0) { MakeLockedChest(template.ChestQuality, template.ChestChance); } //////// End of locked chest ///////// //////// Do we make skill books? ///////// if (template.skillBooks.Count > 0) { foreach (var skillBook in template.skillBooks) { MakeSkillBook(skillBook.skillTier, skillBook.ChanceOfDrop); } } //////// End of skill books ///////// //////// Magic items ///////// if (template.MagicQuality > 0) { if (template.randMagicItemFromGroup.Count > 0) { if (_itemGroups != null) { foreach (var group in template.randMagicItemFromGroup) { MakeMagicItem(group.Name, template.MagicQuality, group.ChanceOfDrop); } } } else { _warnings.Add("Template has magic quality but no magic items! Variable is useless!"); } } else { if (template.randMagicItemFromGroup.Count > 0) { _warnings.Add("Template has magic quality of 0 or null but contains magic item drops (Won't be dropped)"); } } //////// End of magic items ///////// //////// Random item out of group ///////// if (_itemGroups != null) { if (template.randItemFromGroup.Count > 0) { foreach (var group in template.randItemFromGroup) { MakeItemOutOfGroup(group.Name, group.UpToHowMuchDropped, group.ChanceOfDropPerItem, false); } //transferStacksToLoot(); } } //////// End of random out of group ///////// //////// Make specified loot ///////// if (template.items.Count() > 0) { foreach (var item in template.items) { MakeSpecifiedLoot(item.Name, item.UpToHowMuchDropped, item.ChanceOfDropPerItem, true); } //transferStacksToLoot(); } //////// End of specified loot ///////// //////// On corpse cut ///////// if (template.cutUps.Count() > 0) { foreach (var item in template.cutUps) { MakeSpecifiedLoot(item.ItemName, item.Amount, 100, false); } } //////// end of corpse cut ///////// }
public static string exportLootTemplates(List <Loot> templates) { string output = "// File generated by Pol-Item-lootgroups tool\r\n\r\n\r\n"; foreach (var template in templates) { output += "lootgroup " + template.Name + "\r\n"; output += "{\r\n"; // check if there is gold and if it's valid if (Dice.isValidDiceString(template.Gold)) { output += "\t// gold \r\n"; output += "\tgold\t" + template.Gold + "\r\n"; } output += "\r\n\t// general loot variables\r\n"; if (template.MagicQuality > 0) { output += "\tmagic_quality\t" + template.MagicQuality.ToString() + "\r\n"; } if (template.ChestChance > 0) { output += "\tchest_chance\t" + template.ChestChance + "\r\n"; output += "\tchest_quality\t" + template.ChestQuality + "\r\n"; } // add specific items if (template.items.Count() > 0) { output += "\r\n\t// specific items\r\n"; foreach (var item in template.items) { if (Dice.isValidDiceString(item.UpToHowMuchDropped)) { output += "\tItem\t" + item.Name + "\t" + item.UpToHowMuchDropped + "\t" + item.ChanceOfDropPerItem + "\r\n"; } } } if (template.randItemFromGroup.Count() > 0) { output += "\r\n\t// random items out of group\r\n"; foreach (var item in template.randItemFromGroup) { if (Dice.isValidDiceString(item.UpToHowMuchDropped)) { output += "\tRandom\t" + item.Name + "\t" + item.UpToHowMuchDropped + "\t" + item.ChanceOfDropPerItem.ToString() + "\r\n"; } } } if (template.randMagicItemFromGroup.Count > 0) { output += "\r\n\t// random magic items out of group\r\n"; foreach (var item in template.randMagicItemFromGroup) { output += "\tmagic_group\t" + item.Name + "\t" + item.ChanceOfDrop.ToString() + "\r\n"; } } if (template.skillBooks.Count > 0) { output += "\r\n\t// skillbooks \r\n"; foreach (var book in template.skillBooks) { output += "\tskillbook\t" + book.skillTier.ToString() + "\t" + book.ChanceOfDrop.ToString() + "\r\n"; } } if (template.cutUps.Count > 0) { output += "\r\n\t// drops when mob is cut \r\n"; foreach (var item in template.cutUps) { output += "\tcutup\t" + item.ItemName + "\t" + item.Amount + "\r\n"; } } output += "\r\n\r\n"; if (template.Head == 1) { output += "\tHead\t1\r\n"; } else { output += "\tHead\t0\r\n"; } if (template.Blood == 1) { output += "\tBlood\t1\r\n"; } else { output += "\tBlood\t0\r\n"; } output += "}\r\n\r\n"; } return(output); }