Selaa lähdekoodia

Effects that gives items to user

Tigran 3 vuotta sitten
vanhempi
commit
b29470c04a

+ 3 - 1
CardCollector/Commands/ChosenInlineResult/SelectTraderResult.cs

@@ -19,8 +19,10 @@ namespace CardCollector.Commands.ChosenInlineResult
             var module = User.Session.GetModule<AuctionModule>();
             if (module.SelectedSticker is not {} sticker) return;
             module.SelectedPosition = product;
+            var discount = 1.0 - await User.AuctionDiscount() / 100.0;
             var messageSticker = await MessageController.SendSticker(User, sticker.Id);
-            var message = await MessageController.SendMessage(User, sticker.ToString(module.MaxCount), Keyboard.GetStickerKeyboard(User.Session));
+            var message = await MessageController.SendMessage(User, sticker.ToString(module.MaxCount), 
+                Keyboard.GetStickerKeyboard(User.Session, discount));
             User.Session.Messages.Add(messageSticker.MessageId);
             User.Session.Messages.Add(message.MessageId);
         }

+ 0 - 2
CardCollector/Extensions.cs

@@ -81,9 +81,7 @@ namespace CardCollector
             this IEnumerable<T> source, Func<T, Task<bool>> predicate)
         {
             foreach (var element in source)
-            {
                 if (await predicate(element)) return true;
-            }
             return false;
         }
 

+ 1 - 1
CardCollector/Resources/Constants.cs

@@ -28,6 +28,6 @@ namespace CardCollector.Resources
         /* Время оповещения и сброса ежедневных заданий */
         public static readonly TimeSpan DailyTaskAlert = DEBUG ? new TimeSpan(21, 0, 0) : new TimeSpan(12, 0, 0);
         public static readonly TimeSpan DailyTaskReset = DEBUG ? new TimeSpan(0, 13, 0) : new TimeSpan(0, 0, 0);
-        public static readonly TimeSpan DailyStickerRewardCheck = DEBUG ? new TimeSpan(0, 30, 0) : new TimeSpan(1, 0, 0);
+        public static readonly TimeSpan DailyStickerRewardCheck = DEBUG ? new TimeSpan(1, 9, 0) : new TimeSpan(1, 0, 0);
     }
 }

+ 5 - 4
CardCollector/Resources/Keyboard.cs

@@ -289,10 +289,11 @@ namespace CardCollector.Resources
             });
         }
 
-        public static InlineKeyboardMarkup GetAuctionProductKeyboard(AuctionModule module)
+        public static InlineKeyboardMarkup GetAuctionProductKeyboard(AuctionModule module, double discount)
         {
+            var price = (int)(module.Price * module.Count * discount);
             return new InlineKeyboardMarkup(new[] {
-                new[] {InlineKeyboardButton.WithCallbackData($"{Text.buy} ({module.Count}) {module.Price * module.Count}{Text.gem}", Command.confirm_buying)},
+                new[] {InlineKeyboardButton.WithCallbackData($"{Text.buy} ({module.Count}) {price}{Text.gem}", Command.confirm_buying)},
                 new[]
                 {
                     InlineKeyboardButton.WithCallbackData(Text.minus, $"{Command.count}-"),
@@ -321,11 +322,11 @@ namespace CardCollector.Resources
             });
         }
 
-        public static InlineKeyboardMarkup GetStickerKeyboard(UserSession session)
+        public static InlineKeyboardMarkup GetStickerKeyboard(UserSession session, double discount = 1.0)
         {
             return session.State switch
             {
-                UserState.ProductMenu => GetAuctionProductKeyboard(session.GetModule<AuctionModule>()),
+                UserState.ProductMenu => GetAuctionProductKeyboard(session.GetModule<AuctionModule>(), discount),
                 UserState.AuctionMenu => GetAuctionStickerKeyboard(),
                 UserState.CombineMenu => GetCombineStickerKeyboard(session.GetModule<CombineModule>()),
                 UserState.CollectionMenu => GetCollectionStickerKeyboard(session.GetModule<CollectionModule>()),

+ 7 - 6
CardCollector/StickerEffects/Effect.cs

@@ -2,11 +2,12 @@
 {
     public enum Effect
     {
-        PiggyBank200,
-        Diamonds25Percent,
-        AuctionDiscount5,
-        Random1Pack5Day,
-        RandomSticker2Tier3Day,
-        RandomSticker1Tier3Day
+        None = 0,
+        PiggyBank200 = 1,
+        Diamonds25Percent = 2,
+        AuctionDiscount5 = 3,
+        Random1Pack5Day = 4,
+        RandomSticker2Tier3Day = 5,
+        RandomSticker1Tier3Day = 6,
     }
 }

+ 11 - 6
CardCollector/StickerEffects/EffectFunctions.cs

@@ -1,4 +1,6 @@
-using System.Threading.Tasks;
+using System;
+using System.Globalization;
+using System.Threading.Tasks;
 using System.Timers;
 using CardCollector.Controllers;
 using CardCollector.DataBase.EntityDao;
@@ -24,7 +26,8 @@ namespace CardCollector.StickerEffects
                 var packsCount = await Random1Pack5Day.GetPacksCount(stickers);
                 var userPacks = await UsersPacksDao.GetUserPacks(user.Id);
                 userPacks.RandomCount += packsCount;
-                await MessageController.SendMessage(user, $"{Messages.effect_Random1Pack5Day} {packsCount}{Text.items}");
+                if (packsCount > 0) await MessageController.SendMessage(user, 
+                    $"{Messages.effect_Random1Pack5Day} {packsCount}{Text.items}");
             }
         }
 
@@ -40,9 +43,10 @@ namespace CardCollector.StickerEffects
                 foreach (var (sticker, count) in stickerList)
                 {
                     generatedMessage += $"\n{sticker.Title} {count}{Text.items}";
-                    await UserStickerRelationDao.AddNew(user, sticker, count);
+                    var relation = await UserStickerRelationDao.AddNew(user, sticker, count);
                 }
-                await MessageController.SendMessage(user, $"{Messages.effect_RandomSticker2Tier3Day}{generatedMessage}");
+                if (stickerList.Count > 0) await MessageController.SendMessage(user, 
+                    $"{Messages.effect_RandomSticker2Tier3Day}{generatedMessage}");
             }
         }
 
@@ -58,9 +62,10 @@ namespace CardCollector.StickerEffects
                 foreach (var (sticker, count) in stickerList)
                 {
                     generatedMessage += $"\n{sticker.Title} {count}{Text.items}";
-                    await UserStickerRelationDao.AddNew(user, sticker, count);
+                    var relation = await UserStickerRelationDao.AddNew(user, sticker, count);
                 }
-                await MessageController.SendMessage(user, $"{Messages.effect_RandomSticker1Tier3Day}{generatedMessage}");
+                if (stickerList.Count > 0) await MessageController.SendMessage(user, 
+                    $"{Messages.effect_RandomSticker1Tier3Day}{generatedMessage}");
             }
         }
     }

+ 9 - 2
CardCollector/StickerEffects/Random1Pack5Day.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Globalization;
 using System.Linq;
 using System.Threading.Tasks;
 using CardCollector.DataBase.Entity;
@@ -13,11 +14,17 @@ namespace CardCollector.StickerEffects
 
         public static async Task<int> GetPacksCount(Dictionary<string, UserStickerRelationEntity> stickers)
         {
+            var today = DateTime.Today.ToString(CultureInfo.CurrentCulture);
             var stickersWithEffect = (await StickerDao.GetListWhere(
                 item => item.Effect == (int) Effect.Random1Pack5Day)).Select(item => item.Md5Hash);
             var userStickers = stickers.Values.Where(item => stickersWithEffect.Contains(item.ShortHash));
-            return userStickers.Sum(item => (DateTime.Today - Convert.ToDateTime(item.AdditionalData)).Days >= Interval 
-                ? item.Count : 0);
+            return userStickers.Sum(item =>
+            {
+                var interval = DateTime.Today - Convert.ToDateTime(item.AdditionalData);
+                if (interval.Days < Interval) return 0;
+                item.AdditionalData = today;
+                return item.Count;
+            });
         }
     }
 }

+ 9 - 2
CardCollector/StickerEffects/RandomSticker1Tier3Day.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Globalization;
 using System.Linq;
 using System.Threading.Tasks;
 using CardCollector.DataBase.Entity;
@@ -13,11 +14,17 @@ namespace CardCollector.StickerEffects
 
         public static async Task<int> GetStickersCount(Dictionary<string, UserStickerRelationEntity> stickers)
         {
+            var today = DateTime.Today.ToString(CultureInfo.CurrentCulture);
             var stickersWithEffect = (await StickerDao.GetListWhere(
                 item => item.Effect == (int) Effect.RandomSticker1Tier3Day)).Select(item => item.Md5Hash);
             var userStickers = stickers.Values.Where(item => stickersWithEffect.Contains(item.ShortHash));
-            return userStickers.Sum(item => (DateTime.Today - Convert.ToDateTime(item.AdditionalData)).Days >= Interval 
-                ? item.Count : 0);
+            return userStickers.Sum(item =>
+            {
+                var interval = DateTime.Today - Convert.ToDateTime(item.AdditionalData);
+                if (interval.Days < Interval) return 0;
+                item.AdditionalData = today;
+                return item.Count;
+            });
         }
 
         public static async Task<Dictionary<StickerEntity, int>> GenerateList(int count)

+ 9 - 2
CardCollector/StickerEffects/RandomSticker2Tier3Day.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Globalization;
 using System.Linq;
 using System.Threading.Tasks;
 using CardCollector.DataBase.Entity;
@@ -13,11 +14,17 @@ namespace CardCollector.StickerEffects
 
         public static async Task<int> GetStickersCount(Dictionary<string, UserStickerRelationEntity> stickers)
         {
+            var today = DateTime.Today.ToString(CultureInfo.CurrentCulture);
             var stickersWithEffect = (await StickerDao.GetListWhere(
                 item => item.Effect == (int) Effect.RandomSticker2Tier3Day)).Select(item => item.Md5Hash);
             var userStickers = stickers.Values.Where(item => stickersWithEffect.Contains(item.ShortHash));
-            return userStickers.Sum(item => (DateTime.Today - Convert.ToDateTime(item.AdditionalData)).Days >= Interval 
-                ? item.Count : 0);
+            return userStickers.Sum(item =>
+            {
+                var interval = DateTime.Today - Convert.ToDateTime(item.AdditionalData);
+                if (interval.Days < Interval) return 0;
+                item.AdditionalData = today;
+                return item.Count;
+            });
         }
 
         public static async Task<Dictionary<StickerEntity, int>> GenerateList(int count)