ソースを参照

Combining stickers complete

Tigran 4 年 前
コミット
303c227f27

+ 2 - 2
CardCollector.sln.DotSettings.user

@@ -1,11 +1,11 @@
 <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
 	
-	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=CardCollector_002FResources_002FCommand/@EntryIndexedValue">True</s:Boolean>
+	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=CardCollector_002FResources_002FCommand/@EntryIndexedValue">False</s:Boolean>
 	
 	
 	
 	
-	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=CardCollector_002FResources_002FMessages/@EntryIndexedValue">False</s:Boolean>
+	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=CardCollector_002FResources_002FMessages/@EntryIndexedValue">True</s:Boolean>
 	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=CardCollector_002FResources_002FSortingTypes/@EntryIndexedValue">False</s:Boolean>
 	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=CardCollector_002FResources_002FText/@EntryIndexedValue">False</s:Boolean>
 	

+ 30 - 2
CardCollector/Commands/CallbackQuery/CombineStickers.cs

@@ -1,5 +1,9 @@
-using System.Threading.Tasks;
+using System;
+using System.Linq;
+using System.Threading.Tasks;
+using CardCollector.Controllers;
 using CardCollector.DataBase.Entity;
+using CardCollector.DataBase.EntityDao;
 using CardCollector.Resources;
 using Telegram.Bot.Types;
 
@@ -10,7 +14,31 @@ namespace CardCollector.Commands.CallbackQuery
         protected override string CommandText => Command.combine_stickers;
         public override async Task Execute()
         {
-            
+            if (User.Cash.Coins < User.Session.CombineCoinsPrice)
+                await MessageController.AnswerCallbackQuery(User, CallbackQueryId, Messages.not_enougth_coins);
+            else if (User.Cash.Gems < User.Session.CombineGemsPrice)
+                await MessageController.AnswerCallbackQuery(User, CallbackQueryId, Messages.not_enougth_gems);
+            else
+            {
+                await User.ClearChat();
+                
+                User.Cash.Coins -= User.Session.CombineCoinsPrice;
+                User.Cash.Gems -= User.Session.CombineGemsPrice;
+                foreach (var item in User.Session.CombineList.Values)
+                    User.Stickers[item.Md5Hash].Count -= item.Count;
+                var authors = User.Session.CombineList.Values.Select(i => i.Author).ToList();
+                var tier = User.Session.CombineList.Values.First().Tier;
+                var rnd = new Random();
+                var author = authors[rnd.Next(authors.Count)];
+                var stickers = await StickerDao.GetListWhere(i => i.Author == author && i.Tier == tier + 1);
+                var sticker = stickers[rnd.Next(stickers.Count)];
+                await UserStickerRelationDao.AddNew(User, sticker, 1);
+                var text = $"{Messages.combined_sticker}:\n" + sticker;
+                var stickerMessage = await MessageController.SendSticker(User, sticker.Id);
+                var message = await MessageController.SendMessage(User, text, Keyboard.BackToFilters(sticker.Title));
+                User.Session.Messages.Add(stickerMessage.MessageId);
+                User.Session.Messages.Add(message.MessageId);
+            }
         }
 
         public CombineStickers() { }

+ 12 - 0
CardCollector/DataBase/Entity/StickerEntity.cs

@@ -1,5 +1,7 @@
 using System.ComponentModel.DataAnnotations;
 using System.ComponentModel.DataAnnotations.Schema;
+using System.Linq;
+using CardCollector.Resources;
 
 namespace CardCollector.DataBase.Entity
 {
@@ -47,5 +49,15 @@ namespace CardCollector.DataBase.Entity
         
         /* Хеш id стикера для определения его в системе */
         [Column("md5hash"), MaxLength(40)] public string Md5Hash { get; set; }
+
+        public override string ToString()
+        {
+            var str = $"\n{Title} {string.Concat(Enumerable.Repeat(Text.star, Tier))}" +
+                             $"\n{Text.emoji}: {Emoji}" +
+                             $"\n{Text.author}: {Author}" +
+                             $"\n{IncomeCoins}{Text.coin} / {IncomeGems}{Text.gem} {IncomeTime}{Text.time}{Text.minutes}";
+            if (Description != "") str += $"\n\n{Text.description}: {Description}";
+            return str;
+        }
     }
 }

+ 5 - 0
CardCollector/DataBase/EntityDao/StickerDao.cs

@@ -64,5 +64,10 @@ namespace CardCollector.DataBase.EntityDao
         {
             await Table.AddAsync(sticker);
         }
+
+        public static async Task<List<StickerEntity>> GetListWhere(Func<StickerEntity, bool> func)
+        {
+            return (await Table.ToListAsync()).Where(func).ToList();
+        }
     }
 }

+ 12 - 0
CardCollector/Others/Session.cs

@@ -68,6 +68,18 @@ namespace CardCollector.Others
             Messages.Clear();
         }
 
+        public int CombineCoinsPrice = 0;
+        public int CombineGemsPrice = 0;
+
+        public void CalculateCombinePrice()
+        {
+            var coinsSum = CombineList.Values.Sum(i => 1440 / i.IncomeTime * i.IncomeCoins);
+            var gemsSum = CombineList.Values.Sum(i => 1440 / i.IncomeTime * i.IncomeGems);
+            var multiplier = SelectedSticker.Tier * 0.25 + 1;
+            CombineCoinsPrice = (int)(coinsSum * multiplier);
+            CombineGemsPrice = (int)(gemsSum * multiplier);
+        }
+
         public async Task CalculateIncome()
         {
             IncomeCoins = 0;

+ 17 - 3
CardCollector/Resources/Keyboard.cs

@@ -17,6 +17,15 @@ namespace CardCollector.Resources
             new KeyboardButton[] {Text.shop, Text.auction},
         }) {ResizeKeyboard = true};
 
+        public static InlineKeyboardMarkup BackToFilters(string stickerTitle)
+        {
+            return new InlineKeyboardMarkup(new[]
+            {
+                new[] {InlineKeyboardButton.WithSwitchInlineQuery(Text.send_sticker, stickerTitle)},
+                new[] {InlineKeyboardButton.WithCallbackData(Text.back, $"{Command.back}={Command.clear_chat}")}
+            });
+        }
+
         public static InlineKeyboardMarkup GetSortingMenu(UserState state)
         {
             var keyboard = new List<InlineKeyboardButton[]>
@@ -293,9 +302,14 @@ namespace CardCollector.Resources
                     $"{Command.delete_combine}={id}")});
             }
             keyboard.Add(new []{InlineKeyboardButton.WithCallbackData(Text.cancel, Command.back)});
-            keyboard.Add(session.GetCombineCount() == Constants.COMBINE_COUNT
-                ? new[] {InlineKeyboardButton.WithCallbackData(Text.combine, Command.combine_stickers)}
-                : new[] {InlineKeyboardButton.WithSwitchInlineQueryCurrentChat(Text.add_sticker)});
+            if (session.GetCombineCount() == Constants.COMBINE_COUNT)
+            {
+                session.CalculateCombinePrice();
+                keyboard.Add(new[] {InlineKeyboardButton.WithCallbackData(
+                    $"{Text.combine} {session.CombineCoinsPrice}{Text.coin}/{session.CombineGemsPrice}{Text.gem}", 
+                    Command.combine_stickers)});
+            }
+            else keyboard.Add(new[] {InlineKeyboardButton.WithSwitchInlineQueryCurrentChat(Text.add_sticker)});
             return new InlineKeyboardMarkup(keyboard);
         }
 

+ 9 - 0
CardCollector/Resources/Messages.Designer.cs

@@ -168,6 +168,15 @@ namespace CardCollector.Resources {
             }
         }
         
+        /// <summary>
+        ///   Looks up a localized string similar to Поздравляем! Вы получили стикер.
+        /// </summary>
+        internal static string combined_sticker {
+            get {
+                return ResourceManager.GetString("combined_sticker", resourceCulture);
+            }
+        }
+        
         /// <summary>
         ///   Looks up a localized string similar to Подтвердите покупку:.
         /// </summary>

+ 3 - 0
CardCollector/Resources/Messages.resx

@@ -135,4 +135,7 @@
     <data name="combine_added_only" xml:space="preserve">
         <value>Не удалось добавить все стикеры. Было добавлено только</value>
     </data>
+    <data name="combined_sticker" xml:space="preserve">
+        <value>Поздравляем! Вы получили стикер</value>
+    </data>
 </root>