public CubeDraftManager(ref MainDbContext db, CubeDraft draft) { Players = new List <Drafter>(); _db = db; _draft = draft; if (_draft == null) { throw new ArgumentNullException("draft", "Draft cannot be null"); } switch (_draft.Status) { case CubeDraftStatus.PreStart: StartDraft(); break; case CubeDraftStatus.Drafting: Recover(); break; default: throw new InvalidOperationException("Draft is in an invalid state."); } }
public void EnsureBroadcaster(CubeDraft draft, User user) { if (draft == null || user == null || draft.Broadcaster.Name.ToLower() != user.TwitchUsername.ToLower()) { throw new InvalidOperationException("You are not the broadcaster of this draft."); } }
public Drafter(CubeDraft draft, CubeDraftPlayer player, int position, DraftCollection draftCollection) { QueuedPicks.Enqueue(draftCollection.GetNextPack().Cards.ToList()); DraftId = draft.Id; PlayerId = player.Id; UserId = player.MtgoLink.UserId; PlayerName = player.MtgoLink.User.TwitchUsername; Position = position; Packs = draftCollection; _isTimed = draft.Timed; }
public HubResponse CreateDraft(string name, int roundLimits, bool requireWatchers) { var user = _db.Users.Find(Context.User.GetUserId()); //Should never happen, but an additional check just in case var broadcaster = _db.Broadcasters.FirstOrDefault(b => b.Name == user.TwitchUsername); if (broadcaster == null) { throw new Exception("Sorry, this feature is only for broadcasters on twitch.tv (With a valid mtgbot.tv client application)."); } var newCubeDraft = new CubeDraft { BroadcasterId = broadcaster.Id, Created = DateTime.Now, Name = name, RoundTime = roundLimits, RequireWatchers = requireWatchers }; try { _db.CubeDrafts.Add(newCubeDraft); _db.SaveChanges(); } catch (DbEntityValidationException) { return(HubResponse.ErrorResponse("There was a problem saving this cube draft. If this problem persists, please contact the developer.")); } string username = null; try { username = BotService.StartCubeDraft(newCubeDraft.Id); } catch (Exception ex) { Log.Error("Error calling BotService.StartCubeDraft(" + newCubeDraft.Id + ")", ex); } if (username == null) { return(HubResponse.ErrorResponse("Unable to create draft. There is no bot available to support this draft. Please try again later.")); } Groups.Add(Context.ConnectionId, String.Format("draft/{0}/clients", newCubeDraft.Id)); return(HubResponse.SuccessResponse(new { Username = username, DraftId = newCubeDraft.Id })); }
public void EndTournament(CubeDraft draft, User user) { if (draft == null) { throw new InvalidOperationException("Draft not found."); } EnsureBroadcaster(draft, user); draft.Status = CubeDraftStatus.ProductHandIn; _db.Entry(draft).State = EntityState.Modified; _db.SaveChanges(); }
public PlayerUpdatedModel(CubeDraftPlayer player, CubeDraft draft, bool trading = false) { if (player.MtgoLink == null) { throw new InvalidOperationException(); } Id = player.Id; UserId = player.MtgoLink.UserId; Username = player.MtgoLink.User.TwitchUsername; Confirmed = player.Confirmed; DeckBuilt = player.DeckBuilt; DeckStatus = "none"; Trading = trading; if (player.Confirmed) { MtgoUsername = player.MtgoLink.MtgoUsername; MtgoId = player.MtgoLink.MtgoId; RequireCollateral = player.RequireCollateral; var mtgoCount = draft.CubeDraftCards.Count(c => c.Location == player.MtgoLink.MtgoId); var pickCount = player.CubeDraftPicks.Count; if (pickCount > 0) { if (mtgoCount > 0 && mtgoCount < pickCount) { DeckStatus = "partial"; } else if (mtgoCount > 0 && mtgoCount >= pickCount) { DeckStatus = "full"; } } } else { RequireCollateral = 0; } }
public Drafter(CubeDraft draft, CubeDraftPlayer player, int position, DraftCollection draftCollection, List <Card> picks) { if (picks == null) { picks = new List <Card>(); } DraftId = draft.Id; PlayerId = player.Id; UserId = player.MtgoLink.UserId; PlayerName = player.MtgoLink.User.TwitchUsername; Position = position; _isTimed = draft.Timed; Packs = draftCollection; if (picks.Count == 0) { QueuedPicks.Enqueue(draftCollection.GetNextPack().Cards.ToList()); } Picks = picks; CurrentPick = picks.Count + 1; }