2016-07-29 11:06:24 +00:00
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.Commands;
|
2016-12-17 00:16:14 +00:00
|
|
|
|
using Discord.WebSocket;
|
2016-08-20 15:02:33 +00:00
|
|
|
|
using NadekoBot.Attributes;
|
2016-07-29 11:06:24 +00:00
|
|
|
|
using NadekoBot.Extensions;
|
2016-08-28 00:46:36 +00:00
|
|
|
|
using NadekoBot.Services;
|
2017-05-24 20:28:16 +00:00
|
|
|
|
using NadekoBot.Services.Database.Models;
|
2016-10-05 05:01:19 +00:00
|
|
|
|
using NLog;
|
2016-07-25 02:21:37 +00:00
|
|
|
|
using System;
|
2016-07-29 11:06:24 +00:00
|
|
|
|
using System.Collections.Concurrent;
|
2016-07-25 02:21:37 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
2016-07-29 11:06:24 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2016-07-25 02:21:37 +00:00
|
|
|
|
|
2016-08-20 20:35:27 +00:00
|
|
|
|
namespace NadekoBot.Modules.Gambling
|
2016-07-25 02:21:37 +00:00
|
|
|
|
{
|
2016-08-20 15:02:33 +00:00
|
|
|
|
public partial class Gambling
|
2016-07-25 02:21:37 +00:00
|
|
|
|
{
|
2016-08-20 15:02:33 +00:00
|
|
|
|
[Group]
|
2017-02-14 13:30:21 +00:00
|
|
|
|
public class AnimalRacing : NadekoSubmodule
|
2016-07-25 02:21:37 +00:00
|
|
|
|
{
|
2017-05-24 20:28:16 +00:00
|
|
|
|
private readonly BotConfig _bc;
|
2017-05-29 04:13:22 +00:00
|
|
|
|
private readonly CurrencyService _cs;
|
2017-05-24 20:28:16 +00:00
|
|
|
|
private readonly DiscordShardedClient _client;
|
|
|
|
|
|
|
|
|
|
|
2016-12-08 17:35:34 +00:00
|
|
|
|
public static ConcurrentDictionary<ulong, AnimalRace> AnimalRaces { get; } = new ConcurrentDictionary<ulong, AnimalRace>();
|
2016-07-25 02:21:37 +00:00
|
|
|
|
|
2017-05-29 04:13:22 +00:00
|
|
|
|
public AnimalRacing(BotConfig bc, CurrencyService cs, DiscordShardedClient client)
|
2017-05-24 20:28:16 +00:00
|
|
|
|
{
|
|
|
|
|
_bc = bc;
|
2017-05-29 04:13:22 +00:00
|
|
|
|
_cs = cs;
|
2017-05-24 20:28:16 +00:00
|
|
|
|
_client = client;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-20 15:02:33 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
public async Task Race()
|
2016-08-20 15:02:33 +00:00
|
|
|
|
{
|
2017-05-24 20:28:16 +00:00
|
|
|
|
var ar = new AnimalRace(Context.Guild.Id, (ITextChannel)Context.Channel, Prefix,
|
2017-05-29 04:13:22 +00:00
|
|
|
|
_bc, _cs, _client,_localization, _strings);
|
2016-07-25 02:21:37 +00:00
|
|
|
|
|
2016-08-20 15:02:33 +00:00
|
|
|
|
if (ar.Fail)
|
2017-02-18 20:07:36 +00:00
|
|
|
|
await ReplyErrorLocalized("race_failed_starting").ConfigureAwait(false);
|
2016-08-20 15:02:33 +00:00
|
|
|
|
}
|
2016-07-25 02:21:37 +00:00
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-20 15:02:33 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-21 08:33:47 +00:00
|
|
|
|
public async Task JoinRace(int amount = 0)
|
2016-08-20 15:02:33 +00:00
|
|
|
|
{
|
2016-07-25 23:00:55 +00:00
|
|
|
|
|
2016-08-20 15:02:33 +00:00
|
|
|
|
if (amount < 0)
|
|
|
|
|
amount = 0;
|
2016-07-25 23:00:55 +00:00
|
|
|
|
|
2016-07-29 11:06:24 +00:00
|
|
|
|
|
2016-08-20 15:02:33 +00:00
|
|
|
|
AnimalRace ar;
|
2016-12-16 21:44:26 +00:00
|
|
|
|
if (!AnimalRaces.TryGetValue(Context.Guild.Id, out ar))
|
2016-08-20 15:02:33 +00:00
|
|
|
|
{
|
2017-02-18 20:07:36 +00:00
|
|
|
|
await ReplyErrorLocalized("race_not_exist").ConfigureAwait(false);
|
2016-08-20 15:02:33 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2016-12-16 18:43:57 +00:00
|
|
|
|
await ar.JoinRace(Context.User as IGuildUser, amount);
|
2016-08-20 15:02:33 +00:00
|
|
|
|
}
|
2016-07-25 02:21:37 +00:00
|
|
|
|
|
2017-05-29 04:13:22 +00:00
|
|
|
|
//todo 85 needs to be completely isolated, shouldn't use any services in the constructor,
|
2017-05-24 20:28:16 +00:00
|
|
|
|
//then move the rest either to the module itself, or the service
|
2016-08-20 15:02:33 +00:00
|
|
|
|
public class AnimalRace
|
|
|
|
|
{
|
2016-07-25 02:21:37 +00:00
|
|
|
|
|
2016-08-28 00:46:36 +00:00
|
|
|
|
private ConcurrentQueue<string> animals { get; }
|
2016-07-25 02:21:37 +00:00
|
|
|
|
|
2016-09-01 01:12:08 +00:00
|
|
|
|
public bool Fail { get; set; }
|
2016-07-25 02:21:37 +00:00
|
|
|
|
|
2017-02-18 20:07:36 +00:00
|
|
|
|
private readonly List<Participant> _participants = new List<Participant>();
|
|
|
|
|
private readonly ulong _serverId;
|
|
|
|
|
private int _messagesSinceGameStarted;
|
2017-02-14 13:30:21 +00:00
|
|
|
|
private readonly string _prefix;
|
|
|
|
|
|
2017-02-18 20:07:36 +00:00
|
|
|
|
private readonly Logger _log;
|
2016-07-25 02:21:37 +00:00
|
|
|
|
|
2017-02-18 20:07:36 +00:00
|
|
|
|
private readonly ITextChannel _raceChannel;
|
2017-05-24 20:28:16 +00:00
|
|
|
|
private readonly BotConfig _bc;
|
2017-05-29 04:13:22 +00:00
|
|
|
|
private readonly CurrencyService _cs;
|
2017-05-24 20:28:16 +00:00
|
|
|
|
private readonly DiscordShardedClient _client;
|
|
|
|
|
private readonly ILocalization _localization;
|
|
|
|
|
private readonly NadekoStrings _strings;
|
|
|
|
|
|
2017-02-18 20:07:36 +00:00
|
|
|
|
public bool Started { get; private set; }
|
2016-07-25 02:21:37 +00:00
|
|
|
|
|
2017-05-24 20:28:16 +00:00
|
|
|
|
public AnimalRace(ulong serverId, ITextChannel channel, string prefix, BotConfig bc,
|
2017-05-29 04:13:22 +00:00
|
|
|
|
CurrencyService cs, DiscordShardedClient client, ILocalization localization,
|
2017-05-24 20:28:16 +00:00
|
|
|
|
NadekoStrings strings)
|
2016-07-25 02:21:37 +00:00
|
|
|
|
{
|
2017-02-18 20:07:36 +00:00
|
|
|
|
_prefix = prefix;
|
2017-05-24 20:28:16 +00:00
|
|
|
|
_bc = bc;
|
2017-05-29 04:13:22 +00:00
|
|
|
|
_cs = cs;
|
2017-02-18 20:07:36 +00:00
|
|
|
|
_log = LogManager.GetCurrentClassLogger();
|
|
|
|
|
_serverId = serverId;
|
2017-05-24 20:28:16 +00:00
|
|
|
|
_raceChannel = channel;
|
|
|
|
|
_client = client;
|
|
|
|
|
_localization = localization;
|
|
|
|
|
_strings = strings;
|
|
|
|
|
|
2016-08-20 15:02:33 +00:00
|
|
|
|
if (!AnimalRaces.TryAdd(serverId, this))
|
2016-07-25 02:21:37 +00:00
|
|
|
|
{
|
2016-08-20 15:02:33 +00:00
|
|
|
|
Fail = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-02-14 13:30:21 +00:00
|
|
|
|
|
2017-05-24 20:28:16 +00:00
|
|
|
|
animals = new ConcurrentQueue<string>(_bc.RaceAnimals.Select(ra => ra.Icon).Shuffle());
|
2016-08-28 00:46:36 +00:00
|
|
|
|
|
|
|
|
|
|
2016-08-20 15:02:33 +00:00
|
|
|
|
var cancelSource = new CancellationTokenSource();
|
|
|
|
|
var token = cancelSource.Token;
|
|
|
|
|
var fullgame = CheckForFullGameAsync(token);
|
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
try
|
2016-07-25 23:32:40 +00:00
|
|
|
|
{
|
2016-12-25 12:35:59 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-02-18 20:07:36 +00:00
|
|
|
|
await _raceChannel.SendConfirmAsync(GetText("animal_race"), GetText("animal_race_starting"),
|
|
|
|
|
footer: GetText("animal_race_join_instr", _prefix));
|
2016-12-25 12:35:59 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_log.Warn(ex);
|
|
|
|
|
}
|
2016-08-20 15:02:33 +00:00
|
|
|
|
var t = await Task.WhenAny(Task.Delay(20000, token), fullgame);
|
|
|
|
|
Started = true;
|
|
|
|
|
cancelSource.Cancel();
|
|
|
|
|
if (t == fullgame)
|
|
|
|
|
{
|
2017-02-18 20:07:36 +00:00
|
|
|
|
try { await _raceChannel.SendConfirmAsync(GetText("animal_race"), GetText("animal_race_full") ); } catch (Exception ex) { _log.Warn(ex); }
|
2016-08-20 15:02:33 +00:00
|
|
|
|
}
|
2017-02-18 20:07:36 +00:00
|
|
|
|
else if (_participants.Count > 1)
|
2016-08-20 15:02:33 +00:00
|
|
|
|
{
|
2017-02-18 20:07:36 +00:00
|
|
|
|
try { await _raceChannel.SendConfirmAsync(GetText("animal_race"), GetText("animal_race_starting_with_x", _participants.Count)); } catch (Exception ex) { _log.Warn(ex); }
|
2016-08-20 15:02:33 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-02-18 20:07:36 +00:00
|
|
|
|
try { await _raceChannel.SendErrorAsync(GetText("animal_race"), GetText("animal_race_failed")); } catch (Exception ex) { _log.Warn(ex); }
|
|
|
|
|
var p = _participants.FirstOrDefault();
|
2016-10-05 05:01:19 +00:00
|
|
|
|
|
2016-11-15 00:06:07 +00:00
|
|
|
|
if (p != null && p.AmountBet > 0)
|
2017-05-29 04:13:22 +00:00
|
|
|
|
await _cs.AddAsync(p.User, "BetRace", p.AmountBet, false).ConfigureAwait(false);
|
2016-08-20 15:02:33 +00:00
|
|
|
|
End();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
await Task.Run(StartRace);
|
2016-07-25 23:32:40 +00:00
|
|
|
|
End();
|
|
|
|
|
}
|
2016-12-08 17:35:34 +00:00
|
|
|
|
catch { try { End(); } catch { } }
|
2016-08-20 15:02:33 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
2016-07-25 02:21:37 +00:00
|
|
|
|
|
2016-08-20 15:02:33 +00:00
|
|
|
|
private void End()
|
2016-07-25 02:21:37 +00:00
|
|
|
|
{
|
2016-08-20 15:02:33 +00:00
|
|
|
|
AnimalRace throwaway;
|
2017-02-18 20:07:36 +00:00
|
|
|
|
AnimalRaces.TryRemove(_serverId, out throwaway);
|
2016-08-20 15:02:33 +00:00
|
|
|
|
}
|
2016-07-25 02:21:37 +00:00
|
|
|
|
|
2016-08-20 15:02:33 +00:00
|
|
|
|
private async Task StartRace()
|
|
|
|
|
{
|
2016-09-10 19:40:25 +00:00
|
|
|
|
var rng = new NadekoRandom();
|
2016-08-20 15:02:33 +00:00
|
|
|
|
Participant winner = null;
|
2016-08-28 02:33:09 +00:00
|
|
|
|
IUserMessage msg = null;
|
2017-02-18 20:07:36 +00:00
|
|
|
|
var place = 1;
|
2016-08-20 15:02:33 +00:00
|
|
|
|
try
|
2016-07-25 02:21:37 +00:00
|
|
|
|
{
|
2017-05-24 20:28:16 +00:00
|
|
|
|
_client.MessageReceived += Client_MessageReceived;
|
2016-07-25 02:21:37 +00:00
|
|
|
|
|
2017-02-18 20:07:36 +00:00
|
|
|
|
while (!_participants.All(p => p.Total >= 60))
|
2016-08-20 15:02:33 +00:00
|
|
|
|
{
|
|
|
|
|
//update the state
|
2017-02-18 20:07:36 +00:00
|
|
|
|
_participants.ForEach(p =>
|
2016-07-25 02:21:37 +00:00
|
|
|
|
{
|
2016-08-20 15:02:33 +00:00
|
|
|
|
p.Total += 1 + rng.Next(0, 10);
|
2016-12-25 12:35:59 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2017-02-18 20:07:36 +00:00
|
|
|
|
_participants
|
2016-12-25 12:35:59 +00:00
|
|
|
|
.OrderByDescending(p => p.Total)
|
|
|
|
|
.ForEach(p =>
|
2016-07-25 02:21:37 +00:00
|
|
|
|
{
|
2016-12-25 12:35:59 +00:00
|
|
|
|
if (p.Total > 60)
|
2016-08-20 15:02:33 +00:00
|
|
|
|
{
|
2016-12-25 12:35:59 +00:00
|
|
|
|
if (winner == null)
|
|
|
|
|
{
|
|
|
|
|
winner = p;
|
|
|
|
|
}
|
|
|
|
|
p.Total = 60;
|
|
|
|
|
if (p.Place == 0)
|
|
|
|
|
p.Place = place++;
|
2016-08-20 15:02:33 +00:00
|
|
|
|
}
|
2016-12-25 12:35:59 +00:00
|
|
|
|
});
|
2016-07-25 02:21:37 +00:00
|
|
|
|
|
|
|
|
|
|
2016-08-20 15:02:33 +00:00
|
|
|
|
//draw the state
|
2016-07-25 02:21:37 +00:00
|
|
|
|
|
2016-08-20 15:02:33 +00:00
|
|
|
|
var text = $@"|🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🔚|
|
2017-02-18 20:07:36 +00:00
|
|
|
|
{String.Join("\n", _participants.Select(p => $"{(int)(p.Total / 60f * 100),-2}%|{p.ToString()}"))}
|
2016-07-25 02:21:37 +00:00
|
|
|
|
|🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🔚|";
|
2017-02-18 20:07:36 +00:00
|
|
|
|
if (msg == null || _messagesSinceGameStarted >= 10) // also resend the message if channel was spammed
|
2016-08-20 15:02:33 +00:00
|
|
|
|
{
|
|
|
|
|
if (msg != null)
|
|
|
|
|
try { await msg.DeleteAsync(); } catch { }
|
2017-02-18 20:07:36 +00:00
|
|
|
|
_messagesSinceGameStarted = 0;
|
|
|
|
|
try { msg = await _raceChannel.SendMessageAsync(text).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
|
2016-08-20 15:02:33 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2016-10-05 05:01:19 +00:00
|
|
|
|
{
|
|
|
|
|
try { await msg.ModifyAsync(m => m.Content = text).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
|
|
|
|
|
}
|
2016-08-20 15:02:33 +00:00
|
|
|
|
|
|
|
|
|
await Task.Delay(2500);
|
2016-07-25 02:21:37 +00:00
|
|
|
|
}
|
2016-08-20 15:02:33 +00:00
|
|
|
|
}
|
2017-02-18 20:07:36 +00:00
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
2016-08-20 15:02:33 +00:00
|
|
|
|
finally
|
|
|
|
|
{
|
2017-05-24 20:28:16 +00:00
|
|
|
|
_client.MessageReceived -= Client_MessageReceived;
|
2016-08-20 15:02:33 +00:00
|
|
|
|
}
|
2016-07-29 11:06:24 +00:00
|
|
|
|
|
2017-02-18 20:07:36 +00:00
|
|
|
|
if (winner != null)
|
2016-08-20 15:02:33 +00:00
|
|
|
|
{
|
2017-02-18 20:07:36 +00:00
|
|
|
|
if (winner.AmountBet > 0)
|
|
|
|
|
{
|
|
|
|
|
var wonAmount = winner.AmountBet * (_participants.Count - 1);
|
|
|
|
|
|
2017-05-29 04:13:22 +00:00
|
|
|
|
await _cs.AddAsync(winner.User, "Won a Race", wonAmount, true)
|
2017-02-18 20:07:36 +00:00
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
await _raceChannel.SendConfirmAsync(GetText("animal_race"),
|
|
|
|
|
Format.Bold(GetText("animal_race_won_money", winner.User.Mention,
|
2017-05-24 20:28:16 +00:00
|
|
|
|
winner.Animal, wonAmount + _bc.CurrencySign)))
|
2017-02-18 20:07:36 +00:00
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await _raceChannel.SendConfirmAsync(GetText("animal_race"),
|
|
|
|
|
Format.Bold(GetText("animal_race_won", winner.User.Mention, winner.Animal))).ConfigureAwait(false);
|
|
|
|
|
}
|
2016-07-25 02:21:37 +00:00
|
|
|
|
}
|
2016-07-25 23:00:55 +00:00
|
|
|
|
|
|
|
|
|
}
|
2016-07-25 02:21:37 +00:00
|
|
|
|
|
2017-01-15 01:28:33 +00:00
|
|
|
|
private Task Client_MessageReceived(SocketMessage imsg)
|
2016-07-25 02:21:37 +00:00
|
|
|
|
{
|
2017-06-15 23:55:14 +00:00
|
|
|
|
var _ = Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
var msg = imsg as SocketUserMessage;
|
|
|
|
|
if (msg == null)
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
if ((msg.Author.Id == _client.CurrentUser.Id) || !(imsg.Channel is ITextChannel) || imsg.Channel != _raceChannel)
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
Interlocked.Increment(ref _messagesSinceGameStarted);
|
2017-01-15 01:28:33 +00:00
|
|
|
|
return Task.CompletedTask;
|
2017-06-15 23:55:14 +00:00
|
|
|
|
});
|
2017-01-15 01:28:33 +00:00
|
|
|
|
return Task.CompletedTask;
|
2016-07-25 02:21:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-20 15:02:33 +00:00
|
|
|
|
private async Task CheckForFullGameAsync(CancellationToken cancelToken)
|
2016-07-25 02:21:37 +00:00
|
|
|
|
{
|
2016-08-20 15:02:33 +00:00
|
|
|
|
while (animals.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay(100, cancelToken);
|
|
|
|
|
}
|
2016-07-25 02:21:37 +00:00
|
|
|
|
}
|
2016-08-20 15:02:33 +00:00
|
|
|
|
|
2016-10-26 16:17:40 +00:00
|
|
|
|
public async Task JoinRace(IGuildUser u, int amount = 0)
|
2016-07-25 02:21:37 +00:00
|
|
|
|
{
|
2017-02-18 20:07:36 +00:00
|
|
|
|
string animal;
|
2016-08-20 15:02:33 +00:00
|
|
|
|
if (!animals.TryDequeue(out animal))
|
|
|
|
|
{
|
2017-02-18 20:07:36 +00:00
|
|
|
|
await _raceChannel.SendErrorAsync(GetText("animal_race_no_race")).ConfigureAwait(false);
|
2016-10-26 16:17:40 +00:00
|
|
|
|
return;
|
2016-08-20 15:02:33 +00:00
|
|
|
|
}
|
|
|
|
|
var p = new Participant(u, animal, amount);
|
2017-02-18 20:07:36 +00:00
|
|
|
|
if (_participants.Contains(p))
|
2016-08-20 15:02:33 +00:00
|
|
|
|
{
|
2017-02-18 20:07:36 +00:00
|
|
|
|
await _raceChannel.SendErrorAsync(GetText("animal_race_already_in")).ConfigureAwait(false);
|
2016-10-26 16:17:40 +00:00
|
|
|
|
return;
|
2016-08-20 15:02:33 +00:00
|
|
|
|
}
|
|
|
|
|
if (Started)
|
|
|
|
|
{
|
2017-02-18 20:07:36 +00:00
|
|
|
|
await _raceChannel.SendErrorAsync(GetText("animal_race_already_started")).ConfigureAwait(false);
|
2016-10-26 16:17:40 +00:00
|
|
|
|
return;
|
2016-08-20 15:02:33 +00:00
|
|
|
|
}
|
2016-10-26 16:17:40 +00:00
|
|
|
|
if (amount > 0)
|
2017-05-29 04:13:22 +00:00
|
|
|
|
if (!await _cs.RemoveAsync(u, "BetRace", amount, false).ConfigureAwait(false))
|
2016-10-26 16:17:40 +00:00
|
|
|
|
{
|
2017-05-24 20:28:16 +00:00
|
|
|
|
await _raceChannel.SendErrorAsync(GetText("not_enough", _bc.CurrencySign)).ConfigureAwait(false);
|
2016-10-26 16:17:40 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-02-18 20:07:36 +00:00
|
|
|
|
_participants.Add(p);
|
|
|
|
|
string confStr;
|
|
|
|
|
if (amount > 0)
|
2017-05-24 20:28:16 +00:00
|
|
|
|
confStr = GetText("animal_race_join_bet", u.Mention, p.Animal, amount + _bc.CurrencySign);
|
2017-02-18 20:07:36 +00:00
|
|
|
|
else
|
|
|
|
|
confStr = GetText("animal_race_join", u.Mention, p.Animal);
|
|
|
|
|
await _raceChannel.SendConfirmAsync(GetText("animal_race"), Format.Bold(confStr)).ConfigureAwait(false);
|
2016-07-25 02:21:37 +00:00
|
|
|
|
}
|
2017-02-18 20:07:36 +00:00
|
|
|
|
|
|
|
|
|
private string GetText(string text)
|
2017-05-24 20:28:16 +00:00
|
|
|
|
=> _strings.GetText(text,
|
|
|
|
|
_localization.GetCultureInfo(_raceChannel.Guild),
|
2017-02-18 20:07:36 +00:00
|
|
|
|
typeof(Gambling).Name.ToLowerInvariant());
|
|
|
|
|
|
|
|
|
|
private string GetText(string text, params object[] replacements)
|
2017-05-24 20:28:16 +00:00
|
|
|
|
=> _strings.GetText(text,
|
|
|
|
|
_localization.GetCultureInfo(_raceChannel.Guild),
|
2017-02-18 20:07:36 +00:00
|
|
|
|
typeof(Gambling).Name.ToLowerInvariant(),
|
|
|
|
|
replacements);
|
2016-07-25 02:21:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-20 15:02:33 +00:00
|
|
|
|
public class Participant
|
2016-07-25 02:21:37 +00:00
|
|
|
|
{
|
2017-02-18 20:07:36 +00:00
|
|
|
|
public IGuildUser User { get; }
|
|
|
|
|
public string Animal { get; }
|
|
|
|
|
public int AmountBet { get; }
|
2016-07-25 02:21:37 +00:00
|
|
|
|
|
2016-08-20 15:02:33 +00:00
|
|
|
|
public float Coeff { get; set; }
|
|
|
|
|
public int Total { get; set; }
|
2016-07-25 02:21:37 +00:00
|
|
|
|
|
2017-02-18 20:07:36 +00:00
|
|
|
|
public int Place { get; set; }
|
2016-07-25 02:21:37 +00:00
|
|
|
|
|
2016-08-20 15:02:33 +00:00
|
|
|
|
public Participant(IGuildUser u, string a, int amount)
|
2016-07-25 02:21:37 +00:00
|
|
|
|
{
|
2017-02-18 20:07:36 +00:00
|
|
|
|
User = u;
|
|
|
|
|
Animal = a;
|
|
|
|
|
AmountBet = amount;
|
2016-07-25 02:21:37 +00:00
|
|
|
|
}
|
2016-08-20 15:02:33 +00:00
|
|
|
|
|
2016-12-28 05:31:39 +00:00
|
|
|
|
public override int GetHashCode() => User.GetHashCode();
|
2016-08-20 15:02:33 +00:00
|
|
|
|
|
|
|
|
|
public override bool Equals(object obj)
|
2016-07-25 02:21:37 +00:00
|
|
|
|
{
|
2016-08-20 15:02:33 +00:00
|
|
|
|
var p = obj as Participant;
|
2017-02-14 13:30:21 +00:00
|
|
|
|
return p != null && p.User == User;
|
2016-07-25 02:21:37 +00:00
|
|
|
|
}
|
2016-08-20 15:02:33 +00:00
|
|
|
|
|
|
|
|
|
public override string ToString()
|
2016-07-29 11:06:24 +00:00
|
|
|
|
{
|
2016-08-20 15:02:33 +00:00
|
|
|
|
var str = new string('‣', Total) + Animal;
|
|
|
|
|
if (Place == 0)
|
|
|
|
|
return str;
|
2017-02-18 20:07:36 +00:00
|
|
|
|
|
|
|
|
|
str += $"`#{Place}`";
|
|
|
|
|
|
2016-08-20 15:02:33 +00:00
|
|
|
|
if (Place == 1)
|
2017-02-18 20:07:36 +00:00
|
|
|
|
str += "🏆";
|
2016-07-25 02:21:37 +00:00
|
|
|
|
|
2017-02-18 20:07:36 +00:00
|
|
|
|
return str;
|
2016-08-20 15:02:33 +00:00
|
|
|
|
}
|
2016-07-25 02:21:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-20 15:02:33 +00:00
|
|
|
|
}
|