Updated to 8.2.0.31429 (scripts disabled atm, they still need updated)

Code Port from TrinityCore https://github.com/TrinityCore/TrinityCore
Casc from WoW-Tools https://github.com/WoW-Tools/CASCExplorer
This commit is contained in:
hondacrx
2019-08-14 11:20:42 -04:00
parent e4d500f4b5
commit 125e3b3ac7
232 changed files with 12268 additions and 14670 deletions
+39 -161
View File
@@ -22,148 +22,79 @@ using System.Collections.Generic;
namespace Game.Entities
{
public class ItemEnchantment
public class ItemEnchantmentManager
{
static ItemEnchantment()
public static void LoadItemRandomBonusListTemplates()
{
RandomItemEnch = new EnchantmentStore();
}
uint oldMSTime = Time.GetMSTime();
public static void LoadRandomEnchantmentsTable()
{
// for reload case
RandomItemEnch[ItemRandomEnchantmentType.Property].Clear();
RandomItemEnch[ItemRandomEnchantmentType.Suffix].Clear();
_storage.Clear();
// 0 1 2 3
SQLResult result = DB.World.Query("SELECT entry, type, ench, chance FROM item_enchantment_template");
// 0 1 2
SQLResult result = DB.World.Query("SELECT Id, BonusListID, Chance FROM item_random_bonus_list_template");
if (result.IsEmpty())
{
Log.outError(LogFilter.Player, "Loaded 0 Item Enchantment definitions. DB table `item_enchantment_template` is empty.");
return;
}
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);
uint id = result.Read<uint>(0);
uint bonusListId = result.Read<uint>(1);
float chance = result.Read<float>(2);
switch (type)
if (Global.DB2Mgr.GetItemBonusList(bonusListId) == null)
{
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;
Log.outError(LogFilter.Sql, $"Bonus list {bonusListId} used in `item_random_bonus_list_template` by id {id} doesn't have exist in ItemBonus.db2");
continue;
}
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);
Log.outError(LogFilter.Sql, $"Bonus list {bonusListId} used in `item_random_bonus_list_template` by id {id} has invalid chance {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;
}
if (!_storage.ContainsKey(id))
_storage[id] = new RandomBonusListIds();
RandomBonusListIds ids = _storage[id];
ids.BonusListIDs.Add(bonusListId);
ids.Chances.Add(chance);
++count;
} while (result.NextRow());
Log.outInfo(LogFilter.Player, "Loaded {0} Item Enchantment definitions", count);
Log.outInfo(LogFilter.Player, $"Loaded {count} Random item bonus list definitions in {Time.GetMSTimeDiffToNow(oldMSTime)} ms");
}
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 static ItemRandomEnchantmentId GenerateItemRandomPropertyId(uint item_id)
public static uint GenerateItemRandomBonusListId(uint item_id)
{
ItemTemplate itemProto = Global.ObjectMgr.GetItemTemplate(item_id);
if (itemProto == null)
return ItemRandomEnchantmentId.Empty;
return 0;
// item must have one from this field values not null if it can have random enchantments
if (itemProto.GetRandomProperty() == 0 && itemProto.GetRandomSuffix() == 0)
return ItemRandomEnchantmentId.Empty;
if (itemProto.RandomBonusListTemplateId == 0)
return 0;
// item can have not null only one from field values
if (itemProto.GetRandomProperty() != 0 && itemProto.GetRandomSuffix() != 0)
var tab = _storage.LookupByKey(itemProto.RandomBonusListTemplateId);
if (tab == null)
{
Log.outError(LogFilter.Sql, "Item template {0} have RandomProperty == {1} and RandomSuffix == {2}, but must have one from field =0", itemProto.GetId(), itemProto.GetRandomProperty(), itemProto.GetRandomSuffix());
return ItemRandomEnchantmentId.Empty;
Log.outError(LogFilter.Sql, $"Item RandomBonusListTemplateId id {itemProto.RandomBonusListTemplateId} used in `item_template_addon` but it does not have records in `item_random_bonus_list_template` table.");
return 0;
}
// RandomProperty case
if (itemProto.GetRandomProperty() != 0)
return GetItemEnchantMod((int)itemProto.GetRandomProperty(), ItemRandomEnchantmentType.Property);
// RandomSuffix case
else
return GetItemEnchantMod((int)itemProto.GetRandomSuffix(), ItemRandomEnchantmentType.Suffix);
}
public static uint GenerateEnchSuffixFactor(uint item_id)
{
ItemTemplate itemProto = Global.ObjectMgr.GetItemTemplate(item_id);
if (itemProto == null)
return 0;
if (itemProto.GetRandomSuffix() == 0)
return 0;
return GetRandomPropertyPoints(itemProto.GetBaseItemLevel(), itemProto.GetQuality(), itemProto.GetInventoryType(), itemProto.GetSubClass());
//todo fix me this is ulgy
return tab.BonusListIDs.SelectRandomElementByWeight(x => (float)tab.Chances[tab.BonusListIDs.IndexOf(x)]);
}
public static uint GetRandomPropertyPoints(uint itemLevel, ItemQuality quality, InventoryType inventoryType, uint subClass)
{
{
uint propIndex;
switch (inventoryType)
{
case InventoryType.Head:
@@ -208,11 +139,11 @@ namespace Game.Entities
default:
return 0;
}
RandPropPointsRecord randPropPointsEntry = CliDB.RandPropPointsStorage.LookupByKey(itemLevel);
if (randPropPointsEntry == null)
return 0;
// Select rare/epic modifier
switch (quality)
{
case ItemQuality.Uncommon:
@@ -225,69 +156,16 @@ namespace Game.Entities
case ItemQuality.Artifact:
return randPropPointsEntry.Epic[propIndex];
}
return 0;
}
static EnchantmentStore RandomItemEnch;
public class EnchStoreItem
{
public EnchStoreItem()
{
ench = 0;
chance = 0;
}
public EnchStoreItem(ItemRandomEnchantmentType _type, uint _ench, float _chance)
{
type = _type;
ench = _ench;
chance = _chance;
}
public ItemRandomEnchantmentType type;
public uint ench;
public float chance;
}
class EnchantmentStore
{
public EnchantmentStore()
{
_data[(byte)ItemRandomEnchantmentType.Property] = new MultiMap<uint, EnchStoreItem>();
_data[(byte)ItemRandomEnchantmentType.Suffix] = new MultiMap<uint, EnchStoreItem>();
}
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];
}
}
MultiMap<uint, EnchStoreItem>[] _data = new MultiMap<uint, EnchStoreItem>[2];
}
static Dictionary<uint, RandomBonusListIds> _storage = new Dictionary<uint, RandomBonusListIds>();
}
public struct ItemRandomEnchantmentId
public class RandomBonusListIds
{
public static ItemRandomEnchantmentId Empty = default(ItemRandomEnchantmentId);
public ItemRandomEnchantmentId(ItemRandomEnchantmentType type, uint id)
{
Type = type;
Id = id;
}
public ItemRandomEnchantmentType Type;
public uint Id;
}
public enum ItemRandomEnchantmentType
{
Property = 0,
Suffix = 1,
BonusList = 2
public List<uint> BonusListIDs = new List<uint>();
public List<double> Chances = new List<double>();
}
}