public MultiMap <uint, EnchStoreItem> this[ItemRandomEnchantmentType type] { get { //(type != ItemRandomEnchantmentType.BonusList, "Random bonus lists do not have their own storage, use Suffix for them"); return(_data[(byte)type]); } }
public static ItemRandomEnchantmentId GetItemEnchantMod(int entry, ItemRandomEnchantmentType type) { if (entry == 0) { return(ItemRandomEnchantmentId.Empty); } if (entry == -1) { return(ItemRandomEnchantmentId.Empty); } var tab = RandomItemEnch[type].LookupByKey(entry); if (tab == null) { Log.outError(LogFilter.Player, "Item RandomProperty / RandomSuffix id #{0} used in `item_template` but it does not have records in `item_enchantment_template` table.", entry); return(ItemRandomEnchantmentId.Empty); } var selectedItem = tab.SelectRandomElementByWeight(enchant => enchant.chance); return(new ItemRandomEnchantmentId(selectedItem.type, selectedItem.ench)); }
public ItemRandomEnchantmentId(ItemRandomEnchantmentType type, uint id) { Type = type; Id = id; }
public static void LoadRandomEnchantmentsTable() { // for reload case RandomItemEnch[ItemRandomEnchantmentType.Property].Clear(); RandomItemEnch[ItemRandomEnchantmentType.Suffix].Clear(); // 0 1 2 3 SQLResult result = DB.World.Query("SELECT entry, type, ench, chance FROM item_enchantment_template"); if (result.IsEmpty()) { Log.outError(LogFilter.Player, "Loaded 0 Item Enchantment definitions. DB table `item_enchantment_template` is empty."); } uint count = 0; do { uint entry = result.Read <uint>(0); ItemRandomEnchantmentType type = (ItemRandomEnchantmentType)result.Read <byte>(1); uint ench = result.Read <uint>(2); float chance = result.Read <float>(3); switch (type) { case ItemRandomEnchantmentType.Property: if (!CliDB.ItemRandomPropertiesStorage.ContainsKey(ench)) { Log.outError(LogFilter.Sql, "Property {0} used in `item_enchantment_template` by entry {1} doesn't have exist in ItemRandomProperties.db2", ench, entry); continue; } break; case ItemRandomEnchantmentType.Suffix: if (!CliDB.ItemRandomSuffixStorage.ContainsKey(ench)) { Log.outError(LogFilter.Sql, "Suffix {0} used in `item_enchantment_template` by entry {1} doesn't have exist in ItemRandomSuffix.db2", ench, entry); continue; } break; case ItemRandomEnchantmentType.BonusList: if (Global.DB2Mgr.GetItemBonusList(ench) == null) { Log.outError(LogFilter.Sql, "Bonus list {0} used in `item_enchantment_template` by entry {1} doesn't have exist in ItemBonus.db2", ench, entry); continue; } break; default: Log.outError(LogFilter.Sql, "Invalid random enchantment type specified in `item_enchantment_template` table for `entry` {0} `ench` {1}", entry, ench); break; } if (chance < 0.000001f || chance > 100.0f) { Log.outError(LogFilter.Sql, "Random item enchantment for entry {0} type {1} ench {2} has invalid chance {3}", entry, type, ench, chance); continue; } switch (type) { case ItemRandomEnchantmentType.Property: RandomItemEnch[ItemRandomEnchantmentType.Property].Add(entry, new EnchStoreItem(type, ench, chance)); break; case ItemRandomEnchantmentType.Suffix: case ItemRandomEnchantmentType.BonusList: // random bonus lists use RandomSuffix field in Item-sparse.db2 RandomItemEnch[ItemRandomEnchantmentType.Suffix].Add(entry, new EnchStoreItem(type, ench, chance)); break; default: break; } ++count; } while (result.NextRow()); Log.outInfo(LogFilter.Player, "Loaded {0} Item Enchantment definitions", count); }
public EnchStoreItem(ItemRandomEnchantmentType _type, uint _ench, float _chance) { type = _type; ench = _ench; chance = _chance; }