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 ///////// }