|
@@ -62,55 +62,30 @@ namespace MafiaTelegramBot.Other
|
|
|
public async Task<ResultCode> GivePrizeTo(Player player)
|
|
|
{
|
|
|
if (!await TryDecreaseCount(player.Id)) return ResultCode.NowYouGetPrizeFromThisGiveaway;
|
|
|
- var firstPrize = _prize != Roles.All ? _prize : await GetRandomBaseRole(player.OpenedRoles);
|
|
|
- var secondPrize = _prize != Roles.All ? Roles.None : await GetRandomRole();
|
|
|
+ if (_prize is Roles.All) return await GivePackToUser(player);
|
|
|
+ var firstPrize = _prize;
|
|
|
if (player.OpenedRoles.TryOpenRole(firstPrize))
|
|
|
{
|
|
|
await Bot.SendStickerAsync(player.ChatId, Stickers.Sticker[firstPrize.ToString()]);
|
|
|
await Bot.SendWithMarkdown2(player.ChatId,$"{strings.congratulations_you_open_role} {roles.ResourceManager.GetString(firstPrize.ToString())}");
|
|
|
}
|
|
|
else await Bot.SendWithMarkdown2(player.ChatId,$"{strings.you_got_role} {roles.ResourceManager.GetString(firstPrize.ToString())} ({strings.now_opened})");
|
|
|
- if (secondPrize != Roles.None && player.OpenedRoles.TryOpenRole(secondPrize))
|
|
|
- {
|
|
|
- await Bot.SendStickerAsync(player.ChatId, Stickers.Sticker[secondPrize.ToString()]);
|
|
|
- await Bot.SendWithMarkdown2(player.ChatId,$"{strings.congratulations_you_additionally_open_role} {roles.ResourceManager.GetString(secondPrize.ToString())}");
|
|
|
- }
|
|
|
- else if(secondPrize != Roles.None) await Bot.SendWithMarkdown2(player.ChatId,$"{strings.you_additionally_got_role} {roles.ResourceManager.GetString(secondPrize.ToString())} ({strings.now_opened})");
|
|
|
return ResultCode.CodeOk;
|
|
|
}
|
|
|
|
|
|
- private Task<Roles> GetRandomBaseRole(OpenedRolesEntity openedRoles)
|
|
|
- {
|
|
|
- return Task.Run(() =>
|
|
|
- {
|
|
|
- var allOpened = openedRoles.Hooker && openedRoles.Bodyguard && openedRoles.Elder && openedRoles.Werewolf;
|
|
|
- if (allOpened)
|
|
|
- return Utilities.TierDictionary[2][Utilities.Rnd.Next(Utilities.TierDictionary[2].Count)];
|
|
|
- var notOpened = Utilities.TierDictionary[2].Except(openedRoles.ToList()).ToArray();
|
|
|
- return notOpened[Utilities.Rnd.Next(notOpened.Length)];
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- private Task<Roles> GetRandomRole()
|
|
|
+ private static async Task<ResultCode> GivePackToUser(Player player)
|
|
|
{
|
|
|
- return Task.Run(() =>
|
|
|
- {
|
|
|
- var chance = Utilities.Rnd.Next(100);
|
|
|
- return chance switch
|
|
|
- {
|
|
|
- <1 => Utilities.TierDictionary[5][Utilities.Rnd.Next(Utilities.TierDictionary[5].Count)],
|
|
|
- <5 => Utilities.TierDictionary[4][Utilities.Rnd.Next(Utilities.TierDictionary[4].Count)],
|
|
|
- <25 => Utilities.TierDictionary[3][Utilities.Rnd.Next(Utilities.TierDictionary[3].Count)],
|
|
|
- _ => Roles.None
|
|
|
- };
|
|
|
- });
|
|
|
+ player.User.PackCount++;
|
|
|
+ await Bot.SendStickerAsync(player.ChatId, Stickers.Sticker["Pool"]);
|
|
|
+ await Bot.SendWithMarkdown2(player.ChatId, $"{strings.your_packs} {player.User.PackCount}", Keyboard.PackKeyboard(player.Id));
|
|
|
+ return ResultCode.CodeOk;
|
|
|
}
|
|
|
|
|
|
private async Task UpdateGiveAwayMessageOrDelete()
|
|
|
{
|
|
|
if (_count == 0)
|
|
|
{
|
|
|
- await Bot.Get().DeleteMessageAsync(_chatId, _messageId);
|
|
|
+ await Bot.Get().EditMessageTextAsync(_chatId, _messageId, strings.giveaway_ended);
|
|
|
OpenedGiveaways.Remove(_id);
|
|
|
_awardedIdList.Clear();
|
|
|
}
|