/// <summary> /// Return items contained by other wow-objects /// </summary> /// <param name="wowOjbectEntry">The entry to search</param> /// <param name="from">Determines the origin table of the id</param> /// <param name="containedIn">Determines the selection of the items from loot or merchant table(only affects creature table)</param> public static List <int> GetItemsById(int wowOjbectEntry, Table from, ContainedIn containedIn) { using (var db = Access.Linq()) { if (wowOjbectEntry == 0) { return(new List <int>()); } var reference_loot_template = from rlt in db.reference_loot_template select new reference_loot_template { Entry = rlt.Entry, Item = rlt.Item, Reference = rlt.Reference, }; if (from == Table.Creature) { if (containedIn == ContainedIn.Loot) { var creature_loot_template = from clt in db.creature_loot_template select new creature_loot_template { Entry = clt.Entry, Item = clt.Item, Reference = clt.Reference, }; creature_loot_template = (from clt in creature_loot_template where clt.Entry == wowOjbectEntry && clt.Item != clt.Reference select new creature_loot_template { Entry = clt.Entry, Item = clt.Item, }) .Union( from clt in creature_loot_template where clt.Entry == wowOjbectEntry && clt.Item == clt.Reference join rlt in reference_loot_template on clt.Reference equals rlt.Entry where rlt.Reference == 0 select new creature_loot_template { Item = rlt.Item, } ) .Union( from clt in creature_loot_template where clt.Entry == wowOjbectEntry && clt.Item == clt.Reference join rlt in reference_loot_template on clt.Reference equals rlt.Entry where rlt.Reference != 0 join rlt_ in reference_loot_template on rlt.Reference equals rlt_.Entry select new creature_loot_template { Item = rlt_.Item, } ); return(creature_loot_template.Select(i => i.Item).ToList()); } if (containedIn == ContainedIn.Merchant) { var npc_vendor = from nv in db.npc_vendor where wowOjbectEntry == nv.entry select new npc_vendor { entry = nv.entry, item = nv.item }; return(npc_vendor.Select(i => i.item).ToList()); } } if (from == Table.GameOjbect) { var gameobject_loot_template = from clt in db.gameobject_loot_template select new gameobject_loot_template { Entry = clt.Entry, Item = clt.Item, Reference = clt.Reference, }; gameobject_loot_template = (from clt in gameobject_loot_template where clt.Entry == wowOjbectEntry && clt.Item != clt.Reference select new gameobject_loot_template { Entry = clt.Entry, Item = clt.Item, }) .Union( from clt in gameobject_loot_template where clt.Entry == wowOjbectEntry && clt.Item == clt.Reference join rlt in reference_loot_template on clt.Reference equals rlt.Entry where rlt.Reference == 0 select new gameobject_loot_template { Item = rlt.Item, } ) .Union( from clt in gameobject_loot_template where clt.Entry == wowOjbectEntry && clt.Item == clt.Reference join rlt in reference_loot_template on clt.Reference equals rlt.Entry where rlt.Reference != 0 join rlt_ in reference_loot_template on rlt.Reference equals rlt_.Entry select new gameobject_loot_template { Item = rlt_.Item, } ); return(gameobject_loot_template.Select(i => i.Item).ToList()); } if (from == Table.Item) { var item_loot_template = from clt in db.item_loot_template select new item_loot_template { Entry = clt.Entry, Item = clt.Item, Reference = clt.Reference, }; item_loot_template = (from clt in item_loot_template where clt.Entry == wowOjbectEntry && clt.Item != clt.Reference select new item_loot_template { Entry = clt.Entry, Item = clt.Item, }) .Union( from clt in item_loot_template where clt.Entry == wowOjbectEntry && clt.Item == clt.Reference join rlt in reference_loot_template on clt.Reference equals rlt.Entry where rlt.Reference == 0 select new item_loot_template { Item = rlt.Item, } ) .Union( from clt in item_loot_template where clt.Entry == wowOjbectEntry && clt.Item == clt.Reference join rlt in reference_loot_template on clt.Reference equals rlt.Entry where rlt.Reference != 0 join rlt_ in reference_loot_template on rlt.Reference equals rlt_.Entry select new item_loot_template { Item = rlt_.Item, } ); return(item_loot_template.Select(i => i.Item).ToList()); } return(new List <int>()); } }
public static IPredicate Load(this Predicate @this, ISession session) { switch (@this.Kind) { case PredicateKind.And: return(new And { Dependencies = @this.Dependencies, Operands = @this.Operands.Select(v => v.Load(session)).ToArray(), }); case PredicateKind.Or: return(new Or { Dependencies = @this.Dependencies, Operands = @this.Operands.Select(v => v.Load(session)).ToArray(), }); case PredicateKind.Not: return(new Not { Dependencies = @this.Dependencies, Operand = @this.Operand.Load(session), }); default: var propertyType = @this.PropertyType != null ? (IPropertyType)session.Database.ObjectFactory.MetaPopulation.Find(@this.PropertyType.Value) : null; var roleType = @this.RoleType != null ? (IRoleType)session.Database.ObjectFactory.MetaPopulation.Find(@this.RoleType.Value) : null; switch (@this.Kind) { case PredicateKind.Instanceof: return(new Instanceof(@this.ObjectType != null ? (IComposite)session.Database.MetaPopulation.Find(@this.ObjectType.Value) : null) { Dependencies = @this.Dependencies, PropertyType = propertyType, }); case PredicateKind.Exists: return(new Exists { Dependencies = @this.Dependencies, PropertyType = propertyType, Parameter = @this.Parameter, }); case PredicateKind.Contains: return(new Contains { Dependencies = @this.Dependencies, PropertyType = propertyType, Parameter = @this.Parameter, Object = session.Instantiate(@this.Object), }); case PredicateKind.ContainedIn: var containedIn = new ContainedIn(propertyType) { Dependencies = @this.Dependencies, Parameter = @this.Parameter }; if (@this.Objects != null) { containedIn.Objects = @this.Objects.Select(session.Instantiate).ToArray(); } else if (@this.Extent != null) { containedIn.Extent = @this.Extent.Load(session); } return(containedIn); case PredicateKind.Equals: var equals = new Equals(propertyType) { Dependencies = @this.Dependencies, Parameter = @this.Parameter }; if (@this.Object != null) { equals.Object = session.Instantiate(@this.Object); } else if (@this.Value != null) { var value = UnitConvert.Parse(((IRoleType)propertyType).ObjectType.Id, @this.Value); equals.Value = value; } return(equals); case PredicateKind.Between: return(new Between(roleType) { Dependencies = @this.Dependencies, Parameter = @this.Parameter, Values = @this.Values?.Select(v => UnitConvert.Parse(roleType.ObjectType.Id, v)).ToArray(), }); case PredicateKind.GreaterThan: return(new GreaterThan(roleType) { Dependencies = @this.Dependencies, Parameter = @this.Parameter, Value = UnitConvert.Parse(roleType.ObjectType.Id, @this.Value), }); case PredicateKind.LessThan: return(new LessThan(roleType) { Dependencies = @this.Dependencies, Parameter = @this.Parameter, Value = UnitConvert.Parse(roleType.ObjectType.Id, @this.Value), }); case PredicateKind.Like: return(new Like(roleType) { Dependencies = @this.Dependencies, Parameter = @this.Parameter, Value = UnitConvert.Parse(roleType.ObjectType.Id, @this.Value)?.ToString(), }); default: throw new Exception("Unknown predicate kind " + @this.Kind); } } }
public IPredicate Load(ISession session) { switch (this.Kind) { case PredicateKind.And: return(new And { Operands = this.Operands.Select(v => v.Load(session)).ToArray() }); case PredicateKind.Or: return(new Or { Operands = this.Operands.Select(v => v.Load(session)).ToArray() }); case PredicateKind.Not: return(new Not { Operand = this.Operand.Load(session) }); default: var propertyType = this.PropertyType != null ? (IPropertyType)session.Database.ObjectFactory.MetaPopulation.Find(this.PropertyType.Value) : null; var roleType = this.RoleType != null ? (IRoleType)session.Database.ObjectFactory.MetaPopulation.Find(this.RoleType.Value) : null; switch (this.Kind) { case PredicateKind.Instanceof: return(new Instanceof(this.ObjectType != null ? (IComposite)session.Database.MetaPopulation.Find(this.ObjectType.Value) : null) { PropertyType = propertyType }); case PredicateKind.Exists: return(new Exists { PropertyType = propertyType, Parameter = this.Parameter }); case PredicateKind.Equals: var equals = new Equals(propertyType) { Parameter = this.Parameter }; if (this.Object != null) { equals.Object = session.Instantiate(this.Object); } else if (this.Value != null) { var value = Convert.ToValue((IUnit)((IRoleType)propertyType)?.ObjectType, this.Value); equals.Value = value; } return(equals); case PredicateKind.Contains: return(new Contains { PropertyType = propertyType, Parameter = this.Parameter, Object = session.Instantiate(this.Object) }); case PredicateKind.ContainedIn: var containedIn = new ContainedIn(propertyType) { Parameter = this.Parameter }; if (this.Objects != null) { containedIn.Objects = this.Objects.Select(session.Instantiate).ToArray(); } else if (this.Extent != null) { containedIn.Extent = this.Extent.Load(session); } return(containedIn); case PredicateKind.Between: return(new Between(roleType) { Parameter = this.Parameter, Values = this.Values.Select(v => Convert.ToValue((IUnit)roleType?.ObjectType, v)).ToArray() }); case PredicateKind.GreaterThan: return(new GreaterThan(roleType) { Parameter = this.Parameter, Value = Convert.ToValue((IUnit)roleType?.ObjectType, this.Value) }); case PredicateKind.LessThan: return(new LessThan(roleType) { Parameter = this.Parameter, Value = Convert.ToValue((IUnit)roleType?.ObjectType, this.Value) }); case PredicateKind.Like: return(new Like(roleType) { Parameter = this.Parameter, Value = this.Value }); default: throw new Exception("Unknown predicate kind " + this.Kind); } } }
/// <param name="contains"> /// Determines which items should be checked from creatures if "HashSet<int> Ids" is not empty /// <para>ContainedIn.Loot: from loot table</para> /// <para>ContainedIn.Merchant: from merchant table</para> /// <para>Default: ContainedIn.Loot</para> /// </param> /// <param name="ids"></param> public ItemIds(ContainedIn contains, HashSet <int> ids) { this.Contains = contains; this.Ids = ids; }