Пример #1
0
 /// <summary>
 /// Returns the <see cref="IProductVariant"/> of this <see cref="IProduct"/> that contains a matching collection of <see cref="IProductAttribute" />. 
 /// If not match is found, returns null.
 /// </summary>
 /// <param name="product"></param>
 /// <param name="selectedChoiceKeys"></param>
 /// <returns><see cref="IProductVariant"/> or null if no <see cref="IProductVariant"/> is found with a matching collection of <see cref="IProductAttribute"/></returns>
 public static IProductVariant GetProductVariantForPurchase(this IProduct product, Guid[] selectedChoiceKeys)
 {
     return
         product.ProductVariants.FirstOrDefault(
             variant => variant.Attributes.Count() == selectedChoiceKeys.Length &&
                        selectedChoiceKeys.All(key => ((ProductAttributeCollection)variant.Attributes).Contains(key)));
 }
 /// <summary>
 /// Gets the <see cref="ProductVariantDisplay"/> with matching with attributes from the product.
 /// </summary>
 /// <param name="product">
 /// The product.
 /// </param>
 /// <param name="optionChoices">
 /// The option choices.
 /// </param>
 /// <returns>
 /// The <see cref="ProductVariantDisplay"/>.
 /// </returns>        
 public static ProductVariantDisplay GetProductVariantDisplayWithAttributes(this ProductDisplay product, Guid[] optionChoices)
 {
     return
         product.ProductVariants.FirstOrDefault(
             x =>
             x.Attributes.Count() == optionChoices.Count()
             && optionChoices.All(key => x.Attributes.FirstOrDefault(att => att.Key == key) != null));
 }
Пример #3
0
        /// <summary>
        /// Gets a list of valid variants based on partial attribute selection
        /// </summary>
        /// <param name="productKey">The product key</param>
        /// <param name="attributeKeys">The selected option choices</param>
        /// <returns>A collection of <see cref="ProductVariantDisplay"/></returns>
        /// <remarks>
        /// Intended to assist in product variant selection 
        /// </remarks>
        public IEnumerable<ProductVariantDisplay> GetValidProductVariants(Guid productKey, Guid[] attributeKeys)
        {
            var product = Product(productKey);
            if(product == null) throw new InvalidOperationException("Product is null");
            if (!attributeKeys.Any()) return product.ProductVariants;

            var variants = product.ProductVariants.Where(x => attributeKeys.All(key => x.Attributes.FirstOrDefault(att => att.Key == key) != null));

            return variants;
        }
Пример #4
0
        /// <summary>Creates new cards on the table, as well as the corresponding CardIdentities.</summary>
        /// <param name="id">An array with the new CardIdentity ids</param>
        /// <param name="modelId"> </param>
        /// <param name="x">The x position of the cards on the table.</param>
        /// <param name="y">The y position of the cards on the table.</param>
        /// <param name="faceUp">Whether the cards are face up or not.</param>
        /// <param name="key"> </param>
        /// <param name="persist"> </param>
        public void CreateCardAt(int[] id, ulong[] key, Guid[] modelId, int[] x, int[] y, bool faceUp, bool persist)
        {
            if (id.Length == 0)
            {
                Program.Trace.TraceEvent(TraceEventType.Warning, EventIds.Event, "[CreateCardAt] Empty id parameter.");
                return;
            }
            if (id.Length != key.Length || id.Length != x.Length || id.Length != y.Length || id.Length != modelId.Length)
            {
                Program.Trace.TraceEvent(TraceEventType.Warning, EventIds.Event, "[CreateCardAt] Inconsistent parameters length.");
                return;
            }
            Player owner = Player.Find((byte)(id[0] >> 16));
            if (owner == null)
            {
                Program.Trace.TraceEvent(TraceEventType.Warning, EventIds.Event, "[CreateCardAt] Player not found.");
                return;
            }
            var table = Program.GameEngine.Table;
            // Bring cards created by oneself to top, for z-order consistency
            if (owner == Player.LocalPlayer)
            {
                for (int i = id.Length - 1; i >= 0; --i)
                {
                    var card = Card.Find(id[i]);
                    if (card == null)
                    {
                        Program.Trace.TraceEvent(TraceEventType.Warning, EventIds.Event, "[CreateCardAt] Card not found.");
                        return;
                    }
                    table.SetCardIndex(card, table.Count + i - id.Length);
                }
            }
            else
            {
                for (int i = 0; i < id.Length; i++)
                    new CreateCard(owner, id[i], key[i], faceUp,Program.GameEngine.Definition.GetCardById(modelId[i]), x[i], y[i], !persist).Do();
            }

            // Display log messages
            try
            {
                if (modelId.All(m => m == modelId[0]))
                    Program.Trace.TraceEvent(TraceEventType.Information, EventIds.Event | EventIds.PlayerFlag(owner), "{0} creates {1} '{2}'", owner, modelId.Length, owner == Player.LocalPlayer || faceUp ? Program.GameEngine.Definition.GetCardById(modelId[0]).Name : "card");
                else
                    foreach (Guid m in modelId)
                        Program.Trace.TraceEvent(TraceEventType.Information, EventIds.Event | EventIds.PlayerFlag(owner), "{0} creates a '{1}'", owner, owner == Player.LocalPlayer || faceUp ? Program.GameEngine.Definition.GetCardById(m).Name : "card");

            }
            catch (Exception e)
            {
                // TODO - [FIX THIS SHIT] - A null reference exception happens on the first trace event. - Kelly Elton - 3/24/2013
                // This should be cleaered up, this is only a temp fix. - Kelly Elton - 3/24/2013
            }
        }
Пример #5
0
        /// <summary>Creates new cards on the table, as well as the corresponding CardIdentities.</summary>
        /// <param name="id">An array with the new CardIdentity ids</param>
        /// <param name="modelId"> </param>
        /// <param name="x">The x position of the cards on the table.</param>
        /// <param name="y">The y position of the cards on the table.</param>
        /// <param name="faceUp">Whether the cards are face up or not.</param>
        /// <param name="key"> </param>
        /// <param name="persist"> </param>
        public void CreateCardAt(int[] id, ulong[] key, Guid[] modelId, int[] x, int[] y, bool faceUp, bool persist)
        {
            if (id.Length == 0)
            {
                Program.Trace.TraceEvent(TraceEventType.Warning, EventIds.Event, "[CreateCardAt] Empty id parameter.");
                return;
            }
            if (id.Length != key.Length || id.Length != x.Length || id.Length != y.Length || id.Length != modelId.Length)
            {
                Program.Trace.TraceEvent(TraceEventType.Warning, EventIds.Event, "[CreateCardAt] Inconsistent parameters length.");
                return;
            }
            Player owner = Player.Find((byte)(id[0] >> 16));
            if (owner == null)
            {
                Program.Trace.TraceEvent(TraceEventType.Warning, EventIds.Event, "[CreateCardAt] Player not found.");
                return;
            }
            var table = Program.Game.Table;
            // Bring cards created by oneself to top, for z-order consistency
            if (owner == Player.LocalPlayer)
            {
                for (int i = id.Length - 1; i >= 0; --i)
                {
                    var card = Card.Find(id[i]);
                    if (card == null)
                    {
                        Program.Trace.TraceEvent(TraceEventType.Warning, EventIds.Event, "[CreateCardAt] Card not found.");
                        return;
                    }
                    table.SetCardIndex(card, table.Count + i - id.Length);
                }
            }
            else
            {
                for (int i = 0; i < id.Length; i++)
                    new CreateCard(owner, id[i], key[i], faceUp,Database.GetCardById(modelId[i]), x[i], y[i], !persist).Do();
            }

            // Display log messages
            if (modelId.All(m => m == modelId[0]))
                Program.Trace.TraceEvent(TraceEventType.Information, EventIds.Event | EventIds.PlayerFlag(owner), "{0} creates {1} '{2}'", owner, modelId.Length, owner == Player.LocalPlayer || faceUp ? Database.GetCardById(modelId[0]).Name :"card");
            else
                foreach (Guid m in modelId)
                    Program.Trace.TraceEvent(TraceEventType.Information, EventIds.Event | EventIds.PlayerFlag(owner), "{0} creates a '{1}'", owner, owner == Player.LocalPlayer || faceUp? Database.GetCardById(m).Name : "card");
        }
Пример #6
0
 /// <summary>
 /// Get a product variant from a product by it's collection of attributes
 /// </summary>
 /// <param name="productKey">The product key</param>
 /// <param name="attributeKeys">The option choices (attributeKeys)</param>
 /// <returns>The <see cref="ProductVariantDisplay"/></returns>
 public ProductVariantDisplay GetProductVariantWithAttributes(Guid productKey, Guid[] attributeKeys)
 {
     var product = Query.Product.GetByKey(productKey);
     return product.ProductVariants.FirstOrDefault(x => x.Attributes.Count() == attributeKeys.Count() && attributeKeys.All(key => x.Attributes.FirstOrDefault(att => att.Key == key) != null));
 }
        /// <summary>
        /// Gets the <see cref="ProductVariantDisplay"/> with matching with attributes from the product.
        /// </summary>
        /// <param name="product">
        /// The product.
        /// </param>
        /// <param name="optionChoices">
        /// The option choices.
        /// </param>
        /// <returns>
        /// The <see cref="ProductVariantDisplay"/>.
        /// </returns>        
        public static IProductVariantContent GetProductVariantDisplayWithAttributes(this IProductContent product, Guid[] optionChoices)
        {
            var variant =
                product.ProductVariants.FirstOrDefault(
                    x =>
                    x.Attributes.Count() == optionChoices.Count()
                    && optionChoices.All(key => x.Attributes.FirstOrDefault(att => att.Key == key) != null));

            if (variant == null)
            {
                MultiLogHelper.Debug(typeof(ProductContentExtensions), "Could not find IProductVariantContent with keys matching choices in optionChoices array.");
            }

            return variant;
        }