Ejemplo n.º 1
0
        public static UseResponse UseCode(string code)
        {
            UseResponse useResp = new UseResponse();

            if (string.IsNullOrWhiteSpace(code))
            {
                useResp.Notification  = "Missing CardCode";
                useResp.UseCodeStatus = Protocol.UseCodeEnum.Error;
                return(useResp);
            }

            using (var context = new EPSContext())
            {
                CardCode cardCode = GetCardCode(context, code);
                if (cardCode != null && string.IsNullOrWhiteSpace(cardCode.Used))
                {
                    cardCode.Used = DateTime.Now.ToString();
                    context.SaveChanges();
                    useResp.UseCodeStatus = Protocol.UseCodeEnum.Used;
                }
                else if (!string.IsNullOrWhiteSpace(cardCode.Used))
                {
                    useResp.Notification  = $"Card code:{code.ToUpper()} alredy used";
                    useResp.UseCodeStatus = Protocol.UseCodeEnum.AlreadyUsed;
                }
                else
                {
                    useResp.Notification  = $"No such code:{code.ToUpper()}";
                    useResp.UseCodeStatus = Protocol.UseCodeEnum.NoCode;
                }

                return(useResp);
            }
        }
Ejemplo n.º 2
0
        public static ChekResponse CheckCardCode(string code)
        {
            ChekResponse checkReq = new ChekResponse();

            if (string.IsNullOrWhiteSpace(code))
            {
                checkReq.Notification = "Missing CardCode";
                return(checkReq);
            }
            using (var context = new EPSContext())
            {
                CardCode cardCode = GetCardCode(context, code);
                if (cardCode != null)
                {
                    var queryProducts = from pr in context.Products
                                        where pr.CardCodeID == cardCode.ID
                                        select pr.ProducCode;
                    checkReq.ProducCodes = queryProducts.ToArray();
                }
                else
                {
                    checkReq.Notification = $"No such code:{code.ToUpper()}";
                }
                return(checkReq);
            }
        }
Ejemplo n.º 3
0
 public PokerCard BuildCard(CardCode cardCode)
 {
     return new PokerCard
         {
             CardFace = _cardRepo.GetFaceFor(cardCode.FaceCode),
             CardSuit = _cardRepo.GetSuitFor(cardCode.SuitCode)
         };
 }
Ejemplo n.º 4
0
        /// <summary>
        /// The targeted player gains a card
        /// </summary>
        /// <param name="target">The player gaining the card</param>
        /// <param name="code">The card being gained</param>
        /// <returns></returns>
        public Card GainCard(Player target, CardCode code)
        {
            if (!Supplies.HasSupply(code))
                throw new ArgumentOutOfRangeException("Supply piles do not include " + code.ToString());

            Card retval = null;
            CardContainer pile = Supplies[code];

            if (pile.Count > 0)
            {
                retval = pile.Draw();
            }

            _game.NotifyPlayers(p => p.OnGainCard(target, code));
            return retval;
        }
Ejemplo n.º 5
0
 /// <summary>
 /// The current player gains a card
 /// </summary>
 /// <param name="code"></param>
 /// <returns></returns>
 public Card GainCard(CardCode code)
 {
     return GainCard(Actor, code);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Signals when a player gains a card
 /// </summary>
 /// <param name="gainingPlayer">The player gaining the card</param>
 /// <param name="gainedCardCode">The card code gained</param>
 public abstract void OnGainCard(Player gainingPlayer, CardCode gainedCardCode);
Ejemplo n.º 7
0
        private static IEnumerable <ICard> ExpandChamp(ICard card, Catalog localCatalog, Catalog homeCatalog)
        {
            // The potential lv. 2+ champs for this card are champion units that share its code (sans T number).
            // We group the cards by name and evaluate the grouped cards together.
            CardCode bc = card.Code;

            IGrouping <string?, ICard>[] hNameGroups = homeCatalog.Cards.Values
                                                       .Where(c =>
                                                              c.Code.Number == bc.Number &&
                                                              c.Code.TNumber != 0 &&
                                                              c.Code.Faction == bc.Faction &&
                                                              c.Code.Set == bc.Set &&
                                                              c.Supertype?.Name == "Champion" &&
                                                              c.Type?.Name == "Unit")
                                                       .GroupBy(c => c.Name)
                                                       .ToArray();

            // Only attempt to find lv. 2+ champs if either:
            // - There's a single name-group of cards (e.g. Spider Queen Elise)
            // - There's a name-group of cards with the same name as the lv. 1 champ (e.g. Anivia but not Eggnivia)
            ICard hCard = homeCatalog.Cards[card.Code];
            IGrouping <string?, ICard>?hNameGroup = hNameGroups.Length == 1 ? hNameGroups[0] : hNameGroups.SingleOrDefault(g => g.Key == hCard.Name);

            if (hNameGroup is null)
            {
                return(new[] { card });
            }

            // If there's only one lv. 2+ champ in the group, assume it's the lv. 2 champ (e.g. Garen)
            // If there are two lv. 2+ champs in the group, assume the one with a level-up is lv. 2 and the one with no level-up is lv. 3 (e.g. Renekton)
            // Otherwise, we can't assume anything.
            ICard[] hCards = hNameGroup.ToArray();
            ICard?  hLv2 = null, hLv3 = null;

            if (hCards.Length == 1)
            {
                hLv2 = hCards[0];
            }
            else if (hCards.Length == 2)
            {
                bool aLeveled = string.IsNullOrWhiteSpace(hCards[0].LevelupDescription);
                bool bLeveled = string.IsNullOrWhiteSpace(hCards[1].LevelupDescription);

                if (!bLeveled && aLeveled)
                {
                    hLv2 = hCards[1];
                    hLv3 = hCards[0];
                }

                if (!aLeveled && bLeveled)
                {
                    hLv2 = hCards[0];
                    hLv3 = hCards[1];
                }
            }

            // We're done! Return either one, two, or three levels of champs.

            if (hLv2 is null)
            {
                return(new[] { card });
            }

            ICard lLv2 = localCatalog.Cards[hLv2.Code];

            if (hLv3 is null)
            {
                return(new[] { card, lLv2 });
            }

            ICard lLv3 = localCatalog.Cards[hLv3.Code];

            return(new[] { card, lLv2, lLv3 });
        }