public override IEnumerable <StoreDictionary> Get(string collection, StoreList columns, StoreDictionary where, int limit) { List <StoreDictionary> records = new List <StoreDictionary>(); JSON names = GetRecords(collection); for (int i = 0; i < names.length; i++) { if (limit == 0) { break; } string name = names[i].stringValue; if (IsRecordIncluded(collection, name, where)) { StoreDictionary record = new StoreDictionary(); foreach (string column in columns) { string value = Get("collections." + collection + "." + name + "." + column); record.Add(column, value); } records.Add(record); limit--; } } return(records); }
public override int Set(string collection, StoreDictionary values, StoreDictionary where) { string valuesJSON = values.ToJSON().ToString(); string whereJSON = where != null ? where.ToJSON().ToString() : ""; return(iosStore_set(collection, valuesJSON, whereJSON)); }
public StoreDictionary Bake(string name, int balance) { StoreDictionary values = Bake(name); values.Add(balanceColumn, balance + ""); return(values); }
public override int Set(string collection, StoreDictionary values, StoreDictionary where) { string valuesJSON = values.ToJSON().ToString(); string whereJSON = where != null ? where.ToJSON().ToString() : ""; return(native.CallStatic <int>("set", collection, valuesJSON, whereJSON)); }
// Non-WDB data but nevertheless data that should be saved to gameobject_template public static string GameobjectTemplateNonWDB(Dictionary<Guid, GameObject> gameobjects) { if (gameobjects.Count == 0) return String.Empty; var templates = new StoreDictionary<uint, GameObjectTemplateNonWDB>(); foreach (var goT in gameobjects) { if (templates.ContainsKey(goT.Key.GetEntry())) continue; var go = goT.Value; var template = new GameObjectTemplateNonWDB { Size = go.Size.GetValueOrDefault(1.0f), Faction = go.Faction.GetValueOrDefault(0), Flags = go.Flags.GetValueOrDefault(GameObjectFlag.None) }; if (template.Faction == 1 || template.Faction == 2 || template.Faction == 3 || template.Faction == 4 || template.Faction == 5 || template.Faction == 6 || template.Faction == 115 || template.Faction == 116 || template.Faction == 1610 || template.Faction == 1629 || template.Faction == 2203 || template.Faction == 2204) // player factions template.Faction = 0; template.Flags &= ~GameObjectFlag.Triggered; template.Flags &= ~GameObjectFlag.Damaged; template.Flags &= ~GameObjectFlag.Destroyed; templates.Add(goT.Key.GetEntry(), template, null); } var templatesDb = SQLDatabase.GetDict<uint, GameObjectTemplateNonWDB>(templates.Keys()); return SQLUtil.CompareDicts(templates, templatesDb, StoreNameType.GameObject); }
public virtual StoreDictionary Bake(string name, string group, int level, bool owned, bool equipped) { StoreDictionary values = Bake(name, group, owned, equipped); values.Add(levelColumn, level + ""); return(values); }
public virtual int Set(string column, string value, string whereColumn, string whereValue) { StoreDictionary values = new StoreDictionary(column, value); StoreDictionary where = new StoreDictionary(whereColumn, whereValue); return(Set(values, where)); }
public static StoreDictionary GetStoreDictionary(JSONDataStore store) { var storeDictionary = new StoreDictionary(store); storeDictionary.LoadDictionary(); return(storeDictionary); }
public virtual bool SetLevelOfGroup(string group, int level) { if (group != noGroupValue) { if (level < 0) { level = 0; } string equipped = GetEquipped(group); if (!string.IsNullOrEmpty(equipped)) { Unequip(equipped); } StoreDictionary columns = new StoreDictionary(equippedColumn, equippedValue); StoreDictionary where = new StoreDictionary(groupColumn, group, levelColumn, level + ""); if (cachedLevel.ContainsKey(group)) { cachedLevel[group] = level; } else { cachedLevel.Add(group, level); } return(Set(columns, where) == 1); } return(false); }
public Task ClearAsync() { var store = StoreDictionary.GetStoreDictionary(this); store.Clear(); store.Save(); return(Task.FromResult(0)); }
public Task DeleteAsync <T>(string key) { var store = StoreDictionary.GetStoreDictionary(this); store.Remove(key); store.Save(); return(Task.FromResult(0)); }
public Task StoreAsync <T>(string key, T value) { var store = StoreDictionary.GetStoreDictionary(this); store[key] = JsonConvert.SerializeObject(value); store.Save(); return(Task.FromResult(0)); }
private List <Store> RemoveInferiorShops(List <Store> storeList, List <Item> itemList) { // ToDo: switch to new BitArrays in Store class List <BitArray> storeBitArrayList = new List <BitArray>(storeList.Count); foreach (Store store in storeList) { BitArray itemBitArray = new BitArray(itemList.Count); foreach (Item item in itemList) { if (store.getQty(item.extid) > item.qty) { // write into bitArray itemBitArray.Set(itemList.IndexOf(item), true); } } storeBitArrayList.Add(itemBitArray); } //2. find stores providing at least the same products int i = storeBitArrayList.Count - 1; int j = 0; while (i >= 0) { while (j < i) { if (storeBitArrayList[j] != storeBitArrayList[i] && storeBitArrayList[j].Or(storeBitArrayList[i]) == storeBitArrayList[j]) // there is another store providing everything this one provides { // now compare prices Boolean isShopInferior = true; foreach (Item item in itemList) { // if price is at least once lower //if (item.price < storeList[j].getPrice(item.extid) && item.price > 0) if (storeList[i].getPrice(item.extid) < storeList[j].getPrice(item.extid) && storeList[i].getPrice(item.extid) > 0) { isShopInferior = false; break; } } if (isShopInferior) { storeBitArrayList.RemoveAt(i); StoreDictionary.Remove(storeList[i].getName()); //wie bekomme ich den shop zu fassen?? storeList.RemoveAt(i); break; } } j++; } i--; } return(storeList); }
public bool Set(string name, string value) { if (Set(name, "value", value) == 0) { StoreDictionary values = Bake(name); values.Add("value", value); return(Add(values) == 1); } return(true); }
public Task <T> GetAsync <T>(string key) { var store = StoreDictionary.GetStoreDictionary(this); string value; return(Task.FromResult( store.TryGetValue(key, out value) ? JsonConvert.DeserializeObject <T>(value) : default(T))); }
private void RemoveStoresWitoutAnyWantedItems() { var keysToRemove = StoreDictionary.Keys.Except(storesWithItemsList).ToList(); foreach (var key in keysToRemove) { StoreDictionary.Remove(key); } AddStatus(Environment.NewLine + " Number of stores with at least one item: " + StoreDictionary.Count + Environment.NewLine); }
public static string CreatureEquip(Dictionary <Guid, Unit> units) { if (units.Count == 0) { return(string.Empty); } if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_equip_template)) { return(string.Empty); } var equips = new StoreDictionary <ushort, CreatureEquipment>(); foreach (var unit in units) { var equip = new CreatureEquipment(); var npc = unit.Value; var entry = (ushort)unit.Key.GetEntry(); if (npc.Equipment == null || npc.Equipment.Length != 3) { continue; } if (npc.Equipment[0] == 0 && npc.Equipment[1] == 0 && npc.Equipment[2] == 0) { continue; } if (equips.ContainsKey(entry)) { var existingEquip = equips[entry].Item1; if (existingEquip.ItemEntry1 != npc.Equipment[0] || existingEquip.ItemEntry2 != npc.Equipment[1] || existingEquip.ItemEntry3 != npc.Equipment[2]) { equips.Remove(entry); // no conflicts } continue; } equip.ItemEntry1 = npc.Equipment[0]; equip.ItemEntry2 = npc.Equipment[1]; equip.ItemEntry3 = npc.Equipment[2]; equips.Add(entry, equip); } var entries = equips.Keys(); var equipsDb = SQLDatabase.GetDict <ushort, CreatureEquipment>(entries); return(SQLUtil.CompareDicts(equips, equipsDb, StoreNameType.Unit)); }
public override IEnumerable <StoreDictionary> Get(string collection, StoreList columns, StoreDictionary where, int limit) { string columnsJSON = columns.ToJSON().ToString(); string whereJSON = where != null ? where.ToJSON().ToString() : ""; string recordsJSON = native.CallStatic <string>("get", collection, columnsJSON, whereJSON, limit < 0 ? null : limit + ""); JSON recordsArray = JSON.Parse(recordsJSON); StoreDictionary[] records = new StoreDictionary[recordsArray.length]; for (int i = 0; i < records.Length; i++) { records[i] = new StoreDictionary(recordsArray[i]); } return(records); }
public static string ModelData(Dictionary <Guid, Unit> units) { if (units.Count == 0) { return(string.Empty); } if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_model_info)) { return(string.Empty); } // Build a dictionary with model data; model is the key var models = new StoreDictionary <uint, ModelData>(); foreach (var npc in units.Select(unit => unit.Value)) { uint modelId; if (npc.Model.HasValue) { modelId = npc.Model.Value; } else { continue; } // Do not add duplicate models if (models.ContainsKey(modelId)) { continue; } float scale = npc.Size.GetValueOrDefault(1.0f); var model = new ModelData { BoundingRadius = npc.BoundingRadius.GetValueOrDefault(0.306f) / scale, CombatReach = npc.CombatReach.GetValueOrDefault(1.5f) / scale, Gender = npc.Gender.GetValueOrDefault(Gender.Male) }; models.Add(modelId, model, null); } var entries = models.Keys(); var modelsDb = SQLDatabase.GetDict <uint, ModelData>(entries, "modelid"); return(SQLUtil.CompareDicts(models, modelsDb, StoreNameType.None, "modelid")); }
public virtual StoreDictionary Bake(string name, string group, bool owned, bool equipped) { StoreDictionary values = Bake(name); values.Add(groupColumn, group); if (owned) { values.Add(balanceColumn, ownedValue); if (equipped) { values.Add(equippedColumn, equippedValue); } } return(values); }
// Non-WDB data but nevertheless data that should be saved to gameobject_template public static string GameobjectTemplateNonWDB(Dictionary <Guid, GameObject> gameobjects) { if (gameobjects.Count == 0) { return(string.Empty); } if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.gameobject_template)) { return(string.Empty); } var templates = new StoreDictionary <uint, GameObjectTemplateNonWDB>(); foreach (var goT in gameobjects) { if (templates.ContainsKey(goT.Key.GetEntry())) { continue; } var go = goT.Value; var template = new GameObjectTemplateNonWDB { Size = go.Size.GetValueOrDefault(1.0f), Faction = go.Faction.GetValueOrDefault(0), Flags = go.Flags.GetValueOrDefault(GameObjectFlag.None) }; if (template.Faction == 1 || template.Faction == 2 || template.Faction == 3 || template.Faction == 4 || template.Faction == 5 || template.Faction == 6 || template.Faction == 115 || template.Faction == 116 || template.Faction == 1610 || template.Faction == 1629 || template.Faction == 2203 || template.Faction == 2204) // player factions { template.Faction = 0; } template.Flags &= ~GameObjectFlag.Triggered; template.Flags &= ~GameObjectFlag.Damaged; template.Flags &= ~GameObjectFlag.Destroyed; templates.Add(goT.Key.GetEntry(), template, null); } var templatesDb = SQLDatabase.GetDict <uint, GameObjectTemplateNonWDB>(templates.Keys()); return(SQLUtil.CompareDicts(templates, templatesDb, StoreNameType.GameObject)); }
private bool IsRecordIncluded(string collection, string name, StoreDictionary where) { if (where != null) { foreach (KeyValuePair <string, string> entry in where) { string column = entry.Key; string value = entry.Value; if (Get("collections." + collection + "." + name + "." + column) != value) { return(false); } } } return(true); }
public static string GameobjectTemplateNonWDB(Dictionary<WowGuid, GameObject> gameobjects) { if (gameobjects.Count == 0) return string.Empty; if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.gameobject_template)) return string.Empty; var templates = new StoreDictionary<uint, GameObjectTemplateNonWDB>(); foreach (var goT in gameobjects) { if (templates.ContainsKey(goT.Key.GetEntry())) continue; var go = goT.Value; if (Settings.AreaFilters.Length > 0) if (!(go.Area.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.AreaFilters))) continue; if (Settings.MapFilters.Length > 0) if (!(go.Map.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.MapFilters))) continue; var template = new GameObjectTemplateNonWDB { Size = go.Size.GetValueOrDefault(1.0f), Faction = go.Faction.GetValueOrDefault(0), Flags = go.Flags.GetValueOrDefault(GameObjectFlag.None) }; if (template.Faction == 1 || template.Faction == 2 || template.Faction == 3 || template.Faction == 4 || template.Faction == 5 || template.Faction == 6 || template.Faction == 115 || template.Faction == 116 || template.Faction == 1610 || template.Faction == 1629 || template.Faction == 2203 || template.Faction == 2204) // player factions template.Faction = 0; template.Flags &= ~GameObjectFlag.Triggered; template.Flags &= ~GameObjectFlag.Damaged; template.Flags &= ~GameObjectFlag.Destroyed; templates.Add(goT.Key.GetEntry(), template); } var templatesDb = SQLDatabase.GetDict<uint, GameObjectTemplateNonWDB>(templates.Keys()); return SQLUtil.CompareDicts(templates, templatesDb, StoreNameType.GameObject); }
public override IEnumerable <StoreDictionary> Get(string collection, StoreList columns, StoreDictionary where, int limit) { string columnsJSON = columns.ToJSON().ToString(); string whereJSON = where != null ? where.ToJSON().ToString() : ""; System.IntPtr pointer = iosStore_get(collection, columnsJSON, whereJSON, limit < 0 ? "" : limit + ""); string recordsJSON = Marshal.PtrToStringAnsi(pointer); Marshal.FreeHGlobal(pointer); JSON recordsArray = JSON.Parse(recordsJSON); StoreDictionary[] records = new StoreDictionary[recordsArray.length]; for (int i = 0; i < records.Length; i++) { records[i] = new StoreDictionary(recordsArray[i]); } return(records); }
public static string CreatureEquip(Dictionary<Guid, Unit> units) { if (units.Count == 0) return string.Empty; if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_equip_template)) return string.Empty; var equips = new StoreDictionary<ushort, CreatureEquipment>(); foreach (var unit in units) { var equip = new CreatureEquipment(); var npc = unit.Value; var entry = (ushort)unit.Key.GetEntry(); if (npc.Equipment == null || npc.Equipment.Length != 3) continue; if (npc.Equipment[0] == 0 && npc.Equipment[1] == 0 && npc.Equipment[2] == 0) continue; if (equips.ContainsKey(entry)) { var existingEquip = equips[entry].Item1; if (existingEquip.ItemEntry1 != npc.Equipment[0] || existingEquip.ItemEntry2 != npc.Equipment[1] || existingEquip.ItemEntry3 != npc.Equipment[2]) equips.Remove(entry); // no conflicts continue; } equip.ItemEntry1 = npc.Equipment[0]; equip.ItemEntry2 = npc.Equipment[1]; equip.ItemEntry3 = npc.Equipment[2]; equips.Add(entry, equip); } var entries = equips.Keys(); var equipsDb = SQLDatabase.GetDict<ushort, CreatureEquipment>(entries); return SQLUtil.CompareDicts(equips, equipsDb, StoreNameType.Unit); }
public override int Set(string collection, StoreDictionary values, StoreDictionary where) { int affected = 0; JSON names = GetRecords(collection); for (int i = 0; i < names.length; i++) { string name = names[i].stringValue; if (IsRecordIncluded(collection, name, where)) { foreach (KeyValuePair <string, string> entry in values) { string column = entry.Key; string value = entry.Value; Set("collections." + collection + "." + name + "." + column, value); } affected++; } } return(affected); }
public override int Remove(string collection, StoreDictionary where) { int affected = 0; StoreList columns = new StoreList(JSON.Parse(Get("meta.collections." + collection))); JSON names = GetRecords(collection); for (int i = 0; i < names.length; i++) { string name = names[i].stringValue; if (IsRecordIncluded(collection, name, where)) { foreach (string column in columns) { Delete("collections." + collection + "." + name + "." + column); } RemoveRecord(collection, name); affected++; } } return(affected); }
public virtual string GetEquipped(string group = singleGroupValue) { if (group != noGroupValue) { foreach (KeyValuePair <string, string> entry in cachedGroup) { if (entry.Value == group && cachedEquipped.ContainsKey(entry.Key) && cachedEquipped[entry.Key]) { return(entry.Key); } } StoreDictionary where = new StoreDictionary(groupColumn, group, equippedColumn, equippedValue); string name = Get(nameColumn, where); if (!string.IsNullOrEmpty(name)) { if (cachedGroup.ContainsKey(name)) { cachedGroup[name] = group; } else { cachedGroup.Add(name, group); } if (cachedEquipped.ContainsKey(name)) { cachedEquipped[name] = true; } else { cachedEquipped.Add(name, true); } } return(name); } return(null); }
public static string NpcTemplateNonWDB(Dictionary<WowGuid, Unit> units) { if (ClientVersion.AddedInVersion(ClientType.WarlordsOfDraenor)) return string.Empty; if (units.Count == 0) return string.Empty; if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_template)) return string.Empty; var levels = GetLevels(units); var templates = new StoreDictionary<uint, UnitTemplateNonWDB>(); foreach (var unit in units) { if (templates.ContainsKey(unit.Key.GetEntry())) continue; var npc = unit.Value; var template = new UnitTemplateNonWDB { GossipMenuId = npc.GossipId, MinLevel = (int) levels[unit.Key.GetEntry()].Item1, MaxLevel = (int) levels[unit.Key.GetEntry()].Item2, Faction = npc.Faction.GetValueOrDefault(35), NpcFlag = (uint) npc.NpcFlags.GetValueOrDefault(NPCFlags.None), SpeedRun = npc.Movement.RunSpeed, SpeedWalk = npc.Movement.WalkSpeed, BaseAttackTime = npc.MeleeTime.GetValueOrDefault(2000), RangedAttackTime = npc.RangedTime.GetValueOrDefault(2000), UnitClass = (uint) npc.Class.GetValueOrDefault(Class.Warrior), UnitFlag = (uint) npc.UnitFlags.GetValueOrDefault(UnitFlags.None), UnitFlag2 = (uint) npc.UnitFlags2.GetValueOrDefault(UnitFlags2.None), DynamicFlag = (uint) npc.DynamicFlags.GetValueOrDefault(UnitDynamicFlags.None), VehicleId = npc.Movement.VehicleId, HoverHeight = npc.HoverHeight.GetValueOrDefault(1.0f) }; if (template.Faction == 1 || template.Faction == 2 || template.Faction == 3 || template.Faction == 4 || template.Faction == 5 || template.Faction == 6 || template.Faction == 115 || template.Faction == 116 || template.Faction == 1610 || template.Faction == 1629 || template.Faction == 2203 || template.Faction == 2204) // player factions template.Faction = 35; template.UnitFlag &= ~(uint)UnitFlags.IsInCombat; template.UnitFlag &= ~(uint)UnitFlags.PetIsAttackingTarget; template.UnitFlag &= ~(uint)UnitFlags.PlayerControlled; template.UnitFlag &= ~(uint)UnitFlags.Silenced; template.UnitFlag &= ~(uint)UnitFlags.PossessedByPlayer; template.DynamicFlag &= ~(uint)UnitDynamicFlags.Lootable; template.DynamicFlag &= ~(uint)UnitDynamicFlags.Tapped; template.DynamicFlag &= ~(uint)UnitDynamicFlags.TappedByPlayer; template.DynamicFlag &= ~(uint)UnitDynamicFlags.TappedByAllThreatList; // has trainer flag but doesn't have prof nor class trainer flag if ((template.NpcFlag & (uint) NPCFlags.Trainer) != 0 && ((template.NpcFlag & (uint) NPCFlags.ProfessionTrainer) == 0 || (template.NpcFlag & (uint) NPCFlags.ClassTrainer) == 0)) { UnitTemplate unitData; var subname = GetSubName((int)unit.Key.GetEntry(), false); // Fall back if (Storage.UnitTemplates.TryGetValue(unit.Key.GetEntry(), out unitData)) { if (unitData.SubName.Length > 0) template.NpcFlag |= ProcessNpcFlags(unitData.SubName); else // If the SubName doesn't exist or is cached, fall back to DB method template.NpcFlag |= ProcessNpcFlags(subname); } else // In case we have NonWDB data which doesn't have an entry in UnitTemplates template.NpcFlag |= ProcessNpcFlags(subname); } templates.Add(unit.Key.GetEntry(), template); } var templatesDb = SQLDatabase.GetDict<uint, UnitTemplateNonWDB>(templates.Keys()); return SQLUtil.CompareDicts(templates, templatesDb, StoreNameType.Unit); }
public static string NpcTemplateNonWDB(Dictionary <WowGuid, Unit> units) { if (units.Count == 0) { return(string.Empty); } if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_template)) { return(string.Empty); } var levels = GetLevels(units); var templates = new StoreDictionary <uint, UnitTemplateNonWDB>(); foreach (var unit in units) { if (templates.ContainsKey(unit.Key.GetEntry())) { continue; } var npc = unit.Value; var template = new UnitTemplateNonWDB { GossipMenuId = npc.GossipId, MinLevel = levels[unit.Key.GetEntry()].Item1, MaxLevel = levels[unit.Key.GetEntry()].Item2, Faction = npc.Faction.GetValueOrDefault(35), NpcFlag = (uint)npc.NpcFlags.GetValueOrDefault(NPCFlags.None), SpeedRun = npc.Movement.RunSpeed, SpeedWalk = npc.Movement.WalkSpeed, BaseAttackTime = npc.MeleeTime.GetValueOrDefault(2000), RangedAttackTime = npc.RangedTime.GetValueOrDefault(2000), UnitClass = (uint)npc.Class.GetValueOrDefault(Class.Warrior), UnitFlag = (uint)npc.UnitFlags.GetValueOrDefault(UnitFlags.None), UnitFlag2 = (uint)npc.UnitFlags2.GetValueOrDefault(UnitFlags2.None), DynamicFlag = (uint)npc.DynamicFlags.GetValueOrDefault(UnitDynamicFlags.None), VehicleId = npc.Movement.VehicleId, HoverHeight = npc.HoverHeight.GetValueOrDefault(1.0f) }; if (template.Faction == 1 || template.Faction == 2 || template.Faction == 3 || template.Faction == 4 || template.Faction == 5 || template.Faction == 6 || template.Faction == 115 || template.Faction == 116 || template.Faction == 1610 || template.Faction == 1629 || template.Faction == 2203 || template.Faction == 2204) // player factions { template.Faction = 35; } template.UnitFlag &= ~(uint)UnitFlags.IsInCombat; template.UnitFlag &= ~(uint)UnitFlags.PetIsAttackingTarget; template.UnitFlag &= ~(uint)UnitFlags.PlayerControlled; template.UnitFlag &= ~(uint)UnitFlags.Silenced; template.UnitFlag &= ~(uint)UnitFlags.PossessedByPlayer; template.DynamicFlag &= ~(uint)UnitDynamicFlags.Lootable; template.DynamicFlag &= ~(uint)UnitDynamicFlags.Tapped; template.DynamicFlag &= ~(uint)UnitDynamicFlags.TappedByPlayer; template.DynamicFlag &= ~(uint)UnitDynamicFlags.TappedByAllThreatList; // has trainer flag but doesn't have prof nor class trainer flag if ((template.NpcFlag & (uint)NPCFlags.Trainer) != 0 && ((template.NpcFlag & (uint)NPCFlags.ProfessionTrainer) == 0 || (template.NpcFlag & (uint)NPCFlags.ClassTrainer) == 0)) { var name = StoreGetters.GetName(StoreNameType.Unit, (int)unit.Key.GetEntry(), false); var firstIndex = name.LastIndexOf('<'); var lastIndex = name.LastIndexOf('>'); if (firstIndex != -1 && lastIndex != -1) { var subname = name.Substring(firstIndex + 1, lastIndex - firstIndex - 1); if (_professionTrainers.Contains(subname)) { template.NpcFlag |= (uint)NPCFlags.ProfessionTrainer; } else if (_classTrainers.Contains(subname)) { template.NpcFlag |= (uint)NPCFlags.ClassTrainer; } } } templates.Add(unit.Key.GetEntry(), template); } var templatesDb = SQLDatabase.GetDict <uint, UnitTemplateNonWDB>(templates.Keys()); return(SQLUtil.CompareDicts(templates, templatesDb, StoreNameType.Unit)); }
/// <summary> /// <para>Compare two dictionaries (of the same types) and creates SQL inserts /// or updates accordingly.</para> /// <remarks>Second dictionary can be null (only inserts queries will be produced)</remarks> /// <remarks>Use DBTableName and DBFieldName attributes to specify table and field names, in TK</remarks> /// </summary> /// <typeparam name="T">Type of the first primary key</typeparam> /// /// <typeparam name="TG">Type of the second primary key</typeparam> /// <typeparam name="TK">Type of the WDB struct (field names and types must match DB field name and types)</typeparam> /// <typeparam name="TH"></typeparam> /// <param name="dict1">Dictionary retrieved from parser</param> /// <param name="dict2">Dictionary retrieved from DB</param> /// <param name="storeType1">(T) Are we dealing with Spells, Quests, Units, ...?</param> /// <param name="storeType2">(TG) Are we dealing with Spells, Quests, Units, ...?</param> /// <param name="storeType3">(TH) Are we dealing with Spells, Quests, Units, ...?</param> /// <param name="primaryKeyName1">The name of the first primary key</param> /// <param name="primaryKeyName2">The name of the second primary key</param> /// <param name="primaryKeyName3">The name of the third primary key</param> /// <returns>A string containing full SQL queries</returns> public static string CompareDicts <T, TG, TH, TK>(StoreDictionary <Tuple <T, TG, TH>, TK> dict1, StoreDictionary <Tuple <T, TG, TH>, TK> dict2, StoreNameType storeType1, StoreNameType storeType2, StoreNameType storeType3, string primaryKeyName1, string primaryKeyName2, string primaryKeyName3) { /*var tableAttrs = (DBTableNameAttribute[])typeof(TK).GetCustomAttributes(typeof(DBTableNameAttribute), false); * if (tableAttrs.Length <= 0) * return string.Empty; * var tableName = tableAttrs[0].Name; * * var fields = Utilities.GetFieldsAndAttributes<TK, DBFieldNameAttribute>(); * if (fields == null) * return string.Empty; * * fields.RemoveAll(field => field.Item2.Name == null); * * var rowsIns = new List<SQLInsertRow>(); * var rowsUpd = new List<SQLUpdateRow>(); * * foreach (var elem1 in Settings.SQLOrderByKey ? dict1.OrderBy(blub => blub.Key).ToList() : dict1.ToList()) * { * if (dict2 != null && dict2.ContainsKey(elem1.Key)) // update * { * var row = new SQLUpdateRow(); * * foreach (var field in fields) * { * var elem2 = dict2[elem1.Key]; * * var val1 = field.Item1.GetValue(elem1.Value.Item1); * var val2 = field.Item1.GetValue(elem2.Item1); * * var arr1 = val1 as Array; * if (arr1 != null) * { * var arr2 = (Array)val2; * * var isString = arr1.GetType().GetElementType() == typeof(string); * * for (var i = 0; i < field.Item2.Count; i++) * { * var value1 = i >= arr1.Length ? (isString ? (object)string.Empty : 0) : arr1.GetValue(i); * var value2 = i >= arr2.Length ? (isString ? (object)string.Empty : 0) : arr2.GetValue(i); * * if (!Utilities.EqualValues(value1, value2)) * row.AddValue(field.Item2.Name + (field.Item2.StartAtZero ? i : i + 1), value1); * } * * continue; * } * * if (!Utilities.EqualValues(val1, val2)) * row.AddValue(field.Item2.Name, val1); * } * * var key1 = Convert.ToUInt32(elem1.Key.Item1); * var key2 = Convert.ToUInt32(elem1.Key.Item2); * var key3 = Convert.ToUInt32(elem1.Key.Item3); * * row.AddWhere(primaryKeyName1, key1); * row.AddWhere(primaryKeyName2, key2); * row.AddWhere(primaryKeyName3, key3); * * var key1Name = storeType1 != StoreNameType.None ? * StoreGetters.GetName(storeType1, (int)key1, false) : * elem1.Key.Item1.ToString(); * var key2Name = storeType2 != StoreNameType.None ? * StoreGetters.GetName(storeType2, (int)key2, false) : * elem1.Key.Item2.ToString(); * var key3Name = storeType3 != StoreNameType.None ? * StoreGetters.GetName(storeType3, (int)key3, false) : * elem1.Key.Item2.ToString(); * * row.Comment = key1Name + " - " + key2Name + " - " + key3Name; * row.Table = tableName; * * if (row.ValueCount == 0) * continue; * * var lastField = fields[fields.Count - 1]; * if (lastField.Item2.Name == "VerifiedBuild") * { * var buildvSniff = (int)lastField.Item1.GetValue(elem1.Value.Item1); * var buildvDB = (int)lastField.Item1.GetValue(dict2[elem1.Key].Item1); * * if (buildvDB > buildvSniff) // skip update if DB already has a VerifiedBuild higher than this one * continue; * } * * rowsUpd.Add(row); * } * else // insert new * { * var row = new SQLInsertRow(); * row.AddValue(primaryKeyName1, elem1.Key.Item1); * row.AddValue(primaryKeyName2, elem1.Key.Item2); * row.AddValue(primaryKeyName3, elem1.Key.Item3); * * var key1 = Convert.ToUInt32(elem1.Key.Item1); * var key2 = Convert.ToUInt32(elem1.Key.Item2); * var key3 = Convert.ToUInt32(elem1.Key.Item3); * * var key1Name = storeType1 != StoreNameType.None ? * StoreGetters.GetName(storeType1, (int)key1, false) : * elem1.Key.Item1.ToString(); * var key2Name = storeType2 != StoreNameType.None ? * StoreGetters.GetName(storeType2, (int)key2, false) : * elem1.Key.Item2.ToString(); * var key3Name = storeType3 != StoreNameType.None ? * StoreGetters.GetName(storeType3, (int)key3, false) : * elem1.Key.Item2.ToString(); * * row.Comment = key1Name + " - " + key2Name + " - " + key3Name; * * foreach (var field in fields) * { * if (field.Item1.FieldType.BaseType == typeof(Array)) * { * var arr = (Array)field.Item1.GetValue(elem1.Value.Item1); * if (arr == null) * continue; * * for (var i = 0; i < arr.Length; i++) * row.AddValue(field.Item2.Name + (field.Item2.StartAtZero ? i : i + 1), arr.GetValue(i)); * * continue; * } * * var val = field.Item1.GetValue(elem1.Value.Item1); * if (val == null && field.Item1.FieldType == typeof(string)) * val = string.Empty; * * row.AddValue(field.Item2.Name, val); * } * rowsIns.Add(row); * } * } * * var result = new SQLInsert(tableName, rowsIns, deleteDuplicates: false, primaryKeyNumber: 3).Build() + * new SQLUpdate(rowsUpd).Build(); * * return result;*/ return(string.Empty); }
/// <summary> /// <para>Compare two dictionaries (of the same types) and creates SQL inserts /// or updates accordingly.</para> /// <remarks>Second dictionary can be null (only inserts queries will be produced)</remarks> /// <remarks>Use DBTableName and DBFieldName attributes to specify table and field names, in TK</remarks> /// </summary> /// <typeparam name="T">Type of the primary key (uint)</typeparam> /// <typeparam name="TK">Type of the WDB struct (field types must match DB field)</typeparam> /// <param name="dict1">Dictionary retrieved from parser</param> /// <param name="dict2">Dictionary retrieved from DB</param> /// <param name="storeType">Are we dealing with Spells, Quests, Units, ...?</param> /// <param name="primaryKeyName">The name of the primary key, usually "entry"</param> /// <returns>A string containing full SQL queries</returns> public static string CompareDicts <T, TK>(StoreDictionary <T, TK> dict1, StoreDictionary <T, TK> dict2, StoreNameType storeType, string primaryKeyName = "entry") { var tableAttrs = (DBTableNameAttribute[])typeof(TK).GetCustomAttributes(typeof(DBTableNameAttribute), false); if (tableAttrs.Length <= 0) { return(string.Empty); } var tableName = tableAttrs[0].Name; var fields = Utilities.GetFieldsAndAttribute <TK, DBFieldNameAttribute>(); if (fields == null) { return(string.Empty); } fields.RemoveAll(field => field.Item2.Name == null); var rowsIns = new List <QueryBuilder.SQLInsertRow>(); var rowsUpd = new List <QueryBuilder.SQLUpdateRow>(); foreach (var elem1 in Settings.SQLOrderByKey ? dict1.OrderBy(blub => blub.Key).ToList() : dict1.ToList()) { if (dict2 != null && dict2.ContainsKey(elem1.Key)) // update { var row = new QueryBuilder.SQLUpdateRow(); foreach (var field in fields) { var elem2 = dict2[elem1.Key]; var val1 = field.Item1.GetValue(elem1.Value.Item1); var val2 = field.Item1.GetValue(elem2.Item1); var arr1 = val1 as Array; if (arr1 != null) { var arr2 = (Array)val2; var isString = arr1.GetType().GetElementType() == typeof(string); for (var i = 0; i < field.Item2.Count; i++) { var value1 = i >= arr1.Length ? (isString ? (object)string.Empty : 0) : arr1.GetValue(i); var value2 = i >= arr2.Length ? (isString ? (object)string.Empty : 0) : arr2.GetValue(i); if (!Utilities.EqualValues(value1, value2)) { row.AddValue(field.Item2.Name + (field.Item2.StartAtZero ? i : i + 1), value1); } } continue; } if ((val2 is Array) && val1 == null) { continue; } if (!Utilities.EqualValues(val1, val2)) { row.AddValue(field.Item2.Name, val1); } } var key = Convert.ToUInt32(elem1.Key); row.AddWhere(primaryKeyName, key); row.Comment = StoreGetters.GetName(storeType, (int)key, false); row.Table = tableName; if (row.ValueCount == 0) { continue; } var lastField = fields[fields.Count - 1]; if (lastField.Item2.Name == "VerifiedBuild") { var buildvSniff = (int)lastField.Item1.GetValue(elem1.Value.Item1); var buildvDB = (int)lastField.Item1.GetValue(dict2[elem1.Key].Item1); if (buildvDB > buildvSniff) // skip update if DB already has a VerifiedBuild higher than this one { continue; } } rowsUpd.Add(row); } else // insert new { var row = new QueryBuilder.SQLInsertRow(); row.AddValue(primaryKeyName, elem1.Key); row.Comment = StoreGetters.GetName(storeType, Convert.ToInt32(elem1.Key), false); foreach (var field in fields) { if (field.Item1.FieldType.BaseType == typeof(Array)) { var arr = (Array)field.Item1.GetValue(elem1.Value.Item1); if (arr == null) { continue; } for (var i = 0; i < arr.Length; i++) { row.AddValue(field.Item2.Name + (field.Item2.StartAtZero ? i : i + 1), arr.GetValue(i)); } continue; } var val = field.Item1.GetValue(elem1.Value.Item1); if (val == null && field.Item1.FieldType == typeof(string)) { val = string.Empty; } row.AddValue(field.Item2.Name, val); } rowsIns.Add(row); } } var result = new QueryBuilder.SQLInsert(tableName, rowsIns, deleteDuplicates: false).Build() + new QueryBuilder.SQLUpdate(rowsUpd).Build(); return(result); }
public static string NpcTemplateNonWDB(Dictionary<WowGuid, Unit> units) { /* if (ClientVersion.AddedInVersion(ClientType.WarlordsOfDraenor)) return string.Empty;*/ if (units.Count == 0) return string.Empty; /*if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_template)) return string.Empty;*/ var levels = GetLevels(units); var result = string.Empty; const string tableName = "creature_template"; var rowsIns = new List<QueryBuilder.SQLUpdateRow>(); uint count = 0; var templates = new StoreDictionary<uint, UnitTemplateNonWDB>(); foreach (var unit in units) { if (templates.ContainsKey(unit.Key.GetEntry())) continue; var row = new QueryBuilder.SQLUpdateRow(); var npc = unit.Value; var template = new UnitTemplateNonWDB { //GossipMenuId = npc.GossipId, MinLevel = (int) levels[unit.Key.GetEntry()].Item1, MaxLevel = (int) levels[unit.Key.GetEntry()].Item2, Faction = npc.Faction.GetValueOrDefault(35), NpcFlag = (uint) npc.NpcFlags.GetValueOrDefault(NPCFlags.None), SpeedRun = npc.Movement.RunSpeed, SpeedWalk = npc.Movement.WalkSpeed /*BaseAttackTime = npc.MeleeTime.GetValueOrDefault(2000), RangedAttackTime = npc.RangedTime.GetValueOrDefault(2000), UnitClass = (uint) npc.Class.GetValueOrDefault(Class.Warrior), UnitFlag = (uint) npc.UnitFlags.GetValueOrDefault(UnitFlags.None), UnitFlag2 = (uint) npc.UnitFlags2.GetValueOrDefault(UnitFlags2.None), DynamicFlag = (uint) npc.DynamicFlags.GetValueOrDefault(UnitDynamicFlags.None), VehicleId = npc.Movement.VehicleId, HoverHeight = npc.HoverHeight.GetValueOrDefault(1.0f)*/ }; if (template.Faction == 1 || template.Faction == 2 || template.Faction == 3 || template.Faction == 4 || template.Faction == 5 || template.Faction == 6 || template.Faction == 115 || template.Faction == 116 || template.Faction == 1610 || template.Faction == 1629 || template.Faction == 2203 || template.Faction == 2204) // player factions template.Faction = 35; /* template.UnitFlag &= ~(uint)UnitFlags.IsInCombat; template.UnitFlag &= ~(uint)UnitFlags.PetIsAttackingTarget; template.UnitFlag &= ~(uint)UnitFlags.PlayerControlled; template.UnitFlag &= ~(uint)UnitFlags.Silenced; template.UnitFlag &= ~(uint)UnitFlags.PossessedByPlayer; if (!ClientVersion.AddedInVersion(ClientType.WarlordsOfDraenor)) { template.DynamicFlag &= ~(uint)UnitDynamicFlags.Lootable; template.DynamicFlag &= ~(uint)UnitDynamicFlags.Tapped; template.DynamicFlag &= ~(uint)UnitDynamicFlags.TappedByPlayer; template.DynamicFlag &= ~(uint)UnitDynamicFlags.TappedByAllThreatList; } else { template.DynamicFlag &= ~(uint)UnitDynamicFlagsWOD.Lootable; template.DynamicFlag &= ~(uint)UnitDynamicFlagsWOD.Tapped; template.DynamicFlag &= ~(uint)UnitDynamicFlagsWOD.TappedByPlayer; template.DynamicFlag &= ~(uint)UnitDynamicFlagsWOD.TappedByAllThreatList; }*/ // has trainer flag but doesn't have prof nor class trainer flag if ((template.NpcFlag & (uint) NPCFlags.Trainer) != 0 && ((template.NpcFlag & (uint) NPCFlags.ProfessionTrainer) == 0 || (template.NpcFlag & (uint) NPCFlags.ClassTrainer) == 0)) { UnitTemplate unitData; var subname = GetSubName((int)unit.Key.GetEntry(), false); // Fall back if (Storage.UnitTemplates.TryGetValue(unit.Key.GetEntry(), out unitData)) { if (unitData.SubName.Length > 0) template.NpcFlag |= ProcessNpcFlags(unitData.SubName); else // If the SubName doesn't exist or is cached, fall back to DB method template.NpcFlag |= ProcessNpcFlags(subname); } else // In case we have NonWDB data which doesn't have an entry in UnitTemplates template.NpcFlag |= ProcessNpcFlags(subname); } row.AddValue("minlevel", template.MinLevel); row.AddValue("maxlevel", template.MaxLevel); row.AddValue("faction", template.Faction); row.AddValue("npcflag", template.NpcFlag); row.AddValue("speed_walk", template.SpeedWalk); row.AddValue("speed_run", template.SpeedRun); row.AddWhere("entry", unit.Key.GetEntry()); row.Table = tableName; rowsIns.Add(row); count++; templates.Add(unit.Key.GetEntry(), template); } //result += new QueryBuilder.SQLDelete(Tuple.Create("@ID+0", "@ID+" + (count - 1)), "entry", tableName).Build(); result += new QueryBuilder.SQLUpdate(rowsIns).Build(); return result; /*var templatesDb = SQLDatabase.GetDict<uint, UnitTemplateNonWDB>(templates.Keys()); return SQLUtil.CompareDicts(templates, templatesDb, StoreNameType.Unit);*/ }
public static string ModelData(Dictionary<WowGuid, Unit> units) { if (units.Count == 0) return string.Empty; if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_model_info)) return string.Empty; // Build a dictionary with model data; model is the key var models = new StoreDictionary<uint, ModelData>(); foreach (var npc in units.Select(unit => unit.Value)) { if (Settings.AreaFilters.Length > 0) if (!(npc.Area.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.AreaFilters))) continue; if (Settings.MapFilters.Length > 0) if (!(npc.Map.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.MapFilters))) continue; uint modelId; if (npc.Model.HasValue) modelId = npc.Model.Value; else continue; // Do not add duplicate models if (models.ContainsKey(modelId)) continue; float scale = npc.Size.GetValueOrDefault(1.0f); var model = new ModelData { BoundingRadius = npc.BoundingRadius.GetValueOrDefault(0.306f) / scale, CombatReach = npc.CombatReach.GetValueOrDefault(1.5f) / scale, Gender = npc.Gender.GetValueOrDefault(Gender.Male) }; models.Add(modelId, model); } var entries = models.Keys(); var modelsDb = SQLDatabase.GetDict<uint, ModelData>(entries, "DisplayID"); return SQLUtil.CompareDicts(models, modelsDb, StoreNameType.None, "DisplayID"); }
public static string CreatureEquip(Dictionary<WowGuid, Unit> units) { if (units.Count == 0) return string.Empty; if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_equip_template)) return string.Empty; var rows = new List<QueryBuilder.SQLInsertRow>(); var equips = new StoreDictionary<uint, CreatureEquipment>(); foreach (var unit in units) { var equip = new CreatureEquipment(); var npc = unit.Value; var CreatureID = unit.Key.GetEntry(); var row = new QueryBuilder.SQLInsertRow(); if (Settings.AreaFilters.Length > 0) if (!(npc.Area.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.AreaFilters))) continue; if (Settings.MapFilters.Length > 0) if (!(npc.Map.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.MapFilters))) continue; if (npc.Equipment == null || npc.Equipment.Length != 3) continue; if (npc.Equipment[0] == 0 && npc.Equipment[1] == 0 && npc.Equipment[2] == 0) continue; if (equips.ContainsKey(CreatureID)) { var existingEquip = equips[CreatureID].Item1; if (existingEquip.ItemEntry1 != npc.Equipment[0] || existingEquip.ItemEntry2 != npc.Equipment[1] || existingEquip.ItemEntry3 != npc.Equipment[2]) equips.Remove(CreatureID); // no conflicts continue; } /*equip.ID = 1; equip.ItemEntry1 = npc.Equipment[0]; equip.ItemEntry2 = npc.Equipment[1]; equip.ItemEntry3 = npc.Equipment[2];*/ row.AddValue("CreatureID", CreatureID); row.AddValue("ID", 1); row.AddValue("ItemID1", npc.Equipment[0]); row.AddValue("ItemID2", npc.Equipment[1]); row.AddValue("ItemID3", npc.Equipment[2]); equips.Add(CreatureID, equip); rows.Add(row); } var entries = equips.Keys(); //var equipsDb = SQLDatabase.GetDict<uint, CreatureEquipment>(entries); //return SQLUtil.CompareDicts(equips, equipsDb, StoreNameType.Unit); return new QueryBuilder.SQLInsert("creature_equip_template", rows, withDelete: true).Build(); }
// Non-WDB data but nevertheless data that should be saved to creature_template public static string NpcTemplateNonWDB(Dictionary <Guid, Unit> units) { if (units.Count == 0) { return(string.Empty); } if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_template)) { return(string.Empty); } var levels = GetLevels(units); var templates = new StoreDictionary <uint, UnitTemplateNonWDB>(); foreach (var unit in units) { if (templates.ContainsKey(unit.Key.GetEntry())) { continue; } var npc = unit.Value; var template = new UnitTemplateNonWDB { GossipMenuId = npc.GossipId, MinLevel = levels[unit.Key.GetEntry()].Item1, MaxLevel = levels[unit.Key.GetEntry()].Item2, Faction = npc.Faction.GetValueOrDefault(35), Faction2 = npc.Faction.GetValueOrDefault(35), NpcFlag = (uint)npc.NpcFlags.GetValueOrDefault(NPCFlags.None), SpeedRun = npc.Movement.RunSpeed, SpeedWalk = npc.Movement.WalkSpeed, BaseAttackTime = npc.MeleeTime.GetValueOrDefault(2000), RangedAttackTime = npc.RangedTime.GetValueOrDefault(2000), UnitClass = (uint)npc.Class.GetValueOrDefault(Class.Warrior), UnitFlag = (uint)npc.UnitFlags.GetValueOrDefault(UnitFlags.None), UnitFlag2 = (uint)npc.UnitFlags2.GetValueOrDefault(UnitFlags2.None), DynamicFlag = (uint)npc.DynamicFlags.GetValueOrDefault(UnitDynamicFlags.None), VehicleId = npc.Movement.VehicleId, HoverHeight = npc.HoverHeight.GetValueOrDefault(1.0f) }; if (template.Faction == 1 || template.Faction == 2 || template.Faction == 3 || template.Faction == 4 || template.Faction == 5 || template.Faction == 6 || template.Faction == 115 || template.Faction == 116 || template.Faction == 1610 || template.Faction == 1629 || template.Faction == 2203 || template.Faction == 2204) // player factions { template.Faction = 35; } template.UnitFlag &= ~(uint)UnitFlags.IsInCombat; template.UnitFlag &= ~(uint)UnitFlags.PetIsAttackingTarget; template.UnitFlag &= ~(uint)UnitFlags.PlayerControlled; template.UnitFlag &= ~(uint)UnitFlags.Silenced; template.UnitFlag &= ~(uint)UnitFlags.PossessedByPlayer; templates.Add(unit.Key.GetEntry(), template, null); } var templatesDb = SQLDatabase.GetDict <uint, UnitTemplateNonWDB>(templates.Keys()); return(SQLUtil.CompareDicts(templates, templatesDb, StoreNameType.Unit)); }
public override int Remove(string collection, StoreDictionary where) { string whereJSON = where != null ? where.ToJSON().ToString() : ""; return(native.CallStatic <int>("remove", collection, whereJSON)); }
// Non-WDB data but nevertheless data that should be saved to creature_template public static string NpcTemplateNonWDB(Dictionary<Guid, Unit> units) { if (units.Count == 0) return string.Empty; if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_template)) return string.Empty; var levels = GetLevels(units); var templates = new StoreDictionary<uint, UnitTemplateNonWDB>(); foreach (var unit in units) { if (templates.ContainsKey(unit.Key.GetEntry())) continue; var npc = unit.Value; var template = new UnitTemplateNonWDB { GossipMenuId = npc.GossipId, MinLevel = levels[unit.Key.GetEntry()].Item1, MaxLevel = levels[unit.Key.GetEntry()].Item2, Faction = npc.Faction.GetValueOrDefault(35), Faction2 = npc.Faction.GetValueOrDefault(35), NpcFlag = (uint) npc.NpcFlags.GetValueOrDefault(NPCFlags.None), SpeedRun = npc.Movement.RunSpeed, SpeedWalk = npc.Movement.WalkSpeed, BaseAttackTime = npc.MeleeTime.GetValueOrDefault(2000), RangedAttackTime = npc.RangedTime.GetValueOrDefault(2000), UnitClass = (uint) npc.Class.GetValueOrDefault(Class.Warrior), UnitFlag = (uint) npc.UnitFlags.GetValueOrDefault(UnitFlags.None), UnitFlag2 = (uint) npc.UnitFlags2.GetValueOrDefault(UnitFlags2.None), DynamicFlag = (uint) npc.DynamicFlags.GetValueOrDefault(UnitDynamicFlags.None), VehicleId = npc.Movement.VehicleId, HoverHeight = npc.HoverHeight.GetValueOrDefault(1.0f) }; if (template.Faction == 1 || template.Faction == 2 || template.Faction == 3 || template.Faction == 4 || template.Faction == 5 || template.Faction == 6 || template.Faction == 115 || template.Faction == 116 || template.Faction == 1610 || template.Faction == 1629 || template.Faction == 2203 || template.Faction == 2204) // player factions template.Faction = 35; template.UnitFlag &= ~(uint)UnitFlags.IsInCombat; template.UnitFlag &= ~(uint)UnitFlags.PetIsAttackingTarget; template.UnitFlag &= ~(uint)UnitFlags.PlayerControlled; template.UnitFlag &= ~(uint)UnitFlags.Silenced; template.UnitFlag &= ~(uint)UnitFlags.PossessedByPlayer; templates.Add(unit.Key.GetEntry(), template, null); } var templatesDb = SQLDatabase.GetDict<uint, UnitTemplateNonWDB>(templates.Keys()); return SQLUtil.CompareDicts(templates, templatesDb, StoreNameType.Unit); }
public static string ModelData(Dictionary<Guid, Unit> units) { if (units.Count == 0) return string.Empty; if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_model_info)) return string.Empty; // Build a dictionary with model data; model is the key var models = new StoreDictionary<uint, ModelData>(); foreach (var npc in units.Select(unit => unit.Value)) { uint modelId; if (npc.Model.HasValue) modelId = npc.Model.Value; else continue; // Do not add duplicate models if (models.ContainsKey(modelId)) continue; var model = new ModelData { BoundingRadius = npc.BoundingRadius.GetValueOrDefault(0.306f), CombatReach = npc.CombatReach.GetValueOrDefault(1.5f), Gender = npc.Gender.GetValueOrDefault(Gender.Male) }; models.Add(modelId, model, null); } var entries = models.Keys(); var modelsDb = SQLDatabase.GetDict<uint, ModelData>(entries, "modelid"); return SQLUtil.CompareDicts(models, modelsDb, StoreNameType.None, "modelid"); }
public static string CreatureDifficultyMisc(Dictionary<WowGuid, Unit> units) { if (!ClientVersion.AddedInVersion(ClientType.WarlordsOfDraenor)) return string.Empty; if (units.Count == 0) return string.Empty; if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_template)) return string.Empty; var templates = new StoreDictionary<uint, CreatureDifficultyMisc>(); foreach (var unit in units) { if (SQLDatabase.CreatureDifficultyStores != null) { foreach (var creatureDiff in SQLDatabase.CreatureDifficultyStores) { if (!Utilities.EqualValues(unit.Key.GetEntry(), creatureDiff.Value.CreatureID)) continue; if (templates.ContainsKey(creatureDiff.Key)) continue; var npc = unit.Value; var template = new CreatureDifficultyMisc { CreatureId = unit.Key.GetEntry(), GossipMenuId = npc.GossipId, NpcFlag = (uint)npc.NpcFlags.GetValueOrDefault(NPCFlags.None), SpeedRun = npc.Movement.RunSpeed, SpeedWalk = npc.Movement.WalkSpeed, BaseAttackTime = npc.MeleeTime.GetValueOrDefault(2000), RangedAttackTime = npc.RangedTime.GetValueOrDefault(2000), UnitClass = (uint)npc.Class.GetValueOrDefault(Class.Warrior), UnitFlag = (uint)npc.UnitFlags.GetValueOrDefault(UnitFlags.None), UnitFlag2 = (uint)npc.UnitFlags2.GetValueOrDefault(UnitFlags2.None), DynamicFlag = (uint)npc.DynamicFlags.GetValueOrDefault(UnitDynamicFlags.None), VehicleId = npc.Movement.VehicleId, HoverHeight = npc.HoverHeight.GetValueOrDefault(1.0f) }; template.UnitFlag &= ~(uint)UnitFlags.IsInCombat; template.UnitFlag &= ~(uint)UnitFlags.PetIsAttackingTarget; template.UnitFlag &= ~(uint)UnitFlags.PlayerControlled; template.UnitFlag &= ~(uint)UnitFlags.Silenced; template.UnitFlag &= ~(uint)UnitFlags.PossessedByPlayer; if (!ClientVersion.AddedInVersion(ClientType.WarlordsOfDraenor)) { template.DynamicFlag &= ~(uint)UnitDynamicFlags.Lootable; template.DynamicFlag &= ~(uint)UnitDynamicFlags.Tapped; template.DynamicFlag &= ~(uint)UnitDynamicFlags.TappedByPlayer; template.DynamicFlag &= ~(uint)UnitDynamicFlags.TappedByAllThreatList; } else { template.DynamicFlag &= ~(uint)UnitDynamicFlagsWOD.Lootable; template.DynamicFlag &= ~(uint)UnitDynamicFlagsWOD.Tapped; template.DynamicFlag &= ~(uint)UnitDynamicFlagsWOD.TappedByPlayer; template.DynamicFlag &= ~(uint)UnitDynamicFlagsWOD.TappedByAllThreatList; } // has trainer flag but doesn't have prof nor class trainer flag if ((template.NpcFlag & (uint)NPCFlags.Trainer) != 0 && ((template.NpcFlag & (uint)NPCFlags.ProfessionTrainer) == 0 || (template.NpcFlag & (uint)NPCFlags.ClassTrainer) == 0)) { var name = StoreGetters.GetName(StoreNameType.Unit, (int)unit.Key.GetEntry(), false); var firstIndex = name.LastIndexOf('<'); var lastIndex = name.LastIndexOf('>'); if (firstIndex != -1 && lastIndex != -1) { var subname = name.Substring(firstIndex + 1, lastIndex - firstIndex - 1); if (_professionTrainers.Contains(subname)) template.NpcFlag |= (uint)NPCFlags.ProfessionTrainer; else if (_classTrainers.Contains(subname)) template.NpcFlag |= (uint)NPCFlags.ClassTrainer; } } templates.Add(creatureDiff.Key, template); } } } var templatesDb = SQLDatabase.GetDict<uint, CreatureDifficultyMisc>(templates.Keys(), "Id"); return SQLUtil.CompareDicts(templates, templatesDb, StoreNameType.Unit, "Id"); }
public static string NpcTemplateNonWDB(Dictionary<WowGuid, Unit> units) { if (units.Count == 0) return string.Empty; if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_template)) return string.Empty; var levels = GetLevels(units); var templates = new StoreDictionary<uint, UnitTemplateNonWDB>(); foreach (var unit in units) { if (templates.ContainsKey(unit.Key.GetEntry())) continue; var npc = unit.Value; var template = new UnitTemplateNonWDB { GossipMenuId = npc.GossipId, MinLevel = levels[unit.Key.GetEntry()].Item1, MaxLevel = levels[unit.Key.GetEntry()].Item2, Faction = npc.Faction.GetValueOrDefault(35), NpcFlag = (uint) npc.NpcFlags.GetValueOrDefault(NPCFlags.None), SpeedRun = npc.Movement.RunSpeed, SpeedWalk = npc.Movement.WalkSpeed, BaseAttackTime = npc.MeleeTime.GetValueOrDefault(2000), RangedAttackTime = npc.RangedTime.GetValueOrDefault(2000), UnitClass = (uint) npc.Class.GetValueOrDefault(Class.Warrior), UnitFlag = (uint) npc.UnitFlags.GetValueOrDefault(UnitFlags.None), UnitFlag2 = (uint) npc.UnitFlags2.GetValueOrDefault(UnitFlags2.None), DynamicFlag = (uint) npc.DynamicFlags.GetValueOrDefault(UnitDynamicFlags.None), VehicleId = npc.Movement.VehicleId, HoverHeight = npc.HoverHeight.GetValueOrDefault(1.0f) }; if (template.Faction == 1 || template.Faction == 2 || template.Faction == 3 || template.Faction == 4 || template.Faction == 5 || template.Faction == 6 || template.Faction == 115 || template.Faction == 116 || template.Faction == 1610 || template.Faction == 1629 || template.Faction == 2203 || template.Faction == 2204) // player factions template.Faction = 35; template.UnitFlag &= ~(uint)UnitFlags.IsInCombat; template.UnitFlag &= ~(uint)UnitFlags.PetIsAttackingTarget; template.UnitFlag &= ~(uint)UnitFlags.PlayerControlled; template.UnitFlag &= ~(uint)UnitFlags.Silenced; template.UnitFlag &= ~(uint)UnitFlags.PossessedByPlayer; template.DynamicFlag &= ~(uint)UnitDynamicFlags.Lootable; template.DynamicFlag &= ~(uint)UnitDynamicFlags.Tapped; template.DynamicFlag &= ~(uint)UnitDynamicFlags.TappedByPlayer; template.DynamicFlag &= ~(uint)UnitDynamicFlags.TappedByAllThreatList; // has trainer flag but doesn't have prof nor class trainer flag if ((template.NpcFlag & (uint) NPCFlags.Trainer) != 0 && ((template.NpcFlag & (uint) NPCFlags.ProfessionTrainer) == 0 || (template.NpcFlag & (uint) NPCFlags.ClassTrainer) == 0)) { var name = StoreGetters.GetName(StoreNameType.Unit, (int) unit.Key.GetEntry(), false); var firstIndex = name.LastIndexOf('<'); var lastIndex = name.LastIndexOf('>'); if (firstIndex != -1 && lastIndex != -1) { var subname = name.Substring(firstIndex + 1, lastIndex - firstIndex - 1); if (_professionTrainers.Contains(subname)) template.NpcFlag |= (uint) NPCFlags.ProfessionTrainer; else if (_classTrainers.Contains(subname)) template.NpcFlag |= (uint) NPCFlags.ClassTrainer; } } templates.Add(unit.Key.GetEntry(), template); } var templatesDb = SQLDatabase.GetDict<uint, UnitTemplateNonWDB>(templates.Keys()); return SQLUtil.CompareDicts(templates, templatesDb, StoreNameType.Unit); }