StickerEntity.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System;
  2. using System.ComponentModel.DataAnnotations;
  3. using System.ComponentModel.DataAnnotations.Schema;
  4. using System.Globalization;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using CardCollector.Controllers;
  8. using CardCollector.Resources;
  9. using CardCollector.StickerEffects;
  10. namespace CardCollector.DataBase.Entity
  11. {
  12. /* Объект таблицы stickers (одна строка)
  13. Здесь хранится Id стикера с серверов Telegram
  14. Наименование стикера, Автор стикера, Доход в монетах,
  15. Доход в алмазах, Количество звезд, Эмоции связанные со стикером,
  16. Описание стикера
  17. */
  18. [Table("stickers")]
  19. public class StickerEntity
  20. {
  21. /* Id стикера на сервере Телеграм */
  22. [Column("id"), MaxLength(127)] public string Id { get; set; }
  23. /* Id стикера с вотермаркой */
  24. [Column("for_sale_id"), MaxLength(127)] public string ForSaleId { get; set; }
  25. /* Название стикера */
  26. [Column("title"), MaxLength(256)] public string Title { get; set; }
  27. /* Автор стикера */
  28. [Column("author"), MaxLength(128)] public string Author { get; set; }
  29. /* Доход от стикера в монетах */
  30. [Column("income"), MaxLength(32)] public int Income { get; set; } = 0;
  31. /* Время, необходимое для получения дохода */
  32. [Column("income_time"), MaxLength(32)] public int IncomeTime { get; set; } = 1;
  33. /* Количество звезд стикера (редкость) */
  34. [Column("tier"), MaxLength(32)] public int Tier { get; set; } = 1;
  35. /* Эмоции, связанные со стикером */
  36. [Column("emoji"), MaxLength(127)] public string Emoji { get; set; } = "";
  37. /* Описание стикера */
  38. [Column("description"), MaxLength(1024)] public string Description { get; set; } = "";
  39. /* Хеш id стикера для определения его в системе */
  40. [Column("md5hash"), MaxLength(40)] public string Md5Hash { get; set; }
  41. [Column("effect"), MaxLength(32)] public int Effect { get; set; }
  42. [Column("pack_id"), MaxLength(32)] public int PackId { get; set; }
  43. [NotMapped] public string IdWithWatermark => ForSaleId ?? Id;
  44. public override string ToString()
  45. {
  46. var str = $"\n{Title} {string.Concat(Enumerable.Repeat(Text.star, Tier))}" +
  47. $"\n{Text.emoji}: {Emoji}" +
  48. $"\n{Text.author}: {Author}" +
  49. $"\n{Income}{Text.coin} {IncomeTime}{Text.time}{Text.minutes}";
  50. if (Effect != 0) str += $"\n{Text.effect}: {EffectTranslations.ResourceManager.GetString(Effect.ToString())}";
  51. if (Description != "") str += $"\n\n{Text.description}: {Description}";
  52. return str;
  53. }
  54. public string ToString(int count)
  55. {
  56. var str = $"\n{Title} {string.Concat(Enumerable.Repeat(Text.star, Tier))}" +
  57. $"\n{Text.emoji}: {Emoji}" +
  58. $"\n{Text.author}: {Author}" +
  59. $"\n{Text.count}: {(count != -1 ? count : "∞")}" +
  60. $"\n{Income}{Text.coin} {IncomeTime}{Text.time}{Text.minutes}";
  61. if (Effect != 0) str += $"\n{Text.effect}: {EffectTranslations.ResourceManager.GetString(Effect.ToString())}";
  62. if (Description != "") str += $"\n\n{Text.description}: {Description}";
  63. return str;
  64. }
  65. public bool Contains(string value)
  66. {
  67. return value != ""
  68. ? Title.Contains(value, StringComparison.CurrentCultureIgnoreCase) ||
  69. Author.Contains(value, StringComparison.CurrentCultureIgnoreCase) ||
  70. Emoji.Equals(value)
  71. : true;
  72. }
  73. public async Task ApplyEffect(UserEntity user, UserStickerRelationEntity relation)
  74. {
  75. switch ((Effect)Effect)
  76. {
  77. case StickerEffects.Effect.PiggyBank200:
  78. user.Cash.MaxCapacity += 200;
  79. await MessageController.EditMessage(user, Messages.effect_PiggyBank200);
  80. break;
  81. case StickerEffects.Effect.Diamonds25Percent:
  82. user.Cash.Gems += (int)(user.Cash.Gems * 0.25);
  83. await MessageController.EditMessage(user, Messages.effect_Diamonds25Percent);
  84. break;
  85. case StickerEffects.Effect.Random1Pack5Day:
  86. relation.AdditionalData = DateTime.Today.ToString(CultureInfo.CurrentCulture);
  87. break;
  88. case StickerEffects.Effect.RandomSticker1Tier3Day:
  89. relation.AdditionalData = DateTime.Today.ToString(CultureInfo.CurrentCulture);
  90. break;
  91. case StickerEffects.Effect.RandomSticker2Tier3Day:
  92. relation.AdditionalData = DateTime.Today.ToString(CultureInfo.CurrentCulture);
  93. break;
  94. }
  95. }
  96. }
  97. }