public void RemoveEntity(BiotaPropertiesIID entity, Action <bool> callback) { _queue.Add(new Task(() => { var result = _wrappedDatabase.RemoveEntity(entity); callback?.Invoke(result); })); }
public bool RemoveEntity(BiotaPropertiesIID entity) { using (var context = new ShardDbContext()) { context.BiotaPropertiesIID.Remove(entity); try { context.SaveChanges(); return(true); } catch (Exception ex) { // Character name might be in use or some other fault log.Error($"RemoveEntity failed with exception: {ex}"); return(false); } } }
private void UpdateBiota(ShardDbContext context, Biota existingBiota, Biota biota) { // This pattern is described here: https://docs.microsoft.com/en-us/ef/core/saving/disconnected-entities // You'll notice though that we're not using the recommended: context.Entry(existingEntry).CurrentValues.SetValues(newEntry); // It is EXTREMLY slow. 4x or more slower. I suspect because it uses reflection to find the properties that the object contains // Manually setting the properties like we do below is the best case scenario for performance. However, it also has risks. // If we add columns to the schema and forget to add those changes here, changes to the biota may not propegate to the database. // Mag-nus 2018-08-18 context.Entry(existingBiota).CurrentValues.SetValues(biota); foreach (var value in biota.BiotaPropertiesAnimPart) { BiotaPropertiesAnimPart existingValue = (value.Id == 0 ? null : existingBiota.BiotaPropertiesAnimPart.FirstOrDefault(r => r.Id == value.Id)); if (existingValue == null) { existingBiota.BiotaPropertiesAnimPart.Add(value); } else { existingValue.Index = value.Index; existingValue.AnimationId = value.AnimationId; existingValue.Order = value.Order; } } foreach (var value in existingBiota.BiotaPropertiesAnimPart) { if (!biota.BiotaPropertiesAnimPart.Any(p => p.Id == value.Id)) { context.BiotaPropertiesAnimPart.Remove(value); } } foreach (var value in biota.BiotaPropertiesAttribute) { BiotaPropertiesAttribute existingValue = (value.Id == 0 ? null : existingBiota.BiotaPropertiesAttribute.FirstOrDefault(r => r.Id == value.Id)); if (existingValue == null) { existingBiota.BiotaPropertiesAttribute.Add(value); } else { existingValue.Type = value.Type; existingValue.InitLevel = value.InitLevel; existingValue.LevelFromCP = value.LevelFromCP; existingValue.CPSpent = value.CPSpent; } } foreach (var value in existingBiota.BiotaPropertiesAttribute) { if (!biota.BiotaPropertiesAttribute.Any(p => p.Id == value.Id)) { context.BiotaPropertiesAttribute.Remove(value); } } foreach (var value in biota.BiotaPropertiesAttribute2nd) { BiotaPropertiesAttribute2nd existingValue = (value.Id == 0 ? null : existingBiota.BiotaPropertiesAttribute2nd.FirstOrDefault(r => r.Id == value.Id)); if (existingValue == null) { existingBiota.BiotaPropertiesAttribute2nd.Add(value); } else { existingValue.Type = value.Type; existingValue.InitLevel = value.InitLevel; existingValue.LevelFromCP = value.LevelFromCP; existingValue.CPSpent = value.CPSpent; existingValue.CurrentLevel = value.CurrentLevel; } } foreach (var value in existingBiota.BiotaPropertiesAttribute2nd) { if (!biota.BiotaPropertiesAttribute2nd.Any(p => p.Id == value.Id)) { context.BiotaPropertiesAttribute2nd.Remove(value); } } foreach (var value in biota.BiotaPropertiesBodyPart) { BiotaPropertiesBodyPart existingValue = (value.Id == 0 ? null : existingBiota.BiotaPropertiesBodyPart.FirstOrDefault(r => r.Id == value.Id)); if (existingValue == null) { existingBiota.BiotaPropertiesBodyPart.Add(value); } else { existingValue.Key = value.Key; existingValue.DType = value.DType; existingValue.DVal = value.DVal; existingValue.DVar = value.DVar; existingValue.BaseArmor = value.BaseArmor; existingValue.ArmorVsSlash = value.ArmorVsSlash; existingValue.ArmorVsPierce = value.ArmorVsPierce; existingValue.ArmorVsBludgeon = value.ArmorVsBludgeon; existingValue.ArmorVsCold = value.ArmorVsCold; existingValue.ArmorVsFire = value.ArmorVsFire; existingValue.ArmorVsAcid = value.ArmorVsAcid; existingValue.ArmorVsElectric = value.ArmorVsElectric; existingValue.ArmorVsNether = value.ArmorVsNether; existingValue.BH = value.BH; existingValue.HLF = value.HLF; existingValue.MLF = value.MLF; existingValue.LLF = value.LLF; existingValue.HRF = value.HRF; existingValue.MRF = value.MRF; existingValue.LRF = value.LRF; existingValue.HLB = value.HLB; existingValue.MLB = value.MLB; existingValue.LLB = value.LLB; existingValue.HRB = value.HRB; existingValue.MRB = value.MRB; existingValue.LRB = value.LRB; } } foreach (var value in existingBiota.BiotaPropertiesBodyPart) { if (!biota.BiotaPropertiesBodyPart.Any(p => p.Id == value.Id)) { context.BiotaPropertiesBodyPart.Remove(value); } } if (biota.BiotaPropertiesBook != null) { if (existingBiota.BiotaPropertiesBook == null) { existingBiota.BiotaPropertiesBook = biota.BiotaPropertiesBook; } else { existingBiota.BiotaPropertiesBook.MaxNumPages = biota.BiotaPropertiesBook.MaxNumPages; existingBiota.BiotaPropertiesBook.MaxNumCharsPerPage = biota.BiotaPropertiesBook.MaxNumCharsPerPage; } } else { if (existingBiota.BiotaPropertiesBook != null) { context.BiotaPropertiesBook.Remove(existingBiota.BiotaPropertiesBook); } } foreach (var value in biota.BiotaPropertiesBookPageData) { BiotaPropertiesBookPageData existingValue = (value.Id == 0 ? null : existingBiota.BiotaPropertiesBookPageData.FirstOrDefault(r => r.Id == value.Id)); if (existingValue == null) { existingBiota.BiotaPropertiesBookPageData.Add(value); } else { existingValue.PageId = value.PageId; existingValue.AuthorId = value.AuthorId; existingValue.AuthorName = value.AuthorName; existingValue.AuthorAccount = value.AuthorAccount; existingValue.IgnoreAuthor = value.IgnoreAuthor; existingValue.PageText = value.PageText; } } foreach (var value in existingBiota.BiotaPropertiesBookPageData) { if (!biota.BiotaPropertiesBookPageData.Any(p => p.Id == value.Id)) { context.BiotaPropertiesBookPageData.Remove(value); } } foreach (var value in biota.BiotaPropertiesBool) { BiotaPropertiesBool existingValue = (value.Id == 0 ? null : existingBiota.BiotaPropertiesBool.FirstOrDefault(r => r.Id == value.Id)); if (existingValue == null) { existingBiota.BiotaPropertiesBool.Add(value); } else { existingValue.Type = value.Type; existingValue.Value = value.Value; } } foreach (var value in existingBiota.BiotaPropertiesBool) { if (!biota.BiotaPropertiesBool.Any(p => p.Id == value.Id)) { context.BiotaPropertiesBool.Remove(value); } } foreach (var value in biota.BiotaPropertiesCreateList) { BiotaPropertiesCreateList existingValue = (value.Id == 0 ? null : existingBiota.BiotaPropertiesCreateList.FirstOrDefault(r => r.Id == value.Id)); if (existingValue == null) { existingBiota.BiotaPropertiesCreateList.Add(value); } else { existingValue.DestinationType = value.DestinationType; existingValue.WeenieClassId = value.WeenieClassId; existingValue.StackSize = value.StackSize; existingValue.Palette = value.Palette; existingValue.Shade = value.Shade; existingValue.TryToBond = value.TryToBond; } } foreach (var value in existingBiota.BiotaPropertiesCreateList) { if (!biota.BiotaPropertiesCreateList.Any(p => p.Id == value.Id)) { context.BiotaPropertiesCreateList.Remove(value); } } foreach (var value in biota.BiotaPropertiesDID) { BiotaPropertiesDID existingValue = (value.Id == 0 ? null : existingBiota.BiotaPropertiesDID.FirstOrDefault(r => r.Id == value.Id)); if (existingValue == null) { existingBiota.BiotaPropertiesDID.Add(value); } else { existingValue.Type = value.Type; existingValue.Value = value.Value; } } foreach (var value in existingBiota.BiotaPropertiesDID) { if (!biota.BiotaPropertiesDID.Any(p => p.Id == value.Id)) { context.BiotaPropertiesDID.Remove(value); } } foreach (var value in biota.BiotaPropertiesEmote) { BiotaPropertiesEmote existingValue = (value.Id == 0 ? null : existingBiota.BiotaPropertiesEmote.FirstOrDefault(r => r.Id == value.Id)); if (existingValue == null) { existingBiota.BiotaPropertiesEmote.Add(value); } else { existingValue.Category = value.Category; existingValue.Probability = value.Probability; existingValue.WeenieClassId = value.WeenieClassId; existingValue.Style = value.Style; existingValue.Substyle = value.Substyle; existingValue.Quest = value.Quest; existingValue.VendorType = value.VendorType; existingValue.MinHealth = value.MinHealth; existingValue.MaxHealth = value.MaxHealth; foreach (var value2 in value.BiotaPropertiesEmoteAction) { BiotaPropertiesEmoteAction existingValue2 = (value2.Id == 0 ? null : existingValue.BiotaPropertiesEmoteAction.FirstOrDefault(r => r.Id == value2.Id)); if (existingValue2 == null) { existingValue.BiotaPropertiesEmoteAction.Add(value2); } else { existingValue2.EmoteId = value2.EmoteId; existingValue2.Order = value2.Order; existingValue2.Type = value2.Type; existingValue2.Delay = value2.Delay; existingValue2.Extent = value2.Extent; existingValue2.Motion = value2.Motion; existingValue2.Message = value2.Message; existingValue2.TestString = value2.TestString; existingValue2.Min = value2.Min; existingValue2.Max = value2.Max; existingValue2.Min64 = value2.Min64; existingValue2.Max64 = value2.Max64; existingValue2.MinDbl = value2.MinDbl; existingValue2.MaxDbl = value2.MaxDbl; existingValue2.Stat = value2.Stat; existingValue2.Display = value2.Display; existingValue2.Amount = value2.Amount; existingValue2.Amount64 = value2.Amount64; existingValue2.HeroXP64 = value2.HeroXP64; existingValue2.Percent = value2.Percent; existingValue2.SpellId = value2.SpellId; existingValue2.WealthRating = value2.WealthRating; existingValue2.TreasureClass = value2.TreasureClass; existingValue2.TreasureType = value2.TreasureType; existingValue2.PScript = value2.PScript; existingValue2.Sound = value2.Sound; existingValue2.DestinationType = value2.DestinationType; existingValue2.WeenieClassId = value2.WeenieClassId; existingValue2.StackSize = value2.StackSize; existingValue2.Palette = value2.Palette; existingValue2.Shade = value2.Shade; existingValue2.TryToBond = value2.TryToBond; existingValue2.ObjCellId = value2.ObjCellId; existingValue2.OriginX = value2.OriginX; existingValue2.OriginY = value2.OriginY; existingValue2.OriginZ = value2.OriginZ; existingValue2.AnglesW = value2.AnglesW; existingValue2.AnglesX = value2.AnglesX; existingValue2.AnglesY = value2.AnglesY; existingValue2.AnglesZ = value2.AnglesZ; } } foreach (var value2 in value.BiotaPropertiesEmoteAction) { if (!existingValue.BiotaPropertiesEmoteAction.Any(p => p.Id == value2.Id)) { context.BiotaPropertiesEmoteAction.Remove(value2); } } } } foreach (var value in existingBiota.BiotaPropertiesEmote) { if (!biota.BiotaPropertiesEmote.Any(p => p.Id == value.Id)) { context.BiotaPropertiesEmote.Remove(value); } } foreach (var value in biota.BiotaPropertiesEnchantmentRegistry) { BiotaPropertiesEnchantmentRegistry existingValue = (value.ObjectId == 0 ? null : existingBiota.BiotaPropertiesEnchantmentRegistry.FirstOrDefault(r => r.ObjectId == value.ObjectId && r.SpellId == value.SpellId && r.LayerId == value.LayerId && r.CasterObjectId == value.CasterObjectId)); if (existingValue == null) { existingBiota.BiotaPropertiesEnchantmentRegistry.Add(value); } else { existingValue.EnchantmentCategory = value.EnchantmentCategory; existingValue.SpellId = value.SpellId; existingValue.LayerId = value.LayerId; existingValue.HasSpellSetId = value.HasSpellSetId; existingValue.SpellCategory = value.SpellCategory; existingValue.PowerLevel = value.PowerLevel; existingValue.StartTime = value.StartTime; existingValue.Duration = value.Duration; existingValue.CasterObjectId = value.CasterObjectId; existingValue.DegradeModifier = value.DegradeModifier; existingValue.DegradeLimit = value.DegradeLimit; existingValue.LastTimeDegraded = value.LastTimeDegraded; existingValue.StatModType = value.StatModType; existingValue.StatModKey = value.StatModKey; existingValue.StatModValue = value.StatModValue; existingValue.SpellSetId = value.SpellSetId; } } foreach (var value in existingBiota.BiotaPropertiesEnchantmentRegistry) { if (!biota.BiotaPropertiesEnchantmentRegistry.Any(p => p.ObjectId == value.ObjectId && p.SpellId == value.SpellId && p.LayerId == value.LayerId && p.CasterObjectId == value.CasterObjectId)) { context.BiotaPropertiesEnchantmentRegistry.Remove(value); } } foreach (var value in biota.BiotaPropertiesEventFilter) { BiotaPropertiesEventFilter existingValue = (value.Id == 0 ? null : existingBiota.BiotaPropertiesEventFilter.FirstOrDefault(r => r.Id == value.Id)); if (existingValue == null) { existingBiota.BiotaPropertiesEventFilter.Add(value); } else { existingValue.Event = value.Event; } } foreach (var value in existingBiota.BiotaPropertiesEventFilter) { if (!biota.BiotaPropertiesEventFilter.Any(p => p.Id == value.Id)) { context.BiotaPropertiesEventFilter.Remove(value); } } foreach (var value in biota.BiotaPropertiesFloat) { BiotaPropertiesFloat existingValue = (value.Id == 0 ? null : existingBiota.BiotaPropertiesFloat.FirstOrDefault(r => r.Id == value.Id)); if (existingValue == null) { existingBiota.BiotaPropertiesFloat.Add(value); } else { existingValue.Type = value.Type; existingValue.Value = value.Value; } } foreach (var value in existingBiota.BiotaPropertiesFloat) { if (!biota.BiotaPropertiesFloat.Any(p => p.Id == value.Id)) { context.BiotaPropertiesFloat.Remove(value); } } foreach (var value in biota.BiotaPropertiesGenerator) { BiotaPropertiesGenerator existingValue = (value.Id == 0 ? null : existingBiota.BiotaPropertiesGenerator.FirstOrDefault(r => r.Id == value.Id)); if (existingValue == null) { existingBiota.BiotaPropertiesGenerator.Add(value); } else { existingValue.Probability = value.Probability; existingValue.WeenieClassId = value.WeenieClassId; existingValue.Delay = value.Delay; existingValue.InitCreate = value.InitCreate; existingValue.MaxCreate = value.MaxCreate; existingValue.WhenCreate = value.WhenCreate; existingValue.WhereCreate = value.WhereCreate; existingValue.StackSize = value.StackSize; existingValue.PaletteId = value.PaletteId; existingValue.Shade = value.Shade; existingValue.ObjCellId = value.ObjCellId; existingValue.OriginX = value.OriginX; existingValue.OriginY = value.OriginY; existingValue.OriginZ = value.OriginZ; existingValue.AnglesW = value.AnglesW; existingValue.AnglesX = value.AnglesX; existingValue.AnglesY = value.AnglesY; existingValue.AnglesZ = value.AnglesZ; } } foreach (var value in existingBiota.BiotaPropertiesGenerator) { if (!biota.BiotaPropertiesGenerator.Any(p => p.Id == value.Id)) { context.BiotaPropertiesGenerator.Remove(value); } } foreach (var value in biota.BiotaPropertiesIID) { BiotaPropertiesIID existingValue = (value.Id == 0 ? null : existingBiota.BiotaPropertiesIID.FirstOrDefault(r => r.Id == value.Id)); if (existingValue == null) { existingBiota.BiotaPropertiesIID.Add(value); } else { existingValue.Type = value.Type; existingValue.Value = value.Value; } } foreach (var value in existingBiota.BiotaPropertiesIID) { if (!biota.BiotaPropertiesIID.Any(p => p.Id == value.Id)) { context.BiotaPropertiesIID.Remove(value); } } foreach (var value in biota.BiotaPropertiesInt) { BiotaPropertiesInt existingValue = (value.Id == 0 ? null : existingBiota.BiotaPropertiesInt.FirstOrDefault(r => r.Id == value.Id)); if (existingValue == null) { existingBiota.BiotaPropertiesInt.Add(value); } else { existingValue.Type = value.Type; existingValue.Value = value.Value; } } foreach (var value in existingBiota.BiotaPropertiesInt) { if (!biota.BiotaPropertiesInt.Any(p => p.Id == value.Id)) { context.BiotaPropertiesInt.Remove(value); } } foreach (var value in biota.BiotaPropertiesInt64) { BiotaPropertiesInt64 existingValue = (value.Id == 0 ? null : existingBiota.BiotaPropertiesInt64.FirstOrDefault(r => r.Id == value.Id)); if (existingValue == null) { existingBiota.BiotaPropertiesInt64.Add(value); } else { existingValue.Type = value.Type; existingValue.Value = value.Value; } } foreach (var value in existingBiota.BiotaPropertiesInt64) { if (!biota.BiotaPropertiesInt64.Any(p => p.Id == value.Id)) { context.BiotaPropertiesInt64.Remove(value); } } foreach (var value in biota.BiotaPropertiesPalette) { BiotaPropertiesPalette existingValue = (value.Id == 0 ? null : existingBiota.BiotaPropertiesPalette.FirstOrDefault(r => r.Id == value.Id)); if (existingValue == null) { existingBiota.BiotaPropertiesPalette.Add(value); } else { existingValue.SubPaletteId = value.SubPaletteId; existingValue.Offset = value.Offset; existingValue.Length = value.Length; } } foreach (var value in existingBiota.BiotaPropertiesPalette) { if (!biota.BiotaPropertiesPalette.Any(p => p.Id == value.Id)) { context.BiotaPropertiesPalette.Remove(value); } } foreach (var value in biota.BiotaPropertiesPosition) { BiotaPropertiesPosition existingValue = (value.Id == 0 ? null : existingBiota.BiotaPropertiesPosition.FirstOrDefault(r => r.Id == value.Id)); if (existingValue == null) { existingBiota.BiotaPropertiesPosition.Add(value); } else { existingValue.PositionType = value.PositionType; existingValue.ObjCellId = value.ObjCellId; existingValue.OriginX = value.OriginX; existingValue.OriginY = value.OriginY; existingValue.OriginZ = value.OriginZ; existingValue.AnglesW = value.AnglesW; existingValue.AnglesX = value.AnglesX; existingValue.AnglesY = value.AnglesY; existingValue.AnglesZ = value.AnglesZ; } } foreach (var value in existingBiota.BiotaPropertiesPosition) { if (!biota.BiotaPropertiesPosition.Any(p => p.Id == value.Id)) { context.BiotaPropertiesPosition.Remove(value); } } foreach (var value in biota.BiotaPropertiesSkill) { BiotaPropertiesSkill existingValue = (value.Id == 0 ? null : existingBiota.BiotaPropertiesSkill.FirstOrDefault(r => r.Id == value.Id)); if (existingValue == null) { existingBiota.BiotaPropertiesSkill.Add(value); } else { existingValue.Type = value.Type; existingValue.LevelFromPP = value.LevelFromPP; existingValue.SAC = value.SAC; existingValue.PP = value.PP; existingValue.InitLevel = value.InitLevel; existingValue.ResistanceAtLastCheck = value.ResistanceAtLastCheck; existingValue.LastUsedTime = value.LastUsedTime; } } foreach (var value in existingBiota.BiotaPropertiesSkill) { if (!biota.BiotaPropertiesSkill.Any(p => p.Id == value.Id)) { context.BiotaPropertiesSkill.Remove(value); } } foreach (var value in biota.BiotaPropertiesSpellBook) { BiotaPropertiesSpellBook existingValue = (value.Id == 0 ? null : existingBiota.BiotaPropertiesSpellBook.FirstOrDefault(r => r.Id == value.Id)); if (existingValue == null) { existingBiota.BiotaPropertiesSpellBook.Add(value); } else { existingValue.Spell = value.Spell; existingValue.Probability = value.Probability; } } foreach (var value in existingBiota.BiotaPropertiesSpellBook) { if (!biota.BiotaPropertiesSpellBook.Any(p => p.Id == value.Id)) { context.BiotaPropertiesSpellBook.Remove(value); } } foreach (var value in biota.BiotaPropertiesString) { BiotaPropertiesString existingValue = (value.Id == 0 ? null : existingBiota.BiotaPropertiesString.FirstOrDefault(r => r.Id == value.Id)); if (existingValue == null) { existingBiota.BiotaPropertiesString.Add(value); } else { existingValue.Type = value.Type; existingValue.Value = value.Value; } } foreach (var value in existingBiota.BiotaPropertiesString) { if (!biota.BiotaPropertiesString.Any(p => p.Id == value.Id)) { context.BiotaPropertiesString.Remove(value); } } foreach (var value in biota.BiotaPropertiesTextureMap) { BiotaPropertiesTextureMap existingValue = (value.Id == 0 ? null : existingBiota.BiotaPropertiesTextureMap.FirstOrDefault(r => r.Id == value.Id)); if (existingValue == null) { existingBiota.BiotaPropertiesTextureMap.Add(value); } else { existingValue.Index = value.Index; existingValue.OldId = value.OldId; existingValue.NewId = value.NewId; existingValue.Order = value.Order; } } foreach (var value in existingBiota.BiotaPropertiesTextureMap) { if (!biota.BiotaPropertiesTextureMap.Any(p => p.Id == value.Id)) { context.BiotaPropertiesTextureMap.Remove(value); } } foreach (var value in biota.HousePermission) { HousePermission existingValue = (value.Id == 0 ? null : existingBiota.HousePermission.FirstOrDefault(r => r.Id == value.Id)); if (existingValue == null) { existingBiota.HousePermission.Add(value); } else { existingValue.PlayerGuid = value.PlayerGuid; existingValue.Storage = value.Storage; } } foreach (var value in existingBiota.HousePermission) { if (!biota.HousePermission.Any(p => p.Id == value.Id)) { context.HousePermission.Remove(value); } } }
public static ACE.Database.Models.Shard.Biota ConvertFromEntityBiota(ACE.Entity.Models.Biota biota) { var result = new ACE.Database.Models.Shard.Biota(); result.Id = biota.Id; result.WeenieClassId = biota.WeenieClassId; result.WeenieType = (int)biota.WeenieType; /* Switch to this code when Step 3 is implemented * if (biota.PropertiesBool != null) * { * foreach (var kvp in biota.PropertiesBool) * result.SetProperty(kvp.Key, kvp.Value); * } * if (biota.PropertiesDID != null) * { * foreach (var kvp in biota.PropertiesDID) * result.SetProperty(kvp.Key, kvp.Value); * } * if (biota.PropertiesFloat != null) * { * foreach (var kvp in biota.PropertiesFloat) * result.SetProperty(kvp.Key, kvp.Value); * } * if (biota.PropertiesIID != null) * { * foreach (var kvp in biota.PropertiesIID) * result.SetProperty(kvp.Key, kvp.Value); * } * if (biota.PropertiesInt != null) * { * foreach (var kvp in biota.PropertiesInt) * result.SetProperty(kvp.Key, kvp.Value); * } * if (biota.PropertiesInt64 != null) * { * foreach (var kvp in biota.PropertiesInt64) * result.SetProperty(kvp.Key, kvp.Value); * } * if (biota.PropertiesString != null) * { * foreach (var kvp in biota.PropertiesString) * result.SetProperty(kvp.Key, kvp.Value); * }*/ if (biota.PropertiesBool != null) { foreach (var kvp in biota.PropertiesBool) { var entity = new BiotaPropertiesBool { ObjectId = biota.Id, Type = (ushort)kvp.Key, Value = kvp.Value }; result.BiotaPropertiesBool.Add(entity); } } if (biota.PropertiesDID != null) { foreach (var kvp in biota.PropertiesDID) { var entity = new BiotaPropertiesDID { ObjectId = biota.Id, Type = (ushort)kvp.Key, Value = kvp.Value }; result.BiotaPropertiesDID.Add(entity); } } if (biota.PropertiesFloat != null) { foreach (var kvp in biota.PropertiesFloat) { var entity = new BiotaPropertiesFloat { ObjectId = biota.Id, Type = (ushort)kvp.Key, Value = kvp.Value }; result.BiotaPropertiesFloat.Add(entity); } } if (biota.PropertiesIID != null) { foreach (var kvp in biota.PropertiesIID) { var entity = new BiotaPropertiesIID { ObjectId = biota.Id, Type = (ushort)kvp.Key, Value = kvp.Value }; result.BiotaPropertiesIID.Add(entity); } } if (biota.PropertiesInt != null) { foreach (var kvp in biota.PropertiesInt) { var entity = new BiotaPropertiesInt { ObjectId = biota.Id, Type = (ushort)kvp.Key, Value = kvp.Value }; result.BiotaPropertiesInt.Add(entity); } } if (biota.PropertiesInt64 != null) { foreach (var kvp in biota.PropertiesInt64) { var entity = new BiotaPropertiesInt64 { ObjectId = biota.Id, Type = (ushort)kvp.Key, Value = kvp.Value }; result.BiotaPropertiesInt64.Add(entity); } } if (biota.PropertiesString != null) { foreach (var kvp in biota.PropertiesString) { var entity = new BiotaPropertiesString { ObjectId = biota.Id, Type = (ushort)kvp.Key, Value = kvp.Value }; result.BiotaPropertiesString.Add(entity); } } if (biota.PropertiesPosition != null) { foreach (var kvp in biota.PropertiesPosition) { var entity = new BiotaPropertiesPosition { ObjectId = biota.Id, PositionType = (ushort)kvp.Key, ObjCellId = kvp.Value.ObjCellId, OriginX = kvp.Value.PositionX, OriginY = kvp.Value.PositionY, OriginZ = kvp.Value.PositionZ, AnglesW = kvp.Value.RotationW, AnglesX = kvp.Value.RotationX, AnglesY = kvp.Value.RotationY, AnglesZ = kvp.Value.RotationZ }; result.BiotaPropertiesPosition.Add(entity); } } if (biota.PropertiesSpellBook != null) { foreach (var kvp in biota.PropertiesSpellBook) { var entity = new BiotaPropertiesSpellBook { ObjectId = biota.Id, Spell = kvp.Key, Probability = kvp.Value }; result.BiotaPropertiesSpellBook.Add(entity); } } if (biota.PropertiesAnimPart != null) { foreach (var value in biota.PropertiesAnimPart) { var entity = new BiotaPropertiesAnimPart { ObjectId = biota.Id, Index = value.Index, AnimationId = value.AnimationId, Order = (byte)biota.PropertiesAnimPart.IndexOf(value) }; result.BiotaPropertiesAnimPart.Add(entity); } } if (biota.PropertiesPalette != null) { foreach (var value in biota.PropertiesPalette) { var entity = new BiotaPropertiesPalette { ObjectId = biota.Id, SubPaletteId = value.SubPaletteId, Offset = value.Offset, Length = value.Length }; result.BiotaPropertiesPalette.Add(entity); } } if (biota.PropertiesTextureMap != null) { foreach (var value in biota.PropertiesTextureMap) { var entity = new BiotaPropertiesTextureMap { ObjectId = biota.Id, Index = value.PartIndex, OldId = value.OldTexture, NewId = value.NewTexture, Order = (byte)biota.PropertiesTextureMap.IndexOf(value) }; result.BiotaPropertiesTextureMap.Add(entity); } } // Properties for all world objects that typically aren't modified over the original weenie if (biota.PropertiesCreateList != null) { foreach (var value in biota.PropertiesCreateList) { var entity = new BiotaPropertiesCreateList { ObjectId = biota.Id, DestinationType = (sbyte)value.DestinationType, WeenieClassId = value.WeenieClassId, StackSize = value.StackSize, Palette = value.Palette, Shade = value.Shade, TryToBond = value.TryToBond }; result.BiotaPropertiesCreateList.Add(entity); } } if (biota.PropertiesEmote != null) { foreach (var value in biota.PropertiesEmote) { var entity = new BiotaPropertiesEmote { ObjectId = biota.Id, Category = (uint)value.Category, Probability = value.Probability, WeenieClassId = value.WeenieClassId, Style = (uint?)value.Style, Substyle = (uint?)value.Substyle, Quest = value.Quest, VendorType = (int?)value.VendorType, MinHealth = value.MinHealth, MaxHealth = value.MaxHealth, }; foreach (var value2 in value.PropertiesEmoteAction) { var entity2 = new BiotaPropertiesEmoteAction { // EmoteId is a foreign key to Emote.Id. // If we don't set this to a non-zero number, EF will not auto-set this for us when we add this biota to the database. // We set it to uint.MaxValue instead of 1 because 1 is more likely to be a valid foreign key. We don't want to enter a valid foreign key. // We just want to enter a value that forces EF to update the record with the correct foreign key. If this behavior changes in the future and we set it to 1, // we're more likely to run into an unnoticed issue (because 1 would not throw an exception and uint.MaxValue probably would). // We put this here instead of in ShardDatabase for efficiency. // It's possible this might be fixable with a attribute in the Emote or EmoteAction classes. // It's also possible we don't have the schema defined in a way that helps scaffolding identify the relationship. // Mag-nus 2018-08-04 EmoteId = uint.MaxValue, Order = (uint)value.PropertiesEmoteAction.IndexOf(value2), Type = value2.Type, Delay = value2.Delay, Extent = value2.Extent, Motion = (int?)value2.Motion, Message = value2.Message, TestString = value2.TestString, Min = value2.Min, Max = value2.Max, Min64 = value2.Min64, Max64 = value2.Max64, MinDbl = value2.MinDbl, MaxDbl = value2.MaxDbl, Stat = value2.Stat, Display = value2.Display, Amount = value2.Amount, Amount64 = value2.Amount64, HeroXP64 = value2.HeroXP64, Percent = value2.Percent, SpellId = value2.SpellId, WealthRating = value2.WealthRating, TreasureClass = value2.TreasureClass, TreasureType = value2.TreasureType, PScript = (int?)value2.PScript, Sound = (int?)value2.Sound, DestinationType = value2.DestinationType, WeenieClassId = value2.WeenieClassId, StackSize = value2.StackSize, Palette = value2.Palette, Shade = value2.Shade, TryToBond = value2.TryToBond, ObjCellId = value2.ObjCellId, OriginX = value2.OriginX, OriginY = value2.OriginY, OriginZ = value2.OriginZ, AnglesW = value2.AnglesW, AnglesX = value2.AnglesX, AnglesY = value2.AnglesY, AnglesZ = value2.AnglesZ, }; entity.BiotaPropertiesEmoteAction.Add(entity2); } result.BiotaPropertiesEmote.Add(entity); } } if (biota.PropertiesEventFilter != null) { foreach (var value in biota.PropertiesEventFilter) { var entity = new BiotaPropertiesEventFilter { ObjectId = biota.Id, Event = value }; result.BiotaPropertiesEventFilter.Add(entity); } } if (biota.PropertiesGenerator != null) { foreach (var value in biota.PropertiesGenerator) { var entity = new BiotaPropertiesGenerator { ObjectId = biota.Id, Probability = value.Probability, WeenieClassId = value.WeenieClassId, Delay = value.Delay, InitCreate = value.InitCreate, MaxCreate = value.MaxCreate, WhenCreate = (uint)value.WhenCreate, WhereCreate = (uint)value.WhereCreate, StackSize = value.StackSize, PaletteId = value.PaletteId, Shade = value.Shade, ObjCellId = value.ObjCellId, OriginX = value.OriginX, OriginY = value.OriginY, OriginZ = value.OriginZ, AnglesW = value.AnglesW, AnglesX = value.AnglesX, AnglesY = value.AnglesY, AnglesZ = value.AnglesZ, }; result.BiotaPropertiesGenerator.Add(entity); } } // Properties for creatures if (biota.PropertiesAttribute != null) { foreach (var kvp in biota.PropertiesAttribute) { var entity = new BiotaPropertiesAttribute { ObjectId = biota.Id, Type = (ushort)kvp.Key, InitLevel = kvp.Value.InitLevel, LevelFromCP = kvp.Value.LevelFromCP, CPSpent = kvp.Value.CPSpent }; result.BiotaPropertiesAttribute.Add(entity); } } if (biota.PropertiesAttribute2nd != null) { foreach (var kvp in biota.PropertiesAttribute2nd) { var entity = new BiotaPropertiesAttribute2nd { ObjectId = biota.Id, Type = (ushort)kvp.Key, InitLevel = kvp.Value.InitLevel, LevelFromCP = kvp.Value.LevelFromCP, CPSpent = kvp.Value.CPSpent, CurrentLevel = kvp.Value.CurrentLevel }; result.BiotaPropertiesAttribute2nd.Add(entity); } } if (biota.PropertiesBodyPart != null) { foreach (var kvp in biota.PropertiesBodyPart) { var entity = new BiotaPropertiesBodyPart { ObjectId = biota.Id, Key = (ushort)kvp.Key, DType = (int)kvp.Value.DType, DVal = kvp.Value.DVal, DVar = kvp.Value.DVar, BaseArmor = kvp.Value.BaseArmor, ArmorVsSlash = kvp.Value.ArmorVsSlash, ArmorVsPierce = kvp.Value.ArmorVsPierce, ArmorVsBludgeon = kvp.Value.ArmorVsBludgeon, ArmorVsCold = kvp.Value.ArmorVsCold, ArmorVsFire = kvp.Value.ArmorVsFire, ArmorVsAcid = kvp.Value.ArmorVsAcid, ArmorVsElectric = kvp.Value.ArmorVsElectric, ArmorVsNether = kvp.Value.ArmorVsNether, BH = kvp.Value.BH, HLF = kvp.Value.HLF, MLF = kvp.Value.MLF, LLF = kvp.Value.LLF, HRF = kvp.Value.HRF, MRF = kvp.Value.MRF, LRF = kvp.Value.LRF, HLB = kvp.Value.HLB, MLB = kvp.Value.MLB, LLB = kvp.Value.LLB, HRB = kvp.Value.HRB, MRB = kvp.Value.MRB, LRB = kvp.Value.LRB, }; result.BiotaPropertiesBodyPart.Add(entity); } } if (biota.PropertiesSkill != null) { foreach (var kvp in biota.PropertiesSkill) { var entity = new BiotaPropertiesSkill { ObjectId = biota.Id, Type = (ushort)kvp.Key, LevelFromPP = kvp.Value.LevelFromPP, SAC = (uint)kvp.Value.SAC, PP = kvp.Value.PP, InitLevel = kvp.Value.InitLevel, ResistanceAtLastCheck = kvp.Value.ResistanceAtLastCheck, LastUsedTime = kvp.Value.LastUsedTime, }; result.BiotaPropertiesSkill.Add(entity); } } // Properties for books if (biota.PropertiesBook != null) { result.BiotaPropertiesBook = new BiotaPropertiesBook { ObjectId = biota.Id, MaxNumPages = biota.PropertiesBook.MaxNumPages, MaxNumCharsPerPage = biota.PropertiesBook.MaxNumCharsPerPage }; } if (biota.PropertiesBookPageData != null) { foreach (var value in biota.PropertiesBookPageData) { var entity = new BiotaPropertiesBookPageData { ObjectId = biota.Id, PageId = (uint)biota.PropertiesBookPageData.IndexOf(value), AuthorId = value.AuthorId, AuthorName = value.AuthorName, AuthorAccount = value.AuthorAccount, IgnoreAuthor = value.IgnoreAuthor, PageText = value.PageText }; result.BiotaPropertiesBookPageData.Add(entity); } } // Biota additions over Weenie if (biota.PropertiesAllegiance != null) { foreach (var kvp in biota.PropertiesAllegiance) { var entity = new BiotaPropertiesAllegiance { AllegianceId = biota.Id, CharacterId = kvp.Key, Banned = kvp.Value.Banned, ApprovedVassal = kvp.Value.ApprovedVassal }; result.BiotaPropertiesAllegiance.Add(entity); } } if (biota.PropertiesEnchantmentRegistry != null) { foreach (var value in biota.PropertiesEnchantmentRegistry) { var entity = new BiotaPropertiesEnchantmentRegistry { ObjectId = biota.Id, EnchantmentCategory = value.EnchantmentCategory, SpellId = value.SpellId, LayerId = value.LayerId, HasSpellSetId = value.HasSpellSetId, SpellCategory = (ushort)value.SpellCategory, PowerLevel = value.PowerLevel, StartTime = value.StartTime, Duration = value.Duration, CasterObjectId = value.CasterObjectId, DegradeModifier = value.DegradeModifier, DegradeLimit = value.DegradeLimit, LastTimeDegraded = value.LastTimeDegraded, StatModType = (uint)value.StatModType, StatModKey = value.StatModKey, StatModValue = value.StatModValue, SpellSetId = (uint)value.SpellSetId, }; result.BiotaPropertiesEnchantmentRegistry.Add(entity); } } if (biota.HousePermissions != null) { foreach (var kvp in biota.HousePermissions) { var entity = new ACE.Database.Models.Shard.HousePermission { HouseId = biota.Id, PlayerGuid = kvp.Key, Storage = kvp.Value }; result.HousePermission.Add(entity); } } return(result); }