예제 #1
0
        public GiftResponse GetRewardGift(string giftId)
        {
            // --- Buscar Regalo solicitado ---
            RewardGift rewardGift
                = Database.RewardGiftStore[giftId];

            if (rewardGift == null)
            {
                throw new HttpNotFoundException(
                          ControllerStrings.Warning701_GiftNotFound
                          );
            }

            // --- Verificar que el Regalo haya sido reclamado por el Usuario ---
            UserRewardGiftClaimed userRewardGiftClaim
                = Database.UserRewardGiftClaimedStore.GetFirst(
                      filter: f =>
                      f.RewardGift.Guid == rewardGift.Guid &&
                      f.RedeemedByUser.Guid == CurrentUser.Guid
                      );

            if (userRewardGiftClaim == null)
            {
                throw new HttpNotFoundException(
                          ControllerStrings.Warning701_GiftNotFound
                          );
            }

            // --- Obtener Información del Regalo ---
            // Obtener fotografías del Regalo
            List <string> rewardGiftPictures
                = new List <string>();

            foreach (RewardGiftPicture picture in rewardGift.RewardGiftPictures)
            {
                rewardGiftPictures.Add(
                    picture.Guid.ToString() + "." + picture.PictureExtension
                    );
            }

            // --- Obtener Regalo en el Idioma actual ---
            return(new GiftResponse()
            {
                NamePlural
                    = rewardGift.GetGlobalization().NamePlural,
                NameSingular
                    = rewardGift.GetGlobalization().NameSingular,

                RedeemCode
                    = userRewardGiftClaim.RedeemCode,
                RedeemPicture
                    = GetDynamicResourceUri(userRewardGiftClaim),

                Pictures
                    = rewardGift.RewardGiftPictures.Select(s => GetDynamicResourceUri(s))
            });
        }
예제 #2
0
        public GiftPopup(GraphicsDevice graphics, SpriteFont font, Gift gift, int x, int y, int width, int height)
        {
            this.font           = font;
            this.gift           = gift;
            giftColor           = Gift.GetColor(gift.Type);
            uniqueGift          = new Gift(gift.Type);
            uniqueGift.Contents = new GiftContents(gift.Contents.Coins, gift.Contents.Projectiles.Unique(),
                                                   gift.Contents.Materials.Unique());

            bgImg  = new Texture2D(graphics, width, height);
            bgImg  = DrawHelper.AddBorder(bgImg, 3, Color.Gray, Color.LightGray);
            bgRect = new Rectangle(x, y, width, height);

            itemRect = new Rectangle();
            ResetItemRect();
            itemImg = Utilities.CoinIcon;

            itemTimer = new Timer(ITEM_SHOW_WAIT_TIME, TimerUnits.Seconds);

            particleImg = new Texture2D(graphics, PARTICLE_SIZE, PARTICLE_SIZE);
            Color[] data = new Color[PARTICLE_SIZE * PARTICLE_SIZE];
            for (int i = 0; i < PARTICLE_SIZE * PARTICLE_SIZE; i++)
            {
                data[i] = Color.White;
            }
            particleImg.SetData(data);
            for (int i = 0; i < NUM_OF_PARTICLES; i++)
            {
                AddParticle();
            }

            claimButton = new MenuButton(new System.Action(() => reward?.Invoke(gift)), Language.Translate("Claim Gift"), 0, 0, true, font,
                                         graphics);
            claimButton.X = bgRect.X + bgRect.Width / 2 - claimButton.Width / 2;
            claimButton.Y = bgRect.Bottom - claimButton.Height - SPACING * 2;
            reward       += new RewardGift(w => Active = false);

            itemString    = "+" + gift.Contents.Coins.ToString() + " " + Language.Translate("coins");
            itemStringPos = new Vector2(0, claimButton.Y - SPACING - font.MeasureString(itemString).Y);
            RepostionItemString();

            fireworkTimer = new Timer(0, TimerUnits.Milliseconds);

            skipTipPos.X = bgRect.X + bgRect.Width / 2 - font.MeasureString(skipTip).X / 2;
            skipTipPos.Y = bgRect.Y + SPACING;
        }
예제 #3
0
 public void AddRewardHandler(RewardGift handler)
 {
     reward += handler;
 }
예제 #4
0
 public void AddClaimHandler(RewardGift handler)
 {
     claim += handler;
 }
예제 #5
0
        public GiftClaimResponse ClaimRewardGift(string giftId)
        {
            // --- Buscar Regalo solicitado ---
            RewardGift rewardGift
                = Database.RewardGiftStore.Get(giftId);

            if (rewardGift == null)
            {
                throw new HttpNotFoundException(
                          ControllerStrings.Warning701_GiftNotFound
                          );
            }

            // --- Verificar que el Regalo haya sido obtenido por el Usuario ---
            UserEarnedReward userEarnedReward
                = Database.UserEarnedRewardStore.GetFirst(
                      filter: f =>
                      f.User.Guid == CurrentUser.Guid &&
                      f.Reward.RewardGift.Any(r => r.Guid == rewardGift.Guid)
                      );

            if (userEarnedReward == null)
            {
                throw new HttpNotFoundException(
                          ControllerStrings.Warning701_GiftNotFound
                          );
            }

            // --- Verificar que el Regalo no haya sido Reclamado por el Usuario ---
            bool userClaimedGift
                = rewardGift.UserRewardGiftClaimed.Where(w =>
                                                         w.RedeemedByUser.Guid == CurrentUser.Guid &&
                                                         w.RewardGift.Guid == rewardGift.Guid
                                                         ).FirstOrDefault() != null;

            if (userClaimedGift)
            {
                throw new HttpNotFoundException(
                          ControllerStrings.Warning701_GiftNotFound
                          );
            }

            // --- Verificar que el Usuario tenga Información de Envío si el Regalo se envía ---
            if (rewardGift.IsShipped)
            {
                ShippingInformation shippingInformation
                    = CurrentUser.ShippingInformation;

                if (shippingInformation == null)
                {
                    throw new HttpConflictException(
                              ControllerStrings.Warning205_ShippingInfoNotSet
                              );
                }
            }

            // --- Obtener un objeto de Reclamo ---
            UserRewardGiftClaimed giftClaim
                = Database.UserRewardGiftClaimedStore.GetFirst(
                      filter: f =>
                      f.RedeemedByUser == null &&
                      f.RewardGift.Guid == rewardGift.Guid
                      );

            if (giftClaim == null)
            {
                throw new HttpNoContentException(
                          ControllerStrings.Warning702_GiftOutOfStock
                          );
            }

            // --- Asociar al Usuario con el Reclamo (efectivamente reclamando el regalo del usuario) ---
            giftClaim.RedeemedByUser
                = CurrentUser;

            Database.UserRewardGiftClaimedStore.Update(giftClaim);
            Database.SaveChanges();

            // Devolver estatus "204 No Content" si el Regalo lo envía KMS.
            if (rewardGift.IsShipped)
            {
                throw new HttpNoContentException("703" + ControllerStrings.Warning703_GiftShippingPending);
            }

            // --- Devolver detalles de canje ---
            return(new GiftClaimResponse()
            {
                ExpirationDate
                    = giftClaim.ExpirationDate.HasValue
                    ? giftClaim.ExpirationDate.Value
                    : DateTime.MaxValue,
                RedeemCode
                    = giftClaim.RedeemCode,
                RedeemPicture
                    = GetDynamicResourceUri(giftClaim)
            });
        }